Implement C# group generator 45/277945/10
authorjh9216.park <jh9216.park@samsung.com>
Fri, 15 Jul 2022 07:10:36 +0000 (03:10 -0400)
committerjh9216.park <jh9216.park@samsung.com>
Mon, 18 Jul 2022 23:56:28 +0000 (19:56 -0400)
Change-Id: Icefd3413c98c7d0bfe266803f42481f81d6931c7
Signed-off-by: jh9216.park <jh9216.park@samsung.com>
Makefile.dibs
idlc/gen/cs_gen_base.cc
idlc/gen/cs_gen_base.h
idlc/gen/cs_gen_base_cb.h
idlc/gen/cs_group_gen.cc [new file with mode: 0644]
idlc/gen/cs_group_gen.h [new file with mode: 0644]
idlc/gen/cs_group_gen_cb.h [new file with mode: 0644]
idlc/main.cc

index 1f58b15..676e812 100644 (file)
@@ -31,6 +31,7 @@ SRC_FILES := \
        idlc/gen/cs_lib_gen.cc \
        idlc/gen/cs_proxy_gen.cc \
        idlc/gen/cs_stub_gen.cc \
+       idlc/gen/cs_group_gen.cc \
        idlc/gen/generator.cc \
        idlc/gen/replace_all.cc \
        idlc/gen_cion/c_cion_body_gen_base.cc \
index bef1498..912d9d5 100644 (file)
@@ -95,55 +95,71 @@ void CsGeneratorBase::GenStructure(std::ofstream& stream, const Structure& st) {
 
 void CsGeneratorBase::GenSerializer(std::ofstream& stream,
     const Structure& st) {
-  stream << NLine(1) << Tab(3) << "private static void Serialize(Parcel h, "
-                   << st.GetID() << " param)" << NLine(1);
-  GenBrace(stream, TAB_SIZE * 3, [&]() {
-    for (const auto& i : st.GetElements()) {
-      auto& t = i->GetType();
-      if (!t.IsUserDefinedType() && t.GetMetaType() == nullptr) {
-        stream << Tab(4) << "h.Write"
-                         << ConvertTypeToParcelType(t.ToString())
-                         << "(param."
-                         << i->GetID()
-                         << ");" << NLine(1);
-      } else {
-        stream << Tab(4) << "Serialize(h, param." << i->GetID()
-                         << ");" << NLine(1);
-      }
-    }
-  });
-  stream << NLine(1);
+  stream << GetSerializer(st);
+}
 
-  stream << Tab(3) << "private static void Deserialize(Parcel h, "
-                   << st.GetID() << " param)" << NLine(1);
-  GenBrace(stream, TAB_SIZE * 3, [&]() {
-    for (const auto& i : st.GetElements()) {
-      auto& t = i->GetType();
-      if (!t.IsUserDefinedType() && t.GetMetaType() == nullptr) {
-        stream << Tab(4) << "var " << i->GetID() << " = "
-                         << "h.Read"
-                         << ConvertTypeToParcelType(t.ToString())
-                         << "();" << NLine(1);
-        stream << Tab(4) << "param." << i->GetID() << " = " << i->GetID()
-               << ";" << NLine(1);
-      } else {
-        stream << Tab(4) << "param." << i->GetID() << " = new "
-                         << ConvertTypeToString(t)
-                         << "();" << NLine(1);
-        stream << Tab(4) << "Deserialize(h, param." << i->GetID()
-                         << ");" << NLine(1);
-      }
-    }
-  });
+std::string CsGeneratorBase::GetSerializer(const Structure& st) {
+  std::string str(ReplaceAll(CB_SERIALIZER)
+      .Change("<TYPE>", st.GetID())
+      .Change("<BODY>", [&]() {
+        std::string ret;
+        for (const auto& i : st.GetElements()) {
+          auto& t = i->GetType();
+          if (!t.IsUserDefinedType() && t.GetMetaType() == nullptr) {
+            ret += Tab(4) + "h.Write"
+                          + ConvertTypeToParcelType(t.ToString())
+                          + "(param."
+                          + i->GetID()
+                          + ");" + NLine(1);
+          } else {
+            ret += Tab(4) + "Serialize(h, param." + i->GetID()
+                          + ");" + NLine(1);
+          }
+        }
+
+        return ret;
+      }));
+
+  str += ReplaceAll(CB_DESERIALIZER)
+      .Change("<TYPE>", st.GetID())
+      .Change("<BODY>", [&]() {
+        std::string ret;
+        for (const auto& i : st.GetElements()) {
+          auto& t = i->GetType();
+          if (!t.IsUserDefinedType() && t.GetMetaType() == nullptr) {
+            ret += Tab(4) + "var " + i->GetID() + " = "
+                          + "h.Read"
+                          + ConvertTypeToParcelType(t.ToString())
+                          + "();" + NLine(1);
+            ret += Tab(4) + "param." + i->GetID() + " = " + i->GetID()
+                          + ";" + NLine(1);
+          } else {
+            ret += Tab(4) + "param." + i->GetID() + " = new "
+                          + ConvertTypeToString(t)
+                          + "();" + NLine(1);
+            ret += Tab(4) + "Deserialize(h, param." + i->GetID()
+                          + ");" + NLine(1);
+          }
+        }
+        return ret;
+      });
+  return str;
 }
 
 void CsGeneratorBase::GenSerializer(std::ofstream& stream) {
+  stream << GetSerializer();
+}
+
+std::string CsGeneratorBase::GetSerializer() {
+  std::string str;
   for (auto& i : GetDocument().GetBlocks()) {
     if (i->GetType() == Block::TYPE_STRUCTURE) {
       const Structure& st = static_cast<const Structure&>(*i);
-      GenSerializer(stream, st);
+      str += GetSerializer(st);
     }
   }
+
+  return str;
 }
 
 void CsGeneratorBase::AddSerializerList(const BaseType& type) {
@@ -155,60 +171,64 @@ void CsGeneratorBase::AddSerializerList(const BaseType& type) {
 
 void CsGeneratorBase::GenListSerializer(std::ofstream& stream,
     const BaseType& type) {
-  stream << NLine(1) << Tab(3) << "private static void Serialize(Parcel h, "
-                   << ConvertTypeToString(type) << " param)" << NLine(1);
-  GenBrace(stream, TAB_SIZE * 3, [&]() {
-    stream << Tab(4)
-           << "h.WriteArrayCount(param.Count);"
-           << NLine(1);
-    stream << Tab(4) << "foreach (var i in param)" << NLine(1);
-    GenBrace(stream, TAB_SIZE * 4, [&]() {
-      auto* ptr = type.GetMetaType();
-      if (ptr == nullptr) return;
-
-      auto& mt = *ptr;
-      if (!mt.IsUserDefinedType() && mt.GetMetaType() == nullptr) {
-        stream << Tab(5) << "h.Write"
-                         << ConvertTypeToParcelType(mt.ToString())
-                         << "(i);" << NLine(1);
-      } else {
-        stream << Tab(5) << "Serialize(h, i);" << NLine(1);
-      }
-    });
-  });
-  stream << NLine(1);
+  stream << GetListSerializer(type);
+}
 
-  stream << Tab(3) << "private static void Deserialize(Parcel h, "
-                   << ConvertTypeToString(type) << " param)" << NLine(1);
-  GenBrace(stream, TAB_SIZE * 3, [&]() {
-    stream << Tab(4)
-           << "int l = h.ReadArrayCount();"
-           << NLine(1);
-    stream << Tab(4) << "for (int i = 0; i < l; i++)" << NLine(1);
-    GenBrace(stream, TAB_SIZE * 4, [&]() {
-      auto* ptr = type.GetMetaType();
-      if (ptr == nullptr)
-        return;
-
-      auto& mt = *ptr;
-      if (!mt.IsUserDefinedType() && mt.GetMetaType() == nullptr) {
-        stream << Tab(5) << "var v = h.Read"
-                         << ConvertTypeToParcelType(mt.ToString())
-                         << "();" << NLine(1);
-      } else {
-        stream << Tab(5) << "var v = new " << ConvertTypeToString(mt)
-               << "();" << NLine(1);
-        stream << Tab(5) << "Deserialize(h, v);" << NLine(1);
-      }
-      if (type.ToString() == "list")
-        stream << Tab(5) << "param.AddLast(v);" << NLine(1);
-      else
-        stream << Tab(5) << "param.Add(v);" << NLine(1);
-    });
-  });
+std::string CsGeneratorBase::GetListSerializer(const BaseType& type) {
+  std::string str(ReplaceAll(CB_LIST_SERIALIZER)
+      .Change("<TYPE>", ConvertTypeToString(type))
+      .Change("<BODY>", [&]() {
+        std::string ret;
+        auto* ptr = type.GetMetaType();
+        if (ptr == nullptr)
+          return ret;
+
+        auto& mt = *ptr;
+        if (!mt.IsUserDefinedType() && mt.GetMetaType() == nullptr) {
+          ret += Tab(5) + "h.Write"
+                        + ConvertTypeToParcelType(mt.ToString())
+                        + "(i);" + NLine(1);
+        } else {
+          ret += Tab(5) + "Serialize(h, i);" + NLine(1);
+        }
+        return ret;
+      }));
+
+  str += ReplaceAll(CB_DESERIALIZER)
+      .Change("<TYPE>", ConvertTypeToString(type))
+      .Change("<BODY>", [&]() {
+        std::string ret;
+        auto* ptr = type.GetMetaType();
+        if (ptr == nullptr)
+          return ret;
+
+        auto& mt = *ptr;
+        if (!mt.IsUserDefinedType() && mt.GetMetaType() == nullptr) {
+          ret += Tab(5) + "var v = h.Read"
+                        + ConvertTypeToParcelType(mt.ToString())
+                        + "();" + NLine(1);
+        } else {
+          ret += Tab(5) + "var v = new " + ConvertTypeToString(mt)
+                        + "();" + NLine(1);
+          ret += Tab(5) + "Deserialize(h, v);" + NLine(1);
+        }
+
+        if (type.ToString() == "list")
+          ret += Tab(5) + "param.AddLast(v);" + NLine(1);
+        else
+          ret += Tab(5) + "param.Add(v);" + NLine(1);
+
+        return ret;
+      });
+
+  return str;
 }
 
 void CsGeneratorBase::GenListSerializer(std::ofstream& stream) {
+  stream << GetListSerializer();
+}
+
+std::string CsGeneratorBase::GetListSerializer() {
   serializer_list_.clear();
   for (auto& i : GetDocument().GetBlocks()) {
     if (i->GetType() == Block::TYPE_STRUCTURE) {
@@ -230,10 +250,13 @@ void CsGeneratorBase::GenListSerializer(std::ofstream& stream) {
     }
   }
 
+  std::string ret;
   for (auto& p : serializer_list_) {
     const BaseType* t = p.second;
-    GenListSerializer(stream, *t);
+    ret += GetListSerializer(*t);
   }
+
+  return ret;
 }
 
 std::string CsGeneratorBase::ConvertTypeToString(const BaseType& type) {
@@ -348,20 +371,22 @@ void CsGeneratorBase::GenWriteBundle(std::ofstream& stream,
     });
 }
 
-void CsGeneratorBase::GenMethodId(std::ofstream& stream,
-    const Interface& iface) {
-  stream << Tab(3) << "private enum MethodId : int" << NLine(1);
-  GenBrace(stream, TAB_SIZE * 3, [&]() {
-    int cnt = 2;
-    stream << Tab(4) << "__Result = 0," << NLine(1);
-    stream << Tab(4) << "__Callback = 1," << NLine(1);
-    for (const auto& i : iface.GetDeclarations()) {
-      if (i->GetMethodType() == Declaration::MethodType::DELEGATE)
-        continue;
-      stream << Tab(4)
-             << i->GetID() << " = " << cnt++ << "," << NLine(1);
-    }
-  });
+std::string CsGeneratorBase::GetMethodId(const Interface& iface) {
+  return std::string(ReplaceAll(CB_METHOD_IDS)
+      .Change("<METHOD_IDS>", [&](){
+        int cnt = 2;
+        std::string str;
+        for (const auto& i : iface.GetDeclarations()) {
+          if (i->GetMethodType() == Declaration::MethodType::DELEGATE)
+            continue;
+          str += Tab(4) + i->GetID() + " = " + std::to_string(cnt++) + "," + NLine(1);
+        }
+        return str;
+      }));
+}
+
+void CsGeneratorBase::GenMethodId(std::ofstream& stream, const Interface& iface) {
+  stream << GetMethodId(iface);
 }
 
 void CsGeneratorBase::GenDelegateId(std::ofstream& stream,
@@ -380,14 +405,20 @@ void CsGeneratorBase::GenDelegateId(std::ofstream& stream,
 }
 
 void CsGeneratorBase::GenDeclaration(std::ofstream& stream,
-                                     const Declaration& decl, bool semicol) {
-  stream << ConvertTypeToString(decl.GetType()) << " "
-         << decl.GetID() << "(";
-  GenParameters(stream, decl.GetParameters());
+    const Declaration& decl, bool semicol) {
+  stream << GetDeclaration(decl, semicol);
+}
+
+std::string CsGeneratorBase::GetDeclaration(const Declaration& decl, bool semicol) {
+  std::string ret;
+  ret += ConvertTypeToString(decl.GetType()) + " "
+      + decl.GetID() + "(";
+  ret += GetParameters(decl.GetParameters());
   if (semicol)
-    stream << ");";
+    ret += ");";
   else
-    stream << ")";
+    ret += ")";
+  return ret;
 }
 
 void CsGeneratorBase::GenParameters(std::ofstream& stream,
index c7c4cdd..7400a4c 100644 (file)
@@ -36,13 +36,19 @@ class CsGeneratorBase : public Generator {
   void GenStructures(std::ofstream& stream);
   void GenStructure(std::ofstream& stream, const Structure& st);
   void GenSerializer(std::ofstream& stream);
+  std::string GetSerializer();
   void GenSerializer(std::ofstream& stream, const Structure& st);
+  std::string GetSerializer(const Structure& st);
   void GenListSerializer(std::ofstream& stream);
+  std::string GetListSerializer();
   void GenListSerializer(std::ofstream& stream, const BaseType& type);
+  std::string GetListSerializer(const BaseType& type);
   void GenMethodId(std::ofstream& stream, const Interface& iface);
+  std::string GetMethodId(const Interface& iface);
   void GenDelegateId(std::ofstream& stream, const Interface& iface);
   void GenDeclaration(std::ofstream& stream,
                       const Declaration& decl, bool semicol = true);
+  std::string GetDeclaration(const Declaration& decl, bool semicol = true);
   void GenParameters(std::ofstream& stream, const Parameters& ps);
   void GenCallbacks(std::ofstream& stream, const Interface& iface,
                     bool is_proxy);
index aabc490..c349111 100644 (file)
@@ -126,4 +126,55 @@ R"__cs_cb(
                 }
 )__cs_cb";
 
+const char CB_METHOD_IDS[] =
+R"__cs_cb(
+            private enum MethodId : int
+            {
+                __Result = 0,
+                __Callback = 1,
+<METHOD_IDS>
+            }
+)__cs_cb";
+
+const char CB_SERIALIZER[] =
+R"__cs_cb(
+            private static void Serialize(Parcel h, <TYPE> param)
+            {
+<BODY>
+            }
+)__cs_cb";
+
+const char CB_DESERIALIZER[] =
+R"__cs_cb(
+            private static void Deserialize(Parcel h, <TYPE> param)
+            {
+<BODY>
+            }
+)__cs_cb";
+
+const char CB_LIST_SERIALIZER[] =
+R"__cs_cb(
+            private static void Serialize(Parcel h, <TYPE> param)
+            {
+                h.WriteArrayCount(param.Count);
+                foreach (var i in param)
+                {
+<BODY>
+                }
+            }
+)__cs_cb";
+
+const char CB_LIST_DESERIALIZER[] =
+R"__cs_cb(
+            private static void Deserialize(Parcel h, <TYPE> param)
+            {
+                int l = h.ReadArrayCount();
+                for (int i = 0; i < l; i++)
+                {
+<BODY>
+                }
+            }
+)__cs_cb";
+
+
 #endif  // IDLC_CS_GEN_CS_GEN_BASE_CB_H_
diff --git a/idlc/gen/cs_group_gen.cc b/idlc/gen/cs_group_gen.cc
new file mode 100644 (file)
index 0000000..b1161e5
--- /dev/null
@@ -0,0 +1,155 @@
+/*
+ * Copyright (c) 2022 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/gen/cs_group_gen.h"
+
+namespace {
+#include "idlc/gen/cs_group_gen_cb.h"
+}
+
+namespace tidl {
+
+CsGroupGen::CsGroupGen(std::shared_ptr<Document> doc)
+    : CsGeneratorBase(doc) {}
+
+void CsGroupGen::OnInitGen(std::ofstream& stream) {
+  GenVersion(stream);
+  stream << CB_USING;
+  GenNamespace(stream);
+}
+
+void CsGroupGen::OnFiniGen(std::ofstream& stream) {
+}
+
+void CsGroupGen::GenNamespace(std::ofstream& stream) {
+  stream << NLine(1);
+  stream << "namespace RPCPort" << NLine(1);
+  GenBrace(stream, 0, [&]() {
+    stream << "namespace " << GetFileNamespace() << NLine(1);
+    GenBrace(stream, 0, [&]() {
+      GenStructures(stream);
+      stream << Tab(1) << "namespace Group" << NLine(1);
+      GenBrace(stream, TAB_SIZE, [&]() {
+        GenInterfaces(stream);
+      });
+    });
+  });
+}
+
+void CsGroupGen::GenInterfaces(std::ofstream& stream) {
+  for (auto& i : GetDocument().GetBlocks()) {
+    if (i->GetType() != Block::TYPE_INTERFACE)
+      continue;
+    Interface& iface = static_cast<Interface&>(*i);
+    GenInterface(stream, iface);
+    stream << NLine(1);
+  }
+}
+
+void CsGroupGen::GenInterface(std::ofstream& stream, const Interface& iface) {
+  ReplaceAll(CB_INTERFACE_FULL)
+      .Change("<CLS_NAME>", iface.GetID())
+      .Change("<METHOD_IDS>", GetMethodId(iface))
+      .Change("<SERIALIZER>", GetSerializer())
+      .Change("<LIST_SERIALIZER>", GetListSerializer())
+      .Change("<METHODS>", GetMethods(iface))
+      .Change("<DISPATCHERS>", GetDispatchers(iface))
+      .Out(stream);
+}
+
+std::string CsGroupGen::GetDispatchers(const Interface& iface) {
+  std::string ret;
+  for (const auto& i : iface.GetDeclarations()) {
+    ret += ReplaceAll(CB_DISPATCHER)
+        .Change("<METHOD_ID>", i->GetID())
+        .Change("<PARAM_DESERIALIZER>", GetParamDeserializer(*i))
+        .Change("<CALL_PARAMS>", GetCallParams(*i));
+  }
+
+  return ret;
+}
+
+std::string CsGroupGen::GetMethods(const Interface& iface) {
+  std::string ret;
+  auto& decls = iface.GetDeclarations();
+  for (const auto& i : decls) {
+    ret += ReplaceAll(CB_METHOD)
+        .Change("<PARAMS>", GetParameters(i->GetParameters()))
+        .Change("<COMMENTS>", i->GetComments().empty() ? "" :
+            AddIndent(TAB_SIZE * 3, i->GetComments()))
+        .Change("<DECL>", GetDeclaration(*i, false))
+        .Change("<METHOD_ID>", i->GetID())
+        .Change("<PARAM_SERIALIZER>", GetParamSerializer(*i))
+        .Change("<CLS_NAME>", iface.GetID());
+  }
+
+  return ret;
+}
+
+std::string CsGroupGen::GetParamSerializer(const Declaration& decl) {
+  std::string m;
+  for (const auto& i : decl.GetParameters()) {
+    auto& pt = i->GetParameterType();
+    if (pt.GetDirection() == ParameterType::Direction::OUT)
+      continue;
+    m += Tab(5) + ConvertTypeToSerializer(pt.GetBaseType(), i->GetID(), "p");
+  }
+
+  return m;
+}
+
+std::string CsGroupGen::GetParamDeserializer(const Declaration& decl) {
+  int cnt = 1;
+  std::string m;
+  for (const auto& i : decl.GetParameters()) {
+    if (i->GetParameterType().GetDirection() == ParameterType::Direction::OUT) {
+      cnt++;
+      continue;
+    }
+
+    std::string v = "param" + std::to_string(cnt);
+    std::string c = ConvertTypeToDeserializer(
+        i->GetParameterType().GetBaseType(), v, "p");
+    m += AddIndent(TAB_SIZE * 6, c);
+    cnt++;
+  }
+
+  return m;
+}
+
+std::string CsGroupGen::GetCallParams(const Declaration& decl) {
+  int cnt = 1;
+  std::string m;
+  for (const auto& i : decl.GetParameters()) {
+    if (cnt != 1) {
+      m += ", ";
+    }
+
+    std::string v = "param" + std::to_string(cnt);
+    auto& pt = i->GetParameterType();
+    if (pt.GetDirection() == ParameterType::Direction::OUT) {
+      m += "out " + ConvertTypeToString(pt.GetBaseType()) + " ";
+    } else if (pt.GetDirection() == ParameterType::Direction::REF) {
+      m += "ref ";
+    }
+    m += v;
+    cnt++;
+  }
+
+  return m;
+}
+
+}  // namespace tidl
diff --git a/idlc/gen/cs_group_gen.h b/idlc/gen/cs_group_gen.h
new file mode 100644 (file)
index 0000000..59bb5dd
--- /dev/null
@@ -0,0 +1,48 @@
+/*
+ * Copyright (c) 2022 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_GEN_CS_GROUP_GEN_H_
+#define IDLC_GEN_CS_GROUP_GEN_H_
+
+#include <memory>
+#include <string>
+
+#include "idlc/gen/cs_gen_base.h"
+
+namespace tidl {
+
+class CsGroupGen : public CsGeneratorBase {
+ public:
+  explicit CsGroupGen(std::shared_ptr<Document> doc);
+  virtual ~CsGroupGen() = default;
+
+  void OnInitGen(std::ofstream& stream) override;
+  void OnFiniGen(std::ofstream& stream) override;
+
+ private:
+  void GenNamespace(std::ofstream& stream);
+  void GenInterfaces(std::ofstream& stream);
+  void GenInterface(std::ofstream& stream, const Interface& iface);
+  std::string GetMethods(const Interface& iface);
+  std::string GetParamSerializer(const Declaration& decl);
+  std::string GetParamDeserializer(const Declaration& decl);
+  std::string GetDispatchers(const Interface& iface);
+  std::string GetCallParams(const Declaration& decl);
+};
+
+}  // namespace tidl
+
+#endif  // IDLC_GEN_CS_GROUP_GEN_H_
\ No newline at end of file
diff --git a/idlc/gen/cs_group_gen_cb.h b/idlc/gen/cs_group_gen_cb.h
new file mode 100644 (file)
index 0000000..d5aaada
--- /dev/null
@@ -0,0 +1,152 @@
+/*
+ * Copyright (c) 2022 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_GEN_CS_GROUP_GEN_CB_H_
+#define IDLC_GEN_CS_GROUP_GEN_CB_H_
+
+const char CB_USING[] =
+R"__cs_cb(
+using System;
+using Tizen.Applications;
+using Tizen.Applications.EventManager;
+using Tizen.Applications.RPCPort;
+
+)__cs_cb";
+
+const char CB_INTERFACE_FULL[] =
+R"__cs_cb(
+        public class <CLS_NAME> : IDisposable
+        {
+            private EventReceiver _eventReceiver;
+            private Object _lock = new Object();
+            private bool _disposedValue = false;
+
+            private Bundle GetBundleFromParcel(Parcel p)
+            {
+                byte[] bytes = p.ToBytes();
+                Bundle b = new Bundle();
+                b.AddItem("TIDL_RAW", bytes);
+                return b;
+            }
+
+            private Parcel GetParcelFromBundle(Bundle b)
+            {
+                byte[] bytes = (byte[])b.GetItem("TIDL_RAW");
+
+                return new Parcel(bytes);
+            }
+
+            private string GetEventName(string appid, string iface_name)
+            {
+                return "event." + appid + ".tidl_iface_" + iface_name;
+            }
+
+            private void OnReceive(Parcel p)
+            {
+                int cmd = p.ReadInt();
+
+                switch ((MethodId)cmd)
+                {
+<DISPATCHERS>
+                }
+            }
+
+<METHOD_IDS>
+<SERIALIZER>
+<LIST_SERIALIZER>
+
+            public <CLS_NAME>(string senderAppid)
+            {
+                string eventName = GetEventName(senderAppid, "<CLS_NAME>");
+                _eventReceiver = new EventReceiver(eventName);
+                _eventReceiver.Received += (obj, args) =>
+                {
+                    Bundle b = args.Data;
+                    using (var parcel = GetParcelFromBundle(b))
+                    {
+                        OnReceive(parcel);
+                    }
+                };
+            }
+
+            public <CLS_NAME>()
+            {
+            }
+
+            ~<CLS_NAME>()
+            {
+                Dispose(false);
+            }
+
+            protected void Dispose(bool disposing)
+            {
+                if (!_disposedValue)
+                {
+                    if (disposing)
+                    {
+                        if (_eventReceiver != null)
+                        {
+                            _eventReceiver.Dispose();
+                            _eventReceiver = null;
+                        }
+                    }
+
+                    _disposedValue = true;
+                }
+            }
+
+            public void Dispose()
+            {
+                Dispose(true);
+                GC.SuppressFinalize(this);
+            }
+
+<METHODS>
+
+        }
+)__cs_cb";
+
+const char CB_METHOD[] =
+R"__cs_cb(
+            public delegate void <METHOD_ID>EventHandler(<PARAMS>);
+            public event <METHOD_ID>EventHandler <METHOD_ID>Event;
+<COMMENTS>
+            public <DECL>
+            {
+                using (Parcel p = new Parcel())
+                {
+                    p.WriteInt((int)MethodId.<METHOD_ID>);
+<PARAM_SERIALIZER>
+                    var bundle = GetBundleFromParcel(p);
+                    string eventName = GetEventName(Application.Current.ApplicationInfo.ApplicationId, "<CLS_NAME>");
+                    ApplicationEventManager.Publish(eventName, bundle);
+                }
+            }
+)__cs_cb";
+
+const char CB_DISPATCHER[] =
+R"__cs_cb(
+                    case MethodId.<METHOD_ID>:
+                    {
+<PARAM_DESERIALIZER>
+                        <METHOD_ID>Event?.Invoke(<CALL_PARAMS>);
+                        break;
+                    }
+)__cs_cb";
+
+
+
+#endif  // IDLC_GEN_CS_GROUP_GEN_CB_H_
index 4df018a..4e4228f 100644 (file)
@@ -22,6 +22,7 @@
 #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"
@@ -338,7 +339,12 @@ void GenerateGroupCodes(std::shared_ptr<tidl::Options> options,
       }
 
       case tidl::Options::LANGUAGE_TYPE_CSHARP:
-      case tidl::Options::LANGUAGE_TYPE_JAVA:
+      {
+        tidl::CsGroupGen group(ps.GetDoc());
+        group.Run(options->GetOutput() + ".cs");
+        break;
+      }
+
       default:
         break;
     }