From: Hwankyu Jhun Date: Tue, 11 Jun 2024 02:34:58 +0000 (+0900) Subject: Add a new option for inhouse developers X-Git-Tag: accepted/tizen/8.0/unified/20240619.075732~5 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=99c98404137dcb78d5aee3ad4b90af7cc04f7f93;p=platform%2Fcore%2Fappfw%2Ftidl.git Add a new option for inhouse developers The 'extension' options is added. It provides the function that checks whether the pending request exists or not. Change-Id: Iab71b0dc8fc5ef7c2d80dd721ed17dc4682f381a Signed-off-by: Hwankyu Jhun --- diff --git a/idlc/default_generator.cc b/idlc/default_generator.cc index 41db8a1..94c7fad 100644 --- a/idlc/default_generator.cc +++ b/idlc/default_generator.cc @@ -96,7 +96,7 @@ void DefaultGenerator::Generate(std::shared_ptr options, void DefaultGenerator::GenCStubCode(std::shared_ptr options, const Parser& ps) { - CStubHeaderGen stub_header(ps.GetDoc()); + CStubHeaderGen stub_header(ps.GetDoc(), options); stub_header.EnableNamespace(options->HasNamespace()); stub_header.EnableProxy(false); stub_header.Run(options->GetOutput() + ".h"); diff --git a/idlc/gen/c_gen_base.h b/idlc/gen/c_gen_base.h index 2920242..ab0d93c 100644 --- a/idlc/gen/c_gen_base.h +++ b/idlc/gen/c_gen_base.h @@ -59,7 +59,8 @@ class CGeneratorBase : public Generator { const std::map>& GetStructures(); void GenVersion(std::ofstream& stream); - virtual void GenIncludeDefaultHeaders(std::ofstream& stream, bool body = true); + virtual void GenIncludeDefaultHeaders(std::ofstream& stream, + bool body = true); void GenGNUSourceDefinition(std::ofstream& stream); virtual std::string GetHandlePrefix(); std::string RemoveLastSpaces(const std::string& str); diff --git a/idlc/gen/c_stub_body_gen.cc b/idlc/gen/c_stub_body_gen.cc index d92af42..61195e9 100644 --- a/idlc/gen/c_stub_body_gen.cc +++ b/idlc/gen/c_stub_body_gen.cc @@ -31,6 +31,7 @@ void CStubBodyGen::OnInitGen(std::ofstream& stream) { GenGNUSourceDefinition(stream); GenIncludeDefaultHeaders(stream); GenIncludeHeader(stream); + GenIncludeInternalHeader(stream); GenLogTag(stream, std::string("RPC_PORT_STUB")); GenLogDefinition(stream); GenVersionDefinition(stream); @@ -48,6 +49,11 @@ void CStubBodyGen::OnInitGen(std::ofstream& stream) { void CStubBodyGen::OnFiniGen(std::ofstream& stream) { } +void CStubBodyGen::GenIncludeInternalHeader(std::ofstream& stream) { + if (options_->UseExtension()) + stream << CB_INTENRAL_HEADER_INCLUSION; +} + // @see #CB_THREAD_ENABLE_DEF void CStubBodyGen::GenThreadEnableDefinition(std::ofstream& stream) { if (!options_->IsThreadEnabled()) @@ -271,6 +277,9 @@ void CStubBodyGen::GenInterface(std::ofstream& stream, const Interface& iface) { GenInterfaceCallbackPortCheck(stream, iface); GenInterfaceBase(stream, iface); + + if (options_->UseExtension()) + GenInterfaceExtensionBase(stream, iface); } // @see #CB_INTERFACE_CONTEXT_BASE @@ -729,4 +738,12 @@ void CStubBodyGen::GenInterfaceBase(std::ofstream& stream, stream << SmartIndent(code); } +void CStubBodyGen::GenInterfaceExtensionBase(std::ofstream& stream, + const Interface& iface) { + std::string code( + ReplaceAll(CB_INTERFACE_EXTENSION_BASE, + {{"", GetHandlePrefix()}, {"", iface.GetID()}})); + stream << SmartIndent(code); +} + } // namespace tidl diff --git a/idlc/gen/c_stub_body_gen.h b/idlc/gen/c_stub_body_gen.h index b8358e8..f65e8c9 100644 --- a/idlc/gen/c_stub_body_gen.h +++ b/idlc/gen/c_stub_body_gen.h @@ -35,6 +35,7 @@ class CStubBodyGen : public CBodyGeneratorBase { void OnFiniGen(std::ofstream& stream) override; private: + void GenIncludeInternalHeader(std::ofstream& stream); void GenThreadEnableDefinition(std::ofstream& stream); void GenInterfaceMethodHandlerType(std::ofstream& stream); void GenInterfaceEnums(std::ofstream& stream); @@ -52,6 +53,7 @@ class CStubBodyGen : public CBodyGeneratorBase { void GenInterfaceCallbackPortCheckDef(std::ofstream& stream, const Interface& iface); void GenInterfaceBaseDef(std::ofstream& stream, const Interface& iface); + void GenInterfaceExtensionDef(std::ofstream& stream); void GenInterfaces(std::ofstream& stream); void GenInterface(std::ofstream& stream, const Interface& iface); @@ -64,6 +66,7 @@ class CStubBodyGen : public CBodyGeneratorBase { void GenInterfaceCallbackPortCheck(std::ofstream& stream, const Interface& iface); void GenInterfaceBase(std::ofstream& stream, const Interface& iface); + void GenInterfaceExtensionBase(std::ofstream& stream, const Interface& iface); std::string GenMethodEnums(const Interface& iface); std::string GenDelegateEnums(const Interface& iface); diff --git a/idlc/gen/c_stub_body_gen_cb.h b/idlc/gen/c_stub_body_gen_cb.h index c1214fc..fe54947 100644 --- a/idlc/gen/c_stub_body_gen_cb.h +++ b/idlc/gen/c_stub_body_gen_cb.h @@ -1206,4 +1206,28 @@ if (ret != RPC_PORT_ERROR_NONE) { } )__c_cb"; +constexpr const char CB_INTENRAL_HEADER_INCLUSION[] = +R"__c_cb( +#include +)__c_cb"; + +/** + * The name of the interface. + */ +constexpr const char CB_INTERFACE_EXTENSION_BASE[] = +R"__c_cb( +bool __has_pending_request(void) +{ + bool has_request = false; + + if (__.stub == nullptr) { + _E("Invalid context"); + return has_request; + } + + rpc_port_stub_has_pending_request(__.stub, &has_request); + return has_request; +} +)__c_cb"; + #endif // IDLC_C_GEN_C_STUB_BODY_GEN_CB_H_ diff --git a/idlc/gen/c_stub_header_gen.cc b/idlc/gen/c_stub_header_gen.cc index 3177368..45cf26c 100644 --- a/idlc/gen/c_stub_header_gen.cc +++ b/idlc/gen/c_stub_header_gen.cc @@ -22,8 +22,9 @@ namespace { namespace tidl { -CStubHeaderGen::CStubHeaderGen(std::shared_ptr doc) - : CHeaderGeneratorBase(doc) {} +CStubHeaderGen::CStubHeaderGen(std::shared_ptr doc, + std::shared_ptr options) + : CHeaderGeneratorBase(doc), options_(std::move(options)) {} void CStubHeaderGen::OnInitGen(std::ofstream& stream) { GenVersion(stream); @@ -156,6 +157,9 @@ void CStubHeaderGen::GenInterface(std::ofstream& stream, } GenInterfaceBase(stream, iface); + + if (options_->UseExtension()) + GenInterfaceExtensionBase(stream, iface); } // @see #CB_INTERFACE_CONTEXT_BASE @@ -229,4 +233,12 @@ void CStubHeaderGen::GenInterfaceBase(std::ofstream& stream, stream << SmartIndent(code); } +void CStubHeaderGen::GenInterfaceExtensionBase(std::ofstream& stream, + const Interface& iface) { + std::string code( + ReplaceAll(CB_INTERFACE_EXTENSION_BASE, + {{"", GetHandlePrefix()}, {"", iface.GetID()}})); + stream << SmartIndent(code); +} + } // namespace tidl diff --git a/idlc/gen/c_stub_header_gen.h b/idlc/gen/c_stub_header_gen.h index 15f7336..cfb77f1 100644 --- a/idlc/gen/c_stub_header_gen.h +++ b/idlc/gen/c_stub_header_gen.h @@ -21,12 +21,14 @@ #include #include "idlc/gen/c_header_gen_base.h" +#include "idlc/options.h" namespace tidl { class CStubHeaderGen : public CHeaderGeneratorBase { public: - explicit CStubHeaderGen(std::shared_ptr doc); + explicit CStubHeaderGen(std::shared_ptr doc, + std::shared_ptr options); virtual ~CStubHeaderGen() = default; void OnInitGen(std::ofstream& stream) override; @@ -50,11 +52,15 @@ class CStubHeaderGen : public CHeaderGeneratorBase { void GenInterfaceDelegateBase(std::ofstream& stream, const Interface& iface, const Declaration& decl); void GenInterfaceBase(std::ofstream& stream, const Interface& iface); + void GenInterfaceExtensionBase(std::ofstream& stream, const Interface& iface); std::string GenDelegateParams(const Interface& iface, const Declaration& decl); std::string GenMethodParams(const Interface& iface, const Declaration& decl); std::string GenMethodCallbackDecls(const Interface& iface); + + private: + std::shared_ptr options_; }; } // namespace tidl diff --git a/idlc/gen/c_stub_header_gen_cb.h b/idlc/gen/c_stub_header_gen_cb.h index ee6c9b9..99b9508 100644 --- a/idlc/gen/c_stub_header_gen_cb.h +++ b/idlc/gen/c_stub_header_gen_cb.h @@ -365,4 +365,18 @@ R"__c_cb( ___cb ; /**< This callback function is invoked when the request is delivered. */ )__c_cb"; +/** + * The prefix of the interface. + * The name of the interface. + */ +constexpr const char CB_INTERFACE_EXTENSION_BASE[] = +R"__c_cb( +/** + * @brief Checks whether the pending request exists or not. + * + * @return @c true if the pending request exists, @c false otherwise. + */ +bool __has_pending_request(void); +)__c_cb"; + #endif // IDLC_C_GEN_C_STUB_HEADER_GEN_CB_H_ diff --git a/idlc/gen/cpp_stub_body_gen.cc b/idlc/gen/cpp_stub_body_gen.cc index 68676e1..0b17100 100644 --- a/idlc/gen/cpp_stub_body_gen.cc +++ b/idlc/gen/cpp_stub_body_gen.cc @@ -42,6 +42,9 @@ void CppStubBodyGen::OnInitGen(std::ofstream& stream) { << "#include " << NLine(1) << NLine(1) << "#include \"" << header_file << "\"" << NLine(2); + if (options_->UseExtension()) + stream << CB_INTERNAL_HEADER_INCLUSION; + GenLogTag(stream, "RPC_PORT_STUB"); GenLogDefinition(stream); GenVersionDefinition(stream); @@ -83,7 +86,7 @@ void CppStubBodyGen::GenInterfaces(std::ofstream& stream) { } void CppStubBodyGen::GenInterface(std::ofstream& stream, - const Interface& iface) { + const Interface& iface) { GenServiceBase(stream, iface); GenBodyCallbacks(stream, iface, false); GenDefaultMethods(stream, iface); @@ -130,6 +133,9 @@ void CppStubBodyGen::GenDefaultMethods(std::ofstream& stream, stream << ReplaceAll(CB_DEFAULT_THREAD_METHODS, "##", iface.GetID()); stream << ReplaceAll(CB_DEFAULT_METHODS, "##", iface.GetID()); + + if (options_->UseExtension()) + stream << ReplaceAll(CB_INTERFACE_EXTENSION_BASE, "", iface.GetID()); } void CppStubBodyGen::GenReceivedEvent(std::ofstream& stream, diff --git a/idlc/gen/cpp_stub_body_gen_cb.h b/idlc/gen/cpp_stub_body_gen_cb.h index 185248d..a544ff0 100644 --- a/idlc/gen/cpp_stub_body_gen_cb.h +++ b/idlc/gen/cpp_stub_body_gen_cb.h @@ -270,4 +270,21 @@ void $$::ServiceBase::Disconnect() { } )__cpp_cb"; +constexpr const char CB_INTERNAL_HEADER_INCLUSION[] = +R"__cpp_cb( +#include +)__cpp_cb"; + +/** + * The interface name. + */ +constexpr const char CB_INTERFACE_EXTENSION_BASE[] = +R"__cpp_cb( +bool ::HasPendingRequest() const { + bool has_request = false; + rpc_port_stub_has_pending_request(stub_, &has_request); + return has_request; +} +)__cpp_cb"; + #endif // IDLC_CPP_GEN_CPP_STUB_BODY_GEN_CB_H_ diff --git a/idlc/gen/cpp_stub_header_gen.cc b/idlc/gen/cpp_stub_header_gen.cc index 86cc340..72a19dc 100644 --- a/idlc/gen/cpp_stub_header_gen.cc +++ b/idlc/gen/cpp_stub_header_gen.cc @@ -121,6 +121,9 @@ void CppStubHeaderGen::GenServiceBase(std::ofstream& stream, void CppStubHeaderGen::GenPublicMethods(std::ofstream& stream, const Interface& iface) { stream << ReplaceAll(CB_PUBLIC_METHODS, "##", iface.GetID()); + + if (options_->UseExtension()) + stream << CB_INTERFACE_EXTENSION_BASE; } } // namespace tidl diff --git a/idlc/gen/cpp_stub_header_gen_cb.h b/idlc/gen/cpp_stub_header_gen_cb.h index 49158c2..a618246 100644 --- a/idlc/gen/cpp_stub_header_gen_cb.h +++ b/idlc/gen/cpp_stub_header_gen_cb.h @@ -312,4 +312,9 @@ R"__cpp_cb( )__cpp_cb"; +constexpr const char CB_INTERFACE_EXTENSION_BASE[] = +R"__cpp_cb( + bool HasPendingRequest() const; +)__cpp_cb"; + #endif // IDLC_CPP_GEN_CPP_STUB_HEADER_GEN_CB_H_ diff --git a/idlc/gen/version2/c_stub_body_generator.cc b/idlc/gen/version2/c_stub_body_generator.cc index 4cb231c..3cedd41 100644 --- a/idlc/gen/version2/c_stub_body_generator.cc +++ b/idlc/gen/version2/c_stub_body_generator.cc @@ -35,6 +35,7 @@ void CStubBodyGenerator::OnInitGen(std::ofstream& stream) { GenGNUSourceDefinition(stream); GenIncludeDefaultHeaders(stream); GenIncludePrivateHeaders(stream); + GenIncludeInternalHeaders(stream); GenIncludeLemHeaders(stream); GenIncludeHeader(stream); GenLogTag(stream, std::string("RPC_PORT_STUB")); @@ -113,6 +114,10 @@ void CStubBodyGenerator::GenIncludePrivateHeaders(std::ofstream& stream) { stream << CB_PRIVATE_HEADERS; } +void CStubBodyGenerator::GenIncludeInternalHeaders(std::ofstream& stream) { + if (options_->UseExtension()) stream << CB_INTERNAL_HEADER_INCLUSION; +} + void CStubBodyGenerator::GenDelegateDefinition(std::ofstream& stream) { if (HasDelegate()) stream << SmartIndent(CB_DELEGATE_DEFS); @@ -334,6 +339,7 @@ void CStubBodyGenerator::GenInterface(std::ofstream& stream, GenInterfaceCallbackPortCheck(stream, iface); GenInterfaceBase(stream, iface); + GenInterfaceExtensionBase(stream, iface); } // @see #CB_INTERFACE_CONTEXT_BASE @@ -796,5 +802,17 @@ void CStubBodyGenerator::GenInterfaceBase(std::ofstream& stream, .Out(stream); } +// @see #CB_INTERFACE_EXTENSION_BASE +void CStubBodyGenerator::GenInterfaceExtensionBase(std::ofstream& stream, + const Interface& iface) { + if (options_->UseExtension()) { + ReplaceAll(CB_INTERFACE_EXTENSION_BASE) + .Change("", GetHandlePrefix()) + .Change("", iface.GetID()) + .Transform([&](std::string code) { return SmartIndent(code); }) + .Out(stream); + } +} + } // namespace version2 } // namespace tidl diff --git a/idlc/gen/version2/c_stub_body_generator.hh b/idlc/gen/version2/c_stub_body_generator.hh index 645bcce..e340ba3 100644 --- a/idlc/gen/version2/c_stub_body_generator.hh +++ b/idlc/gen/version2/c_stub_body_generator.hh @@ -37,6 +37,7 @@ class CStubBodyGenerator : public CBodyGeneratorBase { private: void GenIncludePrivateHeaders(std::ofstream& stream); + void GenIncludeInternalHeaders(std::ofstream& stream); void GenThreadEnableDefinition(std::ofstream& stream); void GenInterfaceMethodHandlerType(std::ofstream& stream); void GenInterfaceEnums(std::ofstream& stream); @@ -72,6 +73,7 @@ class CStubBodyGenerator : public CBodyGeneratorBase { void GenInterfaceCallbackPortCheck(std::ofstream& stream, const Interface& iface); void GenInterfaceBase(std::ofstream& stream, const Interface& iface); + void GenInterfaceExtensionBase(std::ofstream& stream, const Interface& iface); std::string GenMethodEnums(const Interface& iface); std::string GenDelegateEnums(const Interface& iface); diff --git a/idlc/gen/version2/c_stub_body_generator_cb.hh b/idlc/gen/version2/c_stub_body_generator_cb.hh index fafe518..748217f 100644 --- a/idlc/gen/version2/c_stub_body_generator_cb.hh +++ b/idlc/gen/version2/c_stub_body_generator_cb.hh @@ -2320,6 +2320,31 @@ EXPORT_API int rpc_port_stub__lem__send(void *context, c } )__c_cb"; +constexpr const char CB_INTERNAL_HEADER_INCLUSION[] = +R"__c_cb( +#include +)__c_cb"; + +/** + * The prefix of the interface. + * The name of the interface. + */ +constexpr const char CB_INTERFACE_EXTENSION_BASE[] = +R"__c_cb( +EXPORT_API bool __has_pending_request(void) +{ + bool has_request = false; + + if (__.stub == nullptr) { + _E("Invalid context"); + return has_request; + } + + rpc_port_stub_has_pending_request(__.stub, &has_request); + return has_request; +} +)__c_cb"; + } // namespace version2 } // namespace tidl diff --git a/idlc/gen/version2/c_stub_header_generator.cc b/idlc/gen/version2/c_stub_header_generator.cc index da089dc..62c9889 100644 --- a/idlc/gen/version2/c_stub_header_generator.cc +++ b/idlc/gen/version2/c_stub_header_generator.cc @@ -17,12 +17,14 @@ #include "idlc/gen/version2/c_stub_header_generator.hh" #include "idlc/gen/version2/c_stub_header_generator_cb.hh" +#include "idlc/options.h" namespace tidl { namespace version2 { -CStubHeaderGenerator::CStubHeaderGenerator(std::shared_ptr doc) - : CHeaderGeneratorBase(doc) {} +CStubHeaderGenerator::CStubHeaderGenerator(std::shared_ptr doc, + std::shared_ptr options) + : CHeaderGeneratorBase(doc), options_(std::move(options)) {} void CStubHeaderGenerator::OnInitGen(std::ofstream& stream) { GenVersion(stream); @@ -156,6 +158,7 @@ void CStubHeaderGenerator::GenInterface(std::ofstream& stream, } GenInterfaceBase(stream, iface); + GenInterfaceExtensionBase(stream, iface); } // @see #CB_INTERFACE_CONTEXT_BASE @@ -224,5 +227,17 @@ void CStubHeaderGenerator::GenInterfaceBase(std::ofstream& stream, .Out(stream); } +// @see #CB_INTERFACE_EXTENSION_BASE +void CStubHeaderGenerator::GenInterfaceExtensionBase(std::ofstream& stream, + const Interface& iface) { + if (options_->UseExtension()) { + ReplaceAll(CB_INTERFACE_EXTENSION_BASE) + .Change("", GetHandlePrefix()) + .Change("", iface.GetID()) + .Transform([&](std::string code) { return SmartIndent(code); }) + .Out(stream); + } +} + } // namespace version2 } // namespace tidl diff --git a/idlc/gen/version2/c_stub_header_generator.hh b/idlc/gen/version2/c_stub_header_generator.hh index 05b57c0..209a0e5 100644 --- a/idlc/gen/version2/c_stub_header_generator.hh +++ b/idlc/gen/version2/c_stub_header_generator.hh @@ -21,13 +21,15 @@ #include #include "idlc/gen/version2/c_header_generator_base.hh" +#include "idlc/options.h" namespace tidl { namespace version2 { class CStubHeaderGenerator : public CHeaderGeneratorBase { public: - explicit CStubHeaderGenerator(std::shared_ptr doc); + CStubHeaderGenerator(std::shared_ptr doc, + std::shared_ptr options); virtual ~CStubHeaderGenerator() = default; void OnInitGen(std::ofstream& stream) override; @@ -52,11 +54,15 @@ class CStubHeaderGenerator : public CHeaderGeneratorBase { void GenInterfaceDelegateBase(std::ofstream& stream, const Interface& iface, const Declaration& decl); void GenInterfaceBase(std::ofstream& stream, const Interface& iface); + void GenInterfaceExtensionBase(std::ofstream& stream, const Interface& iface); std::string GenDelegateParams(const Interface& iface, const Declaration& decl); std::string GenMethodParams(const Interface& iface, const Declaration& decl); std::string GenMethodCallbackDecls(const Interface& iface); + + private: + std::shared_ptr options_; }; } // namespace version2 diff --git a/idlc/gen/version2/c_stub_header_generator_cb.hh b/idlc/gen/version2/c_stub_header_generator_cb.hh index e98f2fc..003fbac 100644 --- a/idlc/gen/version2/c_stub_header_generator_cb.hh +++ b/idlc/gen/version2/c_stub_header_generator_cb.hh @@ -368,6 +368,15 @@ R"__c_cb( ___cb ; /**< This callback function is invoked when the request is delivered. */ )__c_cb"; +/** + * The prefix of the interface. + * The name of the interface. + */ +constexpr const char CB_INTERFACE_EXTENSION_BASE[] = +R"__c_cb( +bool __has_pending_request(void); +)__c_cb"; + } // namespace version2 } // namespace tidl diff --git a/idlc/gen/version2/cpp_stub_body_generator.cc b/idlc/gen/version2/cpp_stub_body_generator.cc index 793d54d..5072c75 100644 --- a/idlc/gen/version2/cpp_stub_body_generator.cc +++ b/idlc/gen/version2/cpp_stub_body_generator.cc @@ -34,6 +34,7 @@ void CppStubBodyGenerator::OnInitGen(std::ofstream& stream) { GenVersion(stream); GenIncludeStubBodyHeader(stream); GenIncludeDefaultHeaders(stream); + GenIncludeInternalHeader(stream); GenLogTag(stream, "RPC_PORT_STUB"); GenLogDefinition(stream); GenVersionDefinition(stream); @@ -58,6 +59,10 @@ void CppStubBodyGenerator::GenIncludeStubBodyHeader(std::ofstream& stream) { .Out(stream); } +void CppStubBodyGenerator::GenIncludeInternalHeader(std::ofstream& stream) { + if (options_->UseExtension()) stream << CB_INTERNAL_HEADER_INCLUSION; +} + void CppStubBodyGenerator::GenNamespace(std::ofstream& stream) { ReplaceAll(CB_NAMESPACE_STUB) .ChangeToLower("", GetFileNamespace()) @@ -134,6 +139,7 @@ std::string CppStubBodyGenerator::GenInterfaces() { auto& iface = static_cast(*block); code += GenInterface(iface) + NLine(1); + code += GenInterfaceExtensionBase(iface) + NLine(1); } return code; @@ -344,5 +350,15 @@ std::string CppStubBodyGenerator::GenInterfaceImplServiceBaseSetPrivilegeMap( return RemoveLine(code); } +std::string CppStubBodyGenerator::GenInterfaceExtensionBase( + const Interface& iface) { + std::string code; + if (options_->UseExtension()) { + code += + ReplaceAll(CB_INTERFACE_EXTENSION_BASE, "", iface.GetID()); + } + return code; +} + } // namespace version2 } // namespace tidl diff --git a/idlc/gen/version2/cpp_stub_body_generator.hh b/idlc/gen/version2/cpp_stub_body_generator.hh index 90a7353..1e32865 100644 --- a/idlc/gen/version2/cpp_stub_body_generator.hh +++ b/idlc/gen/version2/cpp_stub_body_generator.hh @@ -36,6 +36,7 @@ class CppStubBodyGenerator : public CppGeneratorBase { void OnFiniGen(std::ofstream& stream) override; private: + void GenIncludeInternalHeader(std::ofstream& stream); void GenIncludeStubBodyHeader(std::ofstream& stream); void GenLemAnonymousNamespace(std::ofstream& stream); std::string GenLemContext(); @@ -58,6 +59,7 @@ class CppStubBodyGenerator : public CppGeneratorBase { std::string GenInterfaceServiceBaseSerialize(const Declaration& decl); std::string GenInterfaceImplServiceBaseSetPrivilegeMap( const Interface& iface); + std::string GenInterfaceExtensionBase(const Interface& iface); private: std::shared_ptr options_; diff --git a/idlc/gen/version2/cpp_stub_body_generator_cb.hh b/idlc/gen/version2/cpp_stub_body_generator_cb.hh index ed24abe..55bf454 100644 --- a/idlc/gen/version2/cpp_stub_body_generator_cb.hh +++ b/idlc/gen/version2/cpp_stub_body_generator_cb.hh @@ -754,6 +754,24 @@ EXPORT_API int rpc_port_stub__lem__send(void* context, rpc } )__cpp_cb"; +constexpr const char CB_INTERNAL_HEADER_INCLUSION[] = +R"__cpp_cb( +#include +)__cpp_cb"; + +/** + * The class name of the interface. + */ +constexpr const char CB_INTERFACE_EXTENSION_BASE[] = +R"__cpp_cb( +bool ::HasPendingRequest() const { + bool has_request = false; + rpc_port_stub_has_pending_request(stub_, &has_request); + return has_request; +} + +)__cpp_cb"; + } // namespace version2 } // namespace tidl diff --git a/idlc/gen/version2/cpp_stub_header_generator.cc b/idlc/gen/version2/cpp_stub_header_generator.cc index 9453b42..20d7773 100644 --- a/idlc/gen/version2/cpp_stub_header_generator.cc +++ b/idlc/gen/version2/cpp_stub_header_generator.cc @@ -82,11 +82,12 @@ std::string CppStubHeaderGenerator::GenInterface(const Interface& iface) { .Change("", GenInterfaceCallbacks(iface)) .Change("", GenEnumerations(iface.GetEnums())) .Change("", - GenInterfaceServiceBaseMethods(iface)) + GenInterfaceServiceBaseMethods(iface)) .Change("", - GenInterfaceServiceBaseDispatchFuncs(iface)) + GenInterfaceServiceBaseDispatchFuncs(iface)) .Change("", - GenInterfaceServiceBaseImplThreadMember()) + GenInterfaceServiceBaseImplThreadMember()) + .Change("", GenInterfaceExtensionBase()) .Change("", GenMethodIds(iface)) .Change("", GenDelegateIds(iface))); } @@ -150,5 +151,11 @@ std::string CppStubHeaderGenerator::GenInterfaceServiceBaseImplThreadMember() { return ""; } +std::string CppStubHeaderGenerator::GenInterfaceExtensionBase() { + if (options_->UseExtension()) return std::string(CB_INTERFACE_EXTENSION_BASE); + + return ""; +} + } // namespace version2 } // namespace tidl diff --git a/idlc/gen/version2/cpp_stub_header_generator.hh b/idlc/gen/version2/cpp_stub_header_generator.hh index e124fc7..7c4277d 100644 --- a/idlc/gen/version2/cpp_stub_header_generator.hh +++ b/idlc/gen/version2/cpp_stub_header_generator.hh @@ -45,6 +45,7 @@ class CppStubHeaderGenerator : public CppGeneratorBase { std::string GenInterfaceServiceBaseMethods(const Interface& iface); std::string GenInterfaceServiceBaseDispatchFuncs(const Interface& iface); std::string GenInterfaceServiceBaseImplThreadMember(); + std::string GenInterfaceExtensionBase(); private: std::shared_ptr options_; diff --git a/idlc/gen/version2/cpp_stub_header_generator_cb.hh b/idlc/gen/version2/cpp_stub_header_generator_cb.hh index 562491a..7049129 100644 --- a/idlc/gen/version2/cpp_stub_header_generator_cb.hh +++ b/idlc/gen/version2/cpp_stub_header_generator_cb.hh @@ -352,7 +352,7 @@ class : public LocalExecution::IEvent { const std::list>& GetServices() const { return services_; } - + private: @@ -442,6 +442,15 @@ class LocalExecution { }; )__cpp_cb"; +constexpr const char CB_INTERFACE_EXTENSION_BASE[] = +R"__cpp_cb( + /// + /// Checks whether the pending request exists or not. + /// + /// True if the pending request exists, false otherwise + bool HasPendingRequest() const; +)__cpp_cb"; + } // namespace version2 } // namespace tidl diff --git a/idlc/options.cc b/idlc/options.cc index 2d819a6..de4b5d9 100644 --- a/idlc/options.cc +++ b/idlc/options.cc @@ -41,6 +41,7 @@ Additional Options: -t, --thread Generate thread code (Stub only). -c, --cion Generate CION code. -m, --mqtt Generate MQTT code. + -e, --extension Use extension version (for inhouse developers). Application Options: -p, --proxy Generate proxy code @@ -84,26 +85,25 @@ std::shared_ptr Options::Parse(int argc, char** argv) { auto options = std::shared_ptr(new Options()); int option_index = 0; - struct option long_options[] = { - {"proxy", no_argument, NULL, 'p'}, - {"stub", no_argument, NULL, 's'}, - {"group", no_argument, NULL, 'g'}, - {"version", no_argument, NULL, 'v'}, - {"help", no_argument, NULL, 'h'}, - {"language", required_argument, NULL, 'l'}, - {"input", required_argument, NULL, 'i'}, - {"output", required_argument, NULL, 'o'}, - {"namespace", no_argument, NULL, 'n'}, - {"rpclib", no_argument, NULL, 'r'}, - {"beta", no_argument, NULL, 'b'}, - {"thread", no_argument, NULL, 't'}, - {"cion", no_argument, NULL, 'c'}, - {"mqtt", no_argument, NULL, 'm'}, - {0, 0, 0, 0} - }; + struct option long_options[] = {{"proxy", no_argument, NULL, 'p'}, + {"stub", no_argument, NULL, 's'}, + {"group", no_argument, NULL, 'g'}, + {"version", no_argument, NULL, 'v'}, + {"help", no_argument, NULL, 'h'}, + {"language", required_argument, NULL, 'l'}, + {"input", required_argument, NULL, 'i'}, + {"output", required_argument, NULL, 'o'}, + {"namespace", no_argument, NULL, 'n'}, + {"rpclib", no_argument, NULL, 'r'}, + {"beta", no_argument, NULL, 'b'}, + {"thread", no_argument, NULL, 't'}, + {"cion", no_argument, NULL, 'c'}, + {"mqtt", no_argument, NULL, 'm'}, + {"extension", no_argument, NULL, 'e'}, + {0, 0, 0, 0}}; while (true) { - int c = getopt_long(argc, argv, "tcbpsgvhml:i:o:nr", long_options, + int c = getopt_long(argc, argv, "tcbpsgvhml:i:o:nre", long_options, &option_index); if (c == -1) break; @@ -170,6 +170,10 @@ std::shared_ptr Options::Parse(int argc, char** argv) { options->isMqtt_ = true; break; + case 'e': + options->useExtension_ = true; + break; + default: cmd[CMD_HELP] = 1; } diff --git a/idlc/options.h b/idlc/options.h index 1478f25..eb9329b 100644 --- a/idlc/options.h +++ b/idlc/options.h @@ -54,6 +54,7 @@ class Options { std::string GetOutput() const { return output_; } bool HasNamespace() const { return hasNamespace_; } bool HasRpcPortLib() const { return hasRpcPortLib_; } + bool UseExtension() const { return useExtension_; } private: enum Cmd { @@ -67,6 +68,7 @@ class Options { OPT_OUTPUT, OPT_NAMESPACE, OPT_RPCLIB, + OPT_EXTENSION, OPT_MAX }; @@ -85,6 +87,7 @@ class Options { bool hasRpcPortLib_ = false; bool isBetaEnabled_ = false; bool isThreadEnabled_ = false; + bool useExtension_ = false; Type type_; }; diff --git a/idlc/version2_default_generator.cc b/idlc/version2_default_generator.cc index 2c52c58..0db6d77 100644 --- a/idlc/version2_default_generator.cc +++ b/idlc/version2_default_generator.cc @@ -88,7 +88,7 @@ void DefaultGenerator::Generate(std::shared_ptr options, void DefaultGenerator::GenCStubCode(std::shared_ptr options, const Parser& ps) { - CStubHeaderGenerator stub_header(ps.GetDoc()); + CStubHeaderGenerator stub_header(ps.GetDoc(), options); stub_header.EnableNamespace(options->HasNamespace()); stub_header.SetChannelType( static_cast(options->GetType()));