blob: 451aca3f32627e1330264bef3a0ae0cc4512ac41 [file] [log] [blame]
Andreas Huberc9410c72016-07-28 12:18:40 -07001#include "Interface.h"
2
Zhuoyao Zhangba7e6e92016-08-10 12:19:02 -07003#include "Annotation.h"
Andreas Huberc9410c72016-07-28 12:18:40 -07004#include "Formatter.h"
5#include "Method.h"
6
7namespace android {
8
Zhuoyao Zhangba7e6e92016-08-10 12:19:02 -07009Interface::Interface(
10 Interface *super,
11 KeyedVector<std::string, Annotation *> *annotations)
12 : mSuperType(super),
13 mAnnotationsByName(annotations) {
Andreas Huberc9410c72016-07-28 12:18:40 -070014}
15
16void Interface::addMethod(Method *method) {
17 mMethods.push_back(method);
18}
19
Andreas Huber6cb08cf2016-08-03 15:44:51 -070020const Interface *Interface::superType() const {
Andreas Huberc9410c72016-07-28 12:18:40 -070021 return mSuperType;
22}
23
Andreas Hubera2723d22016-07-29 15:36:07 -070024bool Interface::isInterface() const {
25 return true;
26}
27
Andreas Huber881227d2016-08-02 14:20:21 -070028const std::vector<Method *> &Interface::methods() const {
29 return mMethods;
30}
31
Zhuoyao Zhangba7e6e92016-08-10 12:19:02 -070032const KeyedVector<std::string, Annotation *> &Interface::annotations() const {
33 return *mAnnotationsByName;
34}
35
Andreas Huber881227d2016-08-02 14:20:21 -070036std::string Interface::getCppType(StorageMode mode, std::string *extra) const {
37 extra->clear();
Andreas Huber31629bc2016-08-03 09:06:40 -070038 const std::string base = "::android::sp<" + fullName() + ">";
Andreas Huber881227d2016-08-02 14:20:21 -070039
40 switch (mode) {
41 case StorageMode_Stack:
42 case StorageMode_Result:
43 return base;
44
45 case StorageMode_Argument:
46 return "const " + base + "&";
47 }
48}
49
50void Interface::emitReaderWriter(
51 Formatter &out,
52 const std::string &name,
53 const std::string &parcelObj,
54 bool parcelObjIsPointer,
55 bool isReader,
56 ErrorMode mode) const {
57 const std::string parcelObjDeref =
58 parcelObj + (parcelObjIsPointer ? "->" : ".");
59
60 if (isReader) {
61 const std::string binderName = "_aidl_" + name + "_binder";
62
Andreas Huber8a82ff72016-08-04 10:29:39 -070063 out << "::android::sp<::android::hardware::IBinder> "
Andreas Huber881227d2016-08-02 14:20:21 -070064 << binderName << ";\n";
65
66 out << "_aidl_err = ";
67 out << parcelObjDeref
68 << "readNullableStrongBinder(&"
69 << binderName
70 << ");\n";
71
72 handleError(out, mode);
73
74 out << name
75 << " = "
Andreas Huber0e00de42016-08-03 09:56:02 -070076 << fullName()
Andreas Huber881227d2016-08-02 14:20:21 -070077 << "::asInterface("
78 << binderName
79 << ");\n";
80 } else {
81 out << "_aidl_err = ";
82 out << parcelObjDeref
83 << "writeStrongBinder("
Andreas Huber0e00de42016-08-03 09:56:02 -070084 << fullName()
Andreas Huber881227d2016-08-02 14:20:21 -070085 << "::asBinder("
86 << name
87 << "));\n";
88
89 handleError(out, mode);
90 }
91}
92
Andreas Huberc9410c72016-07-28 12:18:40 -070093} // namespace android
94