Add user data in delegate object 01/173601/1
authorJunghoon Park <jh9216.park@samsung.com>
Thu, 22 Mar 2018 11:16:53 +0000 (20:16 +0900)
committerJunghoon Park <jh9216.park@samsung.com>
Thu, 22 Mar 2018 11:16:53 +0000 (20:16 +0900)
Change-Id: I668baf7cf28b49c6dc3fc887a52b3d5b83f56495
Signed-off-by: Junghoon Park <jh9216.park@samsung.com>
idlc/c_gen/c_proxy_body_gen.cc
idlc/c_gen/c_proxy_body_gen_cb.h
idlc/c_gen/c_proxy_header_gen.cc
idlc/c_gen/c_proxy_header_gen_cb.h

index c53b9f0..d7299fb 100644 (file)
@@ -177,13 +177,10 @@ void CProxyBodyGen::GenInterfaceDelegatorInvoker(
         },
         [&]()->std::string {
           std::string str;
-          str += "handle->callback(";
-          int cnt = 1;
+          str += "handle->callback(handle->user_data";
           for (auto& i: decl.GetParameters().GetParams()) {
-            if (cnt != 1)
-              str += ", ";
+            str += ", ";
             str += i->GetID();
-            cnt++;
           }
           str += ");" + NLine(1);
           return str;
@@ -303,9 +300,9 @@ void CProxyBodyGen::GenInterfaceMethods(std::ofstream& stream,
             for (auto& p : i->GetParameters().GetParams()) {
               str += ", ";
               if (TypeIsDelegator(inf, p->GetParameterType().GetBaseType())) {
-                str += inf.GetID() + "_" +
+                str += "rpc_port_" + inf.GetID() + "_" +
                     p->GetParameterType().GetBaseType().ToString() +
-                    " " + p->GetID();
+                    "_h " + p->GetID();
               } else {
                 str += GetParamTypeString(p->GetParameterType().GetDirection(),
                     p->GetParameterType().GetBaseType()) + p->GetID();
index 1abf199..08e3325 100644 (file)
@@ -33,6 +33,7 @@ struct ##_s {
     int id;
     int seq_id;
     ## callback;
+    void *user_data;
 };
 )__c_cb";
 
@@ -70,7 +71,7 @@ static void __##_from(rpc_port_parcel_h parcel, void *data)
 
 const char CB_DELEGATE_CTOR[] =
 R"__c_cb(
-static struct ##_s *__create_##(## callback)
+rpc_port_##_h rpc_port_##_create(## callback, void *user_data)
 {
     struct ##_s *handle;
     static int seq_num;
@@ -86,6 +87,7 @@ static struct ##_s *__create_##(## callback)
     handle->id = $$_DELEGATE_$$;
     handle->seq_id = seq_num++;
     handle->callback = callback;
+    handle->user_data = user_data;
 
     return handle;
 }
@@ -375,11 +377,7 @@ int rpc_port_proxy_##_disconnect(rpc_port_proxy_##_h h)
 const char CB_DELEGATE_BLOCK[] =
 R"__c_cb(
 do {
-    struct ##_s *handle;
-
-    handle = __create_##($$);
-    if (!handle)
-        break;
+    struct ##_s *handle = $$;
 
     rpc_port_parcel_write(parcel, &handle->parcelable, handle);
     h->delegates = g_list_append(h->delegates, handle);
index caa7eb8..7da766b 100644 (file)
@@ -69,6 +69,16 @@ void CProxyHeaderGen::GenInterfaceDelegators(std::ofstream& stream,
 void CProxyHeaderGen::GenInterfaceDelegator(std::ofstream& stream,
                                             const std::string& id,
                                             const Declaration& decl) {
+  const char handle[] = "typedef struct $$_s *rpc_port_$$_h;";
+
+  stream << GenTemplateString(handle,
+      [&]()->std::string {
+        return id + "_" + decl.GetID();
+      },
+      [&]()->std::string {
+        return id + "_" + decl.GetID();
+      });
+
   stream << GenTemplateString(CB_INTERFACE_DELEGATOR,
       [&]()->std::string {
         return GetReturnTypeString(decl.GetType());
@@ -78,17 +88,17 @@ void CProxyHeaderGen::GenInterfaceDelegator(std::ofstream& stream,
       },
       [&]()->std::string {
         std::string str;
-        int cnt = 1;
+        str += "void *user_data";
         for (auto& p : decl.GetParameters().GetParams()) {
-          if (cnt != 1)
-            str += ", ";
+          str += ", ";
           str += GetParamTypeString(p->GetParameterType().GetDirection(),
               p->GetParameterType().GetBaseType()) + p->GetID();
-          cnt++;
         }
         return str;
       }
       );
+
+  stream << ReplaceAll(CB_DELEGATE_CTOR, "##", id + "_" + decl.GetID());
 }
 
 void CProxyHeaderGen::GenInterfaceDeclaration(std::ofstream& stream,
@@ -114,9 +124,9 @@ void CProxyHeaderGen::GenInterfaceMethods(std::ofstream& stream,
           for (auto& p : i->GetParameters().GetParams()) {
             str += ", ";
             if (TypeIsDelegator(inf, p->GetParameterType().GetBaseType())) {
-              str += inf.GetID() + "_" +
+              str += "rpc_port_" + inf.GetID() + "_" +
                   p->GetParameterType().GetBaseType().ToString() +
-                  " " + p->GetID();
+                  "_h " + p->GetID();
             } else {
               str += GetParamTypeString(p->GetParameterType().GetDirection(),
                   p->GetParameterType().GetBaseType()) + p->GetID();
index 8569328..7306c2f 100644 (file)
@@ -46,3 +46,8 @@ const char CB_INTERFACE_DELEGATOR[] =
 R"__c_cb(
 typedef $$(*$$)($$);
 )__c_cb";
+
+const char CB_DELEGATE_CTOR[] =
+R"__c_cb(
+rpc_port_##_h rpc_port_##_create(## callback, void *user_data);
+)__c_cb";