blob: 698b71212a3ff8da883e4f9e11b02071827aed9e [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
19#include "Formatter.h"
20
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
54std::string GenericBinder::getJavaType() const {
55 return "IHwBinder";
56}
57
58void GenericBinder::emitReaderWriter(
59 Formatter &out,
60 const std::string &name,
61 const std::string &parcelObj,
62 bool parcelObjIsPointer,
63 bool isReader,
64 ErrorMode mode) const {
65 const std::string parcelObjDeref =
66 parcelObj + (parcelObjIsPointer ? "->" : ".");
67
68 if (isReader) {
69 out << "_hidl_err = ";
70 out << parcelObjDeref
71 << "readNullableStrongBinder(&"
72 << name
73 << ");\n";
74
75 handleError(out, mode);
76 } else {
77 out << "_hidl_err = ";
78 out << parcelObjDeref
79 << "writeStrongBinder("
80 << name
81 << ");\n";
82
83 handleError(out, mode);
84 }
85}
86
87void GenericBinder::emitJavaReaderWriter(
88 Formatter &out,
89 const std::string &parcelObj,
90 const std::string &argName,
91 bool isReader) const {
92 if (isReader) {
93 out << parcelObj
94 << ".readStrongBinder());\n";
95 } else {
96 out << parcelObj
97 << ".writeStrongBinder("
98 << argName
99 << " == null ? null : "
100 << argName
101 << ");\n";
102 }
103}
104
Zhuoyao Zhang864c7712016-08-16 15:35:28 -0700105status_t GenericBinder::emitVtsAttributeType(Formatter &) const {
Andreas Huber295ad302016-08-16 11:35:00 -0700106 return UNKNOWN_ERROR;
107}
108
109} // namespace android