Add device eject / device invite api in capi layer
authorJihoon Jung <jh8801.jung@samsung.com>
Mon, 15 Jan 2018 07:54:13 +0000 (16:54 +0900)
committersaerome.kim <saerome.kim@samsung.com>
Mon, 2 Jul 2018 10:38:40 +0000 (19:38 +0900)
Signed-off-by: Jihoon Jung <jh8801.jung@samsung.com>
capi/demo/companion_demo.c
capi/include/companion.h
capi/src/companion.c
capi/src/companion_gdbus.xml
src/companion-manager/include/comp_gdbus_group.h
src/companion-manager/src/comp_gdbus_group.c
src/companion-manager/src/comp_iot.c
src/companion-manager/src/companion_gdbus.xml

index 6600c72f8d89ee72906ffb8e14cefc565977a3bc..1a0919715978c991060a333b9aee41b2c5592b05 100755 (executable)
@@ -162,14 +162,14 @@ int companion_group_get_found_groups_test(void)
 
        found_group_list = NULL;
 
-       ret = companion_group_get_found_groups(&groups ,&count);
+       ret = companion_group_get_found_groups(&groups&count);
 
        if (ret == 0)
                TC_PRT("group find successful");
        else
                TC_PRT("group find failed, ret [%d]", ret);
 
-       TC_PRT("Found group count : ", count);
+       TC_PRT("Found group count : %d", count);
 
        for (int i = 0; i < count; i++) {
                companion_group_type_e type;
@@ -217,9 +217,9 @@ int companion_device_find_test(void)
        companion_device_find(input_int, _device_found_cb, _group_finish_cb, NULL);
 
        if (ret == 0)
-               TC_PRT("group find successful");
+               TC_PRT("device find successful");
        else
-               TC_PRT("group find failed, ret [%d]", ret);
+               TC_PRT("device find failed, ret [%d]", ret);
 
        END();
        return ret;
@@ -261,23 +261,54 @@ int companion_device_get_found_devices_test(void)
        return ret;
 }
 
+void _device_invite_result_cb(int result, void *user_data)
+{
+       TC_PRT("Invite complete !!!! ret : %d", result);
+}
+
 int companion_device_invite_test(void)
 {
        int ret = 0;
        BEGIN();
 
        /* using stored group list and device list */
+       if (g_list_length(found_device_list) > 0 && g_list_length(found_group_list) > 0) {
+               TC_PRT("Invite Test Start");
+               companion_group_h group = (companion_group_h)(found_group_list[0].data);
+               companion_device_h device = (companion_device_h)(found_device_list[0].data);
+
+               companion_device_invite(group, device, "12341234", _device_invite_result_cb, NULL);
+
+       } else {
+               TC_PRT("not exist found group or device list");
+       }
 
        END();
        return ret;
 }
 
+void _device_eject_result_cb(int result, void *user_data)
+{
+       TC_PRT("eject complete !!!! ret : %d", result);
+}
+
 int companion_device_eject_test(void)
 {
        int ret = 0;
        BEGIN();
 
        /* using stored group list and device list */
+       if (g_list_length(found_device_list) > 0 && g_list_length(found_group_list) > 0) {
+               TC_PRT("Invite Test Start");
+               companion_group_h group = (companion_group_h)(found_group_list[0].data);
+               companion_device_h device = (companion_device_h)(found_device_list[0].data);
+
+               /* using stored group list and device list */
+               companion_device_eject(group, device, _device_eject_result_cb, NULL);
+       } else {
+               TC_PRT("not exist found group or device list");
+       }
+
 
        END();
        return ret;
index 8db0fc29d38aa2882434f8a65a48744706e2570c..11758cb15636275b6d406c59fc11703b3ee44358 100755 (executable)
@@ -17,7 +17,10 @@ typedef void *companion_device_h;
 
 typedef bool (*companion_group_found_cb)(companion_group_type_e type, companion_group_h group, void *user_data);
 typedef bool (*companion_device_found_cb)(companion_device_h device, void *user_data);
-typedef void (*companion_group_finish_cb)(int result, void *user_data);
+typedef void (*companion_group_find_finish_cb)(int result, void *user_data);
+typedef void (*companion_device_find_finish_cb)(int result, void *user_data);
+typedef void (*companion_device_invite_result_cb)(int result, void *user_data);
+typedef void (*companion_device_eject_result_cb)(int result, void *user_data);
 
 
 
@@ -29,13 +32,13 @@ int companion_deinitialize(); /* deinitialize gdbus connection with manager daem
 /* companion_group_create : craete group in my daemon */
 int companion_group_create(char *group_name); /* O */
 /* companion_group_find : find groups in my daemon + remote groups in network */
-int companion_group_find(int timeout, companion_group_found_cb found_cb, companion_group_finish_cb finish_cb, void *user_data); /* O */
+int companion_group_find(int timeout, companion_group_found_cb found_cb, companion_group_find_finish_cb finish_cb, void *user_data); /* O */
 /* companion_group_find : find groups in my daemon + remote groups in network */
 int companion_group_get_found_groups(companion_group_h **groups, int *count); /* O */
 /* companion_group_join : join to remote group. if group handle is my daemon's, then the api return fail error */
-int companion_group_join(companion_group_h group, companion_group_finish_cb callback, void *user_data);
+int companion_group_join(companion_group_h group, companion_group_find_finish_cb callback, void *user_data);
 /* companion_group_join : leave from remote group. if group handle is my daemon's, then the api return fail error */
-int companion_group_leave(companion_group_h group, companion_group_finish_cb callback, void *user_data);
+int companion_group_leave(companion_group_h group, companion_group_find_finish_cb callback, void *user_data);
 /* companion_group_delete : remove group. if group handle is remote group, then the api return fail error */
 int companion_group_delete(companion_group_h group);
 int companion_group_merge(companion_group_h dest_group, companion_group_h src_group);
@@ -48,18 +51,18 @@ int companion_group_get_member_devices(companion_group_h group, companion_device
 
 /* companion_group_device_find : Find the group devices on the network. (exclude myself) */
 int companion_device_find(int timeout, companion_device_found_cb found_cb,
-       companion_group_finish_cb finish_cb, void *user_data);
+       companion_device_find_finish_cb finish_cb, void *user_data);
 
 /* companion_group_join : join to remote group. if group handle is my daemon's, then the api return fail error */
 int companion_device_get_found_devices(companion_device_h **devices, int *count);
 
 /* companion_group_device_invite : Invite a remote group device to my group. */
 int companion_device_invite(companion_group_h group,
-       companion_device_h device, char *PIN, companion_group_finish_cb callback, void *user_data);
+       companion_device_h device, char *PIN, companion_device_invite_result_cb callback, void *user_data);
 
 /* companion_group_device_eject : Eject a remote group device from my group. */
 int companion_device_eject(companion_group_h group,
-       companion_device_h device, companion_group_finish_cb callback, void *user_data);
+       companion_device_h device, companion_device_eject_result_cb callback, void *user_data);
 
 /* Group Information Module */
 int companion_group_information_get_type(companion_group_h group, companion_group_type_e *type);
index 1e42f5f4ee528951d7bea6d84f3206d6628380c8..6e0e0a498a9f81b48ece921df980872e08159b1d 100755 (executable)
@@ -46,20 +46,41 @@ typedef struct _companion_device_t
        char *device_type;
 } companion_device_t;
 
-typedef struct _group_event_cb_t {
+typedef struct _group_found_cb_t {
         companion_group_found_cb found_cb;
-                 companion_group_finish_cb finish_cb;
         void *user_data;
-} group_event_cb_t;
+} group_found_cb_t;
+group_found_cb_t group_found_cb;
 
-typedef struct _device_event_cb_t {
+typedef struct _device_found_cb_t {
         companion_device_found_cb found_cb;
-                 companion_group_finish_cb finish_cb;
         void *user_data;
-} device_event_cb_t;
+} device_found_cb_t;
+device_found_cb_t device_found_cb;
 
-static __thread GSList *group_event_cb_list = NULL;
-static __thread GSList *device_event_cb_list = NULL;
+typedef struct _group_find_finish_cb_t {
+        companion_group_find_finish_cb finish_cb;
+        void *user_data;
+} group_find_finish_cb_t;
+group_find_finish_cb_t group_find_finish_cb;
+
+typedef struct _device_find_finish_cb_t {
+        companion_device_find_finish_cb finish_cb;
+        void *user_data;
+} device_find_finish_cb_t;
+device_find_finish_cb_t device_find_finish_cb;
+
+typedef struct _device_invite_result_cb_t {
+        companion_device_invite_result_cb result_cb;
+        void *user_data;
+} device_invite_result_cb_t;
+device_invite_result_cb_t device_invite_result_cb;
+
+typedef struct _device_eject_result_cb_t {
+        companion_device_eject_result_cb result_cb;
+        void *user_data;
+} device_eject_result_cb_t;
+device_eject_result_cb_t device_eject_result_cb;
 
 static companion_group_t *_create_group_handle(char *uri_path, char *device_id,
        char *group_name, char *host_addr, char *resource_type, companion_group_type_e type)
@@ -121,59 +142,66 @@ static void __group_found_cb(Group *object,
        g_variant_iter_free(iter);
 
        group = _create_group_handle(uri_path, device_id, group_name, host_addr, resource_type, type);
+       group_found_cb.found_cb(type, group, group_found_cb.user_data);
+}
 
-       for (GSList *l = group_event_cb_list; l != NULL; l = l->next) {
-               group_event_cb_t *event_s = (group_event_cb_t *)l->data;
-               event_s->found_cb(type, group, event_s->user_data);
-       }
+static void _group_find_finish_cb(Group *object,
+        gint ret, gpointer user_data)
+{
+       group_find_finish_cb.finish_cb(ret, group_find_finish_cb.user_data);
 }
 
 static void __device_found_cb(Group *object,
-        GVariant *va, gpointer user_data)
+        gint count, GVariant *va, gpointer user_data)
 {
        GVariantIter *iter = NULL;
+       GVariantIter *iter_row = NULL;
        const gchar *key;
        GVariant *key_value;
        companion_device_t *device = NULL;
-       char *device_id;
-       char *friendly_name;
-       char *device_type;
 
-       g_variant_get(va, "a{sv}", &iter);
-       while (g_variant_iter_loop(iter, "{sv}", &key, &key_value)) {
-               if (g_strcmp0(key, "UUID") == 0) {
-                       device_id = g_variant_get_string(key_value, NULL);
-               } else if (g_strcmp0(key, "FriendlyName") == 0) {
-                       friendly_name = g_variant_get_string(key_value, NULL);
-               } else if (g_strcmp0(key, "DeviceType") == 0) {
-                       device_type = g_variant_get_string(key_value, NULL);
+       g_variant_get(va, "aa{sv}", &iter);
+       while (g_variant_iter_next(iter, "a{sv}", &iter_row)) {
+               char *device_id;
+               char *friendly_name;
+               char *device_type;
+
+               while (g_variant_iter_loop(iter_row, "{sv}", &key, &key_value)) {
+                       if (g_strcmp0(key, "DeviceID") == 0) {
+                               device_id = g_variant_get_string(key_value, NULL);
+                       } else if (g_strcmp0(key, "FriendlyName") == 0) {
+                               friendly_name = g_variant_get_string(key_value, NULL);
+                       } else if (g_strcmp0(key, "DeviceType") == 0) {
+                               device_type = g_variant_get_string(key_value, NULL);
+                       }
                }
-       }
+               g_variant_iter_free(iter_row);
 
+               device = _create_device_handle(device_id, friendly_name, device_type);
+               device_found_cb.found_cb(device, device_found_cb.user_data);
+       }
        g_variant_iter_free(iter);
+}
 
-       device = _create_device_handle(device_id, friendly_name, device_type);
-
-       for (GSList *l = device_event_cb_list; l != NULL; l = l->next) {
-               device_event_cb_t *event_s = (device_event_cb_t *)l->data;
-               event_s->found_cb(device, event_s->user_data);
-       }
+static void _device_find_finish_cb(Group *object,
+        gint ret, gpointer user_data)
+{
+       device_find_finish_cb.finish_cb(ret, device_find_finish_cb.user_data);
 }
 
-static void _finish_cb(Group *object,
+static void __device_invite_result_cb(Group *object,
         gint ret, gpointer user_data)
 {
-       for (GSList *gl = group_event_cb_list; gl != NULL; gl = gl->next) {
-               group_event_cb_t *event_s = (group_event_cb_t *)gl->data;
-               event_s->finish_cb(ret, event_s->user_data);
-       }
+       device_invite_result_cb.result_cb(ret, device_invite_result_cb.user_data);
+}
 
-       for (GSList *dl = device_event_cb_list; dl != NULL; dl = dl->next) {
-               device_event_cb_t *event_s = (device_event_cb_t *)dl->data;
-               event_s->finish_cb(ret, event_s->user_data);
-       }
+static void __device_eject_result_cb(Group *object,
+        gint ret, gpointer user_data)
+{
+       device_eject_result_cb.result_cb(ret, device_eject_result_cb.user_data);
 }
 
+
 static void _group_proxy_init(void)
 {
        GError *error = NULL;
@@ -187,8 +215,12 @@ static void _group_proxy_init(void)
                 &error);
 
        g_signal_connect(group_proxy, "group-found", G_CALLBACK(__group_found_cb), NULL);
+       g_signal_connect(group_proxy, "group-find-finish", G_CALLBACK(_group_find_finish_cb), NULL);
        g_signal_connect(group_proxy, "device-found", G_CALLBACK(__device_found_cb), NULL);
-       g_signal_connect(group_proxy, "finish", G_CALLBACK(_finish_cb), NULL);
+       g_signal_connect(group_proxy, "device-find-finish", G_CALLBACK(_device_find_finish_cb), NULL);
+       g_signal_connect(group_proxy, "device-invite-result", G_CALLBACK(__device_invite_result_cb), NULL);
+       g_signal_connect(group_proxy, "device-eject-result", G_CALLBACK(__device_eject_result_cb), NULL);
+
 }
 
 static void _group_proxy_deinit(void)
@@ -274,23 +306,15 @@ int companion_group_create(char *group_name)
        return ret;
 }
 
-int companion_group_find(int timeout, companion_group_found_cb found_cb, companion_group_finish_cb finish_cb, void *user_data)
+int companion_group_find(int timeout, companion_group_found_cb found_cb, companion_group_find_finish_cb finish_cb, void *user_data)
 {
        int ret = 0;
        GError *error = NULL;
 
-       /* set event cb */
-       group_event_cb_t *event_t;
-
-       event_t = g_try_new0(group_event_cb_t, 1);
-       if (event_t == NULL)
-                         return -1;
-
-       event_t->found_cb = found_cb;
-       event_t->finish_cb = finish_cb;
-       event_t->user_data = user_data;
-
-       group_event_cb_list = g_slist_prepend(group_event_cb_list, event_t);
+       group_found_cb.found_cb = found_cb;
+       group_find_finish_cb.finish_cb = finish_cb;
+       group_found_cb.user_data = user_data;
+       group_find_finish_cb.user_data = user_data;
 
        /* get groups from daemon using gdbus */
        group_call_find_sync(group_proxy, timeout, &ret, NULL, &error);
@@ -359,23 +383,15 @@ int companion_group_get_found_groups(companion_group_h **groups, int *count)
 }
 
 int companion_device_find(int timeout, companion_device_found_cb found_cb,
-       companion_group_finish_cb finish_cb, void *user_data)
+       companion_device_find_finish_cb finish_cb, void *user_data)
 {
        int ret = 0;
        GError *error = NULL;
 
-       /* set event cb */
-       device_event_cb_t *event_t;
-
-       event_t = g_try_new0(device_event_cb_t, 1);
-       if (event_t == NULL)
-                         return -1;
-
-       event_t->found_cb = found_cb;
-       event_t->finish_cb = finish_cb;
-       event_t->user_data = user_data;
-
-       device_event_cb_list = g_slist_prepend(device_event_cb_list, event_t);
+       device_found_cb.found_cb = found_cb;
+       device_found_cb.user_data = user_data;
+       device_find_finish_cb.finish_cb= finish_cb;
+       device_find_finish_cb.user_data = user_data;
 
        /* get groups from daemon using gdbus */
        group_call_device_find_sync(group_proxy, timeout, &ret, NULL, &error);
@@ -397,9 +413,29 @@ int companion_group_merge(companion_group_h dest_group, companion_group_h src_gr
 }
 
 int companion_device_invite(companion_group_h group,
-       companion_device_h device, char *PIN, companion_group_finish_cb callback, void *user_data)
+       companion_device_h device, char *PIN, companion_device_invite_result_cb result_cb, void *user_data)
+{
+       int ret = 0;
+       GError *error = NULL;
+       companion_device_t *dev = (companion_device_t *)device;
+
+       device_invite_result_cb.result_cb = result_cb;
+       device_invite_result_cb.user_data = user_data;
+
+       group_call_device_invite_sync(group_proxy, dev->device_id, PIN, &ret, NULL, &error);
+}
+
+int companion_device_eject(companion_group_h group,
+       companion_device_h device, companion_device_eject_result_cb result_cb, void *user_data)
 {
+       int ret = 0;
+       GError *error = NULL;
+       companion_device_t *dev = (companion_device_t *)device;
+
+       device_eject_result_cb.result_cb = result_cb;
+       device_eject_result_cb.user_data = user_data;
 
+       group_call_device_eject_sync(group_proxy, dev->device_id, &ret, NULL, &error);
 }
 
 int companion_group_information_get_type(companion_group_h group, companion_group_type_e *type)
index 787c43a92a22a03f748e39a7bcf249c9139b559f..6e007153cc807b6bcd92b4880fb98c5767e6d896 100755 (executable)
                        <arg type="i" name="result" direction="out" />
                </method>
                <method name="DeviceInvite">
-                       <arg type="i" name="group_count" direction="out" />
-                       <arg type="aa{sv}" name="groups" direction="out" />
+                       <arg type="s" name="uuid" direction="in" />
+                       <arg type="s" name="pin" direction="in" />
                        <arg type="i" name="result" direction="out" />
                </method>
                <method name="DeviceEject">
-                       <arg type="i" name="group_count" direction="out" />
-                       <arg type="aa{sv}" name="groups" direction="out" />
+                       <arg type="s" name="uuid" direction="in" />
                        <arg type="i" name="result" direction="out" />
                </method>
+               <method name="GetRemoteDevice">
+                       <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>
-               <signal name="Finish">
+               <signal name="GroupFindFinish">
+                       <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="DeviceFindFinish">
+                       <arg type="i" name="result" direction="out" />
+               </signal>
+               <signal name="DeviceInviteResult">
+                       <arg type="i" name="result" direction="out" />
+               </signal>
+               <signal name="DeviceEjectResult">
                        <arg type="i" name="result" direction="out" />
                </signal>
        </interface>
index b9d264eb5101ff914b5ec6bc66aee23f1a871b6e..5f7e568d93b28858fd8a9d507853ab566b8dcb77 100755 (executable)
@@ -36,7 +36,7 @@ gboolean group_get_remote_device(Group *group, GDBusMethodInvocation *invocation
        gpointer user_data);
 
 void notify_group_found(GVariant *group_data);
-void notify_group_finish(int ret);
+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);
index 89f851ac4dfb2958b480faf745048540cbc46816..94b02ca16d765c24516c2b38295b39c8b9327b5f 100755 (executable)
@@ -129,9 +129,9 @@ void notify_group_found(GVariant *group_data)
        group_emit_group_found(group_dbus_get_object(), group_data);
 }
 
-void notify_group_finish(int ret)
+void notify_group_find_finish(int ret)
 {
-       group_emit_finish(group_dbus_get_object(), ret);
+       group_emit_group_find_finish(group_dbus_get_object(), ret);
 }
 
 void notify_device_found(int device_count, GVariant *device_data)
index 6ab0737ed2369e208a40d35985241a6de619fdfa..92c54b75248dfbf491063085ac91f44595b532da 100755 (executable)
@@ -263,7 +263,7 @@ static gboolean _timeout_cb(gpointer data)
        if (found_device_count > 0)
                ret = 0;
 
-       notify_group_finish(ret);
+       notify_group_find_finish(ret);
 
        return false;
 }
index c00926ed16556b9217d6207c5770ae692d73b8f0..0194923e0fd7cb4458064d63705fdd74c48053dc 100755 (executable)
@@ -56,7 +56,7 @@
                <signal name="GroupFound">
                        <arg type="a{sv}" name="group_info" direction="out" />
                </signal>
-               <signal name="Finish">
+               <signal name="GroupFindFinish">
                        <arg type="i" name="result" direction="out" />
                </signal>
                <signal name="DeviceFound">