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 static void __media_storage_get_detail(sqlite3_stmt* stmt, media_storage_h storage)
22 media_storage_s *_storage = (media_storage_s*)storage;
24 _storage->storage_id = g_strdup((const char *)sqlite3_column_text(stmt, 0));
25 _storage->storage_name = g_strdup((const char *)sqlite3_column_text(stmt, 1));
26 _storage->storage_path = g_strdup((const char *)sqlite3_column_text(stmt, 2));
27 _storage->storage_account = g_strdup((const char *)sqlite3_column_text(stmt, 3));
28 _storage->storage_type = (int)sqlite3_column_int(stmt, 4);
33 int media_storage_get_storage_info_from_db(const char *storage_id, media_storage_h *storage)
35 int ret = MEDIA_CONTENT_ERROR_NONE;
36 char select_query[DEFAULT_QUERY_SIZE];
37 sqlite3_stmt *stmt = NULL;
39 if (!STRING_VALID(storage_id) || (storage == NULL)) {
40 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
41 return MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
44 memset(select_query, 0x00, sizeof(select_query));
45 snprintf(select_query, sizeof(select_query), SELECT_STORAGE_INFO_FROM_STORAGE, storage_id);
47 ret = _content_query_prepare(&stmt, select_query, NULL, NULL);
48 media_content_retv_if(ret != MEDIA_CONTENT_ERROR_NONE, ret);
50 while (sqlite3_step(stmt) == SQLITE_ROW) {
51 media_storage_s *_storage = (media_storage_s*)calloc(1, sizeof(media_storage_s));
53 if (_storage == NULL) {
54 media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY);
55 SQLITE3_FINALIZE(stmt);
56 return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY;
59 __media_storage_get_detail(stmt, (media_storage_h)_storage);
61 *storage = (media_storage_h)_storage;
64 SQLITE3_FINALIZE(stmt);
69 int media_storage_get_storage_count_from_db(filter_h filter, int *storage_count)
71 int ret = MEDIA_CONTENT_ERROR_NONE;
74 ret = _media_db_get_group_count(filter, MEDIA_GROUP_STORAGE, storage_count);
76 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
77 return MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
83 int media_storage_foreach_storage_from_db(filter_h filter, media_storage_cb callback, void *user_data)
85 int ret = MEDIA_CONTENT_ERROR_NONE;
87 if (callback != NULL) {
88 ret = _media_db_get_storage(filter, callback, user_data);
90 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
91 return MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
97 int media_storage_get_media_count_from_db(const char *storage_id, filter_h filter, int *media_count)
99 int ret = MEDIA_CONTENT_ERROR_NONE;
101 if (STRING_VALID(storage_id) && media_count) {
102 ret = _media_db_get_group_item_count(storage_id, filter, MEDIA_GROUP_STORAGE, media_count);
104 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
105 return MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
111 int media_storage_foreach_media_from_db(const char *storage_id, filter_h filter, media_info_cb callback, void *user_data)
113 int ret = MEDIA_CONTENT_ERROR_NONE;
115 if ((callback != NULL) && STRING_VALID(storage_id)) {
116 ret = _media_db_get_group_item(storage_id, filter, callback, user_data, MEDIA_GROUP_STORAGE);
118 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
119 return MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
125 int media_storage_destroy(media_storage_h storage)
127 int ret = MEDIA_CONTENT_ERROR_NONE;
128 media_storage_s *_storage = (media_storage_s*)storage;
130 SAFE_FREE(_storage->storage_id);
131 SAFE_FREE(_storage->storage_path);
132 SAFE_FREE(_storage->storage_name);
133 SAFE_FREE(_storage->storage_account);
136 ret = MEDIA_CONTENT_ERROR_NONE;
138 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
139 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
145 int media_storage_clone(media_storage_h *dst, media_storage_h src)
147 int ret = MEDIA_CONTENT_ERROR_NONE;
148 media_storage_s *_src = (media_storage_s*)src;
151 media_storage_s *_dst = (media_storage_s*)calloc(1, sizeof(media_storage_s));
152 media_content_retvm_if(_dst == NULL, MEDIA_CONTENT_ERROR_OUT_OF_MEMORY, "OUT_OF_MEMORY");
154 if (STRING_VALID(_src->storage_id)) {
155 _dst->storage_id = strdup(_src->storage_id);
156 if (_dst->storage_id == NULL) {
157 media_storage_destroy((media_storage_h)_dst);
158 media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY);
159 return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY;
163 if (STRING_VALID(_src->storage_name)) {
164 _dst->storage_name = strdup(_src->storage_name);
165 if (_dst->storage_name == NULL) {
166 media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY);
167 media_storage_destroy((media_storage_h)_dst);
168 return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY;
172 if (STRING_VALID(_src->storage_path)) {
173 _dst->storage_path = strdup(_src->storage_path);
174 if (_dst->storage_path == NULL) {
175 media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY);
176 media_storage_destroy((media_storage_h)_dst);
177 return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY;
181 if (STRING_VALID(_src->storage_account)) {
182 _dst->storage_account = strdup(_src->storage_account);
183 if (_dst->storage_account == NULL) {
184 media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY);
185 media_storage_destroy((media_storage_h)_dst);
186 return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY;
190 _dst->storage_type = _src->storage_type;
192 *dst = (media_storage_h)_dst;
194 ret = MEDIA_CONTENT_ERROR_NONE;
196 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
197 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
203 int media_storage_get_id(media_storage_h storage, char **storage_id)
205 int ret = MEDIA_CONTENT_ERROR_NONE;
206 media_storage_s *_storage = (media_storage_s*)storage;
208 if (_storage && storage_id) {
209 if (STRING_VALID(_storage->storage_id)) {
210 *storage_id = strdup(_storage->storage_id);
211 media_content_retvm_if(*storage_id == NULL, MEDIA_CONTENT_ERROR_OUT_OF_MEMORY, "OUT_OF_MEMORY");
216 ret = MEDIA_CONTENT_ERROR_NONE;
218 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
219 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
225 int media_storage_get_name(media_storage_h storage, char **storage_name)
227 int ret = MEDIA_CONTENT_ERROR_NONE;
228 media_storage_s *_storage = (media_storage_s*)storage;
230 if (_storage && storage_name) {
231 if (STRING_VALID(_storage->storage_name)) {
232 *storage_name = strdup(_storage->storage_name);
233 media_content_retvm_if(*storage_name == NULL, MEDIA_CONTENT_ERROR_OUT_OF_MEMORY, "OUT_OF_MEMORY");
235 *storage_name = NULL;
238 ret = MEDIA_CONTENT_ERROR_NONE;
240 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
241 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
247 int media_storage_get_path(media_storage_h storage, char **storage_path)
249 int ret = MEDIA_CONTENT_ERROR_NONE;
250 media_storage_s *_storage = (media_storage_s*)storage;
252 if (_storage && storage_path) {
253 if (STRING_VALID(_storage->storage_path)) {
254 *storage_path = strdup(_storage->storage_path);
255 media_content_retvm_if(*storage_path == NULL, MEDIA_CONTENT_ERROR_OUT_OF_MEMORY, "OUT_OF_MEMORY");
257 *storage_path = NULL;
260 ret = MEDIA_CONTENT_ERROR_NONE;
262 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
263 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
269 int media_storage_get_type(media_storage_h storage, media_content_storage_e *storage_type)
271 int ret = MEDIA_CONTENT_ERROR_NONE;
272 media_storage_s *_storage = (media_storage_s*)storage;
274 if (_storage && storage_type) {
275 *storage_type = _storage->storage_type;
276 ret = MEDIA_CONTENT_ERROR_NONE;
278 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
279 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
285 #ifdef _USE_TV_PROFILE
286 int media_storage_get_scan_status(const char *storage_uuid, media_storage_scan_status_e *scan_status)
288 int ret = MEDIA_CONTENT_ERROR_NONE;
289 media_svc_scan_status_type_e status = MEDIA_STORAGE_SCAN_NONE;
291 if (STRING_VALID(storage_uuid)) {
292 ret = media_svc_get_storage_scan_status(_content_get_db_handle(), storage_uuid, &status);
293 if (ret != MS_MEDIA_ERR_NONE) {
294 media_content_error("media_svc_get_storage_scan_status failed");
295 ret = _content_error_capi(MEDIA_CONTENT_TYPE, ret);
297 *scan_status = status;
300 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
301 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;