Martijn Coenen | 115d428 | 2016-12-19 05:14:04 +0100 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2016 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | #include "DeathRecipientType.h" |
| 18 | |
| 19 | #include <hidl-util/Formatter.h> |
| 20 | #include <android-base/logging.h> |
| 21 | |
| 22 | namespace android { |
| 23 | |
Timur Iskhakov | 63f3990 | 2017-08-29 15:47:29 -0700 | [diff] [blame] | 24 | DeathRecipientType::DeathRecipientType(Scope* parent) : Type(parent) {} |
Martijn Coenen | 115d428 | 2016-12-19 05:14:04 +0100 | [diff] [blame] | 25 | |
Steven Moreland | 0ecc7b8 | 2017-07-19 12:59:23 -0700 | [diff] [blame] | 26 | std::string DeathRecipientType::typeName() const { |
| 27 | return "death recipient"; |
| 28 | } |
| 29 | |
Martijn Coenen | 115d428 | 2016-12-19 05:14:04 +0100 | [diff] [blame] | 30 | std::string DeathRecipientType::getCppType(StorageMode mode, |
| 31 | bool specifyNamespaces) const { |
| 32 | const std::string base = |
| 33 | std::string(specifyNamespaces ? "::android::" : "") |
| 34 | + "sp<" |
| 35 | + (specifyNamespaces ? "::android::hardware::" : "") |
| 36 | + "hidl_death_recipient>"; |
| 37 | |
| 38 | switch (mode) { |
| 39 | case StorageMode_Stack: |
| 40 | return base; |
| 41 | |
| 42 | case StorageMode_Argument: |
| 43 | return "const " + base + "&"; |
| 44 | |
| 45 | case StorageMode_Result: |
| 46 | return "const " + base + "*"; |
| 47 | } |
| 48 | } |
| 49 | |
| 50 | std::string DeathRecipientType::getJavaType(bool /* forInitializer */) const { |
Martijn Coenen | 8d12b50 | 2016-12-27 14:30:27 +0100 | [diff] [blame] | 51 | // TODO(b/33440494) decouple from hwbinder |
| 52 | return "android.os.IHwBinder.DeathRecipient"; |
Martijn Coenen | 115d428 | 2016-12-19 05:14:04 +0100 | [diff] [blame] | 53 | } |
| 54 | |
| 55 | std::string DeathRecipientType::getVtsType() const { |
| 56 | return "TYPE_DEATH_RECIPIENT"; |
| 57 | } |
| 58 | |
| 59 | void DeathRecipientType::emitReaderWriter( |
| 60 | Formatter& out, |
| 61 | const std::string& /* name */, |
| 62 | const std::string& /* parcelObj */, |
| 63 | bool /* parcelObjIsPointer */, |
| 64 | bool /* isReader */, |
| 65 | ErrorMode /* mode */) const { |
| 66 | out << "LOG_ALWAYS_FATAL(\"DeathRecipient is only supported in passthrough mode\");\n"; |
| 67 | } |
| 68 | |
| 69 | bool DeathRecipientType::needsEmbeddedReadWrite() const { |
| 70 | return false; |
| 71 | } |
| 72 | |
| 73 | bool DeathRecipientType::resultNeedsDeref() const { |
| 74 | return true; |
| 75 | } |
| 76 | |
Martijn Coenen | 115d428 | 2016-12-19 05:14:04 +0100 | [diff] [blame] | 77 | void DeathRecipientType::getAlignmentAndSize(size_t *align, size_t *size) const { |
| 78 | *align = *size = 0; // this object should only be used in passthrough mode |
| 79 | } |
| 80 | |
| 81 | status_t DeathRecipientType::emitVtsTypeDeclarations(Formatter &out) const { |
| 82 | out << "type: " << getVtsType() << "\n"; |
| 83 | return OK; |
| 84 | } |
| 85 | |
| 86 | } // namespace android |
| 87 | |