Andreas Huber | c9410c7 | 2016-07-28 12:18:40 -0700 | [diff] [blame] | 1 | #include "Interface.h" |
| 2 | |
| 3 | #include "Formatter.h" |
| 4 | #include "Method.h" |
| 5 | |
| 6 | namespace android { |
| 7 | |
Andreas Huber | 6cb08cf | 2016-08-03 15:44:51 -0700 | [diff] [blame] | 8 | Interface::Interface(Interface *super) |
Andreas Huber | 31629bc | 2016-08-03 09:06:40 -0700 | [diff] [blame] | 9 | : mSuperType(super) { |
Andreas Huber | c9410c7 | 2016-07-28 12:18:40 -0700 | [diff] [blame] | 10 | } |
| 11 | |
| 12 | void Interface::addMethod(Method *method) { |
| 13 | mMethods.push_back(method); |
| 14 | } |
| 15 | |
Andreas Huber | 6cb08cf | 2016-08-03 15:44:51 -0700 | [diff] [blame] | 16 | const Interface *Interface::superType() const { |
Andreas Huber | c9410c7 | 2016-07-28 12:18:40 -0700 | [diff] [blame] | 17 | return mSuperType; |
| 18 | } |
| 19 | |
Andreas Huber | a2723d2 | 2016-07-29 15:36:07 -0700 | [diff] [blame] | 20 | bool Interface::isInterface() const { |
| 21 | return true; |
| 22 | } |
| 23 | |
Andreas Huber | 881227d | 2016-08-02 14:20:21 -0700 | [diff] [blame] | 24 | const std::vector<Method *> &Interface::methods() const { |
| 25 | return mMethods; |
| 26 | } |
| 27 | |
| 28 | std::string Interface::getCppType(StorageMode mode, std::string *extra) const { |
| 29 | extra->clear(); |
Andreas Huber | 31629bc | 2016-08-03 09:06:40 -0700 | [diff] [blame] | 30 | const std::string base = "::android::sp<" + fullName() + ">"; |
Andreas Huber | 881227d | 2016-08-02 14:20:21 -0700 | [diff] [blame] | 31 | |
| 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 | |
| 42 | void 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 Malchev | 549e259 | 2016-08-10 08:59:12 -0700 | [diff] [blame^] | 53 | const std::string binderName = "_hidl_" + name + "_binder"; |
Andreas Huber | 881227d | 2016-08-02 14:20:21 -0700 | [diff] [blame] | 54 | |
Andreas Huber | 8a82ff7 | 2016-08-04 10:29:39 -0700 | [diff] [blame] | 55 | out << "::android::sp<::android::hardware::IBinder> " |
Andreas Huber | 881227d | 2016-08-02 14:20:21 -0700 | [diff] [blame] | 56 | << binderName << ";\n"; |
| 57 | |
Iliyan Malchev | 549e259 | 2016-08-10 08:59:12 -0700 | [diff] [blame^] | 58 | out << "_hidl_err = "; |
Andreas Huber | 881227d | 2016-08-02 14:20:21 -0700 | [diff] [blame] | 59 | out << parcelObjDeref |
| 60 | << "readNullableStrongBinder(&" |
| 61 | << binderName |
| 62 | << ");\n"; |
| 63 | |
| 64 | handleError(out, mode); |
| 65 | |
| 66 | out << name |
| 67 | << " = " |
Andreas Huber | 0e00de4 | 2016-08-03 09:56:02 -0700 | [diff] [blame] | 68 | << fullName() |
Andreas Huber | 881227d | 2016-08-02 14:20:21 -0700 | [diff] [blame] | 69 | << "::asInterface(" |
| 70 | << binderName |
| 71 | << ");\n"; |
| 72 | } else { |
Iliyan Malchev | 549e259 | 2016-08-10 08:59:12 -0700 | [diff] [blame^] | 73 | out << "_hidl_err = "; |
Andreas Huber | 881227d | 2016-08-02 14:20:21 -0700 | [diff] [blame] | 74 | out << parcelObjDeref |
| 75 | << "writeStrongBinder(" |
Andreas Huber | 0e00de4 | 2016-08-03 09:56:02 -0700 | [diff] [blame] | 76 | << fullName() |
Andreas Huber | 881227d | 2016-08-02 14:20:21 -0700 | [diff] [blame] | 77 | << "::asBinder(" |
| 78 | << name |
| 79 | << "));\n"; |
| 80 | |
| 81 | handleError(out, mode); |
| 82 | } |
| 83 | } |
| 84 | |
Andreas Huber | c9410c7 | 2016-07-28 12:18:40 -0700 | [diff] [blame] | 85 | } // namespace android |
| 86 | |