Interface.h revision f1b902d10bd2d71ad7f4769620678101821fd5d1
11aec397b1fdea7db4120dbe55b6995bb2a9d9138Andreas Huber/* 21aec397b1fdea7db4120dbe55b6995bb2a9d9138Andreas Huber * Copyright (C) 2016 The Android Open Source Project 31aec397b1fdea7db4120dbe55b6995bb2a9d9138Andreas Huber * 41aec397b1fdea7db4120dbe55b6995bb2a9d9138Andreas Huber * Licensed under the Apache License, Version 2.0 (the "License"); 51aec397b1fdea7db4120dbe55b6995bb2a9d9138Andreas Huber * you may not use this file except in compliance with the License. 61aec397b1fdea7db4120dbe55b6995bb2a9d9138Andreas Huber * You may obtain a copy of the License at 71aec397b1fdea7db4120dbe55b6995bb2a9d9138Andreas Huber * 81aec397b1fdea7db4120dbe55b6995bb2a9d9138Andreas Huber * http://www.apache.org/licenses/LICENSE-2.0 91aec397b1fdea7db4120dbe55b6995bb2a9d9138Andreas Huber * 101aec397b1fdea7db4120dbe55b6995bb2a9d9138Andreas Huber * Unless required by applicable law or agreed to in writing, software 111aec397b1fdea7db4120dbe55b6995bb2a9d9138Andreas Huber * distributed under the License is distributed on an "AS IS" BASIS, 121aec397b1fdea7db4120dbe55b6995bb2a9d9138Andreas Huber * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 131aec397b1fdea7db4120dbe55b6995bb2a9d9138Andreas Huber * See the License for the specific language governing permissions and 141aec397b1fdea7db4120dbe55b6995bb2a9d9138Andreas Huber * limitations under the License. 151aec397b1fdea7db4120dbe55b6995bb2a9d9138Andreas Huber */ 161aec397b1fdea7db4120dbe55b6995bb2a9d9138Andreas Huber 17c9410c7e62a33fd7599b2f3e025093a2d171577eAndreas Huber#ifndef INTERFACE_H_ 18c9410c7e62a33fd7599b2f3e025093a2d171577eAndreas Huber 19c9410c7e62a33fd7599b2f3e025093a2d171577eAndreas Huber#define INTERFACE_H_ 20c9410c7e62a33fd7599b2f3e025093a2d171577eAndreas Huber 216f2f2c026b0b6e372194794e171208a91d74f852Steven Moreland#include <vector> 224b80bc4402ec88504265e6fdbcdb8a803d67eb64Timur Iskhakov 23505316c499a4dbb95f6567e8531fb6f1e74c3dedTimur Iskhakov#include "Reference.h" 24505316c499a4dbb95f6567e8531fb6f1e74c3dedTimur Iskhakov#include "Scope.h" 25505316c499a4dbb95f6567e8531fb6f1e74c3dedTimur Iskhakov 26c9410c7e62a33fd7599b2f3e025093a2d171577eAndreas Hubernamespace android { 27c9410c7e62a33fd7599b2f3e025093a2d171577eAndreas Huber 28c9410c7e62a33fd7599b2f3e025093a2d171577eAndreas Huberstruct Method; 2910fe0b55e774903fe37b658458053527da8b5a53Yifan Hongstruct InterfaceAndMethod; 30c9410c7e62a33fd7599b2f3e025093a2d171577eAndreas Huber 31c9410c7e62a33fd7599b2f3e025093a2d171577eAndreas Huberstruct Interface : public Scope { 32505316c499a4dbb95f6567e8531fb6f1e74c3dedTimur Iskhakov Interface(const char* localName, const Location& location, Scope* parent, 33505316c499a4dbb95f6567e8531fb6f1e74c3dedTimur Iskhakov const Reference<Interface>& superType); 34c9410c7e62a33fd7599b2f3e025093a2d171577eAndreas Huber 3514ee6749f12bcd43477fe8110fbec38e15376b40Steven Moreland bool addMethod(Method *method); 36ffa913993fb527b44053c11f139689d3267748ecYifan Hong bool addAllReservedMethods(); 37c9410c7e62a33fd7599b2f3e025093a2d171577eAndreas Huber 38b40ef02ca14e507a5a5b878c90eaac52ffe64fd9Martijn Coenen bool isElidableType() const override; 39a2723d26427f7db19777dfed330047253e7a4e1bAndreas Huber bool isInterface() const override; 40295ad30bf6212c16accc5095601b2a71d44b4c8bAndreas Huber bool isBinder() const override; 41c89340422f53046bfe24ff3e529161f9194120f8Yifan Hong bool isIBase() const { return fqName() == gIBaseFqName; } 4230bb6a869be0f3f82497b7b11c71ec9d47652ed0Steven Moreland std::string typeName() const override; 43c9410c7e62a33fd7599b2f3e025093a2d171577eAndreas Huber 44505316c499a4dbb95f6567e8531fb6f1e74c3dedTimur Iskhakov const Interface* superType() const; 45c9410c7e62a33fd7599b2f3e025093a2d171577eAndreas Huber 4614ee6749f12bcd43477fe8110fbec38e15376b40Steven Moreland Method *lookupMethod(std::string name) const; 47fe95aa243eb53df9cb46ca74192e760d7520b611Yifan Hong // Super type chain to root type. 48fe95aa243eb53df9cb46ca74192e760d7520b611Yifan Hong // First element is superType(). 49fe95aa243eb53df9cb46ca74192e760d7520b611Yifan Hong std::vector<const Interface *> superTypeChain() const; 5010fe0b55e774903fe37b658458053527da8b5a53Yifan Hong // Super type chain to root type, including myself. 5110fe0b55e774903fe37b658458053527da8b5a53Yifan Hong // First element is this. 5210fe0b55e774903fe37b658458053527da8b5a53Yifan Hong std::vector<const Interface *> typeChain() const; 5310fe0b55e774903fe37b658458053527da8b5a53Yifan Hong 5410fe0b55e774903fe37b658458053527da8b5a53Yifan Hong // user defined methods (explicit definition in HAL files) 5510fe0b55e774903fe37b658458053527da8b5a53Yifan Hong const std::vector<Method *> &userDefinedMethods() const; 5610fe0b55e774903fe37b658458053527da8b5a53Yifan Hong // HIDL reserved methods (every interface has these implicitly defined) 5710fe0b55e774903fe37b658458053527da8b5a53Yifan Hong const std::vector<Method *> &hidlReservedMethods() const; 5810fe0b55e774903fe37b658458053527da8b5a53Yifan Hong // the sum of userDefinedMethods() and hidlReservedMethods(). 5910fe0b55e774903fe37b658458053527da8b5a53Yifan Hong std::vector<Method *> methods() const; 6010fe0b55e774903fe37b658458053527da8b5a53Yifan Hong 6110fe0b55e774903fe37b658458053527da8b5a53Yifan Hong // userDefinedMethods() for all super type + methods() 6210fe0b55e774903fe37b658458053527da8b5a53Yifan Hong // The order will be as follows (in the transaction code order): 6310fe0b55e774903fe37b658458053527da8b5a53Yifan Hong // great-great-...-great-grand parent->userDefinedMethods() 6410fe0b55e774903fe37b658458053527da8b5a53Yifan Hong // ... 6510fe0b55e774903fe37b658458053527da8b5a53Yifan Hong // parent->userDefinedMethods() 6610fe0b55e774903fe37b658458053527da8b5a53Yifan Hong // this->userDefinedMethods() 6710fe0b55e774903fe37b658458053527da8b5a53Yifan Hong // this->hidlReservedMethods() 6810fe0b55e774903fe37b658458053527da8b5a53Yifan Hong std::vector<InterfaceAndMethod> allMethodsFromRoot() const; 69881227d860c59471eee31d39946e96ce2daa35d6Andreas Huber 70f1b902d10bd2d71ad7f4769620678101821fd5d1Timur Iskhakov // allMethodsFromRoot for parent 71f1b902d10bd2d71ad7f4769620678101821fd5d1Timur Iskhakov std::vector<InterfaceAndMethod> allSuperMethodsFromRoot() const; 72f1b902d10bd2d71ad7f4769620678101821fd5d1Timur Iskhakov 73eefe4f2405c3cb0f1d164bdb748e5d0ded3624f9Yifan Hong // aliases for corresponding methods in this->fqName() 744078631353d6d34db21c890d1870e796eca6ea38Steven Moreland std::string getBaseName() const; 75eefe4f2405c3cb0f1d164bdb748e5d0ded3624f9Yifan Hong std::string getProxyName() const; 76eefe4f2405c3cb0f1d164bdb748e5d0ded3624f9Yifan Hong std::string getStubName() const; 77eefe4f2405c3cb0f1d164bdb748e5d0ded3624f9Yifan Hong std::string getPassthroughName() const; 78eefe4f2405c3cb0f1d164bdb748e5d0ded3624f9Yifan Hong std::string getHwName() const; 7951a6509db3078657a2401069c37515504b40c12cYifan Hong FQName getProxyFqName() const; 8051a6509db3078657a2401069c37515504b40c12cYifan Hong FQName getStubFqName() const; 8151a6509db3078657a2401069c37515504b40c12cYifan Hong FQName getPassthroughFqName() const; 82158655a90308d8e5f03dc28b8330d5b0cce038f0Yifan Hong 834c865b72b320a46f326a335cfd326b66b0e10f67Andreas Huber std::string getCppType( 844c865b72b320a46f326a335cfd326b66b0e10f67Andreas Huber StorageMode mode, 854c865b72b320a46f326a335cfd326b66b0e10f67Andreas Huber bool specifyNamespaces) const override; 86881227d860c59471eee31d39946e96ce2daa35d6Andreas Huber 874ed1347cd29e6e07acad368891bb03078c798abaYifan Hong std::string getJavaType(bool forInitializer) const override; 88a588b23323213c525bf34dc0562679195afe611eZhuoyao Zhang std::string getVtsType() const override; 892831d5145675ead9f2fb767bf5fe4ae56b88349fAndreas Huber 90881227d860c59471eee31d39946e96ce2daa35d6Andreas Huber void emitReaderWriter( 91881227d860c59471eee31d39946e96ce2daa35d6Andreas Huber Formatter &out, 92881227d860c59471eee31d39946e96ce2daa35d6Andreas Huber const std::string &name, 93881227d860c59471eee31d39946e96ce2daa35d6Andreas Huber const std::string &parcelObj, 94881227d860c59471eee31d39946e96ce2daa35d6Andreas Huber bool parcelObjIsPointer, 95881227d860c59471eee31d39946e96ce2daa35d6Andreas Huber bool isReader, 96881227d860c59471eee31d39946e96ce2daa35d6Andreas Huber ErrorMode mode) const override; 97881227d860c59471eee31d39946e96ce2daa35d6Andreas Huber 98f5cc2f74e86504f7904a0a24e7fcc00fa19cd579Yifan Hong status_t emitGlobalTypeDeclarations(Formatter &out) const override; 99f5cc2f74e86504f7904a0a24e7fcc00fa19cd579Yifan Hong status_t emitTypeDefinitions( 100f5cc2f74e86504f7904a0a24e7fcc00fa19cd579Yifan Hong Formatter &out, const std::string prefix) const override; 101f5cc2f74e86504f7904a0a24e7fcc00fa19cd579Yifan Hong 1022831d5145675ead9f2fb767bf5fe4ae56b88349fAndreas Huber void emitJavaReaderWriter( 1032831d5145675ead9f2fb767bf5fe4ae56b88349fAndreas Huber Formatter &out, 1042831d5145675ead9f2fb767bf5fe4ae56b88349fAndreas Huber const std::string &parcelObj, 1052831d5145675ead9f2fb767bf5fe4ae56b88349fAndreas Huber const std::string &argName, 1062831d5145675ead9f2fb767bf5fe4ae56b88349fAndreas Huber bool isReader) const override; 1072831d5145675ead9f2fb767bf5fe4ae56b88349fAndreas Huber 108864c771ca4ec8a01e31c7c243625b7a5f6316768Zhuoyao Zhang status_t emitVtsAttributeType(Formatter &out) const override; 109864c771ca4ec8a01e31c7c243625b7a5f6316768Zhuoyao Zhang 110864c771ca4ec8a01e31c7c243625b7a5f6316768Zhuoyao Zhang status_t emitVtsAttributeDeclaration(Formatter &out) const; 111864c771ca4ec8a01e31c7c243625b7a5f6316768Zhuoyao Zhang status_t emitVtsMethodDeclaration(Formatter &out) const; 1125158db484e5ab302368f191d75d5b1334c270e52Zhuoyao Zhang 11369e7c70e72dff0734d542b737ba8bb1178244218Steven Moreland bool hasOnewayMethods() const; 11469e7c70e72dff0734d542b737ba8bb1178244218Steven Moreland 11570a59e1dc3dcf32f791d2dd7966111d4adf32ecaAndreas Huber bool isJavaCompatible() const override; 11670a59e1dc3dcf32f791d2dd7966111d4adf32ecaAndreas Huber 117505316c499a4dbb95f6567e8531fb6f1e74c3dedTimur Iskhakov private: 118505316c499a4dbb95f6567e8531fb6f1e74c3dedTimur Iskhakov Reference<Interface> mSuperType; 119505316c499a4dbb95f6567e8531fb6f1e74c3dedTimur Iskhakov 120505316c499a4dbb95f6567e8531fb6f1e74c3dedTimur Iskhakov std::vector<Method*> mUserMethods; 121505316c499a4dbb95f6567e8531fb6f1e74c3dedTimur Iskhakov std::vector<Method*> mReservedMethods; 122505316c499a4dbb95f6567e8531fb6f1e74c3dedTimur Iskhakov 123ea081b35840e687dfe7a5c11d4a546f2bf2db99eAndreas Huber mutable bool mIsJavaCompatibleInProgress; 124505316c499a4dbb95f6567e8531fb6f1e74c3dedTimur Iskhakov 125505316c499a4dbb95f6567e8531fb6f1e74c3dedTimur Iskhakov bool fillPingMethod(Method* method) const; 126505316c499a4dbb95f6567e8531fb6f1e74c3dedTimur Iskhakov bool fillDescriptorChainMethod(Method* method) const; 127505316c499a4dbb95f6567e8531fb6f1e74c3dedTimur Iskhakov bool fillGetDescriptorMethod(Method* method) const; 128505316c499a4dbb95f6567e8531fb6f1e74c3dedTimur Iskhakov bool fillHashChainMethod(Method* method) const; 129505316c499a4dbb95f6567e8531fb6f1e74c3dedTimur Iskhakov bool fillSyspropsChangedMethod(Method* method) const; 130505316c499a4dbb95f6567e8531fb6f1e74c3dedTimur Iskhakov bool fillLinkToDeathMethod(Method* method) const; 131505316c499a4dbb95f6567e8531fb6f1e74c3dedTimur Iskhakov bool fillUnlinkToDeathMethod(Method* method) const; 132505316c499a4dbb95f6567e8531fb6f1e74c3dedTimur Iskhakov bool fillSetHALInstrumentationMethod(Method* method) const; 133505316c499a4dbb95f6567e8531fb6f1e74c3dedTimur Iskhakov bool fillGetDebugInfoMethod(Method* method) const; 134505316c499a4dbb95f6567e8531fb6f1e74c3dedTimur Iskhakov bool fillDebugMethod(Method* method) const; 135c9410c7e62a33fd7599b2f3e025093a2d171577eAndreas Huber 136c9410c7e62a33fd7599b2f3e025093a2d171577eAndreas Huber DISALLOW_COPY_AND_ASSIGN(Interface); 137c9410c7e62a33fd7599b2f3e025093a2d171577eAndreas Huber}; 138c9410c7e62a33fd7599b2f3e025093a2d171577eAndreas Huber 13910fe0b55e774903fe37b658458053527da8b5a53Yifan Hong// An interface / method tuple. 14010fe0b55e774903fe37b658458053527da8b5a53Yifan Hongstruct InterfaceAndMethod { 14110fe0b55e774903fe37b658458053527da8b5a53Yifan Hong InterfaceAndMethod(const Interface *iface, Method *method) 14210fe0b55e774903fe37b658458053527da8b5a53Yifan Hong : mInterface(iface), 14310fe0b55e774903fe37b658458053527da8b5a53Yifan Hong mMethod(method) {} 14410fe0b55e774903fe37b658458053527da8b5a53Yifan Hong Method *method() const { return mMethod; } 14510fe0b55e774903fe37b658458053527da8b5a53Yifan Hong const Interface *interface() const { return mInterface; } 146505316c499a4dbb95f6567e8531fb6f1e74c3dedTimur Iskhakov 147505316c499a4dbb95f6567e8531fb6f1e74c3dedTimur Iskhakov private: 14810fe0b55e774903fe37b658458053527da8b5a53Yifan Hong // do not own these objects. 14910fe0b55e774903fe37b658458053527da8b5a53Yifan Hong const Interface *mInterface; 15010fe0b55e774903fe37b658458053527da8b5a53Yifan Hong Method *mMethod; 15110fe0b55e774903fe37b658458053527da8b5a53Yifan Hong}; 15210fe0b55e774903fe37b658458053527da8b5a53Yifan Hong 153c9410c7e62a33fd7599b2f3e025093a2d171577eAndreas Huber} // namespace android 154c9410c7e62a33fd7599b2f3e025093a2d171577eAndreas Huber 155c9410c7e62a33fd7599b2f3e025093a2d171577eAndreas Huber#endif // INTERFACE_H_ 156c9410c7e62a33fd7599b2f3e025093a2d171577eAndreas Huber 157