1 /* 2 * Copyright (C) 2016 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 #ifndef INTERFACE_H_ 18 19 #define INTERFACE_H_ 20 21 #include "Scope.h" 22 #include <vector> 23 24 namespace android { 25 26 struct Method; 27 struct InterfaceAndMethod; 28 29 struct Interface : public Scope { 30 Interface(const char* localName, const Location& location, Scope* parent, Interface* super); 31 32 bool addMethod(Method *method); 33 bool addAllReservedMethods(); 34 35 bool isElidableType() const override; 36 bool isInterface() const override; 37 bool isBinder() const override; 38 bool isRootType() const { return mSuperType == nullptr; } 39 bool isIBase() const { return fqName() == gIBaseFqName; } 40 std::string typeName() const override; 41 42 const Interface *superType() const; 43 44 Method *lookupMethod(std::string name) const; 45 // Super type chain to root type. 46 // First element is superType(). 47 std::vector<const Interface *> superTypeChain() const; 48 // Super type chain to root type, including myself. 49 // First element is this. 50 std::vector<const Interface *> typeChain() const; 51 52 // user defined methods (explicit definition in HAL files) 53 const std::vector<Method *> &userDefinedMethods() const; 54 // HIDL reserved methods (every interface has these implicitly defined) 55 const std::vector<Method *> &hidlReservedMethods() const; 56 // the sum of userDefinedMethods() and hidlReservedMethods(). 57 std::vector<Method *> methods() const; 58 59 // userDefinedMethods() for all super type + methods() 60 // The order will be as follows (in the transaction code order): 61 // great-great-...-great-grand parent->userDefinedMethods() 62 // ... 63 // parent->userDefinedMethods() 64 // this->userDefinedMethods() 65 // this->hidlReservedMethods() 66 std::vector<InterfaceAndMethod> allMethodsFromRoot() const; 67 68 // aliases for corresponding methods in this->fqName() 69 std::string getBaseName() const; 70 std::string getProxyName() const; 71 std::string getStubName() const; 72 std::string getPassthroughName() const; 73 std::string getHwName() const; 74 FQName getProxyFqName() const; 75 FQName getStubFqName() const; 76 FQName getPassthroughFqName() const; 77 78 std::string getCppType( 79 StorageMode mode, 80 bool specifyNamespaces) const override; 81 82 std::string getJavaType(bool forInitializer) const override; 83 std::string getVtsType() const override; 84 85 void emitReaderWriter( 86 Formatter &out, 87 const std::string &name, 88 const std::string &parcelObj, 89 bool parcelObjIsPointer, 90 bool isReader, 91 ErrorMode mode) const override; 92 93 status_t emitGlobalTypeDeclarations(Formatter &out) const override; 94 status_t emitTypeDefinitions( 95 Formatter &out, const std::string prefix) const override; 96 97 void emitJavaReaderWriter( 98 Formatter &out, 99 const std::string &parcelObj, 100 const std::string &argName, 101 bool isReader) const override; 102 103 status_t emitVtsAttributeType(Formatter &out) const override; 104 105 status_t emitVtsAttributeDeclaration(Formatter &out) const; 106 status_t emitVtsMethodDeclaration(Formatter &out) const; 107 108 bool hasOnewayMethods() const; 109 110 bool isJavaCompatible() const override; 111 112 private: 113 Interface *mSuperType; 114 std::vector<Method *> mUserMethods; 115 std::vector<Method *> mReservedMethods; 116 mutable bool mIsJavaCompatibleInProgress; 117 bool fillPingMethod(Method *method) const; 118 bool fillDescriptorChainMethod(Method *method) const; 119 bool fillGetDescriptorMethod(Method *method) const; 120 bool fillHashChainMethod(Method *method) const; 121 bool fillSyspropsChangedMethod(Method *method) const; 122 bool fillLinkToDeathMethod(Method *method) const; 123 bool fillUnlinkToDeathMethod(Method *method) const; 124 bool fillSetHALInstrumentationMethod(Method *method) const; 125 bool fillGetDebugInfoMethod(Method *method) const; 126 bool fillDebugMethod(Method *method) const; 127 128 DISALLOW_COPY_AND_ASSIGN(Interface); 129 }; 130 131 // An interface / method tuple. 132 struct InterfaceAndMethod { 133 InterfaceAndMethod(const Interface *iface, Method *method) 134 : mInterface(iface), 135 mMethod(method) {} 136 Method *method() const { return mMethod; } 137 const Interface *interface() const { return mInterface; } 138 private: 139 // do not own these objects. 140 const Interface *mInterface; 141 Method *mMethod; 142 }; 143 144 } // namespace android 145 146 #endif // INTERFACE_H_ 147 148