From 8c34ce4448c94f80822a29228ee4ac8ee64c53ec Mon Sep 17 00:00:00 2001 From: Saurav Babu Date: Thu, 15 Feb 2018 10:23:58 +0530 Subject: [PATCH] comp-manager: Register new signal for mot_enb_devs_added event 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 --- src/companion-manager/include/comp_group.h | 2 +- src/companion-manager/src/comp_group.c | 15 ++- src/companion-manager/src/comp_mot_agent.c | 170 +++++++++++++++-------------- 3 files changed, 97 insertions(+), 90 deletions(-) diff --git a/src/companion-manager/include/comp_group.h b/src/companion-manager/include/comp_group.h index 4b0b15e..472abb2 100644 --- a/src/companion-manager/include/comp_group.h +++ b/src/companion-manager/include/comp_group.h @@ -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(); diff --git a/src/companion-manager/src/comp_group.c b/src/companion-manager/src/comp_group.c index 2d7a76c..a8534a7 100644 --- a/src/companion-manager/src/comp_group.c +++ b/src/companion-manager/src/comp_group.c @@ -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; diff --git a/src/companion-manager/src/comp_mot_agent.c b/src/companion-manager/src/comp_mot_agent.c index e2c01a9..3382a14 100644 --- a/src/companion-manager/src/comp_mot_agent.c +++ b/src/companion-manager/src/comp_mot_agent.c @@ -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, -- 2.7.4