From b15f58346f0c778c1c069ddbf3f6a53aeb337499 Mon Sep 17 00:00:00 2001 From: Saurav Babu Date: Mon, 7 May 2018 14:36:55 +0530 Subject: [PATCH 01/16] Implemented mdg_group_delete to delete local groups Signed-off-by: Saurav Babu --- src/mdg.c | 16 ++++++++++++++-- src/mdg_gdbus.xml | 5 ++--- test/mdg-manager.c | 2 +- 3 files changed, 17 insertions(+), 6 deletions(-) diff --git a/src/mdg.c b/src/mdg.c index 65294a5..b4c3301 100644 --- a/src/mdg.c +++ b/src/mdg.c @@ -640,11 +640,23 @@ EXPORT_API int mdg_group_merge(mdg_h hadnle, EXPORT_API int mdg_group_delete(mdg_h handle, mdg_group_h group) { int ret = MDG_ERROR_NONE; + GError *error = NULL; CHECK_FEATURE_SUPPORTED(MDG_FEATURE); - NOTUSED(handle); - NOTUSED(group); + mdg_manager_s *_handle = handle; + mdg_check_null_ret_error("handle", handle, MDG_ERROR_INVALID_PARAMETER); + + mdg_group_s *grp = (mdg_group_s *)group; + mdg_check_null_ret_error("grp", grp, MDG_ERROR_INVALID_PARAMETER); + + group_call_delete_sync(_handle->group_proxy, grp->group_name, &ret, NULL, + &error); + if (error) { + _ERR("Failed DBus call [%s]", error->message); + g_error_free(error); + ret = MDG_ERROR_IO_ERROR; + } return ret; } diff --git a/src/mdg_gdbus.xml b/src/mdg_gdbus.xml index 5aa4c1e..e7535bf 100644 --- a/src/mdg_gdbus.xml +++ b/src/mdg_gdbus.xml @@ -32,9 +32,8 @@ - - - + + diff --git a/test/mdg-manager.c b/test/mdg-manager.c index 46fd594..ba5670f 100644 --- a/test/mdg-manager.c +++ b/test/mdg-manager.c @@ -1355,7 +1355,7 @@ struct menu_data menu_mdg_manager[] = { { "4", "Show Found Group(s)", NULL, run_group_show_found , NULL }, { "5", "Join Group (Not yet developed)", menu_group_join, NULL, NULL }, { "6", "Leave Group (Not yet developed)", menu_group_leave, NULL, NULL }, - { "7", "Delete Group (Not yet developed)", menu_group_delete, NULL, NULL }, + { "7", "Delete Group", menu_group_delete, NULL, NULL }, { "8", "Find Device(s)", menu_devices_find, NULL, NULL }, { "9", "Show Found Device(s)", NULL, run_device_show_found, NULL }, { "10", "Invite Device", menu_group_invite_device, NULL, NULL }, -- 2.7.4 From 1cf6c6e75d5c313534c54f71ed33856d4cf45d03 Mon Sep 17 00:00:00 2001 From: "saerome.kim" Date: Wed, 9 May 2018 18:25:09 +0900 Subject: [PATCH 02/16] Fixed svace issues. Signed-off-by: saerome.kim --- src/mdg.c | 5 +++-- src/mdg_dbus.c | 17 +++++++++++------ src/mdg_util.c | 42 ++++++++++++++++++++++++++++++++++++++++++ src/mdg_util.h | 1 + test/mdg-manager.c | 30 +++++++++++++++--------------- 5 files changed, 72 insertions(+), 23 deletions(-) mode change 100644 => 100755 src/mdg.c mode change 100644 => 100755 src/mdg_dbus.c mode change 100644 => 100755 src/mdg_util.c mode change 100644 => 100755 src/mdg_util.h mode change 100644 => 100755 test/mdg-manager.c diff --git a/src/mdg.c b/src/mdg.c old mode 100644 new mode 100755 index b4c3301..482c4f1 --- a/src/mdg.c +++ b/src/mdg.c @@ -98,6 +98,7 @@ EXPORT_API int mdg_deinitialize(mdg_h handle) /* LCOV_EXCL_START */ _DBG("all connections closed\n"); ref_count = 0; + MDG_UNLOCK; return ret; /* LCOV_EXCL_STOP */ } @@ -921,10 +922,10 @@ EXPORT_API int mdg_device_info_clone(mdg_device_h target, CHECK_FEATURE_SUPPORTED(MDG_FEATURE); - mdg_device_s * dst = (mdg_device_s *)target; + mdg_device_s *dst = (mdg_device_s *)target; mdg_check_null_ret_error("target", target, MDG_ERROR_INVALID_PARAMETER); - mdg_device_s * src = (mdg_device_s *)source; + mdg_device_s *src = (mdg_device_s *)source; mdg_check_null_ret_error("source", source, MDG_ERROR_INVALID_PARAMETER); ret = mdg_device_info_create(&target); diff --git a/src/mdg_dbus.c b/src/mdg_dbus.c old mode 100644 new mode 100755 index 510374f..1f59604 --- a/src/mdg_dbus.c +++ b/src/mdg_dbus.c @@ -214,6 +214,7 @@ static void __mowned_device_found_cb(Group *object, gint count, GVariant *va, if (handle->mowned_device_found_cb.found_cb) handle->mowned_device_found_cb.found_cb(device, handle->mowned_device_found_cb.user_data); + destroy_device_handle(device); } g_variant_iter_free(iter); } @@ -283,14 +284,18 @@ static void __request_result_cb(Group *object, gchar *cmd, gchar *device_id, g_variant_get(arg, "(iay)", &len, &iter); data = g_try_malloc0(len + 1); + if (data) { + data = NULL; + len = 0; + } else { + while (g_variant_iter_loop(iter, "y", &data[length])) + length += 1; - while (g_variant_iter_loop(iter, "y", &data[length])) - length += 1; + data[length > len ? len : length] = '\0'; + _DBG("Received result length %d data %s", len, data); - data[length] = '\0'; - _DBG("Received result length %d data %s", len, data); - - g_variant_iter_free(iter); + g_variant_iter_free(iter); + } if (handle->request_result_cb.result_cb) handle->request_result_cb.result_cb(cmd, device_id, data, len, ret, diff --git a/src/mdg_util.c b/src/mdg_util.c old mode 100644 new mode 100755 index bc91fb5..1593e6c --- a/src/mdg_util.c +++ b/src/mdg_util.c @@ -147,3 +147,45 @@ CREATE_DEVICE_HANDLER_ERROR: return NULL; /* LCOV_EXCL_STOP */ } + +void destroy_device_handle(mdg_device_s *device) +{ + if (NULL == device) { + /* LCOV_EXCL_START */ + _ERR("Memory allocation failed"); + return; + /* LCOV_EXCL_STOP */ + } + + if (device->device_id) { + free(device->device_id); + device->device_id = NULL; + } + if (device->model_name) { + free(device->model_name); + device->model_name = NULL; + } + if (device->device_name) { + free(device->device_name); + device->device_name = NULL; + } + if (device->platform_ver) { + free(device->platform_ver); + device->platform_ver = NULL; + } + if (device->vendor_id) { + free(device->vendor_id); + device->vendor_id = NULL; + } + if (device->profile) { + free(device->profile); + device->profile = NULL; + } + if (device->ip) { + free(device->ip); + device->ip = NULL; + } + free(device); + device = NULL; +} + diff --git a/src/mdg_util.h b/src/mdg_util.h old mode 100644 new mode 100755 index 39d5d6e..56c8843 --- a/src/mdg_util.h +++ b/src/mdg_util.h @@ -30,6 +30,7 @@ mdg_group_s *create_group_handle(char *uri_path, char *device_id, mdg_device_s *create_device_handle(char *device_id, char *ip, int device_type, int port, int sec_port, char *model_name, char *device_name, char *platform_ver, char *vendor_id, char *profile); +void destroy_device_handle(mdg_device_s *device); #ifdef __cplusplus } diff --git a/test/mdg-manager.c b/test/mdg-manager.c old mode 100644 new mode 100755 index ba5670f..a299e0a --- a/test/mdg-manager.c +++ b/test/mdg-manager.c @@ -127,7 +127,7 @@ void _device_eject_result_cb(int result, void *user_data) static int run_device_eject(MManager *mm, struct menu_data *menu) { int ret; - int idx; + int idx = 1; mdg_group_h group = NULL; mdg_device_h device = NULL; @@ -186,7 +186,7 @@ void _device_invite_result_cb(int result, void *user_data) static int run_device_invite(MManager *mm, struct menu_data *menu) { int ret; - int idx; + int idx = 1; mdg_group_h group = NULL; mdg_device_h device = NULL; @@ -414,8 +414,8 @@ static int run_group_merge(MManager *mm, struct menu_data *menu) static int run_group_delete(MManager *mm, struct menu_data *menu) { int ret; - int idx; - mdg_group_h group; + int idx = 1; + mdg_group_h group = NULL; msg("Delete Group"); @@ -533,7 +533,7 @@ bool _device_found_cb(mdg_device_h device, void *user_data) static int run_devices_find(MManager *mm, struct menu_data *menu) { int ret; - int duration; + int duration = 2; msg("Find Devices"); if (strlen(timeout)) @@ -595,8 +595,8 @@ int run_device_show_my_device(MManager *mm, struct menu_data *menu) static int run_group_leave(MManager *mm, struct menu_data *menu) { int ret; - int idx; - mdg_group_h group; + int idx = 1; + mdg_group_h group = NULL; msg("Leave Group"); @@ -668,8 +668,8 @@ static int run_group_show(MManager *mm, struct menu_data *menu) static int run_group_join(MManager *mm, struct menu_data *menu) { int ret; - int idx; - mdg_group_h group; + int idx = 1; + mdg_group_h group = NULL; msg("Join Group"); @@ -708,7 +708,7 @@ static int run_group_show_found(MManager *mm, struct menu_data *menu) { int ret; int count; - mdg_group_h *groups; + mdg_group_h *groups = NULL; msg("Show Found Group(s)"); @@ -771,7 +771,7 @@ void _group_finish_cb(int result, void *user_data) static int run_group_find(MManager *mm, struct menu_data *menu) { int ret; - int duration; + int duration = 2; msg("Find Group"); if (strlen(timeout)) @@ -919,7 +919,7 @@ bool _mowned_device_found_cb(mdg_device_h device, void *user_data) static int run_devices_find_mowned_device(MManager *mm, struct menu_data *menu) { int ret; - int duration; + int duration = 2; msg("Find My Owned Devices"); if (strlen(timeout)) @@ -982,6 +982,7 @@ int run_device_show_mowned_device(MManager *mm, struct menu_data *menu) static int run_request_create_group(MManager *mm, struct menu_data *menu) { int ret = 0; + int dev_idx = 1; int dev_count = 0; mdg_device_h device = NULL; @@ -994,7 +995,6 @@ static int run_request_create_group(MManager *mm, struct menu_data *menu) return RET_SUCCESS; } - int dev_idx; if (device_idx != NULL && strlen(device_idx)) { dev_idx = (unsigned short)strtol(device_idx, NULL, 10); if (0 >= dev_idx) { @@ -1028,6 +1028,8 @@ static int run_request_create_group(MManager *mm, struct menu_data *menu) static int run_request_invite(MManager *mm, struct menu_data *menu) { int ret = 0; + int grp_idx = 1; + int dev_idx = 1; int grp_count = 0; int dev_count = 0; mdg_device_h device = NULL; @@ -1041,7 +1043,6 @@ static int run_request_invite(MManager *mm, struct menu_data *menu) return RET_SUCCESS; } - int grp_idx; if (group_idx != NULL && strlen(group_idx)) { grp_idx = (unsigned short)strtol(group_idx, NULL, 10); if (0 >= grp_idx) { @@ -1058,7 +1059,6 @@ static int run_request_invite(MManager *mm, struct menu_data *menu) } } - int dev_idx; if (device_idx != NULL && strlen(device_idx)) { dev_idx = (unsigned short)strtol(device_idx, NULL, 10); if (0 >= dev_idx) { -- 2.7.4 From 038897a41f0d85b3dd817d2671ef0ca0a732e292 Mon Sep 17 00:00:00 2001 From: "saerome.kim" Date: Wed, 9 May 2018 20:13:36 +0900 Subject: [PATCH 03/16] Make 0 length group name not to be made. Signed-off-by: saerome.kim --- src/mdg.c | 2 ++ 1 file changed, 2 insertions(+) mode change 100755 => 100644 src/mdg.c diff --git a/src/mdg.c b/src/mdg.c old mode 100755 new mode 100644 index 482c4f1..a887ffa --- a/src/mdg.c +++ b/src/mdg.c @@ -125,6 +125,8 @@ EXPORT_API int mdg_group_create(mdg_h handle, char *group_name) mdg_manager_s *_handle = handle; mdg_check_null_ret_error("handle", handle, MDG_ERROR_INVALID_PARAMETER); + if (0 == strlen(group_name)) + return MDG_ERROR_INVALID_PARAMETER; /* create group to daemon using gdbus */ group_call_create_sync(_handle->group_proxy, group_name, &ret, NULL, &error); -- 2.7.4 From 99d4254d48466e4423bb8f97c7be93135a2b94f4 Mon Sep 17 00:00:00 2001 From: Jihoon Jung Date: Tue, 26 Jun 2018 20:08:53 +0900 Subject: [PATCH 04/16] Change mdg framework Signed-off-by: Jihoon Jung --- include/mdg.h | 407 ++++-------------------- src/mdg.c | 902 +++++++++++++++++------------------------------------ src/mdg_dbus.c | 369 ++++------------------ src/mdg_dbus.h | 4 + src/mdg_gdbus.xml | 134 ++------ src/mdg_private.h | 77 ++--- src/mdg_util.c | 223 +++++-------- src/mdg_util.h | 8 +- test/common.h | 0 test/main.c | 10 +- test/mdg-manager.c | 741 +++++++++++++++---------------------------- test/mdg-test.c | 489 ----------------------------- test/menu.c | 0 test/menu.h | 0 14 files changed, 798 insertions(+), 2566 deletions(-) mode change 100644 => 100755 src/mdg.c mode change 100644 => 100755 test/common.h mode change 100644 => 100755 test/main.c delete mode 100644 test/mdg-test.c mode change 100644 => 100755 test/menu.c mode change 100644 => 100755 test/menu.h diff --git a/include/mdg.h b/include/mdg.h index 7390100..4ae2b05 100644 --- a/include/mdg.h +++ b/include/mdg.h @@ -71,7 +71,6 @@ typedef enum { MDG_ERROR_PLUGIN_FAIL = TIZEN_ERROR_MDG | 0x08, /**< Plugin failed */ MDG_ERROR_ALREADY_IN_PROGRESS = TIZEN_ERROR_MDG | 0x09, /**< Already in progress */ MDG_ERROR_NOT_STARTED = TIZEN_ERROR_MDG | 0x0A, /**< Not Started */ - MDG_ERROR_ALREADY_INITIALIZED = TIZEN_ERROR_MDG | 0x0B, /**< Already initilized */ MDG_ERROR_UNKNOWN = -999, } mdg_error_e; @@ -158,8 +157,7 @@ int mdg_deinitialize(mdg_h handle); * @since_tizen 5.0 */ typedef enum { - MDG_GROUP_TYPE_ERROR = 0, /**< Error */ - MDG_GROUP_TYPE_MINE = 1, /**< Local group */ + MDG_GROUP_TYPE_LOCAL = 1, /**< Local group */ MDG_GROUP_TYPE_REMOTE = 2, /**< Remote grojp */ } mdg_group_type_e; @@ -203,7 +201,7 @@ typedef bool (*mdg_group_found_cb)(mdg_group_type_e type, typedef void (*mdg_group_find_finish_cb)(int result, void *user_data); /** - * @brief Finds group resources in local and the network. + * @brief Finds group resources in the network. * @details This function is find group resources in the network plus my local network. * * @since_tizen 5.0 @@ -221,7 +219,6 @@ typedef void (*mdg_group_find_finish_cb)(int result, void *user_data); * @retval #MDG_ERROR_INVALID_PARAMETER Invalid parameter * * @see mdg_group_create() - * @see mdg_group_get_found_groups() * */ int mdg_group_find(mdg_h handle, int timeout, @@ -229,30 +226,6 @@ int mdg_group_find(mdg_h handle, int timeout, void *user_data); /** - * @brief Gets a list of group resources. - * @details This function retrieves a list of group resources found. - * - * @since_tizen 5.0 - * @privlevel public - * @privilege %http://tizen.org/privilege/internet - * - * @param[in] handle The multi device group manager handle - * @param[in] groups Group resource list - * @param[out] count Number of groups - * - * - * @return 0 on success, otherwise a negative error value. - * @retval #MDG_ERROR_NONE Successful - * @retval #MDG_ERROR_INVALID_PARAMETER Invalid parameter - * - * @see mdg_group_create() - * @see mdg_group_find() - * - */ -int mdg_group_get_found_groups(mdg_h handle, - mdg_group_h **groups, int *count); - -/** * @} */ @@ -277,7 +250,6 @@ int mdg_group_get_found_groups(mdg_h handle, * @retval #MDG_ERROR_INVALID_PARAMETER Invalid parameter * * @see mdg_group_find() - * @see mdg_group_get_found_groups() * */ int mdg_group_create(mdg_h handle, char *group_name); @@ -353,7 +325,7 @@ int mdg_group_get_member_devices(mdg_h handle, * * @see mdg_group_invite_device() */ -typedef void (*mdg_group_invite_device_result_cb)(int result, void *user_data); +typedef void (*mdg_group_invite_device_finish_cb)(int result, void *user_data); /** * @brief Called after mdg_group_eject_device(). @@ -371,7 +343,7 @@ typedef void (*mdg_group_invite_device_result_cb)(int result, void *user_data); * * @see mdg_group_ejecct_device() */ -typedef void (*mdg_group_eject_device_result_cb)(int result, void *user_data); +typedef void (*mdg_group_eject_device_finish_cb)(int result, void *user_data); /** * @brief Requests to invite a device to the group which local device owns. @@ -403,7 +375,7 @@ typedef void (*mdg_group_eject_device_result_cb)(int result, void *user_data); */ int mdg_group_invite_device(mdg_h handle, mdg_group_h group, mdg_device_h device, char *PIN, - mdg_group_invite_device_result_cb callback, void *user_data); + mdg_group_invite_device_finish_cb callback, void *user_data); /** * @brief Requests to expel the device from the group which local device owns. @@ -432,7 +404,7 @@ int mdg_group_invite_device(mdg_h handle, mdg_group_h group, * */ int mdg_group_eject_device(mdg_h handle, mdg_group_h group, - mdg_device_h device, mdg_group_eject_device_result_cb callback, + mdg_device_h device, mdg_group_eject_device_finish_cb callback, void *user_data); @@ -523,7 +495,7 @@ int mdg_request_join_group(mdg_h handle, mdg_group_h group, * @see mdg_group_get_member_devices() * */ -int mdg_request_leave_group (mdg_h handle, mdg_group_h group, +int mdg_request_leave_group(mdg_h handle, mdg_group_h group, mdg_request_result_cb cb, void *user_data); /** @@ -620,34 +592,6 @@ int mdg_request_eject_device(mdg_h handle, mdg_group_h group, mdg_device_h device, mdg_request_result_cb cb, void *user_data); /** - * @brief Requests to delete the group. - * @details This function deletes a specific group and expels all devices in that group. - * - * @since_tizen 5.0 - * @privlevel public - * @privilege %http://tizen.org/privilege/internet - * - * @param[in] handle The multi device group manager handle - * @param[in] group Group handle - * @param[in] cb Callback handler to receive the result - * @param[in] user_data User data pointer - * - * - * @return 0 on success, otherwise a negative error value. - * @retval #MDG_ERROR_NONE Successful - * @retval #MDG_ERROR_INVALID_PARAMETER Invalid parameter - * - * @see mdg_request_create_group() - * @see mdg_request_invite_device() - * @see mdg_request_eject_device() - * @see mdg_request_result_callback() - * @see mdg_device_send_data() - * - */ -int mdg_request_delete_group(mdg_h handle, mdg_group_h group, - mdg_request_result_cb cb, void *user_data); - -/** * @} */ @@ -680,7 +624,7 @@ int mdg_request_delete_group(mdg_h handle, mdg_group_h group, * @see mdg_group_info_get_host_addr() * */ -int mdg_group_info_clone(mdg_group_h dst, +int mdg_group_info_clone(mdg_group_h *dst, mdg_group_h src); /** @@ -706,6 +650,9 @@ int mdg_group_info_clone(mdg_group_h dst, */ int mdg_group_info_destroy(mdg_group_h group); +int mdg_group_info_get_device_id(mdg_group_h group, char **device_id); +int mdg_group_info_get_host_addr(mdg_group_h group, char **host_addr); + /** * @brief Gets group type of the group handle. * @@ -728,62 +675,7 @@ int mdg_group_info_destroy(mdg_group_h group); * @see mdg_group_info_get_host_addr() * */ -int mdg_group_info_get_type(mdg_group_h group, - mdg_group_type_e *type); - -/** - * @brief Gets resource type of the group handle. - * - * @since_tizen 5.0 - * @privlevel public - * - * @remarks The @a resource_type should be released using free(). - * - * @param[in] group Group handle - * @param[out] resource_type Resource type - * - * @return 0 on success, otherwise a negative error value. - * @retval #MDG_ERROR_NONE Successful - * @retval #MDG_ERROR_INVALID_PARAMETER Invalid parameter - * - * @see mdg_group_info_create() - * @see mdg_group_info_clone() - * @see mdg_group_info_destroy() - * @see mdg_group_info_get_type() - * @see mdg_group_info_get_uri_path() - * @see mdg_group_info_get_name() - * @see mdg_group_info_get_host_addr() - * - */ -int mdg_group_info_get_resource_type( - mdg_group_h group, char **resource_type); - -/** - * @brief Gets URI path of the group handle. - * - * @since_tizen 5.0 - * @privlevel public - * - * @remarks The @a uri_path should be released using free(). - * - * @param[in] group Group handle - * @param[out] uri_path URI path - * - * @return 0 on success, otherwise a negative error value. - * @retval #MDG_ERROR_NONE Successful - * @retval #MDG_ERROR_INVALID_PARAMETER Invalid parameter - * - * @see mdg_group_info_create() - * @see mdg_group_info_clone() - * @see mdg_group_info_destroy() - * @see mdg_group_info_get_type() - * @see mdg_group_info_get_resource_type() - * @see mdg_group_info_get_name() - * @see mdg_group_info_get_host_addr() - * - */ -int mdg_group_info_get_uri_path(mdg_group_h group, - char **uri_path); +int mdg_group_info_get_type(mdg_group_h group, mdg_group_type_e *type); /** * @brief Gets name of the group handle. @@ -809,35 +701,7 @@ int mdg_group_info_get_uri_path(mdg_group_h group, * @see mdg_group_info_get_host_addr() * */ -int mdg_group_info_get_name(mdg_group_h group, - char **name); - -/** - * @brief Gets host address of the group handle. - * - * @since_tizen 5.0 - * @privlevel public - * - * @remarks The @a host_addr should be released using free(). - * - * @param[in] group Group handle - * @param[out] host_addr Host address of the group - * - * @return 0 on success, otherwise a negative error value. - * @retval #MDG_ERROR_NONE Successful - * @retval #MDG_ERROR_INVALID_PARAMETER Invalid parameter - * - * @see mdg_group_info_create() - * @see mdg_group_info_clone() - * @see mdg_group_info_destroy() - * @see mdg_group_info_get_type() - * @see mdg_group_info_get_resource_type() - * @see mdg_group_info_get_name() - * @see mdg_group_info_get_uri_path() - * - */ -int mdg_group_info_get_host_addr(mdg_group_h group, - char **host_addr); +int mdg_group_info_get_name(mdg_group_h group, char **name); /** * @} @@ -855,22 +719,11 @@ int mdg_group_info_get_host_addr(mdg_group_h group, * @since_tizen 5.0 */ typedef enum { - MDG_DEVICE_TYPE_ERROR = 0, /**< Error */ MDG_DEVICE_TYPE_LOCAL = 1, /**< Local device */ MDG_DEVICE_TYPE_REMOTE = 2, /**< Remote device */ } mdg_device_type_e; /** - * @brief Device Status. - * - * @since_tizen 5.0 - */ -typedef enum { - MDG_DEVICE_ADDED = 0, /**< Device Added */ - MDG_DEVICE_REMOVED = 1, /**< Device Removed */ -} mdg_device_status_e; - -/** * @brief Called after mdg_device_find(). * @details This function can receive a device found. * @@ -928,87 +781,33 @@ typedef void (*mdg_device_find_finish_cb)(int result, void *user_data); * * @see mdg_device_send_data() */ -typedef void (*mdg_device_send_data_finish_cb)(int result, char *resp_data, - void *user_data); - -/** - * @brief Callback function pointer to be regsitered after enabling device - * monitor - * - * @since_tizen 5.0 - * @privlevel public - * @privilege %http://tizen.org/privilege/internet - * - * @remarks The @a uuid, @arg should not be released. - * @remarks The @a uuid, @arg can be used only in the callback. To use outside, make a copy. - * @remarks The @a group_name, @arg should not be released. - * @remarks The @a group_name, @arg can be used only in the callback. To use outside, make a copy. - * - * @param[out] uuid Device ID - * @param[out] group_name Group name - * @param[out] status Device Status - * @param[out] user_data User data pointer - * - * @pre The callback must be registered with mdg_request_result_callback() - * - * @see mdg_device_monitor_start() - */ -typedef void (*mdg_device_monitor_result_cb)(char *uuid, char *group_name, - mdg_device_status_e status, void *user_data); +typedef void (*mdg_device_send_data_finish_cb)(int result, void *user_data); /** - * @brief Finds candidate devices to include my groups in the network. - * @details This function will search for candidate devices that can be included in local group. + * @brief Gets my local device handle. + * @details This function returns the local device information handle. * * @since_tizen 5.0 - * @privlevel public - * @privilege %http://tizen.org/privilege/internet - * - * @param[in] handle The multi device group manager handle - * @param[in] timeout Time to find - * @param[in] found_cb Callback handler to retrieve the found device - * @param[in] finish_cb Callback handler to know finding process finished - * @param[in] user_data User data poiter - * - * - * @return 0 on success, otherwise a negative error value. - * @retval #MDG_ERROR_NONE Successful - * @retval #MDG_ERROR_INVALID_PARAMETER Invalid parameter - * - * @see mdg_device_get_found_devices() - * - */ -int mdg_device_find(mdg_h handle, int timeout, - mdg_device_found_cb found_cb, mdg_device_find_finish_cb finish_cb, - void *user_data); - -/** - * @brief Gets a list of candidate devices to can be included my group. - * @details This function retrieves a list of multiple owner enabled devices found. * - * @since_tizen 5.0 - * @privlevel public - * @privilege %http://tizen.org/privilege/internet + * @remarks The @a target should be released using mdg_device_info_destroy(). * * @param[in] handle The multi device group manager handle - * @param[in] devices Device list - * @param[in] count Number of devices - * + * @param[in] device Local device handle * * @return 0 on success, otherwise a negative error value. * @retval #MDG_ERROR_NONE Successful * @retval #MDG_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #MDG_ERROR_NO_DATA No data * - * @see mdg_device_find_mowned_device() + * @see mdg_device_info_get_my_uuid() * */ -int mdg_device_get_found_devices(mdg_h handle, - mdg_device_h **devices, int *count); +int mdg_device_get_local_device(mdg_h handle, + mdg_device_h *device); /** - * @brief Finds my owned devices in the network. - * @details This function looks up devices on your network that are registered as multiple - * owners. + * @brief Finds candidate devices to include my groups in the network. + * @details This function will search for candidate devices that can be included in local group. * * @since_tizen 5.0 * @privlevel public @@ -1025,35 +824,23 @@ int mdg_device_get_found_devices(mdg_h handle, * @retval #MDG_ERROR_NONE Successful * @retval #MDG_ERROR_INVALID_PARAMETER Invalid parameter * - * @see mdg_device_get_found_mowned_devices() - * */ -int mdg_device_find_mowned_device(mdg_h handle, int timeout, +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); -/** - * @brief Gets a list of discovered owned devices. - * @details This function retrieves a list of my owned devices found. - * - * @since_tizen 5.0 - * @privlevel public - * @privilege %http://tizen.org/privilege/internet - * - * @param[in] handle The multi device group manager handle - * @param[in] devices Device list - * @param[in] count Number of devices - * - * - * @return 0 on success, otherwise a negative error value. - * @retval #MDG_ERROR_NONE Successful - * @retval #MDG_ERROR_INVALID_PARAMETER Invalid parameter - * - * @see mdg_device_find_mowned_device() - * - */ -int mdg_device_get_found_mowned_devices(mdg_h handle, - mdg_device_h **devices, int *count); +typedef void (*mdg_channel_cb)(int result, mdg_device_h device, char *channel_id, + unsigned char *arg, int len, void *user_data); + +/* Server Side */ +int mdg_device_regist_channel(mdg_h handle, char *channel_id, + mdg_channel_cb channel_cb, void *user_data); + +int mdg_device_unregist_channel(mdg_h handle, char *channel_id); + +/* Client Side */ +//int mdg_device_get_channels(mdg_h handle, mdg_device_h device, +// mdg_device_get_channels_cb get_channels_cb, void *user_data); /** * @brief Sends data to the remote device. @@ -1082,51 +869,11 @@ int mdg_device_get_found_mowned_devices(mdg_h handle, * @see mdg_request_result_callback() * */ -int mdg_device_send_data(mdg_h handle, mdg_device_h device, +int mdg_device_send_data(mdg_h handle, mdg_device_h device, char *channel_id, unsigned char *data, int len, mdg_device_send_data_finish_cb finish_cb, void *user_data); /** - * @brief Starts monitoring peers in the network. - * - * @since_tizen 5.0 - * @privlevel public - * @privilege %http://tizen.org/privilege/internet - * - * @param[in] handle The multi device group manager handle - * @param[in] cb Callback to be called when receiving keep alive message from peers - * @param[in] user_data User data pointer - * - * @return 0 on success, otherwise a negative error value. - * @retval #MDG_ERROR_NONE Successful - * @retval #MDG_ERROR_INVALID_PARAMETER Invalid parameter - * - * @see mdg_device_monitor_stop() - * - */ -int mdg_device_monitor_start(mdg_h handle, mdg_device_monitor_result_cb cb, - void *user_data); - -/** - * @brief Stops monitoring peers in the network. - * - * @since_tizen 5.0 - * @privlevel public - * @privilege %http://tizen.org/privilege/internet - * - * @param[in] handle The multi device group manager handle - * - * @return 0 on success, otherwise a negative error value. - * @retval #MDG_ERROR_NONE Successful - * @retval #MDG_ERROR_INVALID_PARAMETER Invalid parameter - * - * @see mdg_device_monitor_start() - * - */ -int mdg_device_monitor_stop(mdg_h handle); - - -/** * @} */ @@ -1136,50 +883,6 @@ int mdg_device_monitor_stop(mdg_h handle); */ /** - * @brief Gets my local device ID. - * @details This function returns current UUID of local device. - * - * @since_tizen 5.0 - * - * @remarks The @a uuid should not be released. - * @remarks The @a uuid can be used only in the callback. To use outside, make a copy. - * - * @param[in] handle The multi device group manager handle - * @param[out] uuid Local device UUID - * - * @return 0 on success, otherwise a negative error value. - * @retval #MDG_ERROR_NONE Successful - * @retval #MDG_ERROR_INVALID_PARAMETER Invalid parameter - * - * @see mdg_device_info_get_my_device() - * - */ - -int mdg_device_info_get_my_uuid(mdg_h handle, char **uuid); - -/** - * @brief Gets my local device handle. - * @details This function returns the local device information handle. - * - * @since_tizen 5.0 - * - * @remarks The @a target should be released using mdg_device_info_destroy(). - * - * @param[in] handle The multi device group manager handle - * @param[in] device Local device handle - * - * @return 0 on success, otherwise a negative error value. - * @retval #MDG_ERROR_NONE Successful - * @retval #MDG_ERROR_INVALID_PARAMETER Invalid parameter - * @retval #MDG_ERROR_NO_DATA No data - * - * @see mdg_device_info_get_my_uuid() - * - */ -int mdg_device_info_get_my_device(mdg_h handle, - mdg_device_h *device); - -/** * @brief Clones the device handle. * * @since_tizen 5.0 @@ -1202,7 +905,7 @@ int mdg_device_info_get_my_device(mdg_h handle, * @see mdg_device_info_get_model_name() * */ -int mdg_device_info_clone(mdg_device_h target, +int mdg_device_info_clone(mdg_device_h *target, mdg_device_h source); /** @@ -1276,18 +979,20 @@ int mdg_device_info_get_device_id(mdg_device_h device, * @see mdg_device_info_get_model_name() * */ -int mdg_device_info_get_ip(mdg_device_h device, char **ip); +int mdg_device_info_get_addr(mdg_device_h device, char **addr); +int mdg_device_info_get_port(mdg_device_h device, int *port); +int mdg_device_info_get_secure_port(mdg_device_h device, int *secure_port); /** - * @brief Gets device type of the device handle. + * @brief Gets model name of the device handle. * * @since_tizen 5.0 * @privlevel public * - * @remarks The @a device_type should be released using free(). + * @remarks The @a model_name should be released using free(). * * @param[in] device Device handle - * @param[out] device_type Device type + * @param[out] model_name Model name * * @return 0 on success, otherwise a negative error value. * @retval #MDG_ERROR_NONE Successful @@ -1298,22 +1003,26 @@ int mdg_device_info_get_ip(mdg_device_h device, char **ip); * @see mdg_device_info_destroy() * @see mdg_device_info_get_device_id() * @see mdg_device_info_get_ip() - * @see mdg_device_info_get_model_name() + * @see mdg_device_info_get_device_type() * */ -int mdg_device_info_get_device_type(mdg_device_h device, - mdg_device_type_e *device_type); +int mdg_device_info_get_model_name(mdg_device_h device, char **model_name); +int mdg_device_info_get_device_name(mdg_device_h device, char **device_name); +int mdg_device_info_get_platform_ver(mdg_device_h device, char **platform_ver); +int mdg_device_info_get_vendor_id(mdg_device_h device, char **vendor_id); +int mdg_device_info_get_profile(mdg_device_h device, char **profile); +int mdg_device_info_is_invited(mdg_device_h device, bool *is_invited); /** - * @brief Gets model name of the device handle. + * @brief Gets device type of the device handle. * * @since_tizen 5.0 * @privlevel public * - * @remarks The @a model_name should be released using free(). + * @remarks The @a device_type should be released using free(). * * @param[in] device Device handle - * @param[out] model_name Model name + * @param[out] device_type Device type * * @return 0 on success, otherwise a negative error value. * @retval #MDG_ERROR_NONE Successful @@ -1324,11 +1033,11 @@ int mdg_device_info_get_device_type(mdg_device_h device, * @see mdg_device_info_destroy() * @see mdg_device_info_get_device_id() * @see mdg_device_info_get_ip() - * @see mdg_device_info_get_device_type() + * @see mdg_device_info_get_model_name() * */ -int mdg_device_info_get_model_name(mdg_device_h device, - char **model_name); +int mdg_device_info_get_type(mdg_device_h device, + mdg_device_type_e *device_type); /** * @} diff --git a/src/mdg.c b/src/mdg.c old mode 100644 new mode 100755 index a887ffa..1c4abe4 --- a/src/mdg.c +++ b/src/mdg.c @@ -27,24 +27,7 @@ #include #include -/** - * Companion Manager CAPI - */ - -static pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER; /**< Mutex for dbus */ - -#define MDG_LOCK \ -do { \ - pthread_mutex_lock(&mutex); \ -} while (0); - -#define MDG_UNLOCK \ -do { \ - pthread_mutex_unlock(&mutex); \ -} while (0); - -int ref_count = 0; /**< How many clients are alive */ -bool __is_initialized = false; /**< Initialize or not */ +GSList *handle_list = NULL; EXPORT_API int mdg_initialize(mdg_h *handle) { @@ -66,18 +49,9 @@ EXPORT_API int mdg_initialize(mdg_h *handle) } *handle = mdg_manager; - if (__is_initialized) { - /* LCOV_EXCL_START */ - _DBG("Already initialized"); - return MDG_ERROR_ALREADY_INITIALIZED; - /* LCOV_EXCL_STOP */ - } - - MDG_LOCK; ret = gdbus_initialize(*handle); - __is_initialized = true; - MDG_UNLOCK; - ref_count++; + + handle_list = g_slist_prepend(handle_list, *handle); _END(); @@ -89,31 +63,17 @@ EXPORT_API int mdg_deinitialize(mdg_h handle) int ret = MDG_ERROR_NONE; CHECK_FEATURE_SUPPORTED(MDG_FEATURE); + CHECK_HANDLE_IS_VALID(handle); _BEGIN(); - MDG_LOCK; + handle_list = g_slist_remove(handle_list, handle); - if (0 > --ref_count) { - /* LCOV_EXCL_START */ - _DBG("all connections closed\n"); - ref_count = 0; - MDG_UNLOCK; - return ret; - /* LCOV_EXCL_STOP */ - } - - if (__is_initialized == true && ref_count == 0) { - ret = gdbus_deinitialize(handle); - __is_initialized = false; - } - - MDG_UNLOCK; + ret = gdbus_deinitialize(handle); _END(); return ret; - } EXPORT_API int mdg_group_create(mdg_h handle, char *group_name) @@ -125,8 +85,7 @@ EXPORT_API int mdg_group_create(mdg_h handle, char *group_name) mdg_manager_s *_handle = handle; mdg_check_null_ret_error("handle", handle, MDG_ERROR_INVALID_PARAMETER); - if (0 == strlen(group_name)) - return MDG_ERROR_INVALID_PARAMETER; + CHECK_HANDLE_IS_VALID(handle); /* create group to daemon using gdbus */ group_call_create_sync(_handle->group_proxy, group_name, &ret, NULL, &error); @@ -140,10 +99,6 @@ EXPORT_API void mdg_group_destroy(mdg_group_s *group) mdg_check_null_ret("group", group); - if (group->uri_path) { - g_free(group->uri_path); - group->uri_path = NULL; - } if (group->device_id) { g_free(group->device_id); group->device_id = NULL; @@ -152,14 +107,7 @@ EXPORT_API void mdg_group_destroy(mdg_group_s *group) g_free(group->group_name); group->group_name = NULL; } - if (group->host_addr) { - g_free(group->host_addr); - group->host_addr = NULL; - } - if (group->resource_type) { - g_free(group->resource_type); - group->resource_type = NULL; - } + g_free(group); group = NULL; } @@ -175,6 +123,7 @@ EXPORT_API int mdg_group_find(mdg_h handle, int timeout, mdg_manager_s *_handle = handle; mdg_check_null_ret_error("handle", handle, MDG_ERROR_INVALID_PARAMETER); + CHECK_HANDLE_IS_VALID(handle); _handle->group_found_cb.found_cb = found_cb; _handle->group_find_finish_cb.finish_cb = finish_cb; @@ -183,84 +132,82 @@ EXPORT_API int mdg_group_find(mdg_h handle, int timeout, /* get groups from daemon using gdbus */ group_call_find_sync(_handle->group_proxy, timeout, &ret, NULL, &error); + if (error) { + _ERR("Failed DBus call [%s]", error->message); + g_error_free(error); + ret = MDG_ERROR_IO_ERROR; + } return ret; } -EXPORT_API int mdg_group_get_found_groups(mdg_h handle, - mdg_group_h **groups, int *count) +EXPORT_API 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) { int ret = MDG_ERROR_NONE; - GVariant *va = NULL; GError *error = NULL; CHECK_FEATURE_SUPPORTED(MDG_FEATURE); mdg_manager_s *_handle = handle; mdg_check_null_ret_error("handle", handle, MDG_ERROR_INVALID_PARAMETER); + CHECK_HANDLE_IS_VALID(handle); + + _handle->device_found_cb.found_cb = found_cb; + _handle->device_found_cb.user_data = user_data; + _handle->device_find_finish_cb.finish_cb = finish_cb; + _handle->device_find_finish_cb.user_data = user_data; /* get groups from daemon using gdbus */ - group_call_get_found_groups_sync(_handle->group_proxy, &ret, &va, NULL, &error); - *count = g_variant_n_children(va); - - _DBG("get found groups : %d", *count); - - /* LCOV_EXCL_START */ - if (*count > 0) { - GVariantIter *iter = NULL, *iter_row = NULL; - GVariant *key_value; - const gchar *key; - guint i = 0; - - *groups = g_new0(mdg_group_h, *count); - - g_variant_get(va, "aa{sv}", &iter); - while (g_variant_iter_next(iter, "a{sv}", &iter_row)) { - - char *uri_path = NULL; - char *device_id = NULL; - char *group_name = NULL; - char *host_addr = NULL; - char *resource_type = NULL; - - mdg_group_s *group = NULL; - mdg_group_type_e type = MDG_GROUP_TYPE_ERROR; - - while (g_variant_iter_loop(iter_row, "{sv}", &key, &key_value)) { - if (g_strcmp0(key, "URI") == 0) - uri_path = (char *)g_variant_get_string(key_value, NULL); - else if (g_strcmp0(key, "DeviceID") == 0) - device_id = (char *)g_variant_get_string(key_value, NULL); - else if (g_strcmp0(key, "GroupName") == 0) - group_name = (char *)g_variant_get_string(key_value, NULL); - else if (g_strcmp0(key, "HostAddress") == 0) - host_addr = (char *)g_variant_get_string(key_value, NULL); - else if (g_strcmp0(key, "GroupDeviceType") == 0) - resource_type = (char *)g_variant_get_string(key_value, NULL); - else if (g_strcmp0(key, "GroupType") == 0) - type = g_variant_get_int32(key_value); - } - g_variant_iter_free(iter_row); - - _INFO("DeviceID %s GroupName %s HostAddress %s GroupDeviceType %s", - device_id, group_name, host_addr, resource_type); - - group = create_group_handle(uri_path, - device_id, group_name, host_addr, resource_type, type); - - (*groups)[i++] = (mdg_group_h)group; - } - g_variant_iter_free(iter); + group_call_find_device_sync(_handle->group_proxy, timeout, is_invited, &ret, NULL, &error); + if (error) { + _ERR("Failed DBus call [%s]", error->message); + g_error_free(error); + ret = MDG_ERROR_IO_ERROR; } - /* LCOV_EXCL_STOP */ - g_variant_unref(va); return ret; } -EXPORT_API int mdg_device_find(mdg_h handle, int timeout, - mdg_device_found_cb found_cb, mdg_device_find_finish_cb finish_cb, - void *user_data) +typedef struct _channel_cb_s { + char *channel_id; + mdg_channel_cb cb; + void *user_data; +} channel_cb_s; + +/** + * Companion Manager CAPI + */ +int __add_channel_cb(mdg_manager_s *handle, char *channel_id, mdg_channel_cb channel_cb, void *user_data) +{ + channel_cb_s *channel_s; + + GSList *l1, *l2; + for (l1 = handle_list; l1 != NULL; l1 = l1->next) { + mdg_manager_s *tmp_handle = (mdg_manager_s *)l1->data; + for (l2 = tmp_handle->channel_cb_list; l2 != NULL; l2 = l2->next) { + channel_cb_s *tmp_channel = (channel_cb_s *)l2->data; + if (g_strcmp0(tmp_channel->channel_id, channel_id) == 0) + return MDG_ERROR_UNKNOWN; + } + } + + channel_s = g_try_new0(channel_cb_s, 1); + if (channel_s == NULL) + return MDG_ERROR_OUT_OF_MEMORY; + + channel_s->channel_id = g_strdup(channel_id); + channel_s->cb = channel_cb; + channel_s->user_data = user_data; + + handle->channel_cb_list = g_slist_prepend(handle->channel_cb_list, channel_s); + + return 0; +} + +EXPORT_API int mdg_device_regist_channel(mdg_h handle, char *channel_id, + mdg_channel_cb channel_cb, void *user_data) { int ret = MDG_ERROR_NONE; GError *error = NULL; @@ -269,53 +216,69 @@ EXPORT_API int mdg_device_find(mdg_h handle, int timeout, mdg_manager_s *_handle = handle; mdg_check_null_ret_error("handle", handle, MDG_ERROR_INVALID_PARAMETER); + CHECK_HANDLE_IS_VALID(_handle); - _handle->device_found_cb.found_cb = found_cb; - _handle->device_found_cb.user_data = user_data; - _handle->device_find_finish_cb.finish_cb = finish_cb; - _handle->device_find_finish_cb.user_data = user_data; + _BEGIN(); - /* get groups from daemon using gdbus */ - group_call_device_find_sync(_handle->group_proxy, timeout, &ret, NULL, &error); + group_call_regist_channel_sync(_handle->group_proxy, channel_id, &ret, NULL, &error); if (error) { _ERR("Failed DBus call [%s]", error->message); g_error_free(error); ret = MDG_ERROR_IO_ERROR; } + if (ret == MDG_ERROR_NONE) + ret = __add_channel_cb(handle, channel_id, channel_cb, user_data); + + _END(); + return ret; } -EXPORT_API int mdg_device_find_mowned_device(mdg_h handle, - int timeout, mdg_device_found_cb found_cb, - mdg_device_find_finish_cb finish_cb, void *user_data) +EXPORT_API int mdg_device_unregist_channel(mdg_h handle, char *channel_id) { int ret = MDG_ERROR_NONE; + bool is_exist = false; GError *error = NULL; CHECK_FEATURE_SUPPORTED(MDG_FEATURE); mdg_manager_s *_handle = handle; mdg_check_null_ret_error("handle", handle, MDG_ERROR_INVALID_PARAMETER); + CHECK_HANDLE_IS_VALID(handle); - _handle->mowned_device_found_cb.found_cb = found_cb; - _handle->mowned_device_found_cb.user_data = user_data; - _handle->mowned_device_find_finish_cb.finish_cb = finish_cb; - _handle->mowned_device_find_finish_cb.user_data = user_data; + _BEGIN(); - /* get groups from daemon using gdbus */ - group_call_find_mowned_devices_sync(_handle->group_proxy, timeout, &ret, NULL, &error); - if (error) { - _ERR("Failed DBus call [%s]", error->message); - g_error_free(error); - ret = MDG_ERROR_IO_ERROR; + 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) { + g_free(tmp_channel->channel_id); + _handle->channel_cb_list = g_slist_remove_link(_handle->channel_cb_list, l); + is_exist = true; + break; + } + } + + if (is_exist == false) + ret = MDG_ERROR_UNKNOWN; + + if (ret == MDG_ERROR_NONE) { + group_call_unregist_channel_sync(_handle->group_proxy, channel_id, &ret, NULL, &error); + if (error) { + _ERR("Failed DBus call [%s]", error->message); + g_error_free(error); + ret = MDG_ERROR_IO_ERROR; + } } + _END(); + return ret; } EXPORT_API int mdg_device_send_data(mdg_h handle, - mdg_device_h device, unsigned char *data, int len, + mdg_device_h device, char *channel_id, unsigned char *data, int len, mdg_device_send_data_finish_cb finish_cb, void *user_data) { int ret = MDG_ERROR_NONE; @@ -329,6 +292,7 @@ EXPORT_API int mdg_device_send_data(mdg_h handle, mdg_manager_s *_handle = handle; mdg_check_null_ret_error("handle", handle, MDG_ERROR_INVALID_PARAMETER); + CHECK_HANDLE_IS_VALID(handle); mdg_device_s *dev = (mdg_device_s *)device; mdg_check_null_ret_error("dev", dev, MDG_ERROR_INVALID_PARAMETER); @@ -352,8 +316,8 @@ EXPORT_API int mdg_device_send_data(mdg_h handle, _handle->send_data_finish_cb.finish_cb = finish_cb; _handle->send_data_finish_cb.user_data = user_data; - group_call_send_data_sync(_handle->group_proxy, dev->device_id, dev->ip, - dev->sec_port, params, &ret, NULL, &error); + group_call_send_data_sync(_handle->group_proxy, dev->device_id, dev->addr, + dev->secure_port, params, &ret, NULL, &error); if (error) { _ERR("Failed DBus call [%s]", error->message); g_error_free(error); @@ -366,276 +330,27 @@ EXPORT_API int mdg_device_send_data(mdg_h handle, return ret; } -/* mdg_request_join_group : join to remote group. if group handle is my daemon's, - then the api return fail error */ -EXPORT_API int mdg_device_get_found_devices(mdg_h handle, - mdg_device_h **devices, int *count) -{ - int ret = MDG_ERROR_NONE; - int num = 0; - GVariant *va = NULL; - GError *error = NULL; - - CHECK_FEATURE_SUPPORTED(MDG_FEATURE); - - mdg_manager_s *_handle = handle; - mdg_check_null_ret_error("handle", handle, MDG_ERROR_INVALID_PARAMETER); - - /* get groups from daemon using gdbus */ - group_call_get_remote_device_sync(_handle->group_proxy, &num, &va, NULL, &error); - if (error) { - _ERR("Failed DBus call [%s]", error->message); - g_error_free(error); - ret = MDG_ERROR_IO_ERROR; - } - /* *count = g_variant_n_children(va); */ - *count = num; - - _DBG("get found devices : %d", *count); - /* LCOV_EXCL_START */ - if (*count > 0) { - GVariantIter *iter = NULL, *iter_row = NULL; - GVariant *key_value = NULL; - const gchar *key; - guint i = 0; - - *devices = g_new0(mdg_group_h, *count); - - g_variant_get(va, "aa{sv}", &iter); - while (g_variant_iter_next(iter, "a{sv}", &iter_row)) { - char *deviceid = NULL; - char *addr = NULL; - int device_type = MDG_DEVICE_TYPE_ERROR; - int port; - int sec_port; - mdg_device_s *device = NULL; - char *model_name = NULL; - char *device_name = NULL; - char *platform_ver = NULL; - char *vendor_id = NULL; - char *profile = NULL; - - while (g_variant_iter_loop(iter_row, "{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, "DeviceType") == 0) - device_type = g_variant_get_uint16(key_value); - else if (g_strcmp0(key, "Port") == 0) - port = g_variant_get_uint16(key_value); - else if (g_strcmp0(key, "SecurePort") == 0) - sec_port = g_variant_get_uint16(key_value); - else if (g_strcmp0(key, "ModelName") == 0) - model_name = (char *)g_variant_get_string(key_value, NULL); - else if (g_strcmp0(key, "DeviceName") == 0) - device_name = (char *)g_variant_get_string(key_value, NULL); - else if (g_strcmp0(key, "PlatformVer") == 0) - platform_ver = (char *)g_variant_get_string(key_value, NULL); - else if (g_strcmp0(key, "VendorID") == 0) - vendor_id = (char *)g_variant_get_string(key_value, NULL); - else if (g_strcmp0(key, "Profile") == 0) - profile = (char *)g_variant_get_string(key_value, NULL); - } - g_variant_iter_free(iter_row); - - device = create_device_handle(deviceid, addr, device_type, port, sec_port, - model_name, device_name, platform_ver, vendor_id, profile); - - (*devices)[i++] = (mdg_device_h)device; - } - g_variant_iter_free(iter); - } - /* LCOV_EXCL_STOP */ - g_variant_unref(va); - - return ret; -} - -EXPORT_API int mdg_device_get_found_mowned_devices( - mdg_h handle, mdg_device_h **devices, int *count) -{ - int ret = MDG_ERROR_NONE; - int num = 0; - GVariant *va = NULL; - GError *error = NULL; - - CHECK_FEATURE_SUPPORTED(MDG_FEATURE); - - mdg_manager_s *_handle = handle; - mdg_check_null_ret_error("handle", handle, MDG_ERROR_INVALID_PARAMETER); - - /* get groups from daemon using gdbus */ - group_call_get_mowned_device_sync(_handle->group_proxy, &num, &va, NULL, &error); - if (error) { - _ERR("Failed DBus call [%s]", error->message); - g_error_free(error); - ret = MDG_ERROR_IO_ERROR; - } - /* *count = g_variant_n_children(va); */ - *count = num; - - _INFO("get found mowned devices : %d", *count); - - /* LCOV_EXCL_START */ - if (*count > 0) { - GVariantIter *iter = NULL, *iter_row = NULL; - GVariant *key_value; - const gchar *key; - guint i = 0; - - *devices = g_new0(mdg_device_h, *count); - - g_variant_get(va, "aa{sv}", &iter); - while (g_variant_iter_next(iter, "a{sv}", &iter_row)) { - char *deviceid = NULL; - char *addr = NULL; - int device_type = MDG_DEVICE_TYPE_ERROR; - int port; - int sec_port; - mdg_device_s *device = NULL; - char *model_name = NULL; - char *device_name = NULL; - char *platform_ver = NULL; - char *vendor_id = NULL; - char *profile = NULL; - - while (g_variant_iter_loop(iter_row, "{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, "DeviceType") == 0) - device_type = g_variant_get_uint16(key_value); - else if (g_strcmp0(key, "Port") == 0) - port = g_variant_get_uint16(key_value); - else if (g_strcmp0(key, "SecurePort") == 0) - sec_port = g_variant_get_uint16(key_value); - else if (g_strcmp0(key, "ModelName") == 0) - model_name = (char *)g_variant_get_string(key_value, NULL); - else if (g_strcmp0(key, "DeviceName") == 0) - device_name = (char *)g_variant_get_string(key_value, NULL); - else if (g_strcmp0(key, "PlatformVer") == 0) - platform_ver = (char *)g_variant_get_string(key_value, NULL); - else if (g_strcmp0(key, "VendorID") == 0) - vendor_id = (char *)g_variant_get_string(key_value, NULL); - else if (g_strcmp0(key, "Profile") == 0) - profile = (char *)g_variant_get_string(key_value, NULL); - } - g_variant_iter_free(iter_row); - - device = create_device_handle(deviceid, addr, device_type, port, sec_port, - model_name, device_name, platform_ver, vendor_id, profile); - - (*devices)[i++] = (mdg_device_h)device; - } - g_variant_iter_free(iter); - } - /* LCOV_EXCL_STOP */ - g_variant_unref(va); - - return ret; -} - -EXPORT_API int mdg_device_info_get_my_uuid(mdg_h handle, char **uuid) -{ - int ret = 0; - GError *error = NULL; - - CHECK_FEATURE_SUPPORTED(MDG_FEATURE); - - mdg_manager_s *_handle = handle; - mdg_check_null_ret_error("handle", handle, MDG_ERROR_INVALID_PARAMETER); - - group_call_get_my_uuid_sync(_handle->group_proxy, uuid, NULL, &error); - if (error) { - _ERR("Failed DBus call [%s]", error->message); - g_error_free(error); - ret = MDG_ERROR_IO_ERROR; - } - - return ret; -} - -EXPORT_API int mdg_device_info_get_my_device(mdg_h handle, +EXPORT_API int mdg_device_get_local_device(mdg_h handle, mdg_device_h *device) { int ret = MDG_ERROR_NONE; GError *error = NULL; GVariant *va = NULL; - GVariantIter *iter = NULL; - const gchar *key; - GVariant *key_value = NULL; - char *deviceid = NULL; - char *addr = NULL; - int device_type = MDG_DEVICE_TYPE_ERROR; - int port = -1; - int sec_port = -1; - char *model_name = NULL; - char *device_name = NULL; - char *platform_ver = NULL; - char *vendor_id = NULL; - char *profile = NULL; CHECK_FEATURE_SUPPORTED(MDG_FEATURE); mdg_manager_s *_handle = handle; mdg_check_null_ret_error("handle", handle, MDG_ERROR_INVALID_PARAMETER); + CHECK_HANDLE_IS_VALID(handle); - group_call_get_my_mowned_device_sync(_handle->group_proxy, &va, NULL, &error); + group_call_get_local_device_sync(_handle->group_proxy, &va, NULL, &error); if (error) { _ERR("Failed DBus call [%s]", error->message); g_error_free(error); ret = MDG_ERROR_IO_ERROR; } - g_variant_get(va, "a{sv}", &iter); - /* LCOV_EXCL_START */ - 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, "DeviceType") == 0) - device_type = g_variant_get_uint16(key_value); - else if (g_strcmp0(key, "Port") == 0) - port = g_variant_get_uint16(key_value); - else if (g_strcmp0(key, "SecurePort") == 0) - sec_port = g_variant_get_uint16(key_value); - else if (g_strcmp0(key, "ModelName") == 0) - model_name = (char *)g_variant_get_string(key_value, NULL); - else if (g_strcmp0(key, "DeviceName") == 0) - device_name = (char *)g_variant_get_string(key_value, NULL); - else if (g_strcmp0(key, "PlatformVer") == 0) - platform_ver = (char *)g_variant_get_string(key_value, NULL); - else if (g_strcmp0(key, "VendorID") == 0) - vendor_id = (char *)g_variant_get_string(key_value, NULL); - else if (g_strcmp0(key, "Profile") == 0) - profile = (char *)g_variant_get_string(key_value, NULL); - } - - if (deviceid == NULL || addr == NULL) - return MDG_ERROR_NO_DATA; - /* LCOV_EXCL_STOP */ - - *device = (mdg_device_h)create_device_handle(deviceid, addr, device_type, port, sec_port, - model_name, device_name, platform_ver, vendor_id, profile); - - g_variant_iter_free(iter); - - return ret; -} - -/* group merge */ -EXPORT_API int mdg_group_merge(mdg_h hadnle, - mdg_group_h dest_group, mdg_group_h src_group) -{ - int ret = MDG_ERROR_NONE; - - CHECK_FEATURE_SUPPORTED(MDG_FEATURE); - - NOTUSED(dest_group); - NOTUSED(src_group); + *device = mdg_get_device_from_variant(va); return ret; } @@ -649,17 +364,13 @@ EXPORT_API int mdg_group_delete(mdg_h handle, mdg_group_h group) mdg_manager_s *_handle = handle; mdg_check_null_ret_error("handle", handle, MDG_ERROR_INVALID_PARAMETER); + CHECK_HANDLE_IS_VALID(handle); mdg_group_s *grp = (mdg_group_s *)group; mdg_check_null_ret_error("grp", grp, MDG_ERROR_INVALID_PARAMETER); - group_call_delete_sync(_handle->group_proxy, grp->group_name, &ret, NULL, - &error); - if (error) { - _ERR("Failed DBus call [%s]", error->message); - g_error_free(error); - ret = MDG_ERROR_IO_ERROR; - } + /* create group to daemon using gdbus */ + group_call_delete_sync(_handle->group_proxy, grp->group_name, &ret, NULL, &error); return ret; } @@ -681,7 +392,7 @@ EXPORT_API int mdg_group_get_member_devices(mdg_h handle, EXPORT_API int mdg_group_invite_device(mdg_h handle, mdg_group_h group, mdg_device_h device, char *PIN, - mdg_group_invite_device_result_cb result_cb, void *user_data) + mdg_group_invite_device_finish_cb finish_cb, void *user_data) { int ret = MDG_ERROR_NONE; GError *error = NULL; @@ -690,6 +401,7 @@ EXPORT_API int mdg_group_invite_device(mdg_h handle, mdg_manager_s *_handle = handle; mdg_check_null_ret_error("handle", handle, MDG_ERROR_INVALID_PARAMETER); + CHECK_HANDLE_IS_VALID(handle); mdg_group_s *grp = (mdg_group_s *)group; mdg_check_null_ret_error("grp", grp, MDG_ERROR_INVALID_PARAMETER); @@ -697,24 +409,18 @@ EXPORT_API int mdg_group_invite_device(mdg_h handle, mdg_device_s *dev = (mdg_device_s *)device; mdg_check_null_ret_error("dev", dev, MDG_ERROR_INVALID_PARAMETER); - _handle->device_invite_result_cb.result_cb = result_cb; - _handle->device_invite_result_cb.user_data = user_data; + _handle->device_invite_finish_cb.finish_cb = finish_cb; + _handle->device_invite_finish_cb.user_data = user_data; - /* Now, for the sake of convenience, we change 'mdg_group_invite_device' to - 'group_call_invite_sync'. */ -#if 0 - group_call_device_invite_sync(group_proxy, dev->device_id, PIN, &ret, NULL, &error); -#else - group_call_invite_sync(_handle->group_proxy, grp->group_name, dev->device_id, PIN, + group_call_invite_device_sync(_handle->group_proxy, grp->group_name, dev->device_id, PIN, &ret, NULL, &error); -#endif return ret; } EXPORT_API int mdg_group_eject_device(mdg_h handle, mdg_group_h group, mdg_device_h device, - mdg_group_eject_device_result_cb result_cb, void *user_data) + mdg_group_eject_device_finish_cb finish_cb, void *user_data) { int ret = MDG_ERROR_NONE; GError *error = NULL; @@ -723,6 +429,7 @@ EXPORT_API int mdg_group_eject_device(mdg_h handle, mdg_manager_s *_handle = handle; mdg_check_null_ret_error("handle", handle, MDG_ERROR_INVALID_PARAMETER); + CHECK_HANDLE_IS_VALID(handle); mdg_device_s *dev = (mdg_device_s *)device; mdg_check_null_ret_error("dev", dev, MDG_ERROR_INVALID_PARAMETER); @@ -730,17 +437,11 @@ EXPORT_API int mdg_group_eject_device(mdg_h handle, mdg_group_s *grp = (mdg_group_s *)group; mdg_check_null_ret_error("grp", grp, MDG_ERROR_INVALID_PARAMETER); - _handle->device_eject_result_cb.result_cb = result_cb; - _handle->device_eject_result_cb.user_data = user_data; + _handle->device_eject_finish_cb.finish_cb = finish_cb; + _handle->device_eject_finish_cb.user_data = user_data; - /* Now, for the sake of convenience, we change 'mdg_device_eject' to - 'group_call_eject_sync'. */ -#if 0 - group_call_device_eject_sync(group_proxy, dev->device_id, &ret, NULL, &error); -#else - group_call_eject_sync(_handle->group_proxy, grp->group_name, dev->device_id, &ret, + group_call_eject_device_sync(_handle->group_proxy, grp->group_name, dev->device_id, &ret, NULL, &error); -#endif return ret; } @@ -763,41 +464,28 @@ EXPORT_API int mdg_group_info_create(mdg_group_h* group) return ret; } -EXPORT_API int mdg_group_info_clone(mdg_group_h target, +EXPORT_API int mdg_group_info_clone(mdg_group_h *target, mdg_group_h source) { int ret = MDG_ERROR_NONE; CHECK_FEATURE_SUPPORTED(MDG_FEATURE); - mdg_group_s * dst = (mdg_group_s *)target; - mdg_check_null_ret_error("target", target, MDG_ERROR_INVALID_PARAMETER); - mdg_group_s * src = (mdg_group_s *)source; mdg_check_null_ret_error("source", source, MDG_ERROR_INVALID_PARAMETER); - ret = mdg_group_info_create(&target); - if (MDG_ERROR_NONE != ret) { - /* LCOV_EXCL_START */ - _ERR("mdg_group_info_create() Failed(%d)", ret); - return ret; - /* LCOV_EXCL_STOP */ - } - - if (src->uri_path) - dst->uri_path = g_strdup(src->uri_path); + *target = (mdg_group_s *)g_malloc0(sizeof(mdg_group_s)); + mdg_check_null_ret_error("target", target, MDG_ERROR_INVALID_PARAMETER); + mdg_group_s *dst = *target; if (src->device_id) dst->device_id = g_strdup(src->device_id); - if (src->group_name) - dst->group_name = g_strdup(src->group_name); - if (src->host_addr) dst->host_addr = g_strdup(src->host_addr); - if (src->resource_type) - dst->resource_type = g_strdup(src->resource_type); + if (src->group_name) + dst->group_name = g_strdup(src->group_name); dst->type = src->type; @@ -813,64 +501,57 @@ EXPORT_API int mdg_group_info_destroy(mdg_group_h data) mdg_group_s * group = (mdg_group_s *)data; mdg_check_null_ret_error("group", group, MDG_ERROR_INVALID_PARAMETER); - if (group->uri_path) { - g_free(group->uri_path); - group->uri_path = NULL; - } if (group->device_id) { g_free(group->device_id); group->device_id = NULL; } - if (group->group_name) { - g_free(group->group_name); - group->group_name = NULL; - } if (group->host_addr) { - g_free((mdg_group_s *)group->host_addr); + g_free(group->host_addr); group->host_addr = NULL; } - if (group->resource_type) { - g_free((mdg_group_s *)group->resource_type); - group->resource_type = NULL; + if (group->group_name) { + g_free(group->group_name); + group->group_name = NULL; } + g_free(group); group = NULL; return ret; } -EXPORT_API int mdg_group_info_get_type(mdg_group_h group, - mdg_group_type_e *type) +EXPORT_API int mdg_group_info_get_device_id( + mdg_group_h group, char **device_id) { int ret = MDG_ERROR_NONE; CHECK_FEATURE_SUPPORTED(MDG_FEATURE); - *type = ((mdg_group_s *)group)->type; + *device_id = g_strdup(((mdg_group_s *)group)->device_id); return ret; } -EXPORT_API int mdg_group_info_get_resource_type( - mdg_group_h group, char **resource_type) +EXPORT_API int mdg_group_info_get_host_addr( + mdg_group_h group, char **host_addr) { int ret = MDG_ERROR_NONE; CHECK_FEATURE_SUPPORTED(MDG_FEATURE); - *resource_type = g_strdup(((mdg_group_s *)group)->resource_type); + *host_addr = g_strdup(((mdg_group_s *)group)->host_addr); return ret; } -EXPORT_API int mdg_group_info_get_uri_path( - mdg_group_h group, char **uri_path) +EXPORT_API int mdg_group_info_get_type(mdg_group_h group, + mdg_group_type_e *type) { int ret = MDG_ERROR_NONE; CHECK_FEATURE_SUPPORTED(MDG_FEATURE); - *uri_path = g_strdup(((mdg_group_s *)group)->uri_path); + *type = ((mdg_group_s *)group)->type; return ret; } @@ -887,63 +568,47 @@ EXPORT_API int mdg_group_info_get_name( return ret; } -EXPORT_API int mdg_group_info_get_host_addr - (mdg_group_h group, char **host_addr) +EXPORT_API int mdg_device_info_clone(mdg_device_h *target, + mdg_device_h source) { int ret = MDG_ERROR_NONE; CHECK_FEATURE_SUPPORTED(MDG_FEATURE); - *host_addr = g_strdup(((mdg_group_s *)group)->host_addr); - - return ret; -} + mdg_device_s * src = (mdg_device_s *)source; + mdg_check_null_ret_error("source", source, MDG_ERROR_INVALID_PARAMETER); -EXPORT_API int mdg_device_info_create(mdg_device_h* device) -{ - int ret = MDG_ERROR_NONE; + *target = (mdg_device_s *)g_malloc0(sizeof(mdg_device_s)); + mdg_check_null_ret_error("target", target, MDG_ERROR_INVALID_PARAMETER); + mdg_device_s *dst = *target; - CHECK_FEATURE_SUPPORTED(MDG_FEATURE); + if (src->device_id) + dst->device_id = g_strdup(src->device_id); - mdg_device_h _device = g_malloc0(sizeof(mdg_device_s)); - if (NULL == device) { - /* LCOV_EXCL_START */ - _ERR("Memory allocation Failed(%d)", errno); - return MDG_ERROR_OUT_OF_MEMORY; - /* LCOV_EXCL_STOP */ - } - *device = _device; + if (src->addr) + dst->addr = g_strdup(src->addr); - return ret; -} + dst->port = src->port; + dst->secure_port = src->secure_port; + dst->conn_type = src->conn_type; -EXPORT_API int mdg_device_info_clone(mdg_device_h target, - mdg_device_h source) -{ - int ret = MDG_ERROR_NONE; + if (src->model_name) + dst->model_name = g_strdup(src->model_name); - CHECK_FEATURE_SUPPORTED(MDG_FEATURE); + if (src->device_name) + dst->device_name = g_strdup(src->device_name); - mdg_device_s *dst = (mdg_device_s *)target; - mdg_check_null_ret_error("target", target, MDG_ERROR_INVALID_PARAMETER); + if (src->platform_ver) + dst->platform_ver = g_strdup(src->platform_ver); - mdg_device_s *src = (mdg_device_s *)source; - mdg_check_null_ret_error("source", source, MDG_ERROR_INVALID_PARAMETER); + if (src->vendor_id) + dst->vendor_id = g_strdup(src->vendor_id); - ret = mdg_device_info_create(&target); - if (MDG_ERROR_NONE != ret) { - /* LCOV_EXCL_START */ - _ERR("mdg_device_info_create() Failed(%d)", ret); - return ret; - /* LCOV_EXCL_STOP */ - } + if (src->profile) + dst->profile = g_strdup(src->profile); - if (src->device_id) - dst->device_id = g_strdup(src->device_id); - if (src->ip) - dst->ip = g_strdup(src->ip); - if (src->device_type) - dst->device_type = src->device_type; + dst->is_invited = src->is_invited; + dst->type = src->type; return ret; } @@ -961,9 +626,35 @@ EXPORT_API int mdg_device_info_destroy(mdg_device_h data) g_free(device->device_id); device->device_id = NULL; } - if (device->ip) { - g_free(device->ip); - device->ip = NULL; + + if (device->addr) { + g_free(device->addr); + device->addr = NULL; + } + + if (device->model_name) { + g_free(device->model_name); + device->model_name = NULL; + } + + if (device->device_name) { + g_free(device->device_name); + device->device_name = NULL; + } + + if (device->platform_ver) { + g_free(device->platform_ver); + device->platform_ver = NULL; + } + + if (device->vendor_id) { + g_free(device->vendor_id); + device->vendor_id = NULL; + } + + if (device->profile) { + g_free(device->profile); + device->profile = NULL; } g_free(device); @@ -982,28 +673,40 @@ EXPORT_API int mdg_device_info_get_device_id( *device_id = g_strdup(((mdg_device_s *)device)->device_id); return ret; - } -EXPORT_API int mdg_device_info_get_ip( - mdg_device_h device, char **ip) + +EXPORT_API int mdg_device_info_get_addr( + mdg_device_h device, char **addr) { int ret = MDG_ERROR_NONE; CHECK_FEATURE_SUPPORTED(MDG_FEATURE); - *ip = g_strdup(((mdg_device_s *)device)->ip); + *addr = g_strdup(((mdg_device_s *)device)->addr); return ret; +} +EXPORT_API int mdg_device_info_get_port( + mdg_device_h device, int *port) +{ + int ret = MDG_ERROR_NONE; + + CHECK_FEATURE_SUPPORTED(MDG_FEATURE); + + *port = (((mdg_device_s *)device)->port); + + return ret; } -EXPORT_API int mdg_device_info_get_device_type( - mdg_device_h device, mdg_device_type_e *device_type) + +EXPORT_API int mdg_device_info_get_secure_port( + mdg_device_h device, int *secure_port) { int ret = MDG_ERROR_NONE; CHECK_FEATURE_SUPPORTED(MDG_FEATURE); - *device_type = ((mdg_device_s *)device)->device_type; + *secure_port = (((mdg_device_s *)device)->secure_port); return ret; } @@ -1020,61 +723,104 @@ EXPORT_API int mdg_device_info_get_model_name( return ret; } -EXPORT_API int mdg_request_create_group(mdg_h handle, - mdg_device_h device, char *group_name, mdg_request_result_cb cb, - void *user_data) +EXPORT_API int mdg_device_info_get_device_name( + mdg_device_h device, char **device_name) { int ret = MDG_ERROR_NONE; - GError *error = NULL; - NOTUSED(cb); - NOTUSED(user_data); + CHECK_FEATURE_SUPPORTED(MDG_FEATURE); + + *device_name = g_strdup(((mdg_device_s *)device)->device_name); + + return ret; +} + +EXPORT_API int mdg_device_info_get_platform_ver( + mdg_device_h device, char **platform_ver) +{ + int ret = MDG_ERROR_NONE; CHECK_FEATURE_SUPPORTED(MDG_FEATURE); - mdg_manager_s *_handle = handle; - mdg_check_null_ret_error("handle", handle, MDG_ERROR_INVALID_PARAMETER); + *platform_ver = g_strdup(((mdg_device_s *)device)->platform_ver); - mdg_device_s *dev = (mdg_device_s *)device; - mdg_check_null_ret_error("device", device, MDG_ERROR_INVALID_PARAMETER); - mdg_check_null_ret_error("group_name", group_name, - MDG_ERROR_INVALID_PARAMETER); + return ret; +} - _DBG("Device id : %s", dev->device_id); +EXPORT_API int mdg_device_info_get_vendor_id( + mdg_device_h device, char **vendor_id) +{ + int ret = MDG_ERROR_NONE; - group_call_request_create_group_sync(_handle->group_proxy, dev->device_id, - group_name, &ret, NULL, &error); + CHECK_FEATURE_SUPPORTED(MDG_FEATURE); + + *vendor_id = g_strdup(((mdg_device_s *)device)->vendor_id); return ret; } -EXPORT_API int mdg_request_join_group(mdg_h handle, mdg_group_h group, - mdg_request_result_cb callback, void *user_data) +EXPORT_API int mdg_device_info_get_profile( + mdg_device_h device, char **profile) { int ret = MDG_ERROR_NONE; CHECK_FEATURE_SUPPORTED(MDG_FEATURE); - NOTUSED(handle); - NOTUSED(group); - NOTUSED(callback); - NOTUSED(user_data); + *profile = g_strdup(((mdg_device_s *)device)->profile); return ret; } -EXPORT_API int mdg_request_leave_group (mdg_h handle, - mdg_group_h group, mdg_request_result_cb callback, void *user_data) +EXPORT_API int mdg_device_info_is_invited( + mdg_device_h device, bool *is_invited) { int ret = MDG_ERROR_NONE; CHECK_FEATURE_SUPPORTED(MDG_FEATURE); - NOTUSED(handle); - NOTUSED(group); - NOTUSED(callback); + *is_invited = ((mdg_device_s *)device)->is_invited; + + return ret; +} + +EXPORT_API int mdg_device_info_get_type( + mdg_device_h device, mdg_device_type_e *type) +{ + int ret = MDG_ERROR_NONE; + + CHECK_FEATURE_SUPPORTED(MDG_FEATURE); + + *type = ((mdg_device_s *)device)->type; + + return ret; +} + +EXPORT_API int mdg_request_create_group(mdg_h handle, + mdg_device_h device, char *group_name, mdg_request_result_cb 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; + mdg_check_null_ret_error("handle", handle, MDG_ERROR_INVALID_PARAMETER); + CHECK_HANDLE_IS_VALID(handle); + + mdg_device_s *dev = (mdg_device_s *)device; + mdg_check_null_ret_error("device", device, MDG_ERROR_INVALID_PARAMETER); + mdg_check_null_ret_error("group_name", group_name, + MDG_ERROR_INVALID_PARAMETER); + + _DBG("Device id : %s", dev->device_id); + + group_call_request_create_group_sync(_handle->group_proxy, dev->device_id, + group_name, &ret, NULL, &error); + return ret; } @@ -1092,6 +838,7 @@ EXPORT_API int mdg_request_invite_device(mdg_h handle, mdg_manager_s *_handle = handle; mdg_check_null_ret_error("handle", handle, MDG_ERROR_INVALID_PARAMETER); + CHECK_HANDLE_IS_VALID(handle); mdg_group_s *grp = (mdg_group_s *)group; mdg_check_null_ret_error("group", group, MDG_ERROR_INVALID_PARAMETER); @@ -1128,6 +875,7 @@ EXPORT_API int mdg_request_eject_device(mdg_h handle, mdg_manager_s *_handle = handle; mdg_check_null_ret_error("handle", handle, MDG_ERROR_INVALID_PARAMETER); + CHECK_HANDLE_IS_VALID(handle); mdg_group_s *grp = (mdg_group_s *)group; mdg_check_null_ret_error("group", group, MDG_ERROR_INVALID_PARAMETER); @@ -1150,20 +898,6 @@ EXPORT_API int mdg_request_eject_device(mdg_h handle, return ret; } -EXPORT_API int mdg_request_delete_group(mdg_h handle, - mdg_group_h group, mdg_request_result_cb cb, void *user_data) -{ - int ret = MDG_ERROR_NONE; - - CHECK_FEATURE_SUPPORTED(MDG_FEATURE); - - NOTUSED(handle); - NOTUSED(group); - NOTUSED(cb); - NOTUSED(user_data); - return ret; -} - EXPORT_API int mdg_request_result_callback(mdg_h handle, mdg_request_result_cb result_cb, void *user_data) { @@ -1179,65 +913,3 @@ EXPORT_API int mdg_request_result_callback(mdg_h handle, return ret; } - -EXPORT_API int mdg_device_monitor_start(mdg_h handle, - mdg_device_monitor_result_cb cb, void *user_data) -{ - int ret = MDG_ERROR_NONE; - GError *error = NULL; - - CHECK_FEATURE_SUPPORTED(MDG_FEATURE); - - mdg_manager_s *_handle = handle; - mdg_check_null_ret_error("handle", handle, - MDG_ERROR_INVALID_PARAMETER); - - group_call_start_invited_device_monitor_sync(_handle->group_proxy, 1, &ret, - NULL, &error); - if (ret != MDG_ERROR_NONE) { - _ERR("Failed to start monitor"); - return ret; - } else if (error) { - _ERR("Failed DBus call [%s]", error->message); - g_error_free(error); - ret = MDG_ERROR_IO_ERROR; - } - - _handle->monitor_result_cb.cb = cb; - _handle->monitor_result_cb.user_data = user_data; - - return ret; -} - -EXPORT_API int mdg_device_monitor_stop(mdg_h handle) -{ - int ret = MDG_ERROR_NONE; - GError *error = NULL; - - CHECK_FEATURE_SUPPORTED(MDG_FEATURE); - - mdg_manager_s *_handle = handle; - mdg_check_null_ret_error("handle", handle, - MDG_ERROR_INVALID_PARAMETER); - - if (_handle->monitor_result_cb.cb == NULL) { - _ERR("Monitor is not started"); - return MDG_ERROR_NOT_STARTED; - } - - group_call_start_invited_device_monitor_sync(_handle->group_proxy, 0, &ret, - NULL, &error); - if (ret != MDG_ERROR_NONE) { - _ERR("Failed to stop monitor"); - return ret; - } else if (error) { - _ERR("Failed DBus call [%s]", error->message); - g_error_free(error); - ret = MDG_ERROR_IO_ERROR; - } - - _handle->monitor_result_cb.cb = NULL; - _handle->monitor_result_cb.user_data = NULL; - - return ret; -} diff --git a/src/mdg_dbus.c b/src/mdg_dbus.c index 1f59604..b7a250f 100755 --- a/src/mdg_dbus.c +++ b/src/mdg_dbus.c @@ -28,307 +28,82 @@ #include #include -#define MDG_DBUS_SERVICE "org.tizen.mdg" /**< For mdg dbus */ -#define MDG_DBUS_GROUP_PATH "/org/tizen/mdg/group" /**< For group dbus */ -#define MDG_DBUS_ENABLER_PATH "/org/tizen/mdg/enabler" /**< dbus auto-activation */ - /* LCOV_EXCL_START */ -static void __group_found_cb(Group *object, GVariant *va, gpointer user_data) +static void __event_cb(Group *object, + gint event_type, gint ret, GVariant *va, gpointer user_data) { - GVariantIter *iter = NULL; - const gchar *key; - GVariant *key_value = NULL; - mdg_group_s *group = NULL; - char *uri_path = NULL; - char *device_id = NULL; - char *group_name = NULL; - char *host_addr = NULL; - char *resource_type = NULL; - mdg_group_type_e type = MDG_GROUP_TYPE_ERROR; - NOTUSED(object); - - mdg_manager_s *handle = user_data; mdg_check_null_ret("user_data", user_data); - g_variant_get(va, "a{sv}", &iter); - while (g_variant_iter_loop(iter, "{sv}", &key, &key_value)) { - if (g_strcmp0(key, "URI") == 0) - uri_path = (char *)g_variant_get_string(key_value, NULL); - else if (g_strcmp0(key, "DeviceID") == 0) - device_id = (char *)g_variant_get_string(key_value, NULL); - else if (g_strcmp0(key, "GroupName") == 0) - group_name = (char *)g_variant_get_string(key_value, NULL); - else if (g_strcmp0(key, "HostAddress") == 0) - host_addr = (char *)g_variant_get_string(key_value, NULL); - else if (g_strcmp0(key, "GroupDeviceType") == 0) - resource_type = (char *)g_variant_get_string(key_value, NULL); - else if (g_strcmp0(key, "GroupType") == 0) - type = g_variant_get_int32(key_value); - } - - g_variant_iter_free(iter); - - group = create_group_handle(uri_path, device_id, group_name, host_addr, - resource_type, type); - if (handle->group_found_cb.found_cb) - handle->group_found_cb.found_cb(type, group, handle->group_found_cb.user_data); -} - -static void _group_find_finish_cb(Group *object, gint ret, gpointer user_data) -{ - NOTUSED(object); - mdg_manager_s *handle = user_data; - mdg_check_null_ret("user_data", user_data); - - if (handle->group_find_finish_cb.finish_cb) - handle->group_find_finish_cb.finish_cb(ret, - handle->group_find_finish_cb.user_data); -} -static void __device_found_cb(Group *object, gint count, GVariant *va, - gpointer user_data) -{ - GVariantIter *iter = NULL; - GVariantIter *iter_row = NULL; - const gchar *key; - GVariant *key_value; - mdg_device_s *device = NULL; + _BEGIN(); - NOTUSED(object); + _DBG("Event occured : %d", event_type); - mdg_manager_s *handle = user_data; - mdg_check_null_ret("user_data", user_data); + if (event_type == MDG_EVENT_GROUP_FOUND) { + mdg_group_s *group = NULL; - g_variant_get(va, "aa{sv}", &iter); - while (g_variant_iter_next(iter, "a{sv}", &iter_row)) { - char *device_id = NULL; - char *ip = NULL; - int device_type = MDG_DEVICE_TYPE_ERROR; - int port = -1; - int sec_port = -1; - char *model_name = NULL; - char *device_name = NULL; - char *platform_ver = NULL; - char *vendor_id = NULL; - char *profile = NULL; - - while (g_variant_iter_loop(iter_row, "{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, "Address") == 0) - ip = (char *)g_variant_get_string(key_value, NULL); - else if (g_strcmp0(key, "DeviceType") == 0) - device_type = g_variant_get_uint16(key_value); - else if (g_strcmp0(key, "Port") == 0) - port = g_variant_get_uint16(key_value); - else if (g_strcmp0(key, "SecurePort") == 0) - sec_port = g_variant_get_uint16(key_value); - else if (g_strcmp0(key, "ModelName") == 0) - model_name = (char *)g_variant_get_string(key_value, NULL); - else if (g_strcmp0(key, "DeviceName") == 0) - device_name = (char *)g_variant_get_string(key_value, NULL); - else if (g_strcmp0(key, "PlatformVer") == 0) - platform_ver = (char *)g_variant_get_string(key_value, NULL); - else if (g_strcmp0(key, "VendorID") == 0) - vendor_id = (char *)g_variant_get_string(key_value, NULL); - else if (g_strcmp0(key, "Profile") == 0) - profile = (char *)g_variant_get_string(key_value, NULL); + group = mdg_get_group_from_variant(va); + if (handle->group_found_cb.found_cb) { + handle->group_found_cb.found_cb(group->type, group, + handle->group_found_cb.user_data); + } else { + _ERR("The callback not exists"); } - g_variant_iter_free(iter_row); - - device = create_device_handle(device_id, ip, device_type, port, - sec_port, model_name, device_name, platform_ver, vendor_id, profile); - if (handle->device_found_cb.found_cb) - handle->device_found_cb.found_cb(device, handle->device_found_cb.user_data); - } - g_variant_iter_free(iter); -} - -static void _device_find_finish_cb(Group *object, gint ret, gpointer user_data) -{ - NOTUSED(object); - - mdg_manager_s *handle = user_data; - mdg_check_null_ret("user_data", user_data); - - if (handle->device_find_finish_cb.finish_cb) - handle->device_find_finish_cb.finish_cb(ret, - handle->device_find_finish_cb.user_data); -} - -static void __mowned_device_found_cb(Group *object, gint count, GVariant *va, - gpointer user_data) -{ - GVariantIter *iter = NULL; - GVariantIter *iter_row = NULL; - const gchar *key; - GVariant *key_value; - mdg_device_s *device = NULL; - - NOTUSED(object); - - mdg_manager_s *handle = user_data; - mdg_check_null_ret("user_data", user_data); - - g_variant_get(va, "aa{sv}", &iter); - while (g_variant_iter_next(iter, "a{sv}", &iter_row)) { - char *device_id = NULL; - char *ip = NULL; - int device_type = MDG_DEVICE_TYPE_ERROR; - int port = -1; - int sec_port = -1; - char *model_name = NULL; - char *device_name = NULL; - char *platform_ver = NULL; - char *vendor_id = NULL; - char *profile = NULL; - - while (g_variant_iter_loop(iter_row, "{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, "Address") == 0) - ip = (char *)g_variant_get_string(key_value, NULL); - else if (g_strcmp0(key, "DeviceType") == 0) - device_type = g_variant_get_uint16(key_value); - else if (g_strcmp0(key, "Port") == 0) - port = g_variant_get_uint16(key_value); - else if (g_strcmp0(key, "SecurePort") == 0) - sec_port = g_variant_get_uint16(key_value); - else if (g_strcmp0(key, "ModelName") == 0) - model_name = (char *)g_variant_get_string(key_value, NULL); - else if (g_strcmp0(key, "DeviceName") == 0) - device_name = (char *)g_variant_get_string(key_value, NULL); - else if (g_strcmp0(key, "PlatformVer") == 0) - platform_ver = (char *)g_variant_get_string(key_value, NULL); - else if (g_strcmp0(key, "VendorID") == 0) - vendor_id = (char *)g_variant_get_string(key_value, NULL); - else if (g_strcmp0(key, "Profile") == 0) - profile = (char *)g_variant_get_string(key_value, NULL); + } else if (event_type == MDG_EVENT_GROUP_FIND_FINISH) { + if (handle->group_find_finish_cb.finish_cb) { + handle->group_find_finish_cb.finish_cb(ret, + handle->group_find_finish_cb.user_data); + } else { + _ERR("The callback not exists"); + } + } else if (event_type == MDG_EVENT_DEVICE_FOUND) { + mdg_device_s *device = NULL; + + device = mdg_get_device_from_variant(va); + if (handle->device_found_cb.found_cb) { + handle->device_found_cb.found_cb(device, + handle->device_found_cb.user_data); + } else { + _ERR("The callback not exists"); + } + } else if (event_type == MDG_EVENT_DEVICE_FIND_FINISH) { + if (handle->device_find_finish_cb.finish_cb) { + handle->device_find_finish_cb.finish_cb(ret, + handle->device_find_finish_cb.user_data); + } else { + _ERR("The callback not exists"); + } + } else if (event_type == MDG_EVENT_INVITE_DEVICE_FINISH) { + if (handle->device_invite_finish_cb.finish_cb) { + handle->device_invite_finish_cb.finish_cb(ret, + handle->device_invite_finish_cb.user_data); + } else { + _ERR("The callback not exists"); + } + } else if (event_type == MDG_EVENT_EJECT_DEVICE_FINISH) { + if (handle->device_eject_finish_cb.finish_cb) { + handle->device_eject_finish_cb.finish_cb(ret, + handle->device_eject_finish_cb.user_data); + } else { + _ERR("The callback not exists"); + } + } else if (event_type == MDG_EVENT_SEND_DATA_FINISH) { + if (handle->send_data_finish_cb.finish_cb) { + handle->send_data_finish_cb.finish_cb(ret, + handle->send_data_finish_cb.user_data); + } else { + _ERR("The callback not exists"); } - g_variant_iter_free(iter_row); - - device = create_device_handle(device_id, ip, device_type, port, - sec_port, model_name, device_name, platform_ver, vendor_id, profile); - if (handle->mowned_device_found_cb.found_cb) - handle->mowned_device_found_cb.found_cb(device, - handle->mowned_device_found_cb.user_data); - destroy_device_handle(device); - } - g_variant_iter_free(iter); -} - -static void _mowned_device_find_finish_cb(Group *object, gint ret, - gpointer user_data) -{ - NOTUSED(object); - - mdg_manager_s *handle = user_data; - mdg_check_null_ret("user_data", user_data); - - if (handle->mowned_device_find_finish_cb.finish_cb) - handle->mowned_device_find_finish_cb.finish_cb(ret, - handle->mowned_device_find_finish_cb.user_data); -} - -static void __device_invite_result_cb(Group *object, gint ret, gpointer user_data) -{ - NOTUSED(object); - - mdg_manager_s *handle = user_data; - mdg_check_null_ret("user_data", user_data); - - if (handle->device_invite_result_cb.result_cb) - handle->device_invite_result_cb.result_cb(ret, - handle->device_invite_result_cb.user_data); -} - -static void __device_eject_result_cb(Group *object, gint ret, gpointer user_data) -{ - NOTUSED(object); - - mdg_manager_s *handle = user_data; - mdg_check_null_ret("user_data", user_data); - - if (handle->device_eject_result_cb.result_cb) - handle->device_eject_result_cb.result_cb(ret, - handle->device_eject_result_cb.user_data); -} - -static void __send_data_finish_cb(Group *object, gchar *resp_data, gint ret, - gpointer user_data) -{ - NOTUSED(object); - - mdg_manager_s *handle = user_data; - mdg_check_null_ret("user_data", user_data); - - if (handle->send_data_finish_cb.finish_cb) - handle->send_data_finish_cb.finish_cb(ret, resp_data, - handle->send_data_finish_cb.user_data); -} - -static void __request_result_cb(Group *object, gchar *cmd, gchar *device_id, - GVariant *arg, gint ret, gpointer user_data) -{ - int len, length = 0; - unsigned char *data; - GVariantIter *iter; - - NOTUSED(object); - - mdg_manager_s *handle = user_data; - mdg_check_null_ret("user_data", user_data); - - g_variant_get(arg, "(iay)", &len, &iter); - - data = g_try_malloc0(len + 1); - if (data) { - data = NULL; - len = 0; } else { - while (g_variant_iter_loop(iter, "y", &data[length])) - length += 1; - - data[length > len ? len : length] = '\0'; - _DBG("Received result length %d data %s", len, data); - - g_variant_iter_free(iter); + _ERR("Unknown Event"); } - if (handle->request_result_cb.result_cb) - handle->request_result_cb.result_cb(cmd, device_id, data, len, ret, - handle->request_result_cb.user_data); - - g_free(data); -} - -static void __monitor_result_cb(Group *object, gchar *uuid, gchar *group_name, - gchar *status, gpointer user_data) -{ - mdg_device_status_e device_status; - mdg_manager_s *handle = user_data; - mdg_check_null_ret("user_data", user_data); - - _DBG("Received Monitor Result uuid %s group name %s status %s", uuid, - group_name, status); - - if (g_strcmp0(status, "Added") == 0) - device_status = MDG_DEVICE_ADDED; - else if (g_strcmp0(status, "Removed") == 0) - device_status = MDG_DEVICE_REMOVED; - else - return; - - if (handle->monitor_result_cb.cb) { - handle->monitor_result_cb.cb(uuid, group_name, device_status, - handle->monitor_result_cb.user_data); - } + _END(); } /* LCOV_EXCL_STOP */ - static int _enabler_proxy_init(mdg_manager_s *handle) { GError *error = NULL; @@ -426,27 +201,7 @@ static int _group_proxy_init(mdg_manager_s *handle) } g_signal_connect(handle->group_proxy, - "group-found", G_CALLBACK(__group_found_cb), handle); - g_signal_connect(handle->group_proxy, - "group-find-finish", G_CALLBACK(_group_find_finish_cb), handle); - g_signal_connect(handle->group_proxy, - "device-found", G_CALLBACK(__device_found_cb), handle); - g_signal_connect(handle->group_proxy, - "device-find-finish", G_CALLBACK(_device_find_finish_cb), handle); - g_signal_connect(handle->group_proxy, - "mowned-device-found", G_CALLBACK(__mowned_device_found_cb), handle); - g_signal_connect(handle->group_proxy, - "mowned-device-find-finish", G_CALLBACK(_mowned_device_find_finish_cb), handle); - g_signal_connect(handle->group_proxy, - "device-invite-result", G_CALLBACK(__device_invite_result_cb), handle); - g_signal_connect(handle->group_proxy, - "device-eject-result", G_CALLBACK(__device_eject_result_cb), handle); - g_signal_connect(handle->group_proxy, - "send-data-finish", G_CALLBACK(__send_data_finish_cb), handle); - g_signal_connect(handle->group_proxy, - "request-result", G_CALLBACK(__request_result_cb), handle); - g_signal_connect(handle->group_proxy, - "device-monitor-result", G_CALLBACK(__monitor_result_cb), handle); + "event", G_CALLBACK(__event_cb), handle); return MDG_ERROR_NONE; } @@ -480,8 +235,6 @@ int gdbus_initialize(mdg_manager_s *handle) if (handle->enabler_proxy == NULL) ret = -1; /* LCOV_EXCL_LINE */ - handle->ca = g_cancellable_new(); - return ret; } @@ -492,10 +245,6 @@ int gdbus_deinitialize(mdg_manager_s *handle) _group_proxy_deinit(handle); _enabler_proxy_deinit(handle); - g_cancellable_cancel(handle->ca); - g_object_unref(handle->ca); - handle->ca = NULL; - return ret; } diff --git a/src/mdg_dbus.h b/src/mdg_dbus.h index 838b2fd..5dcf832 100644 --- a/src/mdg_dbus.h +++ b/src/mdg_dbus.h @@ -25,6 +25,10 @@ extern "C" { #endif +#define MDG_DBUS_SERVICE "org.tizen.mdg" /**< For mdg dbus */ +#define MDG_DBUS_GROUP_PATH "/org/tizen/mdg/group" /**< For group dbus */ +#define MDG_DBUS_ENABLER_PATH "/org/tizen/mdg/enabler" /**< dbus auto-activation */ + int gdbus_initialize(mdg_manager_s *handle); int gdbus_deinitialize(mdg_manager_s *handle); diff --git a/src/mdg_gdbus.xml b/src/mdg_gdbus.xml index e7535bf..e30676d 100644 --- a/src/mdg_gdbus.xml +++ b/src/mdg_gdbus.xml @@ -21,77 +21,40 @@ - - - - - - - - - - - - + + - + + - + - + - - - - - - - - - - - - - + + - - - - + + + - - - - - - - - - - - - - - - - - - + + + - - - - + + + @@ -100,20 +63,6 @@ - - - - - - - - - - - - - - @@ -137,54 +86,11 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + - - - - - - - - - - - - - - - + diff --git a/src/mdg_private.h b/src/mdg_private.h index e4ccfd6..6bc4beb 100644 --- a/src/mdg_private.h +++ b/src/mdg_private.h @@ -53,6 +53,7 @@ } #endif + /** * @brief New group found callback structure * @since_tizen 5.0 @@ -90,40 +91,22 @@ typedef struct _device_find_finish_cb_t { } device_find_finish_cb_t; /** - * @brief New my own device found callback structure - * @since_tizen 5.0 - */ -typedef struct _mowned_device_found_cb_t { - mdg_device_found_cb found_cb; /**< User callback to be called */ - void *user_data; /**< User data pointer */ -} mowned_device_found_cb_t; - -/** - * @brief Finding my own device done callback structure - * @since_tizen 5.0 - */ -typedef struct _mowned_device_find_finish_cb_t { - mdg_device_find_finish_cb finish_cb; /**< User callback to be called */ - void *user_data; /**< User data pointer */ -} mowned_device_find_finish_cb_t; - -/** * @brief Inviting a device done callback structure * @since_tizen 5.0 */ -typedef struct _device_invite_result_cb_t { - mdg_group_invite_device_result_cb result_cb; /**< User callback to be called */ +typedef struct _device_invite_finish_cb_t { + mdg_group_invite_device_finish_cb finish_cb; /**< User callback to be called */ void *user_data; /**< User data pointer */ -} device_invite_result_cb_t; +} device_invite_finish_cb_t; /** * @brief Ejecting the device done callback structure * @since_tizen 5.0 */ -typedef struct _device_eject_result_cb_t { - mdg_group_eject_device_result_cb result_cb; /**< User callback to be called */ +typedef struct _device_eject_finish_cb_t { + mdg_group_eject_device_finish_cb finish_cb; /**< User callback to be called */ void *user_data; /**< User data pointer */ -} device_eject_result_cb_t; +} device_eject_finish_cb_t; /** * @brief Sending data to the device done callback structure @@ -144,48 +127,38 @@ typedef struct _request_result_cb_t { } request_result_cb_t; /** - * @brief Sending device monitor result callback structure - * @since_tizen 5.0 - */ -typedef struct _monitor_result_cb_t { - mdg_device_monitor_result_cb cb; /**< User callback to be called */ - void *user_data; /**< User data pointer */ -} monitor_result_cb_t; - -/** * @brief The mdg-manager context * @since_tizen 5.0 */ typedef struct _mdg_manager_s { - GCancellable *ca; /**< Cancelable */ - Group *group_proxy; /**< To receive signal from cmdgd */ Enabler *enabler_proxy; /**< Enbler proxy */ GDBusConnection *system_bus; /**< GDBus System Bus */ + GSList *channel_cb_list; group_found_cb_t group_found_cb; /**< When it called after finding a every single group */ group_find_finish_cb_t group_find_finish_cb; /**< When it called the group finging time is up */ device_found_cb_t device_found_cb; /**< When it called after finding a every single device */ device_find_finish_cb_t device_find_finish_cb; /**< When it called the device finging time is up */ - mowned_device_found_cb_t mowned_device_found_cb; /**< When it called after finding a every single my own device */ - mowned_device_find_finish_cb_t mowned_device_find_finish_cb; /**< When it called the time of finding my own devices is up */ - device_invite_result_cb_t device_invite_result_cb; /**< When it called after invinting a device done or timeout */ - device_eject_result_cb_t device_eject_result_cb; /**< When it called after ejecting the device done or timeout */ + device_invite_finish_cb_t device_invite_finish_cb; /**< When it called after invinting a device done or timeout */ + 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 */ - monitor_result_cb_t monitor_result_cb; /**< It is called after device status is changed */ } mdg_manager_s; +#define CHECK_HANDLE_IS_VALID(handle) { \ + if (g_slist_find (handle_list, handle) == NULL) \ + return MDG_ERROR_UNKNOWN; \ +} + /** * @brief The group structure * @since_tizen 5.0 */ typedef struct _mdg_group_s { - char *uri_path; /**< URI Path for group resource */ char *device_id; /**< Device ID of the device has this group resource */ - char *group_name; /**< Group Name (Friendly name) */ char *host_addr; /**< Host address */ - char *resource_type; /**< Resource type */ + char *group_name; /**< Group Name (Friendly name) */ mdg_group_type_e type; /**< Mine or Remote */ } mdg_group_s; @@ -195,16 +168,28 @@ typedef struct _mdg_group_s { */ typedef struct _mdg_device_s { char *device_id; /**< Device ID */ - char *ip; /**< Device IP */ - int device_type; /**< Device Type */ + char *addr; /**< Device IP */ int port; /**< Port Number */ - int sec_port; /**< Secure Port Number */ + int secure_port; /**< Secure Port Number */ + unsigned int conn_type; /**< Connection type */ char *model_name; char *device_name; char *platform_ver; char *vendor_id; char *profile; + bool is_invited; + mdg_device_type_e type; /**< Device Type */ } mdg_device_s; +typedef enum { + MDG_EVENT_GROUP_FOUND = 0, + MDG_EVENT_GROUP_FIND_FINISH, + MDG_EVENT_DEVICE_FOUND, + MDG_EVENT_DEVICE_FIND_FINISH, + MDG_EVENT_INVITE_DEVICE_FINISH, + MDG_EVENT_EJECT_DEVICE_FINISH, + MDG_EVENT_REQUEST_FINISH, + MDG_EVENT_SEND_DATA_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 1593e6c..09d94bd 100755 --- a/src/mdg_util.c +++ b/src/mdg_util.c @@ -20,172 +20,115 @@ #include #include -mdg_group_s *create_group_handle(char *uri_path, char *device_id, - char *group_name, char *host_addr, char *resource_type, mdg_group_type_e type) +mdg_group_s *mdg_get_group_from_variant(GVariant *va) { + char *device_id = NULL; + char *host_addr = NULL; + char *group_name = NULL; + mdg_group_type_e type = MDG_GROUP_TYPE_LOCAL; + GVariantIter *iter = NULL; + const gchar *key; + GVariant *key_value = NULL; + mdg_group_s *group = calloc(1, sizeof(mdg_group_s)); if (NULL == group) { - /* LCOV_EXCL_START */ - _ERR("Memory allocation failed"); - goto CREATE_GROUP_HANDLER_ERROR; - /* LCOV_EXCL_STOP */ + /* LCOV_EXCL_START */ + _ERR("Memory allocation failed"); + return NULL; + /* LCOV_EXCL_STOP */ + } + + 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, "HostAddr") == 0) + host_addr = (char *)g_variant_get_string(key_value, NULL); + else if (g_strcmp0(key, "GroupName") == 0) + group_name = (char *)g_variant_get_string(key_value, NULL); + else if (g_strcmp0(key, "Type") == 0) + type = g_variant_get_int32(key_value); } - group->uri_path = g_strdup(uri_path); group->device_id = g_strdup(device_id); - group->group_name = g_strdup(group_name); group->host_addr = g_strdup(host_addr); - group->resource_type = g_strdup(resource_type); + group->group_name = g_strdup(group_name); group->type = type; - if (!group->uri_path || !group->device_id || - !group->host_addr || !group->resource_type) { - /* LCOV_EXCL_START */ - _ERR("Memory allocation failed"); - goto CREATE_GROUP_HANDLER_ERROR; - /* LCOV_EXCL_STOP */ - } - return group; + g_variant_iter_free(iter); -CREATE_GROUP_HANDLER_ERROR: - /* LCOV_EXCL_START */ - if (group) { - if (group->uri_path) { - free(group->uri_path); - group->uri_path = NULL; - } - if (group->device_id) { - free(group->device_id); - group->device_id = NULL; - } - if (group->group_name) { - free(group->group_name); - group->group_name = NULL; - } - if (group->host_addr) { - free(group->host_addr); - group->host_addr = NULL; - } - if (group->resource_type) { - free(group->resource_type); - group->resource_type = NULL; - } - free(group); - group = NULL; - } - return NULL; - /* LCOV_EXCL_STOP */ + return group; } -mdg_device_s *create_device_handle(char *device_id, char *ip, - int device_type, int port, int sec_port, char *model_name, char *device_name, - char *platform_ver, char *vendor_id, char *profile) +mdg_device_s *mdg_get_device_from_variant(GVariant *va) { + char *device_id = NULL; + char *addr = NULL; + int port; + int secure_port; + int conn_type; + char *model_name = NULL; + char *device_name = NULL; + char *platform_ver = NULL; + char *vendor_id = NULL; + char *profile = NULL; + bool is_invited; + int type = MDG_DEVICE_TYPE_LOCAL; + GVariantIter *iter = NULL; + const gchar *key; + GVariant *key_value = NULL; + mdg_device_s *device = calloc(1, sizeof(mdg_device_s)); if (NULL == device) { - /* LCOV_EXCL_START */ - _ERR("Memory allocation failed"); - goto CREATE_DEVICE_HANDLER_ERROR; - /* LCOV_EXCL_STOP */ + /* LCOV_EXCL_START */ + _ERR("Memory allocation failed"); + return NULL; + /* LCOV_EXCL_STOP */ + } + + 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, "Addr") == 0) + addr = (char *)g_variant_get_string(key_value, NULL); + else if (g_strcmp0(key, "Port") == 0) + port = g_variant_get_int32(key_value); + else if (g_strcmp0(key, "SecurePort") == 0) + secure_port = g_variant_get_int32(key_value); + else if (g_strcmp0(key, "ConnType") == 0) + conn_type = g_variant_get_int32(key_value); + else if (g_strcmp0(key, "ModelName") == 0) + model_name = (char *)g_variant_get_string(key_value, NULL); + else if (g_strcmp0(key, "DeviceName") == 0) + device_name = (char *)g_variant_get_string(key_value, NULL); + else if (g_strcmp0(key, "PlatformVer") == 0) + platform_ver = (char *)g_variant_get_string(key_value, NULL); + else if (g_strcmp0(key, "VendorID") == 0) + vendor_id = (char *)g_variant_get_string(key_value, NULL); + else if (g_strcmp0(key, "Profile") == 0) + profile = (char *)g_variant_get_string(key_value, NULL); + else if (g_strcmp0(key, "IsInvited") == 0) + is_invited = g_variant_get_int32(key_value); + else if (g_strcmp0(key, "Type") == 0) + type = g_variant_get_int32(key_value); } device->device_id = g_strdup(device_id); - device->ip = g_strdup(ip); - device->device_type = device_type; + device->addr = g_strdup(addr); device->port = port; - device->sec_port = sec_port; + device->secure_port = secure_port; + device->conn_type = conn_type; device->model_name = g_strdup(model_name); device->device_name = g_strdup(device_name); device->platform_ver = g_strdup(platform_ver); device->vendor_id = g_strdup(vendor_id); device->profile = g_strdup(profile); + device->is_invited = is_invited; + device->type = type; - if (!device->device_id || !device->ip || !device->model_name || !device->device_name || - !device->platform_ver || !device->vendor_id || !device->profile) { - /* LCOV_EXCL_START */ - _ERR("Memory allocation failed"); - goto CREATE_DEVICE_HANDLER_ERROR; - /* LCOV_EXCL_STOP */ - } + g_variant_iter_free(iter); return device; - -CREATE_DEVICE_HANDLER_ERROR: - /* LCOV_EXCL_START */ - if (device) { - if (device->device_id) { - free(device->device_id); - device->device_id = NULL; - } - if (device->model_name) { - free(device->model_name); - device->model_name = NULL; - } - if (device->device_name) { - free(device->device_name); - device->device_name = NULL; - } - if (device->platform_ver) { - free(device->platform_ver); - device->platform_ver = NULL; - } - if (device->vendor_id) { - free(device->vendor_id); - device->vendor_id = NULL; - } - if (device->profile) { - free(device->profile); - device->profile = NULL; - } - if (device->ip) { - free(device->ip); - device->ip = NULL; - } - free(device); - device = NULL; - } - return NULL; - /* LCOV_EXCL_STOP */ -} - -void destroy_device_handle(mdg_device_s *device) -{ - if (NULL == device) { - /* LCOV_EXCL_START */ - _ERR("Memory allocation failed"); - return; - /* LCOV_EXCL_STOP */ - } - - if (device->device_id) { - free(device->device_id); - device->device_id = NULL; - } - if (device->model_name) { - free(device->model_name); - device->model_name = NULL; - } - if (device->device_name) { - free(device->device_name); - device->device_name = NULL; - } - if (device->platform_ver) { - free(device->platform_ver); - device->platform_ver = NULL; - } - if (device->vendor_id) { - free(device->vendor_id); - device->vendor_id = NULL; - } - if (device->profile) { - free(device->profile); - device->profile = NULL; - } - if (device->ip) { - free(device->ip); - device->ip = NULL; - } - free(device); - device = NULL; } diff --git a/src/mdg_util.h b/src/mdg_util.h index 56c8843..aaed549 100755 --- a/src/mdg_util.h +++ b/src/mdg_util.h @@ -25,12 +25,8 @@ extern "C" { #endif -mdg_group_s *create_group_handle(char *uri_path, char *device_id, - char *group_name, char *host_addr, char *resource_type, mdg_group_type_e type); -mdg_device_s *create_device_handle(char *device_id, char *ip, int device_type, - int port, int sec_port, char *model_name, char *device_name, - char *platform_ver, char *vendor_id, char *profile); -void destroy_device_handle(mdg_device_s *device); +mdg_device_s *mdg_get_device_from_variant(GVariant *va); +mdg_group_s *mdg_get_group_from_variant(GVariant *va); #ifdef __cplusplus } diff --git a/test/common.h b/test/common.h old mode 100644 new mode 100755 diff --git a/test/main.c b/test/main.c old mode 100644 new mode 100755 index bb4bf44..3d807f8 --- a/test/main.c +++ b/test/main.c @@ -59,7 +59,6 @@ const char* mdg_error_to_string(mdg_error_e err) CASE_TO_STR(MDG_ERROR_PLUGIN_FAIL) CASE_TO_STR(MDG_ERROR_ALREADY_IN_PROGRESS) CASE_TO_STR(MDG_ERROR_NOT_STARTED) - CASE_TO_STR(MDG_ERROR_ALREADY_INITIALIZED) default : return "MDG_ERROR_UNKNOWN"; } @@ -68,7 +67,7 @@ const char* mdg_error_to_string(mdg_error_e err) const char *mdg_group_type_to_string(mdg_group_type_e e) { switch (e) { - CASE_TO_STR(MDG_GROUP_TYPE_MINE) + CASE_TO_STR(MDG_GROUP_TYPE_LOCAL) CASE_TO_STR(MDG_GROUP_TYPE_REMOTE) default : return "Unknown station type"; @@ -114,6 +113,11 @@ static gboolean __create_init_menu(struct menu_data init_menu[1]) return TRUE; } +void _free_group(gpointer data) +{ + mdg_group_info_destroy(data); +} + void _free_device(gpointer data) { mdg_device_info_destroy(data); @@ -150,7 +154,7 @@ int main(int arg, char **argv) OUT: if (found_group_list) - g_list_free_full(found_group_list, _free_device); + g_list_free_full(found_group_list, _free_group); if (found_device_list) g_list_free_full(found_device_list, _free_device); diff --git a/test/mdg-manager.c b/test/mdg-manager.c index a299e0a..9a5c8ce 100755 --- a/test/mdg-manager.c +++ b/test/mdg-manager.c @@ -30,20 +30,17 @@ mdg_h handle = NULL; GList *found_group_list; GList *found_device_list; -GList *my_devices_list; +GList *invited_device_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"; -#if 0 -static char group_idx_a[MENU_DATA_SIZE + 1] = "1"; -static char group_idx_b[MENU_DATA_SIZE + 1] = "2"; -#endif 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 char monitor[MENU_DATA_SIZE + 1] = "1"; +static char channel_id[MENU_DATA_SIZE + 1] = "Channel1"; +//static char monitor[MENU_DATA_SIZE + 1] = "1"; static int run_group_find(MManager *mm, struct menu_data *menu); static int run_devices_find(MManager *mm, struct menu_data *menu); @@ -100,25 +97,6 @@ void receive_request_result(char *cmd, char *device_id, unsigned char *arg, } } -int run_get_my_id(MManager *mm, struct menu_data *menu) -{ - msg("Get Device ID of my device"); - - int ret; - char *uuid; - ret = mdg_device_info_get_my_uuid(handle, &uuid); - - if (MDG_ERROR_NONE != ret) { - msgr("Failed to Get My Device ID: [%s(0x%X)]", mdg_error_to_string(ret), ret); - return RET_FAILURE; - } - - msg(" - mdg_device_my_deviceid() ret: [0x%X] [%s]", ret, mdg_error_to_string(ret)); - msgb("[ID] : [%s]", uuid); - - return RET_SUCCESS; -} - void _device_eject_result_cb(int result, void *user_data) { msgb("\rEject Device Complete [%s]", mdg_error_to_string(result)); @@ -127,7 +105,7 @@ void _device_eject_result_cb(int result, void *user_data) static int run_device_eject(MManager *mm, struct menu_data *menu) { int ret; - int idx = 1; + int idx; mdg_group_h group = NULL; mdg_device_h device = NULL; @@ -186,7 +164,7 @@ void _device_invite_result_cb(int result, void *user_data) static int run_device_invite(MManager *mm, struct menu_data *menu) { int ret; - int idx = 1; + int idx; mdg_group_h group = NULL; mdg_device_h device = NULL; @@ -244,54 +222,90 @@ static void _destroy_mdg_device_info(gpointer data) static int run_devices_show(MManager *mm, struct menu_data *menu) { - char *deviceid = NULL; - char *ip = NULL; - mdg_device_type_e devicetype; mdg_device_h device; - int ret; - int count; - mdg_device_h *devices = NULL; + int i; GList *iter = NULL; - ret = mdg_device_get_found_devices(handle, &devices, &count); - if (MDG_ERROR_NONE != ret) { - msgr("Failed to Get Found Devices: [%s(0x%X)]", - mdg_error_to_string(ret), ret); - return RET_FAILURE; - } else { - if (found_device_list) { - g_list_free_full(found_device_list, _destroy_mdg_device_info); - found_device_list = NULL; + /* Get a first item */ + i = 0; + iter = g_list_first(found_device_list); + while (NULL != iter) { + device = iter->data; + if (!device) { + msgr("device is null"); + break; } - for (i = 0; i < count; i++) - found_device_list = g_list_append(found_device_list, devices[i]); + char *model_name; + char *addr; + mdg_device_info_get_model_name(device, &model_name); + mdg_device_info_get_addr(device, &addr); + + msgp("[%d] Model : %s, Addr : %s", i+1, model_name, addr); + + mdg_device_h cloned_device; + char *cloned_model_name; + char *cloned_addr; + + mdg_device_info_clone(&cloned_device, device); + mdg_device_info_get_model_name(cloned_device, &cloned_model_name); + mdg_device_info_get_addr(cloned_device, &cloned_addr); + + msgp("*Cloned* [%d] Model : %s, Addr : %s", i+1, cloned_model_name, cloned_addr); + + if (model_name) + free(model_name); + + if (addr) + free(addr); + + if (cloned_model_name) + free(cloned_model_name); + + if (cloned_addr) + free(cloned_addr); + + mdg_device_info_destroy(cloned_device); + + /* Next item */ + iter = g_list_next(iter); + i++; } + return RET_SUCCESS; +} + +static int run_invited_devices_show(MManager *mm, struct menu_data *menu) +{ + mdg_device_h device; + + int i; + GList *iter = NULL; + /* Get a first item */ i = 0; - iter = g_list_first(found_device_list); + iter = g_list_first(invited_device_list); while (NULL != iter) { device = iter->data; if (!device) { - msgr("device list is null"); + msgr("device is null"); break; } - mdg_device_info_get_device_id(device, &deviceid); - mdg_device_info_get_ip(device, &ip); - mdg_device_info_get_device_type(device, &devicetype); - msgp("[%d] deviceid: %s, IP: %s type: %s", i+1, deviceid, ip, - __device_type_to_string(devicetype)); - - if (deviceid) { - free(deviceid); - deviceid = NULL; - } - if (ip) { - free(ip); - ip = NULL; - } + + char *model_name; + char *addr; + mdg_device_info_get_model_name(device, &model_name); + mdg_device_info_get_addr(device, &addr); + + msgp("[%d] Model : %s, Addr : %s", i+1, model_name, addr); + + if (model_name) + free(model_name); + + if (addr) + free(addr); + /* Next item */ iter = g_list_next(iter); i++; @@ -357,65 +371,12 @@ static int run_group_get_members(MManager *mm, struct menu_data *menu) return RET_SUCCESS; } #endif -#if 0 -static int run_group_merge(MManager *mm, struct menu_data *menu) -{ - int ret; - int a, b; - mdg_group_h group_a; - mdg_group_h group_b; - - msg("Merge Group"); - - if (strlen(group_idx_a)) { - a = (unsigned short)strtol(group_idx_a, NULL, 10); - if (0 >= a) { - msgp("Invalid index. set to 1"); - a = 1; - } - } - - if (found_group_list) { - group_a = g_list_nth_data(found_group_list, a - 1); - if (NULL == group_a) { - msgr("Failed to g_hash_table_find"); - return RET_FAILURE; - } - } - - if (strlen(group_idx_b)) { - b = (unsigned short)strtol(group_idx_b, NULL, 10); - if (0 >= b) { - msgp("Invalid index. set to 2"); - b = 1; - } - } - - if (found_group_list) { - group_b = g_list_nth_data(found_group_list, b - 1); - if (NULL == group_b) { - msgr("Failed to g_hash_table_find"); - return RET_FAILURE; - } - } - - - ret = mdg_group_merge(handle, group_a, group_b); - if (MDG_ERROR_NONE != ret) { - msgr("Failed to Merge Group: [%s(0x%X)]", mdg_error_to_string(ret), ret); - return RET_FAILURE; - } - msg(" - mdg_group_merge() ret: [0x%X] [%s]", ret, mdg_error_to_string(ret)); - - return RET_SUCCESS; -} -#endif static int run_group_delete(MManager *mm, struct menu_data *menu) { int ret; - int idx = 1; - mdg_group_h group = NULL; + int idx; + mdg_group_h group; msg("Delete Group"); @@ -445,40 +406,6 @@ static int run_group_delete(MManager *mm, struct menu_data *menu) return RET_SUCCESS; } -int run_device_show_found(MManager *mm, struct menu_data *menu) -{ - int ret; - int count; - mdg_device_h *devices = NULL; - - ret = mdg_device_get_found_devices(handle, &devices, &count); - if (MDG_ERROR_NONE != ret) { - msgr("Failed to Get Found Devices: [%s(0x%X)]", mdg_error_to_string(ret), ret); - return RET_FAILURE; - } - msg(" - mdg_device_get_found_devices() ret: [0x%X] [%s]", ret, mdg_error_to_string(ret)); - - for (int i = 0; i < count; i++) { - char *device_id = NULL; - char *ip = NULL; - mdg_device_type_e device_type; - - mdg_device_info_get_device_id(devices[i], &device_id); - mdg_device_info_get_ip(devices[i], &ip); - mdg_device_info_get_device_type(devices[i], &device_type); - - msgb("\n[ID] %s [IP] %s [Type] %s", device_id, ip, - __device_type_to_string(device_type)); - - if (device_id) - free(device_id); - if (ip) - free(ip); - } - - return RET_SUCCESS; -} - void _device_finish_cb(int result, void *user_data) { msgb("\rFind Device Finished ret: [0x%X] [%s]", result, mdg_error_to_string(result)); @@ -486,7 +413,7 @@ void _device_finish_cb(int result, void *user_data) bool _device_found_cb(mdg_device_h device, void *user_data) { - char *ip = NULL; + char *addr = NULL; char *device_id = NULL; char *model_name = NULL; mdg_device_type_e device_type; @@ -494,9 +421,9 @@ bool _device_found_cb(mdg_device_h device, void *user_data) gboolean is_exist = FALSE; mdg_device_info_get_device_id(device, &device_id); - mdg_device_info_get_ip(device, &ip); - mdg_device_info_get_device_type(device, &device_type); + mdg_device_info_get_addr(device, &addr); mdg_device_info_get_model_name(device, &model_name); + mdg_device_info_get_type(device, &device_type); iter = found_device_list; while (iter != NULL) { @@ -518,14 +445,14 @@ bool _device_found_cb(mdg_device_h device, void *user_data) if (is_exist == FALSE) { found_device_list = g_list_append(found_device_list, device); - msgp("\r[ID] %s [IP] %s [Type] %s [Name] %s", device_id, ip, + msgp("\r[ID] %s [IP] %s [Type] %s [Name] %s", device_id, addr, __device_type_to_string(device_type), model_name); } if (device_id) free(device_id); - if (ip) - free(ip); + if (addr) + free(addr); return TRUE; } @@ -533,13 +460,13 @@ bool _device_found_cb(mdg_device_h device, void *user_data) static int run_devices_find(MManager *mm, struct menu_data *menu) { int ret; - int duration = 2; + int duration; msg("Find Devices"); if (strlen(timeout)) duration = (unsigned short)strtol(timeout, NULL, 10); - ret = mdg_device_find(handle, duration, _device_found_cb, _device_finish_cb, NULL); + ret = mdg_device_find(handle, duration, false, _device_found_cb, _device_finish_cb, NULL); if (MDG_ERROR_NONE != ret) { msgr("Failed to Find Devices: [%s(0x%X)]", mdg_error_to_string(ret), ret); return RET_FAILURE; @@ -554,36 +481,71 @@ static int run_devices_find(MManager *mm, struct menu_data *menu) return RET_SUCCESS; } -int run_device_show_my_device(MManager *mm, struct menu_data *menu) +int run_device_show_local_device(MManager *mm, struct menu_data *menu) { int ret = 0; mdg_device_h device = NULL; - msg("Get My Device"); + msg("Get Local Device"); - ret = mdg_device_info_get_my_device(handle, &device); + ret = mdg_device_get_local_device(handle, &device); if (MDG_ERROR_NONE != ret) { msgr("Failed to Get My Device: [%s(0x%X)]", mdg_error_to_string(ret), ret); return RET_FAILURE; } - msg(" - mdg_device_info_get_my_device() ret: [0x%X] [%s]", ret, mdg_error_to_string(ret)); + msg(" - mdg_device_info_get_local_device() ret: [0x%X] [%s]", ret, mdg_error_to_string(ret)); if (ret == 0) { char *device_id = NULL; - char *ip = NULL; - mdg_device_type_e device_type; + char *addr = NULL; + int port; + int secure_port; + char *model_name; + char *device_name; + char *platform_ver; + char *vendor_id; + char *profile; + bool is_invited; + mdg_device_type_e type; mdg_device_info_get_device_id(device, &device_id); - mdg_device_info_get_ip(device, &ip); - mdg_device_info_get_device_type(device, &device_type); - - msgb("\n[ID] %s [IP] %s [Type] %s", device_id, ip, - __device_type_to_string(device_type)); + mdg_device_info_get_addr(device, &addr); + mdg_device_info_get_port(device, &port); + mdg_device_info_get_secure_port(device, &secure_port); + mdg_device_info_get_model_name(device, &model_name); + mdg_device_info_get_device_name(device, &device_name); + mdg_device_info_get_platform_ver(device, &platform_ver); + mdg_device_info_get_vendor_id(device, &vendor_id); + mdg_device_info_get_profile(device, &profile); + mdg_device_info_is_invited(device, &is_invited); + mdg_device_info_get_type(device, &type); + + msgb("\n[ID] %s", device_id); + msgb("[ADDR] %s", addr); + msgb("[PORT] %d", port); + msgb("[S.PORT] %d", secure_port); + msgb("[Model Name] %s", model_name); + msgb("[Device Name] %s", device_name); + msgb("[Platform Ver.] %s", platform_ver); + msgb("[Vendor ID] %s", vendor_id); + msgb("[Profile] %s", profile); + msgb("[Is Invited] %d", is_invited); + msgb("[Type] %s\n", __device_type_to_string(type)); if (device_id) free(device_id); - if (ip) - free(ip); + if (addr) + free(addr); + if (model_name) + free(model_name); + if (device_name) + free(device_name); + if (platform_ver) + free(platform_ver); + if (vendor_id) + free(vendor_id); + if (profile) + free(profile); mdg_device_info_destroy(device); device = NULL; @@ -592,45 +554,8 @@ int run_device_show_my_device(MManager *mm, struct menu_data *menu) return RET_SUCCESS; } -static int run_group_leave(MManager *mm, struct menu_data *menu) -{ - int ret; - int idx = 1; - mdg_group_h group = NULL; - - msg("Leave Group"); - - if (strlen(group_idx)) { - idx = (unsigned short)strtol(group_idx, NULL, 10); - if (0 >= idx) { - msgp("Invalid index. set to 1"); - idx = 1; - } - } - - if (found_group_list) { - group = g_list_nth_data(found_group_list, idx - 1); - if (NULL == group) { - msgr("Failed to g_hash_table_find"); - return RET_FAILURE; - } - } - - ret = mdg_request_leave_group (handle, group, receive_request_result, NULL); - if (MDG_ERROR_NONE != ret) { - msgr("Failed to Leave Group: [%s(0x%X)]", mdg_error_to_string(ret), ret); - return RET_FAILURE; - } - msg(" - mdg_request_leave_group () ret: [0x%X] [%s]", ret, mdg_error_to_string(ret)); - - return RET_SUCCESS; -} - static int run_group_show(MManager *mm, struct menu_data *menu) { - char *rt; - char *uri; - mdg_group_type_e type; mdg_group_h group; int i; @@ -645,56 +570,55 @@ static int run_group_show(MManager *mm, struct menu_data *menu) msgr("groups is null"); break; } + + char *device_id; + char *host_addr; + char *name; + mdg_group_type_e type; + + mdg_group_info_get_device_id(group, &device_id); + mdg_group_info_get_host_addr(group, &host_addr); + mdg_group_info_get_name(group, &name); mdg_group_info_get_type(group, &type); - mdg_group_info_get_uri_path(group, &uri); - mdg_group_info_get_resource_type(group, &rt); - msgp("[%d] type: %s, URI: %s RT: %s", i+1, mdg_group_type_to_string(type), uri, rt); - if (uri) { - free(uri); - uri = NULL; - } - if (rt) { - free(rt); - rt = NULL; - } - /* Next item */ - iter = g_list_next(iter); - i++; - } - return RET_SUCCESS; -} + msgp("[%d] type: %s, name: %s", i+1, mdg_group_type_to_string(type), name); + msgp(" host_addr: %s, device_id: %s\n", host_addr, device_id); -static int run_group_join(MManager *mm, struct menu_data *menu) -{ - int ret; - int idx = 1; - mdg_group_h group = NULL; + mdg_group_h cloned_group; + char *cloned_device_id; + char *cloned_host_addr; + char *cloned_name; + mdg_group_type_e cloned_type; - msg("Join Group"); + mdg_group_info_clone(&cloned_group, group); + mdg_group_info_get_device_id(cloned_group, &cloned_device_id); + mdg_group_info_get_host_addr(cloned_group, &cloned_host_addr); + mdg_group_info_get_name(cloned_group, &cloned_name); + mdg_group_info_get_type(cloned_group, &cloned_type); - if (strlen(group_idx)) { - idx = (unsigned short)strtol(group_idx, NULL, 10); - if (0 >= idx) { - msgp("Invalid index. set to 1"); - idx = 1; - } - } + msgp("*Cloned* [%d] type: %s, name: %s", i+1, mdg_group_type_to_string(cloned_type), cloned_name); + msgp(" host_addr: %s, device_id: %s\n", cloned_host_addr, cloned_device_id); - if (found_group_list) { - group = g_list_nth_data(found_group_list, idx - 1); - if (NULL == group) { - msgr("Failed to g_hash_table_find"); - return RET_FAILURE; - } - } + if (device_id) + free(device_id); + if (host_addr) + free(host_addr); + if (name) + free(name); - ret = mdg_request_join_group(handle, group, receive_request_result, NULL); - if (MDG_ERROR_NONE != ret) { - msgr("Failed to Join Group: [%s(0x%X)]", mdg_error_to_string(ret), ret); - return RET_FAILURE; + if (cloned_device_id) + free(cloned_device_id); + if (cloned_host_addr) + free(cloned_host_addr); + if (cloned_name) + free(cloned_name); + + mdg_group_info_destroy(cloned_group); + + /* Next item */ + iter = g_list_next(iter); + i++; } - msg(" - mdg_request_join_group() ret: [0x%X] [%s]", ret, mdg_error_to_string(ret)); return RET_SUCCESS; } @@ -704,56 +628,13 @@ static void _destroy_mdg_group_info(gpointer data) mdg_group_info_destroy((mdg_group_h)data); } -static int run_group_show_found(MManager *mm, struct menu_data *menu) -{ - int ret; - int count; - mdg_group_h *groups = NULL; - - msg("Show Found Group(s)"); - - ret = mdg_group_get_found_groups(handle, &groups, &count); - if (MDG_ERROR_NONE != ret) { - msgr("Failed to Get Found Groups: [%s(0x%X)]", mdg_error_to_string(ret), ret); - return RET_FAILURE; - } - msg(" - mdg_group_get_found_groups() ret: [0x%X] [%s]", ret, mdg_error_to_string(ret)); - - if (found_group_list) { - g_list_free_full(found_group_list, _destroy_mdg_group_info); - found_group_list = NULL; - } - - for (int i = 0; i < count; i++) { - mdg_group_type_e type; - char *uri_path; - char *group_name; - - mdg_group_info_get_type(groups[i], &type); - mdg_group_info_get_uri_path(groups[i], &uri_path); - mdg_group_info_get_name(groups[i], &group_name); - - if (type == MDG_GROUP_TYPE_MINE) - msgb("%d. type : MINE, name : %s, uri : %s", i+1, group_name, uri_path); - else - msgb("%d. type : REMOTE, name : %s, uri : %s", i+1, group_name, uri_path); - - found_group_list = g_list_append(found_group_list, groups[i]); - - g_free(uri_path); - g_free(group_name); - } - - return RET_SUCCESS; -} - bool _group_found_cb(mdg_group_type_e type, mdg_group_h group, void *user_data) { char *group_name; mdg_group_info_get_name(group, &group_name); - if (type == MDG_GROUP_TYPE_MINE) + if (type == MDG_GROUP_TYPE_LOCAL) msgp("\rfound group type : MINE, name : %s", group_name); else msgp("\rfound group type : REMOTE, name : %s", group_name); @@ -771,7 +652,7 @@ void _group_finish_cb(int result, void *user_data) static int run_group_find(MManager *mm, struct menu_data *menu) { int ret; - int duration = 2; + int duration; msg("Find Group"); if (strlen(timeout)) @@ -808,11 +689,9 @@ static int run_group_create(MManager *mm, struct menu_data *menu) return RET_SUCCESS; } -void _send_data_finish_cb(int result, char *resp_data, void *user_data) +void _send_data_finish_cb(int result, void *user_data) { msgb("\rFind Send Data Finished = %d", result); - if (resp_data != NULL && strlen(resp_data) > 0) - msgp("Response from %s", resp_data); } static int __send_data(int idx) @@ -825,14 +704,14 @@ static int __send_data(int idx) if (found_device_list) { device = g_list_nth_data(found_device_list, idx - 1); if (NULL == device) { - msgr("Find my device first"); + msgr("Find local device first"); return RET_FAILURE; } } mdg_device_info_get_device_id(device, &deviceid); - mdg_device_info_get_ip(device, &address); - msgp("Sent to [ID] %s [IP] %s", deviceid, address); + mdg_device_info_get_addr(device, &address); + msgp("Sent to [ID] %s [ADDR] %s", deviceid, address); if (deviceid) { free(deviceid); deviceid = NULL; @@ -842,7 +721,7 @@ static int __send_data(int idx) address = NULL; } - ret = mdg_device_send_data(handle, device, (unsigned char *) message, + ret = mdg_device_send_data(handle, device, 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); @@ -870,110 +749,58 @@ static int run_send_data(MManager *mm, struct menu_data *menu) return __send_data(idx); } -static int run_send_data_all(MManager *mm, struct menu_data *menu) -{ - int count = 0; - - count = g_list_length(found_device_list); - - if (0 >= count) { - msgr("No Device"); - return RET_SUCCESS; - } - - for (int i = 1; i <= count; i++) - __send_data(i); - - return RET_SUCCESS; -} - -void _mowned_device_finish_cb(int result, void *user_data) +void _invited_device_finish_cb(int result, void *user_data) { msgb("\rFind My Owned Devices Finished ret: [0x%X] [%s]", result, mdg_error_to_string(result)); } -bool _mowned_device_found_cb(mdg_device_h device, void *user_data) +bool _invited_device_found_cb(mdg_device_h device, void *user_data) { - char *ip = NULL; + char *addr = NULL; char *device_id = NULL; mdg_device_type_e device_type; mdg_device_info_get_device_id(device, &device_id); - mdg_device_info_get_ip(device, &ip); - mdg_device_info_get_device_type(device, &device_type); + mdg_device_info_get_addr(device, &addr); + mdg_device_info_get_type(device, &device_type); - msgp("\r[ID] %s [IP] %s [Type] %s", device_id, ip, + msgp("\r[ID] %s [IP] %s [Type] %s", device_id, addr, __device_type_to_string(device_type)); if (device_id) free(device_id); - if (ip) - free(ip); + if (addr) + free(addr); - my_devices_list = g_list_append(my_devices_list, device); + invited_device_list = g_list_append(invited_device_list, device); return TRUE; } -static int run_devices_find_mowned_device(MManager *mm, struct menu_data *menu) +static int run_devices_find_invited_device(MManager *mm, struct menu_data *menu) { int ret; - int duration = 2; + int duration; msg("Find My Owned Devices"); if (strlen(timeout)) duration = (unsigned short)strtol(timeout, NULL, 10); - ret = mdg_device_find_mowned_device(handle, duration, _mowned_device_found_cb, - _mowned_device_finish_cb, NULL); + ret = mdg_device_find(handle, duration, true, _invited_device_found_cb, + _invited_device_finish_cb, NULL); if (MDG_ERROR_NONE != ret) { msgr("Failed to Find My Owned Devices: [%s(0x%X)]", mdg_error_to_string(ret), ret); return RET_FAILURE; } - msg(" - mdg_device_find_mowned_device() ret: [0x%X] [%s]", - ret, mdg_error_to_string(ret)); - - if (my_devices_list) { - g_list_free_full(my_devices_list, _destroy_mdg_device_info); - my_devices_list = NULL; - } - - return RET_SUCCESS; -} - -int run_device_show_mowned_device(MManager *mm, struct menu_data *menu) -{ - int ret; - int count; - mdg_device_h *devices = NULL; - - ret = mdg_device_get_found_mowned_devices(handle, &devices, &count); - if (MDG_ERROR_NONE != ret) { - msgr("Failed to Get Found Mowned Devices: [%s(0x%X)]", - mdg_error_to_string(ret), ret); - return RET_FAILURE; - } - msg(" - mdg_device_get_found_mowned_devices() ret: [0x%X] [%s]", ret, - mdg_error_to_string(ret)); - for (int i = 0; i < count; i++) { - char *device_id = NULL; - char *ip = NULL; - mdg_device_type_e device_type; - - mdg_device_info_get_device_id(devices[i], &device_id); - mdg_device_info_get_ip(devices[i], &ip); - mdg_device_info_get_device_type(devices[i], &device_type); - - msgb("\n[ID] %s [IP] %s [Type] %s", device_id, ip, - __device_type_to_string(device_type)); + msg(" - mdg_device_find_invited_device() ret: [0x%X] [%s]", + ret, mdg_error_to_string(ret)); - if (device_id) - free(device_id); - if (ip) - free(ip); + if (invited_device_list) { + g_list_free_full(invited_device_list, _destroy_mdg_device_info); + invited_device_list = NULL; } return RET_SUCCESS; @@ -982,7 +809,6 @@ int run_device_show_mowned_device(MManager *mm, struct menu_data *menu) static int run_request_create_group(MManager *mm, struct menu_data *menu) { int ret = 0; - int dev_idx = 1; int dev_count = 0; mdg_device_h device = NULL; @@ -995,6 +821,7 @@ static int run_request_create_group(MManager *mm, struct menu_data *menu) return RET_SUCCESS; } + int dev_idx; if (device_idx != NULL && strlen(device_idx)) { dev_idx = (unsigned short)strtol(device_idx, NULL, 10); if (0 >= dev_idx) { @@ -1028,8 +855,6 @@ static int run_request_create_group(MManager *mm, struct menu_data *menu) static int run_request_invite(MManager *mm, struct menu_data *menu) { int ret = 0; - int grp_idx = 1; - int dev_idx = 1; int grp_count = 0; int dev_count = 0; mdg_device_h device = NULL; @@ -1043,6 +868,7 @@ static int run_request_invite(MManager *mm, struct menu_data *menu) return RET_SUCCESS; } + int grp_idx; if (group_idx != NULL && strlen(group_idx)) { grp_idx = (unsigned short)strtol(group_idx, NULL, 10); if (0 >= grp_idx) { @@ -1059,6 +885,7 @@ static int run_request_invite(MManager *mm, struct menu_data *menu) } } + int dev_idx; if (device_idx != NULL && strlen(device_idx)) { dev_idx = (unsigned short)strtol(device_idx, NULL, 10); if (0 >= dev_idx) { @@ -1150,82 +977,35 @@ static int run_request_eject(MManager *mm, struct menu_data *menu) return RET_SUCCESS; } -static int run_request_delete_group(MManager *mm, struct menu_data *menu) +void __channel_cb(int result, mdg_device_h device, char *channel_id, + unsigned char *arg, int len, void *user_data) { - int ret = 0; - int grp_count = 0; - mdg_group_h group = NULL; - - grp_count = g_list_length(found_group_list); - - if (0 >= grp_count) { - msgr("No Device"); - return RET_SUCCESS; - } - - int grp_idx; - if (group_idx != NULL && strlen(group_idx)) { - grp_idx = (unsigned short)strtol(group_idx, NULL, 10); - if (0 >= grp_idx) { - msgp("Invalid index. set to 1"); - grp_idx = 1; - } - } + msg("[%s] channel callback is called by remote send message", channel_id); + msg("result is %d", result); +} - if (found_group_list) { - group = g_list_nth_data(found_group_list, grp_idx - 1); - if (NULL == group) { - msgr("Failed to g_hash_table_find"); - return RET_FAILURE; - } - } +static int run_regist_channel(MManager *mm, struct menu_data *menu) +{ + int ret = 0; - ret = mdg_request_delete_group(handle, group, receive_request_result, NULL); - if (MDG_ERROR_NONE != ret) { - msgr("Failed to Request Delete Group: [%s(0x%X)]", - mdg_error_to_string(ret), ret); - return RET_FAILURE; - } + ret = mdg_device_regist_channel(handle, channel_id, __channel_cb, NULL); - msg(" - mdg_request_delete_group() ret: [0x%X] [%s]", - ret, mdg_error_to_string(ret)); + msg(" - mdg_device_regist_channel() ret: [0x%X] [%s]", ret, mdg_error_to_string(ret)); return RET_SUCCESS; } -static void device_monitor_result(char *uuid, char *group_name, - mdg_device_status_e status, void *user_data) +static int run_unregist_channel(MManager *mm, struct menu_data *menu) { - msgp("device monitor result uuid %s group_name %s status %s", uuid, - group_name, status == MDG_DEVICE_ADDED ? "ADDED" : "REMOVED"); -} + int ret = 0; -static int run_start_device_monitor(MManager *mm, struct menu_data *menu) -{ - int ret; + ret = mdg_device_unregist_channel(handle, channel_id); + + msg(" - mdg_unregist_channel() ret: [0x%X] [%s]", ret, mdg_error_to_string(ret)); - if (g_strcmp0(monitor, "1") == 0) { - msg(" - Start device monitor"); - ret = mdg_device_monitor_start(handle, device_monitor_result, - NULL); - if (MDG_ERROR_NONE != ret) { - msgr("Failed to Start Monitor: [%s(0x%X)]", - mdg_error_to_string(ret), ret); - return RET_FAILURE; - } - } else { - msg(" - Stop device monitor"); - ret = mdg_device_monitor_stop(handle); - if (MDG_ERROR_NONE != ret) { - msgr("Failed to Stop Monitor: [%s(0x%X)]", - mdg_error_to_string(ret), ret); - return RET_FAILURE; - } - } return RET_SUCCESS; } - static struct menu_data menu_group_create[] = { { "0", "Group Name", NULL, NULL, groupid }, { "1", "Run", NULL, run_group_create, NULL }, @@ -1238,35 +1018,13 @@ static struct menu_data menu_group_find[] = { { NULL, NULL, }, }; -static struct menu_data menu_group_join[] = { - { "0", "Show Found Group(s)", NULL, run_group_show, NULL }, - { "1", "Index", NULL, NULL, group_idx }, - { "2", "Run", NULL, run_group_join, NULL }, - { NULL, NULL, }, -}; - -static struct menu_data menu_group_leave[] = { - { "0", "Show Found Group(s)", NULL, run_group_show, NULL }, - { "1", "Index", NULL, NULL, group_idx }, - { "2", "Run", NULL, run_group_leave, NULL }, - { NULL, NULL, }, -}; - static struct menu_data menu_group_delete[] = { { "0", "Show Found Group(s)", NULL, run_group_show, NULL }, { "1", "Index", NULL, NULL, group_idx }, { "2", "Run", NULL, run_group_delete, NULL }, { NULL, NULL, }, }; -#if 0 -static struct menu_data menu_group_merge[] = { - { "0", "Show Found Group(s)", NULL, run_group_show, NULL }, - { "1", "A Index", NULL, NULL, group_idx_a }, - { "2", "B Index", NULL, NULL, group_idx_b }, - { "3", "Run", NULL, run_group_merge, NULL }, - { NULL, NULL, }, -}; -#endif + static struct menu_data menu_devices_find[] = { { "0", "Timeout", NULL, NULL, timeout }, { "1", "Run", NULL, run_devices_find, NULL }, @@ -1293,17 +1051,17 @@ static struct menu_data menu_group_eject_device[] = { }; static struct menu_data menu_send_data[] = { - { "0", "Show My Owned Device(s)", NULL, run_device_show_mowned_device, NULL }, + { "0", "Show My Owned Device(s)", NULL, run_invited_devices_show, NULL }, { "1", "Message", NULL, NULL, message }, - { "2", "Device Index", NULL, NULL, device_idx }, - { "3", "Send (Unicast)", NULL, run_send_data, NULL }, - { "4", "Send (Broadcast)", NULL, run_send_data_all, NULL }, + { "2", "Channel Name", NULL, NULL, channel_id }, + { "3", "Device Index", NULL, NULL, device_idx }, + { "4", "Send", NULL, run_send_data, NULL }, { NULL, NULL, }, }; -static struct menu_data menu_devices_find_mownd_device[] = { +static struct menu_data menu_devices_find_invited_device[] = { { "0", "Timeout", NULL, NULL, timeout }, - { "1", "Run", NULL, run_devices_find_mowned_device, NULL }, + { "1", "Run", NULL, run_devices_find_invited_device, NULL }, { NULL, NULL, }, }; @@ -1334,40 +1092,35 @@ static struct menu_data menu_request_eject[] = { { NULL, NULL, }, }; -static struct menu_data menu_request_delete_group[] = { - { "0", "Show Found Group(s)", NULL, run_group_show, NULL }, - { "1", "Group Index", NULL, NULL, group_idx }, - { "2", "Run", NULL, run_request_delete_group, NULL }, +static struct menu_data menu_regist_channel[] = { + { "0", "Channel ID", NULL, NULL, channel_id }, + { "1", "Run", NULL, run_regist_channel, NULL }, { NULL, NULL, }, }; -static struct menu_data menu_monitor[] = { - { "1", "Input 1 to Start and 2 to Stop Monitor", NULL, NULL, monitor }, - { "2", "Start/Stop Device Monitor", NULL, run_start_device_monitor, NULL }, +static struct menu_data menu_unregist_channel[] = { + { "0", "Channel ID", NULL, NULL, channel_id }, + { "1", "Run", NULL, run_unregist_channel, NULL }, { NULL, NULL, }, }; struct menu_data menu_mdg_manager[] = { - { "0", "Show My Device ID", NULL, run_get_my_id, NULL }, - { "1", "Show My Device", NULL, run_device_show_my_device, NULL }, - { "2", "Create Group", menu_group_create, NULL, NULL }, - { "3", "Find Group(s)", menu_group_find, NULL, NULL }, - { "4", "Show Found Group(s)", NULL, run_group_show_found , NULL }, - { "5", "Join Group (Not yet developed)", menu_group_join, NULL, NULL }, - { "6", "Leave Group (Not yet developed)", menu_group_leave, NULL, NULL }, - { "7", "Delete Group", menu_group_delete, NULL, NULL }, - { "8", "Find Device(s)", menu_devices_find, NULL, NULL }, - { "9", "Show Found Device(s)", NULL, run_device_show_found, NULL }, - { "10", "Invite Device", menu_group_invite_device, NULL, NULL }, - { "11", "Eject Device", menu_group_eject_device, NULL, NULL }, - { "12", "Find My Owned Device(s)", menu_devices_find_mownd_device, NULL, NULL }, - { "13", "Show My Owned Device(s)", NULL, run_device_show_mowned_device, NULL}, - { "14", "Send Message", menu_send_data, NULL, NULL }, - { "15", "Request Create Group", menu_request_create_group, NULL, NULL }, - { "16", "Request Invite", menu_request_invite, NULL, NULL }, - { "17", "Request Eject", menu_request_eject, NULL, NULL }, - { "18", "Request Delete Group (Not yet developed)", menu_request_delete_group, - NULL, NULL }, - { "19", "Start/Stop Device Monitor", menu_monitor, NULL, NULL }, - { NULL, NULL, }, + { "1", "Show Local Device", NULL, run_device_show_local_device, NULL }, // O + { "2", "Create Group", menu_group_create, NULL, NULL }, // 0 + { "3", "Find Group(s)", menu_group_find, NULL, NULL }, // 0 + { "4", "Show Group(s)", NULL, run_group_show, NULL }, // 0 + { "5", "Delete Group", menu_group_delete, NULL, NULL }, // 0 + { "6", "Find Device(s)", menu_devices_find, NULL, NULL }, // 0 + { "7", "Show Device(s)", NULL, run_devices_show, NULL }, // 0 + { "8", "Invite Device", menu_group_invite_device, NULL, NULL }, // 0 + { "9", "Eject Device", menu_group_eject_device, NULL, NULL }, // 0 + { "10", "Find Invited Device(s)", menu_devices_find_invited_device, NULL, NULL }, // 0 + { "11", "Show Invited Device(s)", NULL, run_invited_devices_show, NULL }, // 0 + { "12", "Request Create Group", menu_request_create_group, NULL, NULL }, + { "13", "Request Invite", menu_request_invite, NULL, NULL }, + { "14", "Request Eject", menu_request_eject, NULL, NULL }, + { "15", "Regist Channel", menu_regist_channel, NULL, NULL }, + { "16", "Unregist Channel", menu_unregist_channel, NULL, NULL }, + { "17", "Get Channel(s)", NULL, run_invited_devices_show, NULL }, + { "18", "Send Message", menu_send_data, NULL, NULL }, // 0 }; diff --git a/test/mdg-test.c b/test/mdg-test.c deleted file mode 100644 index 639317c..0000000 --- a/test/mdg-test.c +++ /dev/null @@ -1,489 +0,0 @@ -/* - * Copyright (c) 2018 Samsung Electronics Co., Ltd. All rights reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - */ - -#include -#include -#include -#include -#include -#include - -#include - -#define BUFFER_LEN 100 -#define TEST_CASE_MAX 10 - -#define PRT(format, args...) printf("%s:%d() "format, __FUNCTION__, __LINE__, ##args) -#define TC_PRT(format, args...) PRT(format"\n", ##args) - -#define BEGIN() TC_PRT("BEGIN"); -#define END() TC_PRT("END"); - -GMainLoop *main_loop = NULL; - -typedef struct { - const char *tc_name; - int tc_code; - int (*tc_func)(void); -} tc_table_t; - -GList *found_group_list; -GList *found_device_list; - -mdg_h handle = NULL; - -#define CASE_TO_STR(x) case x: return #x; -static const char* __device_type_to_string(mdg_device_type_e type) -{ - switch (type) { - /* CHECK: List all enum values here */ - CASE_TO_STR(MDG_DEVICE_TYPE_LOCAL) - CASE_TO_STR(MDG_DEVICE_TYPE_REMOTE) - default : - return "MDG_DEVICE_TYPE_ERROR"; - } -} - -static bool test_get_user_int(const char *msg, int *num) -{ - if (msg == NULL || num == NULL) - return false; - - int rv; - char buf[32] = { 0, }; - printf("%s\n", msg); - rv = read(0, buf, 32); - - if (rv < 0 || *buf == 0 || *buf == '\n' || *buf == '\r') - return false; - - *num = atoi(buf); - return true; -} - -static bool test_get_user_string(const char *msg, char *buf, int buf_size) -{ - if (msg == NULL || buf == NULL || buf_size < 2) - return false; - - int rv; - printf("%s\n", msg); - memset(buf, 0, buf_size); - rv = read(0, buf, buf_size - 1); - - if (rv < 0 || buf[0] == '\0' || buf[0] == '\n' || buf[0] == '\r') { - buf[0] = '\0'; - return false; - } - - if (rv >= 0) - buf[rv] = '\0'; - - return true; -} - -int mdg_initialize_test(void) -{ - int ret = 0; - - BEGIN(); - - ret = mdg_initialize(&handle); - - if (ret == 0) - TC_PRT("Initialize successful"); - else - TC_PRT("Initialize failed, ret [%d]", ret); - - END(); - return ret; -} - -int mdg_group_create_test(void) -{ - int ret = 0; - char input_str[50] = {0, }; - mdg_h handle = NULL; - - BEGIN(); - - if (test_get_user_string("Input group name(ex - GROUP123)" - " - (Enter for skip) :", input_str, 50)) { - g_strstrip(input_str); - } else { - TC_PRT("Invalid Input !!![%s]", input_str); - END(); - return -1; - } - - ret = mdg_group_create(handle, input_str); - - if (ret == 0) - TC_PRT("Group create successful"); - else - TC_PRT("Group create failed, ret [%d]", ret); - - END(); - return ret; -} - -bool _group_found_cb(mdg_group_type_e type, mdg_group_h group, void *user_data) -{ - char *uri_path; - - mdg_group_info_get_uri_path(group, &uri_path); - - TC_PRT("found group type : %d, uri : %s", type, uri_path); - - found_group_list = g_list_append(found_group_list, group); -} - -void _group_finish_cb(int result, void *user_data) -{ - TC_PRT("find operation finished"); -} - -int mdg_group_find_test(void) -{ - int ret = 0; - int input_int = 0; - - BEGIN(); - found_group_list = NULL; - - if (!test_get_user_int("==> Input timeout value (sec)" - " - (Enter for skip) :", &input_int)) { - input_int = 5; - TC_PRT("default timeout value [%d]", input_int); - } - - mdg_group_find(handle, input_int, _group_found_cb, _group_finish_cb, NULL); - - if (ret == 0) - TC_PRT("group find successful"); - else - TC_PRT("group find failed, ret [%d]", ret); - - END(); - return ret; -} - -int mdg_group_get_found_groups_test(void) -{ - int ret = 0; - int count; - mdg_group_h *groups; - - BEGIN(); - - found_group_list = NULL; - - ret = mdg_group_get_found_groups(handle, &groups, &count); - - if (ret == 0) - TC_PRT("group find successful"); - else - TC_PRT("group find failed, ret [%d]", ret); - - TC_PRT("Found group count : %d", count); - - for (int i = 0; i < count; i++) { - mdg_group_type_e type; - char *uri_path; - mdg_group_info_get_type(groups[i], &type); - mdg_group_info_get_uri_path(groups[i], &uri_path); - TC_PRT("%d. type : %d, uri path : %s", i+1, type, uri_path); - found_group_list = g_list_append(found_group_list, groups[i]); - } - - END(); - return ret; -} - -bool _device_found_cb(mdg_device_h device, void *user_data) -{ - char *device_id; - char *ip; - mdg_device_type_e device_type; - - mdg_device_info_get_device_id(device, &device_id); - mdg_device_info_get_ip(device, &ip); - mdg_device_info_get_device_type(device, &device_type); - - TC_PRT("found device device_id : %s, ip : %s, device_type : %s", device_id, ip, - __device_type_to_string(device_type)); - - found_device_list = g_list_append(found_device_list, device); -} - -int mdg_device_find_test(void) -{ - int ret = 0; - int input_int = 0; - - BEGIN(); - found_device_list = NULL; - - if (!test_get_user_int("==> Input timeout value (sec)" - " - (Enter for skip) :", &input_int)) { - input_int = 5; - TC_PRT("default timeout value [%d]", input_int); - } - - mdg_device_find(handle, input_int, _device_found_cb, _group_finish_cb, NULL); - - if (ret == 0) - TC_PRT("device find successful"); - else - TC_PRT("device find failed, ret [%d]", ret); - - END(); - return ret; -} - -int mdg_device_get_found_devices_test(void) -{ - int ret = 0; - int count = 0; - mdg_device_h *devices; - - BEGIN(); - - found_device_list = NULL; - - ret = mdg_device_get_found_devices(hadnle, &devices, &count); - - if (ret == 0) - TC_PRT("device find successful"); - else - TC_PRT("device find failed, ret [%d]", ret); - - TC_PRT("Found device count : ", count); - - for (int i = 0; i < count; i++) { - char *uuid; - char *ip; - mdg_device_type_e device_type; - - mdg_device_info_get_device_id(devices[i], &uuid); - mdg_device_info_get_ip(devices[i], &ip); - mdg_device_info_get_device_type(devices[i], &device_type); - - TC_PRT("%d. uuid : %s, ip : %s, device_type : %s", i+1, uuid, ip, - __device_type_to_string(device_type)); - found_device_list = g_list_append(found_device_list, devices[i]); - } - - END(); - return ret; -} - -void _device_invite_result_cb(int result, void *user_data) -{ - TC_PRT("Invite complete !!!! ret : %d", result); -} - -int mdg_device_invite_test(void) -{ - int ret = 0; - BEGIN(); - - /* using stored group list and device list */ - if (g_list_length(found_device_list) > 0 && g_list_length(found_group_list) > 0) { - TC_PRT("Invite Test Start"); - mdg_group_h group = (mdg_group_h)(found_group_list[0].data); - mdg_device_h device = (mdg_device_h)(found_device_list[0].data); - - mdg_group_invite_device(handle, group, device, "12341234", _device_invite_result_cb, NULL); - - } else { - TC_PRT("not exist found group or device list"); - } - - END(); - return ret; -} - -void _device_eject_result_cb(int result, void *user_data) -{ - TC_PRT("eject complete !!!! ret : %d", result); -} - -int mdg_device_eject_test(void) -{ - int ret = 0; - BEGIN(); - - /* using stored group list and device list */ - if (g_list_length(found_device_list) > 0 && g_list_length(found_group_list) > 0) { - TC_PRT("Invite Test Start"); - mdg_group_h group = (mdg_group_h)(found_group_list[0].data); - mdg_device_h device = (mdg_device_h)(found_device_list[0].data); - - /* using stored group list and device list */ - mdg_group_eject_device(handle, group, device, _device_eject_result_cb, NULL); - } else { - TC_PRT("not exist found group or device list"); - } - - - END(); - return ret; -} - -//send_data_callback : if the remote device not invited, then callback is called include result failed. -//send_data_callback : if the remote device invited, then callback result successful. - -int mdg_send_data_to_remote_device_test(void) -{ - int ret = 0; - BEGIN(); - - if (g_list_length(found_device_list) > 0) { - mdg_device_h device = (mdg_device_h)(found_device_list[0].data); - ret = mdg_device_send_data(handle, device, "123", NULL, NULL); - } else { - TC_PRT("not exist found device list"); - } - - END(); - return ret; -} - -int mdg_deinitialize_test(void) -{ - int ret = 0; - - BEGIN(); - - ret = mdg_deinitialize(handle); - - if (ret == 0) - TC_PRT("Initialize successful"); - else - TC_PRT("Initialize failed, ret [%d]", ret); - - END(); - return ret; -} - -tc_table_t tc_table[] = { - /* manager api */ - {"mdg_initialize_test", 1, mdg_initialize_test}, - {"mdg_group_create_test", 2, mdg_group_create_test}, - {"mdg_group_find_test", 3, mdg_group_find_test}, - {"mdg_group_get_found_groups_test", 4, mdg_group_get_found_groups_test}, - {"mdg_device_find_test", 5, mdg_device_find_test}, - {"mdg_device_get_found_devices_test", 6, mdg_device_get_found_devices_test}, - {"mdg_device_invite_test", 7, mdg_device_invite_test}, - {"mdg_device_eject_test", 8, mdg_device_eject_test}, - {"mdg_send_data_to_remote_device_test", 9, mdg_send_data_to_remote_device_test}, - {"mdg_deinitialize_test", TEST_CASE_MAX, mdg_deinitialize_test}, - - /*-----------*/ - {"Finish", 0x0000, NULL}, - {NULL, 0x00ff, NULL}, -}; - -static void tc_usage_print(void) -{ - int i = 0; - - while (tc_table[i].tc_name) { - if (tc_table[i].tc_code != 0x00ff) - printf("Key [%2d] : usage %s\n", tc_table[i].tc_code, tc_table[i].tc_name); - else - printf("Key [%2d] : usage %s\n\n", 0x00ff, tc_table[i].tc_name); - - i++; - } -} - -static int test_input_callback(void *data) -{ - long test_id = (long)data; - int ret = 0; - - if ((test_id >= 1) && (test_id <= TEST_CASE_MAX)) { - TC_PRT("test_input_callback test_id : %ld", test_id); - - if (tc_table[test_id-1].tc_func != NULL) { - ret = tc_table[test_id-1].tc_func(); - - if (ret != 0) - TC_PRT(">>>>> Test Error Returned !!! : %d", ret); - } - } - - return 0; -} - -static int test_terminate(void) -{ - int ret = 0; - - TC_PRT("Finished"); - - mdg_deinitialize_test(); - g_main_loop_quit(main_loop); - - return ret; -} - -static gboolean key_event_cb(GIOChannel *chan, GIOCondition cond, gpointer data) -{ - char buf[BUFFER_LEN] = {0,}; - long test_id; - int rv = 0; - - memset(buf, 0, sizeof(buf)); - - rv = read(0, buf, 100); - - if (rv < 0 || buf[0] == '0') { - test_terminate(); - exit(1); - } - - if (*buf == '\n' || *buf == '\r') - tc_usage_print(); - - test_id = atoi(buf); - - test_input_callback((void *)test_id); - - return TRUE; -} - - -int main(int argc, char ** argv) -{ - GIOChannel *key_io; - - main_loop = g_main_loop_new(NULL, FALSE); - key_io = g_io_channel_unix_new(0); - - printf("Test Thread created...\n"); - - g_io_add_watch(key_io, (G_IO_IN | G_IO_HUP | G_IO_ERR | G_IO_NVAL), key_event_cb, NULL); - g_main_loop_run(main_loop); - - g_io_channel_unref(key_io); - g_main_loop_unref(main_loop); - - return 0; -} diff --git a/test/menu.c b/test/menu.c old mode 100644 new mode 100755 diff --git a/test/menu.h b/test/menu.h old mode 100644 new mode 100755 -- 2.7.4 From 381fd600fbf8ae12623e59de5fe23c486b29037c Mon Sep 17 00:00:00 2001 From: Jihoon Jung Date: Thu, 28 Jun 2018 18:11:01 +0900 Subject: [PATCH 05/16] Add sender implementation Signed-off-by: Jihoon Jung --- include/mdg.h | 61 +++--------------------------------------------------- src/mdg.c | 43 ++++++++++++++++++++++++++++++++------ src/mdg_gdbus.xml | 11 ++++++++-- test/mdg-manager.c | 60 +++++++++++++++++++++++++++++++++++++++++++++++------ 4 files changed, 103 insertions(+), 72 deletions(-) mode change 100644 => 100755 include/mdg.h mode change 100644 => 100755 src/mdg_gdbus.xml diff --git a/include/mdg.h b/include/mdg.h old mode 100644 new mode 100755 index 4ae2b05..15fd796 --- a/include/mdg.h +++ b/include/mdg.h @@ -441,64 +441,6 @@ typedef void (*mdg_request_result_cb)(char *cmd, char *device_id, unsigned char *arg, int len, int ret, void *user_data); /** - * @brief Requests my device to be joined to remote group. - * @details This function requests a remote groups to join my device in the remote groups. - * - * @since_tizen 5.0 - * @privlevel public - * @privilege %http://tizen.org/privilege/internet - * - * @param[in] handle The multi device group manager handle - * @param[in] group Group resource list - * @param[in] cb Callback handler to receive the result - * @param[in] user_data User data pointer - * - * - * @return 0 on success, otherwise a negative error value. - * @retval #MDG_ERROR_NONE Successful - * @retval #MDG_ERROR_INVALID_PARAMETER Invalid parameter - * - * @see mdg_group_create() - * @see mdg_request_leave_group () - * @see mdg_request_create_group() - * @see mdg_request_invite_device() - * @see mdg_request_eject_device() - * @see mdg_request_delete_group() - * - */ -int mdg_request_join_group(mdg_h handle, mdg_group_h group, - mdg_request_result_cb cb, void *user_data); - -/** - * @brief Requests my device to be exit from remote group. - * @details This function requests remote groups to exit my devices that belonged to the - * remote group. - * - * @since_tizen 5.0 - * @privlevel public - * @privilege %http://tizen.org/privilege/internet - * - * @param[in] handle The multi device group manager handle - * @param[in] group Group handle - * @param[in] cb Callback handler to receive the result - * @param[in] user_data User data pointer - * - * - * @return 0 on success, otherwise a negative error value. - * @retval #MDG_ERROR_NONE Successful - * @retval #MDG_ERROR_INVALID_PARAMETER Invalid parameter - * - * @see mdg_group_create() - * @see mdg_request_join_group() - * @see mdg_group_delete() - * @see mdg_group_merge() - * @see mdg_group_get_member_devices() - * - */ -int mdg_request_leave_group(mdg_h handle, mdg_group_h group, - mdg_request_result_cb cb, void *user_data); - -/** * @brief Requests to create a group. * @details We can create a group. This generated group can include device, and remote * devices can inquire remotely group information and device information included in group. @@ -591,6 +533,9 @@ int mdg_request_invite_device(mdg_h handle, mdg_group_h group, 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); + /** * @} */ diff --git a/src/mdg.c b/src/mdg.c index 1c4abe4..18e06c0 100755 --- a/src/mdg.c +++ b/src/mdg.c @@ -818,8 +818,8 @@ EXPORT_API int mdg_request_create_group(mdg_h handle, _DBG("Device id : %s", dev->device_id); - group_call_request_create_group_sync(_handle->group_proxy, dev->device_id, - group_name, &ret, NULL, &error); + group_call_request_create_group_sync(_handle->group_proxy, dev->device_id, dev->addr, + dev->secure_port, group_name, &ret, NULL, &error); return ret; } @@ -850,8 +850,8 @@ EXPORT_API int mdg_request_invite_device(mdg_h handle, _DBG("%s", grp->group_name); _DBG("%s", dev->device_id); - group_call_request_invite(_handle->group_proxy, grp->device_id, grp->group_name, - dev->device_id, PIN, NULL, NULL, &error); + group_call_request_invite(_handle->group_proxy, grp->device_id, dev->addr, + dev->secure_port, grp->group_name, dev->device_id, PIN, NULL, NULL, &error); if (error) { _ERR("Failed DBus call [%s]", error->message); g_error_free(error); @@ -887,8 +887,39 @@ EXPORT_API int mdg_request_eject_device(mdg_h handle, _DBG("%s", grp->group_name); _DBG("%s", dev->device_id); - group_call_request_eject(_handle->group_proxy, grp->device_id, grp->group_name, - dev->device_id, NULL, NULL, &error); + group_call_request_eject(_handle->group_proxy, grp->device_id, dev->addr, + dev->secure_port, grp->group_name, dev->device_id, NULL, NULL, &error); + if (error) { + _ERR("Failed DBus call [%s]", error->message); + g_error_free(error); + ret = MDG_ERROR_IO_ERROR; + } + + return ret; +} + +EXPORT_API int mdg_request_channel_list(mdg_h handle, mdg_device_h device, mdg_request_result_cb 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; + mdg_check_null_ret_error("handle", handle, MDG_ERROR_INVALID_PARAMETER); + CHECK_HANDLE_IS_VALID(handle); + + mdg_device_s *dev = (mdg_device_s *)device; + mdg_check_null_ret_error("device", device, MDG_ERROR_INVALID_PARAMETER); + + _DBG("%s", dev->device_id); + + group_call_request_channel_list(_handle->group_proxy, dev->device_id, dev->addr, + dev->secure_port, NULL, NULL, &error); if (error) { _ERR("Failed DBus call [%s]", error->message); g_error_free(error); diff --git a/src/mdg_gdbus.xml b/src/mdg_gdbus.xml old mode 100644 new mode 100755 index e30676d..7b418db --- a/src/mdg_gdbus.xml +++ b/src/mdg_gdbus.xml @@ -65,11 +65,15 @@ + + + + @@ -77,13 +81,16 @@ + + - + - + + diff --git a/test/mdg-manager.c b/test/mdg-manager.c index 9a5c8ce..930d048 100755 --- a/test/mdg-manager.c +++ b/test/mdg-manager.c @@ -977,6 +977,47 @@ static int run_request_eject(MManager *mm, struct menu_data *menu) return RET_SUCCESS; } +static int run_request_channel_list(MManager *mm, struct menu_data *menu) +{ + int ret = 0; + int dev_count = 0; + mdg_device_h device = NULL; + + dev_count = g_list_length(found_device_list); + + if (0 >= dev_count) { + msgr("No Device"); + return RET_SUCCESS; + } + + int dev_idx; + if (device_idx != NULL && strlen(device_idx)) { + dev_idx = (unsigned short)strtol(device_idx, NULL, 10); + if (0 >= dev_idx) { + msgp("Invalid index. set to 1"); + dev_idx = 1; + } + } + + if (found_device_list) { + device = g_list_nth_data(found_device_list, dev_idx - 1); + if (NULL == device) { + msgr("Failed to g_hash_table_find"); + return RET_FAILURE; + } + } + + ret = mdg_request_channel_list(handle, device, receive_request_result, NULL); + if (MDG_ERROR_NONE != ret) { + msgr("Failed to Request Eject: [%s(0x%X)]", mdg_error_to_string(ret), ret); + return RET_FAILURE; + } + + msg(" - mdg_request_eject_device() ret: [0x%X] [%s]", ret, mdg_error_to_string(ret)); + + return RET_SUCCESS; +} + void __channel_cb(int result, mdg_device_h device, char *channel_id, unsigned char *arg, int len, void *user_data) { @@ -1092,6 +1133,13 @@ static struct menu_data menu_request_eject[] = { { NULL, NULL, }, }; +static struct menu_data menu_request_channel_list[] = { + { "0", "Show Found Device(s)", NULL, run_devices_show, NULL }, + { "1", "Device Index", NULL, NULL, device_idx }, + { "2", "Run", NULL, run_request_channel_list, NULL }, + { NULL, NULL, }, +}; + static struct menu_data menu_regist_channel[] = { { "0", "Channel ID", NULL, NULL, channel_id }, { "1", "Run", NULL, run_regist_channel, NULL }, @@ -1116,11 +1164,11 @@ struct menu_data menu_mdg_manager[] = { { "9", "Eject Device", menu_group_eject_device, NULL, NULL }, // 0 { "10", "Find Invited Device(s)", menu_devices_find_invited_device, NULL, NULL }, // 0 { "11", "Show Invited Device(s)", NULL, run_invited_devices_show, NULL }, // 0 - { "12", "Request Create Group", menu_request_create_group, NULL, NULL }, - { "13", "Request Invite", menu_request_invite, NULL, NULL }, - { "14", "Request Eject", menu_request_eject, NULL, NULL }, - { "15", "Regist Channel", menu_regist_channel, NULL, NULL }, - { "16", "Unregist Channel", menu_unregist_channel, NULL, NULL }, - { "17", "Get Channel(s)", NULL, run_invited_devices_show, NULL }, + { "12", "Request Create Group", menu_request_create_group, NULL, NULL }, // 0 + { "13", "Request Invite", menu_request_invite, NULL, NULL }, // 0 + { "14", "Request Eject", menu_request_eject, NULL, NULL }, // 0 + { "15", "Request Channel List", menu_request_channel_list, NULL, NULL }, // 0 + { "16", "Regist Channel", menu_regist_channel, NULL, NULL }, + { "17", "Unregist Channel", menu_unregist_channel, NULL, NULL }, { "18", "Send Message", menu_send_data, NULL, NULL }, // 0 }; -- 2.7.4 From 9b663b39fe5be705e28eb3aabad9387d611cf0c9 Mon Sep 17 00:00:00 2001 From: Jihoon Jung Date: Thu, 28 Jun 2018 19:34:12 +0900 Subject: [PATCH 06/16] Add req channel list Signed-off-by: Jihoon Jung --- include/mdg.h | 6 ++-- src/mdg.c | 9 +++--- src/mdg_dbus.c | 11 +++++++ src/mdg_private.h | 7 +++++ src/mdg_util.c | 17 ++++++++++ src/mdg_util.h | 1 + test/mdg-manager.c | 92 +++++++++++++++++++++++++++++++++++++++++++++--------- 7 files changed, 122 insertions(+), 21 deletions(-) mode change 100644 => 100755 src/mdg_private.h 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, }, }; -- 2.7.4 From d90af7063abee4c3981e8c222ab25b57774cabac Mon Sep 17 00:00:00 2001 From: Jihoon Jung Date: Fri, 29 Jun 2018 17:00:55 +0900 Subject: [PATCH 07/16] Add mdg send data using channel id Signed-off-by: Jihoon Jung --- include/mdg.h | 4 ++-- src/mdg.c | 8 +------- src/mdg_dbus.c | 21 ++++++++++++++++++++ src/mdg_gdbus.xml | 1 + src/mdg_private.h | 9 ++++++++- src/mdg_util.c | 32 ++++++++++++++++++++++++++++++ src/mdg_util.h | 2 ++ test/mdg-manager.c | 57 +++++++++++++++++++++++++++--------------------------- 8 files changed, 96 insertions(+), 38 deletions(-) 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, }, -- 2.7.4 From 82cefe8b93062e77755f7ecc031a066dcba16385 Mon Sep 17 00:00:00 2001 From: Jihoon Jung Date: Tue, 3 Jul 2018 15:30:07 +0900 Subject: [PATCH 08/16] Apply coding rule Change-Id: I128899b0591188f63a8169d3a019a53a3173f431 Signed-off-by: Jihoon Jung --- src/mdg_dbus.c | 3 +-- src/mdg_private.h | 2 +- src/mdg_util.c | 3 +-- test/mdg-manager.c | 2 +- test/menu.h | 9 ++++++--- 5 files changed, 10 insertions(+), 9 deletions(-) diff --git a/src/mdg_dbus.c b/src/mdg_dbus.c index 20201fe..6038c3d 100755 --- a/src/mdg_dbus.c +++ b/src/mdg_dbus.c @@ -124,9 +124,8 @@ static void __event_cb(Group *object, channel = tmp_channel; } - if (channel != NULL) { + 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_private.h b/src/mdg_private.h index 78a667d..35f6beb 100755 --- a/src/mdg_private.h +++ b/src/mdg_private.h @@ -153,7 +153,7 @@ typedef struct _mdg_manager_s { } mdg_manager_s; #define CHECK_HANDLE_IS_VALID(handle) { \ - if (g_slist_find (handle_list, handle) == NULL) \ + if (g_slist_find(handle_list, handle) == NULL) \ return MDG_ERROR_UNKNOWN; \ } diff --git a/src/mdg_util.c b/src/mdg_util.c index abea395..9282b3a 100755 --- a/src/mdg_util.c +++ b/src/mdg_util.c @@ -174,9 +174,8 @@ void mdg_get_data_from_variant(GVariant *va, char **device_id, char **channel_id *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)) { + while (g_variant_iter_loop(data_iter, "(y)", &byte_data)) (*data)[i++] = byte_data; - } g_variant_iter_free(iter); } diff --git a/test/mdg-manager.c b/test/mdg-manager.c index 96141e2..0d21f01 100755 --- a/test/mdg-manager.c +++ b/test/mdg-manager.c @@ -55,7 +55,7 @@ static const char* __device_type_to_string(mdg_device_type_e type) return "Local"; case MDG_DEVICE_TYPE_REMOTE: return "Remote"; - default : + default: return "Unknown"; } } diff --git a/test/menu.h b/test/menu.h index 728d36c..fcfcfc8 100755 --- a/test/menu.h +++ b/test/menu.h @@ -62,16 +62,19 @@ __BEGIN_DECLS 3 + ((n) * 2), ##args); fflush(stdout); } while (0) #define pmsg(fmt, args...) do { \ - if (is_pid_show()) { fprintf(stdout, "(%5d) ", get_tid()); } \ + if (is_pid_show()) \ + fprintf(stdout, "(%5d) ", get_tid()); \ fprintf(stdout, fmt "\n", ##args); fflush(stdout); } while (0) #define pmsgb(fmt, args...) do { \ - if (is_pid_show()) { fprintf(stdout, "(%5d) ", get_tid()); } \ + if (is_pid_show()) \ + fprintf(stdout, "(%5d) ", get_tid()); \ fprintf(stdout, ANSI_COLOR_LIGHTGREEN fmt \ ANSI_COLOR_NORMAL "\n", ##args); fflush(stdout); } while (0) #define pmsgt(n, fmt, args...) do { \ - if (is_pid_show()) { fprintf(stdout, "(%5d) ", get_tid()); } \ + if (is_pid_show()) \ + fprintf(stdout, "(%5d) ", get_tid()); \ fprintf(stdout, "\e[%dC" fmt "\n", \ 3 + ((n) * 2), ##args); fflush(stdout); } while (0) -- 2.7.4 From f3ef049c986332303e60097be481d47c834f48b5 Mon Sep 17 00:00:00 2001 From: Jihoon Jung Date: Thu, 19 Jul 2018 15:40:29 +0900 Subject: [PATCH 09/16] Add file transfer impl (Not reliable) Change-Id: Ieb7fa7dfd51925d0c66291688ca70fe41ba746f7 Signed-off-by: Jihoon Jung --- test/mdg-manager.c | 84 +++++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 83 insertions(+), 1 deletion(-) diff --git a/test/mdg-manager.c b/test/mdg-manager.c index 0d21f01..f06cd8e 100755 --- a/test/mdg-manager.c +++ b/test/mdg-manager.c @@ -42,7 +42,7 @@ 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"; -//static char monitor[MENU_DATA_SIZE + 1] = "1"; +static char file_path[MENU_DATA_SIZE + 1] = "/path/to/file"; static int run_group_find(MManager *mm, struct menu_data *menu); static int run_devices_find(MManager *mm, struct menu_data *menu); @@ -799,6 +799,77 @@ static int run_send_data(MManager *mm, struct menu_data *menu) return __send_data(devidx, chaidx); } +static int __send_file(int devidx, int chaidx) +{ + int ret = 0; + char *deviceid = NULL; + char *address = NULL; + mdg_device_h device = NULL; + channel_t *channel = NULL; + 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; + } + } + + 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 [CHANNEL ID] %s", deviceid, address, channel->channel_id); + if (deviceid) { + free(deviceid); + deviceid = NULL; + } + if (address) { + free(address); + address = NULL; + } + + ret = mdg_device_send_data(handle, device, channel->channel_id, (unsigned char *)file_path, + strlen(file_path), _send_data_finish_cb, NULL); + if (MDG_ERROR_NONE != ret) + msgr("Failed to Send Data: [ID] %s [IP] %s", deviceid, address); + + return ret; +} + +static int run_send_file(MManager *mm, struct menu_data *menu) +{ + int devidx = 0; + int chaidx = 0; + int count = g_list_length(found_invited_device_list); + + if (0 >= count) { + msgr("No Device"); + return RET_SUCCESS; + } + + if (strlen(device_idx)) { + devidx = (unsigned short)strtol(device_idx, NULL, 10); + if (0 >= devidx) { + msgp("Invalid index. set to 1"); + devidx = 1; + } + } + 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_file(devidx, chaidx); +} + void _invited_device_finish_cb(int result, void *user_data) { msgb("\rFind My Owned Devices Finished ret: [0x%X] [%s]", result, @@ -1165,6 +1236,16 @@ static struct menu_data menu_send_data[] = { { NULL, NULL, }, }; +static struct menu_data menu_send_file[] = { + { "0", "Show Found Invited Device(s)", NULL, run_invited_devices_show, NULL }, + { "1", "Show Channel List", NULL, run_channels_show, NULL }, + { "2", "File Path", NULL, NULL, file_path }, + { "3", "Device Index", NULL, NULL, device_idx }, + { "4", "Channel Index", NULL, NULL, channel_idx }, + { "5", "Send", NULL, run_send_file, NULL }, + { NULL, NULL, }, +}; + static struct menu_data menu_devices_find_invited_device[] = { { "0", "Timeout", NULL, NULL, timeout }, { "1", "Run", NULL, run_devices_find_invited_device, NULL }, @@ -1236,4 +1317,5 @@ struct menu_data menu_mdg_manager[] = { { "16", "Regist Channel", menu_regist_channel, NULL, NULL }, { "17", "Unregist Channel", menu_unregist_channel, NULL, NULL }, { "18", "Send Message", menu_send_data, NULL, NULL }, // 0 + { "19", "Send File", menu_send_file, NULL, NULL }, // 0 }; -- 2.7.4 From 8f4aac226a5cb1a79a4a49a5ba2e401705fd52ff Mon Sep 17 00:00:00 2001 From: Jihoon Jung Date: Tue, 24 Jul 2018 15:24:18 +0900 Subject: [PATCH 10/16] Add proper device parameter when device eject Change-Id: Ibf62dd96c37f90623bbe13c20de48f0870682806 Signed-off-by: Jihoon Jung --- test/mdg-manager.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/test/mdg-manager.c b/test/mdg-manager.c index f06cd8e..01a5b3b 100755 --- a/test/mdg-manager.c +++ b/test/mdg-manager.c @@ -137,12 +137,12 @@ static int run_device_eject(MManager *mm, struct menu_data *menu) } } - if (NULL == found_device_list) { + if (NULL == found_invited_device_list) { msgr("Find device first"); return RET_FAILURE; } - device = g_list_nth_data(found_device_list, idx - 1); + device = g_list_nth_data(found_invited_device_list, idx - 1); if (NULL == device) { msgr("Failed to g_hash_table_find"); return RET_FAILURE; @@ -1219,7 +1219,7 @@ static struct menu_data menu_group_invite_device[] = { static struct menu_data menu_group_eject_device[] = { { "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_device_eject, NULL }, -- 2.7.4 From 9b765af7335f1b448104f5c943fc56b822a074ca Mon Sep 17 00:00:00 2001 From: Jihoon Jung Date: Tue, 24 Jul 2018 18:15:18 +0900 Subject: [PATCH 11/16] Add handle in invite callback Signed-off-by: Jihoon Jung Change-Id: Idef956d4043c452fa90e4c6338ef1e79c159b6a5 --- include/mdg.h | 3 ++- src/mdg.c | 4 ++++ src/mdg_dbus.c | 6 +++++- src/mdg_private.h | 1 + test/mdg-manager.c | 5 ++++- 5 files changed, 16 insertions(+), 3 deletions(-) diff --git a/include/mdg.h b/include/mdg.h index 18f858f..4c8a88a 100755 --- a/include/mdg.h +++ b/include/mdg.h @@ -325,7 +325,8 @@ int mdg_group_get_member_devices(mdg_h handle, * * @see mdg_group_invite_device() */ -typedef void (*mdg_group_invite_device_finish_cb)(int result, void *user_data); +typedef void (*mdg_group_invite_device_finish_cb)(int result, + mdg_device_h invited_device, void *user_data); /** * @brief Called after mdg_group_eject_device(). diff --git a/src/mdg.c b/src/mdg.c index 5a1d7a5..7f32107 100755 --- a/src/mdg.c +++ b/src/mdg.c @@ -403,8 +403,12 @@ EXPORT_API int mdg_group_invite_device(mdg_h handle, mdg_device_s *dev = (mdg_device_s *)device; mdg_check_null_ret_error("dev", dev, MDG_ERROR_INVALID_PARAMETER); + mdg_device_h cloned_device = NULL; + mdg_device_info_clone(&cloned_device, device); + _handle->device_invite_finish_cb.finish_cb = finish_cb; _handle->device_invite_finish_cb.user_data = user_data; + _handle->device_invite_finish_cb.device = cloned_device; group_call_invite_device_sync(_handle->group_proxy, grp->group_name, dev->device_id, PIN, &ret, NULL, &error); diff --git a/src/mdg_dbus.c b/src/mdg_dbus.c index 6038c3d..bd304de 100755 --- a/src/mdg_dbus.c +++ b/src/mdg_dbus.c @@ -77,7 +77,11 @@ static void __event_cb(Group *object, } } else if (event_type == MDG_EVENT_INVITE_DEVICE_FINISH) { if (handle->device_invite_finish_cb.finish_cb) { - handle->device_invite_finish_cb.finish_cb(ret, + mdg_device_s *device = (mdg_device_s *)(handle->device_invite_finish_cb.device); + if (device != NULL) { + device->is_invited = true; + } + handle->device_invite_finish_cb.finish_cb(ret, device, handle->device_invite_finish_cb.user_data); } else { _ERR("The callback not exists"); diff --git a/src/mdg_private.h b/src/mdg_private.h index 35f6beb..486de50 100755 --- a/src/mdg_private.h +++ b/src/mdg_private.h @@ -96,6 +96,7 @@ typedef struct _device_find_finish_cb_t { */ typedef struct _device_invite_finish_cb_t { mdg_group_invite_device_finish_cb finish_cb; /**< User callback to be called */ + mdg_device_h device; void *user_data; /**< User data pointer */ } device_invite_finish_cb_t; diff --git a/test/mdg-manager.c b/test/mdg-manager.c index 01a5b3b..b030ce1 100755 --- a/test/mdg-manager.c +++ b/test/mdg-manager.c @@ -158,9 +158,12 @@ static int run_device_eject(MManager *mm, struct menu_data *menu) return RET_SUCCESS; } -void _device_invite_result_cb(int result, void *user_data) +void _device_invite_result_cb(int result, mdg_device_h device, void *user_data) { + bool is_invited; + mdg_device_info_is_invited(device, &is_invited); msgb("\rInvite Device Finished [%s]", mdg_error_to_string(result)); + msgb("\rThe device invited is : %d", is_invited); } static int run_device_invite(MManager *mm, struct menu_data *menu) -- 2.7.4 From 0b9651a2bd6332164955971cd2abfe1ee2a86656 Mon Sep 17 00:00:00 2001 From: Jihoon Jung Date: Wed, 25 Jul 2018 17:32:27 +0900 Subject: [PATCH 12/16] Add foreach device in group API Change-Id: I5b2410743cf26697528ea4711994b1428d3baed3 Signed-off-by: Jihoon Jung --- include/mdg.h | 46 +++++++++++------ include/mdg_internal.h | 133 ------------------------------------------------- src/mdg.c | 49 ++++++++++++++---- src/mdg_gdbus.xml | 5 +- src/mdg_private.h | 2 +- src/mdg_util.c | 40 +++++++++++++++ src/mdg_util.h | 1 + test/main.c | 15 +++--- test/mdg-manager.c | 74 +++++++++++++++++++++++---- 9 files changed, 187 insertions(+), 178 deletions(-) delete mode 100644 include/mdg_internal.h diff --git a/include/mdg.h b/include/mdg.h index 4c8a88a..e491f82 100755 --- a/include/mdg.h +++ b/include/mdg.h @@ -16,8 +16,8 @@ * limitations under the License. * */ -#ifndef __TIZEN_NETWORK_MULTI_DEVICE_GROUP_H__ -#define __TIZEN_NETWORK_MULTI_DEVICE_GROUP_H__ +#ifndef __TIZEN_NETWORK_MULTI_DEVICE_GROUP_MDG_H__ +#define __TIZEN_NETWORK_MULTI_DEVICE_GROUP_MDG_H__ #include @@ -61,18 +61,15 @@ typedef enum { MDG_ERROR_OUT_OF_MEMORY = TIZEN_ERROR_OUT_OF_MEMORY, /**< Out of memory */ MDG_ERROR_PERMISSION_DENIED = TIZEN_ERROR_PERMISSION_DENIED, /**< Permission denied */ MDG_ERROR_NOT_SUPPORTED = TIZEN_ERROR_NOT_SUPPORTED, /**< Not supported */ - MDG_ERROR_NO_DATA = TIZEN_ERROR_MDG | 0x01, /**< Data not exists */ - MDG_ERROR_OPERATION_FAILED = TIZEN_ERROR_MDG | 0x02, /**< operation failed */ + MDG_ERROR_OPERATION_FAILED = TIZEN_ERROR_MDG | 0x01, /**< operation failed */ + MDG_ERROR_NO_DATA = TIZEN_ERROR_MDG | 0x02, /**< Data not exists */ MDG_ERROR_ALREADY_REGISTERED = TIZEN_ERROR_MDG | 0x03, /**< Request already registered */ MDG_ERROR_IN_PROGRESS = TIZEN_ERROR_MDG | 0x04,/**< operation is in progress */ - MDG_ERROR_COMM_ERROR = TIZEN_ERROR_MDG | 0x05, /**< communication error */ - MDG_ERROR_RX = TIZEN_ERROR_MDG | 0x06, /**< RX error */ - MDG_ERROR_TX = TIZEN_ERROR_MDG | 0x07, /**< TX error */ - MDG_ERROR_PLUGIN_FAIL = TIZEN_ERROR_MDG | 0x08, /**< Plugin failed */ - MDG_ERROR_ALREADY_IN_PROGRESS = TIZEN_ERROR_MDG | 0x09, /**< Already in progress */ - MDG_ERROR_NOT_STARTED = TIZEN_ERROR_MDG | 0x0A, /**< Not Started */ - MDG_ERROR_UNKNOWN = -999, - + MDG_ERROR_COMM_ERROR = TIZEN_ERROR_MDG | 0x05, /**< communication error in lower layer */ + MDG_ERROR_NOT_STARTED = TIZEN_ERROR_MDG | 0x06, /**< Service Not Started */ + MDG_ERROR_DB = TIZEN_ERROR_MDG | 0x07, /**< Internal DB error */ + MDG_ERROR_NOT_PROPER_GROUP = TIZEN_ERROR_MDG | 0x08, /**< Not proper group */ + MDG_ERROR_NOT_PROPER_DEVICE = TIZEN_ERROR_MDG | 0x09, /**< Not proper device */ } mdg_error_e; /** @@ -119,7 +116,6 @@ typedef void *mdg_group_h; /**< Group handle */ * * @return @c 0 on success, otherwise negative error value * @retval #MDG_ERROR_NONE Successful - * @retval #MDG_ERROR_ALREADY_INITIALIZED Already initialized * @retval #MDG_ERROR_INVALID_PARAMETER Invalid parameter * @retval #MDG_ERROR_OPERATION_FAILED Operation failed * @retval #MDG_ERROR_OUT_OF_MEMORY Out of memory @@ -280,6 +276,24 @@ int mdg_group_create(mdg_h handle, char *group_name); int mdg_group_delete(mdg_h handle, mdg_group_h group); /** + * @brief Called after mdg_group_invite_device(). + * @details Called when the maximum wait time elapsed or after the mdg_group_invite_device() + * finished successfully. + * + * @since_tizen 5.0 + * @privlevel public + * @privilege %http://tizen.org/privilege/internet + * + * @param[out] result Result of operation + * @param[out] user_data User data pointer + * + * @pre The callback must be registered with mdg_group_invite_device() + * + * @see mdg_group_invite_device() + */ +typedef bool (*mdg_group_foreach_cb)(mdg_device_h device, void *user_data); + +/** * @brief Gets devices list in a group resource. * @details This function retrieves a devices list of group resources. * @@ -306,8 +320,8 @@ int mdg_group_delete(mdg_h handle, mdg_group_h group); * @see mdg_group_merge() * */ -int mdg_group_get_member_devices(mdg_h handle, - mdg_group_h group, mdg_device_h **devices, int *count); +int mdg_group_foreach_device(mdg_h handle, mdg_group_h group, + mdg_group_foreach_cb foreach_cb, void *user_data); /** * @brief Called after mdg_group_invite_device(). @@ -996,4 +1010,4 @@ int mdg_device_info_get_type(mdg_device_h device, } #endif -#endif /* __TIZEN_NETWORK_MULTI_DEVICE_GROUP_H__ */ +#endif /* __TIZEN_NETWORK_MULTI_DEVICE_GROUP_MDG_H__ */ diff --git a/include/mdg_internal.h b/include/mdg_internal.h deleted file mode 100644 index 42266b7..0000000 --- a/include/mdg_internal.h +++ /dev/null @@ -1,133 +0,0 @@ -/* - * Network Configuration Module - * - * Copyright (c) 2017 Samsung Electronics Co., Ltd. All rights reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - */ -#ifndef __TIZEN_NETWORK_MDG_INTERNAL_H__ -#define __TIZEN_NETWORK_MDG_INTERNAL_H__ - -#include - -#ifdef __cplusplus -extern "C" { -#endif - -/** - * @brief Creates a group handle. - * - * @since_tizen 5.0 - * - * @remarks The @a group should be released using mdg_group_info_destroy(). - * - * @param[in] group Group handle - * - * @return 0 on success, otherwise a negative error value. - * @retval #MDG_ERROR_NONE Successful - * @retval #MDG_ERROR_INVALID_PARAMETER Invalid parameter - * - * @see mdg_group_info_clone() - * @see mdg_group_info_destroy() - * @see mdg_group_info_get_type() - * @see mdg_group_info_get_resource_type() - * @see mdg_group_info_get_uri_path() - * @see mdg_group_info_get_name() - * @see mdg_group_info_get_host_addr() - * - */ -int mdg_group_info_create(mdg_group_h* group); - - -/** - * @brief Creates a device handle. - * - * @since_tizen 5.0 - * - * @remarks The @a device should be released using mdg_device_info_destroy(). - * - * @param[out] device Device handle - * - * @return 0 on success, otherwise a negative error value. - * @retval #MDG_ERROR_NONE Successful - * @retval #MDG_ERROR_INVALID_PARAMETER Invalid parameter - * - * @see mdg_device_info_clone() - * @see mdg_device_info_destroy() - * @see mdg_device_info_get_device_id() - * @see mdg_device_info_get_ip() - * @see mdg_device_info_get_device_type() - * - */ -int mdg_device_info_create(mdg_device_h* device); - -/** - * @brief Combines both groups to one. - * @details This function combines two groups into one. - * - * @since_tizen 5.0 - * @privlevel public - * @privilege %http://tizen.org/privilege/internet - * - * @param[in] handle The multi device group manager handle - * @param[in] dest_group Group handle to be united - * @param[in] src_group Group handle to be merged - * - * - * @return 0 on success, otherwise a negative error value. - * @retval #MDG_ERROR_NONE Successful - * @retval #MDG_ERROR_INVALID_PARAMETER Invalid parameter - * - * @see mdg_group_create() - * @see mdg_request_join_group() - * @see mdg_request_leave_group () - * @see mdg_group_delete() - * @see mdg_group_get_member_devices() - * - */ -int mdg_group_merge(mdg_h handle, mdg_group_h dest_group, - mdg_group_h src_group); - - -/** - * @brief Registers request result callback funtion. - * @details This function registers the callback function for requested group management - * functions and receive processing results after the request complete. - * - * @since_tizen 5.0 - * - * @param[in] handle The multi device group manager handle - * @param[in] callback Callback function pointer - * @param[in] user_data User data pointer - * - * - * @return 0 on success, otherwise a negative error value. - * @retval #MDG_ERROR_NONE Successful - * @retval #MDG_ERROR_INVALID_PARAMETER Invalid parameter - * - * @see mdg_request_create_group() - * @see mdg_request_invite_device() - * @see mdg_request_eject_device() - * @see mdg_request_delete_group() - * @see mdg_device_send_data() - * - */ -int mdg_request_result_callback(mdg_h handle, - mdg_request_result_cb callback, void *user_data); - -#ifdef __cplusplus -} -#endif - -#endif /* __TIZEN_NETWORK_MDG_INTERNAL_H__ */ diff --git a/src/mdg.c b/src/mdg.c index 7f32107..5ac3e5b 100755 --- a/src/mdg.c +++ b/src/mdg.c @@ -183,7 +183,7 @@ int __add_channel_cb(mdg_manager_s *handle, char *channel_id, mdg_channel_cb cha for (l2 = tmp_handle->channel_cb_list; l2 != NULL; l2 = l2->next) { channel_cb_s *tmp_channel = (channel_cb_s *)l2->data; if (g_strcmp0(tmp_channel->channel_id, channel_id) == 0) - return MDG_ERROR_UNKNOWN; + return MDG_ERROR_OPERATION_FAILED; } } @@ -255,7 +255,7 @@ EXPORT_API int mdg_device_unregist_channel(mdg_h handle, char *channel_id) } if (is_exist == false) - ret = MDG_ERROR_UNKNOWN; + ret = MDG_ERROR_OPERATION_FAILED; if (ret == MDG_ERROR_NONE) { group_call_unregist_channel_sync(_handle->group_proxy, channel_id, &ret, NULL, &error); @@ -369,17 +369,45 @@ EXPORT_API int mdg_group_delete(mdg_h handle, mdg_group_h group) return ret; } -EXPORT_API int mdg_group_get_member_devices(mdg_h handle, - mdg_group_h group, mdg_device_h **devices, int *count) +EXPORT_API int mdg_group_foreach_device(mdg_h handle, mdg_group_h group, + mdg_group_foreach_cb foreach_cb, void *user_data) { int ret = MDG_ERROR_NONE; + GError *error = NULL; + GVariant *va = NULL; + int count; CHECK_FEATURE_SUPPORTED(MDG_FEATURE); - NOTUSED(handle); - NOTUSED(group); - NOTUSED(devices); - NOTUSED(count); + mdg_manager_s *_handle = handle; + mdg_check_null_ret_error("handle", handle, MDG_ERROR_INVALID_PARAMETER); + CHECK_HANDLE_IS_VALID(handle); + + mdg_group_s *grp = (mdg_group_s *)group; + mdg_check_null_ret_error("grp", grp, MDG_ERROR_INVALID_PARAMETER); + + group_call_foreach_device_sync(_handle->group_proxy, grp->group_name, &ret, &va, NULL, &error); + count = g_variant_n_children(va); + + if (count > 0) { + GVariantIter *iter = NULL; + GVariant *device_va = NULL; + int result; + + g_variant_get(va, "aa{sv}", &iter); + while ((device_va = g_variant_iter_next_value(iter)) != NULL) { + mdg_device_s *device; + + device = mdg_get_device_from_variant(device_va); + + result = foreach_cb((mdg_device_h)device, user_data); + if (result == false) + break; + } + g_variant_iter_free(iter); + } + + g_variant_unref(va); return ret; } @@ -390,6 +418,7 @@ EXPORT_API int mdg_group_invite_device(mdg_h handle, { int ret = MDG_ERROR_NONE; GError *error = NULL; + GVariant *va = NULL; CHECK_FEATURE_SUPPORTED(MDG_FEATURE); @@ -406,11 +435,13 @@ EXPORT_API int mdg_group_invite_device(mdg_h handle, mdg_device_h cloned_device = NULL; mdg_device_info_clone(&cloned_device, device); + va = mdg_create_variant_device(dev); + _handle->device_invite_finish_cb.finish_cb = finish_cb; _handle->device_invite_finish_cb.user_data = user_data; _handle->device_invite_finish_cb.device = cloned_device; - group_call_invite_device_sync(_handle->group_proxy, grp->group_name, dev->device_id, PIN, + group_call_invite_device_sync(_handle->group_proxy, grp->group_name, va, PIN, &ret, NULL, &error); return ret; diff --git a/src/mdg_gdbus.xml b/src/mdg_gdbus.xml index 57e2a0f..a2c466e 100755 --- a/src/mdg_gdbus.xml +++ b/src/mdg_gdbus.xml @@ -32,7 +32,7 @@ - + @@ -44,8 +44,9 @@ - + + diff --git a/src/mdg_private.h b/src/mdg_private.h index 486de50..1ea0eae 100755 --- a/src/mdg_private.h +++ b/src/mdg_private.h @@ -155,7 +155,7 @@ typedef struct _mdg_manager_s { #define CHECK_HANDLE_IS_VALID(handle) { \ if (g_slist_find(handle_list, handle) == NULL) \ - return MDG_ERROR_UNKNOWN; \ + return MDG_ERROR_OPERATION_FAILED; \ } /** diff --git a/src/mdg_util.c b/src/mdg_util.c index 9282b3a..fcbf729 100755 --- a/src/mdg_util.c +++ b/src/mdg_util.c @@ -180,3 +180,43 @@ void mdg_get_data_from_variant(GVariant *va, char **device_id, char **channel_id g_variant_iter_free(iter); } +GVariant *mdg_create_variant_device(mdg_device_s *device) +{ + GVariant *va; + + GVariantBuilder *builder; + + builder = g_variant_builder_new(G_VARIANT_TYPE("a{sv}")); + + g_variant_builder_add(builder, "{sv}", "DeviceID", + g_variant_new_string(device->device_id)); + g_variant_builder_add(builder, "{sv}", "Port", + g_variant_new_int32(device->port)); + g_variant_builder_add(builder, "{sv}", "Addr", + g_variant_new_string(device->addr)); + g_variant_builder_add(builder, "{sv}", "ConnType", + g_variant_new_int32(device->conn_type)); + g_variant_builder_add(builder, "{sv}", "SecurePort", + g_variant_new_int32(device->secure_port)); + g_variant_builder_add(builder, "{sv}", "ModelName", + g_variant_new_string(device->model_name)); + g_variant_builder_add(builder, "{sv}", "DeviceName", + g_variant_new_string(device->device_name)); + g_variant_builder_add(builder, "{sv}", "PlatformVer", + g_variant_new_string(device->platform_ver)); + g_variant_builder_add(builder, "{sv}", "VendorID", + g_variant_new_string(device->vendor_id)); + g_variant_builder_add(builder, "{sv}", "Profile", + g_variant_new_string(device->profile)); + g_variant_builder_add(builder, "{sv}", "IsInvited", + g_variant_new_int32(device->is_invited)); + g_variant_builder_add(builder, "{sv}", "Type", + g_variant_new_int32(device->type)); + + va = g_variant_builder_end(builder); + + g_variant_builder_unref(builder); + + return va; +} + diff --git a/src/mdg_util.h b/src/mdg_util.h index 8ad2bcc..0a5e141 100755 --- a/src/mdg_util.h +++ b/src/mdg_util.h @@ -25,6 +25,7 @@ extern "C" { #endif +GVariant *mdg_create_variant_device(mdg_device_s *device); 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); diff --git a/test/main.c b/test/main.c index 3d807f8..b522dcd 100755 --- a/test/main.c +++ b/test/main.c @@ -26,7 +26,6 @@ #include #include -#include #include "menu.h" #include "common.h" @@ -52,13 +51,15 @@ const char* mdg_error_to_string(mdg_error_e err) CASE_TO_STR(MDG_ERROR_PERMISSION_DENIED) CASE_TO_STR(MDG_ERROR_NOT_SUPPORTED) CASE_TO_STR(MDG_ERROR_OPERATION_FAILED) + CASE_TO_STR(MDG_ERROR_NO_DATA) CASE_TO_STR(MDG_ERROR_ALREADY_REGISTERED) CASE_TO_STR(MDG_ERROR_IN_PROGRESS) - CASE_TO_STR(MDG_ERROR_RX) - CASE_TO_STR(MDG_ERROR_TX) - CASE_TO_STR(MDG_ERROR_PLUGIN_FAIL) - CASE_TO_STR(MDG_ERROR_ALREADY_IN_PROGRESS) + CASE_TO_STR(MDG_ERROR_COMM_ERROR) CASE_TO_STR(MDG_ERROR_NOT_STARTED) + CASE_TO_STR(MDG_ERROR_DB) + CASE_TO_STR(MDG_ERROR_NOT_PROPER_GROUP) + CASE_TO_STR(MDG_ERROR_NOT_PROPER_DEVICE) + default : return "MDG_ERROR_UNKNOWN"; } @@ -85,7 +86,7 @@ static int __init_func(MManager *mm, struct menu_data *menu) mdg_error_to_string(ret), ret); return RET_FAILURE; } - +/* ret = mdg_request_result_callback(handle, receive_request_result, NULL); if (ret != 0) { @@ -93,7 +94,7 @@ static int __init_func(MManager *mm, struct menu_data *menu) mdg_error_to_string(ret), ret); return RET_FAILURE; } - +*/ return RET_SUCCESS; } diff --git a/test/mdg-manager.c b/test/mdg-manager.c index b030ce1..a131433 100755 --- a/test/mdg-manager.c +++ b/test/mdg-manager.c @@ -158,6 +158,52 @@ static int run_device_eject(MManager *mm, struct menu_data *menu) return RET_SUCCESS; } +bool __group_foreach_cb(mdg_device_h device, void *user_data) +{ + char *addr; + char *device_id; + + mdg_device_info_get_addr(device, &addr); + mdg_device_info_get_device_id(device, &device_id); + msgb("\rDevice is [%s], ADDR [%s]", device_id, addr); + + return true; +} + +static int run_group_foreach_device(MManager *mm, struct menu_data *menu) +{ + int ret; + int idx; + mdg_group_h group = NULL; + + msg("Foreach Device"); + + if (strlen(group_idx)) { + idx = (unsigned short)strtol(group_idx, NULL, 10); + if (0 >= idx) { + msgp("Invalid index. set to 1"); + idx = 1; + } + } + + if (found_group_list) { + group = g_list_nth_data(found_group_list, idx - 1); + if (NULL == group) { + msgr("Failed to g_hash_table_find"); + return RET_FAILURE; + } + } + + ret = mdg_group_foreach_device(handle, group, __group_foreach_cb, NULL); + if (MDG_ERROR_NONE != ret) { + msgr("Failed to foreach device: [%s(0x%X)]", mdg_error_to_string(ret), ret); + return RET_FAILURE; + } + msg(" - mdg_group_foreach_device() ret: [0x%X] [%s]", ret, mdg_error_to_string(ret)); + + return RET_SUCCESS; +} + void _device_invite_result_cb(int result, mdg_device_h device, void *user_data) { bool is_invited; @@ -1229,6 +1275,13 @@ static struct menu_data menu_group_eject_device[] = { { NULL, NULL, }, }; +static struct menu_data menu_group_foreach_device[] = { + { "0", "Show Found Group(s)", NULL, run_group_show, NULL }, + { "1", "Group Index", NULL, NULL, group_idx }, + { "2", "Run", NULL, run_group_foreach_device, NULL }, + { NULL, NULL, }, +}; + static struct menu_data menu_send_data[] = { { "0", "Show Found Invited Device(s)", NULL, run_invited_devices_show, NULL }, { "1", "Show Channel List", NULL, run_channels_show, NULL }, @@ -1311,14 +1364,15 @@ struct menu_data menu_mdg_manager[] = { { "7", "Show Device(s)", NULL, run_devices_show, NULL }, // 0 { "8", "Invite Device", menu_group_invite_device, NULL, NULL }, // 0 { "9", "Eject Device", menu_group_eject_device, NULL, NULL }, // 0 - { "10", "Find Invited Device(s)", menu_devices_find_invited_device, NULL, NULL }, // 0 - { "11", "Show Invited Device(s)", NULL, run_invited_devices_show, NULL }, // 0 - { "12", "Request Create Group", menu_request_create_group, NULL, NULL }, // 0 - { "13", "Request Invite", menu_request_invite, NULL, NULL }, // 0 - { "14", "Request Eject", menu_request_eject, NULL, NULL }, // 0 - { "15", "Request Channel List", menu_request_channel_list, NULL, NULL }, // 0 - { "16", "Regist Channel", menu_regist_channel, NULL, NULL }, - { "17", "Unregist Channel", menu_unregist_channel, NULL, NULL }, - { "18", "Send Message", menu_send_data, NULL, NULL }, // 0 - { "19", "Send File", menu_send_file, NULL, NULL }, // 0 + { "10", "Foreach Device", menu_group_foreach_device, NULL, NULL }, + { "11", "Find Invited Device(s)", menu_devices_find_invited_device, NULL, NULL }, // 0 + { "12", "Show Invited Device(s)", NULL, run_invited_devices_show, NULL }, // 0 + { "13", "Request Create Group", menu_request_create_group, NULL, NULL }, // 0 + { "14", "Request Invite", menu_request_invite, NULL, NULL }, // 0 + { "15", "Request Eject", menu_request_eject, NULL, NULL }, // 0 + { "16", "Request Channel List", menu_request_channel_list, NULL, NULL }, // 0 + { "17", "Regist Channel", menu_regist_channel, NULL, NULL }, + { "18", "Unregist Channel", menu_unregist_channel, NULL, NULL }, + { "19", "Send Message", menu_send_data, NULL, NULL }, // 0 + { "20", "Send File", menu_send_file, NULL, NULL }, // 0 }; -- 2.7.4 From 2055e051fc04b59e0cf5d9acd7bd0dd319b34d8b Mon Sep 17 00:00:00 2001 From: Jihoon Jung Date: Thu, 26 Jul 2018 18:19:47 +0900 Subject: [PATCH 13/16] Add send file implmentation Change-Id: Id9e379896ef3ae2f73f915eab87d213d5931288e Signed-off-by: Jihoon Jung --- include/mdg.h | 10 +++++--- src/mdg.c | 35 ++++++++++++++++++++++++++ src/mdg_dbus.c | 74 ++++++++++++++++++++++++++++++++++++++++++++++-------- src/mdg_gdbus.xml | 7 ++++++ src/mdg_private.h | 17 ++++++++++++- src/mdg_util.c | 23 +++++++++++++++++ src/mdg_util.h | 2 ++ test/mdg-manager.c | 51 ++++++++++++++++++------------------- 8 files changed, 177 insertions(+), 42 deletions(-) diff --git a/include/mdg.h b/include/mdg.h index e491f82..3b437c0 100755 --- a/include/mdg.h +++ b/include/mdg.h @@ -801,9 +801,6 @@ int mdg_device_regist_channel(mdg_h handle, char *channel_id, int mdg_device_unregist_channel(mdg_h handle, char *channel_id); /* Client Side */ -//int mdg_device_get_channels(mdg_h handle, mdg_device_h device, -// mdg_device_get_channels_cb get_channels_cb, void *user_data); - /** * @brief Sends data to the remote device. * @details We can send data to devices included in group. @@ -835,6 +832,13 @@ int mdg_device_send_data(mdg_h handle, mdg_device_h device, char *channel_id, unsigned char *data, int len, mdg_device_send_data_finish_cb finish_cb, void *user_data); +typedef void (*mdg_send_file_progress_cb)(const char *file_path, long send_size, + long total_size, int percent, void *user_data); +typedef void (*mdg_send_file_finish_cb)(int result, mdg_device_h device, void *user_data); + +int mdg_device_send_file(mdg_h handle, mdg_device_h device, char *file_path, + mdg_send_file_progress_cb progress_cb, mdg_send_file_finish_cb finish_cb, void *user_data); + /** * @} */ diff --git a/src/mdg.c b/src/mdg.c index 5ac3e5b..ef1a477 100755 --- a/src/mdg.c +++ b/src/mdg.c @@ -324,6 +324,41 @@ EXPORT_API int mdg_device_send_data(mdg_h handle, return ret; } +EXPORT_API int mdg_device_send_file(mdg_h handle, mdg_device_h device, + char *file_path, mdg_send_file_progress_cb progress_cb, mdg_send_file_finish_cb finish_cb, void *user_data) +{ + int ret = MDG_ERROR_NONE; + GError *error = NULL; + + CHECK_FEATURE_SUPPORTED(MDG_FEATURE); + + mdg_manager_s *_handle = handle; + mdg_check_null_ret_error("handle", handle, MDG_ERROR_INVALID_PARAMETER); + CHECK_HANDLE_IS_VALID(handle); + + mdg_device_s *dev = (mdg_device_s *)device; + mdg_check_null_ret_error("dev", dev, MDG_ERROR_INVALID_PARAMETER); + mdg_check_null_ret_error("file_path", file_path, MDG_ERROR_INVALID_PARAMETER); + + mdg_device_h cloned_device = NULL; + mdg_device_info_clone(&cloned_device, device); + + _handle->send_file_cb.finish_cb = finish_cb; + _handle->send_file_cb.progress_cb = progress_cb; + _handle->send_file_cb.device = cloned_device; + _handle->send_file_cb.user_data = user_data; + + group_call_send_file_sync(_handle->group_proxy, dev->device_id, dev->addr, + dev->secure_port, file_path, &ret, NULL, &error); + if (error) { + _ERR("Failed DBus call [%s]", error->message); + g_error_free(error); + ret = MDG_ERROR_IO_ERROR; + } + + return ret; +} + EXPORT_API int mdg_device_get_local_device(mdg_h handle, mdg_device_h *device) { diff --git a/src/mdg_dbus.c b/src/mdg_dbus.c index bd304de..154f6c1 100755 --- a/src/mdg_dbus.c +++ b/src/mdg_dbus.c @@ -41,7 +41,9 @@ static void __event_cb(Group *object, _DBG("Event occured : %d", event_type); - if (event_type == MDG_EVENT_GROUP_FOUND) { + switch (event_type) { + case MDG_EVENT_GROUP_FOUND: + { mdg_group_s *group = NULL; group = mdg_get_group_from_variant(va); @@ -51,14 +53,20 @@ static void __event_cb(Group *object, } else { _ERR("The callback not exists"); } - } else if (event_type == MDG_EVENT_GROUP_FIND_FINISH) { + break; + } + case MDG_EVENT_GROUP_FIND_FINISH: + { if (handle->group_find_finish_cb.finish_cb) { handle->group_find_finish_cb.finish_cb(ret, handle->group_find_finish_cb.user_data); } else { _ERR("The callback not exists"); } - } else if (event_type == MDG_EVENT_DEVICE_FOUND) { + break; + } + case MDG_EVENT_DEVICE_FOUND: + { mdg_device_s *device = NULL; device = mdg_get_device_from_variant(va); @@ -68,14 +76,20 @@ static void __event_cb(Group *object, } else { _ERR("The callback not exists"); } - } else if (event_type == MDG_EVENT_DEVICE_FIND_FINISH) { + break; + } + case MDG_EVENT_DEVICE_FIND_FINISH: + { if (handle->device_find_finish_cb.finish_cb) { handle->device_find_finish_cb.finish_cb(ret, handle->device_find_finish_cb.user_data); } else { _ERR("The callback not exists"); } - } else if (event_type == MDG_EVENT_INVITE_DEVICE_FINISH) { + break; + } + case MDG_EVENT_INVITE_DEVICE_FINISH: + { if (handle->device_invite_finish_cb.finish_cb) { mdg_device_s *device = (mdg_device_s *)(handle->device_invite_finish_cb.device); if (device != NULL) { @@ -86,21 +100,30 @@ static void __event_cb(Group *object, } else { _ERR("The callback not exists"); } - } else if (event_type == MDG_EVENT_EJECT_DEVICE_FINISH) { + break; + } + case MDG_EVENT_EJECT_DEVICE_FINISH: + { if (handle->device_eject_finish_cb.finish_cb) { handle->device_eject_finish_cb.finish_cb(ret, handle->device_eject_finish_cb.user_data); } else { _ERR("The callback not exists"); } - } else if (event_type == MDG_EVENT_SEND_DATA_FINISH) { + break; + } + case MDG_EVENT_SEND_DATA_FINISH: + { if (handle->send_data_finish_cb.finish_cb) { handle->send_data_finish_cb.finish_cb(ret, handle->send_data_finish_cb.user_data); } else { _ERR("The callback not exists"); } - } else if (event_type == MDG_EVENT_REQ_CHANNEL_LIST_FINISH) { + break; + } + case MDG_EVENT_REQ_CHANNEL_LIST_FINISH: + { char *device_id; char *channel_id; @@ -111,7 +134,10 @@ static void __event_cb(Group *object, } else { _ERR("The callback not exists"); } - } else if (event_type == MDGD_EVENT_RECEIVE_DATA) { + break; + } + case MDG_EVENT_RECEIVE_DATA: + { char *device_id; char *channel_id; unsigned char *data; @@ -130,9 +156,35 @@ static void __event_cb(Group *object, if (channel != NULL) channel->cb(0, device_id, channel_id, data, data_len, channel->user_data); - - } else { + break; + } + case MDG_EVENT_SEND_FILE_PROGRESS: + { + if (handle->send_file_cb.progress_cb) { + int percent = 0; + long send_size, total_size; + char *file_path; + mdg_get_progress_from_variant(va, &file_path, &send_size, &total_size, &percent); + handle->send_file_cb.progress_cb(file_path, send_size, total_size, percent, + handle->send_file_cb.user_data); + } else { + _ERR("The callback not exists"); + } + break; + } + case MDG_EVENT_SEND_FILE_FINISH: + { + if (handle->send_file_cb.finish_cb) { + mdg_device_s *device = (mdg_device_s *)(handle->send_file_cb.device); + handle->send_file_cb.finish_cb(ret, device, handle->send_file_cb.user_data); + } else { + _ERR("The callback not exists"); + } + break; + } + default: _ERR("Unknown Event"); + break; } _END(); diff --git a/src/mdg_gdbus.xml b/src/mdg_gdbus.xml index a2c466e..4424848 100755 --- a/src/mdg_gdbus.xml +++ b/src/mdg_gdbus.xml @@ -65,6 +65,13 @@ + + + + + + + diff --git a/src/mdg_private.h b/src/mdg_private.h index 1ea0eae..8f0774e 100755 --- a/src/mdg_private.h +++ b/src/mdg_private.h @@ -119,6 +119,17 @@ typedef struct _send_data_finish_cb_t { } send_data_finish_cb_t; /** + * @brief Sending data to the device done callback structure + * @since_tizen 5.0 + */ +typedef struct _send_file_cb_t { + mdg_send_file_progress_cb progress_cb; /**< User callback to be called */ + mdg_send_file_finish_cb finish_cb; /**< User callback to be called */ + mdg_device_h device; + void *user_data; /**< User data pointer */ +} send_file_cb_t; + +/** * @brief Sending internal commands to the device done callback structure * @since_tizen 5.0 */ @@ -149,6 +160,7 @@ typedef struct _mdg_manager_s { device_invite_finish_cb_t device_invite_finish_cb; /**< When it called after invinting a device done or timeout */ 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 */ + send_file_cb_t send_file_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; @@ -204,7 +216,10 @@ typedef enum { MDG_EVENT_REQUEST_FINISH, MDG_EVENT_SEND_DATA_FINISH, MDG_EVENT_REQ_CHANNEL_LIST_FINISH, - MDGD_EVENT_RECEIVE_DATA, + MDG_EVENT_RECEIVE_DATA, + MDG_EVENT_RECEIVE_FILE = 10, + MDG_EVENT_SEND_FILE_PROGRESS, + MDG_EVENT_SEND_FILE_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 fcbf729..3291cc5 100755 --- a/src/mdg_util.c +++ b/src/mdg_util.c @@ -148,6 +148,7 @@ 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) { @@ -180,6 +181,28 @@ void mdg_get_data_from_variant(GVariant *va, char **device_id, char **channel_id g_variant_iter_free(iter); } +void mdg_get_progress_from_variant(GVariant *va, char **file_path, + long *send_size, long *total_size, int *percent) +{ + 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, "FilePath") == 0) + *file_path = (char *)g_variant_get_string(key_value, NULL); + if (g_strcmp0(key, "SendSize") == 0) + *send_size = g_variant_get_int64(key_value); + if (g_strcmp0(key, "TotalSize") == 0) + *total_size = g_variant_get_int64(key_value); + if (g_strcmp0(key, "Percent") == 0) + *percent = g_variant_get_int32(key_value); + } + + g_variant_iter_free(iter); +} + GVariant *mdg_create_variant_device(mdg_device_s *device) { GVariant *va; diff --git a/src/mdg_util.h b/src/mdg_util.h index 0a5e141..df46e2e 100755 --- a/src/mdg_util.h +++ b/src/mdg_util.h @@ -31,6 +31,8 @@ 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); +void mdg_get_progress_from_variant(GVariant *va, char **file_path, + long *send_size, long *total_size, int *percent); #ifdef __cplusplus } diff --git a/test/mdg-manager.c b/test/mdg-manager.c index a131433..9637951 100755 --- a/test/mdg-manager.c +++ b/test/mdg-manager.c @@ -848,13 +848,27 @@ static int run_send_data(MManager *mm, struct menu_data *menu) return __send_data(devidx, chaidx); } -static int __send_file(int devidx, int chaidx) +void __send_file_progress_cb(const char *file_path, long send_size, + long total_size, int percent, void *user_data) +{ + msgp("%s %d%% [%ld/%ld]", file_path, percent, send_size, total_size); +} +void __send_file_finish_cb(int result, mdg_device_h device, void *user_data) +{ + char *addr; + + mdg_device_info_get_addr(device, &addr); + + msgp("Send file to %s Finished [%s]", addr, mdg_error_to_string(result)); +} + +static int __send_file(int devidx) { int ret = 0; char *deviceid = NULL; char *address = NULL; mdg_device_h device = NULL; - channel_t *channel = NULL; + if (found_invited_device_list) { device = g_list_nth_data(found_invited_device_list, devidx - 1); if (NULL == device) { @@ -863,17 +877,9 @@ static int __send_file(int devidx, int chaidx) } } - 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 [CHANNEL ID] %s", deviceid, address, channel->channel_id); + msgp("Sent to [ID] %s [ADDR] %s", deviceid, address); if (deviceid) { free(deviceid); deviceid = NULL; @@ -883,8 +889,8 @@ static int __send_file(int devidx, int chaidx) address = NULL; } - ret = mdg_device_send_data(handle, device, channel->channel_id, (unsigned char *)file_path, - strlen(file_path), _send_data_finish_cb, NULL); + ret = mdg_device_send_file(handle, device, file_path, + __send_file_progress_cb, __send_file_finish_cb, NULL); if (MDG_ERROR_NONE != ret) msgr("Failed to Send Data: [ID] %s [IP] %s", deviceid, address); @@ -894,7 +900,6 @@ static int __send_file(int devidx, int chaidx) static int run_send_file(MManager *mm, struct menu_data *menu) { int devidx = 0; - int chaidx = 0; int count = g_list_length(found_invited_device_list); if (0 >= count) { @@ -909,14 +914,8 @@ static int run_send_file(MManager *mm, struct menu_data *menu) devidx = 1; } } - 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_file(devidx, chaidx); + + return __send_file(devidx); } void _invited_device_finish_cb(int result, void *user_data) @@ -1294,11 +1293,9 @@ static struct menu_data menu_send_data[] = { static struct menu_data menu_send_file[] = { { "0", "Show Found Invited Device(s)", NULL, run_invited_devices_show, NULL }, - { "1", "Show Channel List", NULL, run_channels_show, NULL }, - { "2", "File Path", NULL, NULL, file_path }, - { "3", "Device Index", NULL, NULL, device_idx }, - { "4", "Channel Index", NULL, NULL, channel_idx }, - { "5", "Send", NULL, run_send_file, NULL }, + { "1", "File Path", NULL, NULL, file_path }, + { "2", "Device Index", NULL, NULL, device_idx }, + { "3", "Send", NULL, run_send_file, NULL }, { NULL, NULL, }, }; -- 2.7.4 From f75948ae39227e9c916a95650f92513aa82175c1 Mon Sep 17 00:00:00 2001 From: Jihoon Jung Date: Wed, 1 Aug 2018 13:01:09 +0900 Subject: [PATCH 14/16] Remove address information Signed-off-by: Jihoon Jung Change-Id: I5193b2350c820e270c8036629908a2e2929645d7 --- include/mdg.h | 12 ----- include/mdg_internal.h | 47 +++++++++++++++++++ src/mdg.c | 122 +++++++++++++++++-------------------------------- src/mdg_dbus.c | 12 +++++ src/mdg_gdbus.xml | 12 ----- src/mdg_private.h | 13 +++--- src/mdg_util.c | 45 +++++++----------- src/mdg_util.h | 1 + test/common.h | 1 + test/mdg-manager.c | 106 +++++++++++++++++++----------------------- 10 files changed, 174 insertions(+), 197 deletions(-) create mode 100755 include/mdg_internal.h diff --git a/include/mdg.h b/include/mdg.h index 3b437c0..f92b7fc 100755 --- a/include/mdg.h +++ b/include/mdg.h @@ -583,7 +583,6 @@ int mdg_request_channel_list(mdg_h handle, mdg_device_h device, * @see mdg_group_info_get_resource_type() * @see mdg_group_info_get_uri_path() * @see mdg_group_info_get_name() - * @see mdg_group_info_get_host_addr() * */ int mdg_group_info_clone(mdg_group_h *dst, @@ -607,13 +606,11 @@ int mdg_group_info_clone(mdg_group_h *dst, * @see mdg_group_info_get_resource_type() * @see mdg_group_info_get_uri_path() * @see mdg_group_info_get_name() - * @see mdg_group_info_get_host_addr() * */ int mdg_group_info_destroy(mdg_group_h group); int mdg_group_info_get_device_id(mdg_group_h group, char **device_id); -int mdg_group_info_get_host_addr(mdg_group_h group, char **host_addr); /** * @brief Gets group type of the group handle. @@ -634,7 +631,6 @@ int mdg_group_info_get_host_addr(mdg_group_h group, char **host_addr); * @see mdg_group_info_get_resource_type() * @see mdg_group_info_get_uri_path() * @see mdg_group_info_get_name() - * @see mdg_group_info_get_host_addr() * */ int mdg_group_info_get_type(mdg_group_h group, mdg_group_type_e *type); @@ -660,7 +656,6 @@ int mdg_group_info_get_type(mdg_group_h group, mdg_group_type_e *type); * @see mdg_group_info_get_type() * @see mdg_group_info_get_resource_type() * @see mdg_group_info_get_uri_path() - * @see mdg_group_info_get_host_addr() * */ int mdg_group_info_get_name(mdg_group_h group, char **name); @@ -832,13 +827,6 @@ int mdg_device_send_data(mdg_h handle, mdg_device_h device, char *channel_id, unsigned char *data, int len, mdg_device_send_data_finish_cb finish_cb, void *user_data); -typedef void (*mdg_send_file_progress_cb)(const char *file_path, long send_size, - long total_size, int percent, void *user_data); -typedef void (*mdg_send_file_finish_cb)(int result, mdg_device_h device, void *user_data); - -int mdg_device_send_file(mdg_h handle, mdg_device_h device, char *file_path, - mdg_send_file_progress_cb progress_cb, mdg_send_file_finish_cb finish_cb, void *user_data); - /** * @} */ diff --git a/include/mdg_internal.h b/include/mdg_internal.h new file mode 100755 index 0000000..52fd474 --- /dev/null +++ b/include/mdg_internal.h @@ -0,0 +1,47 @@ +/* + * Network Configuration Module + * + * Copyright (c) 2017 Samsung Electronics Co., Ltd. All rights reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ +#ifndef __TIZEN_NETWORK_MULTI_DEVICE_GROUP_MDG_INTERNAL_H__ +#define __TIZEN_NETWORK_MULTI_DEVICE_GROUP_MDG_INTERNAL_H__ + +#ifdef __cplusplus +extern "C" { +#endif + +/* File transfer for Client Side */ +typedef void (*mdg_send_file_progress_cb)(const char *file_path, long send_size, + long total_size, int percent, void *user_data); +typedef void (*mdg_send_file_finish_cb)(int result, mdg_device_h device, void *user_data); + +int mdg_device_send_file(mdg_h handle, mdg_device_h device, char *file_path, + mdg_send_file_progress_cb progress_cb, mdg_send_file_finish_cb finish_cb, void *user_data); + +/* File transfer for Server Side */ +typedef void (*mdg_receive_file_cb)(int result, char *device_id, + const char *file_path, void *user_data); + +int mdg_set_receive_file_cb(mdg_h handle, mdg_receive_file_cb receive_cb, void *user_data); +int mdg_unset_receive_file_cb(mdg_h handle); + + +#ifdef __cplusplus +} +#endif + +#endif /* __TIZEN_NETWORK_MULTI_DEVICE_GROUP_MDG_H__ */ + diff --git a/src/mdg.c b/src/mdg.c index ef1a477..b84f955 100755 --- a/src/mdg.c +++ b/src/mdg.c @@ -310,8 +310,8 @@ EXPORT_API int mdg_device_send_data(mdg_h handle, _handle->send_data_finish_cb.finish_cb = finish_cb; _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, channel_id, params, &ret, NULL, &error); + group_call_send_data_sync(_handle->group_proxy, dev->device_id, + channel_id, params, &ret, NULL, &error); if (error) { _ERR("Failed DBus call [%s]", error->message); g_error_free(error); @@ -348,8 +348,7 @@ EXPORT_API int mdg_device_send_file(mdg_h handle, mdg_device_h device, _handle->send_file_cb.device = cloned_device; _handle->send_file_cb.user_data = user_data; - group_call_send_file_sync(_handle->group_proxy, dev->device_id, dev->addr, - dev->secure_port, file_path, &ret, NULL, &error); + group_call_send_file_sync(_handle->group_proxy, dev->device_id, file_path, &ret, NULL, &error); if (error) { _ERR("Failed DBus call [%s]", error->message); g_error_free(error); @@ -359,6 +358,39 @@ EXPORT_API int mdg_device_send_file(mdg_h handle, mdg_device_h device, return ret; } +EXPORT_API int mdg_set_receive_file_cb(mdg_h handle, + mdg_receive_file_cb receive_cb, void *user_data) +{ + int ret = MDG_ERROR_NONE; + + CHECK_FEATURE_SUPPORTED(MDG_FEATURE); + + mdg_manager_s *_handle = handle; + mdg_check_null_ret_error("handle", handle, MDG_ERROR_INVALID_PARAMETER); + CHECK_HANDLE_IS_VALID(handle); + + _handle->receive_file_cb.receive_cb = receive_cb; + _handle->receive_file_cb.user_data = user_data; + + return ret; +} + +EXPORT_API int mdg_unset_receive_file_cb(mdg_h handle) +{ + int ret = MDG_ERROR_NONE; + + CHECK_FEATURE_SUPPORTED(MDG_FEATURE); + + mdg_manager_s *_handle = handle; + mdg_check_null_ret_error("handle", handle, MDG_ERROR_INVALID_PARAMETER); + CHECK_HANDLE_IS_VALID(handle); + + _handle->receive_file_cb.receive_cb = NULL; + _handle->receive_file_cb.user_data = NULL; + + return ret; +} + EXPORT_API int mdg_device_get_local_device(mdg_h handle, mdg_device_h *device) { @@ -545,9 +577,6 @@ EXPORT_API int mdg_group_info_clone(mdg_group_h *target, if (src->device_id) dst->device_id = g_strdup(src->device_id); - if (src->host_addr) - dst->host_addr = g_strdup(src->host_addr); - if (src->group_name) dst->group_name = g_strdup(src->group_name); @@ -569,10 +598,6 @@ EXPORT_API int mdg_group_info_destroy(mdg_group_h data) g_free(group->device_id); group->device_id = NULL; } - if (group->host_addr) { - g_free(group->host_addr); - group->host_addr = NULL; - } if (group->group_name) { g_free(group->group_name); group->group_name = NULL; @@ -596,18 +621,6 @@ EXPORT_API int mdg_group_info_get_device_id( return ret; } -EXPORT_API int mdg_group_info_get_host_addr( - mdg_group_h group, char **host_addr) -{ - int ret = MDG_ERROR_NONE; - - CHECK_FEATURE_SUPPORTED(MDG_FEATURE); - - *host_addr = g_strdup(((mdg_group_s *)group)->host_addr); - - return ret; -} - EXPORT_API int mdg_group_info_get_type(mdg_group_h group, mdg_group_type_e *type) { @@ -649,13 +662,6 @@ EXPORT_API int mdg_device_info_clone(mdg_device_h *target, if (src->device_id) dst->device_id = g_strdup(src->device_id); - if (src->addr) - dst->addr = g_strdup(src->addr); - - dst->port = src->port; - dst->secure_port = src->secure_port; - dst->conn_type = src->conn_type; - if (src->model_name) dst->model_name = g_strdup(src->model_name); @@ -691,11 +697,6 @@ EXPORT_API int mdg_device_info_destroy(mdg_device_h data) device->device_id = NULL; } - if (device->addr) { - g_free(device->addr); - device->addr = NULL; - } - if (device->model_name) { g_free(device->model_name); device->model_name = NULL; @@ -739,42 +740,6 @@ EXPORT_API int mdg_device_info_get_device_id( return ret; } -EXPORT_API int mdg_device_info_get_addr( - mdg_device_h device, char **addr) -{ - int ret = MDG_ERROR_NONE; - - CHECK_FEATURE_SUPPORTED(MDG_FEATURE); - - *addr = g_strdup(((mdg_device_s *)device)->addr); - - return ret; -} - -EXPORT_API int mdg_device_info_get_port( - mdg_device_h device, int *port) -{ - int ret = MDG_ERROR_NONE; - - CHECK_FEATURE_SUPPORTED(MDG_FEATURE); - - *port = (((mdg_device_s *)device)->port); - - return ret; -} - -EXPORT_API int mdg_device_info_get_secure_port( - mdg_device_h device, int *secure_port) -{ - int ret = MDG_ERROR_NONE; - - CHECK_FEATURE_SUPPORTED(MDG_FEATURE); - - *secure_port = (((mdg_device_s *)device)->secure_port); - - return ret; -} - EXPORT_API int mdg_device_info_get_model_name( mdg_device_h device, char **model_name) { @@ -882,8 +847,8 @@ EXPORT_API int mdg_request_create_group(mdg_h handle, _DBG("Device id : %s", dev->device_id); - group_call_request_create_group_sync(_handle->group_proxy, dev->device_id, dev->addr, - dev->secure_port, group_name, &ret, NULL, &error); + group_call_request_create_group_sync(_handle->group_proxy, dev->device_id, + group_name, &ret, NULL, &error); return ret; } @@ -914,8 +879,8 @@ EXPORT_API int mdg_request_invite_device(mdg_h handle, _DBG("%s", grp->group_name); _DBG("%s", dev->device_id); - group_call_request_invite(_handle->group_proxy, grp->device_id, dev->addr, - dev->secure_port, grp->group_name, dev->device_id, PIN, NULL, NULL, &error); + group_call_request_invite(_handle->group_proxy, grp->device_id, + grp->group_name, dev->device_id, PIN, NULL, NULL, &error); if (error) { _ERR("Failed DBus call [%s]", error->message); g_error_free(error); @@ -951,8 +916,8 @@ EXPORT_API int mdg_request_eject_device(mdg_h handle, _DBG("%s", grp->group_name); _DBG("%s", dev->device_id); - group_call_request_eject(_handle->group_proxy, grp->device_id, dev->addr, - dev->secure_port, grp->group_name, dev->device_id, NULL, NULL, &error); + group_call_request_eject(_handle->group_proxy, grp->device_id, + grp->group_name, dev->device_id, NULL, NULL, &error); if (error) { _ERR("Failed DBus call [%s]", error->message); g_error_free(error); @@ -981,8 +946,7 @@ EXPORT_API int mdg_request_channel_list(mdg_h handle, mdg_device_h device, _DBG("%s", dev->device_id); - group_call_request_channel_list(_handle->group_proxy, dev->device_id, dev->addr, - dev->secure_port, NULL, NULL, &error); + group_call_request_channel_list(_handle->group_proxy, dev->device_id, NULL, 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 154f6c1..8e50fc1 100755 --- a/src/mdg_dbus.c +++ b/src/mdg_dbus.c @@ -182,6 +182,18 @@ static void __event_cb(Group *object, } break; } + case MDG_EVENT_RECEIVE_FILE: + { + if (handle->receive_file_cb.receive_cb) { + char *device_id; + char *file_path; + mdg_get_receive_file_from_variant(va, &device_id, &file_path); + handle->receive_file_cb.receive_cb(ret, device_id, file_path, + handle->receive_file_cb.user_data); + } else { + _ERR("The callback not exists"); + } + } default: _ERR("Unknown Event"); break; diff --git a/src/mdg_gdbus.xml b/src/mdg_gdbus.xml index 4424848..bcb0828 100755 --- a/src/mdg_gdbus.xml +++ b/src/mdg_gdbus.xml @@ -59,30 +59,22 @@ - - - - - - - - @@ -90,16 +82,12 @@ - - - - diff --git a/src/mdg_private.h b/src/mdg_private.h index 8f0774e..8e8e245 100755 --- a/src/mdg_private.h +++ b/src/mdg_private.h @@ -21,9 +21,9 @@ #include #include #include +#include #include #include - #include #define MDG_FEATURE "http://tizen.org/feature/network.mdg" @@ -129,6 +129,11 @@ typedef struct _send_file_cb_t { void *user_data; /**< User data pointer */ } send_file_cb_t; +typedef struct _receive_file_cb_t { + mdg_receive_file_cb receive_cb; /**< User callback to be called */ + void *user_data; /**< User data pointer */ +} receive_file_cb_t; + /** * @brief Sending internal commands to the device done callback structure * @since_tizen 5.0 @@ -161,6 +166,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 */ send_file_cb_t send_file_cb; /**< When it called after sending the device done or timeout */ + receive_file_cb_t receive_file_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; @@ -176,7 +182,6 @@ typedef struct _mdg_manager_s { */ typedef struct _mdg_group_s { char *device_id; /**< Device ID of the device has this group resource */ - char *host_addr; /**< Host address */ char *group_name; /**< Group Name (Friendly name) */ mdg_group_type_e type; /**< Mine or Remote */ } mdg_group_s; @@ -187,10 +192,6 @@ typedef struct _mdg_group_s { */ typedef struct _mdg_device_s { char *device_id; /**< Device ID */ - char *addr; /**< Device IP */ - int port; /**< Port Number */ - int secure_port; /**< Secure Port Number */ - unsigned int conn_type; /**< Connection type */ char *model_name; char *device_name; char *platform_ver; diff --git a/src/mdg_util.c b/src/mdg_util.c index 3291cc5..501d6c0 100755 --- a/src/mdg_util.c +++ b/src/mdg_util.c @@ -23,7 +23,6 @@ mdg_group_s *mdg_get_group_from_variant(GVariant *va) { char *device_id = NULL; - char *host_addr = NULL; char *group_name = NULL; mdg_group_type_e type = MDG_GROUP_TYPE_LOCAL; GVariantIter *iter = NULL; @@ -42,8 +41,6 @@ mdg_group_s *mdg_get_group_from_variant(GVariant *va) 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, "HostAddr") == 0) - host_addr = (char *)g_variant_get_string(key_value, NULL); else if (g_strcmp0(key, "GroupName") == 0) group_name = (char *)g_variant_get_string(key_value, NULL); else if (g_strcmp0(key, "Type") == 0) @@ -51,7 +48,6 @@ mdg_group_s *mdg_get_group_from_variant(GVariant *va) } group->device_id = g_strdup(device_id); - group->host_addr = g_strdup(host_addr); group->group_name = g_strdup(group_name); group->type = type; @@ -63,10 +59,6 @@ mdg_group_s *mdg_get_group_from_variant(GVariant *va) mdg_device_s *mdg_get_device_from_variant(GVariant *va) { char *device_id = NULL; - char *addr = NULL; - int port; - int secure_port; - int conn_type; char *model_name = NULL; char *device_name = NULL; char *platform_ver = NULL; @@ -90,14 +82,6 @@ mdg_device_s *mdg_get_device_from_variant(GVariant *va) 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, "Addr") == 0) - addr = (char *)g_variant_get_string(key_value, NULL); - else if (g_strcmp0(key, "Port") == 0) - port = g_variant_get_int32(key_value); - else if (g_strcmp0(key, "SecurePort") == 0) - secure_port = g_variant_get_int32(key_value); - else if (g_strcmp0(key, "ConnType") == 0) - conn_type = g_variant_get_int32(key_value); else if (g_strcmp0(key, "ModelName") == 0) model_name = (char *)g_variant_get_string(key_value, NULL); else if (g_strcmp0(key, "DeviceName") == 0) @@ -115,10 +99,6 @@ mdg_device_s *mdg_get_device_from_variant(GVariant *va) } device->device_id = g_strdup(device_id); - device->addr = g_strdup(addr); - device->port = port; - device->secure_port = secure_port; - device->conn_type = conn_type; device->model_name = g_strdup(model_name); device->device_name = g_strdup(device_name); device->platform_ver = g_strdup(platform_ver); @@ -203,6 +183,23 @@ void mdg_get_progress_from_variant(GVariant *va, char **file_path, g_variant_iter_free(iter); } +void mdg_get_receive_file_from_variant(GVariant *va, char **device_id, char **file_path) +{ + 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); + if (g_strcmp0(key, "FilePath") == 0) + *file_path = (char *)g_variant_get_string(key_value, NULL); + } + + g_variant_iter_free(iter); +} + GVariant *mdg_create_variant_device(mdg_device_s *device) { GVariant *va; @@ -213,14 +210,6 @@ GVariant *mdg_create_variant_device(mdg_device_s *device) g_variant_builder_add(builder, "{sv}", "DeviceID", g_variant_new_string(device->device_id)); - g_variant_builder_add(builder, "{sv}", "Port", - g_variant_new_int32(device->port)); - g_variant_builder_add(builder, "{sv}", "Addr", - g_variant_new_string(device->addr)); - g_variant_builder_add(builder, "{sv}", "ConnType", - g_variant_new_int32(device->conn_type)); - g_variant_builder_add(builder, "{sv}", "SecurePort", - g_variant_new_int32(device->secure_port)); g_variant_builder_add(builder, "{sv}", "ModelName", g_variant_new_string(device->model_name)); g_variant_builder_add(builder, "{sv}", "DeviceName", diff --git a/src/mdg_util.h b/src/mdg_util.h index df46e2e..ac64c8e 100755 --- a/src/mdg_util.h +++ b/src/mdg_util.h @@ -31,6 +31,7 @@ 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); +void mdg_get_receive_file_from_variant(GVariant *va, char **device_id, char **file_path); void mdg_get_progress_from_variant(GVariant *va, char **file_path, long *send_size, long *total_size, int *percent); diff --git a/test/common.h b/test/common.h index 01eade4..79f3102 100755 --- a/test/common.h +++ b/test/common.h @@ -19,6 +19,7 @@ #define __COMMON_H__ #include +#include __BEGIN_DECLS diff --git a/test/mdg-manager.c b/test/mdg-manager.c index 9637951..d6d40cb 100755 --- a/test/mdg-manager.c +++ b/test/mdg-manager.c @@ -60,6 +60,11 @@ static const char* __device_type_to_string(mdg_device_type_e type) } } +static void _destroy_mdg_device_info(gpointer data) +{ + mdg_device_info_destroy((mdg_device_h)data); +} + void receive_request_result(char *cmd, char *device_id, unsigned char *arg, int len, int ret, void *user_data) { @@ -160,12 +165,12 @@ static int run_device_eject(MManager *mm, struct menu_data *menu) bool __group_foreach_cb(mdg_device_h device, void *user_data) { - char *addr; char *device_id; - mdg_device_info_get_addr(device, &addr); mdg_device_info_get_device_id(device, &device_id); - msgb("\rDevice is [%s], ADDR [%s]", device_id, addr); + msgb("\rDevice is [%s]", device_id); + + found_invited_device_list = g_list_append(found_invited_device_list, device); return true; } @@ -194,6 +199,11 @@ static int run_group_foreach_device(MManager *mm, struct menu_data *menu) } } + if (found_invited_device_list) { + g_list_free_full(found_device_list, _destroy_mdg_device_info); + found_invited_device_list = NULL; + } + ret = mdg_group_foreach_device(handle, group, __group_foreach_cb, NULL); if (MDG_ERROR_NONE != ret) { msgr("Failed to foreach device: [%s(0x%X)]", mdg_error_to_string(ret), ret); @@ -266,10 +276,6 @@ static int run_device_invite(MManager *mm, struct menu_data *menu) return RET_SUCCESS; } -static void _destroy_mdg_device_info(gpointer data) -{ - mdg_device_info_destroy((mdg_device_h)data); -} static int run_devices_show(MManager *mm, struct menu_data *menu) { @@ -289,33 +295,33 @@ static int run_devices_show(MManager *mm, struct menu_data *menu) } char *model_name; - char *addr; + char *device_id; mdg_device_info_get_model_name(device, &model_name); - mdg_device_info_get_addr(device, &addr); + mdg_device_info_get_device_id(device, &device_id); - msgp("[%d] Model : %s, Addr : %s", i+1, model_name, addr); + msgp("[%d] Model : %s, Device ID : %s", i+1, model_name, device_id); mdg_device_h cloned_device; char *cloned_model_name; - char *cloned_addr; + char *cloned_device_id; mdg_device_info_clone(&cloned_device, device); mdg_device_info_get_model_name(cloned_device, &cloned_model_name); - mdg_device_info_get_addr(cloned_device, &cloned_addr); + mdg_device_info_get_device_id(cloned_device, &cloned_device_id); - msgp("*Cloned* [%d] Model : %s, Addr : %s", i+1, cloned_model_name, cloned_addr); + msgp("*Cloned* [%d] Model : %s, Device ID : %s", i+1, cloned_model_name, cloned_device_id); if (model_name) free(model_name); - if (addr) - free(addr); + if (device_id) + free(device_id); if (cloned_model_name) free(cloned_model_name); - if (cloned_addr) - free(cloned_addr); + if (cloned_device_id) + free(cloned_device_id); mdg_device_info_destroy(cloned_device); @@ -345,17 +351,18 @@ static int run_invited_devices_show(MManager *mm, struct menu_data *menu) } char *model_name; - char *addr; + char *device_id; + + mdg_device_info_get_device_id(device, &device_id); mdg_device_info_get_model_name(device, &model_name); - mdg_device_info_get_addr(device, &addr); - msgp("[%d] Model : %s, Addr : %s", i+1, model_name, addr); + msgp("[%d] Device : %s, Model : %s", i+1, device_id, model_name); if (model_name) free(model_name); - if (addr) - free(addr); + if (device_id) + free(device_id); /* Next item */ iter = g_list_next(iter); @@ -504,7 +511,6 @@ bool _device_found_cb(mdg_device_h device, void *user_data) gboolean is_exist = FALSE; mdg_device_info_get_device_id(device, &device_id); - mdg_device_info_get_addr(device, &addr); mdg_device_info_get_model_name(device, &model_name); mdg_device_info_get_type(device, &device_type); @@ -528,7 +534,7 @@ bool _device_found_cb(mdg_device_h device, void *user_data) if (is_exist == FALSE) { found_device_list = g_list_append(found_device_list, device); - msgp("\r[ID] %s [IP] %s [Type] %s [Name] %s", device_id, addr, + msgp("\r[ID] %s [Type] %s [Name] %s", device_id, __device_type_to_string(device_type), model_name); } @@ -564,6 +570,11 @@ static int run_devices_find(MManager *mm, struct menu_data *menu) return RET_SUCCESS; } +void __receive_file_cb(int result, char *device_id, const char *file_path, void *user_data) +{ + msgb("The %s is stored by %s", file_path, device_id); +} + int run_device_show_local_device(MManager *mm, struct menu_data *menu) { int ret = 0; @@ -580,9 +591,6 @@ int run_device_show_local_device(MManager *mm, struct menu_data *menu) if (ret == 0) { char *device_id = NULL; - char *addr = NULL; - int port; - int secure_port; char *model_name; char *device_name; char *platform_ver; @@ -592,9 +600,6 @@ int run_device_show_local_device(MManager *mm, struct menu_data *menu) mdg_device_type_e type; mdg_device_info_get_device_id(device, &device_id); - mdg_device_info_get_addr(device, &addr); - mdg_device_info_get_port(device, &port); - mdg_device_info_get_secure_port(device, &secure_port); mdg_device_info_get_model_name(device, &model_name); mdg_device_info_get_device_name(device, &device_name); mdg_device_info_get_platform_ver(device, &platform_ver); @@ -604,9 +609,6 @@ int run_device_show_local_device(MManager *mm, struct menu_data *menu) mdg_device_info_get_type(device, &type); msgb("\n[ID] %s", device_id); - msgb("[ADDR] %s", addr); - msgb("[PORT] %d", port); - msgb("[S.PORT] %d", secure_port); msgb("[Model Name] %s", model_name); msgb("[Device Name] %s", device_name); msgb("[Platform Ver.] %s", platform_ver); @@ -617,10 +619,6 @@ int run_device_show_local_device(MManager *mm, struct menu_data *menu) if (device_id) free(device_id); - if (addr) - free(addr); - if (model_name) - free(model_name); if (device_name) free(device_name); if (platform_ver) @@ -634,6 +632,9 @@ int run_device_show_local_device(MManager *mm, struct menu_data *menu) device = NULL; } + + mdg_set_receive_file_cb(handle, __receive_file_cb, NULL); + return RET_SUCCESS; } @@ -655,44 +656,36 @@ static int run_group_show(MManager *mm, struct menu_data *menu) } char *device_id; - char *host_addr; char *name; mdg_group_type_e type; mdg_group_info_get_device_id(group, &device_id); - mdg_group_info_get_host_addr(group, &host_addr); mdg_group_info_get_name(group, &name); mdg_group_info_get_type(group, &type); msgp("[%d] type: %s, name: %s", i+1, mdg_group_type_to_string(type), name); - msgp(" host_addr: %s, device_id: %s\n", host_addr, device_id); + msgp(" device_id: %s\n", device_id); mdg_group_h cloned_group; char *cloned_device_id; - char *cloned_host_addr; char *cloned_name; mdg_group_type_e cloned_type; mdg_group_info_clone(&cloned_group, group); mdg_group_info_get_device_id(cloned_group, &cloned_device_id); - mdg_group_info_get_host_addr(cloned_group, &cloned_host_addr); mdg_group_info_get_name(cloned_group, &cloned_name); mdg_group_info_get_type(cloned_group, &cloned_type); msgp("*Cloned* [%d] type: %s, name: %s", i+1, mdg_group_type_to_string(cloned_type), cloned_name); - msgp(" host_addr: %s, device_id: %s\n", cloned_host_addr, cloned_device_id); + msgp(" device_id: %s\n", cloned_device_id); if (device_id) free(device_id); - if (host_addr) - free(host_addr); if (name) free(name); if (cloned_device_id) free(cloned_device_id); - if (cloned_host_addr) - free(cloned_host_addr); if (cloned_name) free(cloned_name); @@ -801,8 +794,7 @@ static int __send_data(int devidx, int chaidx) } mdg_device_info_get_device_id(device, &deviceid); - mdg_device_info_get_addr(device, &address); - msgp("Sent to [ID] %s [ADDR] %s [CHANNEL ID] %s", deviceid, address, channel->channel_id); + msgp("Sent to [ID] %s [CHANNEL ID] %s", deviceid, channel->channel_id); if (deviceid) { free(deviceid); deviceid = NULL; @@ -855,11 +847,11 @@ void __send_file_progress_cb(const char *file_path, long send_size, } void __send_file_finish_cb(int result, mdg_device_h device, void *user_data) { - char *addr; + char *device_id; - mdg_device_info_get_addr(device, &addr); + mdg_device_info_get_device_id(device, &device_id); - msgp("Send file to %s Finished [%s]", addr, mdg_error_to_string(result)); + msgp("Send file to %s Finished [%s]", device_id, mdg_error_to_string(result)); } static int __send_file(int devidx) @@ -878,8 +870,7 @@ static int __send_file(int devidx) } 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", deviceid); if (deviceid) { free(deviceid); deviceid = NULL; @@ -926,21 +917,16 @@ void _invited_device_finish_cb(int result, void *user_data) bool _invited_device_found_cb(mdg_device_h device, void *user_data) { - char *addr = NULL; char *device_id = NULL; mdg_device_type_e device_type; mdg_device_info_get_device_id(device, &device_id); - mdg_device_info_get_addr(device, &addr); mdg_device_info_get_type(device, &device_type); - msgp("\r[ID] %s [IP] %s [Type] %s", device_id, addr, - __device_type_to_string(device_type)); + msgp("\r[ID] %s [Type] %s", device_id, __device_type_to_string(device_type)); if (device_id) free(device_id); - if (addr) - free(addr); found_invited_device_list = g_list_append(found_invited_device_list, device); -- 2.7.4 From ade4624f4838ab164cfde4a0c2ada13f325122d0 Mon Sep 17 00:00:00 2001 From: "saerome.kim" Date: Wed, 1 Aug 2018 14:44:44 +0900 Subject: [PATCH 15/16] Fixed typo mdg-test app. is using the previous name, So we change the name of mdg-test app. Change-Id: I0b30cc2994b2e9965d8fb08e05757354db019890 Signed-off-by: saerome.kim --- test/main.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) mode change 100755 => 100644 test/main.c diff --git a/test/main.c b/test/main.c old mode 100755 new mode 100644 index b522dcd..477af92 --- a/test/main.c +++ b/test/main.c @@ -99,7 +99,7 @@ static int __init_func(MManager *mm, struct menu_data *menu) } static struct menu_data menu_main[] = { - { "1", "Comp-Manager", menu_mdg_manager, NULL, NULL }, + { "1", "Mdg-Manager", menu_mdg_manager, NULL, NULL }, { NULL, NULL, }, }; @@ -137,7 +137,7 @@ int main(int arg, char **argv) mainloop = g_main_loop_new(NULL, FALSE); msg(""); - msg("* Companion-Manager Test application "); + msg("* Mdg-Manager Test application "); msg("* Build On: %s %s", __DATE__, __TIME__); if (__create_init_menu(init_menu) == FALSE) -- 2.7.4 From 7c64f0dd1b66c2d44652f3ce3e6d279a0315b9b3 Mon Sep 17 00:00:00 2001 From: Jihoon Jung Date: Wed, 8 Aug 2018 19:08:08 +0900 Subject: [PATCH 16/16] Add send response API Signed-off-by: Jihoon Jung Change-Id: I619577c74ea68871f075b9fbe34a966d470d89f6 --- include/mdg.h | 22 ++++++++++-------- include/mdg_internal.h | 4 ++-- src/mdg.c | 60 +++++++++++++++++++++++++++++++++++++++++++++----- src/mdg_dbus.c | 17 ++++++++++---- src/mdg_gdbus.xml | 8 +++++++ src/mdg_private.h | 5 ++++- src/mdg_util.c | 20 ++++++++++------- src/mdg_util.h | 4 ++-- test/mdg-manager.c | 42 ++++++++++++++++++++++++++--------- 9 files changed, 141 insertions(+), 41 deletions(-) diff --git a/include/mdg.h b/include/mdg.h index f92b7fc..205bbfe 100755 --- a/include/mdg.h +++ b/include/mdg.h @@ -738,7 +738,8 @@ typedef void (*mdg_device_find_finish_cb)(int result, void *user_data); * * @see mdg_device_send_data() */ -typedef void (*mdg_device_send_data_finish_cb)(int result, void *user_data); +typedef void (*mdg_device_send_data_finish_cb)(int result, mdg_device_h device, + char *channel_id, int msg_id, unsigned char *data, int len, void *user_data); /** * @brief Gets my local device handle. @@ -759,8 +760,7 @@ typedef void (*mdg_device_send_data_finish_cb)(int result, void *user_data); * @see mdg_device_info_get_my_uuid() * */ -int mdg_device_get_local_device(mdg_h handle, - mdg_device_h *device); +int mdg_device_get_local_device(mdg_h handle, mdg_device_h *device); /** * @brief Finds candidate devices to include my groups in the network. @@ -786,12 +786,16 @@ 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, char *device_id, char *channel_id, - unsigned char *data, int data_length, void *user_data); +typedef void (*mdg_receive_data_cb)(int result, char *device_id, char *channel_id, + int msg_id, unsigned char *data, int len, void *user_data); /* Server Side */ int mdg_device_regist_channel(mdg_h handle, char *channel_id, - mdg_channel_cb channel_cb, void *user_data); + mdg_receive_data_cb receive_data_cb, void *user_data); + +/* In 5 seconds */ +int mdg_device_send_response(mdg_h handle, char *device_id, char *channel_id, + int msg_id, unsigned char *data, int len); int mdg_device_unregist_channel(mdg_h handle, char *channel_id); @@ -823,9 +827,9 @@ int mdg_device_unregist_channel(mdg_h handle, char *channel_id); * @see mdg_request_result_callback() * */ -int mdg_device_send_data(mdg_h handle, mdg_device_h device, char *channel_id, - unsigned char *data, int len, - mdg_device_send_data_finish_cb finish_cb, void *user_data); +int mdg_device_send_data(mdg_h handle, + mdg_device_h device, char *channel_id, unsigned char *data, int len, + mdg_device_send_data_finish_cb finish_cb, void *user_data, int *msg_id); /** * @} diff --git a/include/mdg_internal.h b/include/mdg_internal.h index 52fd474..9eee306 100755 --- a/include/mdg_internal.h +++ b/include/mdg_internal.h @@ -24,8 +24,8 @@ extern "C" { #endif /* File transfer for Client Side */ -typedef void (*mdg_send_file_progress_cb)(const char *file_path, long send_size, - long total_size, int percent, void *user_data); +typedef void (*mdg_send_file_progress_cb)(const char *file_path, long long send_size, + long long total_size, int percent, void *user_data); typedef void (*mdg_send_file_finish_cb)(int result, mdg_device_h device, void *user_data); int mdg_device_send_file(mdg_h handle, mdg_device_h device, char *file_path, diff --git a/src/mdg.c b/src/mdg.c index b84f955..62844c7 100755 --- a/src/mdg.c +++ b/src/mdg.c @@ -173,7 +173,7 @@ EXPORT_API int mdg_device_find(mdg_h handle, int timeout, bool is_invited, /** * Companion Manager CAPI */ -int __add_channel_cb(mdg_manager_s *handle, char *channel_id, mdg_channel_cb channel_cb, void *user_data) +int __add_channel_cb(mdg_manager_s *handle, char *channel_id, mdg_receive_data_cb channel_cb, void *user_data) { channel_cb_s *channel_s; @@ -201,7 +201,7 @@ int __add_channel_cb(mdg_manager_s *handle, char *channel_id, mdg_channel_cb cha } EXPORT_API int mdg_device_regist_channel(mdg_h handle, char *channel_id, - mdg_channel_cb channel_cb, void *user_data) + mdg_receive_data_cb receive_data_cb, void *user_data) { int ret = MDG_ERROR_NONE; GError *error = NULL; @@ -222,13 +222,59 @@ EXPORT_API int mdg_device_regist_channel(mdg_h handle, char *channel_id, } if (ret == MDG_ERROR_NONE) - ret = __add_channel_cb(handle, channel_id, channel_cb, user_data); + ret = __add_channel_cb(handle, channel_id, receive_data_cb, user_data); _END(); return ret; } +EXPORT_API int mdg_device_send_response(mdg_h handle, char *device_id, char *channel_id, + int msg_id, unsigned char *data, int len) +{ + int ret = MDG_ERROR_NONE; + unsigned char *buf = NULL; + GVariantBuilder *bytearray_builder = NULL; + int i; + GVariant *params = NULL; + GError *error = NULL; + + CHECK_FEATURE_SUPPORTED(MDG_FEATURE); + + mdg_manager_s *_handle = handle; + mdg_check_null_ret_error("handle", handle, MDG_ERROR_INVALID_PARAMETER); + CHECK_HANDLE_IS_VALID(handle); + + buf = g_try_malloc0(len + 1); + if (NULL == buf) { + /* LCOV_EXCL_START */ + _ERR("g_malloc0 is failed"); + return MDG_ERROR_OUT_OF_MEMORY; + /* LCOV_EXCL_STOP */ + } + memcpy(buf, data, len); + + bytearray_builder = g_variant_builder_new(G_VARIANT_TYPE("ay")); + for (i = 0; i < len; i++) + g_variant_builder_add(bytearray_builder, "y", buf[i]); + + params = g_variant_new("(iay)", len, bytearray_builder); + g_variant_builder_unref(bytearray_builder); + + group_call_send_response_sync(_handle->group_proxy, device_id, channel_id, msg_id, + params, &ret, NULL, &error); + if (error) { + _ERR("Failed DBus call [%s]", error->message); + g_error_free(error); + ret = MDG_ERROR_IO_ERROR; + } + + g_free(buf); + buf = NULL; + + return ret; +} + EXPORT_API int mdg_device_unregist_channel(mdg_h handle, char *channel_id) { int ret = MDG_ERROR_NONE; @@ -273,7 +319,7 @@ EXPORT_API int mdg_device_unregist_channel(mdg_h handle, char *channel_id) EXPORT_API int mdg_device_send_data(mdg_h handle, mdg_device_h device, char *channel_id, unsigned char *data, int len, - mdg_device_send_data_finish_cb finish_cb, void *user_data) + mdg_device_send_data_finish_cb finish_cb, void *user_data, int *msg_id) { int ret = MDG_ERROR_NONE; unsigned char *buf = NULL; @@ -307,11 +353,15 @@ EXPORT_API int mdg_device_send_data(mdg_h handle, params = g_variant_new("(iay)", len, bytearray_builder); g_variant_builder_unref(bytearray_builder); + mdg_device_h cloned_device = NULL; + mdg_device_info_clone(&cloned_device, device); + _handle->send_data_finish_cb.finish_cb = finish_cb; _handle->send_data_finish_cb.user_data = user_data; + _handle->send_data_finish_cb.device = cloned_device; group_call_send_data_sync(_handle->group_proxy, dev->device_id, - channel_id, params, &ret, NULL, &error); + channel_id, params, &ret, msg_id, 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 8e50fc1..c12d0b5 100755 --- a/src/mdg_dbus.c +++ b/src/mdg_dbus.c @@ -114,8 +114,16 @@ static void __event_cb(Group *object, } case MDG_EVENT_SEND_DATA_FINISH: { + char *device_id; + char *channel_id; + int msg_id; + unsigned char *data = NULL; + int data_len = 0; + + mdg_get_data_from_variant(va, &device_id, &channel_id, &msg_id, &data, &data_len); + mdg_device_s *device = (mdg_device_s *)(handle->send_data_finish_cb.device); if (handle->send_data_finish_cb.finish_cb) { - handle->send_data_finish_cb.finish_cb(ret, + handle->send_data_finish_cb.finish_cb(ret, device, channel_id, msg_id, data, data_len, handle->send_data_finish_cb.user_data); } else { _ERR("The callback not exists"); @@ -140,10 +148,11 @@ static void __event_cb(Group *object, { char *device_id; char *channel_id; + int msg_id; unsigned char *data; int data_len; - mdg_get_data_from_variant(va, &device_id, &channel_id, &data, &data_len); + mdg_get_data_from_variant(va, &device_id, &channel_id, &msg_id, &data, &data_len); channel_cb_s *channel = NULL; @@ -155,14 +164,14 @@ static void __event_cb(Group *object, } if (channel != NULL) - channel->cb(0, device_id, channel_id, data, data_len, channel->user_data); + channel->cb(0, device_id, channel_id, msg_id, data, data_len, channel->user_data); break; } case MDG_EVENT_SEND_FILE_PROGRESS: { if (handle->send_file_cb.progress_cb) { int percent = 0; - long send_size, total_size; + long long send_size, total_size; char *file_path; mdg_get_progress_from_variant(va, &file_path, &send_size, &total_size, &percent); handle->send_file_cb.progress_cb(file_path, send_size, total_size, percent, diff --git a/src/mdg_gdbus.xml b/src/mdg_gdbus.xml index bcb0828..0f72d56 100755 --- a/src/mdg_gdbus.xml +++ b/src/mdg_gdbus.xml @@ -62,6 +62,14 @@ + + + + + + + + diff --git a/src/mdg_private.h b/src/mdg_private.h index 8e8e245..532637f 100755 --- a/src/mdg_private.h +++ b/src/mdg_private.h @@ -115,6 +115,7 @@ typedef struct _device_eject_finish_cb_t { */ typedef struct _send_data_finish_cb_t { mdg_device_send_data_finish_cb finish_cb; /**< User callback to be called */ + mdg_device_h device; void *user_data; /**< User data pointer */ } send_data_finish_cb_t; @@ -203,7 +204,7 @@ typedef struct _mdg_device_s { typedef struct _channel_cb_s { char *channel_id; - mdg_channel_cb cb; + mdg_receive_data_cb cb; void *user_data; } channel_cb_s; @@ -221,6 +222,8 @@ typedef enum { MDG_EVENT_RECEIVE_FILE = 10, MDG_EVENT_SEND_FILE_PROGRESS, MDG_EVENT_SEND_FILE_FINISH, + MDG_EVENT_INVITED, + MDG_EVENT_EJECTED, } mdg_event_type_e; #endif /* __TIZEN_NETWORK_COMMON_MDG_PRIVATE_H__ */ diff --git a/src/mdg_util.c b/src/mdg_util.c index 501d6c0..7f10160 100755 --- a/src/mdg_util.c +++ b/src/mdg_util.c @@ -130,7 +130,7 @@ void mdg_get_channel_from_variant(GVariant *va, char **device_id, char **channel } void mdg_get_data_from_variant(GVariant *va, char **device_id, char **channel_id, - unsigned char **data, int *data_len) + int *msg_id, unsigned char **data, int *data_len) { GVariantIter *iter = NULL; const gchar *key; @@ -145,24 +145,28 @@ void mdg_get_data_from_variant(GVariant *va, char **device_id, char **channel_id *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, "MsgID") == 0) + *msg_id = g_variant_get_int32(key_value); else if (g_strcmp0(key, "Data") == 0) data_va = g_variant_get_variant(key_value); - else if (g_strcmp0(key, "DataLength") == 0) + else if (g_strcmp0(key, "DataLen") == 0) *data_len = g_variant_get_int32(key_value); } - int i = 0; - *data = (unsigned char *)g_try_malloc0(*data_len + 1); + if (*data_len > 0) { + 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_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); } void mdg_get_progress_from_variant(GVariant *va, char **file_path, - long *send_size, long *total_size, int *percent) + long long *send_size, long long *total_size, int *percent) { GVariantIter *iter = NULL; const gchar *key; diff --git a/src/mdg_util.h b/src/mdg_util.h index ac64c8e..bfead55 100755 --- a/src/mdg_util.h +++ b/src/mdg_util.h @@ -30,10 +30,10 @@ 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); + int *msg_id, unsigned char **data, int *data_len); void mdg_get_receive_file_from_variant(GVariant *va, char **device_id, char **file_path); void mdg_get_progress_from_variant(GVariant *va, char **file_path, - long *send_size, long *total_size, int *percent); + long long *send_size, long long *total_size, int *percent); #ifdef __cplusplus } diff --git a/test/mdg-manager.c b/test/mdg-manager.c index d6d40cb..f98df4a 100755 --- a/test/mdg-manager.c +++ b/test/mdg-manager.c @@ -765,9 +765,26 @@ static int run_group_create(MManager *mm, struct menu_data *menu) return RET_SUCCESS; } -void _send_data_finish_cb(int result, void *user_data) +void _send_data_finish2_cb(int result, mdg_device_h device, char *channel_id, int msg_id, + unsigned char *data, int len, void *user_data) { - msgb("\rFind Send Data Finished = %d", result); + msgb("\rmsg id = %d, data = %s, len = %d", msg_id, data, len); + msgb("\rSend Data once more Finished = %d", result); +} + +void _send_data_finish_cb(int result, mdg_device_h device, char *channel_id, int msg_id, + unsigned char *data, int len, void *user_data) +{ + int msg_id2; + + msgb("\rmsg id = %d, channel ID data = %s, len = %d", msg_id, data, len); + msgb("\rSend Data Finished = %d", result); + + msgb("\rSend Data Once more"); + mdg_device_send_data(handle, device, channel_id, (unsigned char *)"Welcome", + 7, _send_data_finish2_cb, NULL, &msg_id2); + + msgp("The message ID is %d", msg_id2); } static int __send_data(int devidx, int chaidx) @@ -804,11 +821,14 @@ static int __send_data(int devidx, int chaidx) address = NULL; } + int msg_id; ret = mdg_device_send_data(handle, device, channel->channel_id, (unsigned char *)message, - strlen(message), _send_data_finish_cb, NULL); + strlen(message), _send_data_finish_cb, NULL, &msg_id); if (MDG_ERROR_NONE != ret) msgr("Failed to Send Data: [ID] %s [IP] %s", deviceid, address); + msgp("The message ID is %d", msg_id); + return ret; } @@ -840,10 +860,10 @@ static int run_send_data(MManager *mm, struct menu_data *menu) return __send_data(devidx, chaidx); } -void __send_file_progress_cb(const char *file_path, long send_size, - long total_size, int percent, void *user_data) +void __send_file_progress_cb(const char *file_path, long long send_size, + long long total_size, int percent, void *user_data) { - msgp("%s %d%% [%ld/%ld]", file_path, percent, send_size, total_size); + msgp("%s %d%% [%lld/%lld]", file_path, percent, send_size, total_size); } void __send_file_finish_cb(int result, mdg_device_h device, void *user_data) { @@ -1186,12 +1206,14 @@ static int run_request_channel_list(MManager *mm, struct menu_data *menu) return RET_SUCCESS; } -void __channel_cb(int result, char *device_id, char *channel_id, +void __channel_cb(int result, char *device_id, char *channel_id, int msg_id, unsigned char *arg, int len, void *user_data) { - 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); + msgb("[%s] channel callback is called by [%s]'s send message", channel_id, device_id); + msgb("The msg_id is %d, arg : %s, len : %d", msg_id, arg, len); + msgb("result is %d", result); + + mdg_device_send_response(handle, device_id, channel_id, msg_id, (unsigned char *)"Ya, Hi", 6); } static int run_regist_channel(MManager *mm, struct menu_data *menu) -- 2.7.4