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 | |
Timur Iskhakov | 505316c | 2017-08-05 03:38:59 +0000 | [diff] [blame] | 23 | #include "Reference.h" |
| 24 | #include "Scope.h" |
| 25 | |
Andreas Huber | c9410c7 | 2016-07-28 12:18:40 -0700 | [diff] [blame] | 26 | namespace android { |
| 27 | |
| 28 | struct Method; |
Yifan Hong | 10fe0b5 | 2016-10-19 14:20:17 -0700 | [diff] [blame] | 29 | struct InterfaceAndMethod; |
Andreas Huber | c9410c7 | 2016-07-28 12:18:40 -0700 | [diff] [blame] | 30 | |
| 31 | struct Interface : public Scope { |
Timur Iskhakov | 505316c | 2017-08-05 03:38:59 +0000 | [diff] [blame] | 32 | Interface(const char* localName, const Location& location, Scope* parent, |
Timur Iskhakov | 0344e61 | 2017-08-25 12:57:09 -0700 | [diff] [blame] | 33 | const Reference<Type>& superType); |
Andreas Huber | c9410c7 | 2016-07-28 12:18:40 -0700 | [diff] [blame] | 34 | |
Steven Moreland | 14ee674 | 2016-10-18 12:58:28 -0700 | [diff] [blame] | 35 | bool addMethod(Method *method); |
Yifan Hong | ffa9139 | 2017-01-31 13:41:23 -0800 | [diff] [blame] | 36 | bool addAllReservedMethods(); |
Andreas Huber | c9410c7 | 2016-07-28 12:18:40 -0700 | [diff] [blame] | 37 | |
Martijn Coenen | b40ef02 | 2017-01-02 15:21:46 +0100 | [diff] [blame] | 38 | bool isElidableType() const override; |
Andreas Huber | a2723d2 | 2016-07-29 15:36:07 -0700 | [diff] [blame] | 39 | bool isInterface() const override; |
Andreas Huber | 295ad30 | 2016-08-16 11:35:00 -0700 | [diff] [blame] | 40 | bool isBinder() const override; |
Yifan Hong | c893404 | 2016-11-17 17:10:52 -0800 | [diff] [blame] | 41 | bool isIBase() const { return fqName() == gIBaseFqName; } |
Steven Moreland | 30bb6a8 | 2016-11-30 09:18:34 -0800 | [diff] [blame] | 42 | std::string typeName() const override; |
Andreas Huber | c9410c7 | 2016-07-28 12:18:40 -0700 | [diff] [blame] | 43 | |
Timur Iskhakov | 505316c | 2017-08-05 03:38:59 +0000 | [diff] [blame] | 44 | const Interface* superType() const; |
Andreas Huber | c9410c7 | 2016-07-28 12:18:40 -0700 | [diff] [blame] | 45 | |
Yifan Hong | fe95aa2 | 2016-10-19 17:26:45 -0700 | [diff] [blame] | 46 | // Super type chain to root type. |
| 47 | // First element is superType(). |
| 48 | std::vector<const Interface *> superTypeChain() const; |
Yifan Hong | 10fe0b5 | 2016-10-19 14:20:17 -0700 | [diff] [blame] | 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; |
Andreas Huber | 881227d | 2016-08-02 14:20:21 -0700 | [diff] [blame] | 68 | |
Timur Iskhakov | f1b902d | 2017-08-13 20:14:31 -0700 | [diff] [blame] | 69 | // allMethodsFromRoot for parent |
| 70 | std::vector<InterfaceAndMethod> allSuperMethodsFromRoot() const; |
| 71 | |
Yifan Hong | eefe4f2 | 2017-01-04 15:32:42 -0800 | [diff] [blame] | 72 | // aliases for corresponding methods in this->fqName() |
Steven Moreland | 4078631 | 2016-08-16 10:29:40 -0700 | [diff] [blame] | 73 | std::string getBaseName() const; |
Yifan Hong | eefe4f2 | 2017-01-04 15:32:42 -0800 | [diff] [blame] | 74 | std::string getProxyName() const; |
| 75 | std::string getStubName() const; |
| 76 | std::string getPassthroughName() const; |
| 77 | std::string getHwName() const; |
Yifan Hong | 51a6509 | 2017-01-04 15:41:44 -0800 | [diff] [blame] | 78 | FQName getProxyFqName() const; |
| 79 | FQName getStubFqName() const; |
| 80 | FQName getPassthroughFqName() const; |
Yifan Hong | 158655a | 2016-11-08 12:34:07 -0800 | [diff] [blame] | 81 | |
Andreas Huber | 4c865b7 | 2016-09-14 15:26:27 -0700 | [diff] [blame] | 82 | std::string getCppType( |
| 83 | StorageMode mode, |
Andreas Huber | 4c865b7 | 2016-09-14 15:26:27 -0700 | [diff] [blame] | 84 | bool specifyNamespaces) const override; |
Andreas Huber | 881227d | 2016-08-02 14:20:21 -0700 | [diff] [blame] | 85 | |
Yifan Hong | 4ed1347 | 2016-11-02 10:44:11 -0700 | [diff] [blame] | 86 | std::string getJavaType(bool forInitializer) const override; |
Zhuoyao Zhang | a588b23 | 2016-11-10 14:37:35 -0800 | [diff] [blame] | 87 | std::string getVtsType() const override; |
Andreas Huber | 2831d51 | 2016-08-15 09:33:47 -0700 | [diff] [blame] | 88 | |
Timur Iskhakov | 33431e6 | 2017-08-21 17:31:23 -0700 | [diff] [blame] | 89 | std::vector<Reference<Type>> getReferences() const override; |
| 90 | |
Timur Iskhakov | 891a866 | 2017-08-25 21:53:48 -0700 | [diff] [blame] | 91 | std::vector<ConstantExpression*> getConstantExpressions() const override; |
| 92 | |
Timur Iskhakov | cec46c4 | 2017-08-09 00:22:02 -0700 | [diff] [blame] | 93 | status_t resolveInheritance() override; |
Timur Iskhakov | cec46c4 | 2017-08-09 00:22:02 -0700 | [diff] [blame] | 94 | status_t validate() const override; |
| 95 | status_t validateUniqueNames() const; |
| 96 | |
Andreas Huber | 881227d | 2016-08-02 14:20:21 -0700 | [diff] [blame] | 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 | |
Yifan Hong | f5cc2f7 | 2017-01-04 18:02:34 -0800 | [diff] [blame] | 105 | status_t emitGlobalTypeDeclarations(Formatter &out) const override; |
Chih-Hung Hsieh | 8c90cc5 | 2017-08-03 14:51:13 -0700 | [diff] [blame] | 106 | status_t emitTypeDefinitions(Formatter& out, const std::string& prefix) const override; |
Yifan Hong | f5cc2f7 | 2017-01-04 18:02:34 -0800 | [diff] [blame] | 107 | |
Andreas Huber | 2831d51 | 2016-08-15 09:33:47 -0700 | [diff] [blame] | 108 | void emitJavaReaderWriter( |
| 109 | Formatter &out, |
| 110 | const std::string &parcelObj, |
| 111 | const std::string &argName, |
| 112 | bool isReader) const override; |
| 113 | |
Zhuoyao Zhang | 864c771 | 2016-08-16 15:35:28 -0700 | [diff] [blame] | 114 | status_t emitVtsAttributeType(Formatter &out) const override; |
| 115 | |
| 116 | status_t emitVtsAttributeDeclaration(Formatter &out) const; |
| 117 | status_t emitVtsMethodDeclaration(Formatter &out) const; |
Zhuoyao Zhang | 5158db4 | 2016-08-10 10:25:20 -0700 | [diff] [blame] | 118 | |
Steven Moreland | 69e7c70 | 2016-09-09 11:16:32 -0700 | [diff] [blame] | 119 | bool hasOnewayMethods() const; |
| 120 | |
Andreas Huber | 70a59e1 | 2016-08-16 12:57:01 -0700 | [diff] [blame] | 121 | bool isJavaCompatible() const override; |
| 122 | |
Timur Iskhakov | 505316c | 2017-08-05 03:38:59 +0000 | [diff] [blame] | 123 | private: |
Timur Iskhakov | 0344e61 | 2017-08-25 12:57:09 -0700 | [diff] [blame] | 124 | Reference<Type> mSuperType; |
Timur Iskhakov | 505316c | 2017-08-05 03:38:59 +0000 | [diff] [blame] | 125 | |
| 126 | std::vector<Method*> mUserMethods; |
| 127 | std::vector<Method*> mReservedMethods; |
| 128 | |
Andreas Huber | ea081b3 | 2016-08-17 15:57:47 -0700 | [diff] [blame] | 129 | mutable bool mIsJavaCompatibleInProgress; |
Timur Iskhakov | 505316c | 2017-08-05 03:38:59 +0000 | [diff] [blame] | 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; |
Andreas Huber | c9410c7 | 2016-07-28 12:18:40 -0700 | [diff] [blame] | 141 | |
| 142 | DISALLOW_COPY_AND_ASSIGN(Interface); |
| 143 | }; |
| 144 | |
Yifan Hong | 10fe0b5 | 2016-10-19 14:20:17 -0700 | [diff] [blame] | 145 | // An interface / method tuple. |
| 146 | struct 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; } |
Timur Iskhakov | 505316c | 2017-08-05 03:38:59 +0000 | [diff] [blame] | 152 | |
| 153 | private: |
Yifan Hong | 10fe0b5 | 2016-10-19 14:20:17 -0700 | [diff] [blame] | 154 | // do not own these objects. |
| 155 | const Interface *mInterface; |
| 156 | Method *mMethod; |
| 157 | }; |
| 158 | |
Andreas Huber | c9410c7 | 2016-07-28 12:18:40 -0700 | [diff] [blame] | 159 | } // namespace android |
| 160 | |
| 161 | #endif // INTERFACE_H_ |
| 162 | |