blob: 4f5163df17538aceb48279a469e0f27176e42d6c [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 METHOD_H_
18
19#define METHOD_H_
20
21#include <android-base/macros.h>
Yifan Hong10fe0b52016-10-19 14:20:17 -070022#include <functional>
23#include <hidl-util/Formatter.h>
Andreas Huberc9410c72016-07-28 12:18:40 -070024#include <string>
Andreas Huber881227d2016-08-02 14:20:21 -070025#include <vector>
Andreas Huberc9410c72016-07-28 12:18:40 -070026
27namespace android {
28
Andreas Huber3599d922016-08-09 10:42:57 -070029struct Annotation;
Andreas Huberc9410c72016-07-28 12:18:40 -070030struct Formatter;
Iliyan Malchev40d474a2016-08-16 06:20:17 -070031struct ScalarType;
Andreas Huberc9410c72016-07-28 12:18:40 -070032struct Type;
Andreas Huber31629bc2016-08-03 09:06:40 -070033struct TypedVar;
Andreas Huberc9410c72016-07-28 12:18:40 -070034
Yifan Hong10fe0b52016-10-19 14:20:17 -070035using MethodImpl = std::function<void(Formatter &)>;
36
Andreas Huberc9410c72016-07-28 12:18:40 -070037struct Method {
38 Method(const char *name,
Andreas Huber881227d2016-08-02 14:20:21 -070039 std::vector<TypedVar *> *args,
Andreas Huber3599d922016-08-09 10:42:57 -070040 std::vector<TypedVar *> *results,
Iliyan Malchev639bff82016-08-13 14:24:11 -070041 bool oneway,
Steven Morelandd537ab02016-09-12 10:32:01 -070042 std::vector<Annotation *> *annotations);
Yifan Hong10fe0b52016-10-19 14:20:17 -070043 Method(const char *name,
44 std::vector<TypedVar *> *args,
45 std::vector<TypedVar *> *results,
46 bool oneway,
47 std::vector<Annotation *> *annotations,
48 size_t serial,
49 MethodImpl cppImpl,
50 MethodImpl javaImpl);
Andreas Huberc9410c72016-07-28 12:18:40 -070051
Andreas Huber881227d2016-08-02 14:20:21 -070052 std::string name() const;
53 const std::vector<TypedVar *> &args() const;
54 const std::vector<TypedVar *> &results() const;
Iliyan Malchev639bff82016-08-13 14:24:11 -070055 bool isOneway() const { return mOneway; }
Yifan Hong10fe0b52016-10-19 14:20:17 -070056 void cppImpl(Formatter &out) const;
57 void javaImpl(Formatter &out) const;
58 bool isHidlReserved() const { return mIsHidlReserved; }
Steven Morelandd537ab02016-09-12 10:32:01 -070059 const std::vector<Annotation *> &annotations() const;
Andreas Huber881227d2016-08-02 14:20:21 -070060
Steven Morelandef1a9fe2016-10-06 17:19:09 -070061 void setSerialId(size_t serial);
62 size_t getSerialId() const;
63
Steven Morelanda7a421a2016-09-07 08:35:18 -070064 void generateCppSignature(Formatter &out,
Yifan Hong068c5522016-10-31 14:07:25 -070065 const std::string &className = "",
66 bool specifyNamespaces = true) const;
Steven Morelanda7a421a2016-09-07 08:35:18 -070067
Steven Moreland979e0992016-09-07 09:18:08 -070068 static std::string GetArgSignature(const std::vector<TypedVar *> &args,
69 bool specifyNamespaces);
Steven Morelanda7a421a2016-09-07 08:35:18 -070070 static std::string GetJavaArgSignature(const std::vector<TypedVar *> &args);
Andreas Huber881227d2016-08-02 14:20:21 -070071
Iliyan Malchev40d474a2016-08-16 06:20:17 -070072 const TypedVar* canElideCallback() const;
73
Andreas Huber3599d922016-08-09 10:42:57 -070074 void dumpAnnotations(Formatter &out) const;
75
Andreas Huber70a59e12016-08-16 12:57:01 -070076 bool isJavaCompatible() const;
77
Andreas Huberc9410c72016-07-28 12:18:40 -070078private:
79 std::string mName;
Steven Morelandef1a9fe2016-10-06 17:19:09 -070080 size_t mSerial = 0;
Andreas Huber881227d2016-08-02 14:20:21 -070081 std::vector<TypedVar *> *mArgs;
82 std::vector<TypedVar *> *mResults;
Iliyan Malchev639bff82016-08-13 14:24:11 -070083 bool mOneway;
Steven Morelandd537ab02016-09-12 10:32:01 -070084 std::vector<Annotation *> *mAnnotations;
Andreas Huberc9410c72016-07-28 12:18:40 -070085
Yifan Hong10fe0b52016-10-19 14:20:17 -070086 bool mIsHidlReserved = false;
87 // The following fields has no meaning if mIsHidlReserved is false.
88 // hard-coded implementation for HIDL reserved methods.
89 MethodImpl mCppImpl = nullptr;
90 MethodImpl mJavaImpl = nullptr;
91
Andreas Huberc9410c72016-07-28 12:18:40 -070092 DISALLOW_COPY_AND_ASSIGN(Method);
93};
94
Andreas Huber31629bc2016-08-03 09:06:40 -070095struct TypedVar {
96 TypedVar(const char *name, Type *type);
97
98 std::string name() const;
99 const Type &type() const;
100
Andreas Huber70a59e12016-08-16 12:57:01 -0700101 bool isJavaCompatible() const;
102
Andreas Huber31629bc2016-08-03 09:06:40 -0700103private:
104 std::string mName;
105 Type *mType;
106
107 DISALLOW_COPY_AND_ASSIGN(TypedVar);
108};
109
Andreas Huberc9410c72016-07-28 12:18:40 -0700110} // namespace android
111
112#endif // METHOD_H_
113