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 2304dea8d14fa4089d690e71f1b79d7d3b810c7272Steven Moreland#include <hidl-hash/Hash.h> 2404dea8d14fa4089d690e71f1b79d7d3b810c7272Steven Moreland 25505316c499a4dbb95f6567e8531fb6f1e74c3dedTimur Iskhakov#include "Reference.h" 26505316c499a4dbb95f6567e8531fb6f1e74c3dedTimur Iskhakov#include "Scope.h" 27505316c499a4dbb95f6567e8531fb6f1e74c3dedTimur Iskhakov 28c9410c7e62a33fd7599b2f3e025093a2d171577eAndreas Hubernamespace android { 29c9410c7e62a33fd7599b2f3e025093a2d171577eAndreas Huber 30c9410c7e62a33fd7599b2f3e025093a2d171577eAndreas Huberstruct Method; 3110fe0b55e774903fe37b658458053527da8b5a53Yifan Hongstruct InterfaceAndMethod; 32c9410c7e62a33fd7599b2f3e025093a2d171577eAndreas Huber 33c9410c7e62a33fd7599b2f3e025093a2d171577eAndreas Huberstruct Interface : public Scope { 343ce7214bd94cc880601d4dd459a37264633452a2Steven Moreland enum { 353ce7214bd94cc880601d4dd459a37264633452a2Steven Moreland /////////////////// Flag(s) - DO NOT CHANGE 363ce7214bd94cc880601d4dd459a37264633452a2Steven Moreland FLAG_ONEWAY = 0x00000001, 373ce7214bd94cc880601d4dd459a37264633452a2Steven Moreland }; 383ce7214bd94cc880601d4dd459a37264633452a2Steven Moreland 39565b0137b2ad0e8e239d38e92c025f096de62f2dTimur Iskhakov Interface(const char* localName, const FQName& fullName, const Location& location, 4004dea8d14fa4089d690e71f1b79d7d3b810c7272Steven Moreland Scope* parent, const Reference<Type>& superType, const Hash* fileHash); 4104dea8d14fa4089d690e71f1b79d7d3b810c7272Steven Moreland 4204dea8d14fa4089d690e71f1b79d7d3b810c7272Steven Moreland const Hash* getFileHash() const; 43c9410c7e62a33fd7599b2f3e025093a2d171577eAndreas Huber 4414ee6749f12bcd43477fe8110fbec38e15376b40Steven Moreland bool addMethod(Method *method); 45ffa913993fb527b44053c11f139689d3267748ecYifan Hong bool addAllReservedMethods(); 46c9410c7e62a33fd7599b2f3e025093a2d171577eAndreas Huber 47b40ef02ca14e507a5a5b878c90eaac52ffe64fd9Martijn Coenen bool isElidableType() const override; 48a2723d26427f7db19777dfed330047253e7a4e1bAndreas Huber bool isInterface() const override; 49295ad30bf6212c16accc5095601b2a71d44b4c8bAndreas Huber bool isBinder() const override; 50c89340422f53046bfe24ff3e529161f9194120f8Yifan Hong bool isIBase() const { return fqName() == gIBaseFqName; } 5130bb6a869be0f3f82497b7b11c71ec9d47652ed0Steven Moreland std::string typeName() const override; 52c9410c7e62a33fd7599b2f3e025093a2d171577eAndreas Huber 53505316c499a4dbb95f6567e8531fb6f1e74c3dedTimur Iskhakov const Interface* superType() const; 54c9410c7e62a33fd7599b2f3e025093a2d171577eAndreas Huber 55fe95aa243eb53df9cb46ca74192e760d7520b611Yifan Hong // Super type chain to root type. 56fe95aa243eb53df9cb46ca74192e760d7520b611Yifan Hong // First element is superType(). 57fe95aa243eb53df9cb46ca74192e760d7520b611Yifan Hong std::vector<const Interface *> superTypeChain() const; 5810fe0b55e774903fe37b658458053527da8b5a53Yifan Hong // Super type chain to root type, including myself. 5910fe0b55e774903fe37b658458053527da8b5a53Yifan Hong // First element is this. 6010fe0b55e774903fe37b658458053527da8b5a53Yifan Hong std::vector<const Interface *> typeChain() const; 6110fe0b55e774903fe37b658458053527da8b5a53Yifan Hong 6210fe0b55e774903fe37b658458053527da8b5a53Yifan Hong // user defined methods (explicit definition in HAL files) 6310fe0b55e774903fe37b658458053527da8b5a53Yifan Hong const std::vector<Method *> &userDefinedMethods() const; 6410fe0b55e774903fe37b658458053527da8b5a53Yifan Hong // HIDL reserved methods (every interface has these implicitly defined) 6510fe0b55e774903fe37b658458053527da8b5a53Yifan Hong const std::vector<Method *> &hidlReservedMethods() const; 6610fe0b55e774903fe37b658458053527da8b5a53Yifan Hong // the sum of userDefinedMethods() and hidlReservedMethods(). 6710fe0b55e774903fe37b658458053527da8b5a53Yifan Hong std::vector<Method *> methods() const; 6810fe0b55e774903fe37b658458053527da8b5a53Yifan Hong 6910fe0b55e774903fe37b658458053527da8b5a53Yifan Hong // userDefinedMethods() for all super type + methods() 7010fe0b55e774903fe37b658458053527da8b5a53Yifan Hong // The order will be as follows (in the transaction code order): 7110fe0b55e774903fe37b658458053527da8b5a53Yifan Hong // great-great-...-great-grand parent->userDefinedMethods() 7210fe0b55e774903fe37b658458053527da8b5a53Yifan Hong // ... 7310fe0b55e774903fe37b658458053527da8b5a53Yifan Hong // parent->userDefinedMethods() 7410fe0b55e774903fe37b658458053527da8b5a53Yifan Hong // this->userDefinedMethods() 7510fe0b55e774903fe37b658458053527da8b5a53Yifan Hong // this->hidlReservedMethods() 7610fe0b55e774903fe37b658458053527da8b5a53Yifan Hong std::vector<InterfaceAndMethod> allMethodsFromRoot() const; 77881227d860c59471eee31d39946e96ce2daa35d6Andreas Huber 78f1b902d10bd2d71ad7f4769620678101821fd5d1Timur Iskhakov // allMethodsFromRoot for parent 79f1b902d10bd2d71ad7f4769620678101821fd5d1Timur Iskhakov std::vector<InterfaceAndMethod> allSuperMethodsFromRoot() const; 80f1b902d10bd2d71ad7f4769620678101821fd5d1Timur Iskhakov 81eefe4f2405c3cb0f1d164bdb748e5d0ded3624f9Yifan Hong // aliases for corresponding methods in this->fqName() 824078631353d6d34db21c890d1870e796eca6ea38Steven Moreland std::string getBaseName() const; 839a6da7a784bea068b1f3fc3758c9cfc785183693Steven Moreland std::string getAdapterName() const; 84eefe4f2405c3cb0f1d164bdb748e5d0ded3624f9Yifan Hong std::string getProxyName() const; 85eefe4f2405c3cb0f1d164bdb748e5d0ded3624f9Yifan Hong std::string getStubName() const; 86eefe4f2405c3cb0f1d164bdb748e5d0ded3624f9Yifan Hong std::string getPassthroughName() const; 87eefe4f2405c3cb0f1d164bdb748e5d0ded3624f9Yifan Hong std::string getHwName() const; 8851a6509db3078657a2401069c37515504b40c12cYifan Hong FQName getProxyFqName() const; 8951a6509db3078657a2401069c37515504b40c12cYifan Hong FQName getStubFqName() const; 9051a6509db3078657a2401069c37515504b40c12cYifan Hong FQName getPassthroughFqName() const; 91158655a90308d8e5f03dc28b8330d5b0cce038f0Yifan Hong 924c865b72b320a46f326a335cfd326b66b0e10f67Andreas Huber std::string getCppType( 934c865b72b320a46f326a335cfd326b66b0e10f67Andreas Huber StorageMode mode, 944c865b72b320a46f326a335cfd326b66b0e10f67Andreas Huber bool specifyNamespaces) const override; 95881227d860c59471eee31d39946e96ce2daa35d6Andreas Huber 964ed1347cd29e6e07acad368891bb03078c798abaYifan Hong std::string getJavaType(bool forInitializer) const override; 97a588b23323213c525bf34dc0562679195afe611eZhuoyao Zhang std::string getVtsType() const override; 982831d5145675ead9f2fb767bf5fe4ae56b88349fAndreas Huber 99b58f4185934a93fc511c03a8a970b31c5ea0dfcaTimur Iskhakov std::vector<const Reference<Type>*> getReferences() const override; 100b58f4185934a93fc511c03a8a970b31c5ea0dfcaTimur Iskhakov std::vector<const Reference<Type>*> getStrongReferences() const override; 10133431e6cd425c6cd179080442a8616e2baa20aaeTimur Iskhakov 102b58f4185934a93fc511c03a8a970b31c5ea0dfcaTimur Iskhakov std::vector<const ConstantExpression*> getConstantExpressions() const override; 103891a866402345777c7e746cf8d0e4ffd0bd28ca2Timur Iskhakov 104cec46c48853a8c1246656d0095a9faa3fad5c4f9Timur Iskhakov status_t resolveInheritance() override; 105cec46c48853a8c1246656d0095a9faa3fad5c4f9Timur Iskhakov status_t validate() const override; 106cec46c48853a8c1246656d0095a9faa3fad5c4f9Timur Iskhakov status_t validateUniqueNames() const; 107368e46077eb9fbe52242e037a5b9de91693fe70fSteven Moreland status_t validateAnnotations() const; 108cec46c48853a8c1246656d0095a9faa3fad5c4f9Timur Iskhakov 109881227d860c59471eee31d39946e96ce2daa35d6Andreas Huber void emitReaderWriter( 110881227d860c59471eee31d39946e96ce2daa35d6Andreas Huber Formatter &out, 111881227d860c59471eee31d39946e96ce2daa35d6Andreas Huber const std::string &name, 112881227d860c59471eee31d39946e96ce2daa35d6Andreas Huber const std::string &parcelObj, 113881227d860c59471eee31d39946e96ce2daa35d6Andreas Huber bool parcelObjIsPointer, 114881227d860c59471eee31d39946e96ce2daa35d6Andreas Huber bool isReader, 115881227d860c59471eee31d39946e96ce2daa35d6Andreas Huber ErrorMode mode) const override; 116881227d860c59471eee31d39946e96ce2daa35d6Andreas Huber 117368e46077eb9fbe52242e037a5b9de91693fe70fSteven Moreland void emitPackageTypeDeclarations(Formatter& out) const override; 118368e46077eb9fbe52242e037a5b9de91693fe70fSteven Moreland void emitTypeDefinitions(Formatter& out, const std::string& prefix) const override; 119f5cc2f74e86504f7904a0a24e7fcc00fa19cd579Yifan Hong 120ecfb4517ff68c59294f1ddc99513aef7b6dc2f24Howard Chen void getAlignmentAndSize(size_t* align, size_t* size) const override; 1212831d5145675ead9f2fb767bf5fe4ae56b88349fAndreas Huber void emitJavaReaderWriter( 1222831d5145675ead9f2fb767bf5fe4ae56b88349fAndreas Huber Formatter &out, 1232831d5145675ead9f2fb767bf5fe4ae56b88349fAndreas Huber const std::string &parcelObj, 1242831d5145675ead9f2fb767bf5fe4ae56b88349fAndreas Huber const std::string &argName, 1252831d5145675ead9f2fb767bf5fe4ae56b88349fAndreas Huber bool isReader) const override; 1262831d5145675ead9f2fb767bf5fe4ae56b88349fAndreas Huber 127368e46077eb9fbe52242e037a5b9de91693fe70fSteven Moreland void emitVtsAttributeType(Formatter& out) const override; 128864c771ca4ec8a01e31c7c243625b7a5f6316768Zhuoyao Zhang 129368e46077eb9fbe52242e037a5b9de91693fe70fSteven Moreland void emitVtsAttributeDeclaration(Formatter& out) const; 130368e46077eb9fbe52242e037a5b9de91693fe70fSteven Moreland void emitVtsMethodDeclaration(Formatter& out) const; 1315158db484e5ab302368f191d75d5b1334c270e52Zhuoyao Zhang 13269e7c70e72dff0734d542b737ba8bb1178244218Steven Moreland bool hasOnewayMethods() const; 13369e7c70e72dff0734d542b737ba8bb1178244218Steven Moreland 1345dc72fe4f6f1d2c03c75307a9bd80f055f752ed3Timur Iskhakov bool deepIsJavaCompatible(std::unordered_set<const Type*>* visited) const override; 13570a59e1dc3dcf32f791d2dd7966111d4adf32ecaAndreas Huber 136ff5e64ae0c65b80e2baa4a95b9ae9ee894b60080Timur Iskhakov bool isNeverStrongReference() const override; 137ff5e64ae0c65b80e2baa4a95b9ae9ee894b60080Timur Iskhakov 138505316c499a4dbb95f6567e8531fb6f1e74c3dedTimur Iskhakov private: 1390344e61434d7af537cbf33c86b47ec165593f7ddTimur Iskhakov Reference<Type> mSuperType; 140505316c499a4dbb95f6567e8531fb6f1e74c3dedTimur Iskhakov 141505316c499a4dbb95f6567e8531fb6f1e74c3dedTimur Iskhakov std::vector<Method*> mUserMethods; 142505316c499a4dbb95f6567e8531fb6f1e74c3dedTimur Iskhakov std::vector<Method*> mReservedMethods; 143505316c499a4dbb95f6567e8531fb6f1e74c3dedTimur Iskhakov 14404dea8d14fa4089d690e71f1b79d7d3b810c7272Steven Moreland const Hash* mFileHash; 14504dea8d14fa4089d690e71f1b79d7d3b810c7272Steven Moreland 146505316c499a4dbb95f6567e8531fb6f1e74c3dedTimur Iskhakov bool fillPingMethod(Method* method) const; 147505316c499a4dbb95f6567e8531fb6f1e74c3dedTimur Iskhakov bool fillDescriptorChainMethod(Method* method) const; 148505316c499a4dbb95f6567e8531fb6f1e74c3dedTimur Iskhakov bool fillGetDescriptorMethod(Method* method) const; 149505316c499a4dbb95f6567e8531fb6f1e74c3dedTimur Iskhakov bool fillHashChainMethod(Method* method) const; 150505316c499a4dbb95f6567e8531fb6f1e74c3dedTimur Iskhakov bool fillSyspropsChangedMethod(Method* method) const; 151505316c499a4dbb95f6567e8531fb6f1e74c3dedTimur Iskhakov bool fillLinkToDeathMethod(Method* method) const; 152505316c499a4dbb95f6567e8531fb6f1e74c3dedTimur Iskhakov bool fillUnlinkToDeathMethod(Method* method) const; 153505316c499a4dbb95f6567e8531fb6f1e74c3dedTimur Iskhakov bool fillSetHALInstrumentationMethod(Method* method) const; 154505316c499a4dbb95f6567e8531fb6f1e74c3dedTimur Iskhakov bool fillGetDebugInfoMethod(Method* method) const; 155505316c499a4dbb95f6567e8531fb6f1e74c3dedTimur Iskhakov bool fillDebugMethod(Method* method) const; 156c9410c7e62a33fd7599b2f3e025093a2d171577eAndreas Huber 15704dea8d14fa4089d690e71f1b79d7d3b810c7272Steven Moreland void emitDigestChain( 15804dea8d14fa4089d690e71f1b79d7d3b810c7272Steven Moreland Formatter& out, const std::string& prefix, const std::vector<const Interface*>& chain, 15904dea8d14fa4089d690e71f1b79d7d3b810c7272Steven Moreland std::function<std::string(std::unique_ptr<ConstantExpression>)> byteToString) const; 16004dea8d14fa4089d690e71f1b79d7d3b810c7272Steven Moreland 161c9410c7e62a33fd7599b2f3e025093a2d171577eAndreas Huber DISALLOW_COPY_AND_ASSIGN(Interface); 162c9410c7e62a33fd7599b2f3e025093a2d171577eAndreas Huber}; 163c9410c7e62a33fd7599b2f3e025093a2d171577eAndreas Huber 16410fe0b55e774903fe37b658458053527da8b5a53Yifan Hong// An interface / method tuple. 16510fe0b55e774903fe37b658458053527da8b5a53Yifan Hongstruct InterfaceAndMethod { 16610fe0b55e774903fe37b658458053527da8b5a53Yifan Hong InterfaceAndMethod(const Interface *iface, Method *method) 16710fe0b55e774903fe37b658458053527da8b5a53Yifan Hong : mInterface(iface), 16810fe0b55e774903fe37b658458053527da8b5a53Yifan Hong mMethod(method) {} 16910fe0b55e774903fe37b658458053527da8b5a53Yifan Hong Method *method() const { return mMethod; } 17010fe0b55e774903fe37b658458053527da8b5a53Yifan Hong const Interface *interface() const { return mInterface; } 171505316c499a4dbb95f6567e8531fb6f1e74c3dedTimur Iskhakov 172505316c499a4dbb95f6567e8531fb6f1e74c3dedTimur Iskhakov private: 17310fe0b55e774903fe37b658458053527da8b5a53Yifan Hong // do not own these objects. 17410fe0b55e774903fe37b658458053527da8b5a53Yifan Hong const Interface *mInterface; 17510fe0b55e774903fe37b658458053527da8b5a53Yifan Hong Method *mMethod; 17610fe0b55e774903fe37b658458053527da8b5a53Yifan Hong}; 17710fe0b55e774903fe37b658458053527da8b5a53Yifan Hong 178c9410c7e62a33fd7599b2f3e025093a2d171577eAndreas Huber} // namespace android 179c9410c7e62a33fd7599b2f3e025093a2d171577eAndreas Huber 180c9410c7e62a33fd7599b2f3e025093a2d171577eAndreas Huber#endif // INTERFACE_H_ 181c9410c7e62a33fd7599b2f3e025093a2d171577eAndreas Huber 182