Modify C Generator related to Remote Exception feature 99/297099/3
authorHwankyu Jhun <h.jhun@samsung.com>
Thu, 10 Aug 2023 07:31:40 +0000 (16:31 +0900)
committerHwankyu Jhun <h.jhun@samsung.com>
Thu, 10 Aug 2023 08:13:40 +0000 (17:13 +0900)
This patch modifies the remote exception feature. The interface name is
removed from the remote exception handle.

Changes:
 - Remove the interface name from the remote exception handle
 - Adjust coding style

Change-Id: Ib79e7c68031e395aeca24be112477b06e3af85c6
Signed-off-by: Hwankyu Jhun <h.jhun@samsung.com>
18 files changed:
idlc/gen/version2/c_body_generator_base.cc
idlc/gen/version2/c_body_generator_base.hh
idlc/gen/version2/c_body_generator_base_cb.hh
idlc/gen/version2/c_header_generator_base.cc
idlc/gen/version2/c_header_generator_base.hh
idlc/gen/version2/c_header_generator_base_cb.hh
idlc/gen/version2/c_proxy_body_generator.cc
idlc/gen/version2/c_proxy_body_generator.hh
idlc/gen/version2/c_proxy_body_generator_cb.hh
idlc/gen/version2/c_proxy_header_generator.cc
idlc/gen/version2/c_proxy_header_generator.hh
idlc/gen/version2/c_proxy_header_generator_cb.hh
idlc/gen/version2/c_stub_body_generator.cc
idlc/gen/version2/c_stub_body_generator.hh
idlc/gen/version2/c_stub_body_generator_cb.hh
idlc/gen/version2/c_stub_header_generator.cc
idlc/gen/version2/c_stub_header_generator.hh
idlc/gen/version2/c_stub_header_generator_cb.hh

index a19a0f3058bbd3f0c124df6cdad27c4ec06184cc..659b6e760bf409b62709e67bfda498a1189e283e 100644 (file)
@@ -1288,11 +1288,11 @@ void CBodyGeneratorBase::GenParameterMap() {
       if (GetChannelType() != ChannelType::TYPE_GROUP) {
         AddParameterType(
             std::make_shared<ParameterType>(
-              new BaseType(iface.GetID() + "_remote_exception", "", true),
+              new BaseType("remote_exception", "", true),
               ParameterType::Direction::OUT));
         AddParameterType(
             std::make_shared<ParameterType>(
-              new BaseType(iface.GetID() + "_remote_exception", "", true),
+              new BaseType("remote_exception", "", true),
               ParameterType::Direction::IN));
       }
 
@@ -1491,5 +1491,25 @@ std::string CBodyGeneratorBase::GenUnitMapRead(
   return code;
 }
 
+void CBodyGeneratorBase::GenRemoteExceptionDefinition(std::ofstream& stream) {
+  ReplaceAll(CB_REMOTE_EXCEPTION_DEF)
+      .Change("<PREFIX>", GetHandlePrefix())
+      .Transform([&](std::string code) { return SmartIndent(code); })
+      .Out(stream);
+}
+
+void CBodyGeneratorBase::GenRemoteExceptionBase(std::ofstream& stream) {
+  ReplaceAll(CB_REMOTE_EXCEPTION_BASE)
+      .Change("<PREFIX>", GetHandlePrefix())
+      .Transform([&](std::string code) { return SmartIndent(code); })
+      .Out(stream);
+
+  ReplaceAll(IsProxy() ? CB_PROXY_REMOTE_EXCEPTION_BASE
+                       : CB_STUB_REMOTE_EXCEPTION_BASE)
+      .Change("<PREFIX>", GetHandlePrefix())
+      .Transform([&](std::string code) { return SmartIndent(code); })
+      .Out(stream);
+}
+
 }  // namespace version2
 }  // namespace tidl
index b2f4559a14e65f155d04559e0d008e76caea72d6..81ba1984153d137b43ba450d203b69ff862b3734 100644 (file)
@@ -40,6 +40,8 @@ class CBodyGeneratorBase : public tidl::CBodyGeneratorBase {
   void GenLemBaseDefinition(std::ofstream& stream);
   void GenIncludeLemHeaders(std::ofstream& stream);
   std::string GetHandlePrefixReverse();
+  void GenRemoteExceptionDefinition(std::ofstream& stream);
+  void GenRemoteExceptionBase(std::ofstream& stream);
 
  private:
   void AddTypeName(const Structure& st);
index 95ffe827f1770bfc72ce102c992cc5e13d774158..e530dfb9d880da06d644f3f4e4001496ffde30ef 100644 (file)
@@ -1051,6 +1051,239 @@ static int __rpc_port_set_private_sharing_list(rpc_port_h port, GList *list)
 }
 )__c_cb";
 
+/**
+ * <PREFIX> The prefix of the interface.
+ */
+constexpr const char CB_REMOTE_EXCEPTION_DEF[] =
+R"__c_cb(
+typedef struct <PREFIX>_remote_exception_s {
+  rpc_port_parcelable_t parcelable;
+  int cause;
+  char *message;
+} <PREFIX>_remote_exception_t;
+
+static __thread <PREFIX>_remote_exception_h __<PREFIX>_remote_exception;
+
+int <PREFIX>_remote_exception_create(<PREFIX>_remote_exception_h *h);
+)__c_cb";
+
+/**
+ * <PREFIX> The prefix of the interface.
+ */
+constexpr const char CB_REMOTE_EXCEPTION_BASE[] =
+R"__c_cb(
+static void __<PREFIX>_remote_exception_to(rpc_port_parcel_h parcel, void *user_data)
+{
+  <PREFIX>_remote_exception_h h = user_data;
+  rpc_port_unit_map_h map;
+
+  map = rpc_port_unit_map_create();
+  if (map == nullptr) {
+    set_last_result(RPC_PORT_ERROR_OUT_OF_MEMORY);
+    return;
+  }
+
+  rpc_port_unit_map_write_int(map, "cause", h->cause);
+  rpc_port_unit_map_write_string(map, "message", h->message);
+  rpc_port_parcel_write(parcel, &map->parcelable, map);
+  rpc_port_unit_map_destroy(map);
+  set_last_result(RPC_PORT_ERROR_NONE);
+}
+
+static void __<PREFIX>_remote_exception_from(rpc_port_parcel_h parcel, void *user_data)
+{
+  <PREFIX>_remote_exception_h h = user_data;
+  rpc_port_unit_map_h map;
+
+  map = rpc_port_unit_map_create();
+  if (map == nullptr) {
+    set_last_result(RPC_PORT_ERROR_OUT_OF_MEMORY);
+    return;
+  }
+
+  rpc_port_parcel_read(parcel, &map->parcelable, map);
+  rpc_port_unit_map_read_int(map, "cause", &h->cause);
+  rpc_port_unit_map_read_string(map, "message", &h->message);
+  rpc_port_unit_map_destroy(map);
+  set_last_result(RPC_PORT_ERROR_NONE);
+}
+
+int <PREFIX>_remote_exception_create(<PREFIX>_remote_exception_h *h)
+{
+  <PREFIX>_remote_exception_h exception;
+
+  if (h == nullptr) {
+    _E("Invalid parameter");
+    return RPC_PORT_ERROR_INVALID_PARAMETER;
+  }
+
+  exception = calloc(1, sizeof(<PREFIX>_remote_exception_t));
+  if (exception == nullptr) {
+    _E("calloc() is failed");
+    return RPC_PORT_ERROR_OUT_OF_MEMORY;
+  }
+
+  exception->parcelable.to = __<PREFIX>_remote_exception_to;
+  exception->parcelable.from = __<PREFIX>_remote_exception_from;
+
+  *h = exception;
+
+  return RPC_PORT_ERROR_NONE;
+}
+
+int <PREFIX>_remote_exception_set_cause(<PREFIX>_remote_exception_h h, int cause)
+{
+  if (h == nullptr) {
+    _E("Invalid parameter");
+    return RPC_PORT_ERROR_INVALID_PARAMETER;
+  }
+
+  h->cause = cause;
+
+  return RPC_PORT_ERROR_NONE;
+}
+
+int <PREFIX>_remote_exception_set_message(<PREFIX>_remote_exception_h h, const char *message)
+{
+  if (h == nullptr || message == nullptr) {
+    _E("Invalid parameter");
+    return RPC_PORT_ERROR_INVALID_PARAMETER;
+  }
+
+  if (h->message)
+    free(h->message);
+
+  h->message = strdup(message);
+  if (h->message == nullptr) {
+    _E("strdup() is failed");
+    return RPC_PORT_ERROR_OUT_OF_MEMORY;
+  }
+
+  return RPC_PORT_ERROR_NONE;
+}
+
+int <PREFIX>_remote_exception_get_cause(<PREFIX>_remote_exception_h h, int *cause)
+{
+  if (h == nullptr || cause == nullptr) {
+    _E("Invalid parameter");
+    return RPC_PORT_ERROR_INVALID_PARAMETER;
+  }
+
+  *cause = h->cause;
+
+  return RPC_PORT_ERROR_NONE;
+}
+
+int <PREFIX>_remote_exception_get_message(<PREFIX>_remote_exception_h h, char **message)
+{
+  if (h == nullptr || message == nullptr) {
+    _E("Invalid parameter");
+    return RPC_PORT_ERROR_INVALID_PARAMETER;
+  }
+
+  *message = strdup(h->message);
+  if (*message == nullptr) {
+    _E("strdup() is failed");
+    return RPC_PORT_ERROR_OUT_OF_MEMORY;
+  }
+
+  return RPC_PORT_ERROR_NONE;
+}
+
+int <PREFIX>_remote_exception_destroy(<PREFIX>_remote_exception_h h)
+{
+  if (h == nullptr) {
+    _E("Invalid parameter");
+    return RPC_PORT_ERROR_INVALID_PARAMETER;
+  }
+
+  if (h->message)
+    free(h->message);
+
+  free(h);
+
+  return RPC_PORT_ERROR_NONE;
+}
+)__c_cb";
+
+/**
+ * <PREFIX> The prefix of the proxy interface.
+ */
+constexpr const char CB_PROXY_REMOTE_EXCEPTION_BASE[] =
+R"__cpp_cb(
+int <PREFIX>_get_remote_exception(<PREFIX>_remote_exception_h *h)
+{
+  rpc_port_unit_map_h map;
+  int ret;
+
+  if (h == nullptr) {
+    _E("Invalid parameter");
+    return RPC_PORT_ERROR_INVALID_PARAMETER;
+  }
+
+  if (__<PREFIX>_remote_exception == nullptr) {
+    _W("There is no exceptions");
+    *h = nullptr;
+    return RPC_PORT_ERROR_NONE;
+  }
+
+  map = rpc_port_unit_map_create();
+  if (map == nullptr) {
+    _E("Failed to create unit map");
+    return RPC_PORT_ERROR_OUT_OF_MEMORY;
+  }
+
+  ret = rpc_port_unit_map_write_remote_exception(map, "clone", __<PREFIX>_remote_exception);
+  if (ret != RPC_PORT_ERROR_NONE) {
+    _E("Failed to write remote exception. error(%d)", ret);
+    rpc_port_unit_map_destroy(map);
+    return ret;
+  }
+
+  ret = rpc_port_unit_map_read_remote_exception(map, "clone", h);
+  rpc_port_unit_map_destroy(map);
+
+  return RPC_PORT_ERROR_NONE;
+}
+)__cpp_cb";
+
+constexpr const char CB_STUB_REMOTE_EXCEPTION_BASE[] =
+R"__cpp_cb(
+int <PREFIX>_remote_exception_throw(<PREFIX>_remote_exception_h h)
+{
+  rpc_port_unit_map_h map;
+  int ret;
+
+  if (h == nullptr) {
+    _E("Invalid parameter");
+    return RPC_PORT_ERROR_INVALID_PARAMETER;
+  }
+
+   map = rpc_port_unit_map_create();
+  if (map == nullptr) {
+    _E("Failed to create unit map");
+    return RPC_PORT_ERROR_OUT_OF_MEMORY;
+  }
+
+  ret = rpc_port_unit_map_write_remote_exception(map, "clone", h);
+  if (ret != RPC_PORT_ERROR_NONE) {
+    _E("Failed to write remote exception. error(%d)", ret);
+    rpc_port_unit_map_destroy(map);
+    return ret;
+  }
+
+  if (__<PREFIX>_remote_exception != nullptr) {
+    <PREFIX>_remote_exception_destroy(__<PREFIX>_remote_exception);
+    __<PREFIX>_remote_exception = nullptr;
+  }
+
+  ret = rpc_port_unit_map_read_remote_exception(map, "clone", &__<PREFIX>_remote_exception);
+  rpc_port_unit_map_destroy(map);
+
+  return ret;
+}
+)__cpp_cb";
+
 }  // namespace version2
 }  // namespace tidl
 
index 7a728fc90cde1b940d5d689f36a5d6257005964b..832441ccf6e8c0549bd66e9a16dfff713ad09177 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2022 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2022 - 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.
@@ -135,8 +135,10 @@ void CHeaderGeneratorBase::GenStructureArrayBase(std::ofstream& stream,
   else
     id = st.GetID();
 
-  auto param_type_in = GetParamTypeString(ParameterType::Direction::IN, type, id);
-  auto param_type_out = GetParamTypeString(ParameterType::Direction::OUT, type, id);
+  auto param_type_in =
+      GetParamTypeString(ParameterType::Direction::IN, type, id);
+  auto param_type_out =
+      GetParamTypeString(ParameterType::Direction::OUT, type, id);
 
   ReplaceAll(CB_STRUCTURE_ARRAY_BASE)
       .Change("<PREFIX>", GetHandlePrefix())
@@ -223,8 +225,10 @@ void CHeaderGeneratorBase::GenStructureBase(std::ofstream& stream,
 
   for (const auto& e : GetElements(st)) {
     auto& type = e->GetType();
-    auto param_type_in = GetParamTypeString(ParameterType::Direction::IN, type, st.GetID());
-    auto param_type_out = GetParamTypeString(ParameterType::Direction::OUT, type, st.GetID());
+    auto param_type_in =
+        GetParamTypeString(ParameterType::Direction::IN, type, st.GetID());
+    auto param_type_out =
+        GetParamTypeString(ParameterType::Direction::OUT, type, st.GetID());
 
     ReplaceAll(CB_STRUCTURE_BASE_SET_GET)
         .Change("<PREFIX>", GetHandlePrefix())
@@ -251,5 +255,25 @@ void CHeaderGeneratorBase::GenStructure(std::ofstream& stream,
     GenStructureBase(stream, st);
 }
 
+void CHeaderGeneratorBase::GenRemoteExceptionHandle(std::ofstream& stream) {
+  ReplaceAll(CB_REMOTE_EXCEPTION_HANDLE)
+      .Change("<PREFIX>", GetHandlePrefix())
+      .Transform([&](std::string code) { return SmartIndent(code); })
+      .Out(stream);
+}
+
+void CHeaderGeneratorBase::GenRemoteException(std::ofstream& stream) {
+  ReplaceAll(CB_REMOTE_EXCEPTION_BASE)
+      .Change("<PREFIX>", GetHandlePrefix())
+      .Transform([&](std::string code) { return SmartIndent(code); })
+      .Out(stream);
+
+  ReplaceAll(IsProxy() ? CB_PROXY_REMOTE_EXCEPTION_BASE
+                       : CB_STUB_REMOTE_EXCEPTION_BASE)
+      .Change("<PREFIX>", GetHandlePrefix())
+      .Transform([&](std::string code) { return SmartIndent(code); })
+      .Out(stream);
+}
+
 }  // namespace version2
 }  // namespace tidl
index def5c8a728fd206aa7bda83742eb5bc17125d271..d5171dd1c85752a34e6129e94f14e137b4f7c5ad 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2022 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2022 - 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.
@@ -32,6 +32,8 @@ class CHeaderGeneratorBase : public tidl::CHeaderGeneratorBase {
   void GenStructureHandles(std::ofstream& stream) override;
   void GenStructures(std::ofstream& stream) override;
   void GenEnums(std::ofstream& stream);
+  void GenRemoteExceptionHandle(std::ofstream& stream);
+  void GenRemoteException(std::ofstream& stream);
 
  private:
   void GenStructureHandle(std::ofstream& stream, const Structure& st);
index da8b7be83458764f1b6ea7f6a976a7725843f2ba..a6c5992e57fa838ec89695441cc587febeb5db88 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2022 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2022 - 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.
@@ -139,6 +139,141 @@ int <PREFIX>_<NAME>_set_<ELEMENT_NAME>(<PREFIX>_<NAME>_h h, <PARAM_TYPE_IN>value
 int <PREFIX>_<NAME>_get_<ELEMENT_NAME>(<PREFIX>_<NAME>_h h, <PARAM_TYPE_OUT>value);
 )__c_cb";
 
+/**
+ * <PREFIX> The prefix of the interface.
+ */
+constexpr const char CB_REMOTE_EXCEPTION_HANDLE[] =
+R"__c_cb(
+/**
+ * @breif The <PREFIX> remote exception handle.
+ */
+typedef struct <PREFIX>_remote_exception_s *<PREFIX>_remote_exception_h;
+)__c_cb";
+
+/**
+ * <PREFIX> The prefix of the interface.
+ */
+constexpr const char CB_REMOTE_EXCEPTION_BASE[] =
+R"__c_cb(
+/**
+ * @brief Creates the <PREFIX> remote exception handle.
+ *
+ * @remarks The @c h handle should be released if it's no longer needed.
+ * @param[out] h The <PREFIX> remote exception handle.
+ * @return @c 0 on success,
+ *         otherwise a negative error value
+ * @retval #RPC_PORT_ERROR_NONE Successful
+ * @retval #RPC_PORT_ERROR_INVALID_PARAMETER Invalid parameter
+ * @retval #RPC_PORT_ERROR_OUT_OF_MEMORY Out of memory
+  * @see <PREFIX>_remote_exception_destroy()
+ */
+int <PREFIX>_remote_exception_create(<PREFIX>_remote_exception_h *h);
+
+/**
+ * @brief Sets the cause of the exception.
+ *
+ * @param[in] h The <PREFIX> remote exception handle
+ * @param[in] cause The cause of the exception
+ * @return @c 0 on success,
+ *         otherwise a negative error value
+ * @retval #RPC_PORT_ERROR_NONE Successful
+ * @retval #RPC_PORT_ERROR_INVALID_PARAMETER Invalid parameter
+ */
+int <PREFIX>_remote_exception_set_cause(<PREFIX>_remote_exception_h h, int cause);
+
+/**
+ * @brief Sets the detail message of the exception.
+ *
+ * @param[in] h The <PREFIX> remote exception handle
+ * @param[in] message The detail message of the exception
+ * @return @c 0 on success,
+ *         otherwise a negative error value
+ * @retval #RPC_PORT_ERROR_NONE Successful
+ * @retval #RPC_PORT_ERROR_INVALID_PARAMETER Invalid parameter
+ * @retval #RPC_PORT_ERROR_OUT_OF_MEMORY Out of memory
+ */
+int <PREFIX>_remote_exception_set_message(<PREFIX>_remote_exception_h h, const char *message);
+
+/**
+ * @brief Gets the cause of the exception.
+ * @param[in] h The <PREFIX> remote exception handle.
+ * @param[out] cause The cause
+ * @return @c 0 on success,
+ *         otherwise a negative error value
+ * @retval #RPC_PORT_ERROR_NONE Successful
+ * @retval #RPC_PORT_ERROR_INVALID_PARAMETER Invalid parameter
+ */
+int <PREFIX>_remote_exception_get_cause(<PREFIX>_remote_exception_h h, int *cause);
+
+/**
+ * @brief Gets the detail message of the exception.
+ * @remarks The @c message should be released if it's no longer needed.
+ * @param[in] h The <PREFIX> remote exception handle.
+ * @param[out] message The detail message
+ * @return @c 0 on success,
+ *         otherwise a negative error value
+ * @retval #RPC_PORT_ERROR_NONE Successful
+ * @retval #RPC_PORT_ERROR_INVALID_PARAMETER Invalid parameter
+ * @retval #RPC_PORT_ERROR_OUT_OF_MEMORY Out of memory
+ */
+int <PREFIX>_remote_exception_get_message(<PREFIX>_remote_exception_h, char **message);
+
+/**
+ * @brief Destroys the remote exception handle.
+ * @param[in] h The <PREFIX> remote exception handle
+ * @return @c 0 on success,
+ *         otherwise a negative error value
+ * @retval #RPC_PORT_ERROR_NONE Successful
+ * @retval #RPC_PORT_ERROR_INVALID_PARAMETER Invalid parameter
+ */
+int <PREFIX>_remote_exception_destroy(<PREFIX>_remote_exception_h h);
+)__c_cb";
+
+/**
+ * <PREFIX> The prefix of the proxy interface.
+ */
+constexpr const char CB_PROXY_REMOTE_EXCEPTION_BASE[] =
+R"__cpp_cb(
+/**
+ * @brief Gets the remote exception handle.
+ * @details If the return value is nullptr, there is no exceptions.
+ * @remarks The handle should be released using <PREFIX>_remote_exception_destroy(), if it's no longer needed.
+ * @param[out] h The <PREFIX> remote exception handle.
+ * @return @c 0 on success,
+ *         otherwise a negative error value
+ * @retval #RPC_PORT_ERROR_NONE Successful
+ * @retval #RPC_PORT_ERROR_INVALID_PARAMETER Invalid parameter
+ * @retval #RPC_PORT_ERROR_OUT_OF_MEMORY Out of memory
+ * @see <PREFIX>_remote_exception_destroy();
+ */
+int <PREFIX>_get_remote_exception(<PREFIX>_remote_exception_h *h);
+)__cpp_cb";
+
+/**
+ * <PREFIX> The prefix of the stub interface.
+ */
+constexpr const char CB_STUB_REMOTE_EXCEPTION_BASE[] =
+R"__c_cb(
+/**
+ * @brief Throws the exception to the client.
+ * @details This function throws the exception to the client in the callback function.
+ *          While calling the registered callback function related the method call, this function should be called
+ *          if you want to send the remote exception to the client.
+ *          If this function is called outside of the registered callback function, it's meaningless.
+ *          The callback function is not returned by calling this function.
+ *
+ * @param[in] h The <PREFIX> remote exception handle
+ * @return @c 0 on success,
+ *         otherwise a negative error value
+ * @retval #RPC_PORT_ERROR_NONE Successful
+ * @retval #RPC_PORT_ERROR_INVALID_PARAMETER Invalid parameter
+ * @retval #RPC_PORT_ERROR_OUT_OF_MEMORY Out of memory
+ * @see <PREFIX>_remote_exception_create()
+ * @see <PREFIX>_remote_exception_destroy()
+ */
+int <PREFIX>_remote_exception_throw(<PREFIX>_remote_exception_h h);
+)__c_cb";
+
 }  // namespace version2
 }  // namespace tidl
 
index 7f4f7fbc8353ae3862ed696ef1f0a9ad72547b68..ad17342507ee9bff35e6aa640bfc3a7199d8872b 100644 (file)
@@ -44,11 +44,13 @@ void CProxyBodyGenerator::OnInitGen(std::ofstream& stream) {
   GenDelegateDefinition(stream);
   GenInterfaceDelegateCallback(stream);
   GenStructureDefinition(stream);
+  GenRemoteExceptionDefinition(stream);
   GenInterfaceDefinition(stream);
   GenUnitMapBase(stream);
   GenDelegateBase(stream);
   GenPrivateSharingListSet(stream);
   GenStructure(stream);
+  GenRemoteExceptionBase(stream);
   GenInterface(stream);
 }
 
@@ -88,7 +90,6 @@ void CProxyBodyGenerator::GenInterfaceDefinition(std::ofstream& stream) {
       GenInterfaceDelegateDefinition(stream, iface, *decl);
     }
 
-    GenInterfaceRemoteExceptionDefinition(stream, iface);
     GenInterfaceBaseDefinition(stream, iface);
   }
 }
@@ -103,15 +104,6 @@ void CProxyBodyGenerator::GenInterfaceDelegateDefinition(std::ofstream& stream,
       .Out(stream);
 }
 
-void CProxyBodyGenerator::GenInterfaceRemoteExceptionDefinition(
-    std::ofstream& stream, const Interface& iface) {
-  ReplaceAll(CB_INTERFACE_REMOTE_EXCEPTION_DEF)
-      .Change("<PREFIX>", GetHandlePrefix())
-      .Change("<NAME>", iface.GetID())
-      .Transform([&](std::string code) { return SmartIndent(code); })
-      .Out(stream);
-}
-
 void CProxyBodyGenerator::GenInterfaceBaseDefinition(std::ofstream& stream,
     const Interface& iface) {
   ReplaceAll(CB_INTERFACE_BASE_DEF)
@@ -138,7 +130,6 @@ void CProxyBodyGenerator::GenInterface(std::ofstream& stream) {
 
     GenInterfaceDelegateTable(stream, iface);
     GenInterfaceMethodEnumBase(stream, iface);
-    GenInterfaceRemoteExceptionBase(stream, iface);
     GenDelegateProcess(stream, iface);
     GenInterfaceBase(stream, iface);
 
@@ -363,7 +354,8 @@ std::string CProxyBodyGenerator::GenMethodUnitMapRead(const Interface& iface,
 void CProxyBodyGenerator::GenMethodBase(std::ofstream& stream,
     const Interface& iface, const Declaration& decl) {
   ReplaceAll(CB_INTERFACE_METHOD_BASE)
-      .Change("<RETURN_TYPE>", GetReturnTypeString(decl.GetType(), iface.GetID()))
+      .Change("<RETURN_TYPE>",
+              GetReturnTypeString(decl.GetType(), iface.GetID()))
       .Change("<PREFIX>", GetHandlePrefix())
       .Change("<NAME>", iface.GetID())
       .Change("<METHOD_NAME>", decl.GetID())
@@ -396,7 +388,8 @@ void CProxyBodyGenerator::GenInterfaceBase(std::ofstream& stream,
   std::string prefix = GetHandlePrefix();
   std::string name = iface.GetID();
   std::string event = HasDelegate() ? CB_INTERFACE_DELEGATE_REGISTER_EVENT : "";
-  std::string callback = HasDelegate() ? CB_INTERFACE_DELEGATE_LEM_RECEIVE_CALLBACK : "";
+  std::string callback =
+      HasDelegate() ? CB_INTERFACE_DELEGATE_LEM_RECEIVE_CALLBACK : "";
 
   ReplaceAll(CB_INTERFACE_BASE)
       .Change("<DELEGATE_REGISTER_EVENT>", event)
@@ -410,15 +403,6 @@ void CProxyBodyGenerator::GenInterfaceBase(std::ofstream& stream,
       .Out(stream);
 }
 
-void CProxyBodyGenerator::GenInterfaceRemoteExceptionBase(std::ofstream& stream,
-    const Interface& iface) {
-  ReplaceAll(CB_INTERFACE_REMOTE_EXCEPTION_BASE)
-      .Change("<PREFIX>", GetHandlePrefix())
-      .Change("<NAME>", iface.GetID())
-      .Transform([&](std::string code) { return SmartIndent(code); })
-      .Out(stream);
-}
-
 void CProxyBodyGenerator::GenInterfaceMethodEnumBase(std::ofstream& stream,
     const Interface& iface) {
   std::string enums = GetHandlePrefix() + "_" + iface.GetID() +
index 806ef3e76b3065f37c74471ffe97bfb0f6cb7b85..98e544359efcbd1721ae41c9f06e995ce924b9b7 100644 (file)
@@ -39,51 +39,49 @@ class CProxyBodyGenerator : public CBodyGeneratorBase {
   void GenInterfaceDelegateCallback(std::ofstream& stream);
   void GenInterfaceDefinition(std::ofstream& stream);
   void GenInterfaceDelegateDefinition(std::ofstream& stream,
-      const Interface& iface, const Declaration& decl);
-  void GenInterfaceRemoteExceptionDefinition(std::ofstream& stream,
-      const Interface& iface);
+                                      const Interface& iface,
+                                      const Declaration& decl);
   void GenInterfaceBaseDefinition(std::ofstream& stream,
-      const Interface& iface);
+                                  const Interface& iface);
   void GenInterface(std::ofstream& stream);
   std::string GenMethodParams(const Interface& iface, const Declaration& decl);
   std::string GenMethodArgs(const Interface& iface, const Declaration& decl);
   std::string GenMethodParamsCheck(const Interface& iface,
-      const Declaration& decl);
+                                   const Declaration& decl);
   std::string GenMethodUnitMapWrite(const Interface& iface,
-      const Declaration& decl);
+                                    const Declaration& decl);
   std::string GenMethodDelegateAppend(const Interface& iface,
-      const Declaration& decl);
+                                      const Declaration& decl);
   void GenMethodAsyncBase(std::ofstream& stream, const Interface& iface,
-      const Declaration& decl);
+                          const Declaration& decl);
   std::string GenMethodUnitMapReadBase(const Interface& iface,
-      const BaseType& type, const std::string& arg_name,
-      const std::string& arg);
+                                       const BaseType& type,
+                                       const std::string& arg_name,
+                                       const std::string& arg);
   std::string GenMethodUnitMapRead(const Interface& iface,
-      const Declaration& decl);
-  std::string GenMethodRefFree(const Interface& iface,
-      const BaseType& type, const std::string& arg);
+                                   const Declaration& decl);
+  std::string GenMethodRefFree(const Interface& iface, const BaseType& type,
+                               const std::string& arg);
   void GenMethodBase(std::ofstream& stream, const Interface& iface,
-      const Declaration& decl);
+                     const Declaration& decl);
   void GenInterfaceMethodBase(std::ofstream& stream, const Interface& iface,
-      const Declaration& decl);
+                              const Declaration& decl);
   void GenInterfaceBase(std::ofstream& stream, const Interface& iface);
-  void GenInterfaceRemoteExceptionBase(std::ofstream& stream,
-      const Interface& iface);
   void GenInterfaceMethodEnumBase(std::ofstream& stream,
-      const Interface& iface);
+                                  const Interface& iface);
   void GenInterfaceDelegateTable(std::ofstream& stream, const Interface& iface);
   void GenInterfaceDelegateBase(std::ofstream& stream, const Interface& iface,
-      const Declaration& decl);
+                                const Declaration& decl);
   void GenDelegateProcess(std::ofstream& stream, const Interface& iface);
   std::string GenDelegateCallbackArgs(const Declaration& decl);
   std::string GenDelegateUnitMapRead(const Interface& iface,
-      const Declaration& decl);
+                                     const Declaration& decl);
   std::string GenDelegateArgsDecl(const Interface& iface,
-      const Declaration& decl);
+                                  const Declaration& decl);
   std::string GenDelegateArgsFree(const Interface& iface,
-      const Declaration& decl, bool* has_free);
+                                  const Declaration& decl, bool* has_free);
   void GenInterfaceDelegateEnumBase(std::ofstream& stream,
-      const Interface& iface);
+                                    const Interface& iface);
   void GenDelegateDefinition(std::ofstream& stream);
   void GenDelegateBase(std::ofstream& stream);
   void GenLemDefinition(std::ofstream& stream);
index 09b194a3344077af9e23513603a96f2aa1b050a7..94e71ff1d9e21e201ae8277fcdbc1ab6f8b9d55f 100644 (file)
@@ -733,11 +733,11 @@ static void __<PREFIX>_<NAME>_consume_command(rpc_port_h port, int seq_num, rpc_
 
     rpc_port_unit_map_read_int(map, "[METHOD]", &cmd);
     if (cmd == <UPPERCASE_PREFIX>_<UPPERCASE_NAME>_METHOD_RESULT_) {
-      if (__<PREFIX>_<NAME>_remote_exception != nullptr)
-        <PREFIX>_<NAME>_remote_exception_destroy(__<PREFIX>_<NAME>_remote_exception);
+      if (__<PREFIX>_remote_exception != nullptr)
+        <PREFIX>_remote_exception_destroy(__<PREFIX>_remote_exception);
 
-      __<PREFIX>_<NAME>_remote_exception = nullptr;
-      rpc_port_unit_map_read_<NAME>_remote_exception(map, "[REMOTE_EXCEPTION]", &__<PREFIX>_<NAME>_remote_exception);
+      __<PREFIX>_remote_exception = nullptr;
+      rpc_port_unit_map_read_remote_exception(map, "[REMOTE_EXCEPTION]", &__<PREFIX>_remote_exception);
 
       *unit_map = map;
       return;
@@ -1373,167 +1373,6 @@ R"__c_cb(
 h->delegates = g_list_append(h->delegates, <ARG>);
 )__c_cb";
 
-/**
- * <PREFIX> The prefix of the interface.
- * <NAME> The name of the interface.
- */
-constexpr const char CB_INTERFACE_REMOTE_EXCEPTION_DEF[] =
-R"__c_cb(
-typedef struct <PREFIX>_<NAME>_remote_exception_s {
-  rpc_port_parcelable_t parcelable;
-  int cause;
-  char *message;
-} <PREFIX>_<NAME>_remote_exception_t;
-
-static __thread <PREFIX>_<NAME>_remote_exception_h __<PREFIX>_<NAME>_remote_exception;
-
-static int <PREFIX>_<NAME>_remote_exception_create(<PREFIX>_<NAME>_remote_exception_h *h);
-)__c_cb";
-
-/**
- * <PREFIX> The prefix of the interface.
- * <NAME> The name of the interface.
- */
-constexpr const char CB_INTERFACE_REMOTE_EXCEPTION_BASE[] =
-R"__c_cb(
-static void __<PREFIX>_<NAME>_remote_exception_to(rpc_port_parcel_h parcel, void *user_data)
-{
-  <PREFIX>_<NAME>_remote_exception_h h = user_data;
-  rpc_port_unit_map_h map;
-
-  map = rpc_port_unit_map_create();
-  if (map == nullptr) {
-    set_last_result(RPC_PORT_ERROR_OUT_OF_MEMORY);
-    return;
-  }
-
-  rpc_port_unit_map_write_int(map, "cause", h->cause);
-  rpc_port_unit_map_write_string(map, "message", h->message);
-  rpc_port_parcel_write(parcel, &map->parcelable, map);
-  rpc_port_unit_map_destroy(map);
-  set_last_result(RPC_PORT_ERROR_NONE);
-}
-
-static void __<PREFIX>_<NAME>_remote_exception_from(rpc_port_parcel_h parcel, void *user_data)
-{
-  <PREFIX>_<NAME>_remote_exception_h h = user_data;
-  rpc_port_unit_map_h map;
-
-  map = rpc_port_unit_map_create();
-  if (map == nullptr) {
-    set_last_result(RPC_PORT_ERROR_OUT_OF_MEMORY);
-    return;
-  }
-
-  rpc_port_parcel_read(parcel, &map->parcelable, map);
-  rpc_port_unit_map_read_int(map, "cause", &h->cause);
-  rpc_port_unit_map_read_string(map, "message", &h->message);
-  rpc_port_unit_map_destroy(map);
-  set_last_result(RPC_PORT_ERROR_NONE);
-}
-
-static int <PREFIX>_<NAME>_remote_exception_create(<PREFIX>_<NAME>_remote_exception_h *h)
-{
-  <PREFIX>_<NAME>_remote_exception_h exception;
-
-  if (h == nullptr) {
-    _E("Invalid parameter");
-    return RPC_PORT_ERROR_INVALID_PARAMETER;
-  }
-
-  exception = calloc(1, sizeof(<PREFIX>_<NAME>_remote_exception_t));
-  if (exception == nullptr) {
-    _E("calloc() is failed");
-    return RPC_PORT_ERROR_OUT_OF_MEMORY;
-  }
-
-  exception->parcelable.to = __<PREFIX>_<NAME>_remote_exception_to;
-  exception->parcelable.from = __<PREFIX>_<NAME>_remote_exception_from;
-
-  *h = exception;
-
-  return RPC_PORT_ERROR_NONE;
-}
-
-int <PREFIX>_<NAME>_get_remote_exception(<PREFIX>_<NAME>_remote_exception_h *h)
-{
-  rpc_port_unit_map_h map;
-  int ret;
-
-  if (h == nullptr) {
-    _E("Invalid parameter");
-    return RPC_PORT_ERROR_INVALID_PARAMETER;
-  }
-
-  if (__<PREFIX>_<NAME>_remote_exception == nullptr) {
-    _W("There is no exceptions");
-    *h = nullptr;
-    return RPC_PORT_ERROR_NONE;
-  }
-
-  map = rpc_port_unit_map_create();
-  if (map == nullptr) {
-    _E("Failed to create unit map");
-    return RPC_PORT_ERROR_OUT_OF_MEMORY;
-  }
-
-  ret = rpc_port_unit_map_write_<NAME>_remote_exception(map, "clone", __<PREFIX>_<NAME>_remote_exception);
-  if (ret != RPC_PORT_ERROR_NONE) {
-    _E("Failed to write remote exception. error(%d)", ret);
-    rpc_port_unit_map_destroy(map);
-    return ret;
-  }
-
-  ret = rpc_port_unit_map_read_<NAME>_remote_exception(map, "clone", h);
-  rpc_port_unit_map_destroy(map);
-
-  return RPC_PORT_ERROR_NONE;
-}
-
-int <PREFIX>_<NAME>_remote_exception_get_cause(<PREFIX>_<NAME>_remote_exception_h h, int *cause)
-{
-  if (h == nullptr || cause == nullptr) {
-    _E("Invalid parameter");
-    return RPC_PORT_ERROR_INVALID_PARAMETER;
-  }
-
-  *cause = h->cause;
-
-  return RPC_PORT_ERROR_NONE;
-}
-
-int <PREFIX>_<NAME>_remote_exception_get_message(<PREFIX>_<NAME>_remote_exception_h h, char **message)
-{
-  if (h == nullptr || message == nullptr) {
-    _E("Invalid parameter");
-    return RPC_PORT_ERROR_INVALID_PARAMETER;
-  }
-
-  *message = strdup(h->message);
-  if (*message == nullptr) {
-    _E("strdup() is failed");
-    return RPC_PORT_ERROR_OUT_OF_MEMORY;
-  }
-
-  return RPC_PORT_ERROR_NONE;
-}
-
-int <PREFIX>_<NAME>_remote_exception_destroy(<PREFIX>_<NAME>_remote_exception_h h)
-{
-  if (h == nullptr) {
-    _E("Invalid parameter");
-    return RPC_PORT_ERROR_INVALID_PARAMETER;
-  }
-
-  if (h->message)
-    free(h->message);
-
-  free(h);
-
-  return RPC_PORT_ERROR_NONE;
-}
-)__c_cb";
-
 }  // namespace version2
 }  // namespace tidl
 
index 88413595b296cca85e70bc92eb4d6886ecfc7826..e188e79ae90128d7e6cd74cb63ca5e61ebfd5ebd 100644 (file)
@@ -32,8 +32,10 @@ void CProxyHeaderGenerator::OnInitGen(std::ofstream& stream) {
   GenExplicitLinkageOpen(stream);
   GenEnums(stream);
   GenStructureHandles(stream);
+  GenRemoteExceptionHandle(stream);
   GenInterfaceHandles(stream);
   GenStructures(stream);
+  GenRemoteException(stream);
   GenInterfaces(stream);
 }
 
@@ -48,7 +50,6 @@ void CProxyHeaderGenerator::GenInterfaceHandles(std::ofstream& stream) {
 
     auto& iface = static_cast<const Interface&>(*b);
     GenInterfaceHandle(stream, iface);
-    GenInterfaceRemoteExceptionHandle(stream, iface);
     for (const auto& d : iface.GetDeclarations()) {
       if (d->GetMethodType() != Declaration::MethodType::DELEGATE)
         continue;
@@ -67,15 +68,6 @@ void CProxyHeaderGenerator::GenInterfaceHandle(std::ofstream& stream,
       .Out(stream);
 }
 
-void CProxyHeaderGenerator::GenInterfaceRemoteExceptionHandle(
-    std::ofstream& stream, const Interface& iface) {
-  ReplaceAll(CB_INTERFACE_REMOTE_EXCEPTION_HANDLE)
-      .Change("<PREFIX>", GetHandlePrefix())
-      .Change("<NAME>", iface.GetID())
-      .Transform([&](std::string code) { return SmartIndent(code); })
-      .Out(stream);
-}
-
 void CProxyHeaderGenerator::GenInterfaceDelegateHandle(std::ofstream& stream,
     const Interface& iface, const Declaration& decl) {
   ReplaceAll(CB_INTERFACE_DELEGATE_HANDLE)
@@ -105,7 +97,6 @@ void CProxyHeaderGenerator::GenInterface(std::ofstream& stream,
     GenInterfaceDelegateBase(stream, iface, *d);
   }
 
-  GenInterfaceRemoteExceptionBase(stream, iface);
   GenInterfaceBase(stream, iface);
 
   for (const auto& d : iface.GetDeclarations()) {
@@ -125,15 +116,6 @@ void CProxyHeaderGenerator::GenInterfaceBase(std::ofstream& stream,
       .Out(stream);
 }
 
-void CProxyHeaderGenerator::GenInterfaceRemoteExceptionBase(
-    std::ofstream& stream, const Interface& iface) {
-  ReplaceAll(CB_INTERFACE_REMOTE_EXCEPTION_BASE)
-      .Change("<PREFIX>", GetHandlePrefix())
-      .Change("<NAME>", iface.GetID())
-      .Transform([&](std::string code) { return SmartIndent(code); })
-      .Out(stream);
-}
-
 std::string CProxyHeaderGenerator::GenDelegateParams(const Interface& iface,
     const Declaration& decl) {
   std::string params;
@@ -176,7 +158,8 @@ std::string CProxyHeaderGenerator::GenMethodParams(const Interface& iface,
 void CProxyHeaderGenerator::GenInterfaceMethodBase(std::ofstream& stream,
     const Interface& iface, const Declaration& decl) {
   ReplaceAll(CB_INTERFACE_METHOD_BASE)
-      .Change("<RETURN_TYPE>", GetReturnTypeString(decl.GetType(), iface.GetID()))
+      .Change("<RETURN_TYPE>",
+              GetReturnTypeString(decl.GetType(), iface.GetID()))
       .Change("<PREFIX>", GetHandlePrefix())
       .Change("<NAME>", iface.GetID())
       .Change("<METHOD_NAME>", decl.GetID())
index d7cb19f8300338f88c237298a7f5abc16bdb1cb4..468eed688a57a0d8cb17bc17a4c29d826a147425 100644 (file)
@@ -36,22 +36,18 @@ class CProxyHeaderGenerator : public CHeaderGeneratorBase {
  private:
   void GenInterfaceHandles(std::ofstream& stream);
   void GenInterfaceHandle(std::ofstream& stream, const Interface& iface);
-  void GenInterfaceRemoteExceptionHandle(std::ofstream& stream,
-      const Interface& iface);
   void GenInterfaceDelegateHandle(std::ofstream& stream, const Interface& iface,
-      const Declaration& decl);
+                                  const Declaration& decl);
 
   void GenInterfaces(std::ofstream& stream);
   void GenInterface(std::ofstream& stream, const Interface& iface);
-  void GenInterfaceRemoteExceptionBase(std::ofstream& stream,
-      const Interface& iface);
   void GenInterfaceDelegateBase(std::ofstream& stream, const Interface& iface,
-      const Declaration& decl);
+                                const Declaration& decl);
   void GenInterfaceBase(std::ofstream& stream, const Interface& iface);
   void GenInterfaceMethodBase(std::ofstream& stream, const Interface& ifaceo,
-      const Declaration& decl);
+                              const Declaration& decl);
   std::string GenDelegateParams(const Interface& iface,
-      const Declaration& decl);
+                                const Declaration& decl);
   std::string GenMethodParams(const Interface& iface, const Declaration& decl);
 };
 
index ceec0ff8cdcd2895947c8f2f081ff5f65dd63dec..a7e66eae92808051d2e39810a62e0853e2a404dc 100644 (file)
@@ -340,65 +340,6 @@ R"__c_cb(
 <RETURN_TYPE><PREFIX>_<NAME>_invoke_<METHOD_NAME>(<PREFIX>_<NAME>_h h<METHOD_PARAMS>);
 )__c_cb";
 
-constexpr const char CB_INTERFACE_REMOTE_EXCEPTION_HANDLE[] =
-R"__c_cb(
-/**
- * @breif The <PREFIX> <NAME> remote exception handle.
- */
-typedef struct <PREFIX>_<NAME>_remote_exception_s *<PREFIX>_<NAME>_remote_exception_h;
-)__c_cb";
-
-constexpr const char CB_INTERFACE_REMOTE_EXCEPTION_BASE[] =
-R"__c_cb(
-/**
- * @brief Gets the remote exception handle.
- * @details If the return value is nullptr, there is no exceptions.
- * @remarks The handle should be released using <PREFIX>_<NAME>_remote_exception_destroy(), if it's no longer needed.
- * @param[out] h The <PREFIX> <NAME> remote exception handle.
- * @return @c 0 on success,
- *         otherwise a negative error value
- * @retval #RPC_PORT_ERROR_NONE Successful
- * @retval #RPC_PORT_ERROR_INVALID_PARAMETER Invalid parameter
- * @retval #RPC_PORT_ERROR_OUT_OF_MEMORY Out of memory
- * @see <PREFIX>_<NAME>_remote_exception_destroy();
- */
-int <PREFIX>_<NAME>_get_remote_exception(<PREFIX>_<NAME>_remote_exception_h *h);
-
-/**
- * @brief Gets the cause of the exception.
- * @param[in] h The <PREFIX> <NAME> remote exception handle.
- * @param[out] cause The cause
- * @return @c 0 on success,
- *         otherwise a negative error value
- * @retval #RPC_PORT_ERROR_NONE Successful
- * @retval #RPC_PORT_ERROR_INVALID_PARAMETER Invalid parameter
- */
-int <PREFIX>_<NAME>_remote_exception_get_cause(<PREFIX>_<NAME>_remote_exception_h h, int *cause);
-
-/**
- * @brief Gets the detail message of the exception.
- * @remarks The @c message should be released if it's no longer needed.
- * @param[in] h The <PREFIX> <NAME> remote exception handle.
- * @param[out] message The detail message
- * @return @c 0 on success,
- *         otherwise a negative error value
- * @retval #RPC_PORT_ERROR_NONE Successful
- * @retval #RPC_PORT_ERROR_INVALID_PARAMETER Invalid parameter
- * @retval #RPC_PORT_ERROR_OUT_OF_MEMORY Out of memory
- */
-int <PREFIX>_<NAME>_remote_exception_get_message(<PREFIX>_<NAME>_remote_exception_h, char **message);
-
-/**
- * @brief Destroys the remote exception handle.
- * @param[in] h The <PREFIX> <NAME> remote exception handle
- * @return @c 0 on success,
- *         otherwise a negative error value
- * @retval #RPC_PORT_ERROR_NONE Successful
- * @retval #RPC_PORT_ERROR_INVALID_PARAMETER Invalid parameter
- */
-int <PREFIX>_<NAME>_remote_exception_destroy(<PREFIX>_<NAME>_remote_exception_h h);
-)__c_cb";
-
 }  // namespace version2
 }  // namespace tidl
 
index d8c9e5ae325096ed6795df24d3d8e6f659496b55..f526afa7421c1c560db79a611b3fb4fbe9f284b7 100644 (file)
@@ -45,11 +45,13 @@ void CStubBodyGenerator::OnInitGen(std::ofstream& stream) {
   GenInterfaceMethodHandlerType(stream);
   GenDelegateDefinition(stream);
   GenStructureDefinition(stream);
+  GenRemoteExceptionDefinition(stream);
   GenInterfaceDefs(stream);
   GenPrivateSharingListSet(stream);
   GenUnitMapBase(stream);
   GenDelegateBase(stream);
   GenStructure(stream);
+  GenRemoteExceptionBase(stream);
   GenInterfaces(stream);
 }
 
@@ -107,50 +109,41 @@ void CStubBodyGenerator::GenInterfaceEnum(std::ofstream& stream,
 
 // @see #CB_INTERFACE_METHOD_ENUM
 std::string CStubBodyGenerator::GenMethodEnums(const Interface& iface) {
-  std::string method_enum(ReplaceAll(CB_INTERFACE_METHOD_ENUM, {
-      { "<UPPERCASE_PREFIX>", GetHandlePrefix() },
-      { "<UPPERCASE_NAME>", iface.GetID() },
-      { "<UPPERCASE_METHOD_NAME>", "RESULT_" }
-  }));
-
-  std::string method_enums = RemoveLine(method_enum);
-
-  method_enum = ReplaceAll(CB_INTERFACE_METHOD_ENUM, {
-      { "<UPPERCASE_PREFIX>", GetHandlePrefix() },
-      { "<UPPERCASE_NAME>", iface.GetID() },
-      { "<UPPERCASE_METHOD_NAME>", "CALLBACK_" }
-  });
-
-  method_enums += RemoveLine(method_enum);
+  std::string method_enums;
+  method_enums += RemoveLine(
+      std::string(ReplaceAll(CB_INTERFACE_METHOD_ENUM)
+                      .ChangeToUpper("<UPPERCASE_PREFIX>", GetHandlePrefix())
+                      .ChangeToUpper("<UPPERCASE_NAME>", iface.GetID())
+                      .ChangeToUpper("<UPPERCASE_METHOD_NAME>", "RESULT_")));
+  method_enums += RemoveLine(
+      std::string(ReplaceAll(CB_INTERFACE_METHOD_ENUM)
+                      .ChangeToUpper("<UPPERCASE_PREFIX>", GetHandlePrefix())
+                      .ChangeToUpper("<UPPERCASE_NAME>", iface.GetID())
+                      .ChangeToUpper("<UPPERCASE_METHOD_NAME>", "CALLBACK_")));
 
   for (const auto& d : iface.GetDeclarations()) {
     if (d->GetMethodType() == Declaration::MethodType::DELEGATE)
       continue;
 
-    method_enum = ReplaceAll(CB_INTERFACE_METHOD_ENUM, {
-        { "<UPPERCASE_PREFIX>", GetHandlePrefix() },
-        { "<UPPERCASE_NAME>", iface.GetID() },
-        { "<UPPERCASE_METHOD_NAME>", d->GetID() }
-    });
-
-    method_enums += RemoveLine(method_enum);
+    method_enums += RemoveLine(
+        std::string(ReplaceAll(CB_INTERFACE_METHOD_ENUM)
+                        .ChangeToUpper("<UPPERCASE_PREFIX>", GetHandlePrefix())
+                        .ChangeToUpper("<UPPERCASE_NAME>", iface.GetID())
+                        .ChangeToUpper("<UPPERCASE_METHOD_NAME>", d->GetID())));
   }
-  std::transform(method_enums.begin(), method_enums.end(), method_enums.begin(),
-      ::toupper);
 
   return method_enums;
 }
 
 // @see #CB_INTERFACE_METHOD_ENUM_BASE
 void CStubBodyGenerator::GenInterfaceMethodEnumBase(std::ofstream& stream,
-    const Interface& iface) {
-  std::string code(ReplaceAll(CB_INTERFACE_METHOD_ENUM_BASE, {
-      { "<PREFIX>", GetHandlePrefix() },
-      { "<NAME>", iface.GetID() },
-      { "<METHOD_ENUMS>", GenMethodEnums(iface) }
-  }));
-
-  stream << SmartIndent(code);
+                                                    const Interface& iface) {
+  ReplaceAll(CB_INTERFACE_METHOD_ENUM_BASE)
+      .Change("<PREFIX>", GetHandlePrefix())
+      .Change("<NAME>", iface.GetID())
+      .Change("<METHOD_ENUMS>", GenMethodEnums(iface))
+      .Transform([&](std::string code) { return SmartIndent(code); })
+      .Out(stream);
 }
 
 // @see #CB_INTERFACE_DELEGATE_ENUM
@@ -161,35 +154,30 @@ std::string CStubBodyGenerator::GenDelegateEnums(const Interface& iface) {
     if (d->GetMethodType() != Declaration::MethodType::DELEGATE)
       continue;
 
-    std::string method_enum(ReplaceAll(CB_INTERFACE_DELEGATE_ENUM, {
-        { "<UPPERCASE_PREFIX>", GetHandlePrefix() },
-        { "<UPPERCASE_NAME>", iface.GetID() },
-        { "<UPPERCASE_DELEGATE_NAME>", d->GetID() },
-        { "<NUMBER>", std::to_string(num++) }
-    }));
-
-    method_enums += RemoveLine(method_enum);
+    method_enums += RemoveLine(
+        std::string(ReplaceAll(CB_INTERFACE_DELEGATE_ENUM)
+                        .ChangeToUpper("<UPPERCASE_PREFIX>", GetHandlePrefix())
+                        .ChangeToUpper("<UPPERCASE_NAME>", iface.GetID())
+                        .ChangeToUpper("<UPPERCASE_DELEGATE_NAME>", d->GetID())
+                        .ChangeToUpper("<NUMBER>", std::to_string(num++))));
   }
-  std::transform(method_enums.begin(), method_enums.end(), method_enums.begin(),
-      ::toupper);
 
   return method_enums;
 }
 
 // @see #CB_INTERFACE_DELEGATE_ENUM_BASE
 void CStubBodyGenerator::GenInterfaceDelegateEnumBase(std::ofstream& stream,
-    const Interface& iface) {
+                                                      const Interface& iface) {
   std::string delegate_enums = GenDelegateEnums(iface);
   if (delegate_enums.empty())
     return;
 
-  std::string code(ReplaceAll(CB_INTERFACE_DELEGATE_ENUM_BASE, {
-      { "<PREFIX>", GetHandlePrefix() },
-      { "<NAME>", iface.GetID() },
-      { "<DELEGATE_ENUMS>", delegate_enums }
-  }));
-
-  stream << SmartIndent(code);
+  ReplaceAll(CB_INTERFACE_DELEGATE_ENUM_BASE)
+      .Change("<PREFIX>", GetHandlePrefix())
+      .Change("<NAME>", iface.GetID())
+      .Change("<DELEGATE_ENUMS>", delegate_enums)
+      .Transform([&](std::string code) { return SmartIndent(code); })
+      .Out(stream);
 }
 
 void CStubBodyGenerator::GenInterfaceDefs(std::ofstream& stream) {
@@ -203,7 +191,7 @@ void CStubBodyGenerator::GenInterfaceDefs(std::ofstream& stream) {
 }
 
 void CStubBodyGenerator::GenInterfaceDef(std::ofstream& stream,
-    const Interface& iface) {
+                                         const Interface& iface) {
   bool has_delegate = false;
   for (const auto& d : iface.GetDeclarations()) {
     if (d->GetMethodType() != Declaration::MethodType::DELEGATE)
@@ -217,63 +205,50 @@ void CStubBodyGenerator::GenInterfaceDef(std::ofstream& stream,
     GenInterfaceCallbackPortCheckDef(stream, iface);
 
   GenInterfaceContextDef(stream, iface);
-  GenInterfaceRemoteExceptionDefinition(stream, iface);
   GenInterfaceBaseDef(stream, iface);
 }
 
 // @see #CB_INTERFACE_DELEGATE_DEF
 void CStubBodyGenerator::GenInterfaceDelegateDef(std::ofstream& stream,
-    const Interface& iface, const Declaration& decl) {
-  std::string code(ReplaceAll(CB_INTERFACE_DELEGATE_DEF, {
-      { "<PREFIX>", GetHandlePrefix() },
-      { "<NAME>", iface.GetID() },
-      { "<DELEGATE_NAME>", decl.GetID() }
-  }));
-
-  stream << SmartIndent(code);
+                                                 const Interface& iface,
+                                                 const Declaration& decl) {
+  ReplaceAll(CB_INTERFACE_DELEGATE_DEF)
+      .Change("<PREFIX>", GetHandlePrefix())
+      .Change("<NAME>", iface.GetID())
+      .Change("<DELEGATE_NAME>", decl.GetID())
+      .Transform([&](std::string code) { return SmartIndent(code); })
+      .Out(stream);
 }
 
 // @see #CB_INTERFACE_CALLBACK_PORT_CHECK_DEF
-void CStubBodyGenerator::GenInterfaceCallbackPortCheckDef(std::ofstream& stream,
-    const Interface& iface) {
-  std::string code(ReplaceAll(CB_INTERFACE_CALLBACK_PORT_CHECK_DEF, {
-      { "<PREFIX>", GetHandlePrefix() },
-      { "<NAME>", iface.GetID() }
-  }));
-
-  stream << SmartIndent(code);
+void CStubBodyGenerator::GenInterfaceCallbackPortCheckDef(
+    std::ofstream& stream, const Interface& iface) {
+  ReplaceAll(CB_INTERFACE_CALLBACK_PORT_CHECK_DEF)
+      .Change("<PREFIX>", GetHandlePrefix())
+      .Change("<NAME>", iface.GetID())
+      .Transform([&](std::string code) { return SmartIndent(code); })
+      .Out(stream);
 }
 
 // @see #CB_INTERFACE_CONTEXT_DEF
 void CStubBodyGenerator::GenInterfaceContextDef(std::ofstream& stream,
-    const Interface& iface) {
-  std::string code(ReplaceAll(CB_INTERFACE_CONTEXT_DEF, {
-      { "<PREFIX>", GetHandlePrefix() },
-      { "<NAME>", iface.GetID() }
-  }));
-
-  stream << SmartIndent(code);
-}
-
-// @see #CB_INTERFACE_REMOTE_EXCEPTION_DEF
-void CStubBodyGenerator::GenInterfaceRemoteExceptionDefinition(
-    std::ofstream& stream, const Interface& iface) {
-  ReplaceAll(CB_INTERFACE_REMOTE_EXCEPTION_DEF)
+                                                const Interface& iface) {
+  ReplaceAll(CB_INTERFACE_CONTEXT_DEF)
       .Change("<PREFIX>", GetHandlePrefix())
       .Change("<NAME>", iface.GetID())
       .Transform([&](std::string code) { return SmartIndent(code); })
       .Out(stream);
 }
 
+
 // @see #CB_INTERFACE_BASE_DEF
 void CStubBodyGenerator::GenInterfaceBaseDef(std::ofstream& stream,
-    const Interface& iface) {
-  std::string code(ReplaceAll(CB_INTERFACE_BASE_DEF, {
-      { "<PREFIX>", GetHandlePrefix() },
-      { "<NAME>", iface.GetID() }
-  }));
-
-  stream << SmartIndent(code);
+                                             const Interface& iface) {
+  ReplaceAll(CB_INTERFACE_BASE_DEF)
+      .Change("<PREFIX>", GetHandlePrefix())
+      .Change("<NAME>", iface.GetID())
+      .Transform([&](std::string code) { return SmartIndent(code); })
+      .Out(stream);
 }
 
 void CStubBodyGenerator::GenInterfaces(std::ofstream& stream) {
@@ -308,7 +283,6 @@ void CStubBodyGenerator::GenInterface(std::ofstream& stream,
   GenInterfaceMethodPrivilegeCheckerTable(stream, iface);
   GenInterfaceMethodTable(stream, iface);
   GenInterfaceContextBase(stream, iface);
-  GenInterfaceRemoteExceptionBase(stream, iface);
 
   if (has_delegate)
     GenInterfaceCallbackPortCheck(stream, iface);
@@ -328,16 +302,6 @@ void CStubBodyGenerator::GenInterfaceContextBase(std::ofstream& stream,
       .Out(stream);
 }
 
-// @see #CB_INTERFACE_REMOTE_EXCEPTION_BASE
-void CStubBodyGenerator::GenInterfaceRemoteExceptionBase(
-    std::ofstream& stream, const Interface& iface) {
-  ReplaceAll(CB_INTERFACE_REMOTE_EXCEPTION_BASE)
-      .Change("<PREFIX>", GetHandlePrefix())
-      .Change("<NAME>", iface.GetID())
-      .Transform([&](std::string code) { return SmartIndent(code); })
-      .Out(stream);
-}
-
 std::string CStubBodyGenerator::GenDelegateParams(const Interface& iface,
     const Declaration& decl) {
   std::string params;
@@ -376,48 +340,39 @@ void CStubBodyGenerator::GenInterfaceDelegateBase(std::ofstream& stream,
     const Interface& iface, const Declaration& decl) {
   std::string enum_value = GetHandlePrefix() + "_" + iface.GetID() +
       "_DELEGATE_" + decl.GetID();
-  std::transform(enum_value.begin(), enum_value.end(), enum_value.begin(),
-      ::toupper);
-
-  std::string prefix = GetHandlePrefix();
-  std::transform(prefix.begin(), prefix.end(), prefix.begin(), ::toupper);
-
-  std::string name = iface.GetID();
-  std::transform(name.begin(), name.end(), name.begin(), ::toupper);
-
-  std::string code(ReplaceAll(CB_INTERFACE_DELEGATE_BASE, {
-      { "<PREFIX>", GetHandlePrefix() },
-      { "<NAME>", iface.GetID() },
-      { "<DELEGATE_NAME>", decl.GetID() },
-      { "<DELEGATE_PARAMS>", GenDelegateParams(iface, decl) },
-      { "<DELEGATE_PARAMS_CHECK>", GenDelegateParamsCheck(iface, decl) },
-      { "<DELEGATE_ENUM_VALUE>", enum_value },
-      { "<DELEGATE_UNIT_MAP_WRITE>", GenDelegateUnitMapWrite(iface, decl) },
-      { "<UPPERCASE_PREFIX>", prefix },
-      { "<UPPERCASE_NAME>", name }
-  }));
-
-  stream << SmartIndent(code);
+  ReplaceAll(CB_INTERFACE_DELEGATE_BASE)
+      .Change("<PREFIX>", GetHandlePrefix())
+      .Change("<NAME>", iface.GetID())
+      .Change("<DELEGATE_NAME>", decl.GetID())
+      .Change("<DELEGATE_PARAMS>", GenDelegateParams(iface, decl))
+      .Change("<DELEGATE_PARAMS_CHECK>", GenDelegateParamsCheck(iface, decl))
+      .ChangeToUpper("<DELEGATE_ENUM_VALUE>", enum_value)
+      .Change("<DELEGATE_UNIT_MAP_WRITE>", GenDelegateUnitMapWrite(iface, decl))
+      .ChangeToUpper("<UPPERCASE_PREFIX>", GetHandlePrefix())
+      .ChangeToUpper("<UPPERCASE_NAME>", iface.GetID())
+      .Transform([&](std::string code) { return SmartIndent(code); })
+      .Out(stream);
 }
 
-std::string CStubBodyGenerator::GenMethodHandlerArgsDecl(const Interface& iface,
-    const Declaration& decl) {
+std::string CStubBodyGenerator::GenMethodHandlerArgsDecl(
+    const Interface& iface, const Declaration& decl) {
   std::string args_decl;
   for (const auto& p : decl.GetParameters()) {
     auto& param_type = p->GetParameterType();
     auto& type = param_type.GetBaseType();
-    if (type.GetUserDefinedType() == BaseType::UserType::ENUM)
+    if (type.IsEnumType()) {
       args_decl += GetArgTypeString(type, iface) + p->GetID() + ";" + NLine(1);
-    else
+    } else {
       args_decl += GetArgTypeString(type, iface) + p->GetID() + " = " +
-          GetErrorValue(type) + ";" + NLine(1);
+                   GetErrorValue(type) + ";" + NLine(1);
+    }
   }
 
   if (decl.GetMethodType() == Declaration::MethodType::SYNC) {
     args_decl += "rpc_port_parcel_h parcel_;" + NLine(1);
     args_decl += "rpc_port_unit_map_h map_;" + NLine(1);
-    args_decl += GetArgTypeString(decl.GetType(), iface) + "res_ = " +
-        GetErrorValue(decl.GetType()) + ";" + NLine(1);
+    args_decl += GetArgTypeString(decl.GetType(), iface) +
+                 "res_ = " + GetErrorValue(decl.GetType()) + ";" + NLine(1);
   }
 
   return args_decl;
@@ -429,7 +384,7 @@ std::string CStubBodyGenerator::GenMethodHandlerArgsDecl(const Interface& iface,
 // @see #CB_INTERFACE_METHOD_STRING_UNIT_MAP_READ
 // @see #CB_INTERFACE_METHOD_BASE_UNIT_MAP_READ
 std::string CStubBodyGenerator::GenMethodUnitMapRead(const Interface& iface,
-    const Declaration& decl) {
+                                                     const Declaration& decl) {
   std::string code;
   for (const auto& p : decl.GetParameters()) {
     std::string parcel_read_code;
@@ -480,16 +435,6 @@ std::string CStubBodyGenerator::GenMethodUnitMapRead(const Interface& iface,
 // @see #CB_INTERFACE_METHOD_CALLBACK_INVOKE
 std::string CStubBodyGenerator::GenMethodHandlerCallbackInvoke(
     const Interface& iface, const Declaration& decl) {
-  std::string code(ReplaceAll(CB_INTERFACE_METHOD_CALLBACK_INVOKE,
-      "<METHOD_NAME>", decl.GetID()));
-  code = ReplaceAll(code, "<PREFIX>", GetHandlePrefix());
-  code = ReplaceAll(code, "<NAME>", iface.GetID());
-
-  if (decl.GetMethodType() == Declaration::MethodType::SYNC)
-    code = ReplaceAll(code, "<RES_SET>", "res_ = ");
-  else
-    code = ReplaceAll(code, "<RES_SET>", "");
-
   std::string args;
   for (const auto& p : decl.GetParameters()) {
     args += ", ";
@@ -499,14 +444,21 @@ std::string CStubBodyGenerator::GenMethodHandlerCallbackInvoke(
 
     args += p->GetID();
   }
-  code = ReplaceAll(code, "<METHOD_ARGS>", args);
 
-  return RemoveLine(code);
+  std::string res_set =
+      (decl.GetMethodType() == Declaration::MethodType::SYNC) ? "res_ = " : "";
+
+  return RemoveLine(std::string(ReplaceAll(CB_INTERFACE_METHOD_CALLBACK_INVOKE)
+                                    .Change("<METHOD_NAME>", decl.GetID())
+                                    .Change("<PREFIX>", GetHandlePrefix())
+                                    .Change("<NAME>", iface.GetID())
+                                    .Change("<RES_SET>", res_set)
+                                    .Change("<METHOD_ARGS>", args)));
 }
 
 std::string CStubBodyGenerator::GenDelegateUnitMapWrite(
     const Interface& iface, const Declaration& decl) {
-    std::string parcel_write_code;
+  std::string parcel_write_code;
   for (const auto& p : decl.GetParameters()) {
     auto& param_type = p->GetParameterType();
     parcel_write_code += GenMethodUnitMapWriteBase(
@@ -572,22 +524,18 @@ std::string CStubBodyGenerator::GenMethodUnitMapWrite(const Interface& iface,
   if (decl.GetMethodType() != Declaration::MethodType::SYNC)
     return code;
 
-  std::string prefix = GetHandlePrefix();
-  std::transform(prefix.begin(), prefix.end(), prefix.begin(), ::toupper);
-  code = ReplaceAll(CB_INTERFACE_METHOD_PARCEL_WRITE_PRE, "<UPPERCASE_PREFIX>",
-      prefix);
-
-  std::string name = iface.GetID();
-  std::transform(name.begin(), name.end(), name.begin(), ::toupper);
-  code = ReplaceAll(code, "<UPPERCASE_NAME>", name);
+  code = ReplaceAll(CB_INTERFACE_METHOD_PARCEL_WRITE_PRE)
+      .ChangeToUpper("<UPPERCASE_PREFIX>", GetHandlePrefix())
+      .ChangeToUpper("<UPPERCASE_NAME>", iface.GetID());
 
   std::string parcel_write_code;
   for (const auto& p : decl.GetParameters()) {
     auto& param_type = p->GetParameterType();
     if (param_type.GetDirection() == ParameterType::Direction::IN)
       continue;
-    code += GenMethodUnitMapWriteBase(
-        iface, param_type.GetBaseType(), p->GetID(), p->GetID());
+
+    code += GenMethodUnitMapWriteBase(iface, param_type.GetBaseType(),
+                                      p->GetID(), p->GetID());
   }
 
   code += GenMethodUnitMapWriteBase(iface, decl.GetType(), "[RESULT]", "res_");
@@ -604,55 +552,39 @@ std::string CStubBodyGenerator::GenMethodUnitMapWrite(const Interface& iface,
 // @see #CB_INTERFACE_METHOD_STRING_FREE
 std::string CStubBodyGenerator::GenMethodHandlerArgsFree(const Interface& iface,
     const Declaration& decl) {
-  std::string free_code;
   std::string code;
   for (const auto& p : decl.GetParameters()) {
     auto& param_type = p->GetParameterType();
     auto& type = param_type.GetBaseType();
-    if (type.GetUserDefinedType() == BaseType::UserType::STRUCTURE  ||
-        type.GetUserDefinedType() == BaseType::UserType::DELEGATE  ||
-        type.GetMetaType() != nullptr ||
-        type.GetKeyType() != nullptr) {
-      free_code = ReplaceAll(CB_INTERFACE_METHOD_USER_DEFINED_FREE,
-          "<PREFIX>", GetHandlePrefix());
-      free_code = ReplaceAll(free_code, "<NAME>",
-          GetFullNameFromType(type, iface));
-      free_code = ReplaceAll(free_code, "<ARG>", p->GetID());
+    if (type.IsStructureType() || type.IsDelegateType() ||
+        type.GetMetaType() != nullptr || type.GetKeyType() != nullptr) {
+      code += ReplaceAll(CB_INTERFACE_METHOD_USER_DEFINED_FREE)
+                  .Change("<PREFIX>", GetHandlePrefix())
+                  .Change("<NAME>", GetFullNameFromType(type, iface))
+                  .Change("<ARG>", p->GetID());
     } else if (type.ToString() == "bundle") {
-      free_code = ReplaceAll(CB_INTERFACE_METHOD_BUNDLE_FREE,
-          "<ARG>", p->GetID());
+      code += ReplaceAll(CB_INTERFACE_METHOD_BUNDLE_FREE)
+                  .Change("<ARG>", p->GetID());
     } else if (type.ToString() == "string" || type.ToString() == "file") {
-      free_code = ReplaceAll(CB_INTERFACE_METHOD_STRING_FREE,
-          "<ARG>", p->GetID());
-    } else {
-      free_code.clear();
+      code += ReplaceAll(CB_INTERFACE_METHOD_STRING_FREE)
+                  .Change("<ARG>", p->GetID());
     }
-
-    code += free_code;
   }
 
   if (decl.GetMethodType() == Declaration::MethodType::SYNC) {
+    std::string arg = "res_";
     auto& type = decl.GetType();
-    if (type.GetUserDefinedType() == BaseType::UserType::STRUCTURE  ||
-        type.GetUserDefinedType() == BaseType::UserType::DELEGATE  ||
-        type.GetMetaType() != nullptr ||
-        type.GetKeyType() != nullptr) {
-      free_code = ReplaceAll(CB_INTERFACE_METHOD_USER_DEFINED_FREE,
-          "<PREFIX>", GetHandlePrefix());
-      free_code = ReplaceAll(free_code, "<NAME>",
-          GetFullNameFromType(type, iface));
-      free_code = ReplaceAll(free_code, "<ARG>", "res_");
+    if (type.IsStructureType() || type.IsDelegateType() ||
+        type.GetMetaType() != nullptr || type.GetKeyType() != nullptr) {
+      code += ReplaceAll(CB_INTERFACE_METHOD_USER_DEFINED_FREE)
+                  .Change("<PREFIX>", GetHandlePrefix())
+                  .Change("<NAME>", GetFullNameFromType(type, iface))
+                  .Change("<ARG>", arg);
     } else if (type.ToString() == "bundle") {
-      free_code = ReplaceAll(CB_INTERFACE_METHOD_BUNDLE_FREE,
-          "<ARG>", "res_");
+      code += ReplaceAll(CB_INTERFACE_METHOD_BUNDLE_FREE).Change("<ARG>", arg);
     } else if (type.ToString() == "string" || type.ToString() == "file") {
-      free_code = ReplaceAll(CB_INTERFACE_METHOD_STRING_FREE,
-          "<ARG>", "res_");
-    } else {
-      free_code.clear();
+      code += ReplaceAll(CB_INTERFACE_METHOD_STRING_FREE).Change("<ARG>", arg);
     }
-
-    code += free_code;
   }
 
   return RemoveLine(code);
@@ -680,10 +612,10 @@ std::string CStubBodyGenerator::GenMethodPrivilegeChecker(
   std::string sync =
       (decl.GetMethodType() == Declaration::MethodType::SYNC) ?
       "true" : "false";
-  std::string code(ReplaceAll(CB_INTERFACE_METHOD_PRIVILEGE_CHECKER)
-      .Change("<PRIVILEGES>", privileges)
-      .Change("<SYNC_TRUE_OR_FALSE>", sync));
-  return RemoveLine(code);
+  return RemoveLine(
+      std::string(ReplaceAll(CB_INTERFACE_METHOD_PRIVILEGE_CHECKER)
+                      .Change("<PRIVILEGES>", privileges)
+                      .Change("<SYNC_TRUE_OR_FALSE>", sync)));
 }
 
 // @see #CB_INTERFACE_METHOD_PRIVILEGE_CHECKER_BASE
@@ -699,23 +631,22 @@ void CStubBodyGenerator::GenInterfaceMethodPrivilegeCheckerBase(
 }
 
 // @see #CB_INTERFACE_METHOD_HANDLER_BASE
-void CStubBodyGenerator::GenInterfaceMethodHandlerBase(std::ofstream& stream,
-    const Interface& iface, const Declaration& decl) {
-  std::string code(ReplaceAll(CB_INTERFACE_METHOD_HANDLER_BASE, {
-      { "<PREFIX>", GetHandlePrefix() },
-      { "<NAME>", iface.GetID() },
-      { "<METHOD_NAME>", decl.GetID() },
-      { "<METHOD_HANDLER_ARGS_DECL>", GenMethodHandlerArgsDecl(iface, decl) },
-      { "<METHOD_UNIT_MAP_READ>",
-          GenMethodUnitMapRead(iface, decl) },
-      { "<METHOD_HANDLER_CALLBACK_INVOKE>",
-          GenMethodHandlerCallbackInvoke(iface, decl) },
-      { "<METHOD_UNIT_MAP_WRITE>",
-          GenMethodUnitMapWrite(iface, decl) },
-      { "<METHOD_HANDLER_ARGS_FREE>", GenMethodHandlerArgsFree(iface, decl) }
-  }));
-
-  stream << SmartIndent(code);
+void CStubBodyGenerator::GenInterfaceMethodHandlerBase(
+    std::ofstream& stream, const Interface& iface, const Declaration& decl) {
+  ReplaceAll(CB_INTERFACE_METHOD_HANDLER_BASE)
+      .Change("<PREFIX>", GetHandlePrefix())
+      .Change("<NAME>", iface.GetID())
+      .Change("<METHOD_NAME>", decl.GetID())
+      .Change("<METHOD_HANDLER_ARGS_DECL>",
+              GenMethodHandlerArgsDecl(iface, decl))
+      .Change("<METHOD_UNIT_MAP_READ>", GenMethodUnitMapRead(iface, decl))
+      .Change("<METHOD_HANDLER_CALLBACK_INVOKE>",
+              GenMethodHandlerCallbackInvoke(iface, decl))
+      .Change("<METHOD_UNIT_MAP_WRITE>", GenMethodUnitMapWrite(iface, decl))
+      .Change("<METHOD_HANDLER_ARGS_FREE>",
+              GenMethodHandlerArgsFree(iface, decl))
+      .Transform([&](std::string code) { return SmartIndent(code); })
+      .Out(stream);
 }
 
 // @ see #CB_INTERFACE_PRIVILEGE_CHECKER
@@ -758,16 +689,12 @@ std::string CStubBodyGenerator::GenMethodHandlers(const Interface& iface) {
 
     std::string enum_value = GetHandlePrefix() + "_" + iface.GetID() +
       "_METHOD_" + d->GetID();
-    std::transform(enum_value.begin(), enum_value.end(), enum_value.begin(),
-        ::toupper);
-    std::string method_handler(ReplaceAll(CB_INTERFACE_METHOD_HANDLER, {
-        { "<ENUM_VALUE>", enum_value },
-        { "<PREFIX>", GetHandlePrefix() },
-        { "<NAME>", iface.GetID() },
-        { "<METHOD_NAME>", d->GetID() }
-    }));
-
-    code += RemoveLine(method_handler);
+    code +=
+        RemoveLine(std::string(ReplaceAll(CB_INTERFACE_METHOD_HANDLER)
+                                   .ChangeToUpper("<ENUM_VALUE>", enum_value)
+                                   .Change("<PREFIX>", GetHandlePrefix())
+                                   .Change("<NAME>", iface.GetID())
+                                   .Change("<METHOD_NAME>", d->GetID())));
   }
 
   return code;
@@ -775,24 +702,22 @@ std::string CStubBodyGenerator::GenMethodHandlers(const Interface& iface) {
 
 // @see #CB_INTERFACE_METHOD_TABLE
 void CStubBodyGenerator::GenInterfaceMethodTable(std::ofstream& stream,
-    const Interface& iface) {
-  std::string code(ReplaceAll(CB_INTERFACE_METHOD_TABLE, {
-      { "<NAME>", iface.GetID() },
-      { "<METHOD_HANDLERS>", GenMethodHandlers(iface) }
-  }));
-
-  stream << SmartIndent(code);
+                                                 const Interface& iface) {
+  ReplaceAll(CB_INTERFACE_METHOD_TABLE)
+      .Change("<NAME>", iface.GetID())
+      .Change("<METHOD_HANDLERS>", GenMethodHandlers(iface))
+      .Transform([&](std::string code) { return SmartIndent(code); })
+      .Out(stream);
 }
 
 // @see #CB_INTERFACE_CALLBACK_PORT_CHECK
 void CStubBodyGenerator::GenInterfaceCallbackPortCheck(std::ofstream& stream,
-    const Interface& iface) {
-  std::string code(ReplaceAll(CB_INTERFACE_CALLBACK_PORT_CHECK, {
-      { "<PREFIX>", GetHandlePrefix() },
-      { "<NAME>", iface.GetID() }
-  }));
-
-  stream << SmartIndent(code);
+                                                       const Interface& iface) {
+  ReplaceAll(CB_INTERFACE_CALLBACK_PORT_CHECK)
+      .Change("<PREFIX>", GetHandlePrefix())
+      .Change("<NAME>", iface.GetID())
+      .Transform([&](std::string code) { return SmartIndent(code); })
+      .Out(stream);
 }
 
 // @see #CB_INTERFACE_PRIVILEGE_ADD
@@ -801,17 +726,12 @@ std::string CStubBodyGenerator::GenAccessControlSet(const Interface& iface) {
   std::string code;
   for (const auto& attr : iface.GetAttributes()) {
     if (attr->GetKey() == "privilege") {
-      std::string privilege_add(ReplaceAll(CB_INTERFACE_PRIVILEGE_ADD, {
-          { "<NAME>", iface.GetID() },
-          { "<PRIVILEGE>", attr->GetValue() }
-      }));
-
-      code += privilege_add;
+      code += ReplaceAll(CB_INTERFACE_PRIVILEGE_ADD)
+          .Change("<NAME>", iface.GetID())
+          .Change("<PRIVILEGE>", attr->GetValue());
     } else if (attr->GetKey() == "trusted" && attr->GetValue() == "true") {
-      std::string trusted_set(ReplaceAll(CB_INTERFACE_TRUSTED_SET,
-          "<NAME>", iface.GetID()));
-
-      code += trusted_set;
+      code += ReplaceAll(CB_INTERFACE_TRUSTED_SET)
+          .Change("<NAME>", iface.GetID());
     }
   }
 
@@ -821,14 +741,13 @@ std::string CStubBodyGenerator::GenAccessControlSet(const Interface& iface) {
 // @see #CB_INTERFACE_BASE
 void CStubBodyGenerator::GenInterfaceBase(std::ofstream& stream,
     const Interface& iface) {
-  std::string code(ReplaceAll(CB_INTERFACE_BASE, {
-      { "<PREFIX>", GetHandlePrefix() },
-      { "<PREFIX_REVERSE>", GetHandlePrefixReverse() },
-      { "<NAME>", iface.GetID() },
-      { "<ACCESS_CONTROL_SET>", GenAccessControlSet(iface) }
-  }));
-
-  stream << SmartIndent(code);
+  ReplaceAll(CB_INTERFACE_BASE)
+      .Change("<PREFIX>", GetHandlePrefix())
+      .Change("<PREFIX_REVERSE>", GetHandlePrefixReverse())
+      .Change("<NAME>", iface.GetID())
+      .Change("<ACCESS_CONTROL_SET>", GenAccessControlSet(iface))
+      .Transform([&](std::string code) { return SmartIndent(code); })
+      .Out(stream);
 }
 
 }  // namespace version2
index 91bd231fd31f8af133dfee9d9921f2ea8f36f3fa..befeb8407ee90a642852ae080e6b4628f78cc8db 100644 (file)
@@ -14,8 +14,8 @@
  * limitations under the License.
  */
 
-#ifndef IDLC_C_GEN_C_STUB_BODY_GENERATOR_HH_
-#define IDLC_C_GEN_C_STUB_BODY_GENERATOR_HH_
+#ifndef IDLC_GEN_VERSION2_C_STUB_BODY_GENERATOR_HH_
+#define IDLC_GEN_VERSION2_C_STUB_BODY_GENERATOR_HH_
 
 #include <memory>
 #include <string>
@@ -29,7 +29,7 @@ namespace version2 {
 class CStubBodyGenerator : public CBodyGeneratorBase {
  public:
   explicit CStubBodyGenerator(std::shared_ptr<Document> doc,
-      std::shared_ptr<Options> options);
+                              std::shared_ptr<Options> options);
   virtual ~CStubBodyGenerator() = default;
 
   void OnInitGen(std::ofstream& stream) override;
@@ -42,64 +42,63 @@ class CStubBodyGenerator : public CBodyGeneratorBase {
   void GenInterfaceEnums(std::ofstream& stream);
   void GenInterfaceEnum(std::ofstream& stream, const Interface& iface);
   void GenInterfaceMethodEnumBase(std::ofstream& stream,
-      const Interface& iface);
+                                  const Interface& iface);
   void GenInterfaceDelegateEnumBase(std::ofstream& stream,
-      const Interface& iface);
+                                    const Interface& iface);
 
   void GenInterfaceDefs(std::ofstream& stream);
   void GenInterfaceDef(std::ofstream& stream, const Interface& iface);
   void GenInterfaceContextDef(std::ofstream& stream, const Interface& iface);
-  void GenInterfaceRemoteExceptionDefinition(std::ofstream& stream,
-      const Interface& iface);
   void GenInterfaceDelegateDef(std::ofstream& stream, const Interface& iface,
-      const Declaration& decl);
+                               const Declaration& decl);
   void GenInterfaceCallbackPortCheckDef(std::ofstream& stream,
-      const Interface& iface);
+                                        const Interface& iface);
   void GenInterfaceBaseDef(std::ofstream& stream, const Interface& iface);
 
   void GenInterfaces(std::ofstream& stream);
   void GenInterface(std::ofstream& stream, const Interface& iface);
   void GenInterfaceContextBase(std::ofstream& stream, const Interface& iface);
-  void GenInterfaceRemoteExceptionBase(std::ofstream& stream,
-      const Interface& iface);
   void GenInterfaceDelegateBase(std::ofstream& stream, const Interface& iface,
-      const Declaration& decl);
+                                const Declaration& decl);
   void GenInterfaceMethodPrivilegeCheckerBase(std::ofstream& stream,
-      const Interface& iface, const Declaration& decl);
+                                              const Interface& iface,
+                                              const Declaration& decl);
   void GenInterfaceMethodPrivilegeCheckerTable(std::ofstream& stream,
-      const Interface& iface);
+                                               const Interface& iface);
   void GenInterfaceMethodHandlerBase(std::ofstream& stream,
-      const Interface& iface, const Declaration& decl);
+                                     const Interface& iface,
+                                     const Declaration& decl);
   void GenInterfaceMethodTable(std::ofstream& stream, const Interface& iface);
   void GenInterfaceCallbackPortCheck(std::ofstream& stream,
-      const Interface& iface);
+                                     const Interface& iface);
   void GenInterfaceBase(std::ofstream& stream, const Interface& iface);
 
   std::string GenMethodEnums(const Interface& iface);
   std::string GenDelegateEnums(const Interface& iface);
 
   std::string GenDelegateParams(const Interface& iface,
-      const Declaration& decl);
+                                const Declaration& decl);
   std::string GenDelegateParamsCheck(const Interface& iface,
-      const Declaration& decl);
+                                     const Declaration& decl);
   std::string GenPrivileges(const Declaration& decl);
   std::string GenMethodPrivilegeChecker(const Declaration& decl);
   std::string GenPrivilegeCheckers(const Interface& iface);
   std::string GenMethodHandlerArgsDecl(const Interface& iface,
-      const Declaration& decl);
+                                       const Declaration& decl);
   std::string GenMethodUnitMapRead(const Interface& iface,
-      const Declaration& decl);
+                                   const Declaration& decl);
   std::string GenMethodHandlerCallbackInvoke(const Interface& iface,
-      const Declaration& decl);
-  std::string GenMethodUnitMapWriteBase(
-      const Interface& iface, const BaseType& type,
-      const std::string& arg_name, const std::string& arg);
+                                             const Declaration& decl);
+  std::string GenMethodUnitMapWriteBase(const Interface& iface,
+                                        const BaseType& type,
+                                        const std::string& arg_name,
+                                        const std::string& arg);
   std::string GenMethodUnitMapWrite(const Interface& iface,
-      const Declaration& decl);
-  std::string GenDelegateUnitMapWrite(
-    const Interface& iface, const Declaration& decl);
+                                    const Declaration& decl);
+  std::string GenDelegateUnitMapWrite(const Interface& iface,
+                                      const Declaration& decl);
   std::string GenMethodHandlerArgsFree(const Interface& iface,
-      const Declaration& decl);
+                                       const Declaration& decl);
   std::string GenMethodHandlers(const Interface& iface);
   std::string GenAccessControlSet(const Interface& iface);
   void GenDelegateDefinition(std::ofstream& stream);
@@ -113,4 +112,4 @@ class CStubBodyGenerator : public CBodyGeneratorBase {
 }  // namespace version2
 }  // namespace tidl
 
-#endif  // IDLC_C_GEN_C_STUB_BODY_GENERATOR_HH_
+#endif  // IDLC_GEN_VERSION2_C_STUB_BODY_GENERATOR_HH_
index d6630764a4b73aa8ad1273a378ffd810c4b82e15..a43d682bc00b7a44bd6eb0d8e282a4a5ac1e5837 100644 (file)
  * limitations under the License.
  */
 
-#ifndef IDLC_C_GEN_C_STUB_BODY_GENERATOR_CB_H_
-#define IDLC_C_GEN_C_STUB_BODY_GENERATOR_CB_H_
+#ifndef IDLC_GEN_VERSION2_C_STUB_BODY_GENERATOR_CB_HH_
+#define IDLC_GEN_VERSION2_C_STUB_BODY_GENERATOR_CB_HH_
+
+namespace tidl {
+namespace version2 {
 
 constexpr const char CB_PRIVATE_HEADERS[] =
 R"__c_cb(
@@ -243,7 +246,7 @@ constexpr const char CB_INTERFACE_CONTEXT_BASE[] =
 R"__c_cb(
 static void __<PREFIX>_<NAME>_throw_remote_exception(rpc_port_h port, rpc_port_parcel_h parcel, int cause, const char *message)
 {
-  <PREFIX>_<NAME>_remote_exception_h remote_exception = nullptr;
+  <PREFIX>_remote_exception_h remote_exception = nullptr;
   rpc_port_parcel_h result_parcel = nullptr;
   rpc_port_parcel_header_h header = nullptr;
   rpc_port_unit_map_h map;
@@ -257,11 +260,11 @@ static void __<PREFIX>_<NAME>_throw_remote_exception(rpc_port_h port, rpc_port_p
 
   rpc_port_unit_map_write_int(map, "[METHOD]", <UPPERCASE_PREFIX>_<UPPERCASE_NAME>_METHOD_RESULT_);
 
-  <PREFIX>_<NAME>_remote_exception_create(&remote_exception);
-  <PREFIX>_<NAME>_remote_exception_set_cause(remote_exception, cause);
-  <PREFIX>_<NAME>_remote_exception_set_message(remote_exception, message);
-  rpc_port_unit_map_write_<NAME>_remote_exception(map, "[REMOTE_EXCEPTION]", remote_exception);
-  <PREFIX>_<NAME>_remote_exception_destroy(remote_exception);
+  <PREFIX>_remote_exception_create(&remote_exception);
+  <PREFIX>_remote_exception_set_cause(remote_exception, cause);
+  <PREFIX>_remote_exception_set_message(remote_exception, message);
+  rpc_port_unit_map_write_remote_exception(map, "[REMOTE_EXCEPTION]", remote_exception);
+  <PREFIX>_remote_exception_destroy(remote_exception);
 
   if (rpc_port_parcel_create(&result_parcel) != RPC_PORT_ERROR_NONE) {
     _E("Failed to create parcel handle");
@@ -1276,9 +1279,9 @@ rpc_port_parcel_read_<PARCEL_TYPE>(parcel, &<ARG>);
  */
 constexpr const char CB_INTERFACE_METHOD_CALLBACK_INVOKE[] =
 R"__c_cb(
-if (__<PREFIX>_<NAME>_remote_exception != nullptr) {
-  <PREFIX>_<NAME>_remote_exception_destroy(__<PREFIX>_<NAME>_remote_exception);
-  __<PREFIX>_<NAME>_remote_exception = nullptr;
+if (__<PREFIX>_remote_exception != nullptr) {
+  <PREFIX>_remote_exception_destroy(__<PREFIX>_remote_exception);
+  __<PREFIX>_remote_exception = nullptr;
 }
 
 if (context_->callback.<METHOD_NAME>)
@@ -1318,8 +1321,8 @@ rpc_port_unit_map_write_int(map_, "[METHOD]",  <UPPERCASE_PREFIX>_<UPPERCASE_NAM
  */
 constexpr const char CB_INTERFACE_METHOD_PARCEL_WRITE_POST[] =
 R"__c_cb(
-if (__<PREFIX>_<NAME>_remote_exception != nullptr)
-  rpc_port_unit_map_write_<NAME>_remote_exception(map_, "[REMOTE_EXCEPTION]", __<PREFIX>_<NAME>_remote_exception);
+if (__<PREFIX>_remote_exception != nullptr)
+  rpc_port_unit_map_write_remote_exception(map_, "[REMOTE_EXCEPTION]", __<PREFIX>_remote_exception);
 
  if (context_->lem_cb.is_LEM) {
   stub_result_.lem_ret = map_;
@@ -1724,167 +1727,6 @@ if (ret != RPC_PORT_ERROR_NONE) {
 }
 )__c_cb";
 
-/**
- * <PREFIX> The prefix of the interface.
- * <NAME> The name of the interface.
- */
-constexpr const char CB_INTERFACE_REMOTE_EXCEPTION_DEF[] =
-R"__c_cb(
-typedef struct <PREFIX>_<NAME>_remote_exception_s {
-  rpc_port_parcelable_t parcelable;
-  int cause;
-  char *message;
-} <PREFIX>_<NAME>_remote_exception_t;
-
-static __thread <PREFIX>_<NAME>_remote_exception_h __<PREFIX>_<NAME>_remote_exception;
-)__c_cb";
-
-/**
- * <PREFIX> The prefix of the interface.
- * <NAME> The name of the interface.
- */
-constexpr const char CB_INTERFACE_REMOTE_EXCEPTION_BASE[] =
-R"__c_cb(
-static void __<PREFIX>_<NAME>_remote_exception_to(rpc_port_parcel_h parcel, void *user_data)
-{
-  <PREFIX>_<NAME>_remote_exception_h h = user_data;
-  rpc_port_unit_map_h map;
-
-  map = rpc_port_unit_map_create();
-  if (map == nullptr) {
-    set_last_result(RPC_PORT_ERROR_OUT_OF_MEMORY);
-    return;
-  }
-
-  rpc_port_unit_map_write_int(map, "cause", h->cause);
-  rpc_port_unit_map_write_string(map, "message", h->message);
-  rpc_port_parcel_write(parcel, &map->parcelable, map);
-  rpc_port_unit_map_destroy(map);
-  set_last_result(RPC_PORT_ERROR_NONE);
-}
-
-static void __<PREFIX>_<NAME>_remote_exception_from(rpc_port_parcel_h parcel, void *user_data)
-{
-  <PREFIX>_<NAME>_remote_exception_h h = user_data;
-  rpc_port_unit_map_h map;
-
-  map = rpc_port_unit_map_create();
-  if (map == nullptr) {
-    set_last_result(RPC_PORT_ERROR_OUT_OF_MEMORY);
-    return;
-  }
-
-  rpc_port_parcel_read(parcel, &map->parcelable, map);
-  rpc_port_unit_map_read_int(map, "cause", &h->cause);
-  rpc_port_unit_map_read_string(map, "message", &h->message);
-  rpc_port_unit_map_destroy(map);
-  set_last_result(RPC_PORT_ERROR_NONE);
-}
-
-int <PREFIX>_<NAME>_remote_exception_create(<PREFIX>_<NAME>_remote_exception_h *h)
-{
-  <PREFIX>_<NAME>_remote_exception_h exception;
-
-  if (h == nullptr) {
-    _E("Invalid parameter");
-    return RPC_PORT_ERROR_INVALID_PARAMETER;
-  }
-
-  exception = calloc(1, sizeof(<PREFIX>_<NAME>_remote_exception_t));
-  if (exception == nullptr) {
-    _E("calloc() is failed");
-    return RPC_PORT_ERROR_OUT_OF_MEMORY;
-  }
-
-  exception->parcelable.to = __<PREFIX>_<NAME>_remote_exception_to;
-  exception->parcelable.from = __<PREFIX>_<NAME>_remote_exception_from;
-
-  *h = exception;
-
-  return RPC_PORT_ERROR_NONE;
-}
-
-int <PREFIX>_<NAME>_remote_exception_set_cause(<PREFIX>_<NAME>_remote_exception_h h, int cause)
-{
-  if (h == nullptr) {
-    _E("Invalid parameter");
-    return RPC_PORT_ERROR_INVALID_PARAMETER;
-  }
-
-  h->cause = cause;
-
-  return RPC_PORT_ERROR_NONE;
-}
-
-int <PREFIX>_<NAME>_remote_exception_set_message(<PREFIX>_<NAME>_remote_exception_h h, const char *message)
-{
-  if (h == nullptr || message == nullptr) {
-    _E("Invalid parameter");
-    return RPC_PORT_ERROR_INVALID_PARAMETER;
-  }
-
-  if (h->message)
-    free(h->message);
-
-  h->message = strdup(message);
-  if (h->message == nullptr) {
-    _E("strdup() is failed");
-    return RPC_PORT_ERROR_OUT_OF_MEMORY;
-  }
-
-  return RPC_PORT_ERROR_NONE;
-}
-
-int <PREFIX>_<NAME>_remote_exception_throw(<PREFIX>_<NAME>_remote_exception_h h)
-{
-  rpc_port_unit_map_h map;
-  int ret;
-
-  if (h == nullptr) {
-    _E("Invalid parameter");
-    return RPC_PORT_ERROR_INVALID_PARAMETER;
-  }
-
-   map = rpc_port_unit_map_create();
-  if (map == nullptr) {
-    _E("Failed to create unit map");
-    return RPC_PORT_ERROR_OUT_OF_MEMORY;
-  }
-
-  ret = rpc_port_unit_map_write_<NAME>_remote_exception(map, "clone", h);
-  if (ret != RPC_PORT_ERROR_NONE) {
-    _E("Failed to write remote exception. error(%d)", ret);
-    rpc_port_unit_map_destroy(map);
-    return ret;
-  }
-
-  if (__<PREFIX>_<NAME>_remote_exception != nullptr) {
-    <PREFIX>_<NAME>_remote_exception_destroy(__<PREFIX>_<NAME>_remote_exception);
-    __<PREFIX>_<NAME>_remote_exception = nullptr;
-  }
-
-  ret = rpc_port_unit_map_read_<NAME>_remote_exception(map, "clone", &__<PREFIX>_<NAME>_remote_exception);
-  rpc_port_unit_map_destroy(map);
-
-  return ret;
-}
-
-int <PREFIX>_<NAME>_remote_exception_destroy(<PREFIX>_<NAME>_remote_exception_h h)
-{
-  if (h == nullptr) {
-    _E("Invalid parameter");
-    return RPC_PORT_ERROR_INVALID_PARAMETER;
-  }
-
-  if (h->message)
-    free(h->message);
-
-  free(h);
-
-  return RPC_PORT_ERROR_NONE;
-}
-)__c_cb";
-
 /**
  * <PREFIX> The prefix of the interace.
  * <NAME> The name of the interface.
@@ -1943,4 +1785,7 @@ R"__c_cb(
 [<ENUM_VALUE>] = __<PREFIX>_<NAME>_method_<METHOD_NAME>_privilege_checker,
 )__c_cb";
 
-#endif  // IDLC_C_GEN_C_STUB_BODY_GENERATOR_CB_H_
+}  // namespace version2
+}  // namespace tidl
+
+#endif  // IDLC_GEN_VERSION2_C_STUB_BODY_GENERATOR_CB_HH_
index b912dd2dae80b1c9e60b7167226bf427bbb67863..da089dc6017d89a302684f07ad1b9ebcf09986e1 100644 (file)
@@ -16,9 +16,7 @@
 
 #include "idlc/gen/version2/c_stub_header_generator.hh"
 
-namespace {
 #include "idlc/gen/version2/c_stub_header_generator_cb.hh"
-}
 
 namespace tidl {
 namespace version2 {
@@ -33,8 +31,10 @@ void CStubHeaderGenerator::OnInitGen(std::ofstream& stream) {
   GenExplicitLinkageOpen(stream);
   GenEnums(stream);
   GenStructureHandles(stream);
+  GenRemoteExceptionHandle(stream);
   GenInterfaceHandles(stream);
   GenStructures(stream);
+  GenRemoteException(stream);
   GenInterfaceCallbacks(stream);
   GenInterfaces(stream);
 }
@@ -50,7 +50,6 @@ void CStubHeaderGenerator::GenInterfaceHandles(std::ofstream& stream) {
 
     auto& iface = static_cast<const Interface&>(*b);
     GenInterfaceContextHandle(stream, iface);
-    GenInterfaceRemoteExceptionHandle(stream, iface);
     for (const auto& d : iface.GetDeclarations()) {
       if (d->GetMethodType() != Declaration::MethodType::DELEGATE)
         continue;
@@ -62,19 +61,8 @@ void CStubHeaderGenerator::GenInterfaceHandles(std::ofstream& stream) {
 
 // @see #CB_INTERFACE_CONTEXT_HANDLE
 void CStubHeaderGenerator::GenInterfaceContextHandle(std::ofstream& stream,
-    const Interface& iface) {
-  std::string code(ReplaceAll(CB_INTERFACE_CONTEXT_HANDLE, {
-      { "<PREFIX>", GetHandlePrefix() },
-      { "<NAME>", iface.GetID() }
-  }));
-
-  stream << SmartIndent(code);
-}
-
-// @see #CB_INTERFACE_REMOTE_EXCEPTION_HANDLE
-void CStubHeaderGenerator::GenInterfaceRemoteExceptionHandle(
-    std::ofstream& stream, const Interface& iface) {
-  ReplaceAll(CB_INTERFACE_REMOTE_EXCEPTION_HANDLE)
+                                                     const Interface& iface) {
+  ReplaceAll(CB_INTERFACE_CONTEXT_HANDLE)
       .Change("<PREFIX>", GetHandlePrefix())
       .Change("<NAME>", iface.GetID())
       .Transform([&](std::string code) { return SmartIndent(code); })
@@ -83,14 +71,14 @@ void CStubHeaderGenerator::GenInterfaceRemoteExceptionHandle(
 
 // @see #CB_INTERFACE_DELEGATE_HANDLE
 void CStubHeaderGenerator::GenInterfaceDelegateHandle(std::ofstream& stream,
-    const Interface& iface, const Declaration& decl) {
-  std::string code(ReplaceAll(CB_INTERFACE_DELEGATE_HANDLE, {
-      { "<PREFIX>", GetHandlePrefix() },
-      { "<NAME>", iface.GetID() },
-      { "<DELEGATE_NAME>", decl.GetID() }
-  }));
-
-  stream << SmartIndent(code);
+                                                      const Interface& iface,
+                                                      const Declaration& decl) {
+  ReplaceAll(CB_INTERFACE_DELEGATE_HANDLE)
+      .Change("<PREFIX>", GetHandlePrefix())
+      .Change("<NAME>", iface.GetID())
+      .Change("<DELEGATE_NAME>", decl.GetID())
+      .Transform([&](std::string code) { return SmartIndent(code); })
+      .Out(stream);
 }
 
 void CStubHeaderGenerator::GenInterfaceCallbacks(std::ofstream& stream) {
@@ -111,17 +99,16 @@ void CStubHeaderGenerator::GenInterfaceCallbacks(std::ofstream& stream) {
 
 // @see #CB_INTERFACE_CALLBACK_BASE
 void CStubHeaderGenerator::GenInterfaceCallbackBase(std::ofstream& stream,
-    const Interface& iface) {
-  std::string code(ReplaceAll(CB_INTERFACE_CALLBACK_BASE, {
-      { "<PREFIX>", GetHandlePrefix() },
-      { "<NAME>", iface.GetID() }
-  }));
-
-  stream << SmartIndent(code);
+                                                    const Interface& iface) {
+  ReplaceAll(CB_INTERFACE_CALLBACK_BASE)
+      .Change("<PREFIX>", GetHandlePrefix())
+      .Change("<NAME>", iface.GetID())
+      .Transform([&](std::string code) { return SmartIndent(code); })
+      .Out(stream);
 }
 
 std::string CStubHeaderGenerator::GenMethodParams(const Interface& iface,
-    const Declaration& decl) {
+                                                  const Declaration& decl) {
   std::string params;
   for (const auto& p : decl.GetParameters()) {
     params += ", ";
@@ -135,17 +122,17 @@ std::string CStubHeaderGenerator::GenMethodParams(const Interface& iface,
 }
 
 // @see #CB_INTERFACE_METHOD_CALLBACK_BASE
-void CStubHeaderGenerator::GenInterfaceMethodCallbackBase(std::ofstream& stream,
-    const Interface& iface, const Declaration& decl) {
-  std::string code(ReplaceAll(CB_INTERFACE_METHOD_CALLBACK_BASE, {
-      { "<RETURN_TYPE>", GetReturnTypeString(decl.GetType(), iface.GetID()) },
-      { "<PREFIX>", GetHandlePrefix() },
-      { "<NAME>", iface.GetID() },
-      { "<METHOD_NAME>", decl.GetID() },
-      { "<METHOD_PARAMS>", GenMethodParams(iface, decl) }
-  }));
-
-  stream << SmartIndent(code);
+void CStubHeaderGenerator::GenInterfaceMethodCallbackBase(
+    std::ofstream& stream, const Interface& iface, const Declaration& decl) {
+  ReplaceAll(CB_INTERFACE_METHOD_CALLBACK_BASE)
+      .Change("<RETURN_TYPE>",
+              GetReturnTypeString(decl.GetType(), iface.GetID()))
+      .Change("<PREFIX>", GetHandlePrefix())
+      .Change("<NAME>", iface.GetID())
+      .Change("<METHOD_NAME>", decl.GetID())
+      .Change("<METHOD_PARAMS>", GenMethodParams(iface, decl))
+      .Transform([&](std::string code) { return SmartIndent(code); })
+      .Out(stream);
 }
 
 void CStubHeaderGenerator::GenInterfaces(std::ofstream& stream) {
@@ -159,9 +146,8 @@ void CStubHeaderGenerator::GenInterfaces(std::ofstream& stream) {
 }
 
 void CStubHeaderGenerator::GenInterface(std::ofstream& stream,
-    const Interface& iface) {
+                                        const Interface& iface) {
   GenInterfaceContextBase(stream, iface);
-  GenInterfaceRemoteExceptionBase(stream, iface);
   for (const auto& d : iface.GetDeclarations()) {
     if (d->GetMethodType() != Declaration::MethodType::DELEGATE)
       continue;
@@ -174,19 +160,8 @@ void CStubHeaderGenerator::GenInterface(std::ofstream& stream,
 
 // @see #CB_INTERFACE_CONTEXT_BASE
 void CStubHeaderGenerator::GenInterfaceContextBase(std::ofstream& stream,
-    const Interface& iface) {
-  std::string code(ReplaceAll(CB_INTERFACE_CONTEXT_BASE, {
-      { "<PREFIX>", GetHandlePrefix() },
-      { "<NAME>", iface.GetID() }
-  }));
-
-  stream << SmartIndent(code);
-}
-
-// @see #CB_INTERFACE_REMOTE_EXCEPTION_BASE
-void CStubHeaderGenerator::GenInterfaceRemoteExceptionBase(
-    std::ofstream& stream, const Interface& iface) {
-  ReplaceAll(CB_INTERFACE_REMOTE_EXCEPTION_BASE)
+                                                   const Interface& iface) {
+  ReplaceAll(CB_INTERFACE_CONTEXT_BASE)
       .Change("<PREFIX>", GetHandlePrefix())
       .Change("<NAME>", iface.GetID())
       .Transform([&](std::string code) { return SmartIndent(code); })
@@ -194,14 +169,14 @@ void CStubHeaderGenerator::GenInterfaceRemoteExceptionBase(
 }
 
 std::string CStubHeaderGenerator::GenDelegateParams(const Interface& iface,
-    const Declaration& decl) {
+                                                    const Declaration& decl) {
   std::string params;
   for (const auto& p : decl.GetParameters()) {
     params += ", ";
     auto& param_type = p->GetParameterType();
     auto& type = param_type.GetBaseType();
-    params += GetParamTypeString(param_type.GetDirection(), type, iface) +
-        p->GetID();
+    params +=
+        GetParamTypeString(param_type.GetDirection(), type, iface) + p->GetID();
   }
 
   return params;
@@ -209,48 +184,44 @@ std::string CStubHeaderGenerator::GenDelegateParams(const Interface& iface,
 
 // @see #CB_INTERFACE_DELEGATE_BASE
 void CStubHeaderGenerator::GenInterfaceDelegateBase(std::ofstream& stream,
-    const Interface& iface, const Declaration& decl) {
-  std::string code(ReplaceAll(CB_INTERFACE_DELEGATE_BASE, {
-      { "<PREFIX>", GetHandlePrefix() },
-      { "<NAME>", iface.GetID() },
-      { "<DELEGATE_NAME>", decl.GetID() },
-      { "<DELEGATE_PARAMS>", GenDelegateParams(iface, decl) }
-  }));
-
-  stream << SmartIndent(code);
+                                                    const Interface& iface,
+                                                    const Declaration& decl) {
+  ReplaceAll(CB_INTERFACE_DELEGATE_BASE)
+      .Change("<PREFIX>", GetHandlePrefix())
+      .Change("<NAME>", iface.GetID())
+      .Change("<DELEGATE_NAME>", decl.GetID())
+      .Change("<DELEGATE_PARAMS>", GenDelegateParams(iface, decl))
+      .Transform([&](std::string code) { return SmartIndent(code); })
+      .Out(stream);
 }
 
 // @see #CB_INTERFACE_METHOD_CALLBACK_DECL
-std::string CStubHeaderGenerator::GenMethodCallbackDecls(const Interface& iface) {
-  std::string method_callback_decls;
+std::string CStubHeaderGenerator::GenMethodCallbackDecls(
+    const Interface& iface) {
+  std::string code;
   for (const auto& d : iface.GetDeclarations()) {
     if (d->GetMethodType() == Declaration::MethodType::DELEGATE)
       continue;
 
-    std::string method_callback_decl(ReplaceAll(
-        CB_INTERFACE_METHOD_CALLBACK_DECL, {
-            { "<PREFIX>", GetHandlePrefix() },
-            { "<NAME>", iface.GetID() },
-            { "<METHOD_NAME>", d->GetID() }
-        }));
-
-    method_callback_decl = RemoveLine(method_callback_decl);
-    method_callback_decls += RemoveLine(method_callback_decl, 2);
+    std::string callback_code(ReplaceAll(CB_INTERFACE_METHOD_CALLBACK_DECL)
+                                  .Change("<PREFIX>", GetHandlePrefix())
+                                  .Change("<NAME>", iface.GetID())
+                                  .Change("<METHOD_NAME>", d->GetID()));
+    code += RemoveLine(callback_code, 3);
   }
 
-  return method_callback_decls;
+  return code;
 }
 
 // @see #CB_INTERFACE_BASE
 void CStubHeaderGenerator::GenInterfaceBase(std::ofstream& stream,
-    const Interface& iface) {
-  std::string code(ReplaceAll(CB_INTERFACE_BASE, {
-      { "<PREFIX>", GetHandlePrefix() },
-      { "<NAME>", iface.GetID() },
-      { "<METHOD_CALLBACK_DECLS>", GenMethodCallbackDecls(iface) }
-  }));
-
-  stream << SmartIndent(code);
+                                            const Interface& iface) {
+  ReplaceAll(CB_INTERFACE_BASE)
+      .Change("<PREFIX>", GetHandlePrefix())
+      .Change("<NAME>", iface.GetID())
+      .Change("<METHOD_CALLBACK_DECLS>", GenMethodCallbackDecls(iface))
+      .Transform([&](std::string code) { return SmartIndent(code); })
+      .Out(stream);
 }
 
 }  // namespace version2
index e464947cda4b7458856c81fb0ebeaf9c0fa09955..05b57c04f5de36021ab9b670e964d6a667785c20 100644 (file)
@@ -14,8 +14,8 @@
  * limitations under the License.
  */
 
-#ifndef IDLC_C_GEN_C_STUB_HEADER_GENERATOR_HH_
-#define IDLC_C_GEN_C_STUB_HEADER_GENERATOR_HH_
+#ifndef IDLC_GEN_VERSION2_C_STUB_HEADER_GENERATOR_HH_
+#define IDLC_GEN_VERSION2_C_STUB_HEADER_GENERATOR_HH_
 
 #include <memory>
 #include <string>
@@ -36,28 +36,25 @@ class CStubHeaderGenerator : public CHeaderGeneratorBase {
  private:
   void GenInterfaceHandles(std::ofstream& stream);
   void GenInterfaceContextHandle(std::ofstream& stream, const Interface& iface);
-  void GenInterfaceRemoteExceptionHandle(std::ofstream& stream,
-      const Interface& iface);
   void GenInterfaceDelegateHandle(std::ofstream& stream, const Interface& iface,
-      const Declaration& decl);
+                                  const Declaration& decl);
 
   void GenInterfaceCallbacks(std::ofstream& stream);
   void GenInterfaceCallbackBase(std::ofstream& stream, const Interface& iface);
   void GenInterfaceMethodCallbackBase(std::ofstream& stream,
-      const Interface& iface, const Declaration& decl);
+                                      const Interface& iface,
+                                      const Declaration& decl);
 
   void GenInterfaces(std::ofstream& stream);
   void GenInterface(std::ofstream& stream, const Interface& iface);
 
   void GenInterfaceContextBase(std::ofstream& stream, const Interface& iface);
-  void GenInterfaceRemoteExceptionBase(std::ofstream& stream,
-      const Interface& iface);
   void GenInterfaceDelegateBase(std::ofstream& stream, const Interface& iface,
-      const Declaration& decl);
+                                const Declaration& decl);
   void GenInterfaceBase(std::ofstream& stream, const Interface& iface);
 
   std::string GenDelegateParams(const Interface& iface,
-      const Declaration& decl);
+                                const Declaration& decl);
   std::string GenMethodParams(const Interface& iface, const Declaration& decl);
   std::string GenMethodCallbackDecls(const Interface& iface);
 };
@@ -65,4 +62,4 @@ class CStubHeaderGenerator : public CHeaderGeneratorBase {
 }  // namespace version2
 }  // namespace tidl
 
-#endif  // IDLC_C_GEN_C_STUB_HEADER_GENERATOR_HH_
+#endif  // IDLC_GEN_VERSION2_C_STUB_HEADER_GENERATOR_HH_
index 1893c52e2e97e8e65d4ccfce9366471fd1243fe3..e98f2fcf813d8777cba5dbb2c055620fec293fcc 100644 (file)
  * limitations under the License.
  */
 
-#ifndef IDLC_C_GEN_C_STUB_HEADER_GENERATOR_CB_H_
-#define IDLC_C_GEN_C_STUB_HEADER_GENERATOR_CB_H_
+#ifndef IDLC_GEN_VERSION2_C_STUB_HEADER_GENERATOR_CB_HH_
+#define IDLC_GEN_VERSION2_C_STUB_HEADER_GENERATOR_CB_HH_
+
+namespace tidl {
+namespace version2 {
 
 /**
  * <PREFIX> The prefix of the interface.
@@ -365,91 +368,7 @@ R"__c_cb(
 <PREFIX>_<NAME>_<METHOD_NAME>_cb <METHOD_NAME>;  /**< This callback function is invoked when the <METHOD_NAME> request is delivered. */
 )__c_cb";
 
-/**
- * <PREFIX> The prefix of the interface.
- * <NAME> The name of the interface.
- */
-constexpr const char CB_INTERFACE_REMOTE_EXCEPTION_HANDLE[] =
-R"__c_cb(
-/**
- * @brief The <PREFIX> <NAME> remote exception handle.
- */
-typedef struct <PREFIX>_<NAME>_remote_exception_s *<PREFIX>_<NAME>_remote_exception_h;
-)__c_cb";
-
-/**
- * <PREFIX> The prefix of the interface.
- * <NAME> The name of the interface.
- */
-constexpr const char CB_INTERFACE_REMOTE_EXCEPTION_BASE[] =
-R"__c_cb(
-/**
- * @brief Creates the <PREFIX> <NAME> remote exception handle.
- *
- * @remarks The @c h handle should be released if it's no longer needed.
- * @param[out] h The <PREFIX> <NAME> remote exception handle.
- * @return @c 0 on success,
- *         otherwise a negative error value
- * @retval #RPC_PORT_ERROR_NONE Successful
- * @retval #RPC_PORT_ERROR_INVALID_PARAMETER Invalid parameter
- * @retval #RPC_PORT_ERROR_OUT_OF_MEMORY Out of memory
- * @see <PREFIX>_<NAME>_remote_exception_throw()
- * @see <PREFIX>_<NAME>_remote_exception_destroy()
- */
-int <PREFIX>_<NAME>_remote_exception_create(<PREFIX>_<NAME>_remote_exception_h *h);
-
-/**
- * @brief Sets the cause of the exception.
- *
- * @param[in] h The <PREFIX> <NAME> remote exception handle
- * @param[in] cause The cause of the exception
- * @return @c 0 on success,
- *         otherwise a negative error value
- * @retval #RPC_PORT_ERROR_NONE Successful
- * @retval #RPC_PORT_ERROR_INVALID_PARAMETER Invalid parameter
- */
-int <PREFIX>_<NAME>_remote_exception_set_cause(<PREFIX>_<NAME>_remote_exception_h h, int cause);
-
-/**
- * @brief Sets the detail message of the exception.
- *
- * @param[in] h The <PREFIX> <NAME> remote exception handle
- * @param[in] message The detail message of the exception
- * @return @c 0 on success,
- *         otherwise a negative error value
- * @retval #RPC_PORT_ERROR_NONE Successful
- * @retval #RPC_PORT_ERROR_INVALID_PARAMETER Invalid parameter
- * @retval #RPC_PORT_ERROR_OUT_OF_MEMORY Out of memory
- */
-int <PREFIX>_<NAME>_remote_exception_set_message(<PREFIX>_<NAME>_remote_exception_h h, const char *message);
-
-/**
- * @brief Throws the exception to the client.
- * @details This function throws the exception to the client in the callback function.
- *          While calling the registered callback function related the method call, this function should be called
- *          if you want to send the remote exception to the client.
- *          If this function is called outside of the registered callback function, it's meaningless.
- *          The callback function is not returned by calling this function.
- *
- * @param[in] h The <PREFIX> <NAME> remote exception handle
- * @return @c 0 on success,
- *         otherwise a negative error value
- * @retval #RPC_PORT_ERROR_NONE Successful
- * @retval #RPC_PORT_ERROR_INVALID_PARAMETER Invalid parameter
- * @retval #RPC_PORT_ERROR_OUT_OF_MEMORY Out of memory
- */
-int <PREFIX>_<NAME>_remote_exception_throw(<PREFIX>_<NAME>_remote_exception_h h);
-
-/**
- * @brief Destroys the <PREFIX> <NAME> remote exception handle.
- *
- * @param[in] h The <PREFIX> <NAME> remote exception handle
- * @return @c 0 on success,
- *         otherwise a negative error value
- * @retval #RPC_PORT_ERROR_NONE Successful
- * @retval #RPC_PORT_ERROR_INVALID_PARAMETER Invalid parameter
- */
-int <PREFIX>_<NAME>_remote_exception_destroy(<PREFIX>_<NAME>_remote_exception_h h);
-)__c_cb";
+}  // namespace version2
+}  // namespace tidl
 
-#endif  // IDLC_C_GEN_C_STUB_HEADER_GENERATOR_CB_H_
+#endif  // IDLC_GEN_VERSION2_C_STUB_HEADER_GENERATOR_CB_HH_