blob: 8dad4e057481c1e0c4e27164ee54c412cdf60331 [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,
Steven Moreland979e0992016-09-07 09:18:08 -070035 bool specifyNamespaces) const {
Steven Moreland979e0992016-09-07 09:18:08 -070036 const std::string base =
37 std::string(specifyNamespaces ? "::android::" : "")
38 + "sp<"
39 + std::string(specifyNamespaces ? "::android::hardware::" : "")
40 + "IBinder>";
Andreas Huber295ad302016-08-16 11:35:00 -070041
42 switch (mode) {
Martijn Coenenac587892016-11-17 15:14:19 +010043 case StorageMode_Compound:
Andreas Huber295ad302016-08-16 11:35:00 -070044 case StorageMode_Stack:
45 case StorageMode_Result:
46 return base;
47
48 case StorageMode_Argument:
49 return "const " + base + "&";
50 }
51}
52
Yifan Hong4ed13472016-11-02 10:44:11 -070053std::string GenericBinder::getJavaType(bool /* forInitializer */) const {
Yifan Hong1af73532016-11-09 14:32:58 -080054 return "android.os.IHwBinder";
Andreas Huber295ad302016-08-16 11:35:00 -070055}
56
57void GenericBinder::emitReaderWriter(
58 Formatter &out,
59 const std::string &name,
60 const std::string &parcelObj,
61 bool parcelObjIsPointer,
62 bool isReader,
63 ErrorMode mode) const {
64 const std::string parcelObjDeref =
65 parcelObj + (parcelObjIsPointer ? "->" : ".");
66
67 if (isReader) {
68 out << "_hidl_err = ";
69 out << parcelObjDeref
70 << "readNullableStrongBinder(&"
71 << name
72 << ");\n";
73
74 handleError(out, mode);
75 } else {
76 out << "_hidl_err = ";
77 out << parcelObjDeref
78 << "writeStrongBinder("
79 << name
80 << ");\n";
81
82 handleError(out, mode);
83 }
84}
85
86void GenericBinder::emitJavaReaderWriter(
87 Formatter &out,
88 const std::string &parcelObj,
89 const std::string &argName,
90 bool isReader) const {
91 if (isReader) {
92 out << parcelObj
Steven Moreland0f0c13d2016-10-28 16:57:45 -070093 << ".readStrongBinder();\n";
Andreas Huber295ad302016-08-16 11:35:00 -070094 } else {
95 out << parcelObj
96 << ".writeStrongBinder("
97 << argName
98 << " == null ? null : "
99 << argName
100 << ");\n";
101 }
102}
103
Zhuoyao Zhang864c7712016-08-16 15:35:28 -0700104status_t GenericBinder::emitVtsAttributeType(Formatter &) const {
Andreas Huber295ad302016-08-16 11:35:00 -0700105 return UNKNOWN_ERROR;
106}
107
108} // namespace android