Separate generator code from main file 50/296750/5
authorHwankyu Jhun <h.jhun@samsung.com>
Fri, 4 Aug 2023 04:06:14 +0000 (13:06 +0900)
committerHwankyu Jhun <h.jhun@samsung.com>
Mon, 7 Aug 2023 01:41:53 +0000 (10:41 +0900)
The code generators are separated.

Adds:
 - CodeGenerator
 - CionGenerator
 - MqttGenerator
 - DefaultGenerator
 - version2::DefaultGenerator

Change-Id: I0287003d997765a7760ef27486bd1047dc55d916
Signed-off-by: Hwankyu Jhun <h.jhun@samsung.com>
idlc/cion_generator.cc [new file with mode: 0644]
idlc/cion_generator.hh [new file with mode: 0644]
idlc/code_generator.hh [new file with mode: 0644]
idlc/default_generator.cc [new file with mode: 0644]
idlc/default_generator.hh [new file with mode: 0644]
idlc/main.cc
idlc/mqtt_generator.cc [new file with mode: 0644]
idlc/mqtt_generator.hh [new file with mode: 0644]
idlc/version2_default_generator.cc [new file with mode: 0644]
idlc/version2_default_generator.hh [new file with mode: 0644]

diff --git a/idlc/cion_generator.cc b/idlc/cion_generator.cc
new file mode 100644 (file)
index 0000000..81504e4
--- /dev/null
@@ -0,0 +1,308 @@
+/*
+ * Copyright (c) 2023 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "idlc/cion_generator.hh"
+
+#include <utility>
+
+#include "idlc/gen_cion/c_cion_group_body_gen.h"
+#include "idlc/gen_cion/c_cion_group_header_gen.h"
+#include "idlc/gen_cion/c_cion_proxy_body_gen.h"
+#include "idlc/gen_cion/c_cion_proxy_header_gen.h"
+#include "idlc/gen_cion/c_cion_stub_body_gen.h"
+#include "idlc/gen_cion/c_cion_stub_header_gen.h"
+#include "idlc/gen_cion/cpp_cion_group_body_gen.h"
+#include "idlc/gen_cion/cpp_cion_group_header_gen.h"
+#include "idlc/gen_cion/cpp_cion_proxy_body_gen.h"
+#include "idlc/gen_cion/cpp_cion_proxy_header_gen.h"
+#include "idlc/gen_cion/cpp_cion_stub_body_gen.h"
+#include "idlc/gen_cion/cpp_cion_stub_header_gen.h"
+#include "idlc/gen_cion/cs_cion_group_gen.h"
+#include "idlc/gen_cion/cs_cion_proxy_gen.h"
+#include "idlc/gen_cion/cs_cion_stub_gen.h"
+#include "idlc/gen_cion/dart_cion_group_gen.h"
+#include "idlc/gen_cion/dart_cion_proxy_gen.h"
+#include "idlc/gen_cion/dart_cion_stub_gen.h"
+#include "idlc/gen_cion/java_cion_common_gen.h"
+#include "idlc/gen_cion/java_cion_group_gen.h"
+#include "idlc/gen_cion/java_cion_group_repo_gen.h"
+#include "idlc/gen_cion/java_cion_proxy_gen.h"
+#include "idlc/gen_cion/java_cion_proxy_repo_gen.h"
+#include "idlc/gen_cion/java_cion_structure_gen.h"
+#include "idlc/gen_cion/java_cion_stub_gen.h"
+#include "idlc/gen_cion/java_cion_stub_repo_gen.h"
+#include "idlc/gen_cion/java_cion_utility_gen.h"
+#include "idlc/gen_cion/plugin_loader.h"
+
+namespace tidl {
+
+CionGenerator::CionGenerator() {
+  cion_funcs_ = {
+      // Stub
+      {std::make_pair(Options::Type::TYPE_STUB, Options::LANGUAGE_TYPE_C),
+       std::bind(&CionGenerator::GenCionCStubCode, this, std::placeholders::_1,
+                 std::placeholders::_2, std::placeholders::_3)},
+      {std::make_pair(Options::Type::TYPE_STUB, Options::LANGUAGE_TYPE_CPP),
+       std::bind(&CionGenerator::GenCionCppStubCode, this,
+                 std::placeholders::_1, std::placeholders::_2,
+                 std::placeholders::_3)},
+      {std::make_pair(Options::Type::TYPE_STUB, Options::LANGUAGE_TYPE_CSHARP),
+       std::bind(&CionGenerator::GenCionCsharpStubCode, this,
+                 std::placeholders::_1, std::placeholders::_2,
+                 std::placeholders::_3)},
+      {std::make_pair(Options::Type::TYPE_STUB, Options::LANGUAGE_TYPE_JAVA),
+       std::bind(&CionGenerator::GenCionJavaStubCode, this,
+                 std::placeholders::_1, std::placeholders::_2,
+                 std::placeholders::_3)},
+      {std::make_pair(Options::Type::TYPE_STUB, Options::LANGUAGE_TYPE_DART),
+       std::bind(&CionGenerator::GenCionDartStubCode, this,
+                 std::placeholders::_1, std::placeholders::_2,
+                 std::placeholders::_3)},
+
+      // Proxy
+      {std::make_pair(Options::Type::TYPE_PROXY, Options::LANGUAGE_TYPE_C),
+       std::bind(&CionGenerator::GenCionCProxyCode, this, std::placeholders::_1,
+                 std::placeholders::_2, std::placeholders::_3)},
+      {std::make_pair(Options::Type::TYPE_PROXY, Options::LANGUAGE_TYPE_CPP),
+       std::bind(&CionGenerator::GenCionCppProxyCode, this,
+                 std::placeholders::_1, std::placeholders::_2,
+                 std::placeholders::_3)},
+      {std::make_pair(Options::Type::TYPE_PROXY, Options::LANGUAGE_TYPE_CSHARP),
+       std::bind(&CionGenerator::GenCionCsharpProxyCode, this,
+                 std::placeholders::_1, std::placeholders::_2,
+                 std::placeholders::_3)},
+      {std::make_pair(Options::Type::TYPE_PROXY, Options::LANGUAGE_TYPE_JAVA),
+       std::bind(&CionGenerator::GenCionJavaProxyCode, this,
+                 std::placeholders::_1, std::placeholders::_2,
+                 std::placeholders::_3)},
+      {std::make_pair(Options::Type::TYPE_PROXY, Options::LANGUAGE_TYPE_DART),
+       std::bind(&CionGenerator::GenCionDartProxyCode, this,
+                 std::placeholders::_1, std::placeholders::_2,
+                 std::placeholders::_3)},
+
+      // Group
+      {std::make_pair(Options::Type::TYPE_GROUP, Options::LANGUAGE_TYPE_C),
+       std::bind(&CionGenerator::GenCionCGroupCode, this, std::placeholders::_1,
+                 std::placeholders::_2, std::placeholders::_3)},
+      {std::make_pair(Options::Type::TYPE_GROUP, Options::LANGUAGE_TYPE_CPP),
+       std::bind(&CionGenerator::GenCionCppGroupCode, this,
+                 std::placeholders::_1, std::placeholders::_2,
+                 std::placeholders::_3)},
+      {std::make_pair(Options::Type::TYPE_GROUP, Options::LANGUAGE_TYPE_CSHARP),
+       std::bind(&CionGenerator::GenCionCsharpGroupCode, this,
+                 std::placeholders::_1, std::placeholders::_2,
+                 std::placeholders::_3)},
+      {std::make_pair(Options::Type::TYPE_GROUP, Options::LANGUAGE_TYPE_JAVA),
+       std::bind(&CionGenerator::GenCionJavaGroupCode, this,
+                 std::placeholders::_1, std::placeholders::_2,
+                 std::placeholders::_3)},
+      {std::make_pair(Options::Type::TYPE_GROUP, Options::LANGUAGE_TYPE_DART),
+       std::bind(&CionGenerator::GenCionDartGroupCode, this,
+                 std::placeholders::_1, std::placeholders::_2,
+                 std::placeholders::_3)},
+  };
+}
+
+void CionGenerator::Generate(std::shared_ptr<Options> options,
+                             const Parser& ps) {
+  auto found = cion_funcs_.find(
+      std::make_pair(options->GetType(), options->GetLanguage()));
+  if (found == cion_funcs_.end()) return;
+
+  auto trans = std::shared_ptr<Transportable>(new PluginLoader(""));
+  auto& func = found->second;
+  func(std::move(options), ps, std::move(trans));
+}
+
+void CionGenerator::GenCionCStubCode(std::shared_ptr<Options> options,
+                                     const Parser& ps,
+                                     std::shared_ptr<Transportable> trans) {
+  CCionStubHeaderGen stub_header(ps.GetDoc(), trans);
+  stub_header.EnableNamespace(options->HasNamespace());
+  stub_header.SetChannelType(
+      static_cast<Generator::ChannelType>(options->GetType()));
+  stub_header.Run(options->GetOutput() + ".h");
+
+  CCionStubBodyGen stub_body(ps.GetDoc(), options, trans);
+  stub_body.EnableNamespace(options->HasNamespace());
+  stub_body.SetChannelType(
+      static_cast<Generator::ChannelType>(options->GetType()));
+  stub_body.Run(options->GetOutput() + ".c");
+}
+
+void CionGenerator::GenCionCppStubCode(std::shared_ptr<Options> options,
+                                       const Parser& ps,
+                                       std::shared_ptr<Transportable> trans) {
+  CppCionStubHeaderGen stub_header(ps.GetDoc(), options, trans);
+  stub_header.Run(options->GetOutput() + ".h");
+
+  CppCionStubBodyGen stub_body(ps.GetDoc(), options, trans);
+  stub_body.Run(options->GetOutput() + ".cc");
+}
+
+void CionGenerator::GenCionCsharpStubCode(
+    std::shared_ptr<Options> options, const Parser& ps,
+    std::shared_ptr<Transportable> trans) {
+  CsCionStubGen stub(ps.GetDoc(), trans);
+  stub.Run(options->GetOutput() + ".cs");
+}
+
+void CionGenerator::GenCionJavaStubCode(std::shared_ptr<Options> options,
+                                        const Parser& ps,
+                                        std::shared_ptr<Transportable> trans) {
+  JavaCionStubRepoGen repo(ps.GetDoc(), trans);
+  repo.Run(options->GetOutput(), true);
+
+  JavaCionStubGen view_model(ps.GetDoc(), trans);
+  view_model.Run(options->GetOutput(), true);
+
+  JavaCionUtilityGen utilities(ps.GetDoc(), trans);
+  utilities.Run(options->GetOutput(), true);
+
+  JavaCionStructureGen structures(ps.GetDoc(), trans);
+  structures.Run(options->GetOutput(), true);
+
+  JavaCionCommonGen cgen(ps.GetDoc(), trans);
+  cgen.Run(options->GetOutput(), true);
+}
+
+void CionGenerator::GenCionDartStubCode(std::shared_ptr<Options> options,
+                                        const Parser& ps,
+                                        std::shared_ptr<Transportable> trans) {
+  DartCionStubGen stub(ps.GetDoc(), trans);
+  stub.EnableProxy(false);
+  stub.Run(options->GetOutput() + ".dart");
+}
+
+void CionGenerator::GenCionCProxyCode(std::shared_ptr<Options> options,
+                                      const Parser& ps,
+                                      std::shared_ptr<Transportable> trans) {
+  CCionProxyHeaderGen proxy_header(ps.GetDoc(), trans);
+  proxy_header.EnableNamespace(options->HasNamespace());
+  proxy_header.SetChannelType(
+      static_cast<Generator::ChannelType>(options->GetType()));
+  proxy_header.Run(options->GetOutput() + ".h");
+
+  CCionProxyBodyGen proxy_body(ps.GetDoc(), options, trans);
+  proxy_body.EnableNamespace(options->HasNamespace());
+  proxy_body.SetChannelType(
+      static_cast<Generator::ChannelType>(options->GetType()));
+  proxy_body.Run(options->GetOutput() + ".c");
+}
+
+void CionGenerator::GenCionCppProxyCode(std::shared_ptr<Options> options,
+                                        const Parser& ps,
+                                        std::shared_ptr<Transportable> trans) {
+  CppCionProxyHeaderGen proxy_header(ps.GetDoc(), trans);
+  proxy_header.Run(options->GetOutput() + ".h");
+
+  CppCionProxyBodyGen proxy_body(ps.GetDoc(), trans);
+  proxy_body.Run(options->GetOutput() + ".cc");
+}
+
+void CionGenerator::GenCionCsharpProxyCode(
+    std::shared_ptr<Options> options, const Parser& ps,
+    std::shared_ptr<Transportable> trans) {
+  CsCionProxyGen proxy(ps.GetDoc(), trans);
+  proxy.Run(options->GetOutput() + ".cs");
+}
+
+void CionGenerator::GenCionJavaProxyCode(std::shared_ptr<Options> options,
+                                         const Parser& ps,
+                                         std::shared_ptr<Transportable> trans) {
+  JavaCionProxyRepoGen base_files(ps.GetDoc(), trans);
+  base_files.Run(options->GetOutput(), true);
+
+  JavaCionProxyGen view_model(ps.GetDoc(), trans);
+  view_model.Run(options->GetOutput(), true);
+
+  JavaCionUtilityGen utilities(ps.GetDoc(), trans);
+  utilities.Run(options->GetOutput(), true);
+
+  JavaCionStructureGen structures(ps.GetDoc(), trans);
+  structures.Run(options->GetOutput(), true);
+
+  JavaCionCommonGen cgen(ps.GetDoc(), trans);
+  cgen.Run(options->GetOutput(), true);
+}
+
+void CionGenerator::GenCionDartProxyCode(std::shared_ptr<Options> options,
+                                         const Parser& ps,
+                                         std::shared_ptr<Transportable> trans) {
+  DartCionProxyGen proxy(ps.GetDoc(), trans);
+  proxy.Run(options->GetOutput() + ".dart");
+}
+
+void CionGenerator::GenCionCGroupCode(std::shared_ptr<Options> options,
+                                      const Parser& ps,
+                                      std::shared_ptr<Transportable> trans) {
+  CCionGroupHeaderGen group_header(ps.GetDoc(), trans);
+  group_header.EnableNamespace(options->HasNamespace());
+  group_header.SetChannelType(
+      static_cast<Generator::ChannelType>(options->GetType()));
+  group_header.Run(options->GetOutput() + ".h");
+
+  CCionGroupBodyGen group_body(ps.GetDoc(), options, trans);
+  group_body.EnableNamespace(options->HasNamespace());
+  group_body.SetChannelType(
+      static_cast<Generator::ChannelType>(options->GetType()));
+  group_body.Run(options->GetOutput() + ".c");
+}
+
+void CionGenerator::GenCionCppGroupCode(std::shared_ptr<Options> options,
+                                        const Parser& ps,
+                                        std::shared_ptr<Transportable> trans) {
+  CppCionGroupHeaderGen group_header(ps.GetDoc(), trans);
+  group_header.Run(options->GetOutput() + ".h");
+
+  CppCionGroupBodyGen group_body(ps.GetDoc(), trans);
+  group_body.Run(options->GetOutput() + ".cc");
+}
+
+void CionGenerator::GenCionCsharpGroupCode(
+    std::shared_ptr<Options> options, const Parser& ps,
+    std::shared_ptr<Transportable> trans) {
+  CsCionGroupGen group(ps.GetDoc(), trans);
+  group.Run(options->GetOutput() + ".cs");
+}
+
+void CionGenerator::GenCionJavaGroupCode(std::shared_ptr<Options> options,
+                                         const Parser& ps,
+                                         std::shared_ptr<Transportable> trans) {
+  JavaCionGroupRepoGen repo(ps.GetDoc(), trans);
+  repo.Run(options->GetOutput(), true);
+
+  JavaCionGroupGen view_model(ps.GetDoc(), trans);
+  view_model.Run(options->GetOutput(), true);
+
+  JavaCionUtilityGen utilities(ps.GetDoc(), trans);
+  utilities.Run(options->GetOutput(), true);
+
+  JavaCionStructureGen structures(ps.GetDoc(), trans);
+  structures.Run(options->GetOutput(), true);
+
+  JavaCionCommonGen cgen(ps.GetDoc(), trans);
+  cgen.Run(options->GetOutput(), true);
+}
+
+void CionGenerator::GenCionDartGroupCode(std::shared_ptr<Options> options,
+                                         const Parser& ps,
+                                         std::shared_ptr<Transportable> trans) {
+  DartCionGroupGen group(ps.GetDoc(), trans);
+  group.Run(options->GetOutput() + ".dart");
+}
+
+}  // namespace tidl
diff --git a/idlc/cion_generator.hh b/idlc/cion_generator.hh
new file mode 100644 (file)
index 0000000..815d36e
--- /dev/null
@@ -0,0 +1,84 @@
+/*
+ * Copyright (c) 2023 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef IDLC_CION_GENERATOR_HH_
+#define IDLC_CION_GENERATOR_HH_
+
+#include <functional>
+#include <memory>
+#include <unordered_map>
+
+#include "idlc/code_generator.hh"
+#include "idlc/gen_cion/transportable.h"
+
+namespace tidl {
+
+class CionGenerator : public CodeGenerator {
+ public:
+  CionGenerator();
+  virtual ~CionGenerator() = default;
+
+  void Generate(std::shared_ptr<Options> options, const Parser& ps) override;
+
+ private:
+  using GeneratorCionFunc = std::function<void(
+      std::shared_ptr<Options>, const Parser&, std::shared_ptr<Transportable>)>;
+
+  /// Stub
+  void GenCionCStubCode(std::shared_ptr<Options> options, const Parser& ps,
+                        std::shared_ptr<Transportable> trans);
+  void GenCionCppStubCode(std::shared_ptr<Options> options, const Parser& ps,
+                          std::shared_ptr<Transportable> trans);
+  void GenCionCsharpStubCode(std::shared_ptr<Options> options, const Parser& ps,
+                             std::shared_ptr<Transportable> trans);
+  void GenCionJavaStubCode(std::shared_ptr<Options> options, const Parser& ps,
+                           std::shared_ptr<Transportable> trans);
+  void GenCionDartStubCode(std::shared_ptr<Options> options, const Parser& ps,
+                           std::shared_ptr<Transportable> trans);
+
+  /// Proxy
+  void GenCionCProxyCode(std::shared_ptr<Options> options, const Parser& ps,
+                         std::shared_ptr<Transportable> trans);
+  void GenCionCppProxyCode(std::shared_ptr<Options> options, const Parser& ps,
+                           std::shared_ptr<Transportable> trans);
+  void GenCionCsharpProxyCode(std::shared_ptr<Options> options,
+                              const Parser& ps,
+                              std::shared_ptr<Transportable> trans);
+  void GenCionJavaProxyCode(std::shared_ptr<Options> options, const Parser& ps,
+                            std::shared_ptr<Transportable> trans);
+  void GenCionDartProxyCode(std::shared_ptr<Options> options, const Parser& ps,
+                            std::shared_ptr<Transportable> trans);
+
+  /// Group
+  void GenCionCGroupCode(std::shared_ptr<Options> options, const Parser& ps,
+                         std::shared_ptr<Transportable> trans);
+  void GenCionCppGroupCode(std::shared_ptr<Options> options, const Parser& ps,
+                           std::shared_ptr<Transportable> trans);
+  void GenCionCsharpGroupCode(std::shared_ptr<Options> options,
+                              const Parser& ps,
+                              std::shared_ptr<Transportable> trans);
+  void GenCionJavaGroupCode(std::shared_ptr<Options> options, const Parser& ps,
+                            std::shared_ptr<Transportable> trans);
+  void GenCionDartGroupCode(std::shared_ptr<Options> options, const Parser& ps,
+                            std::shared_ptr<Transportable> trans);
+
+ private:
+  std::unordered_map<GeneratorCond, GeneratorCionFunc, PairHash> cion_funcs_;
+};
+
+}  // namespace tidl
+
+#endif  // IDLC_CION_GENERATOR_HH_
diff --git a/idlc/code_generator.hh b/idlc/code_generator.hh
new file mode 100644 (file)
index 0000000..544147f
--- /dev/null
@@ -0,0 +1,46 @@
+/*
+ * Copyright (c) 2023 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef IDLC_CODE_GENERATOR_HH_
+#define IDLC_CODE_GENERATOR_HH_
+
+#include <memory>
+#include <utility>
+
+#include "idlc/ast/parser.h"
+#include "idlc/options.h"
+
+namespace tidl {
+
+class CodeGenerator {
+ public:
+  struct PairHash {
+    template <class T1, class T2>
+    std::size_t operator()(const std::pair<T1, T2>& pair) const {
+      return std::hash<T1>()(pair.first) ^ std::hash<T2>()(pair.second);
+    }
+  };
+
+  using GeneratorCond = std::pair<int, int>;
+
+  virtual ~CodeGenerator() = default;
+
+  virtual void Generate(std::shared_ptr<Options> options, const Parser& ps) = 0;
+};
+
+}  // namespace tidl
+
+#endif  // IDLC_CODE_GENERATOR_HH_
diff --git a/idlc/default_generator.cc b/idlc/default_generator.cc
new file mode 100644 (file)
index 0000000..41db8a1
--- /dev/null
@@ -0,0 +1,200 @@
+/*
+ * Copyright (c) 2023 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "idlc/default_generator.hh"
+
+#include <utility>
+
+#include "idlc/ast/parser.h"
+#include "idlc/gen/c_group_body_gen.h"
+#include "idlc/gen/c_group_header_gen.h"
+#include "idlc/gen/c_proxy_body_gen.h"
+#include "idlc/gen/c_proxy_header_gen.h"
+#include "idlc/gen/c_stub_body_gen.h"
+#include "idlc/gen/c_stub_header_gen.h"
+#include "idlc/gen/cpp_group_body_gen.h"
+#include "idlc/gen/cpp_group_header_gen.h"
+#include "idlc/gen/cpp_proxy_body_gen.h"
+#include "idlc/gen/cpp_proxy_header_gen.h"
+#include "idlc/gen/cpp_stub_body_gen.h"
+#include "idlc/gen/cpp_stub_header_gen.h"
+#include "idlc/gen/cs_group_gen.h"
+#include "idlc/gen/cs_lib_gen.h"
+#include "idlc/gen/cs_proxy_gen.h"
+#include "idlc/gen/cs_stub_gen.h"
+#include "idlc/gen/dart_proxy_gen.h"
+#include "idlc/gen/dart_stub_gen.h"
+#include "idlc/options.h"
+
+namespace tidl {
+
+DefaultGenerator::DefaultGenerator() {
+  funcs_ = {
+      // Stub
+      {std::make_pair(Options::Type::TYPE_STUB, Options::LANGUAGE_TYPE_C),
+       std::bind(&DefaultGenerator::GenCStubCode, this, std::placeholders::_1,
+                 std::placeholders::_2)},
+      {std::make_pair(Options::Type::TYPE_STUB, Options::LANGUAGE_TYPE_CPP),
+       std::bind(&DefaultGenerator::GenCppStubCode, this, std::placeholders::_1,
+                 std::placeholders::_2)},
+      {std::make_pair(Options::Type::TYPE_STUB, Options::LANGUAGE_TYPE_CSHARP),
+       std::bind(&DefaultGenerator::GenCsharpStubCode, this,
+                 std::placeholders::_1, std::placeholders::_2)},
+      {std::make_pair(Options::Type::TYPE_STUB, Options::LANGUAGE_TYPE_DART),
+       std::bind(&DefaultGenerator::GenDartStubCode, this,
+                 std::placeholders::_1, std::placeholders::_2)},
+
+      // Proxy
+      {std::make_pair(Options::Type::TYPE_PROXY, Options::LANGUAGE_TYPE_C),
+       std::bind(&DefaultGenerator::GenCProxyCode, this, std::placeholders::_1,
+                 std::placeholders::_2)},
+      {std::make_pair(Options::Type::TYPE_PROXY, Options::LANGUAGE_TYPE_CPP),
+       std::bind(&DefaultGenerator::GenCppProxyCode, this,
+                 std::placeholders::_1, std::placeholders::_2)},
+      {std::make_pair(Options::Type::TYPE_PROXY, Options::LANGUAGE_TYPE_CSHARP),
+       std::bind(&DefaultGenerator::GenCsharpProxyCode, this,
+                 std::placeholders::_1, std::placeholders::_2)},
+      {std::make_pair(Options::Type::TYPE_PROXY, Options::LANGUAGE_TYPE_DART),
+       std::bind(&DefaultGenerator::GenDartProxyCode, this,
+                 std::placeholders::_1, std::placeholders::_2)},
+
+      // Group
+      {std::make_pair(Options::Type::TYPE_GROUP, Options::LANGUAGE_TYPE_C),
+       std::bind(&DefaultGenerator::GenCGroupCode, this, std::placeholders::_1,
+                 std::placeholders::_2)},
+      {std::make_pair(Options::Type::TYPE_GROUP, Options::LANGUAGE_TYPE_CPP),
+       std::bind(&DefaultGenerator::GenCppGroupCode, this,
+                 std::placeholders::_1, std::placeholders::_2)},
+      {std::make_pair(Options::Type::TYPE_GROUP, Options::LANGUAGE_TYPE_CSHARP),
+       std::bind(&DefaultGenerator::GenCsharpGroupCode, this,
+                 std::placeholders::_1, std::placeholders::_2)},
+  };
+}
+
+void DefaultGenerator::Generate(std::shared_ptr<Options> options,
+                                const Parser& ps) {
+  auto found = funcs_.find(
+      std::make_pair(options->GetType(), options->GetLanguage()));
+  if (found == funcs_.end()) return;
+
+  auto& func = found->second;
+  func(std::move(options), ps);
+}
+
+void DefaultGenerator::GenCStubCode(std::shared_ptr<Options> options,
+                                    const Parser& ps) {
+  CStubHeaderGen stub_header(ps.GetDoc());
+  stub_header.EnableNamespace(options->HasNamespace());
+  stub_header.EnableProxy(false);
+  stub_header.Run(options->GetOutput() + ".h");
+
+  CStubBodyGen stub_body(ps.GetDoc(), options);
+  stub_body.EnableNamespace(options->HasNamespace());
+  stub_body.EnableProxy(false);
+  stub_body.Run(options->GetOutput() + ".c");
+}
+
+void DefaultGenerator::GenCppStubCode(std::shared_ptr<Options> options,
+                                      const Parser& ps) {
+  CppStubHeaderGen stub_header(ps.GetDoc(), options);
+  stub_header.Run(options->GetOutput() + ".h");
+
+  CppStubBodyGen stub_body(ps.GetDoc(), options);
+  stub_body.Run(options->GetOutput() + ".cc");
+}
+
+void DefaultGenerator::GenCsharpStubCode(std::shared_ptr<Options> options,
+                                         const Parser& ps) {
+  CsStubGen stub(ps.GetDoc());
+  stub.Run(options->GetOutput() + ".cs");
+
+  if (options->HasRpcPortLib()) {
+    CsLibGen lib(ps.GetDoc());
+    lib.Run("rpc-port.cs");
+  }
+}
+
+void DefaultGenerator::GenDartStubCode(std::shared_ptr<Options> options,
+                                       const Parser& ps) {
+  DartStubGen stub(ps.GetDoc());
+  stub.EnableProxy(false);
+  stub.Run(options->GetOutput() + ".dart");
+}
+
+void DefaultGenerator::GenCProxyCode(std::shared_ptr<Options> options,
+                                     const Parser& ps) {
+  CProxyHeaderGen proxy_header(ps.GetDoc());
+  proxy_header.EnableNamespace(options->HasNamespace());
+  proxy_header.EnableProxy(true);
+  proxy_header.Run(options->GetOutput() + ".h");
+
+  CProxyBodyGen proxy_body(ps.GetDoc(), options);
+  proxy_body.EnableNamespace(options->HasNamespace());
+  proxy_body.EnableProxy(true);
+  proxy_body.Run(options->GetOutput() + ".c");
+}
+
+void DefaultGenerator::GenCppProxyCode(std::shared_ptr<Options> options,
+                                       const Parser& ps) {
+  CppProxyHeaderGen proxy_header(ps.GetDoc());
+  proxy_header.Run(options->GetOutput() + ".h");
+
+  CppProxyBodyGen proxy_body(ps.GetDoc());
+  proxy_body.Run(options->GetOutput() + ".cc");
+}
+
+void DefaultGenerator::GenCsharpProxyCode(std::shared_ptr<Options> options,
+                                          const Parser& ps) {
+  CsProxyGen proxy(ps.GetDoc());
+  proxy.Run(options->GetOutput() + ".cs");
+
+  if (options->HasRpcPortLib()) {
+    CsLibGen lib(ps.GetDoc());
+    lib.Run("rpc-port.cs");
+  }
+}
+
+void DefaultGenerator::GenDartProxyCode(std::shared_ptr<Options> options,
+                                        const Parser& ps) {
+  DartProxyGen proxy(ps.GetDoc());
+  proxy.Run(options->GetOutput() + ".dart");
+}
+
+void DefaultGenerator::GenCGroupCode(std::shared_ptr<Options> options,
+                                     const Parser& ps) {
+  CGroupHeaderGen group_header(ps.GetDoc());
+  group_header.Run(options->GetOutput() + ".h");
+
+  CGroupBodyGen group_body(ps.GetDoc());
+  group_body.Run(options->GetOutput() + ".c");
+}
+
+void DefaultGenerator::GenCppGroupCode(std::shared_ptr<Options> options,
+                                       const Parser& ps) {
+  CppGroupHeaderGen group_header(ps.GetDoc());
+  group_header.Run(options->GetOutput() + ".h");
+
+  CppGroupBodyGen group_body(ps.GetDoc());
+  group_body.Run(options->GetOutput() + ".cc");
+}
+
+void DefaultGenerator::GenCsharpGroupCode(std::shared_ptr<Options> options,
+                                          const Parser& ps) {
+  CsGroupGen group(ps.GetDoc());
+  group.Run(options->GetOutput() + ".cs");
+}
+
+}  // namespace tidl
diff --git a/idlc/default_generator.hh b/idlc/default_generator.hh
new file mode 100644 (file)
index 0000000..e2c12b6
--- /dev/null
@@ -0,0 +1,62 @@
+/*
+ * Copyright (c) 2023 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef IDLC_DEFAULT_GENERATOR_HH_
+#define IDLC_DEFAULT_GENERATOR_HH_
+
+#include <functional>
+#include <memory>
+#include <unordered_map>
+
+#include "idlc/code_generator.hh"
+
+namespace tidl {
+
+class DefaultGenerator : public CodeGenerator {
+ public:
+  DefaultGenerator();
+  virtual ~DefaultGenerator() = default;
+
+  void Generate(std::shared_ptr<Options> options, const Parser& ps) override;
+
+ private:
+  using GeneratorFunc =
+      std::function<void(std::shared_ptr<Options>, const Parser&)>;
+
+  /// Stub
+  void GenCStubCode(std::shared_ptr<Options> options, const Parser& ps);
+  void GenCppStubCode(std::shared_ptr<Options> options, const Parser& ps);
+  void GenCsharpStubCode(std::shared_ptr<Options> options, const Parser& ps);
+  void GenDartStubCode(std::shared_ptr<Options> options, const Parser& ps);
+
+  /// Proxy
+  void GenCProxyCode(std::shared_ptr<Options> options, const Parser& ps);
+  void GenCppProxyCode(std::shared_ptr<Options> options, const Parser& ps);
+  void GenCsharpProxyCode(std::shared_ptr<Options> options, const Parser& ps);
+  void GenDartProxyCode(std::shared_ptr<Options> options, const Parser& ps);
+
+  /// Group
+  void GenCGroupCode(std::shared_ptr<Options> options, const Parser& ps);
+  void GenCppGroupCode(std::shared_ptr<Options> options, const Parser& ps);
+  void GenCsharpGroupCode(std::shared_ptr<Options> options, const Parser& ps);
+
+ private:
+  std::unordered_map<GeneratorCond, GeneratorFunc, PairHash> funcs_;
+};
+
+}  // namespace tidl
+
+#endif  // IDLC_DEFAULT_GENERATOR_HH_
index 5f3a97d2173aab2ed3b2d347ead1b3903eb4c410..63ddb8409c0298913882e15ca586ccd0683d3e37 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2017 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2017 - 2023 Samsung Electronics Co., Ltd.
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
  * limitations under the License.
  */
 
-
-#include <iostream>
 #include <cstring>
+#include <functional>
+#include <iostream>
 #include <memory>
+#include <utility>
 
 #include "idlc/ast/parser.h"
-#include "idlc/gen/cs_proxy_gen.h"
-#include "idlc/gen/cs_stub_gen.h"
-#include "idlc/gen/cs_group_gen.h"
-#include "idlc/gen/cs_lib_gen.h"
-#include "idlc/gen/c_proxy_header_gen.h"
-#include "idlc/gen/c_proxy_body_gen.h"
-#include "idlc/gen/c_stub_header_gen.h"
-#include "idlc/gen/c_stub_body_gen.h"
-#include "idlc/gen/c_group_header_gen.h"
-#include "idlc/gen/c_group_body_gen.h"
-#include "idlc/gen/cpp_proxy_header_gen.h"
-#include "idlc/gen/cpp_proxy_body_gen.h"
-#include "idlc/gen/cpp_stub_header_gen.h"
-#include "idlc/gen/cpp_stub_body_gen.h"
-#include "idlc/gen/cpp_group_header_gen.h"
-#include "idlc/gen/cpp_group_body_gen.h"
-#include "idlc/gen/dart_proxy_gen.h"
-#include "idlc/gen/dart_stub_gen.h"
-#include "idlc/gen/version2/c_proxy_header_generator.hh"
-#include "idlc/gen/version2/c_proxy_body_generator.hh"
-#include "idlc/gen/version2/c_stub_header_generator.hh"
-#include "idlc/gen/version2/c_stub_body_generator.hh"
-#include "idlc/gen/version2/c_group_header_generator.hh"
-#include "idlc/gen/version2/c_group_body_generator.hh"
-#include "idlc/gen/version2/cpp_proxy_body_generator.hh"
-#include "idlc/gen/version2/cpp_proxy_header_generator.hh"
-#include "idlc/gen/version2/cpp_stub_header_generator.hh"
-#include "idlc/gen/version2/cpp_stub_body_generator.hh"
-#include "idlc/gen/version2/cs_proxy_generator.h"
-#include "idlc/gen/version2/cs_stub_generator.h"
-#include "idlc/gen/version2/cs_group_generator.h"
-#include "idlc/gen/version2/cpp_group_body_generator.hh"
-#include "idlc/gen/version2/cpp_group_header_generator.hh"
-#include "idlc/gen_cion/c_cion_proxy_header_gen.h"
-#include "idlc/gen_cion/c_cion_proxy_body_gen.h"
-#include "idlc/gen_cion/c_cion_stub_header_gen.h"
-#include "idlc/gen_cion/c_cion_stub_body_gen.h"
-#include "idlc/gen_cion/c_cion_group_header_gen.h"
-#include "idlc/gen_cion/c_cion_group_body_gen.h"
-#include "idlc/gen_cion/cs_cion_proxy_gen.h"
-#include "idlc/gen_cion/cs_cion_stub_gen.h"
-#include "idlc/gen_cion/cs_cion_group_gen.h"
-#include "idlc/gen_cion/cpp_cion_proxy_header_gen.h"
-#include "idlc/gen_cion/cpp_cion_proxy_body_gen.h"
-#include "idlc/gen_cion/cpp_cion_stub_header_gen.h"
-#include "idlc/gen_cion/cpp_cion_stub_body_gen.h"
-#include "idlc/gen_cion/cpp_cion_group_header_gen.h"
-#include "idlc/gen_cion/cpp_cion_group_body_gen.h"
-#include "idlc/gen_cion/dart_cion_proxy_gen.h"
-#include "idlc/gen_cion/dart_cion_stub_gen.h"
-#include "idlc/gen_cion/dart_cion_group_gen.h"
-#include "idlc/gen_cion/plugin_loader.h"
-#include "idlc/gen_mqtt_plugin/mqtt_plugin_internal_header_gen.h"
-#include "idlc/gen_mqtt_plugin/mqtt_plugin_internal_body_gen.h"
-#include "idlc/gen_mqtt_plugin/mqtt_plugin_c_transportable.h"
-#include "idlc/gen_mqtt_plugin/mqtt_plugin_loader.h"
-#include "idlc/gen_mqtt_plugin/mqtt_plugin_cs_base_gen.h"
-#include "idlc/gen_mqtt_plugin/mqtt_plugin_cs_interop_gen.h"
-#include "idlc/gen_mqtt_plugin/mqtt_plugin_cpp_transportable.h"
-
+#include "idlc/cion_generator.hh"
+#include "idlc/code_generator.hh"
+#include "idlc/default_generator.hh"
+#include "idlc/mqtt_generator.hh"
 #include "idlc/options.h"
+#include "idlc/version2_default_generator.hh"
 
-#include "idlc/gen_cion/java_cion_stub_gen.h"
-#include "idlc/gen_cion/java_cion_stub_repo_gen.h"
-#include "idlc/gen_cion/java_cion_proxy_gen.h"
-#include "idlc/gen_cion/java_cion_proxy_repo_gen.h"
-#include "idlc/gen_cion/java_cion_group_gen.h"
-#include "idlc/gen_cion/java_cion_group_repo_gen.h"
-#include "idlc/gen_cion/java_cion_utility_gen.h"
-#include "idlc/gen_cion/java_cion_structure_gen.h"
-#include "idlc/gen_cion/java_cion_common_gen.h"
-
-void GenerateStubCodes(std::shared_ptr<tidl::Options> options,
-    const tidl::Parser& ps) {
-  if (options->IsCion()) {
-    auto trans = std::shared_ptr<tidl::Transportable>(
-        new tidl::PluginLoader(""));
-    switch (options->GetLanguage()) {
-    case tidl::Options::LANGUAGE_TYPE_C:
-    {
-      tidl::CCionStubHeaderGen stub_header(ps.GetDoc(), trans);
-      stub_header.EnableNamespace(options->HasNamespace());
-      stub_header.SetChannelType(
-          static_cast<tidl::Generator::ChannelType>(options->GetType()));
-      stub_header.Run(options->GetOutput() + ".h");
-      tidl::CCionStubBodyGen stub_body(ps.GetDoc(), options, trans);
-      stub_body.EnableNamespace(options->HasNamespace());
-      stub_body.SetChannelType(
-          static_cast<tidl::Generator::ChannelType>(options->GetType()));
-      stub_body.Run(options->GetOutput() + ".c");
-      break;
-    }
-    case tidl::Options::LANGUAGE_TYPE_CPP:
-    {
-      tidl::CppCionStubHeaderGen stub_header(ps.GetDoc(), options, trans);
-      stub_header.Run(options->GetOutput() + ".h");
-      tidl::CppCionStubBodyGen stub_body(ps.GetDoc(), options, trans);
-      stub_body.Run(options->GetOutput() + ".cc");
-      break;
-    }
-    case tidl::Options::LANGUAGE_TYPE_CSHARP:
-    {
-       tidl::CsCionStubGen stub(ps.GetDoc(), trans);
-       stub.Run(options->GetOutput() + ".cs");
-       break;
-    }
-    case tidl::Options::LANGUAGE_TYPE_JAVA:
-    {
-      tidl::JavaCionStubRepoGen repo(ps.GetDoc(), trans);
-      repo.Run(options->GetOutput(), true);
-
-      tidl::JavaCionStubGen view_model(ps.GetDoc(), trans);
-      view_model.Run(options->GetOutput(), true);
-
-      tidl::JavaCionUtilityGen utilities(ps.GetDoc(), trans);
-      utilities.Run(options->GetOutput(), true);
-
-      tidl::JavaCionStructureGen structures(ps.GetDoc(), trans);
-      structures.Run(options->GetOutput(), true);
-
-      tidl::JavaCionCommonGen cgen(ps.GetDoc(), trans);
-      cgen.Run(options->GetOutput(), true);
-      break;
-    }
-    case tidl::Options::LANGUAGE_TYPE_DART:
-    {
-      tidl::DartCionStubGen stub(ps.GetDoc(), trans);
-      stub.EnableProxy(false);
-      stub.Run(options->GetOutput() + ".dart");
-      break;
-    }
-
-    default:
-      break;
-    }
-  } else if (options->IsMqtt()) {
-    auto trans = std::shared_ptr<tidl::Transportable>(
-        new tidl::MqttPluginLoader(""));
-    switch (options->GetLanguage()) {
-    case tidl::Options::LANGUAGE_TYPE_C:
-    {
-      tidl::MqttPluginInternalHeaderGen internal_header(ps.GetDoc(), trans);
-      internal_header.EnableNamespace(options->HasNamespace());
-      internal_header.EnableGeneratedAPI(true);
-      internal_header.SetChannelType(
-          static_cast<tidl::Generator::ChannelType>(options->GetType()));
-      internal_header.Run(options->GetOutput() + "_internal.h");
-
-      tidl::MqttPluginInternalBodyGen internal_body(ps.GetDoc(), trans);
-      internal_body.EnableNamespace(options->HasNamespace());
-                internal_body.EnableGeneratedAPI(true);
-      internal_body.SetChannelType(
-          static_cast<tidl::Generator::ChannelType>(options->GetType()));
-      internal_body.Run(options->GetOutput() + "_internal.c");
-
-      tidl::CCionStubHeaderGen stub_header(ps.GetDoc(), trans);
-      stub_header.EnableNamespace(options->HasNamespace());
-                stub_header.EnableGeneratedAPI(true);
-      stub_header.SetChannelType(
-          static_cast<tidl::Generator::ChannelType>(options->GetType()));
-      stub_header.Run(options->GetOutput() + ".h");
-
-      tidl::CCionStubBodyGen stub_body(ps.GetDoc(), options, trans);
-      stub_body.EnableNamespace(options->HasNamespace());
-      stub_body.EnableGeneratedAPI(true);
-      stub_body.SetChannelType(
-          static_cast<tidl::Generator::ChannelType>(options->GetType()));
-      stub_body.Run(options->GetOutput() + ".c");
-
-      break;
-    }
-    case tidl::Options::LANGUAGE_TYPE_CPP:
-    {
-      tidl::MqttPluginInternalHeaderGen internal_header(ps.GetDoc(), trans);
-      internal_header.EnableNamespace(options->HasNamespace());
-      internal_header.EnableGeneratedAPI(true);
-      internal_header.SetChannelType(
-          static_cast<tidl::Generator::ChannelType>(options->GetType()));
-      internal_header.Run(options->GetOutput() + "_internal.h");
-
-      tidl::MqttPluginInternalBodyGen internal_body(ps.GetDoc(), trans);
-      internal_body.EnableNamespace(options->HasNamespace());
-      internal_body.EnableGeneratedAPI(true);
-      internal_body.SetChannelType(
-          static_cast<tidl::Generator::ChannelType>(options->GetType()));
-      internal_body.Run(options->GetOutput() + "_internal.c");
-
-      tidl::CppCionStubHeaderGen stub_header(ps.GetDoc(), options, trans);
-      stub_header.SetChannelType(
-          static_cast<tidl::Generator::ChannelType>(options->GetType()));
-      stub_header.EnableGeneratedAPI(true);
-      stub_header.EnableNamespace(options->HasNamespace());
-      stub_header.Run(options->GetOutput() + ".h");
-
-      tidl::CppCionStubBodyGen stub_body(ps.GetDoc(), options, trans);
-      stub_body.SetChannelType(
-          static_cast<tidl::Generator::ChannelType>(options->GetType()));
-      stub_body.EnableGeneratedAPI(true);
-      stub_body.EnableNamespace(options->HasNamespace());
-      stub_body.Run(options->GetOutput() + ".cc");
-      break;
-    }
-    case tidl::Options::LANGUAGE_TYPE_CSHARP:
-    {
-      tidl::MqttPluginCsInteropGen interop(ps.GetDoc(), trans);
-      interop.SetChannelType(
-          static_cast<tidl::Generator::ChannelType>(options->GetType()));
-      interop.Run("Interop.MqttPlugin.cs");
-      tidl::MqttPluginCsBaseGen base(ps.GetDoc(), trans);
-      base.SetChannelType(
-          static_cast<tidl::Generator::ChannelType>(options->GetType()));
-      base.Run("MqttPluginBase.cs");
-
-      tidl::CsCionStubGen stub(ps.GetDoc(), trans);
-      stub.Run(options->GetOutput() + ".cs");
-      break;
-    }
-    case tidl::Options::LANGUAGE_TYPE_JAVA:
-    {
-      tidl::JavaCionStubRepoGen repo(ps.GetDoc(), trans);
-      repo.Run(options->GetOutput(), true);
+namespace {
 
-      tidl::JavaCionStubGen view_model(ps.GetDoc(), trans);
-      view_model.Run(options->GetOutput(), true);
-
-      tidl::JavaCionUtilityGen utilities(ps.GetDoc(), trans);
-      utilities.Run(options->GetOutput(), true);
-
-      tidl::JavaCionStructureGen structures(ps.GetDoc(), trans);
-      structures.Run(options->GetOutput(), true);
-
-      tidl::JavaCionCommonGen cgen(ps.GetDoc(), trans);
-      cgen.Run(options->GetOutput(), true);
-      break;
-    }
-
-    default:
-      break;
-    }
-  } else {
-    switch (options->GetLanguage()) {
-    case tidl::Options::LANGUAGE_TYPE_C:
-    {
-      if (ps.GetVersion() == 2) {
-        tidl::version2::CStubHeaderGenerator stub_header(ps.GetDoc());
-        stub_header.EnableNamespace(options->HasNamespace());
-        stub_header.SetChannelType(
-          static_cast<tidl::Generator::ChannelType>(options->GetType()));
-        stub_header.EnableProxy(false);
-        stub_header.Run(options->GetOutput() + ".h");
-        tidl::version2::CStubBodyGenerator stub_body(ps.GetDoc(), options);
-        stub_body.EnableNamespace(options->HasNamespace());
-        stub_body.SetChannelType(
-          static_cast<tidl::Generator::ChannelType>(options->GetType()));
-        stub_body.EnableProxy(false);
-        stub_body.Run(options->GetOutput() + ".c");
-      } else {
-        tidl::CStubHeaderGen stub_header(ps.GetDoc());
-        stub_header.EnableNamespace(options->HasNamespace());
-        stub_header.EnableProxy(false);
-        stub_header.Run(options->GetOutput() + ".h");
-        tidl::CStubBodyGen stub_body(ps.GetDoc(), options);
-        stub_body.EnableNamespace(options->HasNamespace());
-        stub_body.EnableProxy(false);
-        stub_body.Run(options->GetOutput() + ".c");
-      }
-      break;
-    }
-    case tidl::Options::LANGUAGE_TYPE_CPP:
-    {
-      if (ps.GetVersion() == 2) {
-        tidl::version2::CppStubHeaderGenerator stub_header(
-            ps.GetDoc(), options);
-        stub_header.Run(options->GetOutput() + ".h");
-        tidl::version2::CppStubBodyGenerator stub_body(ps.GetDoc(), options);
-        stub_body.Run(options->GetOutput() + ".cc");
-      } else {
-        tidl::CppStubHeaderGen stub_header(ps.GetDoc(), options);
-        stub_header.Run(options->GetOutput() + ".h");
-        tidl::CppStubBodyGen stub_body(ps.GetDoc(), options);
-        stub_body.Run(options->GetOutput() + ".cc");
-      }
-      break;
-    }
-    case tidl::Options::LANGUAGE_TYPE_CSHARP:
-    {
-      if (ps.GetVersion() == 2) {
-        tidl::version2::CsStubGen stub(ps.GetDoc());
-        stub.Run(options->GetOutput() + ".cs");
-      } else {
-        tidl::CsStubGen stub(ps.GetDoc());
-        stub.Run(options->GetOutput() + ".cs");
-        if (options->HasRpcPortLib()) {
-          tidl::CsLibGen lib(ps.GetDoc());
-          lib.Run("rpc-port.cs");
-        }
-      }
-      break;
-    }
-    case tidl::Options::LANGUAGE_TYPE_DART:
-    {
-      tidl::DartStubGen stub(ps.GetDoc());
-      stub.EnableProxy(false);
-      stub.Run(options->GetOutput() + ".dart");
-      break;
-    }
-
-    default:
-      break;
-    }
-  }
-}
-
-void GenerateProxyCodes(std::shared_ptr<tidl::Options> options,
+void GenerateCodes(std::shared_ptr<tidl::Options> options,
     const tidl::Parser& ps) {
+  std::shared_ptr<tidl::CodeGenerator> generator;
   if (options->IsCion()) {
-    auto trans = std::shared_ptr<tidl::Transportable>(
-        new tidl::PluginLoader(""));
-    switch (options->GetLanguage()) {
-    case tidl::Options::LANGUAGE_TYPE_C:
-    {
-      tidl::CCionProxyHeaderGen proxy_header(ps.GetDoc(), trans);
-      proxy_header.EnableNamespace(options->HasNamespace());
-      proxy_header.SetChannelType(
-          static_cast<tidl::Generator::ChannelType>(options->GetType()));
-      proxy_header.Run(options->GetOutput() + ".h");
-      tidl::CCionProxyBodyGen proxy_body(ps.GetDoc(), options, trans);
-      proxy_body.EnableNamespace(options->HasNamespace());
-      proxy_body.SetChannelType(
-          static_cast<tidl::Generator::ChannelType>(options->GetType()));
-      proxy_body.Run(options->GetOutput() + ".c");
-      break;
-    }
-    case tidl::Options::LANGUAGE_TYPE_CPP:
-    {
-      tidl::CppCionProxyHeaderGen proxy_header(ps.GetDoc(), trans);
-      proxy_header.Run(options->GetOutput() + ".h");
-      tidl::CppCionProxyBodyGen proxy_body(ps.GetDoc(), trans);
-      proxy_body.Run(options->GetOutput() + ".cc");
-      break;
-    }
-    case tidl::Options::LANGUAGE_TYPE_CSHARP:
-    {
-      tidl::CsCionProxyGen proxy(ps.GetDoc(), trans);
-      proxy.Run(options->GetOutput() + ".cs");
-      break;
-    }
-    case tidl::Options::LANGUAGE_TYPE_JAVA:
-    {
-      tidl::JavaCionProxyRepoGen base_files(ps.GetDoc(), trans);
-      base_files.Run(options->GetOutput(), true);
-
-      tidl::JavaCionProxyGen view_model(ps.GetDoc(), trans);
-      view_model.Run(options->GetOutput(), true);
-
-      tidl::JavaCionUtilityGen utilities(ps.GetDoc(), trans);
-      utilities.Run(options->GetOutput(), true);
-
-      tidl::JavaCionStructureGen structures(ps.GetDoc(), trans);
-      structures.Run(options->GetOutput(), true);
-
-      tidl::JavaCionCommonGen cgen(ps.GetDoc(), trans);
-      cgen.Run(options->GetOutput(), true);
-      break;
-    }
-    case tidl::Options::LANGUAGE_TYPE_DART:
-    {
-      tidl::DartCionProxyGen proxy(ps.GetDoc(), trans);
-      proxy.Run(options->GetOutput() + ".dart");
-      break;
-    }
-
-    default:
-      break;
-    }
+    generator.reset(new tidl::CionGenerator());
   } else if (options->IsMqtt()) {
-    auto trans = std::shared_ptr<tidl::Transportable>(
-        new tidl::MqttPluginLoader(""));
-    switch (options->GetLanguage()) {
-    case tidl::Options::LANGUAGE_TYPE_C:
-    {
-      tidl::MqttPluginInternalHeaderGen internal_header(ps.GetDoc(), trans);
-      internal_header.EnableNamespace(options->HasNamespace());
-      internal_header.EnableGeneratedAPI(true);
-      internal_header.SetChannelType(
-          static_cast<tidl::Generator::ChannelType>(options->GetType()));
-      internal_header.Run(options->GetOutput() + "_internal.h");
-
-      tidl::MqttPluginInternalBodyGen internal_body(ps.GetDoc(), trans);
-      internal_body.EnableNamespace(options->HasNamespace());
-      internal_body.EnableGeneratedAPI(true);
-      internal_body.SetChannelType(
-          static_cast<tidl::Generator::ChannelType>(options->GetType()));
-      internal_body.Run(options->GetOutput() + "_internal.c");
-
-      tidl::CCionProxyHeaderGen proxy_header(ps.GetDoc(), trans);
-      proxy_header.EnableNamespace(options->HasNamespace());
-      proxy_header.EnableGeneratedAPI(true);
-      proxy_header.SetChannelType(
-          static_cast<tidl::Generator::ChannelType>(options->GetType()));
-      proxy_header.Run(options->GetOutput() + ".h");
-
-      tidl::CCionProxyBodyGen proxy_body(ps.GetDoc(), options, trans);
-      proxy_body.EnableNamespace(options->HasNamespace());
-      proxy_body.EnableGeneratedAPI(true);
-      proxy_body.SetChannelType(
-          static_cast<tidl::Generator::ChannelType>(options->GetType()));
-      proxy_body.Run(options->GetOutput() + ".c");
-      break;
-    }
-    case tidl::Options::LANGUAGE_TYPE_CPP:
-    {
-      tidl::MqttPluginInternalHeaderGen internal_header(ps.GetDoc(), trans);
-      internal_header.SetChannelType(
-          static_cast<tidl::Generator::ChannelType>(options->GetType()));
-      internal_header.EnableNamespace(options->HasNamespace());
-      internal_header.EnableGeneratedAPI(true);
-      internal_header.Run(options->GetOutput() + "_internal.h");
-
-      tidl::MqttPluginInternalBodyGen internal_body(ps.GetDoc(), trans);
-      internal_body.SetChannelType(
-          static_cast<tidl::Generator::ChannelType>(options->GetType()));
-      internal_body.EnableNamespace(options->HasNamespace());
-      internal_body.EnableGeneratedAPI(true);
-      internal_body.Run(options->GetOutput() + "_internal.c");
-
-      tidl::CppCionProxyHeaderGen proxy_header(ps.GetDoc(), trans);
-      proxy_header.EnableNamespace(options->HasNamespace());
-      proxy_header.EnableGeneratedAPI(true);
-      proxy_header.SetChannelType(
-          static_cast<tidl::Generator::ChannelType>(options->GetType()));
-      proxy_header.Run(options->GetOutput() + ".h");
-
-      tidl::CppCionProxyBodyGen proxy_body(ps.GetDoc(), trans);
-      proxy_body.EnableNamespace(options->HasNamespace());
-      proxy_body.EnableGeneratedAPI(true);
-      proxy_body.SetChannelType(
-          static_cast<tidl::Generator::ChannelType>(options->GetType()));
-      proxy_body.Run(options->GetOutput() + ".cc");
-      break;
-    }
-    case tidl::Options::LANGUAGE_TYPE_CSHARP:
-    {
-      tidl::MqttPluginCsInteropGen interop(ps.GetDoc(), trans);
-      interop.SetChannelType(
-          static_cast<tidl::Generator::ChannelType>(options->GetType()));
-      interop.Run("Interop.MqttPlugin.cs");
-      tidl::MqttPluginCsBaseGen base(ps.GetDoc(), trans);
-      base.SetChannelType(
-          static_cast<tidl::Generator::ChannelType>(options->GetType()));
-      base.Run("MqttPluginBase.cs");
-
-      tidl::CsCionProxyGen proxy(ps.GetDoc(), trans);
-      proxy.Run(options->GetOutput() + ".cs");
-      break;
-    }
-    case tidl::Options::LANGUAGE_TYPE_JAVA:
-    {
-      tidl::JavaCionProxyRepoGen base_files(ps.GetDoc(), trans);
-      base_files.Run(options->GetOutput(), true);
-
-      tidl::JavaCionProxyGen view_model(ps.GetDoc(), trans);
-      view_model.Run(options->GetOutput(), true);
-
-      tidl::JavaCionUtilityGen utilities(ps.GetDoc(), trans);
-      utilities.Run(options->GetOutput(), true);
-
-      tidl::JavaCionStructureGen structures(ps.GetDoc(), trans);
-      structures.Run(options->GetOutput(), true);
-
-      tidl::JavaCionCommonGen cgen(ps.GetDoc(), trans);
-      cgen.Run(options->GetOutput(), true);
-      break;
-    }
-
-    default:
-      break;
-    }
+    generator.reset(new tidl::MqttGenerator());
   } else {
-    switch (options->GetLanguage()) {
-    case tidl::Options::LANGUAGE_TYPE_C:
-    {
-      if (ps.GetVersion() == 2) {
-        tidl::version2::CProxyHeaderGenerator proxy_header(ps.GetDoc());
-        proxy_header.EnableNamespace(options->HasNamespace());
-        proxy_header.EnableProxy(true);
-        proxy_header.SetChannelType(
-          static_cast<tidl::Generator::ChannelType>(options->GetType()));
-        proxy_header.Run(options->GetOutput() + ".h");
-
-        tidl::version2::CProxyBodyGenerator proxy_body(ps.GetDoc(), options);
-        proxy_body.EnableNamespace(options->HasNamespace());
-        proxy_body.EnableProxy(true);
-        proxy_body.SetChannelType(
-          static_cast<tidl::Generator::ChannelType>(options->GetType()));
-        proxy_body.Run(options->GetOutput() + ".c");
-      } else {
-        tidl::CProxyHeaderGen proxy_header(ps.GetDoc());
-        proxy_header.EnableNamespace(options->HasNamespace());
-        proxy_header.EnableProxy(true);
-        proxy_header.Run(options->GetOutput() + ".h");
-
-        tidl::CProxyBodyGen proxy_body(ps.GetDoc(), options);
-        proxy_body.EnableNamespace(options->HasNamespace());
-        proxy_body.EnableProxy(true);
-        proxy_body.Run(options->GetOutput() + ".c");
-      }
-      break;
-    }
-    case tidl::Options::LANGUAGE_TYPE_CPP:
-    {
-      if (ps.GetVersion() == 2) {
-        tidl::version2::CppProxyHeaderGenerator proxy_header(ps.GetDoc());
-        proxy_header.Run(options->GetOutput() + ".h");
-        tidl::version2::CppProxyBodyGenerator proxy_body(ps.GetDoc());
-        proxy_body.Run(options->GetOutput() + ".cc");
-      } else {
-        tidl::CppProxyHeaderGen proxy_header(ps.GetDoc());
-        proxy_header.Run(options->GetOutput() + ".h");
-        tidl::CppProxyBodyGen proxy_body(ps.GetDoc());
-        proxy_body.Run(options->GetOutput() + ".cc");
-      }
-      break;
-    }
-    case tidl::Options::LANGUAGE_TYPE_CSHARP:
-    {
-      if (ps.GetVersion() == 2) {
-        tidl::version2::CsProxyGen proxy(ps.GetDoc());
-        proxy.Run(options->GetOutput() + ".cs");
-      } else {
-        tidl::CsProxyGen proxy(ps.GetDoc());
-        proxy.Run(options->GetOutput() + ".cs");
-        if (options->HasRpcPortLib()) {
-          tidl::CsLibGen lib(ps.GetDoc());
-          lib.Run("rpc-port.cs");
-        }
-      }
-      break;
-    }
-    case tidl::Options::LANGUAGE_TYPE_DART:
-    {
-      tidl::DartProxyGen proxy(ps.GetDoc());
-      proxy.Run(options->GetOutput() + ".dart");
-      break;
-    }
-
-    default:
-      break;
-    }
+    if (ps.GetVersion() == 2)
+      generator.reset(new tidl::version2::DefaultGenerator());
+    else
+      generator.reset(new tidl::DefaultGenerator());
   }
-}
-
-void GenerateGroupCodes(std::shared_ptr<tidl::Options> options,
-    const tidl::Parser& ps) {
-  if (options->IsCion()) {
-    auto trans = std::shared_ptr<tidl::Transportable>(
-        new tidl::PluginLoader(""));
-    switch (options->GetLanguage()) {
-    case tidl::Options::LANGUAGE_TYPE_C:
-    {
-      tidl::CCionGroupHeaderGen group_header(ps.GetDoc(), trans);
-      group_header.EnableNamespace(options->HasNamespace());
-      group_header.SetChannelType(
-          static_cast<tidl::Generator::ChannelType>(options->GetType()));
-      group_header.Run(options->GetOutput() + ".h");
-
-      tidl::CCionGroupBodyGen group_body(ps.GetDoc(), options, trans);
-      group_body.EnableNamespace(options->HasNamespace());
-      group_body.SetChannelType(
-          static_cast<tidl::Generator::ChannelType>(options->GetType()));
-      group_body.Run(options->GetOutput() + ".c");
-      break;
-    }
-    case tidl::Options::LANGUAGE_TYPE_CPP:
-    {
-      tidl::CppCionGroupHeaderGen group_header(ps.GetDoc(), trans);
-      group_header.Run(options->GetOutput() + ".h");
-      tidl::CppCionGroupBodyGen group_body(ps.GetDoc(), trans);
-      group_body.Run(options->GetOutput() + ".cc");
-      break;
-    }
-    case tidl::Options::LANGUAGE_TYPE_CSHARP:
-    {
-      tidl::CsCionGroupGen group(ps.GetDoc(), trans);
-      group.Run(options->GetOutput() + ".cs");
-      break;
-    }
-    case tidl::Options::LANGUAGE_TYPE_JAVA:
-    {
-      tidl::JavaCionGroupRepoGen repo(ps.GetDoc(), trans);
-      repo.Run(options->GetOutput(), true);
-
-      tidl::JavaCionGroupGen view_model(ps.GetDoc(), trans);
-      view_model.Run(options->GetOutput(), true);
-
-      tidl::JavaCionUtilityGen utilities(ps.GetDoc(), trans);
-      utilities.Run(options->GetOutput(), true);
-
-      tidl::JavaCionStructureGen structures(ps.GetDoc(), trans);
-      structures.Run(options->GetOutput(), true);
-
-      tidl::JavaCionCommonGen cgen(ps.GetDoc(), trans);
-      cgen.Run(options->GetOutput(), true);
-      break;
-    }
-    case tidl::Options::LANGUAGE_TYPE_DART:
-    {
-      tidl::DartCionGroupGen group(ps.GetDoc(), trans);
-      group.Run(options->GetOutput() + ".dart");
-      break;
-    }
-    default:
-      break;
-    }
-  } else if (options->IsMqtt()) {
-    auto trans = std::shared_ptr<tidl::Transportable>(
-        new tidl::MqttPluginLoader(""));
-    switch (options->GetLanguage()) {
-    case tidl::Options::LANGUAGE_TYPE_C:
-    {
-      tidl::MqttPluginInternalHeaderGen internal_header(ps.GetDoc(), trans);
-      internal_header.EnableNamespace(options->HasNamespace());
-      internal_header.EnableGeneratedAPI(true);
-      internal_header.SetChannelType(
-          static_cast<tidl::Generator::ChannelType>(options->GetType()));
-      internal_header.Run(options->GetOutput() + "_internal.h");
-
-      tidl::MqttPluginInternalBodyGen internal_body(ps.GetDoc(), trans);
-      internal_body.EnableNamespace(options->HasNamespace());
-      internal_body.EnableGeneratedAPI(true);
-      internal_body.SetChannelType(
-          static_cast<tidl::Generator::ChannelType>(options->GetType()));
-      internal_body.Run(options->GetOutput() + "_internal.c");
 
-      tidl::CCionGroupHeaderGen group_header(ps.GetDoc(), trans);
-      group_header.EnableNamespace(options->HasNamespace());
-      group_header.EnableGeneratedAPI(true);
-      group_header.SetChannelType(
-          static_cast<tidl::Generator::ChannelType>(options->GetType()));
-      group_header.EnableGeneratedAPI(true);
-      group_header.Run(options->GetOutput() + ".h");
-
-      tidl::CCionGroupBodyGen group_body(ps.GetDoc(), options, trans);
-      group_body.EnableNamespace(options->HasNamespace());
-      group_body.EnableGeneratedAPI(true);
-      group_body.SetChannelType(
-          static_cast<tidl::Generator::ChannelType>(options->GetType()));
-      group_body.EnableGeneratedAPI(true);
-      group_body.Run(options->GetOutput() + ".c");
-      break;
-    }
-    case tidl::Options::LANGUAGE_TYPE_CPP:
-    {
-      tidl::MqttPluginInternalHeaderGen internal_header(ps.GetDoc(), trans);
-      internal_header.SetChannelType(
-          static_cast<tidl::Generator::ChannelType>(options->GetType()));
-      internal_header.EnableNamespace(options->HasNamespace());
-      internal_header.EnableGeneratedAPI(true);
-      internal_header.Run(options->GetOutput() + "_internal.h");
-
-      tidl::MqttPluginInternalBodyGen internal_body(ps.GetDoc(), trans);
-      internal_body.SetChannelType(
-          static_cast<tidl::Generator::ChannelType>(options->GetType()));
-      internal_body.EnableNamespace(options->HasNamespace());
-      internal_body.EnableGeneratedAPI(true);
-      internal_body.Run(options->GetOutput() + "_internal.c");
-
-      tidl::CppCionGroupHeaderGen group_header(ps.GetDoc(), trans);
-      group_header.SetChannelType(
-          static_cast<tidl::Generator::ChannelType>(options->GetType()));
-      group_header.EnableNamespace(options->HasNamespace());
-      group_header.EnableGeneratedAPI(true);
-      group_header.Run(options->GetOutput() + ".h");
-
-      tidl::CppCionGroupBodyGen group_body(ps.GetDoc(), trans);
-      group_body.SetChannelType(
-          static_cast<tidl::Generator::ChannelType>(options->GetType()));
-      group_body.EnableNamespace(options->HasNamespace());
-      group_body.EnableGeneratedAPI(true);
-      group_body.Run(options->GetOutput() + ".cc");
-      break;
-    }
-    case tidl::Options::LANGUAGE_TYPE_CSHARP:
-    {
-      tidl::MqttPluginCsInteropGen interop(ps.GetDoc(), trans);
-      interop.SetChannelType(
-          static_cast<tidl::Generator::ChannelType>(options->GetType()));
-      interop.Run("Interop.MqttPlugin.cs");
-      tidl::MqttPluginCsBaseGen base(ps.GetDoc(), trans);
-      base.SetChannelType(
-          static_cast<tidl::Generator::ChannelType>(options->GetType()));
-      base.Run("MqttPluginBase.cs");
-
-      tidl::CsCionGroupGen group(ps.GetDoc(), trans);
-      group.Run(options->GetOutput() + ".cs");
-      break;
-    }
-    case tidl::Options::LANGUAGE_TYPE_JAVA:
-    {
-      tidl::JavaCionGroupRepoGen repo(ps.GetDoc(), trans);
-      repo.Run(options->GetOutput(), true);
-
-      tidl::JavaCionGroupGen view_model(ps.GetDoc(), trans);
-      view_model.Run(options->GetOutput(), true);
-
-      tidl::JavaCionUtilityGen utilities(ps.GetDoc(), trans);
-      utilities.Run(options->GetOutput(), true);
-
-      tidl::JavaCionStructureGen structures(ps.GetDoc(), trans);
-      structures.Run(options->GetOutput(), true);
-
-      tidl::JavaCionCommonGen cgen(ps.GetDoc(), trans);
-      cgen.Run(options->GetOutput(), true);
-      break;
-    }
-
-    default:
-      break;
-    }
-  } else {
-    switch (options->GetLanguage()) {
-    case tidl::Options::LANGUAGE_TYPE_CPP:
-    {
-      if (ps.GetVersion() == 2) {
-        tidl::version2::CppGroupHeaderGenerator group_header(ps.GetDoc());
-        group_header.Run(options->GetOutput() + ".h");
-        tidl::version2::CppGroupBodyGenerator group_body(ps.GetDoc());
-        group_body.Run(options->GetOutput() + ".cc");
-      } else {
-        tidl::CppGroupHeaderGen group_header(ps.GetDoc());
-        group_header.Run(options->GetOutput() + ".h");
-        tidl::CppGroupBodyGen group_body(ps.GetDoc());
-        group_body.Run(options->GetOutput() + ".cc");
-      }
-      break;
-    }
-
-    case tidl::Options::LANGUAGE_TYPE_C:
-    {
-      if (ps.GetVersion() == 2) {
-        tidl::version2::CGroupHeaderGenerator group_header(ps.GetDoc());
-        group_header.SetChannelType(
-            static_cast<tidl::Generator::ChannelType>(options->GetType()));
-        group_header.Run(options->GetOutput() + ".h");
-        tidl::version2::CGroupBodyGenerator group_body(ps.GetDoc());
-        group_body.SetChannelType(
-            static_cast<tidl::Generator::ChannelType>(options->GetType()));
-        group_body.Run(options->GetOutput() + ".c");
-      } else {
-        tidl::CGroupHeaderGen group_header(ps.GetDoc());
-        group_header.Run(options->GetOutput() + ".h");
-        tidl::CGroupBodyGen group_body(ps.GetDoc());
-        group_body.Run(options->GetOutput() + ".c");
-      }
-      break;
-    }
-
-    case tidl::Options::LANGUAGE_TYPE_CSHARP:
-    {
-      if (ps.GetVersion() == 2) {
-        tidl::version2::CsGroupGen group(ps.GetDoc());
-        group.Run(options->GetOutput() + ".cs");
-      } else {
-        tidl::CsGroupGen group(ps.GetDoc());
-        group.Run(options->GetOutput() + ".cs");
-        break;
-      }
-    }
-
-    default:
-      break;
-    }
-  }
+  generator->Generate(std::move(options), ps);
 }
 
-void GenerateCodes(std::shared_ptr<tidl::Options> options,
-    const tidl::Parser& ps) {
-  switch (options->GetType()) {
-  case tidl::Options::Type::TYPE_STUB:
-    GenerateStubCodes(options, ps);
-    break;
-  case tidl::Options::Type::TYPE_PROXY:
-    GenerateProxyCodes(options, ps);
-    break;
-  case tidl::Options::Type::TYPE_GROUP:
-    GenerateGroupCodes(options, ps);
-    break;
-
-  default:
-    break;
-  }
-}
+}  // namespace
 
 int main(int argc, char** argv) {
   std::shared_ptr<tidl::Options> options = tidl::Options::Parse(argc, argv);
diff --git a/idlc/mqtt_generator.cc b/idlc/mqtt_generator.cc
new file mode 100644 (file)
index 0000000..35d1a55
--- /dev/null
@@ -0,0 +1,424 @@
+/*
+ * Copyright (c) 2023 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "idlc/mqtt_generator.hh"
+
+#include <utility>
+
+#include "idlc/gen_cion/c_cion_group_body_gen.h"
+#include "idlc/gen_cion/c_cion_group_header_gen.h"
+#include "idlc/gen_cion/c_cion_proxy_body_gen.h"
+#include "idlc/gen_cion/c_cion_proxy_header_gen.h"
+#include "idlc/gen_cion/c_cion_stub_body_gen.h"
+#include "idlc/gen_cion/c_cion_stub_header_gen.h"
+#include "idlc/gen_cion/cpp_cion_group_body_gen.h"
+#include "idlc/gen_cion/cpp_cion_group_header_gen.h"
+#include "idlc/gen_cion/cpp_cion_proxy_body_gen.h"
+#include "idlc/gen_cion/cpp_cion_proxy_header_gen.h"
+#include "idlc/gen_cion/cpp_cion_stub_body_gen.h"
+#include "idlc/gen_cion/cpp_cion_stub_header_gen.h"
+#include "idlc/gen_cion/cs_cion_group_gen.h"
+#include "idlc/gen_cion/cs_cion_proxy_gen.h"
+#include "idlc/gen_cion/cs_cion_stub_gen.h"
+#include "idlc/gen_cion/dart_cion_group_gen.h"
+#include "idlc/gen_cion/dart_cion_proxy_gen.h"
+#include "idlc/gen_cion/dart_cion_stub_gen.h"
+#include "idlc/gen_cion/java_cion_common_gen.h"
+#include "idlc/gen_cion/java_cion_group_gen.h"
+#include "idlc/gen_cion/java_cion_group_repo_gen.h"
+#include "idlc/gen_cion/java_cion_proxy_gen.h"
+#include "idlc/gen_cion/java_cion_proxy_repo_gen.h"
+#include "idlc/gen_cion/java_cion_structure_gen.h"
+#include "idlc/gen_cion/java_cion_stub_gen.h"
+#include "idlc/gen_cion/java_cion_stub_repo_gen.h"
+#include "idlc/gen_cion/java_cion_utility_gen.h"
+#include "idlc/gen_cion/plugin_loader.h"
+#include "idlc/gen_mqtt_plugin/mqtt_plugin_c_transportable.h"
+#include "idlc/gen_mqtt_plugin/mqtt_plugin_cpp_transportable.h"
+#include "idlc/gen_mqtt_plugin/mqtt_plugin_cs_base_gen.h"
+#include "idlc/gen_mqtt_plugin/mqtt_plugin_cs_interop_gen.h"
+#include "idlc/gen_mqtt_plugin/mqtt_plugin_internal_body_gen.h"
+#include "idlc/gen_mqtt_plugin/mqtt_plugin_internal_header_gen.h"
+#include "idlc/gen_mqtt_plugin/mqtt_plugin_loader.h"
+
+namespace tidl {
+
+MqttGenerator::MqttGenerator() {
+  mqtt_funcs_ = {
+      // Stub
+      {std::make_pair(Options::Type::TYPE_STUB, Options::LANGUAGE_TYPE_C),
+       std::bind(&MqttGenerator::GenMqttCStubCode, this, std::placeholders::_1,
+                 std::placeholders::_2, std::placeholders::_3)},
+      {std::make_pair(Options::Type::TYPE_STUB, Options::LANGUAGE_TYPE_CPP),
+       std::bind(&MqttGenerator::GenMqttCppStubCode, this,
+                 std::placeholders::_1, std::placeholders::_2,
+                 std::placeholders::_3)},
+      {std::make_pair(Options::Type::TYPE_STUB, Options::LANGUAGE_TYPE_CSHARP),
+       std::bind(&MqttGenerator::GenMqttCsharpStubCode, this,
+                 std::placeholders::_1, std::placeholders::_2,
+                 std::placeholders::_3)},
+      {std::make_pair(Options::Type::TYPE_STUB, Options::LANGUAGE_TYPE_JAVA),
+       std::bind(&MqttGenerator::GenMqttJavaStubCode, this,
+                 std::placeholders::_1, std::placeholders::_2,
+                 std::placeholders::_3)},
+
+      // Proxy
+      {std::make_pair(Options::Type::TYPE_PROXY, Options::LANGUAGE_TYPE_C),
+       std::bind(&MqttGenerator::GenMqttCProxyCode, this, std::placeholders::_1,
+                 std::placeholders::_2, std::placeholders::_3)},
+      {std::make_pair(Options::Type::TYPE_PROXY, Options::LANGUAGE_TYPE_CPP),
+       std::bind(&MqttGenerator::GenMqttCppProxyCode, this,
+                 std::placeholders::_1, std::placeholders::_2,
+                 std::placeholders::_3)},
+      {std::make_pair(Options::Type::TYPE_PROXY, Options::LANGUAGE_TYPE_CSHARP),
+       std::bind(&MqttGenerator::GenMqttCsharpProxyCode, this,
+                 std::placeholders::_1, std::placeholders::_2,
+                 std::placeholders::_3)},
+      {std::make_pair(Options::Type::TYPE_PROXY, Options::LANGUAGE_TYPE_JAVA),
+       std::bind(&MqttGenerator::GenMqttJavaProxyCode, this,
+                 std::placeholders::_1, std::placeholders::_2,
+                 std::placeholders::_3)},
+
+      // Group
+      {std::make_pair(Options::Type::TYPE_GROUP, Options::LANGUAGE_TYPE_C),
+       std::bind(&MqttGenerator::GenMqttCGroupCode, this, std::placeholders::_1,
+                 std::placeholders::_2, std::placeholders::_3)},
+      {std::make_pair(Options::Type::TYPE_GROUP, Options::LANGUAGE_TYPE_CPP),
+       std::bind(&MqttGenerator::GenMqttCppGroupCode, this,
+                 std::placeholders::_1, std::placeholders::_2,
+                 std::placeholders::_3)},
+      {std::make_pair(Options::Type::TYPE_GROUP, Options::LANGUAGE_TYPE_CSHARP),
+       std::bind(&MqttGenerator::GenMqttCsharpGroupCode, this,
+                 std::placeholders::_1, std::placeholders::_2,
+                 std::placeholders::_3)},
+      {std::make_pair(Options::Type::TYPE_GROUP, Options::LANGUAGE_TYPE_JAVA),
+       std::bind(&MqttGenerator::GenMqttJavaGroupCode, this,
+                 std::placeholders::_1, std::placeholders::_2,
+                 std::placeholders::_3)},
+  };
+}
+
+void MqttGenerator::Generate(std::shared_ptr<Options> options,
+                             const Parser& ps) {
+  auto found = mqtt_funcs_.find(
+      std::make_pair(options->GetType(), options->GetLanguage()));
+  if (found == mqtt_funcs_.end()) return;
+
+  auto trans = std::shared_ptr<Transportable>(new MqttPluginLoader(""));
+  auto& func = found->second;
+  func(std::move(options), ps, std::move(trans));
+}
+
+void MqttGenerator::GenMqttCStubCode(std::shared_ptr<Options> options,
+                                     const Parser& ps,
+                                     std::shared_ptr<Transportable> trans) {
+  MqttPluginInternalHeaderGen internal_header(ps.GetDoc(), trans);
+  internal_header.EnableNamespace(options->HasNamespace());
+  internal_header.EnableGeneratedAPI(true);
+  internal_header.SetChannelType(
+      static_cast<Generator::ChannelType>(options->GetType()));
+  internal_header.Run(options->GetOutput() + "_internal.h");
+
+  MqttPluginInternalBodyGen internal_body(ps.GetDoc(), trans);
+  internal_body.EnableNamespace(options->HasNamespace());
+  internal_body.EnableGeneratedAPI(true);
+  internal_body.SetChannelType(
+      static_cast<Generator::ChannelType>(options->GetType()));
+  internal_body.Run(options->GetOutput() + "_internal.c");
+
+  CCionStubHeaderGen stub_header(ps.GetDoc(), trans);
+  stub_header.EnableNamespace(options->HasNamespace());
+  stub_header.EnableGeneratedAPI(true);
+  stub_header.SetChannelType(
+      static_cast<Generator::ChannelType>(options->GetType()));
+  stub_header.Run(options->GetOutput() + ".h");
+
+  CCionStubBodyGen stub_body(ps.GetDoc(), options, trans);
+  stub_body.EnableNamespace(options->HasNamespace());
+  stub_body.EnableGeneratedAPI(true);
+  stub_body.SetChannelType(
+      static_cast<Generator::ChannelType>(options->GetType()));
+  stub_body.Run(options->GetOutput() + ".c");
+}
+
+void MqttGenerator::GenMqttCppStubCode(std::shared_ptr<Options> options,
+                                       const Parser& ps,
+                                       std::shared_ptr<Transportable> trans) {
+  MqttPluginInternalHeaderGen internal_header(ps.GetDoc(), trans);
+  internal_header.EnableNamespace(options->HasNamespace());
+  internal_header.EnableGeneratedAPI(true);
+  internal_header.SetChannelType(
+      static_cast<Generator::ChannelType>(options->GetType()));
+  internal_header.Run(options->GetOutput() + "_internal.h");
+
+  MqttPluginInternalBodyGen internal_body(ps.GetDoc(), trans);
+  internal_body.EnableNamespace(options->HasNamespace());
+  internal_body.EnableGeneratedAPI(true);
+  internal_body.SetChannelType(
+      static_cast<Generator::ChannelType>(options->GetType()));
+  internal_body.Run(options->GetOutput() + "_internal.c");
+
+  CppCionStubHeaderGen stub_header(ps.GetDoc(), options, trans);
+  stub_header.SetChannelType(
+      static_cast<Generator::ChannelType>(options->GetType()));
+  stub_header.EnableGeneratedAPI(true);
+  stub_header.EnableNamespace(options->HasNamespace());
+  stub_header.Run(options->GetOutput() + ".h");
+
+  CppCionStubBodyGen stub_body(ps.GetDoc(), options, trans);
+  stub_body.SetChannelType(
+      static_cast<Generator::ChannelType>(options->GetType()));
+  stub_body.EnableGeneratedAPI(true);
+  stub_body.EnableNamespace(options->HasNamespace());
+  stub_body.Run(options->GetOutput() + ".cc");
+}
+
+void MqttGenerator::GenMqttCsharpStubCode(
+    std::shared_ptr<Options> options, const Parser& ps,
+    std::shared_ptr<Transportable> trans) {
+  MqttPluginCsInteropGen interop(ps.GetDoc(), trans);
+  interop.SetChannelType(
+      static_cast<Generator::ChannelType>(options->GetType()));
+  interop.Run("Interop.MqttPlugin.cs");
+
+  MqttPluginCsBaseGen base(ps.GetDoc(), trans);
+  base.SetChannelType(static_cast<Generator::ChannelType>(options->GetType()));
+  base.Run("MqttPluginBase.cs");
+
+  CsCionStubGen stub(ps.GetDoc(), trans);
+  stub.Run(options->GetOutput() + ".cs");
+}
+
+void MqttGenerator::GenMqttJavaStubCode(std::shared_ptr<Options> options,
+                                        const Parser& ps,
+                                        std::shared_ptr<Transportable> trans) {
+  JavaCionStubRepoGen repo(ps.GetDoc(), trans);
+  repo.Run(options->GetOutput(), true);
+
+  JavaCionStubGen view_model(ps.GetDoc(), trans);
+  view_model.Run(options->GetOutput(), true);
+
+  JavaCionUtilityGen utilities(ps.GetDoc(), trans);
+  utilities.Run(options->GetOutput(), true);
+
+  JavaCionStructureGen structures(ps.GetDoc(), trans);
+  structures.Run(options->GetOutput(), true);
+
+  JavaCionCommonGen cgen(ps.GetDoc(), trans);
+  cgen.Run(options->GetOutput(), true);
+}
+
+void MqttGenerator::GenMqttCProxyCode(std::shared_ptr<Options> options,
+                                      const Parser& ps,
+                                      std::shared_ptr<Transportable> trans) {
+  MqttPluginInternalHeaderGen internal_header(ps.GetDoc(), trans);
+  internal_header.EnableNamespace(options->HasNamespace());
+  internal_header.EnableGeneratedAPI(true);
+  internal_header.SetChannelType(
+      static_cast<Generator::ChannelType>(options->GetType()));
+  internal_header.Run(options->GetOutput() + "_internal.h");
+
+  MqttPluginInternalBodyGen internal_body(ps.GetDoc(), trans);
+  internal_body.EnableNamespace(options->HasNamespace());
+  internal_body.EnableGeneratedAPI(true);
+  internal_body.SetChannelType(
+      static_cast<Generator::ChannelType>(options->GetType()));
+  internal_body.Run(options->GetOutput() + "_internal.c");
+
+  CCionProxyHeaderGen proxy_header(ps.GetDoc(), trans);
+  proxy_header.EnableNamespace(options->HasNamespace());
+  proxy_header.EnableGeneratedAPI(true);
+  proxy_header.SetChannelType(
+      static_cast<Generator::ChannelType>(options->GetType()));
+  proxy_header.Run(options->GetOutput() + ".h");
+
+  CCionProxyBodyGen proxy_body(ps.GetDoc(), options, trans);
+  proxy_body.EnableNamespace(options->HasNamespace());
+  proxy_body.EnableGeneratedAPI(true);
+  proxy_body.SetChannelType(
+      static_cast<Generator::ChannelType>(options->GetType()));
+  proxy_body.Run(options->GetOutput() + ".c");
+}
+
+void MqttGenerator::GenMqttCppProxyCode(std::shared_ptr<Options> options,
+                                        const Parser& ps,
+                                        std::shared_ptr<Transportable> trans) {
+  MqttPluginInternalHeaderGen internal_header(ps.GetDoc(), trans);
+  internal_header.SetChannelType(
+      static_cast<Generator::ChannelType>(options->GetType()));
+  internal_header.EnableNamespace(options->HasNamespace());
+  internal_header.EnableGeneratedAPI(true);
+  internal_header.Run(options->GetOutput() + "_internal.h");
+
+  MqttPluginInternalBodyGen internal_body(ps.GetDoc(), trans);
+  internal_body.SetChannelType(
+      static_cast<Generator::ChannelType>(options->GetType()));
+  internal_body.EnableNamespace(options->HasNamespace());
+  internal_body.EnableGeneratedAPI(true);
+  internal_body.Run(options->GetOutput() + "_internal.c");
+
+  CppCionProxyHeaderGen proxy_header(ps.GetDoc(), trans);
+  proxy_header.EnableNamespace(options->HasNamespace());
+  proxy_header.EnableGeneratedAPI(true);
+  proxy_header.SetChannelType(
+      static_cast<Generator::ChannelType>(options->GetType()));
+  proxy_header.Run(options->GetOutput() + ".h");
+
+  CppCionProxyBodyGen proxy_body(ps.GetDoc(), trans);
+  proxy_body.EnableNamespace(options->HasNamespace());
+  proxy_body.EnableGeneratedAPI(true);
+  proxy_body.SetChannelType(
+      static_cast<Generator::ChannelType>(options->GetType()));
+  proxy_body.Run(options->GetOutput() + ".cc");
+}
+
+void MqttGenerator::GenMqttCsharpProxyCode(
+    std::shared_ptr<Options> options, const Parser& ps,
+    std::shared_ptr<Transportable> trans) {
+  MqttPluginCsInteropGen interop(ps.GetDoc(), trans);
+  interop.SetChannelType(
+      static_cast<Generator::ChannelType>(options->GetType()));
+  interop.Run("Interop.MqttPlugin.cs");
+
+  MqttPluginCsBaseGen base(ps.GetDoc(), trans);
+  base.SetChannelType(static_cast<Generator::ChannelType>(options->GetType()));
+  base.Run("MqttPluginBase.cs");
+
+  CsCionProxyGen proxy(ps.GetDoc(), trans);
+  proxy.Run(options->GetOutput() + ".cs");
+}
+
+void MqttGenerator::GenMqttJavaProxyCode(std::shared_ptr<Options> options,
+                                         const Parser& ps,
+                                         std::shared_ptr<Transportable> trans) {
+  JavaCionProxyRepoGen base_files(ps.GetDoc(), trans);
+  base_files.Run(options->GetOutput(), true);
+
+  JavaCionProxyGen view_model(ps.GetDoc(), trans);
+  view_model.Run(options->GetOutput(), true);
+
+  JavaCionUtilityGen utilities(ps.GetDoc(), trans);
+  utilities.Run(options->GetOutput(), true);
+
+  JavaCionStructureGen structures(ps.GetDoc(), trans);
+  structures.Run(options->GetOutput(), true);
+
+  JavaCionCommonGen cgen(ps.GetDoc(), trans);
+  cgen.Run(options->GetOutput(), true);
+}
+
+void MqttGenerator::GenMqttCGroupCode(std::shared_ptr<Options> options,
+                                      const Parser& ps,
+                                      std::shared_ptr<Transportable> trans) {
+  MqttPluginInternalHeaderGen internal_header(ps.GetDoc(), trans);
+  internal_header.EnableNamespace(options->HasNamespace());
+  internal_header.EnableGeneratedAPI(true);
+  internal_header.SetChannelType(
+      static_cast<Generator::ChannelType>(options->GetType()));
+  internal_header.Run(options->GetOutput() + "_internal.h");
+
+  MqttPluginInternalBodyGen internal_body(ps.GetDoc(), trans);
+  internal_body.EnableNamespace(options->HasNamespace());
+  internal_body.EnableGeneratedAPI(true);
+  internal_body.SetChannelType(
+      static_cast<Generator::ChannelType>(options->GetType()));
+  internal_body.Run(options->GetOutput() + "_internal.c");
+
+  CCionGroupHeaderGen group_header(ps.GetDoc(), trans);
+  group_header.EnableNamespace(options->HasNamespace());
+  group_header.EnableGeneratedAPI(true);
+  group_header.SetChannelType(
+      static_cast<Generator::ChannelType>(options->GetType()));
+  group_header.EnableGeneratedAPI(true);
+  group_header.Run(options->GetOutput() + ".h");
+
+  CCionGroupBodyGen group_body(ps.GetDoc(), options, trans);
+  group_body.EnableNamespace(options->HasNamespace());
+  group_body.EnableGeneratedAPI(true);
+  group_body.SetChannelType(
+      static_cast<Generator::ChannelType>(options->GetType()));
+  group_body.EnableGeneratedAPI(true);
+  group_body.Run(options->GetOutput() + ".c");
+}
+
+void MqttGenerator::GenMqttCppGroupCode(std::shared_ptr<Options> options,
+                                        const Parser& ps,
+                                        std::shared_ptr<Transportable> trans) {
+  MqttPluginInternalHeaderGen internal_header(ps.GetDoc(), trans);
+  internal_header.SetChannelType(
+      static_cast<Generator::ChannelType>(options->GetType()));
+  internal_header.EnableNamespace(options->HasNamespace());
+  internal_header.EnableGeneratedAPI(true);
+  internal_header.Run(options->GetOutput() + "_internal.h");
+
+  MqttPluginInternalBodyGen internal_body(ps.GetDoc(), trans);
+  internal_body.SetChannelType(
+      static_cast<Generator::ChannelType>(options->GetType()));
+  internal_body.EnableNamespace(options->HasNamespace());
+  internal_body.EnableGeneratedAPI(true);
+  internal_body.Run(options->GetOutput() + "_internal.c");
+
+  CppCionGroupHeaderGen group_header(ps.GetDoc(), trans);
+  group_header.SetChannelType(
+      static_cast<Generator::ChannelType>(options->GetType()));
+  group_header.EnableNamespace(options->HasNamespace());
+  group_header.EnableGeneratedAPI(true);
+  group_header.Run(options->GetOutput() + ".h");
+
+  CppCionGroupBodyGen group_body(ps.GetDoc(), trans);
+  group_body.SetChannelType(
+      static_cast<Generator::ChannelType>(options->GetType()));
+  group_body.EnableNamespace(options->HasNamespace());
+  group_body.EnableGeneratedAPI(true);
+  group_body.Run(options->GetOutput() + ".cc");
+}
+
+void MqttGenerator::GenMqttCsharpGroupCode(
+    std::shared_ptr<Options> options, const Parser& ps,
+    std::shared_ptr<Transportable> trans) {
+  MqttPluginCsInteropGen interop(ps.GetDoc(), trans);
+  interop.SetChannelType(
+      static_cast<Generator::ChannelType>(options->GetType()));
+  interop.Run("Interop.MqttPlugin.cs");
+
+  MqttPluginCsBaseGen base(ps.GetDoc(), trans);
+  base.SetChannelType(static_cast<Generator::ChannelType>(options->GetType()));
+  base.Run("MqttPluginBase.cs");
+
+  CsCionGroupGen group(ps.GetDoc(), trans);
+  group.Run(options->GetOutput() + ".cs");
+}
+
+void MqttGenerator::GenMqttJavaGroupCode(std::shared_ptr<Options> options,
+                                         const Parser& ps,
+                                         std::shared_ptr<Transportable> trans) {
+  JavaCionGroupRepoGen repo(ps.GetDoc(), trans);
+  repo.Run(options->GetOutput(), true);
+
+  JavaCionGroupGen view_model(ps.GetDoc(), trans);
+  view_model.Run(options->GetOutput(), true);
+
+  JavaCionUtilityGen utilities(ps.GetDoc(), trans);
+  utilities.Run(options->GetOutput(), true);
+
+  JavaCionStructureGen structures(ps.GetDoc(), trans);
+  structures.Run(options->GetOutput(), true);
+
+  JavaCionCommonGen cgen(ps.GetDoc(), trans);
+  cgen.Run(options->GetOutput(), true);
+}
+
+}  // namespace tidl
diff --git a/idlc/mqtt_generator.hh b/idlc/mqtt_generator.hh
new file mode 100644 (file)
index 0000000..c1db9ec
--- /dev/null
@@ -0,0 +1,78 @@
+/*
+ * Copyright (c) 2023 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef IDLC_MQTT_GENERATOR_HH_
+#define IDLC_MQTT_GENERATOR_HH_
+
+#include <functional>
+#include <memory>
+#include <unordered_map>
+
+#include "idlc/code_generator.hh"
+#include "idlc/gen_cion/transportable.h"
+
+namespace tidl {
+
+class MqttGenerator : public CodeGenerator {
+ public:
+  MqttGenerator();
+  virtual ~MqttGenerator() = default;
+
+  void Generate(std::shared_ptr<Options> options, const Parser& ps) override;
+
+ private:
+  using GeneratorMqttFunc = std::function<void(
+      std::shared_ptr<Options>, const Parser&, std::shared_ptr<Transportable>)>;
+
+  /// Stub
+  void GenMqttCStubCode(std::shared_ptr<Options> options, const Parser& ps,
+                        std::shared_ptr<Transportable> trans);
+  void GenMqttCppStubCode(std::shared_ptr<Options> options, const Parser& ps,
+                          std::shared_ptr<Transportable> trans);
+  void GenMqttCsharpStubCode(std::shared_ptr<Options> options, const Parser& ps,
+                             std::shared_ptr<Transportable> trans);
+  void GenMqttJavaStubCode(std::shared_ptr<Options> options, const Parser& ps,
+                           std::shared_ptr<Transportable> trans);
+
+  /// Proxy
+  void GenMqttCProxyCode(std::shared_ptr<Options> options, const Parser& ps,
+                         std::shared_ptr<Transportable> trans);
+  void GenMqttCppProxyCode(std::shared_ptr<Options> options, const Parser& ps,
+                           std::shared_ptr<Transportable> trans);
+  void GenMqttCsharpProxyCode(std::shared_ptr<Options> options,
+                              const Parser& ps,
+                              std::shared_ptr<Transportable> trans);
+  void GenMqttJavaProxyCode(std::shared_ptr<Options> options, const Parser& ps,
+                            std::shared_ptr<Transportable> trans);
+
+  /// Group
+  void GenMqttCGroupCode(std::shared_ptr<Options> options, const Parser& ps,
+                         std::shared_ptr<Transportable> trans);
+  void GenMqttCppGroupCode(std::shared_ptr<Options> options, const Parser& ps,
+                           std::shared_ptr<Transportable> trans);
+  void GenMqttCsharpGroupCode(std::shared_ptr<Options> options,
+                              const Parser& ps,
+                              std::shared_ptr<Transportable> trans);
+  void GenMqttJavaGroupCode(std::shared_ptr<Options> options, const Parser& ps,
+                            std::shared_ptr<Transportable> trans);
+
+ private:
+  std::unordered_map<GeneratorCond, GeneratorMqttFunc, PairHash> mqtt_funcs_;
+};
+
+}  // namespace tidl
+
+#endif  // IDLC_MQTT_GENERATOR_HH_
diff --git a/idlc/version2_default_generator.cc b/idlc/version2_default_generator.cc
new file mode 100644 (file)
index 0000000..af5e199
--- /dev/null
@@ -0,0 +1,182 @@
+/*
+ * Copyright (c) 2023 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "idlc/version2_default_generator.hh"
+
+#include <utility>
+
+#include "idlc/ast/parser.h"
+#include "idlc/gen/version2/c_group_body_generator.hh"
+#include "idlc/gen/version2/c_group_header_generator.hh"
+#include "idlc/gen/version2/c_proxy_body_generator.hh"
+#include "idlc/gen/version2/c_proxy_header_generator.hh"
+#include "idlc/gen/version2/c_stub_body_generator.hh"
+#include "idlc/gen/version2/c_stub_header_generator.hh"
+#include "idlc/gen/version2/cpp_group_body_generator.hh"
+#include "idlc/gen/version2/cpp_group_header_generator.hh"
+#include "idlc/gen/version2/cpp_proxy_body_generator.hh"
+#include "idlc/gen/version2/cpp_proxy_header_generator.hh"
+#include "idlc/gen/version2/cpp_stub_body_generator.hh"
+#include "idlc/gen/version2/cpp_stub_header_generator.hh"
+#include "idlc/gen/version2/cs_group_generator.h"
+#include "idlc/gen/version2/cs_proxy_generator.h"
+#include "idlc/gen/version2/cs_stub_generator.h"
+#include "idlc/options.h"
+
+namespace tidl {
+namespace version2 {
+
+DefaultGenerator::DefaultGenerator() {
+  funcs_ = {
+      // Stub
+      {std::make_pair(Options::Type::TYPE_STUB, Options::LANGUAGE_TYPE_C),
+       std::bind(&DefaultGenerator::GenCStubCode, this, std::placeholders::_1,
+                 std::placeholders::_2)},
+      {std::make_pair(Options::Type::TYPE_STUB, Options::LANGUAGE_TYPE_CPP),
+       std::bind(&DefaultGenerator::GenCppStubCode, this, std::placeholders::_1,
+                 std::placeholders::_2)},
+      {std::make_pair(Options::Type::TYPE_STUB, Options::LANGUAGE_TYPE_CSHARP),
+       std::bind(&DefaultGenerator::GenCsharpStubCode, this,
+                 std::placeholders::_1, std::placeholders::_2)},
+
+      // Proxy
+      {std::make_pair(Options::Type::TYPE_PROXY, Options::LANGUAGE_TYPE_C),
+       std::bind(&DefaultGenerator::GenCProxyCode, this, std::placeholders::_1,
+                 std::placeholders::_2)},
+      {std::make_pair(Options::Type::TYPE_PROXY, Options::LANGUAGE_TYPE_CPP),
+       std::bind(&DefaultGenerator::GenCppProxyCode, this,
+                 std::placeholders::_1, std::placeholders::_2)},
+      {std::make_pair(Options::Type::TYPE_PROXY, Options::LANGUAGE_TYPE_CSHARP),
+       std::bind(&DefaultGenerator::GenCsharpProxyCode, this,
+                 std::placeholders::_1, std::placeholders::_2)},
+
+      // Group
+      {std::make_pair(Options::Type::TYPE_GROUP, Options::LANGUAGE_TYPE_C),
+       std::bind(&DefaultGenerator::GenCGroupCode, this, std::placeholders::_1,
+                 std::placeholders::_2)},
+      {std::make_pair(Options::Type::TYPE_GROUP, Options::LANGUAGE_TYPE_CPP),
+       std::bind(&DefaultGenerator::GenCppGroupCode, this,
+                 std::placeholders::_1, std::placeholders::_2)},
+      {std::make_pair(Options::Type::TYPE_GROUP, Options::LANGUAGE_TYPE_CSHARP),
+       std::bind(&DefaultGenerator::GenCsharpGroupCode, this,
+                 std::placeholders::_1, std::placeholders::_2)},
+  };
+}
+
+void DefaultGenerator::Generate(std::shared_ptr<Options> options,
+                                const Parser& ps) {
+  auto found = funcs_.find(
+      std::make_pair(options->GetType(), options->GetLanguage()));
+  if (found == funcs_.end()) return;
+
+  auto& func = found->second;
+  func(std::move(options), ps);
+}
+
+void DefaultGenerator::GenCStubCode(std::shared_ptr<Options> options,
+                                    const Parser& ps) {
+  CStubHeaderGenerator stub_header(ps.GetDoc());
+  stub_header.EnableNamespace(options->HasNamespace());
+  stub_header.SetChannelType(
+      static_cast<Generator::ChannelType>(options->GetType()));
+  stub_header.EnableProxy(false);
+  stub_header.Run(options->GetOutput() + ".h");
+
+  CStubBodyGenerator stub_body(ps.GetDoc(), options);
+  stub_body.EnableNamespace(options->HasNamespace());
+  stub_body.SetChannelType(
+      static_cast<Generator::ChannelType>(options->GetType()));
+  stub_body.EnableProxy(false);
+  stub_body.Run(options->GetOutput() + ".c");
+}
+
+void DefaultGenerator::GenCppStubCode(std::shared_ptr<Options> options,
+                                      const Parser& ps) {
+  CppStubHeaderGenerator stub_header(ps.GetDoc(), options);
+  stub_header.Run(options->GetOutput() + ".h");
+
+  CppStubBodyGenerator stub_body(ps.GetDoc(), options);
+  stub_body.Run(options->GetOutput() + ".cc");
+}
+
+void DefaultGenerator::GenCsharpStubCode(std::shared_ptr<Options> options,
+                                         const Parser& ps) {
+  CsStubGen stub(ps.GetDoc());
+  stub.Run(options->GetOutput() + ".cs");
+}
+
+void DefaultGenerator::GenCProxyCode(std::shared_ptr<Options> options,
+                                        const Parser& ps) {
+  CProxyHeaderGenerator proxy_header(ps.GetDoc());
+  proxy_header.EnableNamespace(options->HasNamespace());
+  proxy_header.EnableProxy(true);
+  proxy_header.SetChannelType(
+      static_cast<Generator::ChannelType>(options->GetType()));
+  proxy_header.Run(options->GetOutput() + ".h");
+
+  CProxyBodyGenerator proxy_body(ps.GetDoc(), options);
+  proxy_body.EnableNamespace(options->HasNamespace());
+  proxy_body.EnableProxy(true);
+  proxy_body.SetChannelType(
+      static_cast<Generator::ChannelType>(options->GetType()));
+  proxy_body.Run(options->GetOutput() + ".c");
+}
+
+void DefaultGenerator::GenCppProxyCode(std::shared_ptr<Options> options,
+                                       const Parser& ps) {
+  CppProxyHeaderGenerator proxy_header(ps.GetDoc());
+  proxy_header.Run(options->GetOutput() + ".h");
+
+  CppProxyBodyGenerator proxy_body(ps.GetDoc());
+  proxy_body.Run(options->GetOutput() + ".cc");
+}
+
+void DefaultGenerator::GenCsharpProxyCode(std::shared_ptr<Options> options,
+                                          const Parser& ps) {
+  CsProxyGen proxy(ps.GetDoc());
+  proxy.Run(options->GetOutput() + ".cs");
+}
+
+void DefaultGenerator::GenCGroupCode(std::shared_ptr<Options> options,
+                                     const Parser& ps) {
+  CGroupHeaderGenerator group_header(ps.GetDoc());
+  group_header.SetChannelType(
+      static_cast<Generator::ChannelType>(options->GetType()));
+  group_header.Run(options->GetOutput() + ".h");
+
+  CGroupBodyGenerator group_body(ps.GetDoc());
+  group_body.SetChannelType(
+      static_cast<Generator::ChannelType>(options->GetType()));
+  group_body.Run(options->GetOutput() + ".c");
+}
+
+void DefaultGenerator::GenCppGroupCode(std::shared_ptr<Options> options,
+                                       const Parser& ps) {
+  CppGroupHeaderGenerator group_header(ps.GetDoc());
+  group_header.Run(options->GetOutput() + ".h");
+
+  CppGroupBodyGenerator group_body(ps.GetDoc());
+  group_body.Run(options->GetOutput() + ".cc");
+}
+
+void DefaultGenerator::GenCsharpGroupCode(std::shared_ptr<Options> options,
+                                          const Parser& ps) {
+  CsGroupGen group(ps.GetDoc());
+  group.Run(options->GetOutput() + ".cs");
+}
+
+}  // namespace version2
+}  // namespace tidl
diff --git a/idlc/version2_default_generator.hh b/idlc/version2_default_generator.hh
new file mode 100644 (file)
index 0000000..44d5d63
--- /dev/null
@@ -0,0 +1,62 @@
+/*
+ * Copyright (c) 2023 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef IDLC_VERSION2_DEFAULT_GENERATOR_HH_
+#define IDLC_VERSION2_DEFAULT_GENERATOR_HH_
+
+#include <functional>
+#include <memory>
+#include <unordered_map>
+
+#include "idlc/code_generator.hh"
+
+namespace tidl {
+namespace version2 {
+
+class DefaultGenerator : public CodeGenerator {
+ public:
+  DefaultGenerator();
+  virtual ~DefaultGenerator() = default;
+
+  void Generate(std::shared_ptr<Options> options, const Parser& ps) override;
+
+ private:
+  using GeneratorFunc =
+      std::function<void(std::shared_ptr<Options>, const Parser&)>;
+
+  /// Stub
+  void GenCStubCode(std::shared_ptr<Options> options, const Parser& ps);
+  void GenCppStubCode(std::shared_ptr<Options> options, const Parser& ps);
+  void GenCsharpStubCode(std::shared_ptr<Options> options, const Parser& ps);
+
+  /// Proxy
+  void GenCProxyCode(std::shared_ptr<Options> options, const Parser& ps);
+  void GenCppProxyCode(std::shared_ptr<Options> options, const Parser& ps);
+  void GenCsharpProxyCode(std::shared_ptr<Options> options, const Parser& ps);
+
+  /// Group
+  void GenCGroupCode(std::shared_ptr<Options> options, const Parser& ps);
+  void GenCppGroupCode(std::shared_ptr<Options> options, const Parser& ps);
+  void GenCsharpGroupCode(std::shared_ptr<Options> options, const Parser& ps);
+
+ private:
+  std::unordered_map<GeneratorCond, GeneratorFunc, PairHash> funcs_;
+};
+
+}  // namespace version2
+}  // namespace tidl
+
+#endif  // IDLC_VERSION2_DEFAULT_GENERATOR_HH_