blob: 9d6e50dfa78e29f0993810a2e2ea770eb71cbfd8 [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
Timur Iskhakov505316c2017-08-05 03:38:59 +000023#include "Reference.h"
24#include "Scope.h"
25
Andreas Huberc9410c72016-07-28 12:18:40 -070026namespace android {
27
28struct Method;
Yifan Hong10fe0b52016-10-19 14:20:17 -070029struct InterfaceAndMethod;
Andreas Huberc9410c72016-07-28 12:18:40 -070030
31struct Interface : public Scope {
Timur Iskhakov505316c2017-08-05 03:38:59 +000032 Interface(const char* localName, const Location& location, Scope* parent,
33 const Reference<Interface>& superType);
Andreas Huberc9410c72016-07-28 12:18:40 -070034
Steven Moreland14ee6742016-10-18 12:58:28 -070035 bool addMethod(Method *method);
Yifan Hongffa91392017-01-31 13:41:23 -080036 bool addAllReservedMethods();
Andreas Huberc9410c72016-07-28 12:18:40 -070037
Martijn Coenenb40ef022017-01-02 15:21:46 +010038 bool isElidableType() const override;
Andreas Hubera2723d22016-07-29 15:36:07 -070039 bool isInterface() const override;
Andreas Huber295ad302016-08-16 11:35:00 -070040 bool isBinder() const override;
Yifan Hongc8934042016-11-17 17:10:52 -080041 bool isIBase() const { return fqName() == gIBaseFqName; }
Steven Moreland30bb6a82016-11-30 09:18:34 -080042 std::string typeName() const override;
Andreas Huberc9410c72016-07-28 12:18:40 -070043
Timur Iskhakov505316c2017-08-05 03:38:59 +000044 const Interface* superType() const;
Andreas Huberc9410c72016-07-28 12:18:40 -070045
Steven Moreland14ee6742016-10-18 12:58:28 -070046 Method *lookupMethod(std::string name) const;
Yifan Hongfe95aa22016-10-19 17:26:45 -070047 // Super type chain to root type.
48 // First element is superType().
49 std::vector<const Interface *> superTypeChain() const;
Yifan Hong10fe0b52016-10-19 14:20:17 -070050 // Super type chain to root type, including myself.
51 // First element is this.
52 std::vector<const Interface *> typeChain() const;
53
54 // user defined methods (explicit definition in HAL files)
55 const std::vector<Method *> &userDefinedMethods() const;
56 // HIDL reserved methods (every interface has these implicitly defined)
57 const std::vector<Method *> &hidlReservedMethods() const;
58 // the sum of userDefinedMethods() and hidlReservedMethods().
59 std::vector<Method *> methods() const;
60
61 // userDefinedMethods() for all super type + methods()
62 // The order will be as follows (in the transaction code order):
63 // great-great-...-great-grand parent->userDefinedMethods()
64 // ...
65 // parent->userDefinedMethods()
66 // this->userDefinedMethods()
67 // this->hidlReservedMethods()
68 std::vector<InterfaceAndMethod> allMethodsFromRoot() const;
Andreas Huber881227d2016-08-02 14:20:21 -070069
Yifan Hongeefe4f22017-01-04 15:32:42 -080070 // aliases for corresponding methods in this->fqName()
Steven Moreland40786312016-08-16 10:29:40 -070071 std::string getBaseName() const;
Yifan Hongeefe4f22017-01-04 15:32:42 -080072 std::string getProxyName() const;
73 std::string getStubName() const;
74 std::string getPassthroughName() const;
75 std::string getHwName() const;
Yifan Hong51a65092017-01-04 15:41:44 -080076 FQName getProxyFqName() const;
77 FQName getStubFqName() const;
78 FQName getPassthroughFqName() const;
Yifan Hong158655a2016-11-08 12:34:07 -080079
Andreas Huber4c865b72016-09-14 15:26:27 -070080 std::string getCppType(
81 StorageMode mode,
Andreas Huber4c865b72016-09-14 15:26:27 -070082 bool specifyNamespaces) const override;
Andreas Huber881227d2016-08-02 14:20:21 -070083
Yifan Hong4ed13472016-11-02 10:44:11 -070084 std::string getJavaType(bool forInitializer) const override;
Zhuoyao Zhanga588b232016-11-10 14:37:35 -080085 std::string getVtsType() const override;
Andreas Huber2831d512016-08-15 09:33:47 -070086
Andreas Huber881227d2016-08-02 14:20:21 -070087 void emitReaderWriter(
88 Formatter &out,
89 const std::string &name,
90 const std::string &parcelObj,
91 bool parcelObjIsPointer,
92 bool isReader,
93 ErrorMode mode) const override;
94
Yifan Hongf5cc2f72017-01-04 18:02:34 -080095 status_t emitGlobalTypeDeclarations(Formatter &out) const override;
96 status_t emitTypeDefinitions(
97 Formatter &out, const std::string prefix) const override;
98
Andreas Huber2831d512016-08-15 09:33:47 -070099 void emitJavaReaderWriter(
100 Formatter &out,
101 const std::string &parcelObj,
102 const std::string &argName,
103 bool isReader) const override;
104
Zhuoyao Zhang864c7712016-08-16 15:35:28 -0700105 status_t emitVtsAttributeType(Formatter &out) const override;
106
107 status_t emitVtsAttributeDeclaration(Formatter &out) const;
108 status_t emitVtsMethodDeclaration(Formatter &out) const;
Zhuoyao Zhang5158db42016-08-10 10:25:20 -0700109
Steven Moreland69e7c702016-09-09 11:16:32 -0700110 bool hasOnewayMethods() const;
111
Andreas Huber70a59e12016-08-16 12:57:01 -0700112 bool isJavaCompatible() const override;
113
Timur Iskhakov505316c2017-08-05 03:38:59 +0000114 private:
115 Reference<Interface> mSuperType;
116
117 std::vector<Method*> mUserMethods;
118 std::vector<Method*> mReservedMethods;
119
Andreas Huberea081b32016-08-17 15:57:47 -0700120 mutable bool mIsJavaCompatibleInProgress;
Timur Iskhakov505316c2017-08-05 03:38:59 +0000121
122 bool fillPingMethod(Method* method) const;
123 bool fillDescriptorChainMethod(Method* method) const;
124 bool fillGetDescriptorMethod(Method* method) const;
125 bool fillHashChainMethod(Method* method) const;
126 bool fillSyspropsChangedMethod(Method* method) const;
127 bool fillLinkToDeathMethod(Method* method) const;
128 bool fillUnlinkToDeathMethod(Method* method) const;
129 bool fillSetHALInstrumentationMethod(Method* method) const;
130 bool fillGetDebugInfoMethod(Method* method) const;
131 bool fillDebugMethod(Method* method) const;
Andreas Huberc9410c72016-07-28 12:18:40 -0700132
133 DISALLOW_COPY_AND_ASSIGN(Interface);
134};
135
Yifan Hong10fe0b52016-10-19 14:20:17 -0700136// An interface / method tuple.
137struct InterfaceAndMethod {
138 InterfaceAndMethod(const Interface *iface, Method *method)
139 : mInterface(iface),
140 mMethod(method) {}
141 Method *method() const { return mMethod; }
142 const Interface *interface() const { return mInterface; }
Timur Iskhakov505316c2017-08-05 03:38:59 +0000143
144 private:
Yifan Hong10fe0b52016-10-19 14:20:17 -0700145 // do not own these objects.
146 const Interface *mInterface;
147 Method *mMethod;
148};
149
Andreas Huberc9410c72016-07-28 12:18:40 -0700150} // namespace android
151
152#endif // INTERFACE_H_
153