Add request result callback
authorJihoon Jung <jh8801.jung@samsung.com>
Thu, 25 Jan 2018 11:22:20 +0000 (20:22 +0900)
committersaerome.kim <saerome.kim@samsung.com>
Mon, 2 Jul 2018 10:38:47 +0000 (19:38 +0900)
Signed-off-by: Jihoon Jung <jh8801.jung@samsung.com>
capi/demo/comp-manager.c [changed mode: 0644->0755]
capi/include/companion.h [changed mode: 0644->0755]
capi/src/companion.c [changed mode: 0644->0755]
capi/src/companion_gdbus.xml [changed mode: 0644->0755]
src/companion-manager/include/comp_gdbus_group.h [changed mode: 0644->0755]
src/companion-manager/src/comp_gdbus_group.c [changed mode: 0644->0755]
src/companion-manager/src/comp_group.c [changed mode: 0644->0755]
src/companion-manager/src/comp_iot.c [changed mode: 0644->0755]
src/companion-manager/src/companion_gdbus.xml [changed mode: 0644->0755]

old mode 100644 (file)
new mode 100755 (executable)
index c21a2c8..0cd1097
@@ -41,6 +41,37 @@ static char device_idx[MENU_DATA_SIZE + 1] = "1";
 static char pin[MENU_DATA_SIZE + 1] = "12341234";
 static char message[MENU_DATA_SIZE + 1] = "Hello World!!";
 
+static int run_group_find(MManager *mm, struct menu_data *menu);
+static int run_devices_find(MManager *mm, struct menu_data *menu);
+
+void _request_result_cb(char *cmd, char *arg, int ret, void *user_data)
+{
+       msg("_request_result_cb is called");
+
+       if (cmd != NULL) {
+               if (strcmp("1", cmd) == 0) {
+                       msgb("[CMD] Request Create Group [%s(0x%X)]", comp_error_to_string(ret), ret);
+                       if (ret == 0 && arg != NULL) {
+                               msgb("Created Group name is %s", arg);
+                               run_group_find(NULL, NULL);
+                               run_devices_find(NULL, NULL);
+                       }
+               } else if (strcmp("2", cmd) == 0) {
+                       msgb("[CMD] Request Invite [%s(0x%X)]", comp_error_to_string(ret), ret);
+                       if (ret == 0 && arg != NULL)
+                               msgb("Invited Device ID is %s", arg);
+               } else if (strcmp("3", cmd) == 0) {
+                       msgb("[CMD] Request Eject [%s(0x%X)]", comp_error_to_string(ret), ret);
+                       if (ret == 0 && arg != NULL)
+                               msgb("Ejected Device ID is %s", arg);
+               } else if (strcmp("4", cmd) == 0) {
+                       msgb("[CMD] Request Delete Group [%s(0x%X)]", comp_error_to_string(ret), ret);
+                       if (ret == 0 && arg != NULL)
+                               msgb("Deleted Group name is %s", arg);
+               }
+       }
+}
+
 int run_get_my_id(MManager *mm, struct menu_data *menu)
 {
        msg("Get Device ID of my device");
@@ -49,6 +80,8 @@ int run_get_my_id(MManager *mm, struct menu_data *menu)
        char *uuid;
        ret = companion_device_get_my_uuid(&uuid);
 
+       companion_request_result_callback(_request_result_cb, NULL);
+
        if (COMP_ERROR_NONE != ret) {
                msgr("Failed to Get My Device ID: [%s(0x%X)]", comp_error_to_string(ret), ret);
                return RET_FAILURE;
@@ -390,7 +423,7 @@ int run_device_show_found(MManager *mm, struct menu_data *menu)
                companion_device_information_get_ip(devices[i], &ip);
                companion_device_information_get_device_type(devices[i], &device_type);
 
-               msgp("\n[ID] %s [IP] %s [Ver] %s", device_id, ip, device_type);
+               msgb("\n[ID] %s [IP] %s [Ver] %s", device_id, ip, device_type);
 
                if (device_id)
                        free(device_id);
old mode 100644 (file)
new mode 100755 (executable)
index 718bf31..33e6055
@@ -41,6 +41,7 @@ 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);
 typedef void (*companion_send_data_finish_cb)(int result, char *resp_data, void *user_data);
+typedef void (*companion_request_result_cb)(char *cmd, char *arg, int ret, void *user_data);
 
 /* Management Module APIs*/
 int companion_initialize(); /* initialize gdbus connection with manager daemon */
@@ -117,6 +118,7 @@ int companion_request_create_group(companion_device_h device, char *group_name);
 int companion_request_invite(companion_group_h group, companion_device_h device, char *PIN);
 int companion_request_eject(companion_group_h group, companion_device_h device);
 int companion_request_delete_group(companion_group_h group);
+int companion_request_result_callback(companion_request_result_cb callback, void *user_data);
 
 
 #ifdef __cplusplus
old mode 100644 (file)
new mode 100755 (executable)
index 4e0f928..457ee9a
@@ -91,6 +91,12 @@ typedef struct _send_data_finish_cb_t {
 } send_data_finish_cb_t;
 send_data_finish_cb_t send_data_finish_cb;
 
+typedef struct _request_result_cb_t {
+        companion_request_result_cb result_cb;
+        void *user_data;
+} request_result_cb_t;
+request_result_cb_t request_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)
 {
@@ -228,6 +234,13 @@ static void __send_data_finish_cb(Group *object,
                send_data_finish_cb.finish_cb(ret, resp_data, send_data_finish_cb.user_data);
 }
 
+static void __request_result_cb(Group *object,
+        gchar *cmd, gchar *arg, gint ret, gpointer user_data)
+{
+       if (request_result_cb.result_cb)
+               request_result_cb.result_cb(cmd, arg, ret, request_result_cb.user_data);
+}
+
 static void _group_proxy_init(void)
 {
        GError *error = NULL;
@@ -248,6 +261,7 @@ static void _group_proxy_init(void)
        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);
        g_signal_connect(group_proxy, "send-data-finish", G_CALLBACK(__send_data_finish_cb), NULL);
+       g_signal_connect(group_proxy, "request-result", G_CALLBACK(__request_result_cb), NULL);
 }
 
 static void _enabler_proxy_init(void)
@@ -964,3 +978,9 @@ int companion_request_delete_group(companion_group_h group)
 
 }
 
+int companion_request_result_callback(companion_request_result_cb result_cb, void *user_data)
+{
+       request_result_cb.result_cb = result_cb;
+       request_result_cb.user_data = user_data;
+}
+
old mode 100644 (file)
new mode 100755 (executable)
index c6e9c85..b895ecb
                        <arg type="s" name="resp_data" direction="out" />
                        <arg type="i" name="result" direction="out" />
                </signal>
+               <signal name="RequestResult">
+                       <arg type="s" name="command" direction="out" />
+                       <arg type="s" name="arg" direction="out" />
+                       <arg type="i" name="result" direction="out" />
+               </signal>
        </interface>
 </node>
old mode 100644 (file)
new mode 100755 (executable)
index 83da7b1..4e9538b
@@ -88,5 +88,6 @@ void notify_group_device_eject_result(int ret);
 void notify_mowned_device_found(int device_count, GVariant *device_data);
 void notify_group_join(int result);
 void notify_send_data_finish(char *resp_data, int ret);
+void notify_request_result(char *cmd, char *arg, int ret);
 
 #endif
old mode 100644 (file)
new mode 100755 (executable)
index f8e9be3..35581b2
@@ -380,3 +380,8 @@ void notify_send_data_finish(char *resp_data, int ret)
        group_emit_send_data_finish(group_dbus_get_object(), resp_data, ret);
 }
 
+void notify_request_result(char *cmd, char *arg, int ret)
+{
+       group_emit_request_result(group_dbus_get_object(), cmd, arg, ret);
+}
+
old mode 100644 (file)
new mode 100755 (executable)
index 5971d20..f957a9e
@@ -463,7 +463,7 @@ int comp_group_invite(char *group_name, char *uuid, char *pin)
 #endif
 
        if (comp_group_add_device_in_group(group_name, uuid) < 0)
-               return COMP_ERROR_UNKNOWN;
+               return COMP_ERROR_NONE;
 
        LOG_END();
 
old mode 100644 (file)
new mode 100755 (executable)
index 1ce2098..a1e656c
@@ -99,6 +99,9 @@ static void _request_handler(iotcon_resource_h resource, iotcon_request_h reques
 
                if (IOTCON_ERROR_NONE == ret && query) {
                        char *command;
+                       char *arg = NULL;
+                       int result;
+
                        iotcon_query_lookup(query, "CMD", &command);
 
                        if (strcmp(command, "1") == 0) {
@@ -106,8 +109,8 @@ static void _request_handler(iotcon_resource_h resource, iotcon_request_h reques
                                char *group_name;
                                iotcon_query_lookup(query, "name", &group_name);
 
-                               comp_group_find_mot_enabled_devices(7);
-                               comp_group_create(group_name);
+                               result = comp_group_create(group_name);
+                               arg = g_strdup(group_name);
                        } else if (strcmp(command, "2") == 0) {
                                LOG_DEBUG("Request invite");
                                char *group_name;
@@ -116,9 +119,10 @@ static void _request_handler(iotcon_resource_h resource, iotcon_request_h reques
                                iotcon_query_lookup(query, "name", &group_name);
                                iotcon_query_lookup(query, "id", &uuid);
 
-                               LOG_DEBUG("group_name : %s, UUID : %s");
+                               LOG_DEBUG("group_name : %s, UUID : %s", group_name, uuid);
 
-                               comp_group_invite(group_name, uuid, "12341234");
+                               result = comp_group_invite(group_name, uuid, "12341234");
+                               arg = g_strdup(uuid);
                        } else if (strcmp(command, "3") == 0) {
                                LOG_DEBUG("Request eject");
                                char *group_name;
@@ -129,11 +133,14 @@ static void _request_handler(iotcon_resource_h resource, iotcon_request_h reques
 
                                LOG_DEBUG("group_name : %s, UUID : %s", group_name, uuid);
 
-                               comp_group_dismiss(group_name, uuid);
+                               result = comp_group_dismiss(group_name, uuid);
+                               arg = g_strdup(uuid);
                        } else if (strcmp(command, "4") == 0) {
                                LOG_DEBUG("Request delete group");
-
+                               arg = g_strdup("DELETED");
                        }
+
+                       notify_request_result(command, arg, result);
                }
 
                ret = iotcon_response_create(request, &response);
old mode 100644 (file)
new mode 100755 (executable)
index c6e9c85..b895ecb
                        <arg type="s" name="resp_data" direction="out" />
                        <arg type="i" name="result" direction="out" />
                </signal>
+               <signal name="RequestResult">
+                       <arg type="s" name="command" direction="out" />
+                       <arg type="s" name="arg" direction="out" />
+                       <arg type="i" name="result" direction="out" />
+               </signal>
        </interface>
 </node>