blob: 4743e4f2f56c51b74eb22180591dcd21b54caa17 [file] [log] [blame]
Martijn Coenen115d4282016-12-19 05:14:04 +01001/*
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
22namespace android {
23
24DeathRecipientType::DeathRecipientType() {}
25
Martijn Coenen115d4282016-12-19 05:14:04 +010026std::string DeathRecipientType::getCppType(StorageMode mode,
27 bool specifyNamespaces) const {
28 const std::string base =
29 std::string(specifyNamespaces ? "::android::" : "")
30 + "sp<"
31 + (specifyNamespaces ? "::android::hardware::" : "")
32 + "hidl_death_recipient>";
33
34 switch (mode) {
35 case StorageMode_Stack:
36 return base;
37
38 case StorageMode_Argument:
39 return "const " + base + "&";
40
41 case StorageMode_Result:
42 return "const " + base + "*";
43 }
44}
45
46std::string DeathRecipientType::getJavaType(bool /* forInitializer */) const {
Martijn Coenen8d12b502016-12-27 14:30:27 +010047 // TODO(b/33440494) decouple from hwbinder
48 return "android.os.IHwBinder.DeathRecipient";
Martijn Coenen115d4282016-12-19 05:14:04 +010049}
50
51std::string DeathRecipientType::getVtsType() const {
52 return "TYPE_DEATH_RECIPIENT";
53}
54
55void DeathRecipientType::emitReaderWriter(
56 Formatter& out,
57 const std::string& /* name */,
58 const std::string& /* parcelObj */,
59 bool /* parcelObjIsPointer */,
60 bool /* isReader */,
61 ErrorMode /* mode */) const {
62 out << "LOG_ALWAYS_FATAL(\"DeathRecipient is only supported in passthrough mode\");\n";
63}
64
65bool DeathRecipientType::needsEmbeddedReadWrite() const {
66 return false;
67}
68
69bool DeathRecipientType::resultNeedsDeref() const {
70 return true;
71}
72
73bool DeathRecipientType::isJavaCompatible() const {
74 return true;
75}
76
77void DeathRecipientType::getAlignmentAndSize(size_t *align, size_t *size) const {
78 *align = *size = 0; // this object should only be used in passthrough mode
79}
80
81status_t DeathRecipientType::emitVtsTypeDeclarations(Formatter &out) const {
82 out << "type: " << getVtsType() << "\n";
83 return OK;
84}
85
86} // namespace android
87