blob: abc69fcccde75c38bae825c5af24773d6721055c [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
Timur Iskhakov63f39902017-08-29 15:47:29 -070024DeathRecipientType::DeathRecipientType(Scope* parent) : Type(parent) {}
Martijn Coenen115d4282016-12-19 05:14:04 +010025
Steven Moreland0ecc7b82017-07-19 12:59:23 -070026std::string DeathRecipientType::typeName() const {
27 return "death recipient";
28}
29
Martijn Coenen115d4282016-12-19 05:14:04 +010030std::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
50std::string DeathRecipientType::getJavaType(bool /* forInitializer */) const {
Martijn Coenen8d12b502016-12-27 14:30:27 +010051 // TODO(b/33440494) decouple from hwbinder
52 return "android.os.IHwBinder.DeathRecipient";
Martijn Coenen115d4282016-12-19 05:14:04 +010053}
54
55std::string DeathRecipientType::getVtsType() const {
56 return "TYPE_DEATH_RECIPIENT";
57}
58
59void 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
69bool DeathRecipientType::needsEmbeddedReadWrite() const {
70 return false;
71}
72
73bool DeathRecipientType::resultNeedsDeref() const {
74 return true;
75}
76
Martijn Coenen115d4282016-12-19 05:14:04 +010077void DeathRecipientType::getAlignmentAndSize(size_t *align, size_t *size) const {
78 *align = *size = 0; // this object should only be used in passthrough mode
79}
80
Steven Moreland6ec9eb92018-02-16 14:21:49 -080081void DeathRecipientType::emitVtsTypeDeclarations(Formatter& out) const {
Martijn Coenen115d4282016-12-19 05:14:04 +010082 out << "type: " << getVtsType() << "\n";
Martijn Coenen115d4282016-12-19 05:14:04 +010083}
84
Martijn Coenen115d4282016-12-19 05:14:04 +010085} // namespace android
86