From f3df8ec971455274d044fa1c70fb5d0177cbcc46 Mon Sep 17 00:00:00 2001 From: Hwankyu Jhun Date: Thu, 13 Aug 2020 15:22:17 +0900 Subject: [PATCH] Support synchronous connection requests Change-Id: I03d0d7435c0f019864b57e44eb74f81a184c0bbf Signed-off-by: Hwankyu Jhun --- idlc/gen/c_proxy_body_gen.cc | 7 +++++++ idlc/gen/c_proxy_body_gen.h | 1 + idlc/gen/c_proxy_body_gen_cb.h | 21 +++++++++++++++++++++ idlc/gen/c_proxy_header_gen.cc | 7 +++++++ idlc/gen/c_proxy_header_gen.h | 1 + idlc/gen/c_proxy_header_gen_cb.h | 5 +++++ idlc/gen/cpp_proxy_body_gen_cb.h | 8 ++++++-- idlc/gen/cpp_proxy_header_gen_cb.h | 3 ++- idlc/gen/cs_proxy_gen.cc | 3 +++ idlc/gen/cs_proxy_gen_cb.h | 20 ++++++++++++++++++++ 10 files changed, 73 insertions(+), 3 deletions(-) diff --git a/idlc/gen/c_proxy_body_gen.cc b/idlc/gen/c_proxy_body_gen.cc index 54df1c8..3e27f6c 100644 --- a/idlc/gen/c_proxy_body_gen.cc +++ b/idlc/gen/c_proxy_body_gen.cc @@ -76,6 +76,7 @@ void CProxyBodyGen::GenInterface(std::ofstream& stream, const Interface& inf) { GenInterfaceCtor(stream, inf); GenInterfaceConnect(stream, inf); GenInterfaceDtor(stream, inf); + GenInterfaceConnectSync(stream, inf); } void CProxyBodyGen::GenInterfaceFileSharing(std::ofstream& stream, @@ -449,6 +450,12 @@ void CProxyBodyGen::GenInterfaceDtor(std::ofstream& stream, GetInterfaceIdWithNamespace(inf))); } +void CProxyBodyGen::GenInterfaceConnectSync(std::ofstream& stream, + const Interface& inf) { + stream << SmartIndent(ReplaceAll(CB_INTERFACE_CONNECT_SYNC, "##", + GetInterfaceIdWithNamespace(inf))); +} + std::string CProxyBodyGen::GetMethodWriteString(const Interface& inf, const Declaration& decl) { const char setter[] = "$$($$, $$);\n"; diff --git a/idlc/gen/c_proxy_body_gen.h b/idlc/gen/c_proxy_body_gen.h index 815f418..a89c602 100644 --- a/idlc/gen/c_proxy_body_gen.h +++ b/idlc/gen/c_proxy_body_gen.h @@ -60,6 +60,7 @@ class CProxyBodyGen : public CBodyGeneratorBase { void GenInterfaceCtor(std::ofstream& stream, const Interface& inf); void GenInterfaceConnect(std::ofstream& stream, const Interface& inf); void GenInterfaceDtor(std::ofstream& stream, const Interface& inf); + void GenInterfaceConnectSync(std::ofstream& stream, const Interface& inf); private: void GenInterfaceDelegator(std::ofstream& stream, const std::string& id, diff --git a/idlc/gen/c_proxy_body_gen_cb.h b/idlc/gen/c_proxy_body_gen_cb.h index a8717df..0757b2d 100644 --- a/idlc/gen/c_proxy_body_gen_cb.h +++ b/idlc/gen/c_proxy_body_gen_cb.h @@ -560,4 +560,25 @@ R"__c_cb( } )__c_cb"; +const char CB_INTERFACE_CONNECT_SYNC[] = +R"__c_cb( +int rpc_port_proxy_##_connect_sync(rpc_port_proxy_##_h h) +{ + int r; + + if (!h || !h->proxy) { + _E("Invalid parameter"); + return -1; + } + + r = rpc_port_proxy_connect_sync(h->proxy, h->stub_appid, "##"); + if (r != 0) { + _E("Failed to connect sync ##(%s)", h->stub_appid); + return r; + } + + return 0; +} +)__c_cb"; + #endif // IDLC_C_GEN_C_PROXY_BODY_GEN_CB_H_ diff --git a/idlc/gen/c_proxy_header_gen.cc b/idlc/gen/c_proxy_header_gen.cc index 64bfab4..b5bca94 100644 --- a/idlc/gen/c_proxy_header_gen.cc +++ b/idlc/gen/c_proxy_header_gen.cc @@ -56,6 +56,7 @@ void CProxyHeaderGen::GenInterface(std::ofstream& stream, GenInterfaceConnect(stream, inf); GenInterfaceDtor(stream, inf); GenInterfaceMethods(stream, inf); + GenInterfaceConnectSync(stream, inf); } void CProxyHeaderGen::GenInterfaceDelegators(std::ofstream& stream, @@ -165,4 +166,10 @@ void CProxyHeaderGen::GenInterfaceDtor(std::ofstream& stream, GetInterfaceIdWithNamespace(inf)); } +void CProxyHeaderGen::GenInterfaceConnectSync(std::ofstream& stream, + const Interface& inf) { + stream << ReplaceAll(CB_INTERFACE_CONNECT_SYNC, "##", + GetInterfaceIdWithNamespace(inf)); +} + } // namespace tidl diff --git a/idlc/gen/c_proxy_header_gen.h b/idlc/gen/c_proxy_header_gen.h index 800d67e..8dfa891 100644 --- a/idlc/gen/c_proxy_header_gen.h +++ b/idlc/gen/c_proxy_header_gen.h @@ -43,6 +43,7 @@ class CProxyHeaderGen : public CHeaderGeneratorBase { void GenInterfaceCtor(std::ofstream& stream, const Interface& inf); void GenInterfaceConnect(std::ofstream& stream, const Interface& inf); void GenInterfaceDtor(std::ofstream& stream, const Interface& inf); + void GenInterfaceConnectSync(std::ofstream& stream, const Interface& inf); private: void GenInterfaceDelegator(std::ofstream& stream, const std::string& id, diff --git a/idlc/gen/c_proxy_header_gen_cb.h b/idlc/gen/c_proxy_header_gen_cb.h index 4fe6daf..e6849e1 100644 --- a/idlc/gen/c_proxy_header_gen_cb.h +++ b/idlc/gen/c_proxy_header_gen_cb.h @@ -70,4 +70,9 @@ R"__c_cb( int rpc_port_##_destroy(rpc_port_##_h delegate); )__c_cb"; +const char CB_INTERFACE_CONNECT_SYNC[] = +R"__c_cb( +int rpc_port_proxy_##_connect_sync(rpc_port_proxy_##_h h); +)__c_cb"; + #endif // IDLC_C_GEN_C_PROXY_HEADER_GEN_CB_H_ diff --git a/idlc/gen/cpp_proxy_body_gen_cb.h b/idlc/gen/cpp_proxy_body_gen_cb.h index b5dbefd..83a9f08 100644 --- a/idlc/gen/cpp_proxy_body_gen_cb.h +++ b/idlc/gen/cpp_proxy_body_gen_cb.h @@ -64,8 +64,12 @@ R"__cpp_cb( const char CB_PROXY_HELPER_METHODS[] = R"__cpp_cb( -void ##::Connect() { - int ret = rpc_port_proxy_connect(proxy_, target_appid_.c_str(), "##"); +void ##::Connect(bool sync) { + int ret; + if (sync) + ret = rpc_port_proxy_connect_sync(proxy_, target_appid_.c_str(), "##"); + else + ret = rpc_port_proxy_connect(proxy_, target_appid_.c_str(), "##"); if (ret != RPC_PORT_ERROR_NONE) { _E("Failed to connect ##"); switch (ret) { diff --git a/idlc/gen/cpp_proxy_header_gen_cb.h b/idlc/gen/cpp_proxy_header_gen_cb.h index 0bf19ee..aea484f 100644 --- a/idlc/gen/cpp_proxy_header_gen_cb.h +++ b/idlc/gen/cpp_proxy_header_gen_cb.h @@ -64,6 +64,7 @@ R"__cpp_cb( /// /// http://tizen.org/privilege/appmanager.launch /// http://tizen.org/privilege/datasharing + // if true, connects to the service app synchornously /// /// Thrown when the appid to connect is invalid. /// @@ -74,7 +75,7 @@ R"__cpp_cb( /// Thrown when the permission is denied. /// /// If you want to use this method, you must add privileges. - void Connect(); + void Connect(bool sync = false); /// /// Disposes delegate objects in this interface diff --git a/idlc/gen/cs_proxy_gen.cc b/idlc/gen/cs_proxy_gen.cc index a45874a..3b96d03 100644 --- a/idlc/gen/cs_proxy_gen.cc +++ b/idlc/gen/cs_proxy_gen.cc @@ -94,6 +94,9 @@ void CsProxyGen::GenConnectMethod(std::ofstream& stream, GenTemplate(CB_CONNECT_METHOD, stream, [&]()->std::string { return iface.GetID(); + }, + [&]()->std::string { + return iface.GetID(); }); stream << NLine(1); } diff --git a/idlc/gen/cs_proxy_gen_cb.h b/idlc/gen/cs_proxy_gen_cb.h index f1e4743..21e25b9 100644 --- a/idlc/gen/cs_proxy_gen_cb.h +++ b/idlc/gen/cs_proxy_gen_cb.h @@ -125,6 +125,26 @@ R"__cs_cb( } /// + /// Connects to the service app synchronously. + /// + /// http://tizen.org/privilege/appmanager.launch + /// http://tizen.org/privilege/datasharing + /// + /// Thrown when the appid to connect is invalid. + /// + /// + /// Thrown when internal I/O error happen. + /// + /// + /// Thrown when the permission is denied. + /// + /// If you want to use this method, you must add privileges. + public void ConnectSync() + { + ConnectSync(_appId, "$$"); + } + + /// /// Disposes delegate objects in this interface /// /// The tag string from delegate object -- 2.7.4