blob: a9b27af3cd4bf232a492fdd72fcb74aa3c9a8e9a [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
Andreas Huber6cb08cf2016-08-03 15:44:51 -07008Interface::Interface(Interface *super)
Andreas Huber31629bc2016-08-03 09:06:40 -07009 : mSuperType(super) {
Andreas Huberc9410c72016-07-28 12:18:40 -070010}
11
12void Interface::addMethod(Method *method) {
13 mMethods.push_back(method);
14}
15
Andreas Huber6cb08cf2016-08-03 15:44:51 -070016const Interface *Interface::superType() const {
Andreas Huberc9410c72016-07-28 12:18:40 -070017 return mSuperType;
18}
19
Andreas Hubera2723d22016-07-29 15:36:07 -070020bool Interface::isInterface() const {
21 return true;
22}
23
Andreas Huber881227d2016-08-02 14:20:21 -070024const std::vector<Method *> &Interface::methods() const {
25 return mMethods;
26}
27
28std::string Interface::getCppType(StorageMode mode, std::string *extra) const {
29 extra->clear();
Andreas Huber31629bc2016-08-03 09:06:40 -070030 const std::string base = "::android::sp<" + fullName() + ">";
Andreas Huber881227d2016-08-02 14:20:21 -070031
32 switch (mode) {
33 case StorageMode_Stack:
34 case StorageMode_Result:
35 return base;
36
37 case StorageMode_Argument:
38 return "const " + base + "&";
39 }
40}
41
42void Interface::emitReaderWriter(
43 Formatter &out,
44 const std::string &name,
45 const std::string &parcelObj,
46 bool parcelObjIsPointer,
47 bool isReader,
48 ErrorMode mode) const {
49 const std::string parcelObjDeref =
50 parcelObj + (parcelObjIsPointer ? "->" : ".");
51
52 if (isReader) {
Iliyan Malchev549e2592016-08-10 08:59:12 -070053 const std::string binderName = "_hidl_" + name + "_binder";
Andreas Huber881227d2016-08-02 14:20:21 -070054
Andreas Huber8a82ff72016-08-04 10:29:39 -070055 out << "::android::sp<::android::hardware::IBinder> "
Andreas Huber881227d2016-08-02 14:20:21 -070056 << binderName << ";\n";
57
Iliyan Malchev549e2592016-08-10 08:59:12 -070058 out << "_hidl_err = ";
Andreas Huber881227d2016-08-02 14:20:21 -070059 out << parcelObjDeref
60 << "readNullableStrongBinder(&"
61 << binderName
62 << ");\n";
63
64 handleError(out, mode);
65
66 out << name
67 << " = "
Andreas Huber0e00de42016-08-03 09:56:02 -070068 << fullName()
Andreas Huber881227d2016-08-02 14:20:21 -070069 << "::asInterface("
70 << binderName
71 << ");\n";
72 } else {
Iliyan Malchev549e2592016-08-10 08:59:12 -070073 out << "_hidl_err = ";
Andreas Huber881227d2016-08-02 14:20:21 -070074 out << parcelObjDeref
75 << "writeStrongBinder("
Andreas Huber0e00de42016-08-03 09:56:02 -070076 << fullName()
Andreas Huber881227d2016-08-02 14:20:21 -070077 << "::asBinder("
78 << name
79 << "));\n";
80
81 handleError(out, mode);
82 }
83}
84
Andreas Huberc9410c72016-07-28 12:18:40 -070085} // namespace android
86