From 32f0a89a79f79a62483efba93c575843ddc37086 Mon Sep 17 00:00:00 2001 From: Ilho Kim Date: Wed, 31 Aug 2022 15:04:44 +0900 Subject: [PATCH] Apply plugin structure to cion java constructor Change to add a parameter to the constructor Change-Id: Iae27f0978f0432e0f8f5a91717e9d939345ccef5 Signed-off-by: Ilho Kim --- .../aitt_plugin_java_transportable.cc | 29 +++++++++++++++++++ .../aitt_plugin_java_transportable.h | 3 ++ idlc/gen_cion/default_java_transportable.cc | 29 +++++++++++++++++++ idlc/gen_cion/default_java_transportable.h | 3 ++ idlc/gen_cion/java_cion_group_gen.cc | 33 ++++++++++------------ idlc/gen_cion/java_cion_proxy_gen.cc | 32 ++++++++++----------- idlc/gen_cion/java_cion_stub_gen.cc | 31 ++++++++++---------- idlc/gen_cion/java_transportable.h | 5 ++++ 8 files changed, 115 insertions(+), 50 deletions(-) diff --git a/idlc/gen_aitt_plugin/aitt_plugin_java_transportable.cc b/idlc/gen_aitt_plugin/aitt_plugin_java_transportable.cc index f4a4ba5..4760b11 100644 --- a/idlc/gen_aitt_plugin/aitt_plugin_java_transportable.cc +++ b/idlc/gen_aitt_plugin/aitt_plugin_java_transportable.cc @@ -22,6 +22,17 @@ namespace { +std::string ParamsToString(std::vector params) { + std::string res; + for (auto it = params.begin(); it != params.end(); it++) { + res += *it; + if ((it + 1) != params.end()) + res += ", "; + } + + return res; +} + constexpr const char __CLIENT_BASE_CONSTRUCTOR[] = R"__java_cb( /** @@ -78,6 +89,14 @@ R"__java_cb( } )__java_cb"; +constexpr const char __INHERITED_CLASS_CONSTRUCTOR[] = +R"__java_cb( +public $$(, String brokerIp) { + super(, brokerIp); + +} +)__java_cb"; + } // namespace namespace tidl { @@ -114,4 +133,14 @@ std::string AittPluginJavaTransportable::GenOnJoinedEventMethod() const { return __ON_JOINED_EVENT_METHOD; } +std::string AittPluginJavaTransportable::GenInheritedClassConstructor( + std::vector params, std::vector base_class_params, + std::string extra_operation) const { + return std::string(ReplaceAll(__INHERITED_CLASS_CONSTRUCTOR, { + { "", ParamsToString(params) }, + { "", ParamsToString(base_class_params) }, + { "", extra_operation } + })); +} + } // namespace tidl diff --git a/idlc/gen_aitt_plugin/aitt_plugin_java_transportable.h b/idlc/gen_aitt_plugin/aitt_plugin_java_transportable.h index 7c77676..ebe543c 100644 --- a/idlc/gen_aitt_plugin/aitt_plugin_java_transportable.h +++ b/idlc/gen_aitt_plugin/aitt_plugin_java_transportable.h @@ -33,6 +33,9 @@ class AittPluginJavaTransportable : public DefaultJavaTransportable { std::string GenGroupBaseConstructor() const override; std::string GenOnLeftEventMethod() const override; std::string GenOnJoinedEventMethod() const override; + std::string GenInheritedClassConstructor(std::vector params, + std::vector base_class_params, + std::string extra_operation) const override; }; } // namespace tidl diff --git a/idlc/gen_cion/default_java_transportable.cc b/idlc/gen_cion/default_java_transportable.cc index eb03687..e36a865 100644 --- a/idlc/gen_cion/default_java_transportable.cc +++ b/idlc/gen_cion/default_java_transportable.cc @@ -22,6 +22,17 @@ namespace { +std::string ParamsToString(std::vector params) { + std::string res; + for (auto it = params.begin(); it != params.end(); it++) { + res += *it; + if ((it + 1) != params.end()) + res += ", "; + } + + return res; +} + constexpr const char __SERVER_ACCEPT[] = ".acceptRequest(peerInfo);"; constexpr const char __SERVER_STOP[] = ".stop();"; @@ -164,6 +175,14 @@ R"__java_cb( } )__java_cb"; +constexpr const char __INHERITED_CLASS_CONSTRUCTOR[] = +R"__java_cb( +public $$() { + super(); + +} +)__java_cb"; + } // namespace @@ -347,4 +366,14 @@ std::string DefaultJavaTransportable::GenOnJoinedEventMethod() const { return __ON_JOINED_EVENT_METHOD; } +std::string DefaultJavaTransportable::GenInheritedClassConstructor( + std::vector params, std::vector base_class_params, + std::string extra_operation) const { + return std::string(ReplaceAll(__INHERITED_CLASS_CONSTRUCTOR, { + { "", ParamsToString(params) }, + { "", ParamsToString(base_class_params) }, + { "", extra_operation } + })); +} + } // namespace tidl diff --git a/idlc/gen_cion/default_java_transportable.h b/idlc/gen_cion/default_java_transportable.h index 372d971..8f186d5 100644 --- a/idlc/gen_cion/default_java_transportable.h +++ b/idlc/gen_cion/default_java_transportable.h @@ -66,6 +66,9 @@ class DefaultJavaTransportable : public JavaTransportable { std::string GenGroupBaseConstructor() const override; std::string GenOnLeftEventMethod() const override; std::string GenOnJoinedEventMethod() const override; + std::string GenInheritedClassConstructor(std::vector params, + std::vector base_class_params, + std::string extra_operation) const override; }; } // namespace tidl diff --git a/idlc/gen_cion/java_cion_group_gen.cc b/idlc/gen_cion/java_cion_group_gen.cc index b55677b..fc196a2 100644 --- a/idlc/gen_cion/java_cion_group_gen.cc +++ b/idlc/gen_cion/java_cion_group_gen.cc @@ -103,36 +103,33 @@ void JavaCionGroupGen::GenEvent(std::ofstream& stream, const Interface& iface, void JavaCionGroupGen::GenCtor(std::ofstream& stream, const Interface& iface) { bool securityCheck = false; - std::string m = "public $$(Context context, String topicName) {\n"; - - m += Tab(1) + "super(context, topicName, new " - + GetTransportable().Java().GenSecurityType() + "("; + std::string security_inst = "new " + + GetTransportable().Java().GenSecurityType() + "("; for (const auto& attr : iface.GetAttributes()) { if (attr->GetKey() == "ca_path") { - m += "\"" + attr->GetValue() + "\", "; + security_inst += "\"" + attr->GetValue() + "\", "; securityCheck = true; } else if (attr->GetKey() == "cert_path") { - m += "\"" + attr->GetValue() + "\", "; + security_inst += "\"" + attr->GetValue() + "\", "; securityCheck = true; } else if (attr->GetKey() == "private_key") { - m += "\"" + attr->GetValue() + "\", "; + security_inst += "\"" + attr->GetValue() + "\", "; securityCheck = true; } } - auto const pos = m.find_last_of(','); - m = m.substr(0, pos); - - if (securityCheck) - m += "));"; /* super(topicName, new SecurityInfo(ca, cert, private_key) */ - else - m += ");"; /* super(topicName) */ + if (securityCheck) { + security_inst = security_inst.substr(0, security_inst.find_last_of(',')); + security_inst += ")"; + } - m += NLine(1); - m += " this.topicName = topicName;\n"; - m += "}"; - m += NLine(1); + std::string m = GetTransportable().Java().GenInheritedClassConstructor( + { "Context context", "String topicName"}, + (securityCheck ? + std::vector{ "context", "topicName", security_inst } : + std::vector{ "context", "topicName" }), + { "this.topicName = topicName;" }); GenTemplate(AddIndent(TAB_SIZE, m), stream, [&]()->std::string { diff --git a/idlc/gen_cion/java_cion_proxy_gen.cc b/idlc/gen_cion/java_cion_proxy_gen.cc index bd078e7..63f9cb7 100644 --- a/idlc/gen_cion/java_cion_proxy_gen.cc +++ b/idlc/gen_cion/java_cion_proxy_gen.cc @@ -80,35 +80,33 @@ void JavaCionProxyGen::GenInterface(std::ofstream& stream, const Interface& ifac void JavaCionProxyGen::GenCtor(std::ofstream& stream, const Interface& iface) { bool securityCheck = false; - std::string m = "public $$(Context context, String serviceName) {\n"; - - m += Tab(1) + "super(context, serviceName, new " - + GetTransportable().Java().GenSecurityType() + "("; + std::string security_inst = "new " + + GetTransportable().Java().GenSecurityType() + "("; for (const auto& attr : iface.GetAttributes()) { if (attr->GetKey() == "ca_path") { - m += "\"" + attr->GetValue() + "\", "; + security_inst += "\"" + attr->GetValue() + "\", "; securityCheck = true; } else if (attr->GetKey() == "cert_path") { - m += "\"" + attr->GetValue() + "\", "; + security_inst += "\"" + attr->GetValue() + "\", "; securityCheck = true; } else if (attr->GetKey() == "private_key") { - m += "\"" + attr->GetValue() + "\", "; + security_inst += "\"" + attr->GetValue() + "\", "; securityCheck = true; } } - auto const pos = m.find_last_of(','); - m = m.substr(0, pos); - - if (securityCheck) - m += "));"; /* super(serviceName, new SecurityInfo(ca, cert, private_key) */ - else - m += ");"; /* super(serviceName) */ + if (securityCheck) { + security_inst = security_inst.substr(0, security_inst.find_last_of(',')); + security_inst += ")"; + } - m += NLine(1); - m += " this.serviceName = serviceName;\n"; - m += "}"; + std::string m = GetTransportable().Java().GenInheritedClassConstructor( + { "Context context", "String serviceName" }, + (securityCheck ? + std::vector{ "context", "serviceName", security_inst } : + std::vector{ "context", "serviceName"}), + { "this.serviceName = serviceName;" }); GenTemplate(AddIndent(TAB_SIZE, m), stream, [&]()->std::string { diff --git a/idlc/gen_cion/java_cion_stub_gen.cc b/idlc/gen_cion/java_cion_stub_gen.cc index d701044..d547cba 100644 --- a/idlc/gen_cion/java_cion_stub_gen.cc +++ b/idlc/gen_cion/java_cion_stub_gen.cc @@ -276,33 +276,34 @@ void JavaCionStubGen::GenDisconnectedEvent(std::ofstream& stream) { void JavaCionStubGen::GenCtor(std::ofstream& stream, const Interface& iface) { bool securityCheck = false; - std::string m = "public $$(Context context, String serviceName, String displayName) {\n"; - m += Tab(1) + "super(context, serviceName, displayName, new " - + GetTransportable().Java().GenSecurityType() + "("; + std::string security_inst = "new " + + GetTransportable().Java().GenSecurityType() + "("; for (const auto& attr : iface.GetAttributes()) { if (attr->GetKey() == "ca_path") { - m += "\"" + attr->GetValue() + "\", "; + security_inst += "\"" + attr->GetValue() + "\", "; securityCheck = true; } else if (attr->GetKey() == "cert_path") { - m += "\"" + attr->GetValue() + "\", "; + security_inst += "\"" + attr->GetValue() + "\", "; securityCheck = true; } else if (attr->GetKey() == "private_key") { - m += "\"" + attr->GetValue() + "\", "; + security_inst += "\"" + attr->GetValue() + "\", "; securityCheck = true; } } - auto const pos = m.find_last_of(','); - m = m.substr(0, pos); - - if (securityCheck) - m += "));"; /* super(serviceName, displayName, new SecurityInfo(a,b,c)); */ - else - m += ");"; /* super(serviceName, displayName); */ + if (securityCheck) { + security_inst = security_inst.substr(0, security_inst.find_last_of(',')); + security_inst += ")"; + } - m += NLine(1); - m += "}"; + std::string m = GetTransportable().Java().GenInheritedClassConstructor( + { "Context context", "String serviceName", "String displayName" }, + (securityCheck ? + std::vector{ "context", "serviceName", + "displayName", security_inst } : + std::vector{ "context", "serviceName", "displayName"}), + {}); GenTemplate(AddIndent(TAB_SIZE * 1, m), stream, [&]()->std::string { diff --git a/idlc/gen_cion/java_transportable.h b/idlc/gen_cion/java_transportable.h index 4edf1c2..f5b10a7 100644 --- a/idlc/gen_cion/java_transportable.h +++ b/idlc/gen_cion/java_transportable.h @@ -18,6 +18,7 @@ #define IDLC_GEN_CION_JAVA_TRANSPORTABLE_H_ #include +#include namespace tidl { @@ -64,6 +65,10 @@ class JavaTransportable { virtual std::string GenGroupBaseConstructor() const = 0; virtual std::string GenOnLeftEventMethod() const = 0; virtual std::string GenOnJoinedEventMethod() const = 0; + virtual std::string GenInheritedClassConstructor( + std::vector params, + std::vector base_class_params, + std::string extra_operation) const = 0; }; } // namespace tidl -- 2.7.4