Modify C proxy generator 43/181943/4
authorHwankyu Jhun <h.jhun@samsung.com>
Tue, 19 Jun 2018 05:52:18 +0000 (14:52 +0900)
committerHwanKyu Jhun <h.jhun@samsung.com>
Mon, 25 Jun 2018 05:32:48 +0000 (05:32 +0000)
To make a reusable function, the functions are separated.

Change-Id: I0cc7252a84bd2e4316ddc30835088fb174c5cee3
Signed-off-by: Hwankyu Jhun <h.jhun@samsung.com>
README.md
idlc/c_gen/c_proxy_body_gen.cc
idlc/c_gen/c_proxy_body_gen.h
idlc/c_gen/c_proxy_body_gen_cb.h
idlc/c_gen/c_proxy_header_gen.cc
idlc/c_gen/c_proxy_header_gen.h
idlc/c_gen/c_proxy_header_gen_cb.h

index ac3e03f..07a3df4 100755 (executable)
--- a/README.md
+++ b/README.md
@@ -247,11 +247,14 @@ typedef struct {
        void (*rejected)(rpc_port_proxy_Runnable_h h, void* user_data); // Rejected event callback
 } rpc_port_proxy_Runnable_callback_s;
 
-//  Function for connecting service app
-int rpc_port_proxy_Runnable_connect(const char* stub_appid,rpc_port_proxy_Runnable_callback_s* callback, void* user_data, rpc_port_proxy_Runnable_h* h);
+//  Function for creating Runnable proxy handle
+int rpc_port_proxy_Runnable_create(const char* stub_appid,rpc_port_proxy_Runnable_callback_s* callback, void* user_data, rpc_port_proxy_Runnable_h* h);
 
-//  Function for disconnecting service app
-int rpc_port_proxy_Runnable_disconnect(rpc_port_proxy_Runnable_h h);
+//  Function for connecting to service app
+int rpc_port_proxy_Runnable_connect(rpc_port_proxy_Runnable_h h);
+
+//  Function for destroying Runnable proxy handle
+int rpc_port_proxy_Runnable_destroy(rpc_port_proxy_Runnable_h h);
 
 // Function from TIDL
 int rpc_port_proxy_Runnable_invoke_Run(rpc_port_proxy_Runnable_h h, rpc_port_Foo_h foo);
index 4b78826..0f9bdea 100644 (file)
@@ -70,10 +70,11 @@ void CProxyBodyGen::GenInterface(std::ofstream& stream, const Interface& inf) {
   GenInterfaceOnRejectedEventCB(stream, inf);
   GenInterfaceOnReceivedEventCB(stream, inf);
   GenInterfaceMethods(stream, inf);
-  GenInterfaceConstructor(stream, inf);
-  GenInterfaceDestructor(stream, inf);
+  GenInterfaceHandleCtor(stream, inf);
+  GenInterfaceHandleDtor(stream, inf);
+  GenInterfaceCtor(stream, inf);
   GenInterfaceConnect(stream, inf);
-  GenInterfaceDisconnect(stream, inf);
+  GenInterfaceDtor(stream, inf);
 }
 
 void CProxyBodyGen::GenInterfaceDeclaration(std::ofstream& stream,
@@ -365,15 +366,21 @@ void CProxyBodyGen::GenInterfaceMethods(std::ofstream& stream,
   }
 }
 
-void CProxyBodyGen::GenInterfaceConstructor(std::ofstream& stream,
-                                            const Interface& inf) {
-  stream << SmartIndent(ReplaceAll(CB_INTERFACE_CTOR, "##",
+void CProxyBodyGen::GenInterfaceHandleCtor(std::ofstream& stream,
+                                           const Interface& inf) {
+  stream << SmartIndent(ReplaceAll(CB_INTERFACE_HANDLE_CTOR, "##",
       GetInterfaceIdWithNamespace(inf)));
 }
 
-void CProxyBodyGen::GenInterfaceDestructor(std::ofstream& stream,
+void CProxyBodyGen::GenInterfaceHandleDtor(std::ofstream& stream,
                                            const Interface& inf) {
-  stream << SmartIndent(ReplaceAll(CB_INTERFACE_DTOR, "##",
+  stream << SmartIndent(ReplaceAll(CB_INTERFACE_HANDLE_DTOR, "##",
+      GetInterfaceIdWithNamespace(inf)));
+}
+
+void CProxyBodyGen::GenInterfaceCtor(std::ofstream& stream,
+                                        const Interface& inf) {
+  stream << SmartIndent(ReplaceAll(CB_INTERFACE_CTOR, "##",
       GetInterfaceIdWithNamespace(inf)));
 }
 
@@ -383,9 +390,9 @@ void CProxyBodyGen::GenInterfaceConnect(std::ofstream& stream,
       GetInterfaceIdWithNamespace(inf)));
 }
 
-void CProxyBodyGen::GenInterfaceDisconnect(std::ofstream& stream,
+void CProxyBodyGen::GenInterfaceDtor(std::ofstream& stream,
                                            const Interface& inf) {
-  stream << SmartIndent(ReplaceAll(CB_INTERFACE_DISCONNECT, "##",
+  stream << SmartIndent(ReplaceAll(CB_INTERFACE_DTOR, "##",
       GetInterfaceIdWithNamespace(inf)));
 }
 
index a37d4fd..341b112 100644 (file)
@@ -54,10 +54,11 @@ class CProxyBodyGen : public CBodyGeneratorBase {
   void GenInterfaceOnReceivedEventCB(std::ofstream& stream,
                                      const Interface& inf);
   void GenInterfaceMethods(std::ofstream& stream, const Interface& inf);
-  void GenInterfaceConstructor(std::ofstream& stream, const Interface& inf);
-  void GenInterfaceDestructor(std::ofstream& stream, const Interface& inf);
+  void GenInterfaceHandleCtor(std::ofstream& stream, const Interface& inf);
+  void GenInterfaceHandleDtor(std::ofstream& stream, const Interface& inf);
+  void GenInterfaceCtor(std::ofstream& stream, const Interface& inf);
   void GenInterfaceConnect(std::ofstream& stream, const Interface& inf);
-  void GenInterfaceDisconnect(std::ofstream& stream, const Interface& inf);
+  void GenInterfaceDtor(std::ofstream& stream, const Interface& inf);
 
  private:
   void GenInterfaceDelegator(std::ofstream& stream, const std::string& id,
index fd75454..2499fa7 100644 (file)
@@ -294,7 +294,7 @@ $$
 }
 )__c_cb";
 
-const char CB_INTERFACE_CTOR[] =
+const char CB_INTERFACE_HANDLE_CTOR[] =
 R"__c_cb(
 static struct ##_s *__create_##(const char *stub_appid, rpc_port_proxy_##_callback_s *callback, void *user_data)
 {
@@ -330,7 +330,7 @@ static struct ##_s *__create_##(const char *stub_appid, rpc_port_proxy_##_callba
 }
 )__c_cb";
 
-const char CB_INTERFACE_DTOR[] =
+const char CB_INTERFACE_HANDLE_DTOR[] =
 R"__c_cb(
 static void __destroy_##(struct ##_s *h)
 {
@@ -352,9 +352,9 @@ static void __destroy_##(struct ##_s *h)
 }
 )__c_cb";
 
-const char CB_INTERFACE_CONNECT[] =
+const char CB_INTERFACE_CTOR[] =
 R"__c_cb(
-int rpc_port_proxy_##_connect(const char *stub_appid, rpc_port_proxy_##_callback_s *callback, void *user_data, rpc_port_proxy_##_h *h)
+int rpc_port_proxy_##_create(const char *stub_appid, rpc_port_proxy_##_callback_s *callback, void *user_data, rpc_port_proxy_##_h *h)
 {
     struct ##_s *handle;
     int r;
@@ -396,22 +396,36 @@ int rpc_port_proxy_##_connect(const char *stub_appid, rpc_port_proxy_##_callback
         return r;
     }
 
-    r = rpc_port_proxy_connect(handle->proxy, stub_appid, "##");
-    if (r != 0) {
-        _E("Failed to connect ##(%s)", stub_appid);
-        __destroy_##(handle);
-        return r;
+    *h = handle;
+
+    return 0;
+}
+)__c_cb";
+
+const char CB_INTERFACE_CONNECT[] =
+R"__c_cb(
+int rpc_port_proxy_##_connect(rpc_port_proxy_##_h h)
+{
+    int r;
+
+    if (!h || !h->proxy) {
+        _E("Invalid parameter");
+       return -1;
     }
 
-    *h = handle;
+    r = rpc_port_proxy_connect(h->proxy, h->stub_appid, "##");
+    if (r != 0) {
+        _E("Failed to connect ##(%s)", h->stub_appid);
+       return r;
+    }
 
     return 0;
 }
 )__c_cb";
 
-const char CB_INTERFACE_DISCONNECT[] =
+const char CB_INTERFACE_DTOR[] =
 R"__c_cb(
-int rpc_port_proxy_##_disconnect(rpc_port_proxy_##_h h)
+int rpc_port_proxy_##_destroy(rpc_port_proxy_##_h h)
 {
     if (!h) {
         _E("Invalid parameter");
index abedb2f..922de75 100644 (file)
@@ -52,8 +52,9 @@ void CProxyHeaderGen::GenInterface(std::ofstream& stream,
                                    const Interface& inf) {
   GenInterfaceDeclaration(stream, inf);
   GenInterfaceDelegators(stream, inf);
+  GenInterfaceCtor(stream, inf);
   GenInterfaceConnect(stream, inf);
-  GenInterfaceDisconnect(stream, inf);
+  GenInterfaceDtor(stream, inf);
   GenInterfaceMethods(stream, inf);
 }
 
@@ -145,15 +146,21 @@ void CProxyHeaderGen::GenInterfaceMethods(std::ofstream& stream,
   }
 }
 
+void CProxyHeaderGen::GenInterfaceCtor(std::ofstream& stream,
+                                          const Interface& inf) {
+  stream << ReplaceAll(CB_INTERFACE_CTOR, "##",
+      GetInterfaceIdWithNamespace(inf));
+}
+
 void CProxyHeaderGen::GenInterfaceConnect(std::ofstream& stream,
                                           const Interface& inf) {
   stream << ReplaceAll(CB_INTERFACE_CONNECT, "##",
       GetInterfaceIdWithNamespace(inf));
 }
 
-void CProxyHeaderGen::GenInterfaceDisconnect(std::ofstream& stream,
+void CProxyHeaderGen::GenInterfaceDtor(std::ofstream& stream,
                                              const Interface& inf) {
-  stream << ReplaceAll(CB_INTERFACE_DISCONNECT, "##",
+  stream << ReplaceAll(CB_INTERFACE_DTOR, "##",
       GetInterfaceIdWithNamespace(inf));
 }
 
index 5957e96..04f3abf 100644 (file)
@@ -40,8 +40,9 @@ class CProxyHeaderGen : public CHeaderGeneratorBase {
   void GenInterfaceDeclaration(std::ofstream& stream, const Interface& inf);
   void GenInterfaceDelegators(std::ofstream& stream, const Interface& inf);
   void GenInterfaceMethods(std::ofstream& stream, const Interface& inf);
+  void GenInterfaceCtor(std::ofstream& stream, const Interface& inf);
   void GenInterfaceConnect(std::ofstream& stream, const Interface& inf);
-  void GenInterfaceDisconnect(std::ofstream& stream, const Interface& inf);
+  void GenInterfaceDtor(std::ofstream& stream, const Interface& inf);
 
  private:
   void GenInterfaceDelegator(std::ofstream& stream, const std::string& id,
index 631b808..0fd524b 100644 (file)
@@ -28,16 +28,21 @@ typedef struct {
 } rpc_port_proxy_##_callback_s;
 )__c_cb";
 
-const char CB_INTERFACE_CONNECT[] =
+const char CB_INTERFACE_CTOR[] =
 R"__c_cb(
-int rpc_port_proxy_##_connect(const char *stub_appid,
+int rpc_port_proxy_##_create(const char *stub_appid,
         rpc_port_proxy_##_callback_s *callback, void *user_data,
         rpc_port_proxy_##_h *h);
 )__c_cb";
 
-const char CB_INTERFACE_DISCONNECT[] =
+const char CB_INTERFACE_CONNECT[] =
+R"__c_cb(
+int rpc_port_proxy_##_connect(rpc_port_proxy_##_h h);
+)__c_cb";
+
+const char CB_INTERFACE_DTOR[] =
 R"__c_cb(
-int rpc_port_proxy_##_disconnect(rpc_port_proxy_##_h h);
+int rpc_port_proxy_##_destroy(rpc_port_proxy_##_h h);
 )__c_cb";
 
 const char CB_INTERFACE_METHODS[] =