From: samsung2013 Date: Thu, 9 Mar 2023 10:05:10 +0000 (+0800) Subject: add APIs to get storage info X-Git-Tag: accepted/tizen/unified/20230313.022908^0 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=refs%2Fchanges%2F42%2F289542%2F1;p=platform%2Fcore%2Fapi%2Fmedia-content.git add APIs to get storage info Change-Id: I1d3e8e87541c9c7efee23fd080b14ca96b3053d3 --- diff --git a/include_product/media_content_product.h b/include_product/media_content_product.h index c3f0b2b..4107636 100755 --- a/include_product/media_content_product.h +++ b/include_product/media_content_product.h @@ -260,7 +260,120 @@ int media_group_foreach_group_and_count_from_db(filter_h filter, media_group_e g */ int media_storage_get_scan_status(const char *storage_uuid, media_storage_scan_status_e *scan_status); +/** + * @brief Iterates through media storage from the media database. + * @details This function gets all media storage handles meeting the given @a filter. + * The @a callback function will be invoked for every retrieved media storage. + * If @c NULL is passed to the @a filter, then no filtering is applied. + * + * @since_tizen @if MOBILE 2.4 @elseif WEARABLE 3.0 @endif + * + * @param[in] filter The handle to the media filter + * @param[in] callback The callback function to be invoked + * @param[in] user_data The user data to be passed to the callback function + * + * @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_OUT_OF_MEMORY Out of memory + * @retval #MEDIA_CONTENT_ERROR_DB_FAILED DB Operation failed + * @retval #MEDIA_CONTENT_ERROR_DB_BUSY DB Operation busy + * + * @pre This function requires opened connection to content service by media_content_connect(). + * @post This function invokes media_storage_destroy(). + * + * @see media_content_connect() + * @see media_storage_destroy() + */ +int media_storage_foreach_storage_from_db(filter_h filter, media_storage_cb callback, void *user_data); + +/** + * @brief Destroys media storage handle. + * @details The function frees all resources related to the media storage handle. This handle + * can no longer be used to perform any operations. New media storage handle has to + * be created before the next usage. + * + * @since_tizen @if MOBILE 2.4 @elseif WEARABLE 3.0 @endif + * + * @param[in] storage The media storage handle + * + * @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 Get copy of media_storage_h handle by calling media_storage_clone(). + * + * @see media_storage_clone() + */ +int media_storage_destroy(media_storage_h storage); +/** + * @brief Clones the media storage handle. + * + * @details This function copies the media storage handle from a source to the destination. + * There is no media_storage_create() function. The media_storage_h is created internally and + * available through media storage foreach function such as media_storage_foreach_storage_from_db(). + * To use this handle outside of these foreach functions, use this function. + * + * @since_tizen @if MOBILE 2.4 @elseif WEARABLE 3.0 @endif + * + * @remarks The @a dst should be released using media_storage_destroy(). + * + * @param[out] dst The destination handle to the media storage + * @param[in] src The source handle to the media storage + * + * @return @c 0 on success, + * otherwise a negative error value + * + * @retval #MEDIA_CONTENT_ERROR_NONE Successful + * @retval #MEDIA_CONTENT_ERROR_OUT_OF_MEMORY Out of memory + * @retval #MEDIA_CONTENT_ERROR_INVALID_PARAMETER Invalid parameter + * + * @see media_storage_destroy() + * @see media_storage_foreach_storage_from_db() + * @see media_storage_get_storage_info_from_db() + */ +int media_storage_clone(media_storage_h *dst, media_storage_h src); + +/** + * @brief Gets the storage id of media storage. + * @since_tizen @if MOBILE 2.4 @elseif WEARABLE 3.0 @endif + * + * @remarks The @a storage_id should be released using free(). + * + * @param[in] storage The media storage handle + * @param[out] storage_id The ID of the media storage + * + * @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_OUT_OF_MEMORY Out of memory + */ +int media_storage_get_id(media_storage_h storage, char **storage_id); + +/** + * @brief Gets the storage path of media storage. + * @since_tizen @if MOBILE 2.4 @elseif WEARABLE 3.0 @endif + * + * @remarks The @a storage_path should be released using free(). + * + * @param[in] storage The media storage handle + * @param[out] storage_path The storage path of the media storage + * + * @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_OUT_OF_MEMORY Out of memory + */ +int media_storage_get_path(media_storage_h storage, char **storage_path); #ifdef __cplusplus } #endif /* __cplusplus */ diff --git a/include_product/media_content_type.h b/include_product/media_content_type.h index 8b1ad04..4d41d1e 100755 --- a/include_product/media_content_type.h +++ b/include_product/media_content_type.h @@ -232,6 +232,20 @@ typedef enum { MEDIA_GROUP_MAX, } media_group_e; +typedef struct { + char *storage_id; + char *storage_path; + int storage_type; +} media_storage_s; + +/** + * @ingroup CAPI_CONTENT_MEDIA_STORAGE_MODULE + * @deprecated Deprecated since 5.0. + * @brief The structure type for the Media storage handle. + * @since_tizen @if MOBILE 2.4 @elseif WEARABLE 3.0 @endif + */ +typedef void *media_storage_h; + /** * @ingroup CAPI_CONTENT_MEDIA_INFO_MODULE * @brief The structure type for the Media info handle. @@ -618,6 +632,27 @@ typedef bool (*media_album_cb)(media_album_h album, void *user_data); typedef bool (*media_group_cb)(const char *group_name, void *user_data); /** + * @ingroup CAPI_CONTENT_MEDIA_STORAGE_MODULE + * @brief Called for every storage in the obtained list of storages. + * @details Iterates over a media storage list. + * + * @since_tizen @if MOBILE 2.4 @elseif WEARABLE 3.0 @endif + * + * @remarks You should not destroy @a storage returned by this function. \n + * The callback is called in the main loop. + * + * @param[in] storage The handle of the media storage + * @param[in] user_data The user data passed from the foreach function + * + * @return @c true to continue with the next iteration of the loop, + * otherwise @c false to break out of the loop + * + * @pre media_storage_foreach_storage_from_db() will invoke this function. + * @see media_storage_foreach_storage_from_db() + */ +typedef bool (*media_storage_cb)(media_storage_h storage, void *user_data); + +/** * @ingroup CAPI_CONTENT_MEDIA_FACE_MODULE * @brief Called for every face in the obtained list of face. * @details Iterates over a media face list. diff --git a/include_product/media_info_private.h b/include_product/media_info_private.h index 6abf6db..36e3cb6 100644 --- a/include_product/media_info_private.h +++ b/include_product/media_info_private.h @@ -714,7 +714,7 @@ void _media_pvr_item_get_detail(sqlite3_stmt* stmt, media_pvr_h pvr); int _media_db_get_pvr_group_item(const char *group_name, filter_h filter, media_group_e group, media_pvr_cb callback, void *user_data); int _media_db_get_uhd(filter_h filter, media_uhd_cb callback, void *user_data); void _media_uhd_item_get_detail(sqlite3_stmt* stmt, media_uhd_h uhd); - +int _media_db_get_storage(filter_h filter, media_storage_cb callback, void *user_data); int _media_filter_build_condition(bool is_full, const char *condition, media_content_collation_e collate_type, char **result); int _media_filter_build_option(filter_h filter, char **result); diff --git a/src/media_db.c b/src/media_db.c index 3f35af0..a1baf37 100755 --- a/src/media_db.c +++ b/src/media_db.c @@ -1655,4 +1655,39 @@ int _media_db_get_uhd(filter_h filter, media_uhd_cb callback, void *user_data) return ret; } + +int _media_db_get_storage(filter_h filter, media_storage_cb callback, void *user_data) +{ + int ret = MEDIA_CONTENT_ERROR_NONE; + char *condition_query = NULL; + char *option_query = NULL; + sqlite3_stmt *stmt = NULL; + + ret = __media_db_make_query(filter, &condition_query, &option_query); + content_retv_if(ret != MEDIA_CONTENT_ERROR_NONE, ret); + + ret = _content_query_prepare(SELECT_STORAGE_LIST, condition_query, option_query, &stmt); + g_free(condition_query); + g_free(option_query); + content_retv_if(ret != MEDIA_CONTENT_ERROR_NONE, ret); + + while (sqlite3_step(stmt) == SQLITE_ROW) { + media_storage_s *_storage = g_new0(media_storage_s, 1); + + _storage->storage_id = g_strdup((const char *)sqlite3_column_text(stmt, 0)); + _storage->storage_path = g_strdup((const char *)sqlite3_column_text(stmt, 1)); + _storage->storage_type = sqlite3_column_int(stmt, 2); + + if (callback((media_storage_h)_storage, user_data) == false) { + media_storage_destroy((media_storage_h) _storage); + break; + } + + media_storage_destroy((media_storage_h) _storage); + } + + SQLITE3_FINALIZE(stmt); + + return ret; +} #endif diff --git a/src/media_storage.c b/src/media_storage.c index adee9f1..f2d18ef 100755 --- a/src/media_storage.c +++ b/src/media_storage.c @@ -36,4 +36,71 @@ int media_storage_get_scan_status(const char *storage_uuid, media_storage_scan_s return ret; } + +int media_storage_foreach_storage_from_db(filter_h filter, media_storage_cb callback, void *user_data) +{ + int ret = MEDIA_CONTENT_ERROR_NONE; + + content_retip_if_fail(callback); + g_mutex_lock(_content_get_db_mutex()); + ret = _media_db_get_storage(filter, callback, user_data); + g_mutex_unlock(_content_get_db_mutex()); + + return ret; +} + +int media_storage_destroy(media_storage_h storage) +{ + media_storage_s *_storage = (media_storage_s*)storage; + + content_retip_if_fail(storage); + + g_free(_storage->storage_id); + g_free(_storage->storage_path); + g_free(_storage); + + return MEDIA_CONTENT_ERROR_NONE; +} + +int media_storage_clone(media_storage_h *dst, media_storage_h src) +{ + media_storage_s *_src = (media_storage_s*)src; + + content_retip_if_fail(dst); + content_retip_if_fail(src); + + media_storage_s *_dst = g_new0(media_storage_s, 1); + + _dst->storage_id = g_strdup(_src->storage_id); + _dst->storage_path = g_strdup(_src->storage_path); + _dst->storage_type = _src->storage_type; + + *dst = (media_storage_h)_dst; + + return MEDIA_CONTENT_ERROR_NONE; +} + +int media_storage_get_id(media_storage_h storage, char **storage_id) +{ + media_storage_s *_storage = (media_storage_s*)storage; + + content_retip_if_fail(storage); + content_retip_if_fail(storage_id); + + *storage_id = g_strdup(_storage->storage_id); + + return MEDIA_CONTENT_ERROR_NONE; +} + +int media_storage_get_path(media_storage_h storage, char **storage_path) +{ + media_storage_s *_storage = (media_storage_s*)storage; + + content_retip_if_fail(storage); + content_retip_if_fail(storage_path); + + *storage_path = g_strdup(_storage->storage_path); + + return MEDIA_CONTENT_ERROR_NONE; +} #endif