From: Hwankyu Jhun Date: Tue, 19 Jun 2018 05:52:18 +0000 (+0900) Subject: Modify C proxy generator X-Git-Tag: accepted/tizen/4.0/unified/20180625.141457~1 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=9284203e1eb4c372eb426560fc85a8b1db4f4c35;p=platform%2Fcore%2Fappfw%2Ftidl.git Modify C proxy generator To make a reusable function, the functions are separated. Change-Id: I0cc7252a84bd2e4316ddc30835088fb174c5cee3 Signed-off-by: Hwankyu Jhun --- diff --git a/README.md b/README.md index ac3e03f..07a3df4 100755 --- 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); diff --git a/idlc/c_gen/c_proxy_body_gen.cc b/idlc/c_gen/c_proxy_body_gen.cc index 4b78826..0f9bdea 100644 --- a/idlc/c_gen/c_proxy_body_gen.cc +++ b/idlc/c_gen/c_proxy_body_gen.cc @@ -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))); } diff --git a/idlc/c_gen/c_proxy_body_gen.h b/idlc/c_gen/c_proxy_body_gen.h index a37d4fd..341b112 100644 --- a/idlc/c_gen/c_proxy_body_gen.h +++ b/idlc/c_gen/c_proxy_body_gen.h @@ -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, diff --git a/idlc/c_gen/c_proxy_body_gen_cb.h b/idlc/c_gen/c_proxy_body_gen_cb.h index fd75454..2499fa7 100644 --- a/idlc/c_gen/c_proxy_body_gen_cb.h +++ b/idlc/c_gen/c_proxy_body_gen_cb.h @@ -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"); diff --git a/idlc/c_gen/c_proxy_header_gen.cc b/idlc/c_gen/c_proxy_header_gen.cc index abedb2f..922de75 100644 --- a/idlc/c_gen/c_proxy_header_gen.cc +++ b/idlc/c_gen/c_proxy_header_gen.cc @@ -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)); } diff --git a/idlc/c_gen/c_proxy_header_gen.h b/idlc/c_gen/c_proxy_header_gen.h index 5957e96..04f3abf 100644 --- a/idlc/c_gen/c_proxy_header_gen.h +++ b/idlc/c_gen/c_proxy_header_gen.h @@ -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, diff --git a/idlc/c_gen/c_proxy_header_gen_cb.h b/idlc/c_gen/c_proxy_header_gen_cb.h index 631b808..0fd524b 100644 --- a/idlc/c_gen/c_proxy_header_gen_cb.h +++ b/idlc/c_gen/c_proxy_header_gen_cb.h @@ -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[] =