Apply plugin structure to cion java constructor 11/280511/5
authorIlho Kim <ilho159.kim@samsung.com>
Wed, 31 Aug 2022 06:04:44 +0000 (15:04 +0900)
committerIlho Kim <ilho159.kim@samsung.com>
Thu, 1 Sep 2022 05:58:11 +0000 (14:58 +0900)
Change to add a parameter to the constructor

Change-Id: Iae27f0978f0432e0f8f5a91717e9d939345ccef5
Signed-off-by: Ilho Kim <ilho159.kim@samsung.com>
idlc/gen_aitt_plugin/aitt_plugin_java_transportable.cc
idlc/gen_aitt_plugin/aitt_plugin_java_transportable.h
idlc/gen_cion/default_java_transportable.cc
idlc/gen_cion/default_java_transportable.h
idlc/gen_cion/java_cion_group_gen.cc
idlc/gen_cion/java_cion_proxy_gen.cc
idlc/gen_cion/java_cion_stub_gen.cc
idlc/gen_cion/java_transportable.h

index f4a4ba5..4760b11 100644 (file)
 
 namespace {
 
+std::string ParamsToString(std::vector<std::string> 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 $$(<PARAMETERS>, String brokerIp) {
+    super(<BASE_CLASS_PARAMETERS>, brokerIp);
+    <EXTRA_OPERATION>
+}
+)__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<std::string> params, std::vector<std::string> base_class_params,
+    std::string extra_operation) const {
+  return std::string(ReplaceAll(__INHERITED_CLASS_CONSTRUCTOR, {
+      { "<PARAMETERS>", ParamsToString(params) },
+      { "<BASE_CLASS_PARAMETERS>", ParamsToString(base_class_params) },
+      { "<EXTRA_OPERATION>", extra_operation }
+  }));
+}
+
 }  // namespace tidl
index 7c77676..ebe543c 100644 (file)
@@ -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<std::string> params,
+      std::vector<std::string> base_class_params,
+      std::string extra_operation) const override;
 };
 
 }  // namespace tidl
index eb03687..e36a865 100644 (file)
 
 namespace {
 
+std::string ParamsToString(std::vector<std::string> 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[] = "<SERVER>.acceptRequest(peerInfo);";
 
 constexpr const char __SERVER_STOP[] = "<SERVER>.stop();";
@@ -164,6 +175,14 @@ R"__java_cb(
     }
 )__java_cb";
 
+constexpr const char __INHERITED_CLASS_CONSTRUCTOR[] =
+R"__java_cb(
+public $$(<PARAMETERS>) {
+    super(<BASE_CLASS_PARAMETERS>);
+    <EXTRA_OPERATION>
+}
+)__java_cb";
+
 
 }  // namespace
 
@@ -347,4 +366,14 @@ std::string DefaultJavaTransportable::GenOnJoinedEventMethod() const {
   return __ON_JOINED_EVENT_METHOD;
 }
 
+std::string DefaultJavaTransportable::GenInheritedClassConstructor(
+    std::vector<std::string> params, std::vector<std::string> base_class_params,
+    std::string extra_operation) const {
+  return std::string(ReplaceAll(__INHERITED_CLASS_CONSTRUCTOR, {
+      { "<PARAMETERS>", ParamsToString(params) },
+      { "<BASE_CLASS_PARAMETERS>", ParamsToString(base_class_params) },
+      { "<EXTRA_OPERATION>", extra_operation }
+  }));
+}
+
 }  // namespace tidl
index 372d971..8f186d5 100644 (file)
@@ -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<std::string> params,
+      std::vector<std::string> base_class_params,
+      std::string extra_operation) const override;
 };
 
 }  // namespace tidl
index b55677b..fc196a2 100644 (file)
@@ -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<std::string>{ "context", "topicName", security_inst } :
+          std::vector<std::string>{ "context", "topicName" }),
+      { "this.topicName = topicName;" });
 
   GenTemplate(AddIndent(TAB_SIZE, m), stream,
     [&]()->std::string {
index bd078e7..63f9cb7 100644 (file)
@@ -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<std::string>{ "context", "serviceName", security_inst } :
+          std::vector<std::string>{ "context", "serviceName"}),
+      { "this.serviceName = serviceName;" });
 
   GenTemplate(AddIndent(TAB_SIZE, m), stream,
     [&]()->std::string {
index d701044..d547cba 100644 (file)
@@ -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<std::string>{ "context", "serviceName",
+              "displayName", security_inst } :
+          std::vector<std::string>{ "context", "serviceName", "displayName"}),
+      {});
 
   GenTemplate(AddIndent(TAB_SIZE * 1, m), stream,
     [&]()->std::string {
index 4edf1c2..f5b10a7 100644 (file)
@@ -18,6 +18,7 @@
 #define IDLC_GEN_CION_JAVA_TRANSPORTABLE_H_
 
 #include <string>
+#include <vector>
 
 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<std::string> params,
+      std::vector<std::string> base_class_params,
+      std::string extra_operation) const = 0;
 };
 
 }  // namespace tidl