From b18552e143befba9d758dd570cff0eae96f02922 Mon Sep 17 00:00:00 2001 From: Inkyun Kil Date: Wed, 13 Oct 2021 18:55:04 +0900 Subject: [PATCH] Change cion listen status - If ondemand list is empty, there is no need to listen. Change-Id: I0d9869b835d90714151061a9b5d55e2195120afb Signed-off-by: Inkyun Kil --- src/esd_cion/esd_cion.cc | 33 +++++++++++++++++++++++++++++++-- 1 file changed, 31 insertions(+), 2 deletions(-) diff --git a/src/esd_cion/esd_cion.cc b/src/esd_cion/esd_cion.cc index a91b95c..e124d59 100644 --- a/src/esd_cion/esd_cion.cc +++ b/src/esd_cion/esd_cion.cc @@ -21,14 +21,35 @@ namespace { std::shared_ptr esd_cion_server; + bool is_listening = false; } // namespace -int _esd_cion_init() { +static void __change_listen_status_cion_server() { + try { + GList *list = nullptr; + int ret = esd_cion_get_enabled_service_list(&list); + if (ret != 0) { + _D("Get list error"); + } else if (list == nullptr && is_listening) { + esd_cion_server->Stop(); + is_listening = false; + _D("esd_cion_server stop listen"); + } else if (list != nullptr && !is_listening) { + esd_cion_server->Listen(); + is_listening = true; + _D("esd_cion_server start listen"); + } + } catch (const cion::Exception& e) { + _E("cion_init failed : %s", e.what()); + } + + return; +} +int _esd_cion_init() { try { esd_cion_server = std::make_shared("__CION_INTERNAL_DAEMON__", ""); - esd_cion_server->Listen(); } catch (const cion::Exception& e) { _D("cion_init failed : %s", e.what()); return -1; @@ -36,6 +57,8 @@ int _esd_cion_init() { _D("cion_init done"); + __change_listen_status_cion_server(); + return 0; } @@ -48,6 +71,9 @@ void _esd_cion_adds_enabled_app(const char *service_name, const char *app_id, esd_cion_server->AddOndemandServiceList(std::string(service_name), std::string(app_id), std::string(display_name)); + + if (!is_listening) + __change_listen_status_cion_server(); } void _esd_cion_removes_enabled_app(const char *service_name, const char *app_id) { @@ -58,4 +84,7 @@ void _esd_cion_removes_enabled_app(const char *service_name, const char *app_id) esd_cion_server->RemoveOndemandServiceList(std::string(service_name), std::string(app_id)); + + if (is_listening) + __change_listen_status_cion_server(); } \ No newline at end of file -- 2.7.4