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_SERVICE_STUB_CODEE_MITTER_H 17 #define OHOS_IDL_HDI_C_SERVICE_STUB_CODEE_MITTER_H 18 19 #include "hdi_c_code_emitter.h" 20 21 namespace OHOS { 22 namespace Idl { 23 class CServiceStubCodeEmitter : public HDICCodeEmitter { 24 public: CServiceStubCodeEmitter()25 CServiceStubCodeEmitter() : HDICCodeEmitter() {} 26 27 ~CServiceStubCodeEmitter() override = default; 28 29 private: 30 bool ResolveDirectory(const std::string &targetDirectory) override; 31 32 void EmitCode() override; 33 34 void EmitServiceStubHeaderFile(); 35 36 void EmitStubHeaderInclusions(StringBuilder &sb); 37 38 void EmitCbServiceStubDef(StringBuilder &sb) const; 39 40 void EmitCbServiceStubMethodsDcl(StringBuilder &sb) const; 41 42 void EmitServiceStubSourceFile(); 43 44 void EmitStubSourceInclusions(StringBuilder &sb); 45 46 void GetSourceOtherLibInclusions(HeaderFile::HeaderFileSet &headerFiles) const; 47 48 // get or release method for driver interface object 49 void EmitExternalMethodImpl(StringBuilder &sb); 50 51 void EmitGetMethodImpl(StringBuilder &sb) const; 52 53 void EmitGetInstanceMehtodImpl(StringBuilder &sb) const; 54 55 void EmitReleaseMethodImpl(StringBuilder &sb) const; 56 57 void EmitReleaseInstanceMethodImpl(StringBuilder &sb) const; 58 59 void EmitServiceStubMethodImpls(StringBuilder &sb, const std::string &prefix); 60 61 void EmitServiceStubMethodImpl(const AutoPtr<ASTMethod> &method, StringBuilder &sb, 62 const std::string &prefix) const; 63 64 void EmitReadFlagVariable(bool readFlag, StringBuilder &sb, const std::string &prefix) const; 65 66 void EmitStubLocalVariable(const AutoPtr<ASTParameter> ¶m, StringBuilder &sb, const std::string &prefix) const; 67 68 void EmitReadStubMethodParameter(const AutoPtr<ASTParameter> ¶m, const std::string &gotoLabel, 69 StringBuilder &sb, const std::string &prefix) const; 70 71 void EmitReadCStringStubMethodParameter(const AutoPtr<ASTParameter> ¶m, const std::string &gotoLabel, 72 StringBuilder &sb, const std::string &prefix, AutoPtr<HdiTypeEmitter> &typeEmitter) const; 73 74 void EmitOutVarMemInitialize(const AutoPtr<ASTParameter> ¶m, const std::string &gotoLabel, StringBuilder &sb, 75 const std::string &prefix) const; 76 77 void EmitStubCallMethod(const AutoPtr<ASTMethod> &method, 78 const std::string &gotoLabel, StringBuilder &sb, const std::string &prefix) const; 79 80 void EmitCallParameter(StringBuilder &sb, const AutoPtr<ASTType> &type, ASTParamAttr::ParamAttr attribute, 81 const std::string &name) const; 82 83 void EmitStubGetVerMethodImpl( 84 const AutoPtr<ASTMethod> &method, StringBuilder &sb, const std::string &prefix) const; 85 86 void EmitStubAsObjectMethodImpl(StringBuilder &sb, const std::string &prefix) const; 87 88 void EmitKernelStubOnRequestMethodImpl(StringBuilder &sb, const std::string &prefix); 89 90 void EmitKernelStubConstruct(StringBuilder &sb) const; 91 92 void EmitStubOnRequestMethodImpl(StringBuilder &sb, const std::string &prefix); 93 94 void EmitStubRemoteDispatcher(StringBuilder &sb) const; 95 96 void EmitStubNewInstance(StringBuilder &sb) const; 97 98 void EmitStubReleaseMethod(StringBuilder &sb) const; 99 100 void EmitStubConstructor(StringBuilder &sb) const; 101 102 void EmitStubRegAndUnreg(StringBuilder &sb) const; 103 104 void EmitUtilMethods(StringBuilder &sb, bool isDecl) override; 105 106 void EmitParamLocalVar(const AutoPtr<ASTParameter> ¶m, StringBuilder &sb, 107 const std::string &prefix) const; 108 109 void EmitErrorHandle(const AutoPtr<ASTMethod> &method, StringBuilder &sb, const std::string &prefix) const; 110 }; 111 } // namespace Idl 112 } // namespace OHOS 113 114 #endif // OHOS_IDL_HDI_C_SERVICE_STUB_CODEE_MITTER_H