blob: 8542f18023ddc8cbd9e12ef4ae2ffe2b6de0b4e6 [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);
Andreas Huberc9410c72016-07-28 12:18:40 -070033
Andreas Hubera2723d22016-07-29 15:36:07 -070034 bool isInterface() const override;
Andreas Huber295ad302016-08-16 11:35:00 -070035 bool isBinder() const override;
Yifan Hongfe95aa22016-10-19 17:26:45 -070036 bool isRootType() const { return mSuperType == nullptr; }
Yifan Hongc8934042016-11-17 17:10:52 -080037 bool isIBase() const { return fqName() == gIBaseFqName; }
Steven Moreland30bb6a82016-11-30 09:18:34 -080038 std::string typeName() const override;
Andreas Huberc9410c72016-07-28 12:18:40 -070039
Andreas Huber6cb08cf2016-08-03 15:44:51 -070040 const Interface *superType() const;
Andreas Huberc9410c72016-07-28 12:18:40 -070041
Steven Moreland14ee6742016-10-18 12:58:28 -070042 Method *lookupMethod(std::string name) const;
Yifan Hongfe95aa22016-10-19 17:26:45 -070043 // Super type chain to root type.
44 // First element is superType().
45 std::vector<const Interface *> superTypeChain() const;
Yifan Hong10fe0b52016-10-19 14:20:17 -070046 // Super type chain to root type, including myself.
47 // First element is this.
48 std::vector<const Interface *> typeChain() const;
49
50 // user defined methods (explicit definition in HAL files)
51 const std::vector<Method *> &userDefinedMethods() const;
52 // HIDL reserved methods (every interface has these implicitly defined)
53 const std::vector<Method *> &hidlReservedMethods() const;
54 // the sum of userDefinedMethods() and hidlReservedMethods().
55 std::vector<Method *> methods() const;
56
57 // userDefinedMethods() for all super type + methods()
58 // The order will be as follows (in the transaction code order):
59 // great-great-...-great-grand parent->userDefinedMethods()
60 // ...
61 // parent->userDefinedMethods()
62 // this->userDefinedMethods()
63 // this->hidlReservedMethods()
64 std::vector<InterfaceAndMethod> allMethodsFromRoot() const;
Andreas Huber881227d2016-08-02 14:20:21 -070065
Steven Moreland40786312016-08-16 10:29:40 -070066 std::string getBaseName() const;
67
Yifan Hong60e52bd2016-11-09 14:47:45 -080068 FQName getProxyName() const;
69 FQName getStubName() const;
Yifan Hong158655a2016-11-08 12:34:07 -080070 FQName getPassthroughName() const;
Yifan Hong158655a2016-11-08 12:34:07 -080071
Andreas Huber4c865b72016-09-14 15:26:27 -070072 std::string getCppType(
73 StorageMode mode,
Andreas Huber4c865b72016-09-14 15:26:27 -070074 bool specifyNamespaces) const override;
Andreas Huber881227d2016-08-02 14:20:21 -070075
Yifan Hong4ed13472016-11-02 10:44:11 -070076 std::string getJavaType(bool forInitializer) const override;
Zhuoyao Zhanga588b232016-11-10 14:37:35 -080077 std::string getVtsType() const override;
Andreas Huber2831d512016-08-15 09:33:47 -070078
Andreas Huber881227d2016-08-02 14:20:21 -070079 void emitReaderWriter(
80 Formatter &out,
81 const std::string &name,
82 const std::string &parcelObj,
83 bool parcelObjIsPointer,
84 bool isReader,
85 ErrorMode mode) const override;
86
Andreas Huber2831d512016-08-15 09:33:47 -070087 void emitJavaReaderWriter(
88 Formatter &out,
89 const std::string &parcelObj,
90 const std::string &argName,
91 bool isReader) const override;
92
Zhuoyao Zhang864c7712016-08-16 15:35:28 -070093 status_t emitVtsAttributeType(Formatter &out) const override;
94
95 status_t emitVtsAttributeDeclaration(Formatter &out) const;
96 status_t emitVtsMethodDeclaration(Formatter &out) const;
Zhuoyao Zhang5158db42016-08-10 10:25:20 -070097
Steven Moreland69e7c702016-09-09 11:16:32 -070098 bool hasOnewayMethods() const;
99
Andreas Huber70a59e12016-08-16 12:57:01 -0700100 bool isJavaCompatible() const override;
101
Andreas Huberc9410c72016-07-28 12:18:40 -0700102private:
Andreas Huber6cb08cf2016-08-03 15:44:51 -0700103 Interface *mSuperType;
Yifan Hong10fe0b52016-10-19 14:20:17 -0700104 std::vector<Method *> mUserMethods;
105 std::vector<Method *> mReservedMethods;
Andreas Huberea081b32016-08-17 15:57:47 -0700106 mutable bool mIsJavaCompatibleInProgress;
Yifan Hong10fe0b52016-10-19 14:20:17 -0700107 Method *createDescriptorChainMethod() const;
Martijn Coenenaf712c02016-11-16 15:26:27 +0100108 Method *createSyspropsChangedMethod() const;
Martijn Coenen115d4282016-12-19 05:14:04 +0100109 Method *createLinkToDeathMethod() const;
110 Method *createUnlinkToDeathMethod() const;
Andreas Huberc9410c72016-07-28 12:18:40 -0700111
112 DISALLOW_COPY_AND_ASSIGN(Interface);
113};
114
Yifan Hong10fe0b52016-10-19 14:20:17 -0700115// An interface / method tuple.
116struct InterfaceAndMethod {
117 InterfaceAndMethod(const Interface *iface, Method *method)
118 : mInterface(iface),
119 mMethod(method) {}
120 Method *method() const { return mMethod; }
121 const Interface *interface() const { return mInterface; }
122private:
123 // do not own these objects.
124 const Interface *mInterface;
125 Method *mMethod;
126};
127
Andreas Huberc9410c72016-07-28 12:18:40 -0700128} // namespace android
129
130#endif // INTERFACE_H_
131