From: Changgyu Choi Date: Thu, 5 Aug 2021 04:37:59 +0000 (+0900) Subject: Add disconnect API X-Git-Tag: submit/tizen/20210813.063429~1 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=006b4211ee45a008078b7e58cd7f2b66e239b468;p=platform%2Fcore%2Fappfw%2Frpc-port.git Add disconnect API Adds: - rpc_port_disconnect() Change-Id: I189f0ef05a0ae63c9f8258f17e741eeba8fc96a2 Signed-off-by: Changgyu Choi --- diff --git a/include/rpc-port.h b/include/rpc-port.h index 86b175d..bde887d 100644 --- a/include/rpc-port.h +++ b/include/rpc-port.h @@ -536,6 +536,17 @@ int rpc_port_set_private_sharing(rpc_port_h port, const char *path); int rpc_port_unset_private_sharing(rpc_port_h port); /** + * @brief Disconnects the port. + * @since_tizen 6.5 + * @param[in] port The rpc port 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 rpc_port_disconnect(rpc_port_h h); + +/** * @} */ diff --git a/src/rpc-port.cc b/src/rpc-port.cc index 310cfbc..2ee572d 100644 --- a/src/rpc-port.cc +++ b/src/rpc-port.cc @@ -544,3 +544,13 @@ RPC_API int rpc_port_unset_private_sharing(rpc_port_h h) { return port->UnsetPrivateSharing(); } + +RPC_API int rpc_port_disconnect(rpc_port_h h) { + if (h == nullptr) + return RPC_PORT_ERROR_INVALID_PARAMETER; + + auto port = static_cast(h); + port->Disconnect(); + + return RPC_PORT_ERROR_NONE; +} diff --git a/test/unit_tests/rpc_port_test.cc b/test/unit_tests/rpc_port_test.cc index 7163202..e738121 100644 --- a/test/unit_tests/rpc_port_test.cc +++ b/test/unit_tests/rpc_port_test.cc @@ -352,10 +352,15 @@ class RpcPortConnection : public RpcPortBase { ret = rpc_port_stub_add_disconnected_event_cb(stub_handle_, [](const char* sender, const char* instance, void *data) { - RpcPortConnection* p = static_cast(data); + auto* p = static_cast(data); p->touch_stub_disconnected_event_cb_ = true; - p->Finish(); - }, this); + g_timeout_add(1, [](void* data) -> gboolean { + auto* p = static_cast(data); + p->Finish(); + return G_SOURCE_REMOVE; + }, p); + }, + this); ASSERT_EQ(ret, 0); ret = rpc_port_stub_add_privilege(stub_handle_, @@ -368,7 +373,7 @@ class RpcPortConnection : public RpcPortBase { void ProxySetup() { int ret = rpc_port_proxy_add_connected_event_cb(proxy_handle_, - [](const char *ep, const char *port_name, rpc_port_h port, void *data) { + [](const char* ep, const char* port_name, rpc_port_h port, void* data) { RpcPortConnection* p = static_cast(data); p->proxy_port_ = port; rpc_port_proxy_get_port(p->proxy_handle_, RPC_PORT_PORT_CALLBACK, @@ -378,11 +383,16 @@ class RpcPortConnection : public RpcPortBase { ASSERT_EQ(ret, 0); ret = rpc_port_proxy_add_disconnected_event_cb(proxy_handle_, - [](const char *ep, const char *port_name, void *data) { - RpcPortConnection* p = static_cast(data); + [](const char* ep, const char* port_name, void* data) { + auto* p = static_cast(data); p->touch_proxy_disconnected_event_cb_ = true; - p->Finish(); - }, this); + g_timeout_add(1, [](void* data) -> gboolean { + auto* p = static_cast(data); + p->Finish(); + return G_SOURCE_REMOVE; + }, p); + }, + this); ASSERT_EQ(ret, 0); ret = rpc_port_proxy_add_received_event_cb(proxy_handle_, @@ -616,3 +626,29 @@ TEST_F(RpcPortConnection, rpc_port_stub_disconnected_N) { ASSERT_TRUE(touch_stub_disconnected_event_cb_); } + +/* + * @testcase rpc_port_disconnect_P + * @description disconnect the port. + * And then, checks whether the disconnected event callback is invoked or not. + * @apicovered rpc_port_disconnect + */ +TEST_F(RpcPortConnection, rpc_port_disconnect_P) { + char res[] = "test"; + if (proxy_port_ == nullptr) + RunMainLoop(); + + ASSERT_NE(proxy_port_, nullptr); + int ret = rpc_port_write(proxy_port_, res, sizeof(res)); + ASSERT_EQ(ret, 0); + + if (stub_port_ == nullptr) + RunMainLoop(); + + ret = rpc_port_disconnect(stub_port_); + EXPECT_EQ(ret, 0); + + RunMainLoop(); + ASSERT_TRUE(touch_stub_disconnected_event_cb_); + ASSERT_TRUE(touch_proxy_disconnected_event_cb_); +}