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 | |
| 8 | Interface::Interface(const char *name, Type *super) |
| 9 | : Scope(name), |
| 10 | mSuperType(super) { |
| 11 | } |
| 12 | |
| 13 | void Interface::addMethod(Method *method) { |
| 14 | mMethods.push_back(method); |
| 15 | } |
| 16 | |
| 17 | const Type *Interface::superType() const { |
| 18 | return mSuperType; |
| 19 | } |
| 20 | |
| 21 | void 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 Huber | a2723d2 | 2016-07-29 15:36:07 -0700 | [diff] [blame] | 45 | bool Interface::isInterface() const { |
| 46 | return true; |
| 47 | } |
| 48 | |
Andreas Huber | 881227d | 2016-08-02 14:20:21 -0700 | [diff] [blame^] | 49 | const std::vector<Method *> &Interface::methods() const { |
| 50 | return mMethods; |
| 51 | } |
| 52 | |
| 53 | std::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 | |
| 67 | void 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 Huber | c9410c7 | 2016-07-28 12:18:40 -0700 | [diff] [blame] | 110 | } // namespace android |
| 111 | |