From af69f95589ba8b39fa2d87dc3fbd0aed4a735adf Mon Sep 17 00:00:00 2001 From: Hwankyu Jhun Date: Wed, 8 Mar 2023 10:15:22 +0000 Subject: [PATCH] Modify aul_app_com_leave function Some program goes to the sleep state immediately after calling the aul_app_com_leave() function. In this case, the main thread of the process will be blocked. It causes increasing memory usage. To avoid the issue, the aul_app_com_leave() function sends the APP_COM_LEAVE command to the amd to deregister the event. Change-Id: Ic3d27b8c4151955094887fea59ed25cda08d2faf Signed-off-by: Hwankyu Jhun --- src/app_com.cc | 22 ++++++++++----------- test/unit_tests/test_app_com.cc | 34 +------------------------------- test/unit_tests/test_launcher_service.cc | 23 --------------------- 3 files changed, 11 insertions(+), 68 deletions(-) diff --git a/src/app_com.cc b/src/app_com.cc index 2ca2f95..57c304d 100644 --- a/src/app_com.cc +++ b/src/app_com.cc @@ -346,22 +346,20 @@ extern "C" API int aul_app_com_leave(aul_app_com_connection_h connection) { std::lock_guard lock(context.GetMutex()); conn->Disable(); + std::string endpoint = conn->GetEndpoint(); + if (!context.ExistConnection(endpoint)) { + tizen_base::Bundle b { { AUL_K_COM_ENDPOINT, endpoint } }; + int ret = AppRequest(APP_COM_LEAVE, getuid()) + .With(std::move(b)) + .SendSimply(AUL_SOCK_NOREPLY); + if (ret != 0) + _E("Failed to send leave request. error(%d)", ret); + } + g_idle_add_full(G_PRIORITY_HIGH, [](gpointer user_data) -> gboolean { auto* conn = static_cast(user_data); std::lock_guard lock(context.GetMutex()); - std::string endpoint = conn->GetEndpoint(); context.RemoveConnection(conn); - - if (context.ExistConnection(endpoint)) - return G_SOURCE_REMOVE; - - tizen_base::Bundle b { { AUL_K_COM_ENDPOINT, endpoint } }; - int ret = AppRequest(APP_COM_LEAVE, getuid()) - .With(std::move(b)) - .SendSimply(AUL_SOCK_NOREPLY); - if (ret != 0) - _E("Failed to send leave request. error(%d)", ret); - return G_SOURCE_REMOVE; }, connection, nullptr); diff --git a/test/unit_tests/test_app_com.cc b/test/unit_tests/test_app_com.cc index 63c9f51..7ccbb80 100644 --- a/test/unit_tests/test_app_com.cc +++ b/test/unit_tests/test_app_com.cc @@ -53,7 +53,6 @@ class AppComTest : public TestFixture { AppComTest() : TestFixture(std::make_unique<::Mocks>()) {} virtual void SetUp() { - loop_ = g_main_loop_new(nullptr, FALSE); permission_ = aul_app_com_permission_create(); } @@ -62,19 +61,6 @@ class AppComTest : public TestFixture { aul_app_com_permission_destroy(permission_); permission_ = nullptr; } - - if (loop_ != nullptr) { - g_main_loop_unref(loop_); - loop_ = nullptr; - } - } - - void RunMainLoop() { - g_main_loop_run(loop_); - } - - void QuitMainLoop() { - g_main_loop_quit(loop_); } std::shared_ptr MakePacket(tizen_base::Bundle b) { @@ -108,9 +94,6 @@ class AppComTest : public TestFixture { bool touched_ = false; aul_app_com_permission_h permission_ = nullptr; - - private: - GMainLoop* loop_ = nullptr; }; TEST_F(AppComTest, aul_app_com_permission_create_P) { @@ -166,9 +149,6 @@ TEST_F(AppComTest, aul_app_com_create_P) { if (cmd == APP_COM_CREATE) kb = bundle_decode(pkt->data, pkt->len); - if (cmd == APP_COM_LEAVE) - QuitMainLoop(); - return n; })); ON_CALL(GetMock(), recv(_, _, _, _)) @@ -192,7 +172,6 @@ TEST_F(AppComTest, aul_app_com_create_P) { EXPECT_EQ(b.GetString(AUL_K_COM_ENDPOINT), "app_com_create"); aul_app_com_leave(connection); - RunMainLoop(); } TEST_F(AppComTest, aul_app_com_create_N) { @@ -224,9 +203,6 @@ TEST_F(AppComTest, aul_app_com_create_async_P) { if (cmd == APP_COM_CREATE) kb = bundle_decode(pkt->data, pkt->len); - if (cmd == APP_COM_LEAVE) - QuitMainLoop(); - return n; })); ON_CALL(GetMock(), recv(_, _, _, _)) @@ -250,7 +226,6 @@ TEST_F(AppComTest, aul_app_com_create_async_P) { EXPECT_EQ(b.GetString(AUL_K_COM_ENDPOINT), "app_com_create_async"); aul_app_com_leave(connection); - RunMainLoop(); } TEST_F(AppComTest, aul_app_com_create_async_N) { @@ -282,9 +257,6 @@ TEST_F(AppComTest, aul_app_com_join_P) { if (cmd == APP_COM_JOIN) kb = bundle_decode(pkt->data, pkt->len); - if (cmd == APP_COM_LEAVE) - QuitMainLoop(); - return n; })); ON_CALL(GetMock(), recv(_, _, _, _)) @@ -308,7 +280,6 @@ TEST_F(AppComTest, aul_app_com_join_P) { EXPECT_EQ(b.GetString(AUL_K_COM_ENDPOINT), "app_com_join"); aul_app_com_leave(connection); - RunMainLoop(); } TEST_F(AppComTest, aul_app_com_join_N) { @@ -379,10 +350,8 @@ TEST_F(AppComTest, aul_app_com_leave_P) { cmd = pkt->cmd; opt = pkt->opt; - if (cmd == APP_COM_LEAVE) { + if (cmd == APP_COM_LEAVE) kb = bundle_decode(pkt->data, pkt->len); - QuitMainLoop(); - } return n; })); @@ -400,7 +369,6 @@ TEST_F(AppComTest, aul_app_com_leave_P) { EXPECT_EQ(ret, AUL_R_OK); ret = aul_app_com_leave(connection); - RunMainLoop(); EXPECT_NE(kb, nullptr); tizen_base::Bundle b(kb, false, true); diff --git a/test/unit_tests/test_launcher_service.cc b/test/unit_tests/test_launcher_service.cc index 66f84c3..67c00a3 100644 --- a/test/unit_tests/test_launcher_service.cc +++ b/test/unit_tests/test_launcher_service.cc @@ -55,8 +55,6 @@ class LauncherServiceTest : public TestFixture { if (!aul_is_initialized()) aul_launch_init(nullptr, nullptr); - loop_ = g_main_loop_new(nullptr, FALSE); - cmd_ = -1; opt_ = -1; @@ -70,9 +68,6 @@ class LauncherServiceTest : public TestFixture { if (opt_ & AUL_SOCK_BUNDLE) kb_ = bundle_decode(pkt->data, pkt->len); - if (cmd_ == APP_COM_LEAVE) - QuitMainLoop(); - return n; })); ON_CALL(GetMock(), recv(_, _, _, _)) @@ -107,19 +102,6 @@ class LauncherServiceTest : public TestFixture { aul_launcher_service_destroy(handle_); handle_ = nullptr; } - - if (loop_ != nullptr) { - g_main_loop_unref(loop_); - loop_ = nullptr; - } - } - - void RunMainLoop() { - g_main_loop_run(loop_); - } - - void QuitMainLoop() { - g_main_loop_quit(loop_); } int cmd_ = -1; @@ -127,9 +109,6 @@ class LauncherServiceTest : public TestFixture { bundle* kb_ = nullptr; aul_launcher_service_h create_handle_ = nullptr; aul_launcher_service_h handle_ = nullptr; - - private: - GMainLoop* loop_ = nullptr; }; TEST_F(LauncherServiceTest, aul_launcher_service_create_P) { @@ -169,8 +148,6 @@ TEST_F(LauncherServiceTest, aul_launcher_service_destroy_P) { EXPECT_EQ(ret, AUL_R_OK); handle_ = nullptr; - RunMainLoop(); - EXPECT_NE(kb_, nullptr); tizen_base::Bundle b(kb_, false, false); EXPECT_EQ(cmd_, APP_COM_LEAVE); -- 2.7.4