From: Minje Ahn Date: Fri, 16 Oct 2015 07:21:14 +0000 (+0900) Subject: [ACR-432] Add for db update notification X-Git-Tag: accepted/tizen/mobile/20151030.063322~2 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=refs%2Fchanges%2F39%2F49639%2F16;p=platform%2Fcore%2Fapi%2Fmedia-content.git [ACR-432] Add for db update notification Change-Id: Ie6f9565300486045448dc5518bf40c62894dd19c Signed-off-by: Minje Ahn --- diff --git a/include/media_content.h b/include/media_content.h index fc50944..71fd8c7 100755 --- a/include/media_content.h +++ b/include/media_content.h @@ -170,6 +170,7 @@ int media_content_scan_folder(const char *path, bool is_recursive, media_scan_co int media_content_cancel_scan_folder(const char *path); /** + * @deprecated Deprecated since 3.0. Use media_content_add_db_updated_cb() instead. * @brief Subscribes notifications of the media DB change. * @details This function subscribes notifications of the media DB change which are published by the media server or other apps. * media_content_db_update_cb() function will be called when notification of the media DB change is subscribed. @@ -194,6 +195,7 @@ int media_content_cancel_scan_folder(const char *path); int media_content_set_db_updated_cb(media_content_db_update_cb callback, void *user_data); /** + * @deprecated Deprecated since 3.0. Use media_content_remove_db_updated_cb() instead. * @brief Unsubscribes notifications of the media DB change. * @details This function unsubscribes notifications of the media DB change which are published by the media server or other apps. * @@ -212,6 +214,56 @@ int media_content_set_db_updated_cb(media_content_db_update_cb callback, void *u int media_content_unset_db_updated_cb(void); /** + * @brief Subscribes notifications of the media DB change. + * @details This function subscribes notifications of the media DB change which are published by the media server or other apps. \n + * media_content_db_update_cb() function will be called when notification of the media DB change is subscribed. \n + * Using this API, multiple callback is possible to register in one process. + * + * @since_tizen 3.0 + * + * @remarks To release the registered callback, you must use media_content_remove_db_updated_cb() API. \n + * media_content_unset_db_updated_cb() API can not release the callbacks added by this API. \n + * If you set the same callback that you previously added, this API returns MEDIA_CONTENT_ERROR_INVALID_OPERATION error. \n + * + * @param[in] callback The callback to be invoked when the scanning is finished + * @param[in] user_data The user data to be passed to the callback function + * @param[out] noti_handle The handle to db updated notification + * + * @return @c 0 on success, + * otherwise a negative error value + * + * @retval #MEDIA_CONTENT_ERROR_NONE Successful + * @retval #MEDIA_CONTENT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #MEDIA_CONTENT_ERROR_INVALID_OPERATION Invalid operation + * @retval #MEDIA_CONTENT_ERROR_OUT_OF_MEMORY Out of memory + * + * @see media_content_db_update_cb() + * @see media_content_remove_db_updated_cb() + */ +int media_content_add_db_updated_cb(media_content_db_update_cb callback, void *user_data, media_content_noti_h *noti_handle); + + +/** + * @brief Unsubscribes notifications of the media DB change. + * @details This function unsubscribes notifications of the media DB change which are published by the media server or other apps. + * + * @since_tizen 3.0 + * + * @param[in] noti_handle The handle to db updated notification + * + * @return @c 0 on success, + * otherwise a negative error value + * + * @retval #MEDIA_CONTENT_ERROR_NONE Successful + * @retval #MEDIA_CONTENT_ERROR_INVALID_PARAMETER Invalid parameter + * + * @pre media_content_add_db_updated_cb() + * + * @see media_content_add_db_updated_cb() + */ +int media_content_remove_db_updated_cb(media_content_noti_h noti_handle); + +/** * @} */ diff --git a/include/media_content_internal.h b/include/media_content_internal.h index 50694ba..e675b5c 100755 --- a/include/media_content_internal.h +++ b/include/media_content_internal.h @@ -331,9 +331,6 @@ int media_info_set_storage_id(media_info_h media, const char *storage_id); */ int media_storage_get_scan_status(const char *storage_uuid, media_storage_scan_status_e *scan_status); -/* Handle for dbus notification to use multiple callback */ -typedef void *media_content_noti_h; - /** * @brief Subscribes notifications of the media DB change. * @details This function subscribes notifications of the media DB change which are published by the media server or other apps. diff --git a/include/media_content_type.h b/include/media_content_type.h index 181c88b..a91f2a4 100755 --- a/include/media_content_type.h +++ b/include/media_content_type.h @@ -272,6 +272,13 @@ typedef void *media_storage_h; typedef void *media_face_h; /** + * @ingroup CAPI_CONTENT_MEDIA_CONTENT_MODULE + * @brief The structure type for the Media content noti handle. + * @since_tizen 3.0 + */ +typedef void *media_content_noti_h; + +/** * @ingroup CAPI_MEDIA_CONTENT_MODULE * @brief Called when the media scanning is finished. * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif diff --git a/src/media_content.c b/src/media_content.c index 6c01f62..3533fef 100755 --- a/src/media_content.c +++ b/src/media_content.c @@ -1098,6 +1098,35 @@ int media_content_set_db_updated_cb_v2(media_content_noti_h *noti_handle, media_ return _content_error_capi(MEDIA_REGISTER_TYPE, ret); } +int media_content_add_db_updated_cb(media_content_db_update_cb callback, void *user_data, media_content_noti_h *noti_handle) +{ + int ret = MEDIA_CONTENT_ERROR_NONE; + media_noti_cb_s *noti_info = NULL; + + if (noti_handle == NULL) { + media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER); + return MEDIA_CONTENT_ERROR_INVALID_PARAMETER; + } + + if (callback == NULL) { + media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER); + return MEDIA_CONTENT_ERROR_INVALID_PARAMETER; + } + + noti_info = (media_noti_cb_s *)calloc(1, sizeof(media_noti_cb_s)); + if (noti_info == NULL) { + media_content_error("Failed to create noti info"); + return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY; + } + + noti_info->update_noti_cb = callback; + noti_info->user_data = user_data; + + ret = media_db_update_subscribe_internal((MediaNotiHandle*)noti_handle, _media_content_db_update_noti_cb, (void *)noti_info); + + return _content_error_capi(MEDIA_REGISTER_TYPE, ret); +} + void __media_content_clear_user_data(void *user_data) { media_noti_cb_s *noti_info = user_data; @@ -1115,3 +1144,14 @@ int media_content_unset_db_updated_cb_v2(media_content_noti_h noti_handle) return _content_error_capi(MEDIA_REGISTER_TYPE, ret); } + + +int media_content_remove_db_updated_cb(media_content_noti_h noti_handle) +{ + int ret = MEDIA_CONTENT_ERROR_NONE; + + ret = media_db_update_unsubscribe_internal((MediaNotiHandle)noti_handle, __media_content_clear_user_data); + + return _content_error_capi(MEDIA_REGISTER_TYPE, ret); +} +