blob: ae7e032bf80b92f48803627fd67875aef59c80cd [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 {
Andreas Huber7c5ddfb2016-09-29 13:45:22 -070030 Interface(const char *localName, 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;
Andreas Huberc9410c72016-07-28 12:18:40 -070036
Andreas Huber6cb08cf2016-08-03 15:44:51 -070037 const Interface *superType() const;
Andreas Huberc9410c72016-07-28 12:18:40 -070038
Steven Moreland14ee6742016-10-18 12:58:28 -070039 Method *lookupMethod(std::string name) const;
Yifan Hong10fe0b52016-10-19 14:20:17 -070040 // Super type chain to root type, including myself.
41 // First element is this.
42 std::vector<const Interface *> typeChain() const;
43
44 // user defined methods (explicit definition in HAL files)
45 const std::vector<Method *> &userDefinedMethods() const;
46 // HIDL reserved methods (every interface has these implicitly defined)
47 const std::vector<Method *> &hidlReservedMethods() const;
48 // the sum of userDefinedMethods() and hidlReservedMethods().
49 std::vector<Method *> methods() const;
50
51 // userDefinedMethods() for all super type + methods()
52 // The order will be as follows (in the transaction code order):
53 // great-great-...-great-grand parent->userDefinedMethods()
54 // ...
55 // parent->userDefinedMethods()
56 // this->userDefinedMethods()
57 // this->hidlReservedMethods()
58 std::vector<InterfaceAndMethod> allMethodsFromRoot() const;
Andreas Huber881227d2016-08-02 14:20:21 -070059
Steven Moreland40786312016-08-16 10:29:40 -070060 std::string getBaseName() const;
61
Andreas Huber4c865b72016-09-14 15:26:27 -070062 std::string getCppType(
63 StorageMode mode,
64 std::string *extra,
65 bool specifyNamespaces) const override;
Andreas Huber881227d2016-08-02 14:20:21 -070066
Andreas Huber4c865b72016-09-14 15:26:27 -070067 std::string getJavaType(
68 std::string *extra, bool forInitializer) const override;
Andreas Huber2831d512016-08-15 09:33:47 -070069
Andreas Huber881227d2016-08-02 14:20:21 -070070 void emitReaderWriter(
71 Formatter &out,
72 const std::string &name,
73 const std::string &parcelObj,
74 bool parcelObjIsPointer,
75 bool isReader,
76 ErrorMode mode) const override;
77
Andreas Huber2831d512016-08-15 09:33:47 -070078 void emitJavaReaderWriter(
79 Formatter &out,
80 const std::string &parcelObj,
81 const std::string &argName,
82 bool isReader) const override;
83
Zhuoyao Zhang864c7712016-08-16 15:35:28 -070084 status_t emitVtsAttributeType(Formatter &out) const override;
85
86 status_t emitVtsAttributeDeclaration(Formatter &out) const;
87 status_t emitVtsMethodDeclaration(Formatter &out) const;
Zhuoyao Zhang5158db42016-08-10 10:25:20 -070088
Steven Moreland69e7c702016-09-09 11:16:32 -070089 bool hasOnewayMethods() const;
90
Andreas Huber70a59e12016-08-16 12:57:01 -070091 bool isJavaCompatible() const override;
92
Andreas Huberc9410c72016-07-28 12:18:40 -070093private:
Andreas Huber6cb08cf2016-08-03 15:44:51 -070094 Interface *mSuperType;
Yifan Hong10fe0b52016-10-19 14:20:17 -070095 std::vector<Method *> mUserMethods;
96 std::vector<Method *> mReservedMethods;
Andreas Huberea081b32016-08-17 15:57:47 -070097 mutable bool mIsJavaCompatibleInProgress;
Yifan Hong10fe0b52016-10-19 14:20:17 -070098 Method *createDescriptorChainMethod() const;
Andreas Huberc9410c72016-07-28 12:18:40 -070099
100 DISALLOW_COPY_AND_ASSIGN(Interface);
101};
102
Yifan Hong10fe0b52016-10-19 14:20:17 -0700103// An interface / method tuple.
104struct InterfaceAndMethod {
105 InterfaceAndMethod(const Interface *iface, Method *method)
106 : mInterface(iface),
107 mMethod(method) {}
108 Method *method() const { return mMethod; }
109 const Interface *interface() const { return mInterface; }
110private:
111 // do not own these objects.
112 const Interface *mInterface;
113 Method *mMethod;
114};
115
Andreas Huberc9410c72016-07-28 12:18:40 -0700116} // namespace android
117
118#endif // INTERFACE_H_
119