comp-manager: Added DeviceFound signal to notify mot devices added
authorSaurav Babu <saurav.babu@samsung.com>
Fri, 12 Jan 2018 10:57:52 +0000 (16:27 +0530)
committersaerome.kim <saerome.kim@samsung.com>
Mon, 2 Jul 2018 10:38:40 +0000 (19:38 +0900)
Signed-off-by: Saurav Babu <saurav.babu@samsung.com>
src/companion-manager/include/comp_gdbus_group.h
src/companion-manager/include/comp_group.h
src/companion-manager/src/comp_gdbus_group.c
src/companion-manager/src/comp_group.c
src/companion-manager/src/comp_mot_agent.c
src/companion-manager/src/companion_gdbus.xml

index f1fa00d..d12dde6 100755 (executable)
@@ -34,6 +34,7 @@ gboolean group_device_eject(Group *group, GDBusMethodInvocation *invocation,
 
 void notify_group_found(GVariant *group_data);
 void notify_group_finish(int ret);
+void notify_device_found(int device_count, GVariant *device_data);
 void notify_group_device_invite_result(int ret);
 void notify_group_device_eject_result(int ret);
 
index fde1628..54826be 100755 (executable)
@@ -12,6 +12,22 @@ typedef struct {
        comp_group_type_e type;
 } comp_group_t;
 
+typedef struct {
+       char *device_id;
+       int adapter;
+       int flags;
+       int port;
+       char *addr;
+       int ifindex;
+       char *route_data;
+       char *remote_id;
+       int conn_type;
+       int secure_port;
+       int tcp_port;
+       char *sec_ver;
+       int dev_status;
+} comp_mot_device_t;
+
 /* Called when daemon is start. */
 int comp_group_initialize();
 
@@ -23,12 +39,15 @@ int comp_group_destroy(comp_group_t *handle);
 int comp_group_find(int timeout);
 GVariant *comp_group_get_found_groups();
 int comp_group_add_new(char *uri_path, char *device_id, char *device_name,
-                                        char *host_addr, char *resource_type, comp_group_type_e type);
+                                char *host_addr, char *resource_type, comp_group_type_e type);
 
 /* Join the remote devices in my daemon */
 int comp_group_get_groups(comp_group_t ***handles, int *count); //Get all of group in my daemon
 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);
+int comp_group_find_mot_enabled_devices();
+
 char *comp_group_invite_get_uuid();
 char *comp_group_invite_get_pin();
 //Join to device in group (async)
index 67ec9c8..afa6039 100755 (executable)
@@ -118,6 +118,11 @@ void notify_group_finish(int ret)
        group_emit_finish(group_dbus_get_object(), ret);
 }
 
+void notify_device_found(int device_count, GVariant *device_data)
+{
+       group_emit_device_found(group_dbus_get_object(), device_count, device_data);
+}
+
 void notify_group_device_invite_result(int ret)
 {
        group_emit_device_invite_result(group_dbus_get_object(), ret);
index a994839..977ec57 100755 (executable)
@@ -1,6 +1,7 @@
 #include <comp_group.h>
 
 GList *found_group_list;
+GList *mot_enb_dev_list = NULL;
 static char *group_invite_uuid = NULL;
 static char *group_invite_pin = NULL;
 
@@ -67,6 +68,26 @@ void _free_func (gpointer data)
        }
 }
 
+void _mot_enb_dev_list_free_func(gpointer data)
+{
+       comp_mot_device_t *device = (comp_mot_device_t *)data;
+
+       if (device != NULL) {
+               if (device->device_id != NULL)
+                       g_free(device->device_id);
+               if (device->addr != NULL)
+                       g_free(device->addr);
+               if (device->route_data != NULL)
+                       g_free(device->route_data);
+               if (device->remote_id != NULL)
+                       g_free(device->remote_id);
+               if (device->sec_ver != NULL)
+                       g_free(device->sec_ver);
+
+               g_free(device);
+       }
+}
+
 int comp_group_find(int timeout)
 {
        int ret;
@@ -196,12 +217,91 @@ void comp_group_notify_group_invite(int result)
 }
 
 // Find MOT enabled devices
+void comp_group_add_new_mot_device(comp_mot_device_t *device)
+{
+       LOG_BEGIN();
+
+       mot_enb_dev_list = g_list_prepend(mot_enb_dev_list, device);
+
+       LOG_END();
+}
+
+GVariant *comp_group_get_remote_mot_enabled_devices()
+{
+       GVariantBuilder builder;
+       GVariant *group_data;
+       GList *iter = NULL;
+
+       g_variant_builder_init(&builder, G_VARIANT_TYPE("aa{sv}"));
+
+       iter = mot_enb_dev_list;
+       while(iter != NULL) {
+               comp_mot_device_t *device = (comp_mot_device_t *)iter->data;
+
+               g_variant_builder_open(&builder, G_VARIANT_TYPE_VARDICT);
+               g_variant_builder_add(&builder, "{sv}", "DeviceID",
+                                                         g_variant_new_string(device->device_id));
+               g_variant_builder_add(&builder, "{sv}", "Adapter",
+                                                         g_variant_new_int32(device->adapter));
+               g_variant_builder_add(&builder, "{sv}", "Flags",
+                                                         g_variant_new_int32(device->flags));
+               g_variant_builder_add(&builder, "{sv}", "Port",
+                                                         g_variant_new_uint16(device->port));
+               g_variant_builder_add(&builder, "{sv}", "Address",
+                                                         g_variant_new_string(device->addr));
+               g_variant_builder_add(&builder, "{sv}", "Ifindex",
+                                                         g_variant_new_int32(device->ifindex));
+               g_variant_builder_add(&builder, "{sv}", "RouteData",
+                                                         g_variant_new_string(device->route_data));
+               g_variant_builder_add(&builder, "{sv}", "RemoteId",
+                                                         g_variant_new_string(device->remote_id));
+               g_variant_builder_add(&builder, "{sv}", "ConnType",
+                                                         g_variant_new_int32(device->conn_type));
+               g_variant_builder_add(&builder, "{sv}", "SecurePort",
+                                                         g_variant_new_uint16(device->secure_port));
+               g_variant_builder_add(&builder, "{sv}", "TcpPort",
+                                                         g_variant_new_uint16(device->tcp_port));
+               g_variant_builder_add(&builder, "{sv}", "SecVer",
+                                                         g_variant_new_string(device->sec_ver));
+               g_variant_builder_add(&builder, "{sv}", "DeviceStatus",
+                                                         g_variant_new_int32(device->dev_status));
+               g_variant_builder_close(&builder);
+
+               iter = g_list_next(iter);
+       }
+
+       group_data = g_variant_builder_end(&builder);
+
+       return group_data;
+}
+
+void comp_group_notify_mot_enable_device_done(int device_count)
+{
+       GVariant *device_data;
+
+       device_data = comp_group_get_remote_mot_enabled_devices();
+
+       notify_device_found(device_count, device_data);
+
+       LOG_BEGIN();
+
+}
+
 int comp_group_find_mot_enabled_devices()
 {
        int ret;
+
        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();
+       if (ret != COMP_ERROR_NONE) {
+               LOG_ERR("Failed to find mot enable devices : %s",
+                                comp_log_get_error_string(ret));
+       }
 
        LOG_END();
 
index 591b66c..dbf5d39 100755 (executable)
@@ -26,6 +26,7 @@
 
 #include <comp_log.h>
 #include <comp_enum.h>
+#include <comp_group.h>
 
 #define AGENT_SERVER_NAME "net.ma"
 #define AGENT_OBJECT_PATH "/net/ma"
@@ -387,6 +388,7 @@ static void _agent_signal_handler(GDBusConnection *connection,
                GVariant *val;
                gsize len = 0;
                int mot_enb_devs_cnt = 0;
+               comp_mot_device_t *device;
 
                if (NULL == parameters) {
                        LOG_ERR("No MOT enabled devices found");
@@ -394,59 +396,77 @@ static void _agent_signal_handler(GDBusConnection *connection,
                }
                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);
                                        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_uint32(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);
+                                       LOG_DEBUG("addr = %s", addr);
+                                       device->addr = g_strdup(addr);
                                } else if (strcasecmp(key, "ifindex") == 0)  {
                                        int ifindex = g_variant_get_uint32(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);
+                                       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);
+                                       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);
+                                       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_row);
                        mot_enb_devs_cnt += 1;
+                       comp_group_add_new_mot_device(device);
                }
 
                g_variant_iter_free(iter);
 
                LOG_DEBUG("mot_enb_devs_cnt = %d", mot_enb_devs_cnt);
 
+               comp_group_notify_mot_enable_device_done(mot_enb_devs_cnt);
+
                if (mot_enb_devs_cnt > 0) // do mot
                        g_idle_add(__perform_mot, NULL);
                else // No device notify group invite fail
index cb6b788..96af362 100755 (executable)
                <signal name="Finish">
                        <arg type="i" name="result" direction="out" />
                </signal>
+               <signal name="DeviceFound">
+                       <arg type="i" name="device_count" direction="out" />
+                       <arg type="aa{sv}" name="device_info" direction="out" />
+               </signal>
                <signal name="DeviceInviteResult">
                        <arg type="i" name="result" direction="out" />
                </signal>