blob: 7b7eb3349bf2239d5e25d0a9bb6ae9dcc80ae801 [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,
Timur Iskhakov0344e612017-08-25 12:57:09 -070033 const Reference<Type>& 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
Yifan Hongfe95aa22016-10-19 17:26:45 -070046 // Super type chain to root type.
47 // First element is superType().
48 std::vector<const Interface *> superTypeChain() const;
Yifan Hong10fe0b52016-10-19 14:20:17 -070049 // Super type chain to root type, including myself.
50 // First element is this.
51 std::vector<const Interface *> typeChain() const;
52
53 // user defined methods (explicit definition in HAL files)
54 const std::vector<Method *> &userDefinedMethods() const;
55 // HIDL reserved methods (every interface has these implicitly defined)
56 const std::vector<Method *> &hidlReservedMethods() const;
57 // the sum of userDefinedMethods() and hidlReservedMethods().
58 std::vector<Method *> methods() const;
59
60 // userDefinedMethods() for all super type + methods()
61 // The order will be as follows (in the transaction code order):
62 // great-great-...-great-grand parent->userDefinedMethods()
63 // ...
64 // parent->userDefinedMethods()
65 // this->userDefinedMethods()
66 // this->hidlReservedMethods()
67 std::vector<InterfaceAndMethod> allMethodsFromRoot() const;
Andreas Huber881227d2016-08-02 14:20:21 -070068
Timur Iskhakovf1b902d2017-08-13 20:14:31 -070069 // allMethodsFromRoot for parent
70 std::vector<InterfaceAndMethod> allSuperMethodsFromRoot() const;
71
Yifan Hongeefe4f22017-01-04 15:32:42 -080072 // aliases for corresponding methods in this->fqName()
Steven Moreland40786312016-08-16 10:29:40 -070073 std::string getBaseName() const;
Yifan Hongeefe4f22017-01-04 15:32:42 -080074 std::string getProxyName() const;
75 std::string getStubName() const;
76 std::string getPassthroughName() const;
77 std::string getHwName() const;
Yifan Hong51a65092017-01-04 15:41:44 -080078 FQName getProxyFqName() const;
79 FQName getStubFqName() const;
80 FQName getPassthroughFqName() const;
Yifan Hong158655a2016-11-08 12:34:07 -080081
Andreas Huber4c865b72016-09-14 15:26:27 -070082 std::string getCppType(
83 StorageMode mode,
Andreas Huber4c865b72016-09-14 15:26:27 -070084 bool specifyNamespaces) const override;
Andreas Huber881227d2016-08-02 14:20:21 -070085
Yifan Hong4ed13472016-11-02 10:44:11 -070086 std::string getJavaType(bool forInitializer) const override;
Zhuoyao Zhanga588b232016-11-10 14:37:35 -080087 std::string getVtsType() const override;
Andreas Huber2831d512016-08-15 09:33:47 -070088
Timur Iskhakov33431e62017-08-21 17:31:23 -070089 std::vector<Reference<Type>> getReferences() const override;
90
Timur Iskhakov891a8662017-08-25 21:53:48 -070091 std::vector<ConstantExpression*> getConstantExpressions() const override;
92
Timur Iskhakovcec46c42017-08-09 00:22:02 -070093 status_t resolveInheritance() override;
Timur Iskhakovcec46c42017-08-09 00:22:02 -070094 status_t validate() const override;
95 status_t validateUniqueNames() const;
96
Andreas Huber881227d2016-08-02 14:20:21 -070097 void emitReaderWriter(
98 Formatter &out,
99 const std::string &name,
100 const std::string &parcelObj,
101 bool parcelObjIsPointer,
102 bool isReader,
103 ErrorMode mode) const override;
104
Yifan Hongf5cc2f72017-01-04 18:02:34 -0800105 status_t emitGlobalTypeDeclarations(Formatter &out) const override;
Chih-Hung Hsieh8c90cc52017-08-03 14:51:13 -0700106 status_t emitTypeDefinitions(Formatter& out, const std::string& prefix) const override;
Yifan Hongf5cc2f72017-01-04 18:02:34 -0800107
Andreas Huber2831d512016-08-15 09:33:47 -0700108 void emitJavaReaderWriter(
109 Formatter &out,
110 const std::string &parcelObj,
111 const std::string &argName,
112 bool isReader) const override;
113
Zhuoyao Zhang864c7712016-08-16 15:35:28 -0700114 status_t emitVtsAttributeType(Formatter &out) const override;
115
116 status_t emitVtsAttributeDeclaration(Formatter &out) const;
117 status_t emitVtsMethodDeclaration(Formatter &out) const;
Zhuoyao Zhang5158db42016-08-10 10:25:20 -0700118
Steven Moreland69e7c702016-09-09 11:16:32 -0700119 bool hasOnewayMethods() const;
120
Andreas Huber70a59e12016-08-16 12:57:01 -0700121 bool isJavaCompatible() const override;
122
Timur Iskhakov505316c2017-08-05 03:38:59 +0000123 private:
Timur Iskhakov0344e612017-08-25 12:57:09 -0700124 Reference<Type> mSuperType;
Timur Iskhakov505316c2017-08-05 03:38:59 +0000125
126 std::vector<Method*> mUserMethods;
127 std::vector<Method*> mReservedMethods;
128
Andreas Huberea081b32016-08-17 15:57:47 -0700129 mutable bool mIsJavaCompatibleInProgress;
Timur Iskhakov505316c2017-08-05 03:38:59 +0000130
131 bool fillPingMethod(Method* method) const;
132 bool fillDescriptorChainMethod(Method* method) const;
133 bool fillGetDescriptorMethod(Method* method) const;
134 bool fillHashChainMethod(Method* method) const;
135 bool fillSyspropsChangedMethod(Method* method) const;
136 bool fillLinkToDeathMethod(Method* method) const;
137 bool fillUnlinkToDeathMethod(Method* method) const;
138 bool fillSetHALInstrumentationMethod(Method* method) const;
139 bool fillGetDebugInfoMethod(Method* method) const;
140 bool fillDebugMethod(Method* method) const;
Andreas Huberc9410c72016-07-28 12:18:40 -0700141
142 DISALLOW_COPY_AND_ASSIGN(Interface);
143};
144
Yifan Hong10fe0b52016-10-19 14:20:17 -0700145// An interface / method tuple.
146struct InterfaceAndMethod {
147 InterfaceAndMethod(const Interface *iface, Method *method)
148 : mInterface(iface),
149 mMethod(method) {}
150 Method *method() const { return mMethod; }
151 const Interface *interface() const { return mInterface; }
Timur Iskhakov505316c2017-08-05 03:38:59 +0000152
153 private:
Yifan Hong10fe0b52016-10-19 14:20:17 -0700154 // do not own these objects.
155 const Interface *mInterface;
156 Method *mMethod;
157};
158
Andreas Huberc9410c72016-07-28 12:18:40 -0700159} // namespace android
160
161#endif // INTERFACE_H_
162