blob: becdd16dec3d0fbad07f14616c757dfaf12878d3 [file] [log] [blame]
Andreas Huber1aec3972016-08-26 09:26:32 -07001/*
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 Huberc9410c72016-07-28 12:18:40 -070017#ifndef INTERFACE_H_
18
19#define INTERFACE_H_
20
Steven Moreland6f2f2c02017-08-05 00:32:14 +000021#include <vector>
Timur Iskhakov4b80bc42017-07-28 15:59:06 -070022
Steven Moreland04dea8d2018-02-06 13:11:24 -080023#include <hidl-hash/Hash.h>
24
Timur Iskhakov505316c2017-08-05 03:38:59 +000025#include "Reference.h"
26#include "Scope.h"
27
Andreas Huberc9410c72016-07-28 12:18:40 -070028namespace android {
29
30struct Method;
Yifan Hong10fe0b52016-10-19 14:20:17 -070031struct InterfaceAndMethod;
Andreas Huberc9410c72016-07-28 12:18:40 -070032
33struct Interface : public Scope {
Steven Moreland3ce72142018-02-02 14:31:18 -080034 enum {
35 /////////////////// Flag(s) - DO NOT CHANGE
36 FLAG_ONEWAY = 0x00000001,
37 };
38
Timur Iskhakov565b0132017-09-06 18:07:11 -070039 Interface(const char* localName, const FQName& fullName, const Location& location,
Steven Moreland04dea8d2018-02-06 13:11:24 -080040 Scope* parent, const Reference<Type>& superType, const Hash* fileHash);
41
42 const Hash* getFileHash() const;
Andreas Huberc9410c72016-07-28 12:18:40 -070043
Steven Moreland14ee6742016-10-18 12:58:28 -070044 bool addMethod(Method *method);
Yifan Hongffa91392017-01-31 13:41:23 -080045 bool addAllReservedMethods();
Andreas Huberc9410c72016-07-28 12:18:40 -070046
Martijn Coenenb40ef022017-01-02 15:21:46 +010047 bool isElidableType() const override;
Andreas Hubera2723d22016-07-29 15:36:07 -070048 bool isInterface() const override;
Andreas Huber295ad302016-08-16 11:35:00 -070049 bool isBinder() const override;
Yifan Hongc8934042016-11-17 17:10:52 -080050 bool isIBase() const { return fqName() == gIBaseFqName; }
Steven Moreland30bb6a82016-11-30 09:18:34 -080051 std::string typeName() const override;
Andreas Huberc9410c72016-07-28 12:18:40 -070052
Timur Iskhakov505316c2017-08-05 03:38:59 +000053 const Interface* superType() const;
Andreas Huberc9410c72016-07-28 12:18:40 -070054
Yifan Hongfe95aa22016-10-19 17:26:45 -070055 // Super type chain to root type.
56 // First element is superType().
57 std::vector<const Interface *> superTypeChain() const;
Yifan Hong10fe0b52016-10-19 14:20:17 -070058 // 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 Huber881227d2016-08-02 14:20:21 -070077
Timur Iskhakovf1b902d2017-08-13 20:14:31 -070078 // allMethodsFromRoot for parent
79 std::vector<InterfaceAndMethod> allSuperMethodsFromRoot() const;
80
Yifan Hongeefe4f22017-01-04 15:32:42 -080081 // aliases for corresponding methods in this->fqName()
Steven Moreland40786312016-08-16 10:29:40 -070082 std::string getBaseName() const;
Steven Moreland9a6da7a2017-09-15 16:21:24 -070083 std::string getAdapterName() const;
Yifan Hongeefe4f22017-01-04 15:32:42 -080084 std::string getProxyName() const;
85 std::string getStubName() const;
86 std::string getPassthroughName() const;
87 std::string getHwName() const;
Yifan Hong51a65092017-01-04 15:41:44 -080088 FQName getProxyFqName() const;
89 FQName getStubFqName() const;
90 FQName getPassthroughFqName() const;
Yifan Hong158655a2016-11-08 12:34:07 -080091
Andreas Huber4c865b72016-09-14 15:26:27 -070092 std::string getCppType(
93 StorageMode mode,
Andreas Huber4c865b72016-09-14 15:26:27 -070094 bool specifyNamespaces) const override;
Andreas Huber881227d2016-08-02 14:20:21 -070095
Yifan Hong4ed13472016-11-02 10:44:11 -070096 std::string getJavaType(bool forInitializer) const override;
Zhuoyao Zhanga588b232016-11-10 14:37:35 -080097 std::string getVtsType() const override;
Andreas Huber2831d512016-08-15 09:33:47 -070098
Timur Iskhakovb58f4182017-08-29 15:19:24 -070099 std::vector<const Reference<Type>*> getReferences() const override;
100 std::vector<const Reference<Type>*> getStrongReferences() const override;
Timur Iskhakov33431e62017-08-21 17:31:23 -0700101
Timur Iskhakovb58f4182017-08-29 15:19:24 -0700102 std::vector<const ConstantExpression*> getConstantExpressions() const override;
Timur Iskhakov891a8662017-08-25 21:53:48 -0700103
Timur Iskhakovcec46c42017-08-09 00:22:02 -0700104 status_t resolveInheritance() override;
Timur Iskhakovcec46c42017-08-09 00:22:02 -0700105 status_t validate() const override;
106 status_t validateUniqueNames() const;
107
Andreas Huber881227d2016-08-02 14:20:21 -0700108 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 Moreland4b8f7a12017-11-17 15:39:54 -0800116 status_t emitPackageTypeDeclarations(Formatter& out) const override;
Chih-Hung Hsieh8c90cc52017-08-03 14:51:13 -0700117 status_t emitTypeDefinitions(Formatter& out, const std::string& prefix) const override;
Yifan Hongf5cc2f72017-01-04 18:02:34 -0800118
Howard Chenecfb4512017-11-21 18:28:53 +0800119 void getAlignmentAndSize(size_t* align, size_t* size) const override;
Andreas Huber2831d512016-08-15 09:33:47 -0700120 void emitJavaReaderWriter(
121 Formatter &out,
122 const std::string &parcelObj,
123 const std::string &argName,
124 bool isReader) const override;
125
Zhuoyao Zhang864c7712016-08-16 15:35:28 -0700126 status_t emitVtsAttributeType(Formatter &out) const override;
127
128 status_t emitVtsAttributeDeclaration(Formatter &out) const;
129 status_t emitVtsMethodDeclaration(Formatter &out) const;
Zhuoyao Zhang5158db42016-08-10 10:25:20 -0700130
Steven Moreland69e7c702016-09-09 11:16:32 -0700131 bool hasOnewayMethods() const;
132
Timur Iskhakov5dc72fe2017-09-07 23:13:44 -0700133 bool deepIsJavaCompatible(std::unordered_set<const Type*>* visited) const override;
Andreas Huber70a59e12016-08-16 12:57:01 -0700134
Timur Iskhakovff5e64a2017-09-11 14:56:18 -0700135 bool isNeverStrongReference() const override;
136
Timur Iskhakov505316c2017-08-05 03:38:59 +0000137 private:
Timur Iskhakov0344e612017-08-25 12:57:09 -0700138 Reference<Type> mSuperType;
Timur Iskhakov505316c2017-08-05 03:38:59 +0000139
140 std::vector<Method*> mUserMethods;
141 std::vector<Method*> mReservedMethods;
142
Steven Moreland04dea8d2018-02-06 13:11:24 -0800143 const Hash* mFileHash;
144
Timur Iskhakov505316c2017-08-05 03:38:59 +0000145 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 Huberc9410c72016-07-28 12:18:40 -0700155
Steven Moreland04dea8d2018-02-06 13:11:24 -0800156 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 Huberc9410c72016-07-28 12:18:40 -0700160 DISALLOW_COPY_AND_ASSIGN(Interface);
161};
162
Yifan Hong10fe0b52016-10-19 14:20:17 -0700163// An interface / method tuple.
164struct 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 Iskhakov505316c2017-08-05 03:38:59 +0000170
171 private:
Yifan Hong10fe0b52016-10-19 14:20:17 -0700172 // do not own these objects.
173 const Interface *mInterface;
174 Method *mMethod;
175};
176
Andreas Huberc9410c72016-07-28 12:18:40 -0700177} // namespace android
178
179#endif // INTERFACE_H_
180