Interface.h revision 891a866402345777c7e746cf8d0e4ffd0bd28ca2
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 <vector> 22 23#include "Reference.h" 24#include "Scope.h" 25 26namespace android { 27 28struct Method; 29struct InterfaceAndMethod; 30 31struct Interface : public Scope { 32 Interface(const char* localName, const Location& location, Scope* parent, 33 const Reference<Type>& superType); 34 35 bool addMethod(Method *method); 36 bool addAllReservedMethods(); 37 38 bool isElidableType() const override; 39 bool isInterface() const override; 40 bool isBinder() const override; 41 bool isIBase() const { return fqName() == gIBaseFqName; } 42 std::string typeName() const override; 43 44 const Interface* superType() const; 45 46 // Super type chain to root type. 47 // First element is superType(). 48 std::vector<const Interface *> superTypeChain() const; 49 // Super type chain to root type, including myself. 50 // First element is this. 51 std::vector<const Interface *> typeChain() const; 52 53 // user defined methods (explicit definition in HAL files) 54 const std::vector<Method *> &userDefinedMethods() const; 55 // HIDL reserved methods (every interface has these implicitly defined) 56 const std::vector<Method *> &hidlReservedMethods() const; 57 // the sum of userDefinedMethods() and hidlReservedMethods(). 58 std::vector<Method *> methods() const; 59 60 // userDefinedMethods() for all super type + methods() 61 // The order will be as follows (in the transaction code order): 62 // great-great-...-great-grand parent->userDefinedMethods() 63 // ... 64 // parent->userDefinedMethods() 65 // this->userDefinedMethods() 66 // this->hidlReservedMethods() 67 std::vector<InterfaceAndMethod> allMethodsFromRoot() const; 68 69 // allMethodsFromRoot for parent 70 std::vector<InterfaceAndMethod> allSuperMethodsFromRoot() const; 71 72 // aliases for corresponding methods in this->fqName() 73 std::string getBaseName() const; 74 std::string getProxyName() const; 75 std::string getStubName() const; 76 std::string getPassthroughName() const; 77 std::string getHwName() const; 78 FQName getProxyFqName() const; 79 FQName getStubFqName() const; 80 FQName getPassthroughFqName() const; 81 82 std::string getCppType( 83 StorageMode mode, 84 bool specifyNamespaces) const override; 85 86 std::string getJavaType(bool forInitializer) const override; 87 std::string getVtsType() const override; 88 89 std::vector<Reference<Type>> getReferences() const override; 90 91 std::vector<ConstantExpression*> getConstantExpressions() const override; 92 93 status_t resolveInheritance() override; 94 status_t validate() const override; 95 status_t validateUniqueNames() const; 96 97 void emitReaderWriter( 98 Formatter &out, 99 const std::string &name, 100 const std::string &parcelObj, 101 bool parcelObjIsPointer, 102 bool isReader, 103 ErrorMode mode) const override; 104 105 status_t emitGlobalTypeDeclarations(Formatter &out) const override; 106 status_t emitTypeDefinitions(Formatter& out, const std::string& prefix) const override; 107 108 void emitJavaReaderWriter( 109 Formatter &out, 110 const std::string &parcelObj, 111 const std::string &argName, 112 bool isReader) const override; 113 114 status_t emitVtsAttributeType(Formatter &out) const override; 115 116 status_t emitVtsAttributeDeclaration(Formatter &out) const; 117 status_t emitVtsMethodDeclaration(Formatter &out) const; 118 119 bool hasOnewayMethods() const; 120 121 bool isJavaCompatible() const override; 122 123 private: 124 Reference<Type> mSuperType; 125 126 std::vector<Method*> mUserMethods; 127 std::vector<Method*> mReservedMethods; 128 129 mutable bool mIsJavaCompatibleInProgress; 130 131 bool fillPingMethod(Method* method) const; 132 bool fillDescriptorChainMethod(Method* method) const; 133 bool fillGetDescriptorMethod(Method* method) const; 134 bool fillHashChainMethod(Method* method) const; 135 bool fillSyspropsChangedMethod(Method* method) const; 136 bool fillLinkToDeathMethod(Method* method) const; 137 bool fillUnlinkToDeathMethod(Method* method) const; 138 bool fillSetHALInstrumentationMethod(Method* method) const; 139 bool fillGetDebugInfoMethod(Method* method) const; 140 bool fillDebugMethod(Method* method) const; 141 142 DISALLOW_COPY_AND_ASSIGN(Interface); 143}; 144 145// An interface / method tuple. 146struct InterfaceAndMethod { 147 InterfaceAndMethod(const Interface *iface, Method *method) 148 : mInterface(iface), 149 mMethod(method) {} 150 Method *method() const { return mMethod; } 151 const Interface *interface() const { return mInterface; } 152 153 private: 154 // do not own these objects. 155 const Interface *mInterface; 156 Method *mMethod; 157}; 158 159} // namespace android 160 161#endif // INTERFACE_H_ 162 163