blob: 793226a278d6e543c2c4f5440a0031b1a1596c43 [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
21#include "Scope.h"
Yifan Hong10fe0b52016-10-19 14:20:17 -070022#include <vector>
Andreas Huberc9410c72016-07-28 12:18:40 -070023
Andreas Huberc9410c72016-07-28 12:18:40 -070024namespace android {
25
26struct Method;
Yifan Hong10fe0b52016-10-19 14:20:17 -070027struct InterfaceAndMethod;
Andreas Huberc9410c72016-07-28 12:18:40 -070028
29struct Interface : public Scope {
Yifan Honga4b53d02016-10-31 17:29:10 -070030 Interface(const char *localName, const Location &location, Interface *super);
Andreas Huberc9410c72016-07-28 12:18:40 -070031
Steven Moreland14ee6742016-10-18 12:58:28 -070032 bool addMethod(Method *method);
Yifan Hongffa91392017-01-31 13:41:23 -080033 bool addAllReservedMethods();
Andreas Huberc9410c72016-07-28 12:18:40 -070034
Martijn Coenenb40ef022017-01-02 15:21:46 +010035 bool isElidableType() const override;
Andreas Hubera2723d22016-07-29 15:36:07 -070036 bool isInterface() const override;
Andreas Huber295ad302016-08-16 11:35:00 -070037 bool isBinder() const override;
Yifan Hongfe95aa22016-10-19 17:26:45 -070038 bool isRootType() const { return mSuperType == nullptr; }
Yifan Hongc8934042016-11-17 17:10:52 -080039 bool isIBase() const { return fqName() == gIBaseFqName; }
Steven Moreland30bb6a82016-11-30 09:18:34 -080040 std::string typeName() const override;
Andreas Huberc9410c72016-07-28 12:18:40 -070041
Andreas Huber6cb08cf2016-08-03 15:44:51 -070042 const Interface *superType() const;
Andreas Huberc9410c72016-07-28 12:18:40 -070043
Steven Moreland14ee6742016-10-18 12:58:28 -070044 Method *lookupMethod(std::string name) const;
Yifan Hongfe95aa22016-10-19 17:26:45 -070045 // Super type chain to root type.
46 // First element is superType().
47 std::vector<const Interface *> superTypeChain() const;
Yifan Hong10fe0b52016-10-19 14:20:17 -070048 // 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 Huber881227d2016-08-02 14:20:21 -070067
Yifan Hongeefe4f22017-01-04 15:32:42 -080068 // aliases for corresponding methods in this->fqName()
Steven Moreland40786312016-08-16 10:29:40 -070069 std::string getBaseName() const;
Yifan Hongeefe4f22017-01-04 15:32:42 -080070 std::string getProxyName() const;
71 std::string getStubName() const;
72 std::string getPassthroughName() const;
73 std::string getHwName() const;
Yifan Hong51a65092017-01-04 15:41:44 -080074 FQName getProxyFqName() const;
75 FQName getStubFqName() const;
76 FQName getPassthroughFqName() const;
Yifan Hong158655a2016-11-08 12:34:07 -080077
Andreas Huber4c865b72016-09-14 15:26:27 -070078 std::string getCppType(
79 StorageMode mode,
Andreas Huber4c865b72016-09-14 15:26:27 -070080 bool specifyNamespaces) const override;
Andreas Huber881227d2016-08-02 14:20:21 -070081
Yifan Hong4ed13472016-11-02 10:44:11 -070082 std::string getJavaType(bool forInitializer) const override;
Zhuoyao Zhanga588b232016-11-10 14:37:35 -080083 std::string getVtsType() const override;
Andreas Huber2831d512016-08-15 09:33:47 -070084
Andreas Huber881227d2016-08-02 14:20:21 -070085 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 Hongf5cc2f72017-01-04 18:02:34 -080093 status_t emitGlobalTypeDeclarations(Formatter &out) const override;
94 status_t emitTypeDefinitions(
95 Formatter &out, const std::string prefix) const override;
96
Andreas Huber2831d512016-08-15 09:33:47 -070097 void emitJavaReaderWriter(
98 Formatter &out,
99 const std::string &parcelObj,
100 const std::string &argName,
101 bool isReader) const override;
102
Zhuoyao Zhang864c7712016-08-16 15:35:28 -0700103 status_t emitVtsAttributeType(Formatter &out) const override;
104
105 status_t emitVtsAttributeDeclaration(Formatter &out) const;
106 status_t emitVtsMethodDeclaration(Formatter &out) const;
Zhuoyao Zhang5158db42016-08-10 10:25:20 -0700107
Steven Moreland69e7c702016-09-09 11:16:32 -0700108 bool hasOnewayMethods() const;
109
Andreas Huber70a59e12016-08-16 12:57:01 -0700110 bool isJavaCompatible() const override;
111
Andreas Huberc9410c72016-07-28 12:18:40 -0700112private:
Andreas Huber6cb08cf2016-08-03 15:44:51 -0700113 Interface *mSuperType;
Yifan Hong10fe0b52016-10-19 14:20:17 -0700114 std::vector<Method *> mUserMethods;
115 std::vector<Method *> mReservedMethods;
Andreas Huberea081b32016-08-17 15:57:47 -0700116 mutable bool mIsJavaCompatibleInProgress;
Steven Moreland424a9482017-02-13 19:20:40 -0800117 bool fillPingMethod(Method *method) const;
Yifan Hongffa91392017-01-31 13:41:23 -0800118 bool fillDescriptorChainMethod(Method *method) const;
119 bool fillGetDescriptorMethod(Method *method) const;
Yifan Hongf509cb02017-04-03 12:19:25 -0700120 bool fillHashChainMethod(Method *method) const;
Yifan Hongffa91392017-01-31 13:41:23 -0800121 bool fillSyspropsChangedMethod(Method *method) const;
122 bool fillLinkToDeathMethod(Method *method) const;
123 bool fillUnlinkToDeathMethod(Method *method) const;
124 bool fillSetHALInstrumentationMethod(Method *method) const;
Yifan Hongbcffce22017-02-01 15:52:06 -0800125 bool fillGetDebugInfoMethod(Method *method) const;
Andreas Huber37065d62017-02-07 14:36:54 -0800126 bool fillDebugMethod(Method *method) const;
Andreas Huberc9410c72016-07-28 12:18:40 -0700127
128 DISALLOW_COPY_AND_ASSIGN(Interface);
129};
130
Yifan Hong10fe0b52016-10-19 14:20:17 -0700131// An interface / method tuple.
132struct InterfaceAndMethod {
133 InterfaceAndMethod(const Interface *iface, Method *method)
134 : mInterface(iface),
135 mMethod(method) {}
136 Method *method() const { return mMethod; }
137 const Interface *interface() const { return mInterface; }
138private:
139 // do not own these objects.
140 const Interface *mInterface;
141 Method *mMethod;
142};
143
Andreas Huberc9410c72016-07-28 12:18:40 -0700144} // namespace android
145
146#endif // INTERFACE_H_
147