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 | |
| 21 | #include "Scope.h" |
Yifan Hong | 10fe0b5 | 2016-10-19 14:20:17 -0700 | [diff] [blame] | 22 | #include <vector> |
Andreas Huber | c9410c7 | 2016-07-28 12:18:40 -0700 | [diff] [blame] | 23 | |
Andreas Huber | c9410c7 | 2016-07-28 12:18:40 -0700 | [diff] [blame] | 24 | namespace android { |
| 25 | |
| 26 | struct Method; |
Yifan Hong | 10fe0b5 | 2016-10-19 14:20:17 -0700 | [diff] [blame] | 27 | struct InterfaceAndMethod; |
Andreas Huber | c9410c7 | 2016-07-28 12:18:40 -0700 | [diff] [blame] | 28 | |
| 29 | struct Interface : public Scope { |
Yifan Hong | a4b53d0 | 2016-10-31 17:29:10 -0700 | [diff] [blame] | 30 | Interface(const char *localName, const Location &location, Interface *super); |
Andreas Huber | c9410c7 | 2016-07-28 12:18:40 -0700 | [diff] [blame] | 31 | |
Steven Moreland | 14ee674 | 2016-10-18 12:58:28 -0700 | [diff] [blame] | 32 | bool addMethod(Method *method); |
Yifan Hong | ffa9139 | 2017-01-31 13:41:23 -0800 | [diff] [blame] | 33 | bool addAllReservedMethods(); |
Andreas Huber | c9410c7 | 2016-07-28 12:18:40 -0700 | [diff] [blame] | 34 | |
Martijn Coenen | b40ef02 | 2017-01-02 15:21:46 +0100 | [diff] [blame] | 35 | bool isElidableType() const override; |
Andreas Huber | a2723d2 | 2016-07-29 15:36:07 -0700 | [diff] [blame] | 36 | bool isInterface() const override; |
Andreas Huber | 295ad30 | 2016-08-16 11:35:00 -0700 | [diff] [blame] | 37 | bool isBinder() const override; |
Yifan Hong | fe95aa2 | 2016-10-19 17:26:45 -0700 | [diff] [blame] | 38 | bool isRootType() const { return mSuperType == nullptr; } |
Yifan Hong | c893404 | 2016-11-17 17:10:52 -0800 | [diff] [blame] | 39 | bool isIBase() const { return fqName() == gIBaseFqName; } |
Steven Moreland | 30bb6a8 | 2016-11-30 09:18:34 -0800 | [diff] [blame] | 40 | std::string typeName() const override; |
Andreas Huber | c9410c7 | 2016-07-28 12:18:40 -0700 | [diff] [blame] | 41 | |
Andreas Huber | 6cb08cf | 2016-08-03 15:44:51 -0700 | [diff] [blame] | 42 | const Interface *superType() 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 | Method *lookupMethod(std::string name) const; |
Yifan Hong | fe95aa2 | 2016-10-19 17:26:45 -0700 | [diff] [blame] | 45 | // Super type chain to root type. |
| 46 | // First element is superType(). |
| 47 | std::vector<const Interface *> superTypeChain() const; |
Yifan Hong | 10fe0b5 | 2016-10-19 14:20:17 -0700 | [diff] [blame] | 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; |
Andreas Huber | 881227d | 2016-08-02 14:20:21 -0700 | [diff] [blame] | 67 | |
Yifan Hong | eefe4f2 | 2017-01-04 15:32:42 -0800 | [diff] [blame] | 68 | // aliases for corresponding methods in this->fqName() |
Steven Moreland | 4078631 | 2016-08-16 10:29:40 -0700 | [diff] [blame] | 69 | std::string getBaseName() const; |
Yifan Hong | eefe4f2 | 2017-01-04 15:32:42 -0800 | [diff] [blame] | 70 | std::string getProxyName() const; |
| 71 | std::string getStubName() const; |
| 72 | std::string getPassthroughName() const; |
| 73 | std::string getHwName() const; |
Yifan Hong | 51a6509 | 2017-01-04 15:41:44 -0800 | [diff] [blame] | 74 | FQName getProxyFqName() const; |
| 75 | FQName getStubFqName() const; |
| 76 | FQName getPassthroughFqName() const; |
Yifan Hong | 158655a | 2016-11-08 12:34:07 -0800 | [diff] [blame] | 77 | |
Andreas Huber | 4c865b7 | 2016-09-14 15:26:27 -0700 | [diff] [blame] | 78 | std::string getCppType( |
| 79 | StorageMode mode, |
Andreas Huber | 4c865b7 | 2016-09-14 15:26:27 -0700 | [diff] [blame] | 80 | bool specifyNamespaces) const override; |
Andreas Huber | 881227d | 2016-08-02 14:20:21 -0700 | [diff] [blame] | 81 | |
Yifan Hong | 4ed1347 | 2016-11-02 10:44:11 -0700 | [diff] [blame] | 82 | std::string getJavaType(bool forInitializer) const override; |
Zhuoyao Zhang | a588b23 | 2016-11-10 14:37:35 -0800 | [diff] [blame] | 83 | std::string getVtsType() const override; |
Andreas Huber | 2831d51 | 2016-08-15 09:33:47 -0700 | [diff] [blame] | 84 | |
Andreas Huber | 881227d | 2016-08-02 14:20:21 -0700 | [diff] [blame] | 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 | |
Yifan Hong | f5cc2f7 | 2017-01-04 18:02:34 -0800 | [diff] [blame] | 93 | status_t emitGlobalTypeDeclarations(Formatter &out) const override; |
| 94 | status_t emitTypeDefinitions( |
| 95 | Formatter &out, const std::string prefix) const override; |
| 96 | |
Andreas Huber | 2831d51 | 2016-08-15 09:33:47 -0700 | [diff] [blame] | 97 | void emitJavaReaderWriter( |
| 98 | Formatter &out, |
| 99 | const std::string &parcelObj, |
| 100 | const std::string &argName, |
| 101 | bool isReader) const override; |
| 102 | |
Zhuoyao Zhang | 864c771 | 2016-08-16 15:35:28 -0700 | [diff] [blame] | 103 | status_t emitVtsAttributeType(Formatter &out) const override; |
| 104 | |
| 105 | status_t emitVtsAttributeDeclaration(Formatter &out) const; |
| 106 | status_t emitVtsMethodDeclaration(Formatter &out) const; |
Zhuoyao Zhang | 5158db4 | 2016-08-10 10:25:20 -0700 | [diff] [blame] | 107 | |
Steven Moreland | 69e7c70 | 2016-09-09 11:16:32 -0700 | [diff] [blame] | 108 | bool hasOnewayMethods() const; |
| 109 | |
Andreas Huber | 70a59e1 | 2016-08-16 12:57:01 -0700 | [diff] [blame] | 110 | bool isJavaCompatible() const override; |
| 111 | |
Andreas Huber | c9410c7 | 2016-07-28 12:18:40 -0700 | [diff] [blame] | 112 | private: |
Andreas Huber | 6cb08cf | 2016-08-03 15:44:51 -0700 | [diff] [blame] | 113 | Interface *mSuperType; |
Yifan Hong | 10fe0b5 | 2016-10-19 14:20:17 -0700 | [diff] [blame] | 114 | std::vector<Method *> mUserMethods; |
| 115 | std::vector<Method *> mReservedMethods; |
Andreas Huber | ea081b3 | 2016-08-17 15:57:47 -0700 | [diff] [blame] | 116 | mutable bool mIsJavaCompatibleInProgress; |
Steven Moreland | 424a948 | 2017-02-13 19:20:40 -0800 | [diff] [blame] | 117 | bool fillPingMethod(Method *method) const; |
Yifan Hong | ffa9139 | 2017-01-31 13:41:23 -0800 | [diff] [blame] | 118 | bool fillDescriptorChainMethod(Method *method) const; |
| 119 | bool fillGetDescriptorMethod(Method *method) const; |
| 120 | bool fillSyspropsChangedMethod(Method *method) const; |
| 121 | bool fillLinkToDeathMethod(Method *method) const; |
| 122 | bool fillUnlinkToDeathMethod(Method *method) const; |
| 123 | bool fillSetHALInstrumentationMethod(Method *method) const; |
Yifan Hong | bcffce2 | 2017-02-01 15:52:06 -0800 | [diff] [blame] | 124 | bool fillGetDebugInfoMethod(Method *method) const; |
Andreas Huber | 37065d6 | 2017-02-07 14:36:54 -0800 | [diff] [blame] | 125 | bool fillDebugMethod(Method *method) const; |
Andreas Huber | c9410c7 | 2016-07-28 12:18:40 -0700 | [diff] [blame] | 126 | |
| 127 | DISALLOW_COPY_AND_ASSIGN(Interface); |
| 128 | }; |
| 129 | |
Yifan Hong | 10fe0b5 | 2016-10-19 14:20:17 -0700 | [diff] [blame] | 130 | // An interface / method tuple. |
| 131 | struct InterfaceAndMethod { |
| 132 | InterfaceAndMethod(const Interface *iface, Method *method) |
| 133 | : mInterface(iface), |
| 134 | mMethod(method) {} |
| 135 | Method *method() const { return mMethod; } |
| 136 | const Interface *interface() const { return mInterface; } |
| 137 | private: |
| 138 | // do not own these objects. |
| 139 | const Interface *mInterface; |
| 140 | Method *mMethod; |
| 141 | }; |
| 142 | |
Andreas Huber | c9410c7 | 2016-07-28 12:18:40 -0700 | [diff] [blame] | 143 | } // namespace android |
| 144 | |
| 145 | #endif // INTERFACE_H_ |
| 146 | |