From: Saurav Babu Date: Fri, 20 Apr 2018 04:50:34 +0000 (+0530) Subject: capi: Added new CAPI to start/stop device monitor X-Git-Tag: submit/tizen/20190131.065036~38 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=50bb2b652c1256e51333786ea83522d01cbd82e4;p=platform%2Fcore%2Fapi%2Fmulti-device-group.git capi: Added new CAPI to start/stop device monitor Signed-off-by: Saurav Babu --- diff --git a/capi/include/companion.h b/capi/include/companion.h index 00ff83e..9928a85 100644 --- a/capi/include/companion.h +++ b/capi/include/companion.h @@ -68,6 +68,7 @@ typedef enum { COMP_ERROR_ALREADY_IN_PROGRESS = TIZEN_ERROR_COMP | 0x05, /**< Operation now in progress */ COMP_ERROR_ALREADY_INITIALIZED = TIZEN_ERROR_COMP | 0x06, /**< Already initilized */ COMP_ERROR_NO_DATA = TIZEN_ERROR_COMP | 0x07, /**< No Data */ + COMP_ERROR_NOT_STARTED = TIZEN_ERROR_COMP | 0x08, /**< Not Started */ COMP_ERROR_UNKNOWN = -999, } comp_error_e; @@ -856,6 +857,16 @@ typedef enum { } companion_device_type_e; /** + * @brief Device Status. + * + * @since_tizen 5.0 + */ +typedef enum { + COMPANION_DEVICE_ADDED = 0, /**< Device Added */ + COMPANION_DEVICE_REMOVED = 1, /**< Device Removed */ +} companion_device_status_e; + +/** * @brief Called after companion_device_find(). * @details This function can receive a device found. * @@ -916,6 +927,30 @@ typedef void (*companion_device_find_finish_cb)(int result, void *user_data); typedef void (*companion_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 companion_request_result_callback() + * + * @see companion_device_monitor_start() + */ +typedef void (*companion_device_monitor_result_cb)(char *uuid, char *group_name, + companion_device_status_e status, void *user_data); /** * @brief Finds candidate devices to include my groups in the network. @@ -1223,6 +1258,11 @@ int companion_device_information_get_device_type(companion_device_h device, int companion_device_information_get_model_name(companion_device_h device, char **model_name); +int companion_device_monitor_start(companion_h handle, + companion_device_monitor_result_cb cb, void *user_data); + +int companion_device_monitor_stop(companion_h handle); + /** * @} */ diff --git a/capi/src/companion.c b/capi/src/companion.c index f61658e..c72089c 100644 --- a/capi/src/companion.c +++ b/capi/src/companion.c @@ -1117,3 +1117,57 @@ EXPORT_API int companion_request_result_callback(companion_h handle, return ret; } + +EXPORT_API int companion_device_monitor_start(companion_h handle, + companion_device_monitor_result_cb cb, void *user_data) +{ + int ret = COMP_ERROR_NONE; + GError *error = NULL; + + CHECK_FEATURE_SUPPORTED(COMPANION_FEATURE); + + comp_manager_s *_handle = handle; + companion_check_null_ret_error("handle", handle, + COMP_ERROR_INVALID_PARAMETER); + + group_call_start_invited_device_monitor_sync(_handle->group_proxy, 1, &ret, + NULL, &error); + if (ret != COMP_ERROR_NONE) { + _ERR("Failed to start monitor"); + return ret; + } + + _handle->monitor_result_cb.cb = cb; + _handle->monitor_result_cb.user_data = user_data; + + return ret; +} + +EXPORT_API int companion_device_monitor_stop(companion_h handle) +{ + int ret = COMP_ERROR_NONE; + GError *error = NULL; + + CHECK_FEATURE_SUPPORTED(COMPANION_FEATURE); + + comp_manager_s *_handle = handle; + companion_check_null_ret_error("handle", handle, + COMP_ERROR_INVALID_PARAMETER); + + if (_handle->monitor_result_cb.cb == NULL) { + _ERR("Monitor is not started"); + return COMP_ERROR_NOT_STARTED; + } + + group_call_start_invited_device_monitor_sync(_handle->group_proxy, 0, &ret, + NULL, &error); + if (ret != COMP_ERROR_NONE) { + _ERR("Failed to stop monitor"); + return ret; + } + + _handle->monitor_result_cb.cb = NULL; + _handle->monitor_result_cb.user_data = NULL; + + return ret; +} diff --git a/capi/src/companion_gdbus.xml b/capi/src/companion_gdbus.xml index 94e1fa5..cb4be58 100644 --- a/capi/src/companion_gdbus.xml +++ b/capi/src/companion_gdbus.xml @@ -138,6 +138,10 @@ + + + + @@ -178,5 +182,10 @@ + + + + + diff --git a/capi/src/companion_private.h b/capi/src/companion_private.h index 5879841..f6bbfa3 100644 --- a/capi/src/companion_private.h +++ b/capi/src/companion_private.h @@ -144,6 +144,15 @@ 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 { + companion_device_monitor_result_cb cb; /**< User callback to be called */ + void *user_data; /**< User data pointer */ +} monitor_result_cb_t; + +/** * @brief The companion-manager context * @since_tizen 5.0 */ @@ -164,6 +173,7 @@ typedef struct _comp_manager_s { device_eject_result_cb_t device_eject_result_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 */ } comp_manager_s; /**