• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2024 Huawei Device Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 #ifndef OHOS_IDL_HDI_C_CLIENT_PROXY_CODE_EMITTER_H
17 #define OHOS_IDL_HDI_C_CLIENT_PROXY_CODE_EMITTER_H
18 
19 #include "hdi_c_code_emitter.h"
20 
21 namespace OHOS {
22 namespace Idl {
23 class CClientProxyCodeEmitter : public HDICCodeEmitter {
24 public:
CClientProxyCodeEmitter()25     CClientProxyCodeEmitter() : HDICCodeEmitter(), loadVersionCheck_(false) {}
26 
27     ~CClientProxyCodeEmitter() override = default;
28 
29 private:
30     bool ResolveDirectory(const std::string &targetDirectory) override;
31 
32     void EmitCode() override;
33 
34     void EmitPassthroughProxySourceFile();
35 
36     void EmitPassthroughProxyInclusions(StringBuilder &sb);
37 
38     void EmitPassthroughGetInstanceMethod(StringBuilder &sb) const;
39 
40     void EmitPassthroughReleaseInstanceMethod(StringBuilder &sb) const;
41 
42     void EmitProxySourceFile();
43 
44     void EmitProxyDefinition(StringBuilder &sb) const;
45 
46     void EmitProxyInclusions(StringBuilder &sb);
47 
48     void GetHeaderOtherLibInclusions(HeaderFile::HeaderFileSet &headerFiles) const;
49 
50     void EmitProxyCallMethodImpl(StringBuilder &sb) const;
51 
52     void EmitProxyKernelCallMethodImpl(StringBuilder &sb) const;
53 
54     void EmitProxyMethodImpls(StringBuilder &sb);
55 
56     void EmitProxyMethodImpl(const AutoPtr<ASTMethod> &method, StringBuilder &sb);
57 
58     void EmitProxyMethodBody(const AutoPtr<ASTMethod> &method, StringBuilder &sb, const std::string &prefix);
59 
60     void EmitCreateBuf(const std::string &dataBufName,
61         const std::string &replyBufName, StringBuilder &sb, const std::string &prefix) const;
62 
63     void EmitCheckThisPointer(StringBuilder &sb, const std::string &prefix) const;
64 
65     void EmitWriteInterfaceToken(const std::string &dataBufName, StringBuilder &sb, const std::string &prefix) const;
66 
67     void EmitWriteFlagOfNeedSetMem(const AutoPtr<ASTMethod> &method,
68         const std::string &dataBufName, StringBuilder &sb, const std::string &prefix) const;
69 
70     void EmitReleaseBuf(const std::string &dataBufName,
71         const std::string &replyBufName, StringBuilder &sb, const std::string &prefix) const;
72 
73     void EmitReadProxyMethodParameter(const AutoPtr<ASTParameter> &param, const std::string &gotoLabel,
74         StringBuilder &sb, const std::string &prefix) const;
75 
76     void EmitStubCallMethod(const AutoPtr<ASTMethod> &method, StringBuilder &sb, const std::string &prefix);
77 
78     void EmitProxyAsObjectMethodImpl(StringBuilder &sb) const;
79 
80     void EmitProxyConstruction(StringBuilder &sb) const;
81 
82     void EmitProxyExternalMethodImpl(StringBuilder &sb);
83 
84     void EmitKernelProxyExternalMethodImpl(StringBuilder &sb);
85 
86 	// the get method for getting kernel driver client object
87     void EmitKernelProxyGetMethodImpl(StringBuilder &sb) const;
88 
89     void EmitKernelProxyGetInstanceMethodImpl(const std::string &remoteName, StringBuilder &sb) const;
90 
91     // the release metod for releasing kernel driver client object
92     void EmitKernelProxyReleaseMethodImpl(const std::string &remoteName, const std::string &recycleFuncName,
93         StringBuilder &sb) const;
94 
95     void EmitSerialProxyExternalMethodImpl(StringBuilder &sb);
96 
97     // the get method for getting interface object
98     void EmitIfaceProxyGetMethodImpl(const std::string &serMajorName, const std::string &serMinorName,
99         const std::string &remoteName, StringBuilder &sb);
100 
101     // the release metod for releasing interface obj
102     void EmitIfaceProxyReleaseMethodImpl(
103         const std::string &remoteName, const std::string &recycleFuncName, StringBuilder &sb) const;
104 
105     void EmitCbProxyReleaseMethodImpl(
106         const std::string &remoteName, const std::string &recycleFuncName, StringBuilder &sb) const;
107 
108     void EmitProxyExternalMethod(StringBuilder &sb);
109 
110     // the get method for getting driver client object
111     void EmitProxyGetMethodImpl(StringBuilder &sb) const;
112 
113     void EmitProxyGetInstanceMethodImpl(const std::string &remoteName, const std::string &serviceName,
114         StringBuilder &sb) const;
115 
116     void EmitProxyGetRemoteService(const std::string &remoteName,
117         const std::string &serviceName, StringBuilder &sb, const std::string &prefix) const;
118 
119     void EmitProxySetInterfaceDesc(const std::string &remoteName, const std::string &recycleFuncName,
120         StringBuilder &sb, const std::string &prefix) const;
121 
122     void EmitProxyCreateProxyObject(const std::string &clientObjName, const std::string &remoteName,
123         const std::string &recycleFuncName, StringBuilder &sb, const std::string &prefix) const;
124 
125     void EmitProxyCheckVersion(const std::string &clientObjName, const std::string &serMajorName,
126         const std::string &serMinorName, StringBuilder &sb, const std::string &prefix) const;
127 
128     // the release metod for releasing driver client obj
129     void EmitProxyReleaseMethodImpl(StringBuilder &sb) const;
130 
131     void EmitProxyReleaseInstanceMethodImpl(const std::string &serviceName, const std::string &remoteName,
132         const std::string &recycleFuncName, StringBuilder &sb);
133 
134     void EmitProxyLoadOrUnLoadHdiImpl(const std::string &serviceName, bool isLoad, StringBuilder &sb,
135         const std::string &prefix) const;
136 
137     void EmitUtilMethods(StringBuilder &sb, bool isDecl) override;
138 
139     std::vector<std::string> freeObjStatements_;
140 
141     mutable bool loadVersionCheck_;
142 };
143 } // namespace Idl
144 } // namespace OHOS
145 
146 #endif // OHOS_IDL_HDI_C_CLIENT_PROXY_CODE_EMITTER_H