blob: f845bc509c53a8460287b9450ab2a7fee522c469 [file] [log] [blame]
Andreas Huberc9410c72016-07-28 12:18:40 -07001#include "Interface.h"
2
3#include "Formatter.h"
4#include "Method.h"
5
6namespace android {
7
8Interface::Interface(const char *name, Type *super)
9 : Scope(name),
10 mSuperType(super) {
11}
12
13void Interface::addMethod(Method *method) {
14 mMethods.push_back(method);
15}
16
17const Type *Interface::superType() const {
18 return mSuperType;
19}
20
21void Interface::dump(Formatter &out) const {
22 out << "interface " << name();
23
24 if (mSuperType != NULL) {
25 out << " extends ";
26 mSuperType->dump(out);
27 }
28
29 out << " {\n";
30
31 out.indent();
32 Scope::dump(out);
33
34 for (size_t i = 0; i < mMethods.size(); ++i) {
35 mMethods[i]->dump(out);
36
37 out << "\n";
38 }
39
40 out.unindent();
41
42 out << "};\n\n";
43}
44
Andreas Hubera2723d22016-07-29 15:36:07 -070045bool Interface::isInterface() const {
46 return true;
47}
48
Andreas Huber881227d2016-08-02 14:20:21 -070049const std::vector<Method *> &Interface::methods() const {
50 return mMethods;
51}
52
53std::string Interface::getCppType(StorageMode mode, std::string *extra) const {
54 extra->clear();
55 const std::string base = "::android::sp<" + name() + ">";
56
57 switch (mode) {
58 case StorageMode_Stack:
59 case StorageMode_Result:
60 return base;
61
62 case StorageMode_Argument:
63 return "const " + base + "&";
64 }
65}
66
67void Interface::emitReaderWriter(
68 Formatter &out,
69 const std::string &name,
70 const std::string &parcelObj,
71 bool parcelObjIsPointer,
72 bool isReader,
73 ErrorMode mode) const {
74 const std::string parcelObjDeref =
75 parcelObj + (parcelObjIsPointer ? "->" : ".");
76
77 if (isReader) {
78 const std::string binderName = "_aidl_" + name + "_binder";
79
80 out << "::android::sp<::android::hidl::IBinder> "
81 << binderName << ";\n";
82
83 out << "_aidl_err = ";
84 out << parcelObjDeref
85 << "readNullableStrongBinder(&"
86 << binderName
87 << ");\n";
88
89 handleError(out, mode);
90
91 out << name
92 << " = "
93 << this->name()
94 << "::asInterface("
95 << binderName
96 << ");\n";
97 } else {
98 out << "_aidl_err = ";
99 out << parcelObjDeref
100 << "writeStrongBinder("
101 << this->name()
102 << "::asBinder("
103 << name
104 << "));\n";
105
106 handleError(out, mode);
107 }
108}
109
Andreas Huberc9410c72016-07-28 12:18:40 -0700110} // namespace android
111