2 * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
18 #include <media_info_private.h>
20 int media_storage_get_storage_info_from_db(const char *storage_id, media_storage_h *storage)
22 int ret = MEDIA_CONTENT_ERROR_NONE;
23 content_warn("DEPRECATION WARNING: media_storage_get_storage_info_from_db() is deprecated and will be removed from next release.");
24 char select_query[DEFAULT_QUERY_SIZE] = {0, };
25 sqlite3_stmt *stmt = NULL;
26 media_storage_s *_storage = NULL;
28 if (!STRING_VALID(storage_id) || (storage == NULL)) {
29 content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
30 return MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
33 memset(select_query, 0x00, sizeof(select_query));
34 snprintf(select_query, sizeof(select_query), SELECT_STORAGE_INFO_FROM_STORAGE, storage_id);
36 ret = _content_get_result(select_query, &stmt);
37 content_retv_if(ret != MEDIA_CONTENT_ERROR_NONE, ret);
39 if (sqlite3_step(stmt) == SQLITE_ROW) {
40 _storage = (media_storage_s*)calloc(1, sizeof(media_storage_s));
42 if (_storage == NULL) {
43 content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY);
44 SQLITE3_FINALIZE(stmt);
45 return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY;
48 _storage->storage_id = g_strdup(storage_id);
49 _storage->storage_path = g_strdup((const char *)sqlite3_column_text(stmt, 0));
50 _storage->storage_type = (int)sqlite3_column_int(stmt, 1);
52 *storage = (media_storage_h)_storage;
54 content_error("Nonexistent storage id[%s]", storage_id);
55 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
58 SQLITE3_FINALIZE(stmt);
63 int media_storage_get_storage_count_from_db(filter_h filter, int *storage_count)
65 int ret = MEDIA_CONTENT_ERROR_NONE;
66 content_warn("DEPRECATION WARNING: media_storage_get_storage_count_from_db() is deprecated and will be removed from next release.");
69 ret = _media_db_get_group_count(filter, MEDIA_GROUP_STORAGE, storage_count);
71 content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
72 return MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
78 int media_storage_foreach_storage_from_db(filter_h filter, media_storage_cb callback, void *user_data)
80 int ret = MEDIA_CONTENT_ERROR_NONE;
81 content_warn("DEPRECATION WARNING: media_storage_foreach_storage_from_db() is deprecated and will be removed from next release.");
83 if (callback != NULL) {
85 g_mutex_lock(_content_get_db_mutex());
88 ret = _media_db_get_storage(filter, callback, user_data);
91 g_mutex_unlock(_content_get_db_mutex());
94 content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
95 return MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
101 int media_storage_get_media_count_from_db(const char *storage_id, filter_h filter, int *media_count)
103 int ret = MEDIA_CONTENT_ERROR_NONE;
104 content_warn("DEPRECATION WARNING: media_storage_get_media_count_from_db() is deprecated and will be removed from next release.");
106 if (STRING_VALID(storage_id) && media_count) {
107 ret = _media_db_get_group_item_count(storage_id, filter, MEDIA_GROUP_STORAGE, media_count);
109 content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
110 return MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
116 int media_storage_foreach_media_from_db(const char *storage_id, filter_h filter, media_info_cb callback, void *user_data)
118 int ret = MEDIA_CONTENT_ERROR_NONE;
119 content_warn("DEPRECATION WARNING: media_storage_foreach_media_from_db() is deprecated and will be removed from next release.");
121 if ((callback != NULL) && STRING_VALID(storage_id)) {
122 ret = _media_db_get_group_item(storage_id, filter, callback, user_data, MEDIA_GROUP_STORAGE);
124 content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
125 return MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
131 int media_storage_destroy(media_storage_h storage)
133 int ret = MEDIA_CONTENT_ERROR_NONE;
134 content_warn("DEPRECATION WARNING: media_storage_destroy() is deprecated and will be removed from next release.");
135 media_storage_s *_storage = (media_storage_s*)storage;
137 SAFE_FREE(_storage->storage_id);
138 SAFE_FREE(_storage->storage_path);
141 ret = MEDIA_CONTENT_ERROR_NONE;
143 content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
144 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
150 int media_storage_clone(media_storage_h *dst, media_storage_h src)
152 int ret = MEDIA_CONTENT_ERROR_NONE;
153 content_warn("DEPRECATION WARNING: media_storage_clone() is deprecated and will be removed from next release.");
154 media_storage_s *_src = (media_storage_s*)src;
157 media_storage_s *_dst = (media_storage_s*)calloc(1, sizeof(media_storage_s));
158 content_retvm_if(_dst == NULL, MEDIA_CONTENT_ERROR_OUT_OF_MEMORY, "OUT_OF_MEMORY");
160 if (STRING_VALID(_src->storage_id)) {
161 _dst->storage_id = strdup(_src->storage_id);
162 if (_dst->storage_id == NULL) {
163 media_storage_destroy((media_storage_h)_dst);
164 content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY);
165 return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY;
169 if (STRING_VALID(_src->storage_path)) {
170 _dst->storage_path = strdup(_src->storage_path);
171 if (_dst->storage_path == NULL) {
172 content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY);
173 media_storage_destroy((media_storage_h)_dst);
174 return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY;
178 _dst->storage_type = _src->storage_type;
180 *dst = (media_storage_h)_dst;
182 ret = MEDIA_CONTENT_ERROR_NONE;
184 content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
185 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
191 int media_storage_get_id(media_storage_h storage, char **storage_id)
193 int ret = MEDIA_CONTENT_ERROR_NONE;
194 content_warn("DEPRECATION WARNING: media_storage_get_id() is deprecated and will be removed from next release.");
195 media_storage_s *_storage = (media_storage_s*)storage;
197 if (_storage && storage_id) {
198 if (STRING_VALID(_storage->storage_id)) {
199 *storage_id = strdup(_storage->storage_id);
200 content_retvm_if(*storage_id == NULL, MEDIA_CONTENT_ERROR_OUT_OF_MEMORY, "OUT_OF_MEMORY");
205 ret = MEDIA_CONTENT_ERROR_NONE;
207 content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
208 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
214 int media_storage_get_path(media_storage_h storage, char **storage_path)
216 int ret = MEDIA_CONTENT_ERROR_NONE;
217 content_warn("DEPRECATION WARNING: media_storage_get_path() is deprecated and will be removed from next release.");
218 media_storage_s *_storage = (media_storage_s*)storage;
220 if (_storage && storage_path) {
221 if (STRING_VALID(_storage->storage_path)) {
222 *storage_path = strdup(_storage->storage_path);
223 content_retvm_if(*storage_path == NULL, MEDIA_CONTENT_ERROR_OUT_OF_MEMORY, "OUT_OF_MEMORY");
225 *storage_path = NULL;
228 ret = MEDIA_CONTENT_ERROR_NONE;
230 content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
231 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
237 int media_storage_get_type(media_storage_h storage, media_content_storage_e *storage_type)
239 int ret = MEDIA_CONTENT_ERROR_NONE;
240 content_warn("DEPRECATION WARNING: media_storage_get_type() is deprecated and will be removed from next release. Use storage_get_type_dev() instead.");
241 media_storage_s *_storage = (media_storage_s*)storage;
243 if (_storage && storage_type) {
244 *storage_type = _storage->storage_type;
245 ret = MEDIA_CONTENT_ERROR_NONE;
247 content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
248 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
254 #ifdef _USE_TVPD_MODE
255 int media_storage_get_scan_status(const char *storage_uuid, media_storage_scan_status_e *scan_status)
257 int ret = MEDIA_CONTENT_ERROR_NONE;
258 media_svc_scan_status_type_e status = MEDIA_STORAGE_SCAN_NONE;
260 if (STRING_VALID(storage_uuid)) {
261 ret = media_svc_get_storage_scan_status(_content_get_db_handle(), storage_uuid, &status);
262 if (ret != MS_MEDIA_ERR_NONE) {
263 content_error("media_svc_get_storage_scan_status failed");
264 ret = _content_error_capi(ret);
266 *scan_status = status;
269 content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
270 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;