Support enum type for C++ generator 78/296978/12
authorHwankyu Jhun <h.jhun@samsung.com>
Tue, 8 Aug 2023 04:30:17 +0000 (13:30 +0900)
committerHwankyu Jhun <h.jhun@samsung.com>
Wed, 9 Aug 2023 08:18:31 +0000 (17:18 +0900)
This patch supports the enumeration type.

Change-Id: If6dce33a7e5c6ba87bdf9dd84e10641b6642c08a
Signed-off-by: Hwankyu Jhun <h.jhun@samsung.com>
17 files changed:
idlc/ast/element.cc
idlc/ast/element.h
idlc/ast/structure.h
idlc/ast/type.cc
idlc/ast/type.h
idlc/gen/c_gen_base.cc
idlc/gen/version2/cpp_generator_base.cc
idlc/gen/version2/cpp_generator_base.hh
idlc/gen/version2/cpp_generator_base_cb.hh
idlc/gen/version2/cpp_group_header_generator.cc
idlc/gen/version2/cpp_group_header_generator_cb.hh
idlc/gen/version2/cpp_proxy_body_generator.cc
idlc/gen/version2/cpp_proxy_header_generator.cc
idlc/gen/version2/cpp_proxy_header_generator_cb.hh
idlc/gen/version2/cpp_stub_header_generator.cc
idlc/gen/version2/cpp_stub_header_generator_cb.hh
tests/build_tests/tidl/Message_v2test.tidl

index 523a0cbccd3a0c5c9445598b1146dfd270317843..580a764373af436a38f4003507317baa81399a2f 100644 (file)
@@ -64,4 +64,8 @@ std::list<std::shared_ptr<Element>>::const_iterator Elements::end() const {
   return elms_.cend();
 }
 
+bool Elements::Empty() const {
+  return elms_.empty();
+}
+
 }  // namespace tidl
index 436d87d4ea09af099c1ecaa8ee3131834ecef174..531617ba65bb6c2679490884cf61a10482dd105d 100644 (file)
@@ -14,8 +14,8 @@
  * limitations under the License.
  */
 
-#ifndef IDLC_ELEMENT_H_
-#define IDLC_ELEMENT_H_
+#ifndef IDLC_AST_ELEMENT_H_
+#define IDLC_AST_ELEMENT_H_
 
 #include <string>
 #include <list>
@@ -49,6 +49,7 @@ class Elements {
   bool Exist(const Element& elm) const;
   std::list<std::shared_ptr<Element>>::const_iterator begin() const;
   std::list<std::shared_ptr<Element>>::const_iterator end() const;
+  bool Empty() const;
 
  private:
   std::list<std::shared_ptr<Element>> elms_;
@@ -56,4 +57,4 @@ class Elements {
 
 }  // namespace tidl
 
-#endif  // IDLC_ELEMENT_H_
+#endif  // IDLC_AST_ELEMENT_H_
index 06c06d21a8e0070576f29805c2a53393a3be8095..816ea021c984bcbd1e23a06a1f51ac164a357f54 100644 (file)
@@ -14,8 +14,8 @@
  * limitations under the License.
  */
 
-#ifndef IDLC_STRUCTURE_H_
-#define IDLC_STRUCTURE_H_
+#ifndef IDLC_AST_STRUCTURE_H_
+#define IDLC_AST_STRUCTURE_H_
 
 #include <string>
 #include <memory>
@@ -44,5 +44,5 @@ class Structure : public Block {
 
 }  // namespace tidl
 
-#endif  // IDLC_STRUCTURE_H_
+#endif  // IDLC_AST_STRUCTURE_H_
 
index 4441fe0bc3be86d13f46f7191595ea6a7e06c64b..802d51b15955a9ba5e13d71863f5074590d33ee6 100644 (file)
@@ -144,6 +144,18 @@ bool BaseType::IsUserDefinedType() const {
   return user_defined_;
 }
 
+bool BaseType::IsEnumType() const {
+  return user_type_ == UserType::ENUM;
+}
+
+bool BaseType::IsStructureType() const {
+  return user_type_ == UserType::STRUCTURE;
+}
+
+bool BaseType::IsDelegateType() const {
+  return user_type_ == UserType::DELEGATE;
+}
+
 bool BaseType::IsFile(const BaseType* type) {
   if (type == nullptr)
     return false;
index bb74a87387bd0a9073e2fb9b7db08dfc0c25d48b..1d39e1b7c429b3c1692ad6710d783b22fd11cd4a 100644 (file)
@@ -74,6 +74,10 @@ class BaseType : public Token {
     return user_type_;
   }
 
+  bool IsEnumType() const;
+  bool IsStructureType() const;
+  bool IsDelegateType() const;
+
   static bool IsFile(const BaseType* type);
   static bool IsKeyType(const BaseType* type);
 
index 01f259264df63312c8d9ac1b07f5f02558eafdb3..b259c6de69670edac8546747c8c877681f423ca4 100644 (file)
@@ -143,23 +143,25 @@ std::string CGeneratorBase::GetFullNameFromType(const BaseType& type,
 }
 
 std::string CGeneratorBase::GetDataTypeString(const BaseType& type,
-  bool is_pointer, const std::string& id) {
-   if (type.GetUserDefinedType() == BaseType::UserType::ENUM) {
-     auto n = type.ToString().find('.');
-     if (id.empty()&& n == std::string::npos) {
-        if (is_pointer)
-          return GetEnumTypeString(ParameterType::Direction::OUT, type,
-              GetEnumBockString(type.ToString()));
-        else
-          return GetEnumTypeString(ParameterType::Direction::IN, type,
-              GetEnumBockString(type.ToString()));
+                                              bool is_pointer,
+                                              const std::string& id) {
+  if (type.GetUserDefinedType() == BaseType::UserType::ENUM) {
+    auto n = type.ToString().find('.');
+    if (id.empty() && n == std::string::npos) {
+      if (is_pointer) {
+        return GetEnumTypeString(ParameterType::Direction::OUT, type,
+                                 GetEnumBockString(type.ToString()));
+      } else {
+        return GetEnumTypeString(ParameterType::Direction::IN, type,
+                                 GetEnumBockString(type.ToString()));
       }
+    }
 
-     if (is_pointer)
-       return GetEnumTypeString(ParameterType::Direction::OUT, type, id);
-     else
-       return GetEnumTypeString(ParameterType::Direction::IN, type, id);
-   }
+    if (is_pointer)
+      return GetEnumTypeString(ParameterType::Direction::OUT, type, id);
+    else
+      return GetEnumTypeString(ParameterType::Direction::IN, type, id);
+  }
 
   if (type.GetUserDefinedType() == BaseType::UserType::STRUCTURE ||
       type.GetUserDefinedType() == BaseType::UserType::DELEGATE)
@@ -454,13 +456,12 @@ std::string CGeneratorBase::GetEnumTypeString(const std::string& id) {
   std::string type_id;
 
   auto n = id.find('.');
-  if (n == std::string::npos) {
+  if (n == std::string::npos)
     return id;
-  } else {
-    block_id = id.substr(0, n);
-    type_id = id.substr(n + 1, id.size() - (n + 1));
-    return block_id + "_" + type_id;
-  }
+
+  block_id = id.substr(0, n);
+  type_id = id.substr(n + 1, id.size() - (n + 1));
+  return block_id + "_" + type_id;
 }
 
 std::string CGeneratorBase::GetEnumTypeString(
@@ -555,8 +556,8 @@ std::string CGeneratorBase::GetParamTypeString(
 }
 
 std::string CGeneratorBase::GetEnumBockString(const std::string& id) {
-   for (auto& b : GetDocument().GetBlocks()) {
-     for (auto& e : b->GetEnums()) {
+  for (auto& b : GetDocument().GetBlocks()) {
+    for (auto& e : b->GetEnums()) {
       if (e->GetID() == id) {
         return b->GetID();
       }
index 3122e51f1d35e7a0d55ac4069a3fece5bf52d4ec..f463197660c88cd47e0e955d9e4cae2f1ea23826 100644 (file)
@@ -27,6 +27,9 @@ namespace version2 {
 namespace {
 
 bool IsObject(const BaseType& type) {
+  if (type.IsEnumType())
+    return false;
+
   if (type.IsUserDefinedType() ||
       type.GetMetaType() != nullptr ||
       type.GetKeyType() != nullptr ||
@@ -227,6 +230,9 @@ std::string CppGeneratorBase::NLine(int cnt) {
 
 std::string CppGeneratorBase::ConvertTypeToString(const BaseType& type,
     bool full_name) {
+  if (type.IsEnumType())
+    return GetEnumTypeString(type.ToString());
+
   if (type.IsUserDefinedType()) {
     if (IsDelegateType(type)) {
       std::string name = type.ToString();
@@ -302,14 +308,23 @@ std::string CppGeneratorBase::GenStructuresForHeader(bool use_file) {
 }
 
 std::string CppGeneratorBase::GenStructureForHeader(const Structure& st) {
-  return std::string(
-      ReplaceAll(CB_HEADER_STRUCTURE_BASE)
+  std::string code;
+  if (st.GetElements().Empty()) {
+    code = ReplaceAll(CB_HEADER_STRUCTURE_BASE_EMPTY)
+        .Change("<CLS_NAME>", st.GetID())
+        .Change("<ENUMS>\n", GenEnumerations(st.GetEnums()));
+  } else {
+    code = ReplaceAll(CB_HEADER_STRUCTURE_BASE)
           .Change("<CLS_NAME>", st.GetID())
           .Change("<PARAMS>", GenParameters(st.GetElements()))
+          .Change("<ENUMS>\n", GenEnumerations(st.GetEnums()))
           .Change("<GETTER_SETTER>",
                   GenStructureGetterSetterForHeader(st.GetElements()))
           .Change("<MEMBERS>\n",
-                  GenStructureMembersForHeader(st.GetElements())));
+                  GenStructureMembersForHeader(st.GetElements()));
+  }
+
+  return code;
 }
 
 std::string CppGeneratorBase::GenStructureGetterSetterForHeader(
@@ -446,12 +461,19 @@ std::string CppGeneratorBase::GenStructures(bool use_file) {
 }
 
 std::string CppGeneratorBase::GenStructure(const Structure& st) {
-  return std::string(
-      ReplaceAll(CB_BODY_STRUCTURE_BASE)
-          .Change("<CLS_NAME>", st.GetID())
-          .Change("<PARAMS>", GenParameters(st.GetElements()))
-          .Change("<MEMBER_INIT>", GenStructureMemberInit(st.GetElements()))
-          .Change("<GETTER_SETTER>", GenStructureGetterSetter(st)));
+  std::string code;
+  if (st.GetElements().Empty()) {
+    code = ReplaceAll(CB_BODY_STRUCTURE_BASE_EMPTY)
+               .Change("<CLS_NAME>", st.GetID());
+  } else {
+    code = ReplaceAll(CB_BODY_STRUCTURE_BASE)
+            .Change("<CLS_NAME>", st.GetID())
+            .Change("<PARAMS>", GenParameters(st.GetElements()))
+            .Change("<MEMBER_INIT>", GenStructureMemberInit(st.GetElements()))
+            .Change("<GETTER_SETTER>", GenStructureGetterSetter(st));
+  }
+
+  return code;
 }
 
 std::string CppGeneratorBase::GenStructureMemberInit(const Elements& elms) {
@@ -489,58 +511,122 @@ std::string CppGeneratorBase::GetSetterValue(const BaseType& type,
 }
 
 void CppGeneratorBase::InitUnitTypes(bool use_file) {
-  AddUnitType("int", BaseType("int", ""));
-  AddUnitType("bool", BaseType("bool", ""));
-  AddUnitType("string", BaseType("string", ""));
-  AddUnitType("bundle", BaseType("bundle", ""));
+  AddUnitType("int", BaseType("int", ""), "");
+  AddUnitType("bool", BaseType("bool", ""), "");
+  AddUnitType("string", BaseType("string", ""), "");
+  AddUnitType("bundle", BaseType("bundle", ""), "");
   if (use_file)
-    AddUnitType("file", BaseType("file", ""));
+    AddUnitType("file", BaseType("file", ""), "");
 
   for (auto& block : GetDocument().GetBlocks()) {
     if (block->GetType() == Block::TYPE_INTERFACE) {
       auto& iface = static_cast<const Interface&>(*block);
+      for (const auto& e : iface.GetEnums()) {
+        std::string name = iface.GetID() + "." + e->GetID();
+        AddUnitType(name, BaseType(name, "", BaseType::UserType::ENUM),
+                    iface.GetID());
+      }
+
       for (const auto& decl : iface.GetDeclarations()) {
         if (decl->GetMethodType() == Declaration::MethodType::DELEGATE) {
           AddUnitType("delegate",
-              BaseType(iface.GetID() + "::CallbackBase", "", true));
-          AddUnitType(decl->GetID(), BaseType(decl->GetID(), "", true));
+                      BaseType(iface.GetID() + "::CallbackBase", "", true),
+                      iface.GetID());
+          AddUnitType(decl->GetID(), BaseType(decl->GetID(), "", true),
+                      iface.GetID());
         } else if (decl->GetMethodType() == Declaration::MethodType::SYNC) {
           auto& type = decl->GetType();
-          AddUnitType(type.GetFullName(false), BaseType(type));
+          AddUnitType(type.GetFullName(false), BaseType(type), iface.GetID());
         }
 
         for (const auto& param : decl->GetParameters()) {
           auto& type = param->GetParameterType().GetBaseType();
-          AddUnitType(type.GetFullName(false), BaseType(type));
+          if (type.IsEnumType()) continue;
+
+          AddUnitType(type.GetFullName(false), BaseType(type), iface.GetID());
         }
       }
     } else if (block->GetType() == Block::TYPE_STRUCTURE) {
       auto& st = static_cast<const Structure&>(*block);
-      AddUnitType(st.GetID(), BaseType(st.GetID(), "", true));
+      AddUnitType(st.GetID(), BaseType(st.GetID(), "", true), st.GetID());
+      for (const auto& e : st.GetEnums()) {
+        std::string name = st.GetID() + "." + e->GetID();
+        AddUnitType(name, BaseType(name, "", BaseType::UserType::ENUM),
+                    st.GetID());
+      }
+
       for (const auto& elm : st.GetElements()) {
         auto& type = elm->GetType();
-        AddUnitType(type.GetFullName(false), BaseType(type));
+        if (type.IsEnumType()) continue;
+
+        AddUnitType(type.GetFullName(false), BaseType(type), st.GetID());
       }
     }
   }
 }
 
-void CppGeneratorBase::AddUnitType(std::string name, BaseType type) {
+std::string CppGeneratorBase::GetUnitTypeKey(std::string name,
+                                             const BaseType& type,
+                                             const std::string& block_id) {
+  if (type.GetMetaType() != nullptr) {
+    auto* meta_type = type.GetMetaType();
+    if (meta_type->IsEnumType() &&
+        meta_type->ToString().find('.') == std::string::npos) {
+      return type.ToString() + "<" + block_id + "." + meta_type->ToString() +
+             ">";
+    }
+  }
+
+  if (type.GetKeyType() != nullptr) {
+    std::string key = type.ToString() + "<";
+    auto* key_type = type.GetKeyType();
+    if (key_type->IsEnumType() &&
+        key_type->ToString().find('.') == std::string::npos)
+      key += block_id + "." + key_type->ToString();
+    else
+      key += key_type->ToString();
+
+    if (type.GetValueType() != nullptr) {
+      auto* value_type = type.GetValueType();
+      if (value_type->IsEnumType() &&
+          value_type->ToString().find('.') == std::string::npos)
+        key += ", " + block_id + "." + value_type->ToString();
+      else
+        key += ", " + value_type->ToString();
+    }
+
+    key += ">";
+    return key;
+  }
+
+  return name;
+}
+
+void CppGeneratorBase::AddUnitType(std::string name, BaseType type,
+    const std::string& block_id) {
   if (type.GetMetaType() != nullptr) {
     auto meta_type = type.GetMetaType();
-    AddUnitType(meta_type->GetFullName(false), BaseType(*meta_type));
+    if (!meta_type->IsEnumType()) {
+      AddUnitType(meta_type->GetFullName(false), BaseType(*meta_type),
+                  block_id);
+    }
   }
 
   if (type.GetKeyType() != nullptr) {
     auto key_type = type.GetKeyType();
-    AddUnitType(key_type->GetFullName(false), BaseType(*key_type));
+    if (!key_type->IsEnumType())
+      AddUnitType(key_type->GetFullName(false), BaseType(*key_type), block_id);
 
     if (type.GetValueType() != nullptr) {
       auto value_type = type.GetValueType();
-      AddUnitType(value_type->GetFullName(false), BaseType(*value_type));
+      if (!value_type->IsEnumType()) {
+        AddUnitType(value_type->GetFullName(false), BaseType(*value_type),
+                    block_id);
+      }
     }
   }
 
+  name = GetUnitTypeKey(name, type, block_id);
   unit_types_[std::move(name)] = std::move(type);
 }
 
@@ -554,6 +640,9 @@ std::string CppGeneratorBase::GenUnitMap(bool use_file) {
 }
 
 std::string CppGeneratorBase::GetFullNameFromType(const BaseType& type) {
+  if (type.IsEnumType())
+    return "int";
+
   if (IsDelegateType(type) ||
       type.ToString().find("::CallbackBase") != std::string::npos)
     return "delegate";
@@ -605,7 +694,9 @@ std::string CppGeneratorBase::GenUnitSerializerBodies() {
 
 std::string CppGeneratorBase::GenUnitImplSerializer(const BaseType& type) {
   std::string code;
-  if (type.IsUserDefinedType() || type.GetMetaType() != nullptr ||
+  if (type.IsEnumType()) {
+    code = CB_UNIT_IMPL_SERIALIZER_ENUM;
+  } else if (type.IsUserDefinedType() || type.GetMetaType() != nullptr ||
       type.GetKeyType() != nullptr) {
     if (IsDelegateType(type)) {
       code = CB_UNIT_IMPL_SERIALIZER_DELEGATE;
@@ -658,7 +749,10 @@ std::string CppGeneratorBase::GenUnitMapWrite(const BaseType& type) {
 
 std::string CppGeneratorBase::GenUnitImplDeserializer(const BaseType& type) {
   std::string code;
-  if (type.IsUserDefinedType() || type.GetMetaType() != nullptr ||
+  if (type.IsEnumType()) {
+    code = ReplaceAll(CB_UNIT_IMPL_DESERIALIZER_ENUM)
+        .Change("<TYPE>", ConvertTypeToString(type));
+  } else if (type.IsUserDefinedType() || type.GetMetaType() != nullptr ||
       type.GetKeyType() != nullptr) {
     if (IsDelegateType(type)) {
       code = ReplaceAll(CB_UNIT_IMPL_DESERIALIZER_DELEGATE)
@@ -718,6 +812,9 @@ std::string CppGeneratorBase::GenUnitMapRead(const BaseType& type) {
 }
 
 std::string CppGeneratorBase::GetParcelType(const BaseType& type) {
+  if (type.IsEnumType())
+    return "int32";
+
   return parcel_type_map_[type.ToString()];
 }
 
@@ -746,5 +843,54 @@ std::string CppGeneratorBase::GetSettingInitValue(const BaseType& type) {
   return code;
 }
 
+std::string CppGeneratorBase::GetClassNameFromEnumType(
+  const std::string& type) {
+  for (auto& block : GetDocument().GetBlocks()) {
+    for (const auto& e : block->GetEnums()) {
+      if (e->GetID() == type)
+        return block->GetID();
+    }
+  }
+
+  return {};
+}
+
+std::string CppGeneratorBase::GetEnumTypeString(const std::string& type,
+    bool use_underbar) {
+  std::string concatenated_char = use_underbar ? "_" : "::";
+  auto pos = type.find('.');
+  if (pos == std::string::npos) {
+    std::string cls_name = GetClassNameFromEnumType(type);
+    if (!cls_name.empty())
+      return cls_name + concatenated_char + type;
+
+    return type;
+  }
+
+  std::string block_id = type.substr(0, pos);
+  std::string type_id = type.substr(pos + 1, type.size() - (pos + 1));
+  return block_id + concatenated_char + type_id;
+}
+
+std::string CppGeneratorBase::GenEnumerations(const Enums& enums) {
+  std::string code;
+  for (const auto& e : enums) {
+    std::string enum_fields;
+    for (const auto& f : e->GetFields()) {
+      if (f->GetValue().empty())
+        enum_fields += f->GetID() + "," + NLine(1);
+      else
+        enum_fields += f->GetID() + " = " + f->GetValue() + "," + NLine(1);
+    }
+
+    code += ReplaceAll(CB_ENUM_BASE)
+        .Change("<NAME>", e->GetID())
+        .Change("<ENUMS>", enum_fields);
+    code += NLine(1);
+  }
+
+  return RemoveLine(code);
+}
+
 }  // namespace version2
 }  // namespace tidl
index 7ca4d091bc3a058f055ad4303383ddac70b75051..6b251c563a791c3133da4f7a95c23351e1b061ae 100644 (file)
@@ -31,7 +31,7 @@ namespace version2 {
 class CppGeneratorBase : public tidl::Generator {
  public:
   explicit CppGeneratorBase(std::shared_ptr<Document> doc,
-      bool thread_enabled = false);
+                            bool thread_enabled = false);
   virtual ~CppGeneratorBase() = default;
 
   void GenVersion(std::ofstream& stream);
@@ -60,6 +60,7 @@ class CppGeneratorBase : public tidl::Generator {
   std::string GenUnitMap(bool use_file = true);
   std::string GenPrivateSharing(const Parameter& param);
   std::string GetSettingInitValue(const BaseType& type);
+  std::string GenEnumerations(const Enums& enums);
 
  private:
   std::string GenStructureForHeader(const Structure& st);
@@ -69,7 +70,10 @@ class CppGeneratorBase : public tidl::Generator {
   std::string GenStructureMemberInit(const Elements& elms);
   std::string GenStructureGetterSetter(const Structure& st);
   void InitUnitTypes(bool use_file);
-  void AddUnitType(std::string name, BaseType type);
+  std::string GetUnitTypeKey(std::string name, const BaseType& type,
+                             const std::string& block_id);
+  void AddUnitType(std::string name, BaseType type,
+                   const std::string& block_id);
   std::string GenUnitMapReadWrite();
   std::string GenUnit();
   std::string GenUnitSerializerHeaders();
@@ -80,6 +84,9 @@ class CppGeneratorBase : public tidl::Generator {
   std::string GenUnitMapRead(const BaseType& type);
   std::string GetParcelType(const BaseType& type);
   std::string GetFullNameFromType(const BaseType& type);
+  std::string GetClassNameFromEnumType(const std::string& type);
+  std::string GetEnumTypeString(const std::string& type,
+                                bool use_underbar = false);
 
  private:
   bool thread_enabled_;
index fc4148f4c3ff216345d55144858dda1d4a5730f7..6cba6b6e5e7e973d2c0d6e040432c42c24323c99 100644 (file)
@@ -203,6 +203,7 @@ class UnitMap;
 /**
  * <CLS_NAME> The class name of the structure.
  * <PARAMS> The parameters of the structure.
+ * <ENUMS> The enumerations of the structure.
  * <GETTER_SETTER> The getters and setters.
  * <MEMBERS> The member variables of the structure.
  */
@@ -210,6 +211,7 @@ constexpr const char CB_HEADER_STRUCTURE_BASE[] =
 R"__cpp_cb(
 class <CLS_NAME> final {
  public:
+  <ENUMS>
   <CLS_NAME>();
   <CLS_NAME>(<PARAMS>);
   <GETTER_SETTER>
@@ -218,6 +220,26 @@ class <CLS_NAME> final {
 };
 )__cpp_cb";
 
+constexpr const char CB_HEADER_STRUCTURE_BASE_EMPTY[] =
+R"__cpp_cb(
+class <CLS_NAME> final {
+ public:
+  <ENUMS>
+  <CLS_NAME>();
+};
+)__cpp_cb";
+
+/**
+ * <NAME> The name of the enum.
+ * <ENUMS> The fields of the enumeration.
+ */
+constexpr const char CB_ENUM_BASE[] =
+R"__c_cb(
+enum class <NAME> : int {
+  <ENUMS>
+};
+)__c_cb";
+
 /**
  * <RETURN_TYPE> The return type of the element.
  * <NAME> The element name.
@@ -379,6 +401,14 @@ R"__cpp_cb(
 <GETTER_SETTER>
 )__cpp_cb";
 
+/**
+ * <CLS_NAME> The class name of the structure.
+ */
+constexpr const char CB_BODY_STRUCTURE_BASE_EMPTY[] =
+R"__cpp_cb(
+<CLS_NAME>::<CLS_NAME>() {}
+)__cpp_cb";
+
 constexpr const char CB_BODY_STRUCTURE_MEMBER_INIT[] =
 "<NAME>_(<VALUE>)";
 
@@ -610,6 +640,11 @@ R"__cpp_cb(
 rpc_port_parcel_write_<PARCEL_TYPE>(GetParcel(), value);
 )__cpp_cb";
 
+constexpr const char CB_UNIT_IMPL_SERIALIZER_ENUM[] =
+R"__cpp_cb(
+rpc_port_parcel_write_int32(GetParcel(), static_cast<int>(value));
+)__cpp_cb";
+
 /**
  * <UNIT_MAP_READ> The implementation to read the data from the unit map.
  */
@@ -757,6 +792,7 @@ if (tmp_filename != nullptr) {
 )__cpp_cb";
 
 /**
+ * <TYPE> The type of the parameter.
  * <PARCEL_TYPE> The type of the parcel type of the parameter.
  */
 constexpr const char CB_UNIT_IMPL_DESERIALIZER_BASE[] =
@@ -766,6 +802,16 @@ rpc_port_parcel_read_<PARCEL_TYPE>(GetParcel(), &tmp_value);
 value = tmp_value;
 )__cpp_cb";
 
+/**
+ * <TYPE> The type of the parameter.
+ */
+constexpr const char CB_UNIT_IMPL_DESERIALIZER_ENUM[] =
+R"__cpp_cb(
+int tmp_value;
+rpc_port_parcel_read_int32(GetParcel(), &tmp_value);
+value = static_cast<<TYPE>>(tmp_value);
+)__cpp_cb";
+
 /**
  * <UNIT_MAP_READ_WRITE> The implementation of the method to read and write.
  */
index 2ceff3646881e9b8daf4aa4a5de3a20742c52ab8..b3798c01ccde3833a27570af7a7fcfb29036c57a 100644 (file)
@@ -62,6 +62,7 @@ std::string CppGroupHeaderGenerator::GenInterface(const Interface& iface) {
   return std::string(
       ReplaceAll(CB_INTERFACE)
           .Change("<CLS_NAME>", iface.GetID())
+          .Change("<ENUMS>", GenEnumerations(iface.GetEnums()))
           .Change("<PUBLIC_MEMBERS>", GenInterfacePublicMembers(iface))
           .Change("<PRIVATE_MEMBERS>", GenInterfacePrivateMembers(iface)));
 }
index 406c0788b57ec71e06d09bf71cb826c8b0146493..1312cc361ddb26c109cba09e57aa78a85a1c2afb 100644 (file)
@@ -70,6 +70,7 @@ class <CLS_NAME> {
  public:
   <CLS_NAME>(std::string sender_appid, bool is_system = false);
   virtual ~<CLS_NAME>();
+  <ENUMS>
 
   <PUBLIC_MEMBERS>
 
index b32902fb1f39fdc8a6574ec783d6d693bcb174bd..20db4c12e2e6ac405cf0986ce4d53684308c8de3 100644 (file)
@@ -79,6 +79,7 @@ std::string CppProxyBodyGenerator::GenInterface(const Interface& iface) {
   return std::string(
       ReplaceAll(CB_INTERFACE_BASE)
           .Change("<CLS_NAME>", iface.GetID())
+          .Change("<ENUMS>", GenEnumerations(iface.GetEnums()))
           .Change("<CALLBACKS>", GenInterfaceCallbacks(iface))
           .Change("<METHODS>", GenInterfaceMethods(iface)));
 }
index 3e3068ece8c75a033f88a1d7a433d6072235860d..6acccc1578f572ed7e454ce1867323c769b3e460 100644 (file)
@@ -62,6 +62,7 @@ std::string CppProxyHeaderGenerator::GenInterface(const Interface& iface) {
   return std::string(
       ReplaceAll(CB_INTERFACE_BASE)
           .Change("<CLS_NAME>", iface.GetID())
+          .Change("<ENUMS>", GenEnumerations(iface.GetEnums()))
           .Change("<CALLBACKS>", GenInterfaceCallbacks(iface))
           .Change("<METHODS>", GenInterfaceMethods(iface))
           .Change("<METHOD_IDS>", GenMethodIds(iface))
index c7b5b5875624a67abe2133464a8624b728ed41d5..6c3953f80b0e97f9e54ea3abee060b8522f0f8ed 100644 (file)
@@ -79,6 +79,7 @@ constexpr const char CB_INTERFACE_BASE[] =
 R"__cpp_cb(
 class <CLS_NAME> {
  public:
+  <ENUMS>
   <CALLBACKS>
   class IEventListener {
    public:
index 331a95870902659935fab88b751d6b88b1a26259..5c31a358e5ae82b4d71aa2d2a0f281d7bbd22af3 100644 (file)
@@ -72,6 +72,7 @@ std::string CppStubHeaderGenerator::GenInterface(const Interface& iface) {
       ReplaceAll(CB_INTERFACE_BASE)
           .Change("<CLS_NAME>", iface.GetID())
           .Change("<CALLBACKS>", GenInterfaceCallbacks(iface))
+          .Change("<ENUMS>", GenEnumerations(iface.GetEnums()))
           .Change("<SERVICE_BASE_METHODS>",
               GenInterfaceServiceBaseMethods(iface))
           .Change("<SERVICE_BASE_DISPATCH_FUNCS>",
index d585d5b67192725573904ec10d0f9cecb83c7f29..127510dc88b6d289e2d5db061fa4e0b922936f3b 100644 (file)
@@ -244,6 +244,7 @@ constexpr const char CB_INTERFACE_BASE[] =
 R"__cpp_cb(
 class <CLS_NAME> {
  public:
+  <ENUMS>
   <CALLBACKS>
   class ServiceBase : public std::enable_shared_from_this<ServiceBase> {
    public:
index d1e1f0e56184e044aa4c9690c8618166d3b6dbe3..c313632966b078b04c877c8aab942d621cc3c4f4 100644 (file)
@@ -1,6 +1,13 @@
 protocol 2
 
 struct Envelope {
+  enum Type {
+    Send,
+    Receive,
+  }
+
+  Type type;
+  list<Type> kk;
   list<string> string_list;
   array<bundle> bundle_array;
   map<string, int> string_int_map;
@@ -8,12 +15,18 @@ struct Envelope {
 }
 
 interface Message {
+  enum PeerInfo {
+    Client,
+    Server,
+  }
+
   void NotifyCB(string sender, string msg) delegate;
 
-  int Register(string name, NotifyCB cb);
+  int Register(string name, PeerInfo peer_info, NotifyCB cb);
   void Unregister() async;
   int Send(string msg);
   int SendFiles(list<file> files);
   int SendFile(file f);
-  int SendEnvelope(Envelope envelope);
+  list<PeerInfo> SendEnvelope(Envelope envelope, list<Envelope.Type> ss);
 }
+