blob: 96f5dc13fcbe7b74009d28b0836bc05d87021694 [file] [log] [blame]
Andreas Huber295ad302016-08-16 11:35:00 -07001#include "GenericBinder.h"
2
3#include "Formatter.h"
4
5namespace android {
6
7GenericBinder::GenericBinder() {}
8
9bool GenericBinder::isBinder() const {
10 return true;
11}
12
13std::string GenericBinder::getCppType(
14 StorageMode mode, std::string *extra) const {
15 extra->clear();
16 const std::string base = "::android::sp<::android::hardware::IBinder>";
17
18 switch (mode) {
19 case StorageMode_Stack:
20 case StorageMode_Result:
21 return base;
22
23 case StorageMode_Argument:
24 return "const " + base + "&";
25 }
26}
27
28std::string GenericBinder::getJavaType() const {
29 return "IHwBinder";
30}
31
32void GenericBinder::emitReaderWriter(
33 Formatter &out,
34 const std::string &name,
35 const std::string &parcelObj,
36 bool parcelObjIsPointer,
37 bool isReader,
38 ErrorMode mode) const {
39 const std::string parcelObjDeref =
40 parcelObj + (parcelObjIsPointer ? "->" : ".");
41
42 if (isReader) {
43 out << "_hidl_err = ";
44 out << parcelObjDeref
45 << "readNullableStrongBinder(&"
46 << name
47 << ");\n";
48
49 handleError(out, mode);
50 } else {
51 out << "_hidl_err = ";
52 out << parcelObjDeref
53 << "writeStrongBinder("
54 << name
55 << ");\n";
56
57 handleError(out, mode);
58 }
59}
60
61void GenericBinder::emitJavaReaderWriter(
62 Formatter &out,
63 const std::string &parcelObj,
64 const std::string &argName,
65 bool isReader) const {
66 if (isReader) {
67 out << parcelObj
68 << ".readStrongBinder());\n";
69 } else {
70 out << parcelObj
71 << ".writeStrongBinder("
72 << argName
73 << " == null ? null : "
74 << argName
75 << ");\n";
76 }
77}
78
Zhuoyao Zhang864c7712016-08-16 15:35:28 -070079status_t GenericBinder::emitVtsAttributeType(Formatter &) const {
Andreas Huber295ad302016-08-16 11:35:00 -070080 return UNKNOWN_ERROR;
81}
82
83} // namespace android