blob: 935da31cf5cf5a67350c14006280da4794056871 [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) {
43 case StorageMode_Stack:
44 case StorageMode_Result:
45 return base;
46
47 case StorageMode_Argument:
48 return "const " + base + "&";
49 }
50}
51
Yifan Hong4ed13472016-11-02 10:44:11 -070052std::string GenericBinder::getJavaType(bool /* forInitializer */) const {
Yifan Hong1af73532016-11-09 14:32:58 -080053 return "android.os.IHwBinder";
Andreas Huber295ad302016-08-16 11:35:00 -070054}
55
56void GenericBinder::emitReaderWriter(
57 Formatter &out,
58 const std::string &name,
59 const std::string &parcelObj,
60 bool parcelObjIsPointer,
61 bool isReader,
62 ErrorMode mode) const {
63 const std::string parcelObjDeref =
64 parcelObj + (parcelObjIsPointer ? "->" : ".");
65
66 if (isReader) {
67 out << "_hidl_err = ";
68 out << parcelObjDeref
69 << "readNullableStrongBinder(&"
70 << name
71 << ");\n";
72
73 handleError(out, mode);
74 } else {
75 out << "_hidl_err = ";
76 out << parcelObjDeref
77 << "writeStrongBinder("
78 << name
79 << ");\n";
80
81 handleError(out, mode);
82 }
83}
84
85void GenericBinder::emitJavaReaderWriter(
86 Formatter &out,
87 const std::string &parcelObj,
88 const std::string &argName,
89 bool isReader) const {
90 if (isReader) {
91 out << parcelObj
Steven Moreland0f0c13d2016-10-28 16:57:45 -070092 << ".readStrongBinder();\n";
Andreas Huber295ad302016-08-16 11:35:00 -070093 } else {
94 out << parcelObj
95 << ".writeStrongBinder("
96 << argName
97 << " == null ? null : "
98 << argName
99 << ");\n";
100 }
101}
102
Zhuoyao Zhang864c7712016-08-16 15:35:28 -0700103status_t GenericBinder::emitVtsAttributeType(Formatter &) const {
Andreas Huber295ad302016-08-16 11:35:00 -0700104 return UNKNOWN_ERROR;
105}
106
107} // namespace android