• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021 Huawei Device Co., Ltd.
3  *
4  * HDF is dual licensed: you can use it either under the terms of
5  * the GPL, or the BSD license, at your option.
6  * See the LICENSE file in the root of this repository for complete details.
7  */
8 
9 #ifndef OHOS_HDI_C_CLIENT_PROXY_CODE_EMITTER_H
10 #define OHOS_HDI_C_CLIENT_PROXY_CODE_EMITTER_H
11 
12 #include "codegen/c_code_emitter.h"
13 
14 namespace OHOS {
15 namespace HDI {
16 class CClientProxyCodeEmitter : public CCodeEmitter {
17 public:
CClientProxyCodeEmitter()18     CClientProxyCodeEmitter() : CCodeEmitter() {}
19 
20     virtual ~CClientProxyCodeEmitter() = default;
21 
22 private:
23     bool ResolveDirectory(const std::string &targetDirectory) override;
24 
25     void EmitCode() override;
26 
27     void EmitPassthroughProxySourceFile();
28 
29     void EmitPassthroughProxyInclusions(StringBuilder &sb);
30 
31     void EmitPassthroughGetInstanceMethod(StringBuilder &sb);
32 
33     void EmitPassthroughReleaseInstanceMethod(StringBuilder &sb);
34 
35     void EmitProxySourceFile();
36 
37     void EmitProxyDefinition(StringBuilder &sb);
38 
39     void EmitProxyInclusions(StringBuilder &sb);
40 
41     void GetHeaderOtherLibInclusions(HeaderFile::HeaderFileSet &headerFiles);
42 
43     void EmitProxyCallMethodImpl(StringBuilder &sb);
44 
45     void EmitProxyKernelCallMethodImpl(StringBuilder &sb);
46 
47     void EmitProxyMethodImpls(StringBuilder &sb);
48 
49     void EmitProxyMethodImpl(const AutoPtr<ASTMethod> &method, StringBuilder &sb);
50 
51     void EmitProxyMethodBody(const AutoPtr<ASTMethod> &method, StringBuilder &sb, const std::string &prefix);
52 
53     void EmitCreateBuf(
54         const std::string &dataBufName, const std::string &replyBufName, StringBuilder &sb, const std::string &prefix);
55 
56     void EmitCheckThisPointer(StringBuilder &sb, const std::string &prefix);
57 
58     void EmitWriteInterfaceToken(const std::string &dataBufName, StringBuilder &sb, const std::string &prefix);
59 
60     void EmitWriteFlagOfNeedSetMem(
61         const AutoPtr<ASTMethod> &method, const std::string &dataBufName, StringBuilder &sb, const std::string &prefix);
62 
63     void EmitReleaseBuf(
64         const std::string &dataBufName, const std::string &replyBufName, StringBuilder &sb, const std::string &prefix);
65 
66     void EmitReadProxyMethodParameter(const AutoPtr<ASTParameter> &param, const std::string &parcelName,
67         const std::string &gotoLabel, StringBuilder &sb, const std::string &prefix);
68 
69     void EmitStubCallMethod(const AutoPtr<ASTMethod> &method, StringBuilder &sb, const std::string &prefix);
70 
71     void EmitProxyAsObjectMethodImpl(StringBuilder &sb);
72 
73     void EmitProxyConstruction(StringBuilder &);
74 
75     void EmitProxyExternalMethodImpl(StringBuilder &sb);
76 
77 	// the get method for getting kernel driver client object
78     void EmitKernelProxyGetMethodImpl(StringBuilder &sb);
79 
80     void EmitKernelProxyGetInstanceMethodImpl(const std::string &objName, const std::string &serMajorName,
81         const std::string &serMinorName, const std::string &remoteName, const std::string &serviceName,
82         StringBuilder &sb);
83 
84     // the release metod for releasing kernel driver client object
85     void EmitKernelProxyReleaseMethodImpl(const std::string &remoteName, const std::string &recycleFuncName,
86         StringBuilder &sb);
87 
88     // the get method for getting interface object
89     void EmitIfaceProxyGetMethodImpl(const std::string &objName, const std::string &serMajorName,
90         const std::string &serMinorName, const std::string &remoteName, StringBuilder &sb);
91 
92     // the release metod for releasing interface obj
93     void EmitIfaceProxyReleaseMethodImpl(
94         const std::string &remoteName, const std::string &recycleFuncName, StringBuilder &sb);
95 
96     void EmitCbProxyReleaseMethodImpl(
97         const std::string &remoteName, const std::string &recycleFuncName, StringBuilder &sb);
98 
99     // the get method for getting driver client object
100     void EmitProxyGetMethodImpl(StringBuilder &sb);
101 
102     void EmitProxyGetInstanceMethodImpl(const std::string &objName, const std::string &serMajorName,
103         const std::string &serMinorName, const std::string &remoteName, const std::string &serviceName,
104         StringBuilder &sb);
105 
106     void EmitProxyGetRemoteService(
107         const std::string &remoteName, const std::string &serviceName, StringBuilder &sb, const std::string &prefix);
108 
109     void EmitProxySetInterfaceDesc(const std::string &remoteName, const std::string &recycleFuncName,
110         StringBuilder &sb, const std::string &prefix);
111 
112     void EmitProxyCreateProxyObject(const std::string &clientObjName, const std::string &remoteName,
113         const std::string &recycleFuncName, StringBuilder &sb, const std::string &prefix);
114 
115     void EmitProxyCheckVersion(const std::string &clientObjName, const std::string &serMajorName,
116         const std::string &serMinorName, StringBuilder &sb, const std::string &prefix);
117 
118     // the release metod for releasing driver client obj
119     void EmitProxyReleaseMethodImpl(StringBuilder &sb);
120 
121     void EmitProxyReleaseInstanceMethodImpl(const std::string &serviceName, const std::string &remoteName,
122         const std::string &recycleFuncName, StringBuilder &sb);
123 
124     void EmitProxyLoadOrUnLoadHdiImpl(const std::string &serviceName, bool isLoad, StringBuilder &sb,
125         const std::string &prefix);
126 
127     void GetUtilMethods(UtilMethodMap &methods) override;
128 
129     std::vector<std::string> freeObjStatements_;
130 };
131 } // namespace HDI
132 } // namespace OHOS
133 
134 #endif // OHOS_HDI_C_CLIENT_PROXY_CODE_EMITTER_H