From: Jihoon Jung Date: Fri, 29 Jun 2018 08:00:55 +0000 (+0900) Subject: Add mdg send data using channel id X-Git-Tag: submit/tizen/20190131.065036~16 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=d90af7063abee4c3981e8c222ab25b57774cabac;p=platform%2Fcore%2Fapi%2Fmulti-device-group.git Add mdg send data using channel id Signed-off-by: Jihoon Jung --- diff --git a/include/mdg.h b/include/mdg.h index a0157fb..18f858f 100755 --- a/include/mdg.h +++ b/include/mdg.h @@ -776,8 +776,8 @@ int mdg_device_find(mdg_h handle, int timeout, bool is_invited, mdg_device_found_cb found_cb, mdg_device_find_finish_cb finish_cb, void *user_data); -typedef void (*mdg_channel_cb)(int result, mdg_device_h device, char *channel_id, - unsigned char *arg, int len, void *user_data); +typedef void (*mdg_channel_cb)(int result, char *device_id, char *channel_id, + unsigned char *data, int data_length, void *user_data); /* Server Side */ int mdg_device_regist_channel(mdg_h handle, char *channel_id, diff --git a/src/mdg.c b/src/mdg.c index 208e3f1..5a1d7a5 100755 --- a/src/mdg.c +++ b/src/mdg.c @@ -170,12 +170,6 @@ EXPORT_API int mdg_device_find(mdg_h handle, int timeout, bool is_invited, return ret; } -typedef struct _channel_cb_s { - char *channel_id; - mdg_channel_cb cb; - void *user_data; -} channel_cb_s; - /** * Companion Manager CAPI */ @@ -317,7 +311,7 @@ EXPORT_API int mdg_device_send_data(mdg_h handle, _handle->send_data_finish_cb.user_data = user_data; group_call_send_data_sync(_handle->group_proxy, dev->device_id, dev->addr, - dev->secure_port, params, &ret, NULL, &error); + dev->secure_port, channel_id, params, &ret, NULL, &error); if (error) { _ERR("Failed DBus call [%s]", error->message); g_error_free(error); diff --git a/src/mdg_dbus.c b/src/mdg_dbus.c index 6388850..20201fe 100755 --- a/src/mdg_dbus.c +++ b/src/mdg_dbus.c @@ -107,6 +107,27 @@ static void __event_cb(Group *object, } else { _ERR("The callback not exists"); } + } else if (event_type == MDGD_EVENT_RECEIVE_DATA) { + char *device_id; + char *channel_id; + unsigned char *data; + int data_len; + + mdg_get_data_from_variant(va, &device_id, &channel_id, &data, &data_len); + + channel_cb_s *channel = NULL; + + GSList *l; + for (l = handle->channel_cb_list; l != NULL; l = l->next) { + channel_cb_s *tmp_channel = (channel_cb_s *)l->data; + if (g_strcmp0(tmp_channel->channel_id, channel_id) == 0) + channel = tmp_channel; + } + + if (channel != NULL) { + channel->cb(0, device_id, channel_id, data, data_len, channel->user_data); + } + } else { _ERR("Unknown Event"); } diff --git a/src/mdg_gdbus.xml b/src/mdg_gdbus.xml index 7b418db..57e2a0f 100755 --- a/src/mdg_gdbus.xml +++ b/src/mdg_gdbus.xml @@ -60,6 +60,7 @@ + diff --git a/src/mdg_private.h b/src/mdg_private.h index 821c123..78a667d 100755 --- a/src/mdg_private.h +++ b/src/mdg_private.h @@ -187,6 +187,12 @@ typedef struct _mdg_device_s { mdg_device_type_e type; /**< Device Type */ } mdg_device_s; +typedef struct _channel_cb_s { + char *channel_id; + mdg_channel_cb cb; + void *user_data; +} channel_cb_s; + typedef enum { MDG_EVENT_GROUP_FOUND = 0, MDG_EVENT_GROUP_FIND_FINISH, @@ -196,7 +202,8 @@ typedef enum { MDG_EVENT_EJECT_DEVICE_FINISH, MDG_EVENT_REQUEST_FINISH, MDG_EVENT_SEND_DATA_FINISH, - MDG_EVENT_REQ_CHANNEL_LIST_FINISH + MDG_EVENT_REQ_CHANNEL_LIST_FINISH, + MDGD_EVENT_RECEIVE_DATA, } mdg_event_type_e; #endif /* __TIZEN_NETWORK_COMMON_MDG_PRIVATE_H__ */ diff --git a/src/mdg_util.c b/src/mdg_util.c index 5acd4e2..abea395 100755 --- a/src/mdg_util.c +++ b/src/mdg_util.c @@ -148,4 +148,36 @@ void mdg_get_channel_from_variant(GVariant *va, char **device_id, char **channel g_variant_iter_free(iter); } +void mdg_get_data_from_variant(GVariant *va, char **device_id, char **channel_id, + unsigned char **data, int *data_len) +{ + GVariantIter *iter = NULL; + const gchar *key; + GVariant *key_value = NULL; + GVariant *data_va; + GVariantIter *data_iter = NULL; + unsigned char byte_data; + + g_variant_get(va, "a{sv}", &iter); + while (g_variant_iter_loop(iter, "{sv}", &key, &key_value)) { + if (g_strcmp0(key, "DeviceID") == 0) + *device_id = (char *)g_variant_get_string(key_value, NULL); + else if (g_strcmp0(key, "ChannelID") == 0) + *channel_id = (char *)g_variant_get_string(key_value, NULL); + else if (g_strcmp0(key, "Data") == 0) + data_va = g_variant_get_variant(key_value); + else if (g_strcmp0(key, "DataLength") == 0) + *data_len = g_variant_get_int32(key_value); + } + + int i = 0; + *data = (unsigned char *)g_try_malloc0(*data_len + 1); + + g_variant_get(data_va, "a(y)", &data_iter); + while (g_variant_iter_loop(data_iter, "(y)", &byte_data)) { + (*data)[i++] = byte_data; + } + + g_variant_iter_free(iter); +} diff --git a/src/mdg_util.h b/src/mdg_util.h index 878feef..8ad2bcc 100755 --- a/src/mdg_util.h +++ b/src/mdg_util.h @@ -28,6 +28,8 @@ extern "C" mdg_device_s *mdg_get_device_from_variant(GVariant *va); mdg_group_s *mdg_get_group_from_variant(GVariant *va); void mdg_get_channel_from_variant(GVariant *va, char **device_id, char **channel_id); +void mdg_get_data_from_variant(GVariant *va, char **device_id, char **channel_id, + unsigned char **data, int *data_len); #ifdef __cplusplus } diff --git a/test/mdg-manager.c b/test/mdg-manager.c index 537c48a..96141e2 100755 --- a/test/mdg-manager.c +++ b/test/mdg-manager.c @@ -30,7 +30,7 @@ mdg_h handle = NULL; GList *found_group_list; GList *found_device_list; -GList *invited_device_list; +GList *found_invited_device_list; GList *found_channel_list; static char groupid[MENU_DATA_SIZE + 1] = "mygroup"; @@ -287,7 +287,7 @@ static int run_invited_devices_show(MManager *mm, struct menu_data *menu) /* Get a first item */ i = 0; - iter = g_list_first(invited_device_list); + iter = g_list_first(found_invited_device_list); while (NULL != iter) { device = iter->data; if (!device) { @@ -735,8 +735,8 @@ static int __send_data(int devidx, int chaidx) char *address = NULL; mdg_device_h device = NULL; channel_t *channel = NULL; - if (found_device_list) { - device = g_list_nth_data(found_device_list, devidx - 1); + if (found_invited_device_list) { + device = g_list_nth_data(found_invited_device_list, devidx - 1); if (NULL == device) { msgr("Find local device first"); return RET_FAILURE; @@ -775,7 +775,7 @@ static int run_send_data(MManager *mm, struct menu_data *menu) { int devidx = 0; int chaidx = 0; - int count = g_list_length(found_device_list); + int count = g_list_length(found_invited_device_list); if (0 >= count) { msgr("No Device"); @@ -823,7 +823,7 @@ bool _invited_device_found_cb(mdg_device_h device, void *user_data) if (addr) free(addr); - invited_device_list = g_list_append(invited_device_list, device); + found_invited_device_list = g_list_append(found_invited_device_list, device); return TRUE; } @@ -848,9 +848,9 @@ static int run_devices_find_invited_device(MManager *mm, struct menu_data *menu) msg(" - mdg_device_find_invited_device() ret: [0x%X] [%s]", ret, mdg_error_to_string(ret)); - if (invited_device_list) { - g_list_free_full(invited_device_list, _destroy_mdg_device_info); - invited_device_list = NULL; + if (found_invited_device_list) { + g_list_free_full(found_invited_device_list, _destroy_mdg_device_info); + found_invited_device_list = NULL; } return RET_SUCCESS; @@ -864,7 +864,7 @@ static int run_request_create_group(MManager *mm, struct menu_data *menu) msg("Request create group"); - dev_count = g_list_length(found_device_list); + dev_count = g_list_length(found_invited_device_list); if (0 >= dev_count) { msgr("No Device"); @@ -880,8 +880,8 @@ static int run_request_create_group(MManager *mm, struct menu_data *menu) } } - if (found_device_list) { - device = g_list_nth_data(found_device_list, dev_idx - 1); + if (found_invited_device_list) { + device = g_list_nth_data(found_invited_device_list, dev_idx - 1); if (NULL == device) { msgr("Failed to g_hash_table_find"); return RET_FAILURE; @@ -910,7 +910,7 @@ static int run_request_invite(MManager *mm, struct menu_data *menu) mdg_device_h device = NULL; mdg_group_h group = NULL; - dev_count = g_list_length(found_device_list); + dev_count = g_list_length(found_invited_device_list); grp_count = g_list_length(found_group_list); if (0 >= dev_count || 0 >= grp_count) { @@ -944,8 +944,8 @@ static int run_request_invite(MManager *mm, struct menu_data *menu) } } - if (found_device_list) { - device = g_list_nth_data(found_device_list, dev_idx - 1); + if (found_invited_device_list) { + device = g_list_nth_data(found_invited_device_list, dev_idx - 1); if (NULL == device) { msgr("Failed to g_hash_table_find"); return RET_FAILURE; @@ -973,7 +973,7 @@ static int run_request_eject(MManager *mm, struct menu_data *menu) mdg_device_h device = NULL; mdg_group_h group = NULL; - dev_count = g_list_length(found_device_list); + dev_count = g_list_length(found_invited_device_list); grp_count = g_list_length(found_group_list); if (0 >= dev_count || 0 >= grp_count) { @@ -1007,8 +1007,8 @@ static int run_request_eject(MManager *mm, struct menu_data *menu) } } - if (found_device_list) { - device = g_list_nth_data(found_device_list, dev_idx - 1); + if (found_invited_device_list) { + device = g_list_nth_data(found_invited_device_list, dev_idx - 1); if (NULL == device) { msgr("Failed to g_hash_table_find"); return RET_FAILURE; @@ -1046,7 +1046,7 @@ static int run_request_channel_list(MManager *mm, struct menu_data *menu) int dev_count = 0; mdg_device_h device = NULL; - dev_count = g_list_length(found_device_list); + dev_count = g_list_length(found_invited_device_list); if (0 >= dev_count) { msgr("No Device"); @@ -1062,8 +1062,8 @@ static int run_request_channel_list(MManager *mm, struct menu_data *menu) } } - if (found_device_list) { - device = g_list_nth_data(found_device_list, dev_idx - 1); + if (found_invited_device_list) { + device = g_list_nth_data(found_invited_device_list, dev_idx - 1); if (NULL == device) { msgr("Failed to g_hash_table_find"); return RET_FAILURE; @@ -1081,10 +1081,11 @@ static int run_request_channel_list(MManager *mm, struct menu_data *menu) return RET_SUCCESS; } -void __channel_cb(int result, mdg_device_h device, char *channel_id, +void __channel_cb(int result, char *device_id, char *channel_id, unsigned char *arg, int len, void *user_data) { - msg("[%s] channel callback is called by remote send message", channel_id); + msg("[%s] channel callback is called by [%s]'s send message", channel_id, device_id); + msg("arg : %s, len : %d", arg, len); msg("result is %d", result); } @@ -1155,7 +1156,7 @@ static struct menu_data menu_group_eject_device[] = { }; static struct menu_data menu_send_data[] = { - { "0", "Show My Owned Device(s)", NULL, run_invited_devices_show, NULL }, + { "0", "Show Found Invited Device(s)", NULL, run_invited_devices_show, NULL }, { "1", "Show Channel List", NULL, run_channels_show, NULL }, { "2", "Message", NULL, NULL, message }, { "3", "Device Index", NULL, NULL, device_idx }, @@ -1171,7 +1172,7 @@ static struct menu_data menu_devices_find_invited_device[] = { }; static struct menu_data menu_request_create_group[] = { - { "0", "Show Found Device(s)", NULL, run_devices_show, NULL }, + { "0", "Show Found Invited Device(s)", NULL, run_invited_devices_show, NULL }, { "1", "Device Index", NULL, NULL, device_idx }, { "2", "Request Group Name", NULL, NULL, request_groupid }, { "3", "Run", NULL, run_request_create_group, NULL }, @@ -1180,7 +1181,7 @@ static struct menu_data menu_request_create_group[] = { static struct menu_data menu_request_invite[] = { { "0", "Show Found Group(s)", NULL, run_group_show, NULL }, - { "1", "Show Found Device(s)", NULL, run_devices_show, NULL }, + { "1", "Show Found Invited Device(s)", NULL, run_invited_devices_show, NULL }, { "2", "Group Index", NULL, NULL, group_idx }, { "3", "Device Index", NULL, NULL, device_idx }, { "4", "PIN", NULL, NULL, pin }, @@ -1190,7 +1191,7 @@ static struct menu_data menu_request_invite[] = { static struct menu_data menu_request_eject[] = { { "0", "Show Found Group(s)", NULL, run_group_show, NULL }, - { "1", "Show Found Device(s)", NULL, run_devices_show, NULL }, + { "1", "Show Found Invited Device(s)", NULL, run_invited_devices_show, NULL }, { "2", "Group Index", NULL, NULL, group_idx }, { "3", "Device Index", NULL, NULL, device_idx }, { "4", "Run", NULL, run_request_eject, NULL }, @@ -1198,7 +1199,7 @@ static struct menu_data menu_request_eject[] = { }; static struct menu_data menu_request_channel_list[] = { - { "0", "Show Found Device(s)", NULL, run_devices_show, NULL }, + { "0", "Show Found Invited Device(s)", NULL, run_invited_devices_show, NULL }, { "1", "Device Index", NULL, NULL, device_idx }, { "2", "Run", NULL, run_request_channel_list, NULL }, { NULL, NULL, },