comp-manager: Add new dbus method to find and get mowned devices
authorSaurav Babu <saurav.babu@samsung.com>
Tue, 16 Jan 2018 12:49:59 +0000 (18:19 +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.c
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 32a1febb35e0ff0fb6c819ecc65eb4b926250cd8..7cab5f0b7b49aadb645bc094cb2e38bef844a408 100755 (executable)
@@ -47,10 +47,17 @@ gboolean group_unpair_resource(Group *group, GDBusMethodInvocation *invocation,
 gboolean group_send_data(Group *group, GDBusMethodInvocation *invocation,
        gchar *uuid_dev, gchar *data, gpointer user_data);
 
+gboolean group_find_mowned_devices(Group *group,
+       GDBusMethodInvocation *invocation, gpointer user_data);
+
+gboolean group_get_mowned_device(Group *group,
+       GDBusMethodInvocation *invocation, gpointer user_data);
+
 void notify_group_found(GVariant *group_data);
 void notify_group_find_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);
+void notify_mowned_device_found(int device_count, GVariant *device_data);
 
 #endif
index 7724e71d8ee0f2d88ec572e66ddd37f9f85cd1a8..77a4dcf126ba1c9c328c90d96aef8313951184f3 100755 (executable)
@@ -69,6 +69,12 @@ int comp_group_send_data(gchar *uuid_dev, gchar *data);
 GVariant *comp_group_get_remote_mot_enabled_devices();
 int comp_group_get_mot_device_count();
 
+void comp_group_add_new_mowned_device(comp_mot_device_t *device);
+void comp_group_notify_mowned_device_find_done(int device_count);
+int comp_group_find_mowned_devices();
+GVariant *comp_group_get_mowned_devices();
+int comp_group_get_mowned_device_count();
+
 /* Join to remote device group */
 int comp_group_join_to(/* callback */); //Join this device to in certain remote group (Async)
 int comp_group_leave_from(/* callback */); //leave from certain remote group (Async)
index 8cf2c5b89ecd0e17b7409940b5b14c9faa6f1d9e..380a37da1bf403c76f2c86490ebee22ccadd3260 100755 (executable)
@@ -84,6 +84,16 @@ static bool __group_init(GDBusConnection *connection)
                G_CALLBACK(group_send_data),
                NULL);
 
+       g_signal_connect(group_skeleton,
+               "handle-find-mowned-devices",
+               G_CALLBACK(group_find_mowned_devices),
+               NULL);
+
+       g_signal_connect(group_skeleton,
+               "handle-get-mowned-device",
+               G_CALLBACK(group_get_mowned_device),
+               NULL);
+
        group = g_dbus_object_manager_server_new(COMP_DBUS_GROUP_PATH);
 
        // Set connection to 'manager'
index ffef284db4ca892cdc517479096d3004d7666717..cfea131eac18d16de444c068c2f493cfbd9dabd6 100755 (executable)
@@ -85,7 +85,7 @@ gboolean group_device_invite(Group *group, GDBusMethodInvocation *invocation,
 {
        gint result = 0;
 
-       LOG_DEBUG("group device invite eject using dbus successful");
+       LOG_DEBUG("group device invite called using dbus successful");
 
        result = comp_group_invite(uuid, pin);
 
@@ -171,6 +171,36 @@ gboolean group_send_data(Group *group, GDBusMethodInvocation *invocation,
        return ret;
 }
 
+gboolean group_find_mowned_devices(Group *group,
+       GDBusMethodInvocation *invocation, gpointer user_data)
+{
+       int ret = 0;
+
+       LOG_DEBUG("find mot owned devices called using dbus successful");
+
+       ret = comp_group_find_mowned_devices();
+
+       group_complete_find_mowned_devices(group, invocation, ret);
+
+       return TRUE;
+}
+
+gboolean group_get_mowned_device(Group *group,
+       GDBusMethodInvocation *invocation, gpointer user_data)
+{
+       int dev_count = 0;
+       GVariant *device_data;
+
+       LOG_DEBUG("get mowned device called using dbus successful");
+
+       dev_count = comp_group_get_mowned_device_count();
+       device_data = comp_group_get_mowned_devices();
+
+       group_complete_get_mowned_device(group, invocation, dev_count, device_data);
+
+       return TRUE;
+}
+
 void notify_group_found(GVariant *group_data)
 {
        group_emit_group_found(group_dbus_get_object(), group_data);
@@ -195,3 +225,9 @@ void notify_group_device_eject_result(int ret)
 {
        group_emit_device_eject_result(group_dbus_get_object(), ret);
 }
+
+void notify_mowned_device_found(int device_count, GVariant *device_data)
+{
+       group_emit_mowned_device_found(group_dbus_get_object(), device_count,
+                                                                  device_data);
+}
index 71ab12b74ef3a245fd3909afa4f5ae49f17ada87..fd75de9ba68a620edf6d0802a1ec625b3a3087ed 100755 (executable)
@@ -5,6 +5,7 @@
 
 GList *found_group_list;
 GList *mot_enb_dev_list = NULL;
+GList *mowned_dev_list = NULL;
 static char *group_invite_uuid = NULL;
 static char *group_invite_pin = NULL;
 
@@ -286,12 +287,13 @@ void comp_group_notify_mot_enable_device_done(int device_count)
 {
        GVariant *device_data;
 
+       LOG_BEGIN();
+
        device_data = comp_group_get_remote_mot_enabled_devices();
 
        notify_device_found(device_count, device_data);
 
-       LOG_BEGIN();
-
+       LOG_END();
 }
 
 int comp_group_find_mot_enabled_devices()
@@ -410,6 +412,104 @@ int comp_group_send_data(gchar *uuid_dev, gchar *data)
        return ret;
 }
 
+void comp_group_add_new_mowned_device(comp_mot_device_t *device)
+{
+       LOG_BEGIN();
+
+       mowned_dev_list = g_list_prepend(mowned_dev_list, device);
+
+       LOG_END();
+}
+
+GVariant *comp_group_get_mowned_devices()
+{
+       GVariantBuilder builder;
+       GVariant *group_data;
+       GList *iter = NULL;
+
+       g_variant_builder_init(&builder, G_VARIANT_TYPE("aa{sv}"));
+
+       iter = mowned_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}", "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;
+}
+
+int comp_group_get_mowned_device_count()
+{
+       if (mowned_dev_list)
+               return g_list_length(mowned_dev_list);
+
+       return 0;
+}
+
+void comp_group_notify_mowned_device_find_done(int device_count)
+{
+       GVariant *device_data;
+
+       LOG_BEGIN();
+
+       device_data = comp_group_get_mowned_devices();
+
+       notify_mowned_device_found(device_count, device_data);
+
+       LOG_END();
+}
+
+int comp_group_find_mowned_devices()
+{
+       int ret;
+
+       LOG_BEGIN();
+
+       /* list freeing */
+       g_list_free_full(mowned_dev_list, _mot_enb_dev_list_free_func);
+       mowned_dev_list = NULL;
+
+       ret = agent_find_mowned_devices();
+       if (ret != COMP_ERROR_NONE) {
+               LOG_ERR("Failed to find mowned devices : %s",
+                                comp_log_get_error_string(ret));
+       }
+
+       LOG_END();
+
+       return ret;
+}
+
 /* Join to remote device group */
 
 int comp_group_join_to(/* callback */) //Join this device to in certain remote group (Async)
index 318a6e6d9df6ab38806f02b78760e7767fc0e50d..db8efa169ba0104118ed791251b7cd31b88bb6bc 100755 (executable)
@@ -510,6 +510,8 @@ static void _agent_signal_handler(GDBusConnection *connection,
                gchar *key;
                GVariant *val;
                gsize len = 0;
+               int mowned_devs_cnt = 0;
+               comp_mot_device_t *device;
 
                if (NULL == parameters) {
                        LOG_ERR("No Multiple Owned devices found");
@@ -517,54 +519,76 @@ 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);
+                                       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);
-                               } else if (strcasecmp(key, "adapter") == 0)  {
-                                       int flags = g_variant_get_uint32(val);
+                                       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);
+                                       LOG_DEBUG("addr = %s", addr);
+                                       device->addr = g_strdup(addr);
                                } else if (strcasecmp(key, "ifindex") == 0)  {
-                                       int ifindex = g_variant_get_uint32(val);
+                                       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);
+                                       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);
+                       mowned_devs_cnt += 1;
+                       comp_group_add_new_mowned_device(device);
                }
+
                g_variant_iter_free(iter);
+
+               LOG_DEBUG("mowned_devs_cnt = %d", mowned_devs_cnt);
+
+               comp_group_notify_mowned_device_find_done(mowned_devs_cnt);
        } else if (0 == g_strcmp0(signal_name, "acl_done")) {
                g_variant_get(parameters, "(i)", &result);
                LOG_DEBUG("Result : %d", result);
index e50a34ea0dd5909da526db029a184aca2604c6ee..8d305d5d408d0f87e3cf48aedb47f0bc7976166c 100755 (executable)
                        <arg type="s" name="data" direction="in"/>
                        <arg type="i" name="result" direction="out" />
                </method>
+               <method name="FindMownedDevices">
+                       <arg type="i" name="result" direction="out" />
+               </method>
+               <method name="GetMownedDevice">
+                       <arg type="i" name="device_count" direction="out" />
+                       <arg type="aa{sv}" name="device_info" direction="out" />
+               </method>
                <!-- Signal (D-Bus) definitions -->
                <signal name="GroupFound">
                        <arg type="a{sv}" name="group_info" direction="out" />
                <signal name="DeviceEjectResult">
                        <arg type="i" name="result" direction="out" />
                </signal>
+               <signal name="MownedDeviceFound">
+                       <arg type="i" name="device_count" direction="out" />
+                       <arg type="aa{sv}" name="device_info" direction="out" />
+               </signal>
        </interface>
 </node>