Method.h revision 068c5526a42abd22e5046fa6455f04e836aec96a
1/* 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 17#ifndef METHOD_H_ 18 19#define METHOD_H_ 20 21#include <android-base/macros.h> 22#include <functional> 23#include <hidl-util/Formatter.h> 24#include <string> 25#include <vector> 26 27namespace android { 28 29struct Annotation; 30struct Formatter; 31struct ScalarType; 32struct Type; 33struct TypedVar; 34 35using MethodImpl = std::function<void(Formatter &)>; 36 37struct Method { 38 Method(const char *name, 39 std::vector<TypedVar *> *args, 40 std::vector<TypedVar *> *results, 41 bool oneway, 42 std::vector<Annotation *> *annotations); 43 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); 51 52 std::string name() const; 53 const std::vector<TypedVar *> &args() const; 54 const std::vector<TypedVar *> &results() const; 55 bool isOneway() const { return mOneway; } 56 void cppImpl(Formatter &out) const; 57 void javaImpl(Formatter &out) const; 58 bool isHidlReserved() const { return mIsHidlReserved; } 59 const std::vector<Annotation *> &annotations() const; 60 61 void setSerialId(size_t serial); 62 size_t getSerialId() const; 63 64 void generateCppSignature(Formatter &out, 65 const std::string &className = "", 66 bool specifyNamespaces = true) const; 67 68 static std::string GetArgSignature(const std::vector<TypedVar *> &args, 69 bool specifyNamespaces); 70 static std::string GetJavaArgSignature(const std::vector<TypedVar *> &args); 71 72 const TypedVar* canElideCallback() const; 73 74 void dumpAnnotations(Formatter &out) const; 75 76 bool isJavaCompatible() const; 77 78private: 79 std::string mName; 80 size_t mSerial = 0; 81 std::vector<TypedVar *> *mArgs; 82 std::vector<TypedVar *> *mResults; 83 bool mOneway; 84 std::vector<Annotation *> *mAnnotations; 85 86 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 92 DISALLOW_COPY_AND_ASSIGN(Method); 93}; 94 95struct TypedVar { 96 TypedVar(const char *name, Type *type); 97 98 std::string name() const; 99 const Type &type() const; 100 101 bool isJavaCompatible() const; 102 103private: 104 std::string mName; 105 Type *mType; 106 107 DISALLOW_COPY_AND_ASSIGN(TypedVar); 108}; 109 110} // namespace android 111 112#endif // METHOD_H_ 113 114