From: Jihoon Jung Date: Thu, 28 Jun 2018 10:34:12 +0000 (+0900) Subject: Add req channel list X-Git-Tag: submit/tizen/20190131.065036~17 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=9b663b39fe5be705e28eb3aabad9387d611cf0c9;p=platform%2Fcore%2Fapi%2Fmulti-device-group.git Add req channel list Signed-off-by: Jihoon Jung --- diff --git a/include/mdg.h b/include/mdg.h index 15fd796..a0157fb 100755 --- a/include/mdg.h +++ b/include/mdg.h @@ -97,7 +97,7 @@ typedef void *mdg_device_h; /**< Device handle */ */ /** - * @brief Group hande. + * @brief Group handle. * * @since_tizen 5.0 */ @@ -440,6 +440,8 @@ int mdg_group_eject_device(mdg_h handle, mdg_group_h group, typedef void (*mdg_request_result_cb)(char *cmd, char *device_id, unsigned char *arg, int len, int ret, void *user_data); +typedef void (*mdg_request_channel_list_finish_cb)(char *device_id, char *channel_id, void *user_data); + /** * @brief Requests to create a group. * @details We can create a group. This generated group can include device, and remote @@ -534,7 +536,7 @@ int mdg_request_eject_device(mdg_h handle, mdg_group_h group, mdg_device_h device, mdg_request_result_cb cb, void *user_data); int mdg_request_channel_list(mdg_h handle, mdg_device_h device, - mdg_request_result_cb cb, void *user_data); + mdg_request_channel_list_finish_cb finish_cb, void *user_data); /** * @} diff --git a/src/mdg.c b/src/mdg.c index 18e06c0..208e3f1 100755 --- a/src/mdg.c +++ b/src/mdg.c @@ -898,15 +898,12 @@ EXPORT_API int mdg_request_eject_device(mdg_h handle, return ret; } -EXPORT_API int mdg_request_channel_list(mdg_h handle, mdg_device_h device, mdg_request_result_cb cb, - void *user_data) +EXPORT_API int mdg_request_channel_list(mdg_h handle, mdg_device_h device, + mdg_request_channel_list_finish_cb finish_cb, void *user_data) { int ret = MDG_ERROR_NONE; GError *error = NULL; - NOTUSED(cb); - NOTUSED(user_data); - CHECK_FEATURE_SUPPORTED(MDG_FEATURE); mdg_manager_s *_handle = handle; @@ -915,6 +912,8 @@ EXPORT_API int mdg_request_channel_list(mdg_h handle, mdg_device_h device, mdg_r mdg_device_s *dev = (mdg_device_s *)device; mdg_check_null_ret_error("device", device, MDG_ERROR_INVALID_PARAMETER); + _handle->request_channel_list_finish_cb.finish_cb = finish_cb; + _handle->request_channel_list_finish_cb.user_data = user_data; _DBG("%s", dev->device_id); diff --git a/src/mdg_dbus.c b/src/mdg_dbus.c index b7a250f..6388850 100755 --- a/src/mdg_dbus.c +++ b/src/mdg_dbus.c @@ -96,6 +96,17 @@ static void __event_cb(Group *object, } else { _ERR("The callback not exists"); } + } else if (event_type == MDG_EVENT_REQ_CHANNEL_LIST_FINISH) { + char *device_id; + char *channel_id; + + mdg_get_channel_from_variant(va, &device_id, &channel_id); + if (handle->request_channel_list_finish_cb.finish_cb) { + handle->request_channel_list_finish_cb.finish_cb(device_id, channel_id, + handle->request_channel_list_finish_cb.user_data); + } else { + _ERR("The callback not exists"); + } } else { _ERR("Unknown Event"); } diff --git a/src/mdg_private.h b/src/mdg_private.h old mode 100644 new mode 100755 index 6bc4beb..821c123 --- a/src/mdg_private.h +++ b/src/mdg_private.h @@ -126,6 +126,11 @@ typedef struct _request_result_cb_t { void *user_data; /**< User data pointer */ } request_result_cb_t; +typedef struct _request_channel_list_finish_cb_t { + mdg_request_channel_list_finish_cb finish_cb; /**< User callback to be called */ + void *user_data; /**< User data pointer */ +} request_channel_list_finish_cb_t; + /** * @brief The mdg-manager context * @since_tizen 5.0 @@ -144,6 +149,7 @@ typedef struct _mdg_manager_s { device_eject_finish_cb_t device_eject_finish_cb; /**< When it called after ejecting the device done or timeout */ send_data_finish_cb_t send_data_finish_cb; /**< When it called after sending the device done or timeout */ request_result_cb_t request_result_cb; /**< When it called after sending private commands or timeout */ + request_channel_list_finish_cb_t request_channel_list_finish_cb; /**< When it called after sending private commands or timeout */ } mdg_manager_s; #define CHECK_HANDLE_IS_VALID(handle) { \ @@ -190,6 +196,7 @@ typedef enum { MDG_EVENT_EJECT_DEVICE_FINISH, MDG_EVENT_REQUEST_FINISH, MDG_EVENT_SEND_DATA_FINISH, + MDG_EVENT_REQ_CHANNEL_LIST_FINISH } mdg_event_type_e; #endif /* __TIZEN_NETWORK_COMMON_MDG_PRIVATE_H__ */ diff --git a/src/mdg_util.c b/src/mdg_util.c index 09d94bd..5acd4e2 100755 --- a/src/mdg_util.c +++ b/src/mdg_util.c @@ -132,3 +132,20 @@ mdg_device_s *mdg_get_device_from_variant(GVariant *va) return device; } +void mdg_get_channel_from_variant(GVariant *va, char **device_id, char **channel_id) +{ + GVariantIter *iter = NULL; + const gchar *key; + GVariant *key_value = NULL; + + 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); + } + + g_variant_iter_free(iter); +} + diff --git a/src/mdg_util.h b/src/mdg_util.h index aaed549..878feef 100755 --- a/src/mdg_util.h +++ b/src/mdg_util.h @@ -27,6 +27,7 @@ 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); #ifdef __cplusplus } diff --git a/test/mdg-manager.c b/test/mdg-manager.c index 930d048..537c48a 100755 --- a/test/mdg-manager.c +++ b/test/mdg-manager.c @@ -31,12 +31,14 @@ mdg_h handle = NULL; GList *found_group_list; GList *found_device_list; GList *invited_device_list; +GList *found_channel_list; static char groupid[MENU_DATA_SIZE + 1] = "mygroup"; static char request_groupid[MENU_DATA_SIZE + 1] = "subgroup"; static char timeout[MENU_DATA_SIZE + 1] = "2"; static char group_idx[MENU_DATA_SIZE + 1] = "1"; static char device_idx[MENU_DATA_SIZE + 1] = "1"; +static char channel_idx[MENU_DATA_SIZE + 1] = "1"; static char pin[MENU_DATA_SIZE + 1] = "12341234"; static char message[MENU_DATA_SIZE + 1] = "Hello World!!"; static char channel_id[MENU_DATA_SIZE + 1] = "Channel1"; @@ -314,6 +316,38 @@ static int run_invited_devices_show(MManager *mm, struct menu_data *menu) return RET_SUCCESS; } +typedef struct _channel_t { + char *device_id; /**< User callback to be called */ + char *channel_id; /**< User data pointer */ +} channel_t; + +static int run_channels_show(MManager *mm, struct menu_data *menu) +{ + channel_t *channel; + + int i; + GList *iter = NULL; + + /* Get a first item */ + i = 0; + iter = g_list_first(found_channel_list); + while (NULL != iter) { + channel = iter->data; + if (!channel) { + msgr("channel is null"); + break; + } + + msgp("[%d] device id : %s, channel id : %s,", i+1, channel->device_id, channel->channel_id); + + /* Next item */ + iter = g_list_next(iter); + i++; + } + + return RET_SUCCESS; +} + #if 0 static int run_group_get_members(MManager *mm, struct menu_data *menu) { @@ -694,24 +728,32 @@ void _send_data_finish_cb(int result, void *user_data) msgb("\rFind Send Data Finished = %d", result); } -static int __send_data(int idx) +static int __send_data(int devidx, int chaidx) { int ret = 0; char *deviceid = NULL; char *address = NULL; mdg_device_h device = NULL; - + channel_t *channel = NULL; if (found_device_list) { - device = g_list_nth_data(found_device_list, idx - 1); + device = g_list_nth_data(found_device_list, devidx - 1); if (NULL == device) { msgr("Find local device first"); return RET_FAILURE; } } + if (found_channel_list) { + channel = g_list_nth_data(found_channel_list, chaidx - 1); + if (NULL == channel) { + msgr("Find local device first"); + return RET_FAILURE; + } + } + mdg_device_info_get_device_id(device, &deviceid); mdg_device_info_get_addr(device, &address); - msgp("Sent to [ID] %s [ADDR] %s", deviceid, address); + msgp("Sent to [ID] %s [ADDR] %s [CHANNEL ID] %s", deviceid, address, channel->channel_id); if (deviceid) { free(deviceid); deviceid = NULL; @@ -721,7 +763,7 @@ static int __send_data(int idx) address = NULL; } - ret = mdg_device_send_data(handle, device, channel_id, (unsigned char *)message, + ret = mdg_device_send_data(handle, device, channel->channel_id, (unsigned char *)message, strlen(message), _send_data_finish_cb, NULL); if (MDG_ERROR_NONE != ret) msgr("Failed to Send Data: [ID] %s [IP] %s", deviceid, address); @@ -731,7 +773,8 @@ static int __send_data(int idx) static int run_send_data(MManager *mm, struct menu_data *menu) { - int idx = 0; + int devidx = 0; + int chaidx = 0; int count = g_list_length(found_device_list); if (0 >= count) { @@ -740,13 +783,20 @@ static int run_send_data(MManager *mm, struct menu_data *menu) } if (strlen(device_idx)) { - idx = (unsigned short)strtol(device_idx, NULL, 10); - if (0 >= idx) { + devidx = (unsigned short)strtol(device_idx, NULL, 10); + if (0 >= devidx) { msgp("Invalid index. set to 1"); - idx = 1; + devidx = 1; } } - return __send_data(idx); + if (strlen(channel_idx)) { + chaidx = (unsigned short)strtol(channel_idx, NULL, 10); + if (0 >= chaidx) { + msgp("Invalid index. set to 1"); + chaidx = 1; + } + } + return __send_data(devidx, chaidx); } void _invited_device_finish_cb(int result, void *user_data) @@ -977,6 +1027,19 @@ static int run_request_eject(MManager *mm, struct menu_data *menu) return RET_SUCCESS; } +void __req_channel_list_finish_cb(char *device_id, char *channel_id, void *user_data) +{ + msgp("\rDevice ID : [%s], Channel ID : [%s]", device_id, channel_id); + + channel_t *channel = g_new0(channel_t, 1); + channel->device_id = g_strdup(device_id); + channel->channel_id = g_strdup(channel_id); + + found_channel_list = g_list_append(found_channel_list, channel); + + return; +} + static int run_request_channel_list(MManager *mm, struct menu_data *menu) { int ret = 0; @@ -1007,7 +1070,7 @@ static int run_request_channel_list(MManager *mm, struct menu_data *menu) } } - ret = mdg_request_channel_list(handle, device, receive_request_result, NULL); + ret = mdg_request_channel_list(handle, device, __req_channel_list_finish_cb, NULL); if (MDG_ERROR_NONE != ret) { msgr("Failed to Request Eject: [%s(0x%X)]", mdg_error_to_string(ret), ret); return RET_FAILURE; @@ -1093,10 +1156,11 @@ 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 }, - { "1", "Message", NULL, NULL, message }, - { "2", "Channel Name", NULL, NULL, channel_id }, + { "1", "Show Channel List", NULL, run_channels_show, NULL }, + { "2", "Message", NULL, NULL, message }, { "3", "Device Index", NULL, NULL, device_idx }, - { "4", "Send", NULL, run_send_data, NULL }, + { "4", "Channel Index", NULL, NULL, channel_idx }, + { "5", "Send", NULL, run_send_data, NULL }, { NULL, NULL, }, };