From: Jihoon Jung Date: Thu, 9 Aug 2018 08:33:20 +0000 (+0900) Subject: Add invited / ejected cb api X-Git-Tag: submit/tizen/20190131.065036~6 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=c37d94c8f71afc6c73c67c812d52f17e3e98a2d5;p=platform%2Fcore%2Fapi%2Fmulti-device-group.git Add invited / ejected cb api Change-Id: Ic01335aea4b08a3aca4056d170810082e2f46196 Signed-off-by: Jihoon Jung --- diff --git a/include/mdg.h b/include/mdg.h index 205bbfe..5f43b12 100755 --- a/include/mdg.h +++ b/include/mdg.h @@ -72,6 +72,11 @@ typedef enum { MDG_ERROR_NOT_PROPER_DEVICE = TIZEN_ERROR_MDG | 0x09, /**< Not proper device */ } mdg_error_e; +typedef enum { + MDG_EVENT_INVITED = 0, + MDG_EVENT_EJECTED, +} mdg_event_type_e; + /** * @addtogroup CAPI_NETWORK_MDG_DEVICE_MODULE * @{ @@ -392,6 +397,14 @@ int mdg_group_invite_device(mdg_h handle, mdg_group_h group, mdg_device_h device, char *PIN, mdg_group_invite_device_finish_cb callback, void *user_data); +typedef void (*mdg_invited_event_cb)(mdg_group_h group, void *user_data); +int mdg_set_invited_event_cb(mdg_h handle, mdg_invited_event_cb event_cb, void *user_data); +int mdg_unset_invited_event_cb(mdg_h handle); + +typedef void (*mdg_ejected_event_cb)(mdg_group_h group, void *user_data); +int mdg_set_ejected_event_cb(mdg_h handle, mdg_ejected_event_cb event_cb, void *user_data); +int mdg_unset_ejected_event_cb(mdg_h handle); + /** * @brief Requests to expel the device from the group which local device owns. * @details This function is used to kick away a remote devices in my local group. diff --git a/src/mdg.c b/src/mdg.c index 62844c7..d2e83d0 100755 --- a/src/mdg.c +++ b/src/mdg.c @@ -1021,3 +1021,63 @@ EXPORT_API int mdg_request_result_callback(mdg_h handle, return ret; } +EXPORT_API int mdg_set_invited_event_cb(mdg_h handle, mdg_invited_event_cb invited_event_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); + + _handle->invited_event_cb.invited_event_cb = invited_event_cb; + _handle->invited_event_cb.user_data = user_data; + + return ret; +} + +EXPORT_API int mdg_unset_invited_event_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); + + _handle->invited_event_cb.invited_event_cb = NULL; + _handle->invited_event_cb.user_data = NULL; + + return ret; +} + +EXPORT_API int mdg_set_ejected_event_cb(mdg_h handle, mdg_ejected_event_cb ejected_event_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); + + _handle->ejected_event_cb.ejected_event_cb = ejected_event_cb; + _handle->ejected_event_cb.user_data = user_data; + + return ret; +} + +EXPORT_API int mdg_unset_ejected_event_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); + + _handle->ejected_event_cb.ejected_event_cb = NULL; + _handle->ejected_event_cb.user_data = NULL; + + return ret; +} + diff --git a/src/mdg_dbus.c b/src/mdg_dbus.c index c12d0b5..556018f 100755 --- a/src/mdg_dbus.c +++ b/src/mdg_dbus.c @@ -202,6 +202,33 @@ static void __event_cb(Group *object, } else { _ERR("The callback not exists"); } + break; + } + case MDG_EVENT_INVITED: + { + mdg_group_s *group = NULL; + + group = mdg_get_group_from_variant(va); + + if (handle->invited_event_cb.invited_event_cb) { + handle->invited_event_cb.invited_event_cb(group, handle->invited_event_cb.user_data); + } else { + _ERR("The callback not exists"); + } + break; + } + case MDG_EVENT_EJECTED: + { + mdg_group_s *group = NULL; + + group = mdg_get_group_from_variant(va); + + if (handle->ejected_event_cb.ejected_event_cb) { + handle->ejected_event_cb.ejected_event_cb(group, handle->ejected_event_cb.user_data); + } else { + _ERR("The callback not exists"); + } + break; } default: _ERR("Unknown Event"); diff --git a/src/mdg_private.h b/src/mdg_private.h index 532637f..5722993 100755 --- a/src/mdg_private.h +++ b/src/mdg_private.h @@ -149,6 +149,16 @@ typedef struct _request_channel_list_finish_cb_t { void *user_data; /**< User data pointer */ } request_channel_list_finish_cb_t; +typedef struct _invited_event_cb_t { + mdg_invited_event_cb invited_event_cb; /**< User callback to be called */ + void *user_data; /**< User data pointer */ +} invited_event_cb_t; + +typedef struct _ejected_event_cb_t { + mdg_ejected_event_cb ejected_event_cb; /**< User callback to be called */ + void *user_data; /**< User data pointer */ +} ejected_event_cb_t; + /** * @brief The mdg-manager context * @since_tizen 5.0 @@ -170,6 +180,8 @@ typedef struct _mdg_manager_s { 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 */ + invited_event_cb_t invited_event_cb; + ejected_event_cb_t ejected_event_cb; } mdg_manager_s; #define CHECK_HANDLE_IS_VALID(handle) { \ @@ -209,7 +221,7 @@ typedef struct _channel_cb_s { } channel_cb_s; typedef enum { - MDG_EVENT_GROUP_FOUND = 0, + MDG_EVENT_GROUP_FOUND = 100, MDG_EVENT_GROUP_FIND_FINISH, MDG_EVENT_DEVICE_FOUND, MDG_EVENT_DEVICE_FIND_FINISH, @@ -219,11 +231,9 @@ typedef enum { MDG_EVENT_SEND_DATA_FINISH, MDG_EVENT_REQ_CHANNEL_LIST_FINISH, MDG_EVENT_RECEIVE_DATA, - MDG_EVENT_RECEIVE_FILE = 10, + MDG_EVENT_RECEIVE_FILE = 110, MDG_EVENT_SEND_FILE_PROGRESS, MDG_EVENT_SEND_FILE_FINISH, - MDG_EVENT_INVITED, - MDG_EVENT_EJECTED, -} mdg_event_type_e; +} mdg_private_event_type_e; #endif /* __TIZEN_NETWORK_COMMON_MDG_PRIVATE_H__ */ diff --git a/test/mdg-manager.c b/test/mdg-manager.c index f98df4a..83f6c75 100755 --- a/test/mdg-manager.c +++ b/test/mdg-manager.c @@ -570,6 +570,28 @@ static int run_devices_find(MManager *mm, struct menu_data *menu) return RET_SUCCESS; } +void __invited_event_cb(mdg_group_h group, void *user_data) +{ + char *device_id; + char *name; + + mdg_group_info_get_device_id(group, &device_id); + mdg_group_info_get_name(group, &name); + + msgb("device is invited by [%s], Group Name [%s]", device_id, name); +} + +void __ejected_event_cb(mdg_group_h group, void *user_data) +{ + char *device_id; + char *name; + + mdg_group_info_get_device_id(group, &device_id); + mdg_group_info_get_name(group, &name); + + msgb("device is ejected by [%s], Group Name [%s]", device_id, name); +} + 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); @@ -632,7 +654,8 @@ int run_device_show_local_device(MManager *mm, struct menu_data *menu) device = NULL; } - + mdg_set_invited_event_cb(handle, __invited_event_cb, NULL); + mdg_set_ejected_event_cb(handle, __ejected_event_cb, NULL); mdg_set_receive_file_cb(handle, __receive_file_cb, NULL); return RET_SUCCESS;