Andreas Huber | 1aec397 | 2016-08-26 09:26:32 -0700 | [diff] [blame] | 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 | |
Andreas Huber | c9410c7 | 2016-07-28 12:18:40 -0700 | [diff] [blame] | 17 | #ifndef INTERFACE_H_ |
| 18 | |
| 19 | #define INTERFACE_H_ |
| 20 | |
Steven Moreland | 6f2f2c0 | 2017-08-05 00:32:14 +0000 | [diff] [blame] | 21 | #include <vector> |
Timur Iskhakov | 4b80bc4 | 2017-07-28 15:59:06 -0700 | [diff] [blame] | 22 | |
Steven Moreland | 04dea8d | 2018-02-06 13:11:24 -0800 | [diff] [blame] | 23 | #include <hidl-hash/Hash.h> |
| 24 | |
Timur Iskhakov | 505316c | 2017-08-05 03:38:59 +0000 | [diff] [blame] | 25 | #include "Reference.h" |
| 26 | #include "Scope.h" |
| 27 | |
Andreas Huber | c9410c7 | 2016-07-28 12:18:40 -0700 | [diff] [blame] | 28 | namespace android { |
| 29 | |
| 30 | struct Method; |
Yifan Hong | 10fe0b5 | 2016-10-19 14:20:17 -0700 | [diff] [blame] | 31 | struct InterfaceAndMethod; |
Andreas Huber | c9410c7 | 2016-07-28 12:18:40 -0700 | [diff] [blame] | 32 | |
| 33 | struct Interface : public Scope { |
Steven Moreland | 3ce7214 | 2018-02-02 14:31:18 -0800 | [diff] [blame] | 34 | enum { |
| 35 | /////////////////// Flag(s) - DO NOT CHANGE |
| 36 | FLAG_ONEWAY = 0x00000001, |
| 37 | }; |
| 38 | |
Timur Iskhakov | 565b013 | 2017-09-06 18:07:11 -0700 | [diff] [blame] | 39 | Interface(const char* localName, const FQName& fullName, const Location& location, |
Steven Moreland | 04dea8d | 2018-02-06 13:11:24 -0800 | [diff] [blame] | 40 | Scope* parent, const Reference<Type>& superType, const Hash* fileHash); |
| 41 | |
| 42 | const Hash* getFileHash() const; |
Andreas Huber | c9410c7 | 2016-07-28 12:18:40 -0700 | [diff] [blame] | 43 | |
Steven Moreland | 14ee674 | 2016-10-18 12:58:28 -0700 | [diff] [blame] | 44 | bool addMethod(Method *method); |
Yifan Hong | ffa9139 | 2017-01-31 13:41:23 -0800 | [diff] [blame] | 45 | bool addAllReservedMethods(); |
Andreas Huber | c9410c7 | 2016-07-28 12:18:40 -0700 | [diff] [blame] | 46 | |
Martijn Coenen | b40ef02 | 2017-01-02 15:21:46 +0100 | [diff] [blame] | 47 | bool isElidableType() const override; |
Andreas Huber | a2723d2 | 2016-07-29 15:36:07 -0700 | [diff] [blame] | 48 | bool isInterface() const override; |
Andreas Huber | 295ad30 | 2016-08-16 11:35:00 -0700 | [diff] [blame] | 49 | bool isBinder() const override; |
Yifan Hong | c893404 | 2016-11-17 17:10:52 -0800 | [diff] [blame] | 50 | bool isIBase() const { return fqName() == gIBaseFqName; } |
Steven Moreland | 30bb6a8 | 2016-11-30 09:18:34 -0800 | [diff] [blame] | 51 | std::string typeName() const override; |
Andreas Huber | c9410c7 | 2016-07-28 12:18:40 -0700 | [diff] [blame] | 52 | |
Timur Iskhakov | 505316c | 2017-08-05 03:38:59 +0000 | [diff] [blame] | 53 | const Interface* superType() const; |
Andreas Huber | c9410c7 | 2016-07-28 12:18:40 -0700 | [diff] [blame] | 54 | |
Yifan Hong | fe95aa2 | 2016-10-19 17:26:45 -0700 | [diff] [blame] | 55 | // Super type chain to root type. |
| 56 | // First element is superType(). |
| 57 | std::vector<const Interface *> superTypeChain() const; |
Yifan Hong | 10fe0b5 | 2016-10-19 14:20:17 -0700 | [diff] [blame] | 58 | // Super type chain to root type, including myself. |
| 59 | // First element is this. |
| 60 | std::vector<const Interface *> typeChain() const; |
| 61 | |
| 62 | // user defined methods (explicit definition in HAL files) |
| 63 | const std::vector<Method *> &userDefinedMethods() const; |
| 64 | // HIDL reserved methods (every interface has these implicitly defined) |
| 65 | const std::vector<Method *> &hidlReservedMethods() const; |
| 66 | // the sum of userDefinedMethods() and hidlReservedMethods(). |
| 67 | std::vector<Method *> methods() const; |
| 68 | |
| 69 | // userDefinedMethods() for all super type + methods() |
| 70 | // The order will be as follows (in the transaction code order): |
| 71 | // great-great-...-great-grand parent->userDefinedMethods() |
| 72 | // ... |
| 73 | // parent->userDefinedMethods() |
| 74 | // this->userDefinedMethods() |
| 75 | // this->hidlReservedMethods() |
| 76 | std::vector<InterfaceAndMethod> allMethodsFromRoot() const; |
Andreas Huber | 881227d | 2016-08-02 14:20:21 -0700 | [diff] [blame] | 77 | |
Timur Iskhakov | f1b902d | 2017-08-13 20:14:31 -0700 | [diff] [blame] | 78 | // allMethodsFromRoot for parent |
| 79 | std::vector<InterfaceAndMethod> allSuperMethodsFromRoot() const; |
| 80 | |
Yifan Hong | eefe4f2 | 2017-01-04 15:32:42 -0800 | [diff] [blame] | 81 | // aliases for corresponding methods in this->fqName() |
Steven Moreland | 4078631 | 2016-08-16 10:29:40 -0700 | [diff] [blame] | 82 | std::string getBaseName() const; |
Steven Moreland | 9a6da7a | 2017-09-15 16:21:24 -0700 | [diff] [blame] | 83 | std::string getAdapterName() const; |
Yifan Hong | eefe4f2 | 2017-01-04 15:32:42 -0800 | [diff] [blame] | 84 | std::string getProxyName() const; |
| 85 | std::string getStubName() const; |
| 86 | std::string getPassthroughName() const; |
| 87 | std::string getHwName() const; |
Yifan Hong | 51a6509 | 2017-01-04 15:41:44 -0800 | [diff] [blame] | 88 | FQName getProxyFqName() const; |
| 89 | FQName getStubFqName() const; |
| 90 | FQName getPassthroughFqName() const; |
Yifan Hong | 158655a | 2016-11-08 12:34:07 -0800 | [diff] [blame] | 91 | |
Andreas Huber | 4c865b7 | 2016-09-14 15:26:27 -0700 | [diff] [blame] | 92 | std::string getCppType( |
| 93 | StorageMode mode, |
Andreas Huber | 4c865b7 | 2016-09-14 15:26:27 -0700 | [diff] [blame] | 94 | bool specifyNamespaces) const override; |
Andreas Huber | 881227d | 2016-08-02 14:20:21 -0700 | [diff] [blame] | 95 | |
Yifan Hong | 4ed1347 | 2016-11-02 10:44:11 -0700 | [diff] [blame] | 96 | std::string getJavaType(bool forInitializer) const override; |
Zhuoyao Zhang | a588b23 | 2016-11-10 14:37:35 -0800 | [diff] [blame] | 97 | std::string getVtsType() const override; |
Andreas Huber | 2831d51 | 2016-08-15 09:33:47 -0700 | [diff] [blame] | 98 | |
Timur Iskhakov | b58f418 | 2017-08-29 15:19:24 -0700 | [diff] [blame] | 99 | std::vector<const Reference<Type>*> getReferences() const override; |
| 100 | std::vector<const Reference<Type>*> getStrongReferences() const override; |
Timur Iskhakov | 33431e6 | 2017-08-21 17:31:23 -0700 | [diff] [blame] | 101 | |
Timur Iskhakov | b58f418 | 2017-08-29 15:19:24 -0700 | [diff] [blame] | 102 | std::vector<const ConstantExpression*> getConstantExpressions() const override; |
Timur Iskhakov | 891a866 | 2017-08-25 21:53:48 -0700 | [diff] [blame] | 103 | |
Timur Iskhakov | cec46c4 | 2017-08-09 00:22:02 -0700 | [diff] [blame] | 104 | status_t resolveInheritance() override; |
Timur Iskhakov | cec46c4 | 2017-08-09 00:22:02 -0700 | [diff] [blame] | 105 | status_t validate() const override; |
| 106 | status_t validateUniqueNames() const; |
| 107 | |
Andreas Huber | 881227d | 2016-08-02 14:20:21 -0700 | [diff] [blame] | 108 | void emitReaderWriter( |
| 109 | Formatter &out, |
| 110 | const std::string &name, |
| 111 | const std::string &parcelObj, |
| 112 | bool parcelObjIsPointer, |
| 113 | bool isReader, |
| 114 | ErrorMode mode) const override; |
| 115 | |
Steven Moreland | 4b8f7a1 | 2017-11-17 15:39:54 -0800 | [diff] [blame] | 116 | status_t emitPackageTypeDeclarations(Formatter& out) const override; |
Chih-Hung Hsieh | 8c90cc5 | 2017-08-03 14:51:13 -0700 | [diff] [blame] | 117 | status_t emitTypeDefinitions(Formatter& out, const std::string& prefix) const override; |
Yifan Hong | f5cc2f7 | 2017-01-04 18:02:34 -0800 | [diff] [blame] | 118 | |
Howard Chen | ecfb451 | 2017-11-21 18:28:53 +0800 | [diff] [blame] | 119 | void getAlignmentAndSize(size_t* align, size_t* size) const override; |
Andreas Huber | 2831d51 | 2016-08-15 09:33:47 -0700 | [diff] [blame] | 120 | void emitJavaReaderWriter( |
| 121 | Formatter &out, |
| 122 | const std::string &parcelObj, |
| 123 | const std::string &argName, |
| 124 | bool isReader) const override; |
| 125 | |
Zhuoyao Zhang | 864c771 | 2016-08-16 15:35:28 -0700 | [diff] [blame] | 126 | status_t emitVtsAttributeType(Formatter &out) const override; |
| 127 | |
| 128 | status_t emitVtsAttributeDeclaration(Formatter &out) const; |
| 129 | status_t emitVtsMethodDeclaration(Formatter &out) const; |
Zhuoyao Zhang | 5158db4 | 2016-08-10 10:25:20 -0700 | [diff] [blame] | 130 | |
Steven Moreland | 69e7c70 | 2016-09-09 11:16:32 -0700 | [diff] [blame] | 131 | bool hasOnewayMethods() const; |
| 132 | |
Timur Iskhakov | 5dc72fe | 2017-09-07 23:13:44 -0700 | [diff] [blame] | 133 | bool deepIsJavaCompatible(std::unordered_set<const Type*>* visited) const override; |
Andreas Huber | 70a59e1 | 2016-08-16 12:57:01 -0700 | [diff] [blame] | 134 | |
Timur Iskhakov | ff5e64a | 2017-09-11 14:56:18 -0700 | [diff] [blame] | 135 | bool isNeverStrongReference() const override; |
| 136 | |
Timur Iskhakov | 505316c | 2017-08-05 03:38:59 +0000 | [diff] [blame] | 137 | private: |
Timur Iskhakov | 0344e61 | 2017-08-25 12:57:09 -0700 | [diff] [blame] | 138 | Reference<Type> mSuperType; |
Timur Iskhakov | 505316c | 2017-08-05 03:38:59 +0000 | [diff] [blame] | 139 | |
| 140 | std::vector<Method*> mUserMethods; |
| 141 | std::vector<Method*> mReservedMethods; |
| 142 | |
Steven Moreland | 04dea8d | 2018-02-06 13:11:24 -0800 | [diff] [blame] | 143 | const Hash* mFileHash; |
| 144 | |
Timur Iskhakov | 505316c | 2017-08-05 03:38:59 +0000 | [diff] [blame] | 145 | bool fillPingMethod(Method* method) const; |
| 146 | bool fillDescriptorChainMethod(Method* method) const; |
| 147 | bool fillGetDescriptorMethod(Method* method) const; |
| 148 | bool fillHashChainMethod(Method* method) const; |
| 149 | bool fillSyspropsChangedMethod(Method* method) const; |
| 150 | bool fillLinkToDeathMethod(Method* method) const; |
| 151 | bool fillUnlinkToDeathMethod(Method* method) const; |
| 152 | bool fillSetHALInstrumentationMethod(Method* method) const; |
| 153 | bool fillGetDebugInfoMethod(Method* method) const; |
| 154 | bool fillDebugMethod(Method* method) const; |
Andreas Huber | c9410c7 | 2016-07-28 12:18:40 -0700 | [diff] [blame] | 155 | |
Steven Moreland | 04dea8d | 2018-02-06 13:11:24 -0800 | [diff] [blame] | 156 | void emitDigestChain( |
| 157 | Formatter& out, const std::string& prefix, const std::vector<const Interface*>& chain, |
| 158 | std::function<std::string(std::unique_ptr<ConstantExpression>)> byteToString) const; |
| 159 | |
Andreas Huber | c9410c7 | 2016-07-28 12:18:40 -0700 | [diff] [blame] | 160 | DISALLOW_COPY_AND_ASSIGN(Interface); |
| 161 | }; |
| 162 | |
Yifan Hong | 10fe0b5 | 2016-10-19 14:20:17 -0700 | [diff] [blame] | 163 | // An interface / method tuple. |
| 164 | struct InterfaceAndMethod { |
| 165 | InterfaceAndMethod(const Interface *iface, Method *method) |
| 166 | : mInterface(iface), |
| 167 | mMethod(method) {} |
| 168 | Method *method() const { return mMethod; } |
| 169 | const Interface *interface() const { return mInterface; } |
Timur Iskhakov | 505316c | 2017-08-05 03:38:59 +0000 | [diff] [blame] | 170 | |
| 171 | private: |
Yifan Hong | 10fe0b5 | 2016-10-19 14:20:17 -0700 | [diff] [blame] | 172 | // do not own these objects. |
| 173 | const Interface *mInterface; |
| 174 | Method *mMethod; |
| 175 | }; |
| 176 | |
Andreas Huber | c9410c7 | 2016-07-28 12:18:40 -0700 | [diff] [blame] | 177 | } // namespace android |
| 178 | |
| 179 | #endif // INTERFACE_H_ |
| 180 | |