blob: aa3d18f33dd594ef4c734c2cc05f98c911503ddf [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
Steven Moreland77943692018-08-09 12:53:42 -070025#include "ConstantExpression.h"
Timur Iskhakov505316c2017-08-05 03:38:59 +000026#include "Reference.h"
27#include "Scope.h"
28
Andreas Huberc9410c72016-07-28 12:18:40 -070029namespace android {
30
31struct Method;
Yifan Hong10fe0b52016-10-19 14:20:17 -070032struct InterfaceAndMethod;
Andreas Huberc9410c72016-07-28 12:18:40 -070033
34struct Interface : public Scope {
Steven Moreland77943692018-08-09 12:53:42 -070035 const static std::unique_ptr<ConstantExpression> FLAG_ONE_WAY;
Steven Moreland3ce72142018-02-02 14:31:18 -080036
Timur Iskhakov565b0132017-09-06 18:07:11 -070037 Interface(const char* localName, const FQName& fullName, const Location& location,
Steven Moreland04dea8d2018-02-06 13:11:24 -080038 Scope* parent, const Reference<Type>& superType, const Hash* fileHash);
39
40 const Hash* getFileHash() const;
Andreas Huberc9410c72016-07-28 12:18:40 -070041
Steven Moreland14ee6742016-10-18 12:58:28 -070042 bool addMethod(Method *method);
Yifan Hongffa91392017-01-31 13:41:23 -080043 bool addAllReservedMethods();
Andreas Huberc9410c72016-07-28 12:18:40 -070044
Martijn Coenenb40ef022017-01-02 15:21:46 +010045 bool isElidableType() const override;
Andreas Hubera2723d22016-07-29 15:36:07 -070046 bool isInterface() const override;
Yifan Hongc8934042016-11-17 17:10:52 -080047 bool isIBase() const { return fqName() == gIBaseFqName; }
Steven Moreland30bb6a82016-11-30 09:18:34 -080048 std::string typeName() const override;
Andreas Huberc9410c72016-07-28 12:18:40 -070049
Timur Iskhakov505316c2017-08-05 03:38:59 +000050 const Interface* superType() const;
Andreas Huberc9410c72016-07-28 12:18:40 -070051
Yifan Hongfe95aa22016-10-19 17:26:45 -070052 // Super type chain to root type.
53 // First element is superType().
54 std::vector<const Interface *> superTypeChain() const;
Yifan Hong10fe0b52016-10-19 14:20:17 -070055 // Super type chain to root type, including myself.
56 // First element is this.
57 std::vector<const Interface *> typeChain() const;
58
59 // user defined methods (explicit definition in HAL files)
60 const std::vector<Method *> &userDefinedMethods() const;
61 // HIDL reserved methods (every interface has these implicitly defined)
62 const std::vector<Method *> &hidlReservedMethods() const;
63 // the sum of userDefinedMethods() and hidlReservedMethods().
64 std::vector<Method *> methods() const;
65
66 // userDefinedMethods() for all super type + methods()
67 // The order will be as follows (in the transaction code order):
68 // great-great-...-great-grand parent->userDefinedMethods()
69 // ...
70 // parent->userDefinedMethods()
71 // this->userDefinedMethods()
72 // this->hidlReservedMethods()
73 std::vector<InterfaceAndMethod> allMethodsFromRoot() const;
Andreas Huber881227d2016-08-02 14:20:21 -070074
Timur Iskhakovf1b902d2017-08-13 20:14:31 -070075 // allMethodsFromRoot for parent
76 std::vector<InterfaceAndMethod> allSuperMethodsFromRoot() const;
77
Yifan Hongeefe4f22017-01-04 15:32:42 -080078 // aliases for corresponding methods in this->fqName()
Steven Moreland40786312016-08-16 10:29:40 -070079 std::string getBaseName() const;
Steven Moreland9a6da7a2017-09-15 16:21:24 -070080 std::string getAdapterName() const;
Yifan Hongeefe4f22017-01-04 15:32:42 -080081 std::string getProxyName() const;
82 std::string getStubName() const;
83 std::string getPassthroughName() const;
84 std::string getHwName() const;
Yifan Hong51a65092017-01-04 15:41:44 -080085 FQName getProxyFqName() const;
86 FQName getStubFqName() const;
87 FQName getPassthroughFqName() const;
Yifan Hong158655a2016-11-08 12:34:07 -080088
Andreas Huber4c865b72016-09-14 15:26:27 -070089 std::string getCppType(
90 StorageMode mode,
Andreas Huber4c865b72016-09-14 15:26:27 -070091 bool specifyNamespaces) const override;
Andreas Huber881227d2016-08-02 14:20:21 -070092
Yifan Hong4ed13472016-11-02 10:44:11 -070093 std::string getJavaType(bool forInitializer) const override;
Zhuoyao Zhanga588b232016-11-10 14:37:35 -080094 std::string getVtsType() const override;
Andreas Huber2831d512016-08-15 09:33:47 -070095
Timur Iskhakovb58f4182017-08-29 15:19:24 -070096 std::vector<const Reference<Type>*> getReferences() const override;
97 std::vector<const Reference<Type>*> getStrongReferences() const override;
Timur Iskhakov33431e62017-08-21 17:31:23 -070098
Timur Iskhakovb58f4182017-08-29 15:19:24 -070099 std::vector<const ConstantExpression*> getConstantExpressions() const override;
Timur Iskhakov891a8662017-08-25 21:53:48 -0700100
Timur Iskhakovcec46c42017-08-09 00:22:02 -0700101 status_t resolveInheritance() override;
Timur Iskhakovcec46c42017-08-09 00:22:02 -0700102 status_t validate() const override;
103 status_t validateUniqueNames() const;
Steven Moreland6ec9eb92018-02-16 14:21:49 -0800104 status_t validateAnnotations() const;
Timur Iskhakovcec46c42017-08-09 00:22:02 -0700105
Andreas Huber881227d2016-08-02 14:20:21 -0700106 void emitReaderWriter(
107 Formatter &out,
108 const std::string &name,
109 const std::string &parcelObj,
110 bool parcelObjIsPointer,
111 bool isReader,
112 ErrorMode mode) const override;
113
Steven Moreland6ec9eb92018-02-16 14:21:49 -0800114 void emitPackageTypeDeclarations(Formatter& out) const override;
Steven Moreland09c6ebe2018-10-09 10:15:48 -0700115 void emitPackageTypeHeaderDefinitions(Formatter& out) const override;
Steven Moreland6ec9eb92018-02-16 14:21:49 -0800116 void emitTypeDefinitions(Formatter& out, const std::string& prefix) const override;
Yifan Hongf5cc2f72017-01-04 18:02:34 -0800117
Howard Chenecfb4512017-11-21 18:28:53 +0800118 void getAlignmentAndSize(size_t* align, size_t* size) const override;
Andreas Huber2831d512016-08-15 09:33:47 -0700119 void emitJavaReaderWriter(
120 Formatter &out,
121 const std::string &parcelObj,
122 const std::string &argName,
123 bool isReader) const override;
124
Steven Moreland6ec9eb92018-02-16 14:21:49 -0800125 void emitVtsAttributeType(Formatter& out) const override;
Zhuoyao Zhang864c7712016-08-16 15:35:28 -0700126
Steven Moreland6ec9eb92018-02-16 14:21:49 -0800127 void emitVtsAttributeDeclaration(Formatter& out) const;
Zhuoyao Zhange59c9332018-07-20 14:16:04 -0700128 void emitVtsMethodDeclaration(Formatter& out, bool isInherited) const;
Zhuoyao Zhang5158db42016-08-10 10:25:20 -0700129
Steven Moreland69e7c702016-09-09 11:16:32 -0700130 bool hasOnewayMethods() const;
131
Timur Iskhakov5dc72fe2017-09-07 23:13:44 -0700132 bool deepIsJavaCompatible(std::unordered_set<const Type*>* visited) const override;
Andreas Huber70a59e12016-08-16 12:57:01 -0700133
Timur Iskhakovff5e64a2017-09-11 14:56:18 -0700134 bool isNeverStrongReference() const override;
135
Timur Iskhakov505316c2017-08-05 03:38:59 +0000136 private:
Timur Iskhakov0344e612017-08-25 12:57:09 -0700137 Reference<Type> mSuperType;
Timur Iskhakov505316c2017-08-05 03:38:59 +0000138
139 std::vector<Method*> mUserMethods;
140 std::vector<Method*> mReservedMethods;
141
Steven Moreland04dea8d2018-02-06 13:11:24 -0800142 const Hash* mFileHash;
143
Timur Iskhakov505316c2017-08-05 03:38:59 +0000144 bool fillPingMethod(Method* method) const;
145 bool fillDescriptorChainMethod(Method* method) const;
146 bool fillGetDescriptorMethod(Method* method) const;
147 bool fillHashChainMethod(Method* method) const;
148 bool fillSyspropsChangedMethod(Method* method) const;
149 bool fillLinkToDeathMethod(Method* method) const;
150 bool fillUnlinkToDeathMethod(Method* method) const;
151 bool fillSetHALInstrumentationMethod(Method* method) const;
152 bool fillGetDebugInfoMethod(Method* method) const;
153 bool fillDebugMethod(Method* method) const;
Andreas Huberc9410c72016-07-28 12:18:40 -0700154
Steven Moreland04dea8d2018-02-06 13:11:24 -0800155 void emitDigestChain(
156 Formatter& out, const std::string& prefix, const std::vector<const Interface*>& chain,
157 std::function<std::string(std::unique_ptr<ConstantExpression>)> byteToString) const;
158
Andreas Huberc9410c72016-07-28 12:18:40 -0700159 DISALLOW_COPY_AND_ASSIGN(Interface);
160};
161
Yifan Hong10fe0b52016-10-19 14:20:17 -0700162// An interface / method tuple.
163struct InterfaceAndMethod {
164 InterfaceAndMethod(const Interface *iface, Method *method)
165 : mInterface(iface),
166 mMethod(method) {}
167 Method *method() const { return mMethod; }
168 const Interface *interface() const { return mInterface; }
Timur Iskhakov505316c2017-08-05 03:38:59 +0000169
170 private:
Yifan Hong10fe0b52016-10-19 14:20:17 -0700171 // do not own these objects.
172 const Interface *mInterface;
173 Method *mMethod;
174};
175
Andreas Huberc9410c72016-07-28 12:18:40 -0700176} // namespace android
177
178#endif // INTERFACE_H_
179