blob: 170611e0a7f90f88d857101bb22ba8023df0b12e [file] [log] [blame]
Andreas Huber1aec3972016-08-26 09:26:32 -07001/*
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
Andreas Huber295ad302016-08-16 11:35:00 -070017#include "GenericBinder.h"
18
Iliyan Malcheva72e0d22016-09-09 11:03:08 -070019#include <hidl-util/Formatter.h>
Andreas Huber295ad302016-08-16 11:35:00 -070020
21namespace android {
22
23GenericBinder::GenericBinder() {}
24
25bool GenericBinder::isBinder() const {
26 return true;
27}
28
Steven Moreland979e0992016-09-07 09:18:08 -070029void GenericBinder::addNamedTypesToSet(std::set<const FQName> &) const {
30 // do nothing
31}
32
Andreas Huber295ad302016-08-16 11:35:00 -070033std::string GenericBinder::getCppType(
Steven Moreland979e0992016-09-07 09:18:08 -070034 StorageMode mode,
35 std::string *extra,
36 bool specifyNamespaces) const {
Andreas Huber295ad302016-08-16 11:35:00 -070037 extra->clear();
Steven Moreland979e0992016-09-07 09:18:08 -070038 const std::string base =
39 std::string(specifyNamespaces ? "::android::" : "")
40 + "sp<"
41 + std::string(specifyNamespaces ? "::android::hardware::" : "")
42 + "IBinder>";
Andreas Huber295ad302016-08-16 11:35:00 -070043
44 switch (mode) {
45 case StorageMode_Stack:
46 case StorageMode_Result:
47 return base;
48
49 case StorageMode_Argument:
50 return "const " + base + "&";
51 }
52}
53
Andreas Huber4c865b72016-09-14 15:26:27 -070054std::string GenericBinder::getJavaType(
55 std::string *extra, bool /* forInitializer */) const {
56 extra->clear();
Andreas Huber295ad302016-08-16 11:35:00 -070057 return "IHwBinder";
58}
59
60void GenericBinder::emitReaderWriter(
61 Formatter &out,
62 const std::string &name,
63 const std::string &parcelObj,
64 bool parcelObjIsPointer,
65 bool isReader,
66 ErrorMode mode) const {
67 const std::string parcelObjDeref =
68 parcelObj + (parcelObjIsPointer ? "->" : ".");
69
70 if (isReader) {
71 out << "_hidl_err = ";
72 out << parcelObjDeref
73 << "readNullableStrongBinder(&"
74 << name
75 << ");\n";
76
77 handleError(out, mode);
78 } else {
79 out << "_hidl_err = ";
80 out << parcelObjDeref
81 << "writeStrongBinder("
82 << name
83 << ");\n";
84
85 handleError(out, mode);
86 }
87}
88
89void GenericBinder::emitJavaReaderWriter(
90 Formatter &out,
91 const std::string &parcelObj,
92 const std::string &argName,
93 bool isReader) const {
94 if (isReader) {
95 out << parcelObj
Steven Moreland0f0c13d2016-10-28 16:57:45 -070096 << ".readStrongBinder();\n";
Andreas Huber295ad302016-08-16 11:35:00 -070097 } else {
98 out << parcelObj
99 << ".writeStrongBinder("
100 << argName
101 << " == null ? null : "
102 << argName
103 << ");\n";
104 }
105}
106
Zhuoyao Zhang864c7712016-08-16 15:35:28 -0700107status_t GenericBinder::emitVtsAttributeType(Formatter &) const {
Andreas Huber295ad302016-08-16 11:35:00 -0700108 return UNKNOWN_ERROR;
109}
110
111} // namespace android