blob: 0c94c0cd2a7178187855b7d89afcb634372aec1d [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;
Steven Moreland6ec9eb92018-02-16 14:21:49 -0800107 status_t validateAnnotations() const;
Timur Iskhakovcec46c42017-08-09 00:22:02 -0700108
Andreas Huber881227d2016-08-02 14:20:21 -0700109 void emitReaderWriter(
110 Formatter &out,
111 const std::string &name,
112 const std::string &parcelObj,
113 bool parcelObjIsPointer,
114 bool isReader,
115 ErrorMode mode) const override;
116
Steven Moreland6ec9eb92018-02-16 14:21:49 -0800117 void emitPackageTypeDeclarations(Formatter& out) const override;
118 void emitTypeDefinitions(Formatter& out, const std::string& prefix) const override;
Yifan Hongf5cc2f72017-01-04 18:02:34 -0800119
Howard Chenecfb4512017-11-21 18:28:53 +0800120 void getAlignmentAndSize(size_t* align, size_t* size) const override;
Andreas Huber2831d512016-08-15 09:33:47 -0700121 void emitJavaReaderWriter(
122 Formatter &out,
123 const std::string &parcelObj,
124 const std::string &argName,
125 bool isReader) const override;
126
Steven Moreland6ec9eb92018-02-16 14:21:49 -0800127 void emitVtsAttributeType(Formatter& out) const override;
Zhuoyao Zhang864c7712016-08-16 15:35:28 -0700128
Steven Moreland6ec9eb92018-02-16 14:21:49 -0800129 void emitVtsAttributeDeclaration(Formatter& out) const;
130 void emitVtsMethodDeclaration(Formatter& out) const;
Zhuoyao Zhang5158db42016-08-10 10:25:20 -0700131
Steven Moreland69e7c702016-09-09 11:16:32 -0700132 bool hasOnewayMethods() const;
133
Timur Iskhakov5dc72fe2017-09-07 23:13:44 -0700134 bool deepIsJavaCompatible(std::unordered_set<const Type*>* visited) const override;
Andreas Huber70a59e12016-08-16 12:57:01 -0700135
Timur Iskhakovff5e64a2017-09-11 14:56:18 -0700136 bool isNeverStrongReference() const override;
137
Timur Iskhakov505316c2017-08-05 03:38:59 +0000138 private:
Timur Iskhakov0344e612017-08-25 12:57:09 -0700139 Reference<Type> mSuperType;
Timur Iskhakov505316c2017-08-05 03:38:59 +0000140
141 std::vector<Method*> mUserMethods;
142 std::vector<Method*> mReservedMethods;
143
Steven Moreland04dea8d2018-02-06 13:11:24 -0800144 const Hash* mFileHash;
145
Timur Iskhakov505316c2017-08-05 03:38:59 +0000146 bool fillPingMethod(Method* method) const;
147 bool fillDescriptorChainMethod(Method* method) const;
148 bool fillGetDescriptorMethod(Method* method) const;
149 bool fillHashChainMethod(Method* method) const;
150 bool fillSyspropsChangedMethod(Method* method) const;
151 bool fillLinkToDeathMethod(Method* method) const;
152 bool fillUnlinkToDeathMethod(Method* method) const;
153 bool fillSetHALInstrumentationMethod(Method* method) const;
154 bool fillGetDebugInfoMethod(Method* method) const;
155 bool fillDebugMethod(Method* method) const;
Andreas Huberc9410c72016-07-28 12:18:40 -0700156
Steven Moreland04dea8d2018-02-06 13:11:24 -0800157 void emitDigestChain(
158 Formatter& out, const std::string& prefix, const std::vector<const Interface*>& chain,
159 std::function<std::string(std::unique_ptr<ConstantExpression>)> byteToString) const;
160
Andreas Huberc9410c72016-07-28 12:18:40 -0700161 DISALLOW_COPY_AND_ASSIGN(Interface);
162};
163
Yifan Hong10fe0b52016-10-19 14:20:17 -0700164// An interface / method tuple.
165struct InterfaceAndMethod {
166 InterfaceAndMethod(const Interface *iface, Method *method)
167 : mInterface(iface),
168 mMethod(method) {}
169 Method *method() const { return mMethod; }
170 const Interface *interface() const { return mInterface; }
Timur Iskhakov505316c2017-08-05 03:38:59 +0000171
172 private:
Yifan Hong10fe0b52016-10-19 14:20:17 -0700173 // do not own these objects.
174 const Interface *mInterface;
175 Method *mMethod;
176};
177
Andreas Huberc9410c72016-07-28 12:18:40 -0700178} // namespace android
179
180#endif // INTERFACE_H_
181