From: Jihoon Jung Date: Thu, 18 Jan 2018 09:33:27 +0000 (+0900) Subject: Add get my uuid & device method X-Git-Tag: submit/tizen/20190131.065036~188 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=1bf2280dd095965f4b23706636b20b009eea24a3;p=platform%2Fcore%2Fapi%2Fmulti-device-group.git Add get my uuid & device method --- diff --git a/capi/demo/comp-manager.c b/capi/demo/comp-manager.c old mode 100644 new mode 100755 index a463829..2edb84d --- a/capi/demo/comp-manager.c +++ b/capi/demo/comp-manager.c @@ -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, }, }; diff --git a/capi/include/companion.h b/capi/include/companion.h index 6d784ad..d774327 100755 --- a/capi/include/companion.h +++ b/capi/include/companion.h @@ -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, diff --git a/capi/src/companion.c b/capi/src/companion.c index 41ed89b..91de09f 100644 --- a/capi/src/companion.c +++ b/capi/src/companion.c @@ -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) { diff --git a/capi/src/companion_gdbus.xml b/capi/src/companion_gdbus.xml index 491220a..0b01eff 100644 --- a/capi/src/companion_gdbus.xml +++ b/capi/src/companion_gdbus.xml @@ -103,6 +103,12 @@ + + + + + + diff --git a/src/companion-manager/include/comp_gdbus_group.h b/src/companion-manager/include/comp_gdbus_group.h index b530d5c..70d2e19 100644 --- a/src/companion-manager/include/comp_gdbus_group.h +++ b/src/companion-manager/include/comp_gdbus_group.h @@ -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); diff --git a/src/companion-manager/include/comp_group.h b/src/companion-manager/include/comp_group.h index ca76a35..f929ac8 100755 --- a/src/companion-manager/include/comp_group.h +++ b/src/companion-manager/include/comp_group.h @@ -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(); diff --git a/src/companion-manager/src/comp_gdbus.c b/src/companion-manager/src/comp_gdbus.c index 7fa8673..4d8e699 100644 --- a/src/companion-manager/src/comp_gdbus.c +++ b/src/companion-manager/src/comp_gdbus.c @@ -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' diff --git a/src/companion-manager/src/comp_gdbus_group.c b/src/companion-manager/src/comp_gdbus_group.c index a74b819..ad5c5bf 100644 --- a/src/companion-manager/src/comp_gdbus_group.c +++ b/src/companion-manager/src/comp_gdbus_group.c @@ -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); diff --git a/src/companion-manager/src/comp_group.c b/src/companion-manager/src/comp_group.c index ce82aa0..3793966 100755 --- a/src/companion-manager/src/comp_group.c +++ b/src/companion-manager/src/comp_group.c @@ -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) diff --git a/src/companion-manager/src/comp_mot_agent.c b/src/companion-manager/src/comp_mot_agent.c old mode 100644 new mode 100755 index 419e24e..5b0c4f9 --- a/src/companion-manager/src/comp_mot_agent.c +++ b/src/companion-manager/src/comp_mot_agent.c @@ -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); } } diff --git a/src/companion-manager/src/companion_gdbus.xml b/src/companion-manager/src/companion_gdbus.xml index 491220a..0b01eff 100644 --- a/src/companion-manager/src/companion_gdbus.xml +++ b/src/companion-manager/src/companion_gdbus.xml @@ -103,6 +103,12 @@ + + + + + +