1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144
|
/*
* Copyright (C) 2016 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef METHOD_H_
#define METHOD_H_
#include <android-base/macros.h>
#include <hidl-util/Formatter.h>
#include <utils/Errors.h>
#include <functional>
#include <map>
#include <set>
#include <string>
#include <unordered_set>
#include <vector>
#include "DocComment.h"
#include "Location.h"
#include "Reference.h"
namespace android {
struct Annotation;
struct ConstantExpression;
struct Formatter;
struct ScalarType;
struct Type;
struct TypedVarVector;
enum MethodImplType {
IMPL_INTERFACE,
IMPL_PROXY,
IMPL_STUB, // overrides the code in onTransact; IMPL_STUB_IMPL will be ignored
IMPL_STUB_IMPL, // use this->method() instead of mImpl->method()
IMPL_PASSTHROUGH,
};
using MethodImpl = std::map<MethodImplType, std::function<void(Formatter &)>>;
struct Method : DocCommentable {
Method(const char* name, std::vector<NamedReference<Type>*>* args,
std::vector<NamedReference<Type>*>* results, bool oneway,
std::vector<Annotation*>* annotations, const Location& location);
std::string name() const;
const std::vector<NamedReference<Type>*>& args() const;
const std::vector<NamedReference<Type>*>& results() const;
bool isOneway() const { return mOneway; }
bool overridesCppImpl(MethodImplType type) const;
bool overridesJavaImpl(MethodImplType type) const;
void cppImpl(MethodImplType type, Formatter &out) const;
void javaImpl(MethodImplType type, Formatter &out) const;
bool isHidlReserved() const { return mIsHidlReserved; }
const std::vector<Annotation *> &annotations() const;
std::vector<Reference<Type>*> getReferences();
std::vector<const Reference<Type>*> getReferences() const;
std::vector<Reference<Type>*> getStrongReferences();
std::vector<const Reference<Type>*> getStrongReferences() const;
std::vector<ConstantExpression*> getConstantExpressions();
std::vector<const ConstantExpression*> getConstantExpressions() const;
// Make a copy with the same name, args, results, oneway, annotations.
// Implementations, serial are not copied.
Method *copySignature() const;
void setSerialId(size_t serial);
size_t getSerialId() const;
// Fill implementation for HIDL reserved methods. mIsHidlReserved will be
// set to true.
void fillImplementation(
size_t serial,
MethodImpl cppImpl,
MethodImpl javaImpl);
void generateCppReturnType(Formatter &out, bool specifyNamespaces = true) const;
void generateCppSignature(Formatter &out,
const std::string &className = "",
bool specifyNamespaces = true) const;
bool hasEmptyCppArgSignature() const;
void emitCppArgSignature(Formatter &out, bool specifyNamespaces = true) const;
void emitCppResultSignature(Formatter &out, bool specifyNamespaces = true) const;
void emitJavaArgSignature(Formatter &out) const;
void emitJavaResultSignature(Formatter &out) const;
const NamedReference<Type>* canElideCallback() const;
void dumpAnnotations(Formatter &out) const;
bool deepIsJavaCompatible(std::unordered_set<const Type*>* visited) const;
const Location& location() const;
private:
std::string mName;
size_t mSerial = 0;
std::vector<NamedReference<Type>*>* mArgs;
std::vector<NamedReference<Type>*>* mResults;
bool mOneway;
std::vector<Annotation *> *mAnnotations;
bool mIsHidlReserved = false;
// The following fields have no meaning if mIsHidlReserved is false.
// hard-coded implementation for HIDL reserved methods.
MethodImpl mCppImpl;
MethodImpl mJavaImpl;
const Location mLocation;
DISALLOW_COPY_AND_ASSIGN(Method);
};
struct TypedVarVector : public std::vector<NamedReference<Type>*> {
TypedVarVector() = default;
bool add(NamedReference<Type>* v);
private:
std::set<std::string> mNames;
};
} // namespace android
#endif // METHOD_H_
|