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
DeathRecipientType(Scope * parent)24 DeathRecipientType::DeathRecipientType(Scope* parent) : Type(parent, "death_recipient") {}
25
typeName() const26 std::string DeathRecipientType::typeName() const {
27 return "death recipient";
28 }
29
getCppType(StorageMode mode,bool specifyNamespaces) const30 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
getJavaType(bool) const50 std::string DeathRecipientType::getJavaType(bool /* forInitializer */) const {
51 // TODO(b/33440494) decouple from hwbinder
52 return "android.os.IHwBinder.DeathRecipient";
53 }
54
getVtsType() const55 std::string DeathRecipientType::getVtsType() const {
56 return "TYPE_DEATH_RECIPIENT";
57 }
58
emitReaderWriter(Formatter & out,const std::string &,const std::string &,bool,bool,ErrorMode) const59 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
needsEmbeddedReadWrite() const69 bool DeathRecipientType::needsEmbeddedReadWrite() const {
70 return false;
71 }
72
resultNeedsDeref() const73 bool DeathRecipientType::resultNeedsDeref() const {
74 return true;
75 }
76
getAlignmentAndSize(size_t * align,size_t * size) const77 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
emitVtsTypeDeclarations(Formatter & out) const81 void DeathRecipientType::emitVtsTypeDeclarations(Formatter& out) const {
82 out << "type: " << getVtsType() << "\n";
83 }
84
85 } // namespace android
86
87