Change cion listen status 63/265263/1
authorInkyun Kil <inkyun.kil@samsung.com>
Wed, 13 Oct 2021 09:55:04 +0000 (18:55 +0900)
committerInkyun Kil <inkyun.kil@samsung.com>
Wed, 13 Oct 2021 09:55:04 +0000 (18:55 +0900)
- If ondemand list is empty, there is no need to listen.

Change-Id: I0d9869b835d90714151061a9b5d55e2195120afb
Signed-off-by: Inkyun Kil <inkyun.kil@samsung.com>
src/esd_cion/esd_cion.cc

index a91b95c..e124d59 100644 (file)
 
 namespace {
   std::shared_ptr<CionOndemandServer> 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<CionOndemandServer>("__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