Add get my uuid & device method
authorJihoon Jung <jh8801.jung@samsung.com>
Thu, 18 Jan 2018 09:33:27 +0000 (18:33 +0900)
committersaerome.kim <saerome.kim@samsung.com>
Mon, 2 Jul 2018 10:38:44 +0000 (19:38 +0900)
capi/demo/comp-manager.c [changed mode: 0644->0755]
capi/include/companion.h
capi/src/companion.c
capi/src/companion_gdbus.xml
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 [changed mode: 0644->0755]
src/companion-manager/src/companion_gdbus.xml

old mode 100644 (file)
new mode 100755 (executable)
index a463829..2edb84d
@@ -42,15 +42,20 @@ static char message[MENU_DATA_SIZE + 1] = "Hello World!!";
 
 int run_get_my_id(MManager *mm, struct menu_data *menu)
 {
-       msg("");
-#if 0
-       ret = companion_device_my_deviceid(&devices, &count);
+       msg("Get Device ID of my device");
+
+       int ret;
+       char *uuid;
+       ret = companion_device_get_my_uuid(&uuid);
+
        if (COMP_ERROR_NONE != ret) {
                msgr("Failed to Get My Device ID: [%s(0x%X)]", comp_error_to_string(ret), ret);
                return RET_FAILURE;
        }
+
        msg(" - companion_device_my_deviceid() ret: [0x%X] [%s]", ret, comp_error_to_string(ret));
-#endif
+       msgb("[ID] : [%s]", uuid);
+
        return RET_SUCCESS;
 }
 
@@ -447,29 +452,29 @@ static int run_devices_find(MManager *mm, struct menu_data *menu)
        return RET_SUCCESS;
 }
 
-int run_device_get_found_mine(MManager *mm, struct menu_data *menu)
+int run_device_get_my_device(MManager *mm, struct menu_data *menu)
 {
        int ret = 0;
        int count = 0;
-       companion_device_h *devices = NULL;
+       companion_device_h device = NULL;
 
-       msg("");
-#if 0
-       ret = companion_device_get_found_my_devices(&devices, &count);
+       msg("Get My Device");
+
+       ret = companion_device_get_my_device(&device);
        if (COMP_ERROR_NONE != ret) {
-               msgr("Failed to Get Found My Devices: [%s(0x%X)]", comp_error_to_string(ret), ret);
+               msgr("Failed to Get My Device: [%s(0x%X)]", comp_error_to_string(ret), ret);
                return RET_FAILURE;
        }
-       msg(" - companion_device_get_found_my_devices() ret: [0x%X] [%s]", ret, comp_error_to_string(ret));
-#endif
-       for (int i = 0; i < count; i++) {
+       msg(" - companion_device_get_my_device() ret: [0x%X] [%s]", ret, comp_error_to_string(ret));
+
+       if (ret == 0) {
                char *device_id = NULL;
                char *friendly_name = NULL;
                char *device_type = NULL;
 
-               companion_device_information_get_device_id(devices[i], &device_id);
-               companion_device_information_get_friendly_name(devices[i], &friendly_name);
-               companion_device_information_get_device_type(devices[i], &device_type);
+               companion_device_information_get_device_id(device, &device_id);
+               companion_device_information_get_friendly_name(device, &friendly_name);
+               companion_device_information_get_device_type(device, &device_type);
 
                msgb("\n[ID] %s [IP] %s [Ver] %s", device_id, friendly_name, device_type);
 
@@ -509,31 +514,6 @@ bool _device_found_mine_cb(companion_device_h device, void *user_data)
        return TRUE;
 }
 
-static int run_devices_find_mine(MManager *mm, struct menu_data *menu)
-{
-       int ret;
-       int duration;
-       msg("Find Devices");
-
-       if (strlen(timeout))
-               duration = (unsigned short)strtol(timeout, NULL, 10);
-#if 0
-       ret = companion_device_find_mine(duration, _device_found_mine_cb, _device_finish_cb, NULL);
-       if (COMP_ERROR_NONE != ret) {
-               msgr("Failed to Find My Devices: [%s(0x%X)]", comp_error_to_string(ret), ret);
-               return RET_FAILURE;
-       }
-       msg(" - companion_device_find_mine() ret: [0x%X] [%s]", ret, comp_error_to_string(ret));
-#endif
-       if (my_devices_list) {
-               g_list_free_full(my_devices_list, _destroy_comp_device_info);
-               my_devices_list = NULL;
-       }
-
-       return RET_SUCCESS;
-}
-
-
 static void _group_leave_finish_cb(int result, void *user_data)
 {
     msgb("leave operation finished");
@@ -856,12 +836,6 @@ static struct menu_data menu_group_eject_device[] = {
        { NULL, NULL, },
 };
 
-static struct menu_data menu_my_devices_find[] = {
-       { "0", "Timeout", NULL, NULL, timeout },
-       { "1", "Run", NULL, run_devices_find_mine, NULL },
-       { NULL, NULL, },
-};
-
 static struct menu_data menu_send_data[] = {
        { "0", "Message", NULL, NULL, message },
        { "1", "Send (Broadcast)", NULL, run_send_data, NULL },
@@ -882,8 +856,7 @@ struct menu_data menu_comp_manager[] = {
        { "10", "Get Found Devices", NULL, run_device_get_found, NULL },
        { "11", "Invite Device", menu_group_invite_device, NULL, NULL },
        { "12", "Eject Device", menu_group_eject_device, NULL, NULL },
-       { "13", "Find My Devices", menu_my_devices_find, NULL, NULL },
-       { "14", "Get Found My Devices", NULL, run_device_get_found_mine, NULL },
-       { "13", "Send Message", menu_send_data, NULL, NULL },
+       { "13", "Get My Device", NULL, run_device_get_my_device, NULL },
+       { "14", "Send Message", menu_send_data, NULL, NULL },
        { NULL, NULL, },
 };
index 6d784ad254aa29fdf73792fc381066395831ae97..d77432799f8fa93044a8337bce6a47ce0927cf2b 100755 (executable)
@@ -82,6 +82,9 @@ int companion_device_invite(companion_group_h group,
 int companion_device_eject(companion_group_h group,
        companion_device_h device, companion_device_eject_result_cb callback, void *user_data);
 
+int companion_device_get_my_device(companion_device_h *device);
+int companion_device_get_my_uuid(char **uuid);
+
 /* Group Information Module */
 int companion_group_information_create(companion_group_h* group);
 int companion_group_information_clone(companion_group_h dst,
index 41ed89b02e8e06c46a570166e6b6c5a948adff25..91de09f649f994674787664c5001a39925067dd8 100644 (file)
@@ -520,6 +520,50 @@ int companion_device_get_found_devices(companion_device_h **devices, int *count)
        return ret;
 }
 
+int companion_device_get_my_device(companion_device_h *device)
+{
+       int ret = 0;
+       GError *error = NULL;
+       GVariant *va = NULL;
+       GVariantIter *iter = NULL;
+       const gchar *key;
+       GVariant *key_value;
+       char *deviceid;
+       char *addr;
+       char *ver;
+
+       group_call_get_my_mowned_device_sync(group_proxy, &va, NULL, &error);
+
+       g_variant_get(va, "a{sv}", &iter);
+       while (g_variant_iter_loop(iter, "{sv}", &key, &key_value)) {
+               if (g_strcmp0(key, "DeviceID") == 0) {
+                       deviceid = (char *)g_variant_get_string(key_value, NULL);
+               } else if (g_strcmp0(key, "Address") == 0) {
+                       addr = (char *)g_variant_get_string(key_value, NULL);
+               } else if (g_strcmp0(key, "SecVer") == 0) {
+                       ver = (char *)g_variant_get_string(key_value, NULL);
+               }
+       }
+
+       if (deviceid == NULL || addr == NULL || ver == NULL)
+               return -1;
+
+       *device = (companion_device_h)_create_device_handle(deviceid, addr, ver);
+
+       g_variant_iter_free(iter);
+
+       return ret;
+}
+int companion_device_get_my_uuid(char **uuid)
+{
+       int ret = 0;
+       GError *error = NULL;
+
+       group_call_get_my_uuid_sync(group_proxy, uuid, NULL, &error);
+
+       return ret;
+}
+
 /* group merge */
 int companion_group_merge(companion_group_h dest_group, companion_group_h src_group)
 {
index 491220ac160473eb316951f07839711d13feadae..0b01eff386f1e7bd3ce51cbcfd4b21d045aebdca 100644 (file)
                        <arg type="i" name="device_count" direction="out" />
                        <arg type="aa{sv}" name="device_info" direction="out" />
                </method>
+               <method name="GetMyMownedDevice">
+                       <arg type="a{sv}" name="device_info" direction="out" />
+               </method>
+               <method name="GetMyUuid">
+                       <arg type="s" name="uuid" direction="out" />
+               </method>
                <!-- Signal (D-Bus) definitions -->
                <signal name="GroupFound">
                        <arg type="a{sv}" name="group_info" direction="out" />
index b530d5ca25fe1d658b99387785580615073d50f1..70d2e19adbd5e3057516450248643a6ad63de580 100644 (file)
@@ -61,6 +61,12 @@ gboolean group_find_mowned_devices(Group *group,
 gboolean group_get_mowned_device(Group *group,
        GDBusMethodInvocation *invocation, gpointer user_data);
 
+gboolean group_get_my_mowned_device(Group *group,
+       GDBusMethodInvocation *invocation, gpointer user_data);
+
+gboolean group_get_my_uuid(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);
index ca76a35b6ec87ff15406ba35801b1fdcc7876fda..f929ac8c120cfec5834eb980f11c4d3dbe0ecbd1 100755 (executable)
@@ -93,6 +93,8 @@ 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();
+GVariant *comp_group_get_my_mowned_devices();
+void comp_group_change_mowned_device(comp_mot_device_t *device);
 
 /* Join to remote device group */
 int comp_group_join();
index 7fa8673547bd8c31fee56310d4d8bc4e6aba0f1f..4d8e6996178611395d17b3b6167cbb89c2f5f4f3 100644 (file)
@@ -104,6 +104,16 @@ static bool __group_init(GDBusConnection *connection)
                G_CALLBACK(group_get_mowned_device),
                NULL);
 
+       g_signal_connect(group_skeleton,
+               "handle-get-my-mowned-device",
+               G_CALLBACK(group_get_my_mowned_device),
+               NULL);
+
+       g_signal_connect(group_skeleton,
+               "handle-get-my-uuid",
+               G_CALLBACK(group_get_my_uuid),
+               NULL);
+
        group = g_dbus_object_manager_server_new(COMP_DBUS_GROUP_PATH);
 
        // Set connection to 'manager'
index a74b8191f71dd0f0c8a09d3a2f9b60b4bbd21461..ad5c5bff3c400a2fe282c720dbc6738e0be4dd28 100644 (file)
@@ -263,6 +263,32 @@ gboolean group_get_mowned_device(Group *group,
        return TRUE;
 }
 
+gboolean group_get_my_mowned_device(Group *group,
+       GDBusMethodInvocation *invocation, gpointer user_data)
+{
+       GVariant *device_data;
+
+       LOG_DEBUG("get mowned device called using dbus successful");
+
+       device_data = comp_group_get_my_mowned_devices();
+       LOG_DEBUG("get mowned device called end ");
+
+       group_complete_get_my_mowned_device(group, invocation, device_data);
+
+       return TRUE;
+}
+
+gboolean group_get_my_uuid(Group *group,
+       GDBusMethodInvocation *invocation, gpointer user_data)
+{
+       LOG_DEBUG("get my uuid called using dbus successful");
+
+       comp_context_t *comp_ctx = comp_context_get_context();
+       group_complete_get_my_uuid(group, invocation, comp_ctx->device_uuid);
+
+       return TRUE;
+}
+
 void notify_group_found(GVariant *group_data)
 {
        group_emit_group_found(group_dbus_get_object(), group_data);
index ce82aa07c98114951b00a373c0052499e6f7c82e..3793966c13fbe781d4d5c8d62c37cfc5ca77a2e4 100755 (executable)
@@ -7,6 +7,7 @@ GList *found_group_list;
 GList *mot_enb_dev_list = NULL;
 GList *mowned_dev_list = NULL;
 comp_group_invite_info_t *group_invite_info = NULL;
+comp_mot_device_t *my_device = NULL;
 
 /* Called when daemon is start. */
 int comp_group_initialize()
@@ -498,6 +499,54 @@ GVariant *comp_group_get_mowned_devices()
        return group_data;
 }
 
+void comp_group_change_mowned_device(comp_mot_device_t *device)
+{
+       LOG_BEGIN();
+
+       my_device = device;
+
+       LOG_END();
+}
+
+GVariant *comp_group_get_my_mowned_devices()
+{
+       GVariantBuilder builder;
+       GVariant *group_data;
+
+       g_variant_builder_init(&builder, G_VARIANT_TYPE("a{sv}"));
+
+       if (my_device != NULL) {
+               g_variant_builder_add(&builder, "{sv}", "DeviceID",
+                                                         g_variant_new_string(my_device->device_id));
+               g_variant_builder_add(&builder, "{sv}", "Adapter",
+                                                         g_variant_new_int32(my_device->adapter));
+               g_variant_builder_add(&builder, "{sv}", "Flags",
+                                                         g_variant_new_int32(my_device->flags));
+               g_variant_builder_add(&builder, "{sv}", "Port",
+                                                         g_variant_new_uint16(my_device->port));
+               g_variant_builder_add(&builder, "{sv}", "Address",
+                                                         g_variant_new_string(my_device->addr));
+               g_variant_builder_add(&builder, "{sv}", "Ifindex",
+                                                         g_variant_new_int32(my_device->ifindex));
+               g_variant_builder_add(&builder, "{sv}", "RouteData",
+                                                         g_variant_new_string(my_device->route_data));
+               g_variant_builder_add(&builder, "{sv}", "ConnType",
+                                                         g_variant_new_int32(my_device->conn_type));
+               g_variant_builder_add(&builder, "{sv}", "SecurePort",
+                                                         g_variant_new_uint16(my_device->secure_port));
+               g_variant_builder_add(&builder, "{sv}", "TcpPort",
+                                                         g_variant_new_uint16(my_device->tcp_port));
+               g_variant_builder_add(&builder, "{sv}", "SecVer",
+                                                         g_variant_new_string(my_device->sec_ver));
+               g_variant_builder_add(&builder, "{sv}", "DeviceStatus",
+                                                         g_variant_new_int32(my_device->dev_status));
+       }
+
+       group_data = g_variant_builder_end(&builder);
+
+       return group_data;
+}
+
 int comp_group_get_mowned_device_count()
 {
        if (mowned_dev_list)
old mode 100644 (file)
new mode 100755 (executable)
index 419e24e..5b0c4f9
@@ -455,6 +455,7 @@ static gboolean __perform_remove_cred_at_local(gpointer data)
        return FALSE;
 }
 
+
 static void _agent_signal_handler(GDBusConnection *connection,
                const gchar *sender_name, const gchar *object_path, const gchar *interface_name,
                const gchar *signal_name, GVariant *parameters, gpointer userdata)
@@ -555,7 +556,8 @@ static void _agent_signal_handler(GDBusConnection *connection,
                                mot_enb_devs_cnt += 1;
                                comp_group_add_new_mot_device(device);
                        } else {
-                               LOG_DEBUG("It is my device. Ignore it.");
+                               LOG_DEBUG("It is my mowned device. Store the mowned device in daemon");
+                               comp_group_change_mowned_device(device);
                        }
                }
 
@@ -648,7 +650,8 @@ static void _agent_signal_handler(GDBusConnection *connection,
                                mowned_devs_cnt += 1;
                                comp_group_add_new_mowned_device(device);
                        } else {
-                               LOG_DEBUG("It is my device. Ignore it.");
+                               LOG_DEBUG("It is my mowned device. Store the mowned device in daemon");
+                               comp_group_change_mowned_device(device);
                        }
                }
 
index 491220ac160473eb316951f07839711d13feadae..0b01eff386f1e7bd3ce51cbcfd4b21d045aebdca 100644 (file)
                        <arg type="i" name="device_count" direction="out" />
                        <arg type="aa{sv}" name="device_info" direction="out" />
                </method>
+               <method name="GetMyMownedDevice">
+                       <arg type="a{sv}" name="device_info" direction="out" />
+               </method>
+               <method name="GetMyUuid">
+                       <arg type="s" name="uuid" direction="out" />
+               </method>
                <!-- Signal (D-Bus) definitions -->
                <signal name="GroupFound">
                        <arg type="a{sv}" name="group_info" direction="out" />