comp-manager: Register new signal for mot_enb_devs_added event
authorSaurav Babu <saurav.babu@samsung.com>
Thu, 15 Feb 2018 04:53:58 +0000 (10:23 +0530)
committersaerome.kim <saerome.kim@samsung.com>
Mon, 2 Jul 2018 10:38:48 +0000 (19:38 +0900)
This patch registers new signal to know whenever new mot enabled device
is added.
There is no need to free existing discovered device list when Already
in progress error is not returned for disc_mot_enb_devs dbus method

Signed-off-by: Saurav Babu <saurav.babu@samsung.com>
src/companion-manager/include/comp_group.h
src/companion-manager/src/comp_group.c
src/companion-manager/src/comp_mot_agent.c

index 4b0b15e1e26c8813cd64f306c8d4b580c9ac38a8..472abb2b96c4dc4d89cb28858d6eee3120ac16a8 100644 (file)
@@ -60,7 +60,7 @@ int comp_group_get_groups(comp_group_t ***handles, int *count); //Get all of gro
 int comp_group_get_remote_devices(/* callback */); //Get all of device in network (Async)
 
 void comp_group_add_new_mot_device(comp_mot_device_t *device);
-void comp_group_notify_mot_enable_device_done(int device_count);
+void comp_group_notify_mot_enable_device_done();
 int comp_group_find_mot_enabled_devices(int timeout);
 
 char *comp_group_invite_get_uuid();
index 2d7a76ccd90b10cb29c781a272402e6395117b2c..a8534a7c303b73c6f5547862e7a952a123ef5b5b 100644 (file)
@@ -320,7 +320,7 @@ int comp_group_get_mot_device_count()
        return 0;
 }
 
-void comp_group_notify_mot_enable_device_done(int device_count)
+void comp_group_notify_mot_enable_device_done()
 {
        GVariant *device_data;
        int count = g_list_length(mot_enb_dev_list);
@@ -340,16 +340,21 @@ int comp_group_find_mot_enabled_devices(int timeout)
 
        LOG_BEGIN();
 
-       /* list freeing */
-       g_list_free_full (mot_enb_dev_list, _mot_enb_dev_list_free_func);
-       mot_enb_dev_list = NULL;
-
        ret = agent_find_mot_enable_devices(timeout);
        if (ret != COMP_ERROR_NONE) {
                LOG_ERR("Failed to find mot enable devices : %s",
                                 comp_log_get_error_string(ret));
        }
 
+       /* No need to free old list when discovery is already in progress */
+       if (ret != 7) {
+               /* list freeing */
+               g_list_free_full(mot_enb_dev_list, _mot_enb_dev_list_free_func);
+               mot_enb_dev_list = NULL;
+       } else {
+               ret = 0;
+       }
+
        LOG_END();
 
        return ret;
index e2c01a979a7f5d746f7a2b500e4e08dbb6363fb3..3382a14cf69139deb060a4e76f472b701ead766a 100644 (file)
@@ -106,8 +106,6 @@ int agent_find_mot_enable_devices(int timeout)
                return COMP_ERROR_IO_ERROR;
        }
 
-       found_device_count = 0;
-
        variant = g_dbus_proxy_call_sync(agent.gproxy_agent_service, "disc_mot_enb_devs",
                                g_variant_new("(i)", timeout), G_DBUS_CALL_FLAGS_NONE,  -1, NULL, &error);
        if (variant) {
@@ -119,6 +117,9 @@ int agent_find_mot_enable_devices(int timeout)
                return COMP_ERROR_IO_ERROR;
        }
 
+       if (result == 0)
+               found_device_count = 0;
+
        g_timeout_add_seconds(timeout + 1, _find_device_timeout_cb, NULL);
 
        return result;
@@ -566,13 +567,13 @@ static void _agent_signal_handler(GDBusConnection *connection,
                g_variant_get(parameters, "(i)", &result);
                LOG_DEBUG("Result : %d", result);
        } else if (0 == g_strcmp0(signal_name, "disc_mot_enb_devs_done")) {
+               comp_group_notify_mot_enable_device_done();
+       } else if (0 == g_strcmp0(signal_name, "mot_enb_devs_added")) {
                GVariantIter *iter = NULL;
-               GVariantIter *iter_row = NULL;
 
                gchar *key;
                GVariant *val;
                gsize len = 0;
-               int mot_enb_devs_cnt = 0;
                comp_mot_device_t *device;
                comp_context_t *comp_ctx = comp_context_get_context();
 
@@ -580,92 +581,82 @@ static void _agent_signal_handler(GDBusConnection *connection,
                        LOG_ERR("No MOT enabled devices found");
                        return;
                }
-               g_variant_get(parameters, "(aa{sv})", &iter);
-               while (g_variant_iter_next(iter, "a{sv}", &iter_row)) {
-                       device = g_try_malloc0(sizeof(comp_mot_device_t));
-
-                       while (g_variant_iter_loop(iter_row, "{sv}", &key, &val)) {
-                               if (strcasecmp(key, "deviceId") == 0)  {
-                                       const char *deviceid = g_variant_get_string(val, &len);
-                                       if (comp_ctx && (FALSE == comp_ctx->mot_me) &&
-                                               strcasecmp(deviceid, comp_ctx->device_uuid) == 0) {
-                                               g_timeout_add(10, __perform_mot_me, NULL);
-                                               comp_ctx->mot_me = TRUE;
-                                       }
-                                       LOG_DEBUG("deviceId = %s", deviceid);
-                                       device->device_id = g_strdup(deviceid);
-
-                               } else if (strcasecmp(key, "adapter") == 0)  {
-                                       int adapter = g_variant_get_uint32(val);
-                                       LOG_DEBUG("adapter = %d", adapter);
-                                       device->adapter = adapter;
-                               } else if (strcasecmp(key, "flags") == 0)  {
-                                       int flags = g_variant_get_int32(val);
-                                       LOG_DEBUG("flags = %d", flags);
-                                       device->flags = flags;
-                               } else if (strcasecmp(key, "port") == 0)  {
-                                       int port = g_variant_get_uint16(val);
-                                       LOG_DEBUG("port = %d", port);
-                                       device->port = port;
-                               } else if (strcasecmp(key, "addr") == 0)  {
-                                       const char *addr = g_variant_get_string(val, &len);
-                                       LOG_DEBUG("addr = %s", addr);
-                                       device->addr = g_strdup(addr);
-                               } else if (strcasecmp(key, "ifindex") == 0)  {
-                                       int ifindex = g_variant_get_int32(val);
-                                       LOG_DEBUG("ifindex = %d", ifindex);
-                                       device->ifindex = ifindex;
-                               } else if (strcasecmp(key, "routeData") == 0)  {
-                                       const char *routeData = g_variant_get_string(val, &len);
-                                       LOG_DEBUG("routeData = %s", routeData);
-                                       device->route_data = g_strdup(routeData);
-                               } else if (strcasecmp(key, "remoteId") == 0)  {
-                                       const char *remoteId = g_variant_get_string(val, &len);
-                                       LOG_DEBUG("remoteId = %s", remoteId);
-                                       device->remote_id = g_strdup(remoteId);
-                               } else if (strcasecmp(key, "connType") == 0)  {
-                                       int connType = g_variant_get_uint32(val);
-                                       LOG_DEBUG("connType = %d", connType);
-                                       device->conn_type = connType;
-                               } else if (strcasecmp(key, "securePort") == 0)  {
-                                       int securePort = g_variant_get_uint16(val);
-                                       LOG_DEBUG("securePort = %d", securePort);
-                                       device->secure_port = securePort;
-#ifdef WITH_TCP
-                               } else if (strcasecmp(key, "tcpPort") == 0)  {
-                                       int tcpPort = g_variant_get_uint16(val);
-                                       LOG_DEBUG("tcpPort = %d", tcpPort);
-                                       device->tcp_port = tcpPort;
-                               }
-#endif
-                               else if (strcasecmp(key, "secVer") == 0)  {
-                                       const char *secVer = g_variant_get_string(val, &len);
-                                       LOG_DEBUG("secVer = %s", secVer);
-                                       device->sec_ver = g_strdup(secVer);
-                               } else if (strcasecmp(key, "devStatus") == 0)  {
-                                       int devStatus = g_variant_get_uint32(val);
-                                       LOG_DEBUG("devStatus = %d", devStatus);
-                                       device->dev_status = devStatus;
+               g_variant_get(parameters, "(a{sv})", &iter);
+               device = g_try_malloc0(sizeof(comp_mot_device_t));
+
+               while (g_variant_iter_loop(iter, "{sv}", &key, &val)) {
+                       if (strcasecmp(key, "deviceId") == 0)  {
+                               const char *deviceid = g_variant_get_string(val, &len);
+                               if (comp_ctx && (FALSE == comp_ctx->mot_me) &&
+                                       strcasecmp(deviceid, comp_ctx->device_uuid) == 0) {
+                                       g_timeout_add(10, __perform_mot_me, NULL);
+                                       comp_ctx->mot_me = TRUE;
                                }
+                               LOG_DEBUG("deviceId = %s", deviceid);
+                               device->device_id = g_strdup(deviceid);
+
+                       } else if (strcasecmp(key, "adapter") == 0)  {
+                               int adapter = g_variant_get_uint32(val);
+                               LOG_DEBUG("adapter = %d", adapter);
+                               device->adapter = adapter;
+                       } else if (strcasecmp(key, "flags") == 0)  {
+                               int flags = g_variant_get_int32(val);
+                               LOG_DEBUG("flags = %d", flags);
+                               device->flags = flags;
+                       } else if (strcasecmp(key, "port") == 0)  {
+                               int port = g_variant_get_uint16(val);
+                               LOG_DEBUG("port = %d", port);
+                               device->port = port;
+                       } else if (strcasecmp(key, "addr") == 0)  {
+                               const char *addr = g_variant_get_string(val, &len);
+                               LOG_DEBUG("addr = %s", addr);
+                               device->addr = g_strdup(addr);
+                       } else if (strcasecmp(key, "ifindex") == 0)  {
+                               int ifindex = g_variant_get_int32(val);
+                               LOG_DEBUG("ifindex = %d", ifindex);
+                               device->ifindex = ifindex;
+                       } else if (strcasecmp(key, "routeData") == 0)  {
+                               const char *routeData = g_variant_get_string(val, &len);
+                               LOG_DEBUG("routeData = %s", routeData);
+                               device->route_data = g_strdup(routeData);
+                       } else if (strcasecmp(key, "remoteId") == 0)  {
+                               const char *remoteId = g_variant_get_string(val, &len);
+                               LOG_DEBUG("remoteId = %s", remoteId);
+                               device->remote_id = g_strdup(remoteId);
+                       } else if (strcasecmp(key, "connType") == 0)  {
+                               int connType = g_variant_get_uint32(val);
+                               LOG_DEBUG("connType = %d", connType);
+                               device->conn_type = connType;
+                       } else if (strcasecmp(key, "securePort") == 0)  {
+                               int securePort = g_variant_get_uint16(val);
+                               LOG_DEBUG("securePort = %d", securePort);
+                               device->secure_port = securePort;
+#ifdef WITH_TCP
+                       } else if (strcasecmp(key, "tcpPort") == 0)  {
+                               int tcpPort = g_variant_get_uint16(val);
+                               LOG_DEBUG("tcpPort = %d", tcpPort);
+                               device->tcp_port = tcpPort;
                        }
-                       g_variant_iter_free(iter_row);
-
-                       comp_context_t *comp_ctx = comp_context_get_context();
-                       if (strcmp(device->device_id, comp_ctx->device_uuid) != 0) {
-                               mot_enb_devs_cnt += 1;
-                               comp_group_add_new_mot_device(device);
-                       } else {
-                               LOG_DEBUG("It is my mowned device. Store the mowned device in daemon");
-                               comp_group_change_mowned_device(device);
+#endif
+                       else if (strcasecmp(key, "secVer") == 0)  {
+                               const char *secVer = g_variant_get_string(val, &len);
+                               LOG_DEBUG("secVer = %s", secVer);
+                               device->sec_ver = g_strdup(secVer);
+                       } else if (strcasecmp(key, "devStatus") == 0)  {
+                               int devStatus = g_variant_get_uint32(val);
+                               LOG_DEBUG("devStatus = %d", devStatus);
+                               device->dev_status = devStatus;
                        }
                }
-
                g_variant_iter_free(iter);
 
-               LOG_DEBUG("mot_enb_devs_cnt = %d", mot_enb_devs_cnt);
-               found_device_count = mot_enb_devs_cnt;
-               comp_group_notify_mot_enable_device_done(mot_enb_devs_cnt);
-
+               if (strcmp(device->device_id, comp_ctx->device_uuid) != 0) {
+                       found_device_count += 1;
+                       comp_group_add_new_mot_device(device);
+               } else {
+                       LOG_DEBUG("It is my mowned device. Store the mowned device in daemon");
+                       comp_group_change_mowned_device(device);
+               }
        } else if (0 == g_strcmp0(signal_name, "disc_mowned_devs_done")) {
                GVariantIter *iter = NULL;
                GVariantIter *iter_row = NULL;
@@ -858,6 +849,17 @@ static int _subscribe_event()
        h->dbus_sub_ids = g_list_append(h->dbus_sub_ids, GUINT_TO_POINTER(id));
        LOG_DEBUG("subscribed for (disc_mot_enb_devs_done) signal %d", id);
 
+       /* mot_enb_devs_added */
+       id = g_dbus_connection_signal_subscribe(h->dbus_connection, NULL,
+                       AGENT_SERVER_NAME, "mot_enb_devs_added", AGENT_OBJECT_PATH, NULL,
+                       G_DBUS_CALL_FLAGS_NONE, _agent_signal_handler, h, NULL);
+       if (0 == id) {
+               LOG_ERR("g_dbus_connection_signal_subscribe(mot_enb_devs_added) Fail(%d)", errno);
+               return -1;
+       }
+       h->dbus_sub_ids = g_list_append(h->dbus_sub_ids, GUINT_TO_POINTER(id));
+       LOG_DEBUG("subscribed for (mot_enb_devs_added) signal %d", id);
+
        /* disc_mowned_devs_done */
        id = g_dbus_connection_signal_subscribe(h->dbus_connection, NULL, AGENT_SERVER_NAME,
                        "disc_mowned_devs_done", AGENT_OBJECT_PATH, NULL,