0a18606b5960465137ec39cef7a921a2c3674110
[platform/core/api/media-content.git] / src / media_storage.c
1  /*
2  * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved
3  *
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
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
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.
15  */
16
17
18 #include <media_info_private.h>
19
20 int media_storage_get_storage_info_from_db(const char *storage_id, media_storage_h *storage)
21 {
22         int ret = MEDIA_CONTENT_ERROR_NONE;
23         media_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;
27
28         if (!STRING_VALID(storage_id) || (storage == NULL)) {
29                 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
30                 return MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
31         }
32
33         memset(select_query, 0x00, sizeof(select_query));
34         snprintf(select_query, sizeof(select_query), SELECT_STORAGE_INFO_FROM_STORAGE, storage_id);
35
36         ret = _content_query_prepare(&stmt, select_query, NULL, NULL);
37         media_content_retv_if(ret != MEDIA_CONTENT_ERROR_NONE, ret);
38
39         if (sqlite3_step(stmt) == SQLITE_ROW) {
40                 _storage = (media_storage_s*)calloc(1, sizeof(media_storage_s));
41
42                 if (_storage == NULL) {
43                         media_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;
46                 }
47
48                 _storage->storage_id = g_strdup((const char *)sqlite3_column_text(stmt, 0));
49                 _storage->storage_path = g_strdup((const char *)sqlite3_column_text(stmt, 1));
50                 _storage->storage_type = (int)sqlite3_column_int(stmt, 2);
51
52                 *storage = (media_storage_h)_storage;
53         } else {
54                 media_content_error("Nonexistent storage id[%s]", storage_id);
55                 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
56         }
57
58         SQLITE3_FINALIZE(stmt);
59
60         return ret;
61 }
62
63 int media_storage_get_storage_count_from_db(filter_h filter, int *storage_count)
64 {
65         int ret = MEDIA_CONTENT_ERROR_NONE;
66         media_content_warn("DEPRECATION WARNING: media_storage_get_storage_count_from_db() is deprecated and will be removed from next release.");
67
68         if (storage_count) {
69                 ret = _media_db_get_group_count(filter, MEDIA_GROUP_STORAGE, storage_count);
70         } else {
71                 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
72                 return MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
73         }
74
75         return ret;
76 }
77
78 int media_storage_foreach_storage_from_db(filter_h filter, media_storage_cb callback, void *user_data)
79 {
80         int ret = MEDIA_CONTENT_ERROR_NONE;
81         media_content_warn("DEPRECATION WARNING: media_storage_foreach_storage_from_db() is deprecated and will be removed from next release.");
82
83         if (callback != NULL) {
84 #ifdef _USE_TVPD_MODE
85         g_mutex_lock(_content_get_db_mutex());
86 #endif
87
88                 ret = _media_db_get_storage(filter, callback, user_data);
89
90 #ifdef _USE_TVPD_MODE
91         g_mutex_unlock(_content_get_db_mutex());
92 #endif
93         } else {
94                 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
95                 return MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
96         }
97
98         return ret;
99 }
100
101 int media_storage_get_media_count_from_db(const char *storage_id, filter_h filter, int *media_count)
102 {
103         int ret = MEDIA_CONTENT_ERROR_NONE;
104         media_content_warn("DEPRECATION WARNING: media_storage_get_media_count_from_db() is deprecated and will be removed from next release.");
105
106         if (STRING_VALID(storage_id) && media_count) {
107                 ret = _media_db_get_group_item_count(storage_id, filter, MEDIA_GROUP_STORAGE, media_count);
108         } else {
109                 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
110                 return MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
111         }
112
113         return ret;
114 }
115
116 int media_storage_foreach_media_from_db(const char *storage_id, filter_h filter, media_info_cb callback, void *user_data)
117 {
118         int ret = MEDIA_CONTENT_ERROR_NONE;
119         media_content_warn("DEPRECATION WARNING: media_storage_foreach_media_from_db() is deprecated and will be removed from next release.");
120
121         if ((callback != NULL) && STRING_VALID(storage_id)) {
122                 ret = _media_db_get_group_item(storage_id, filter, callback, user_data, MEDIA_GROUP_STORAGE);
123         } else {
124                 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
125                 return MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
126         }
127
128         return ret;
129 }
130
131 int media_storage_destroy(media_storage_h storage)
132 {
133         int ret = MEDIA_CONTENT_ERROR_NONE;
134         media_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;
136         if (_storage) {
137                 SAFE_FREE(_storage->storage_id);
138                 SAFE_FREE(_storage->storage_path);
139                 SAFE_FREE(_storage);
140
141                 ret = MEDIA_CONTENT_ERROR_NONE;
142         } else {
143                 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
144                 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
145         }
146
147         return ret;
148 }
149
150 int media_storage_clone(media_storage_h *dst, media_storage_h src)
151 {
152         int ret = MEDIA_CONTENT_ERROR_NONE;
153         media_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;
155
156         if (_src != NULL) {
157                 media_storage_s *_dst = (media_storage_s*)calloc(1, sizeof(media_storage_s));
158                 media_content_retvm_if(_dst == NULL, MEDIA_CONTENT_ERROR_OUT_OF_MEMORY, "OUT_OF_MEMORY");
159
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                                 media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY);
165                                 return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY;
166                         }
167                 }
168
169                 if (STRING_VALID(_src->storage_path)) {
170                         _dst->storage_path = strdup(_src->storage_path);
171                         if (_dst->storage_path == NULL) {
172                                 media_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;
175                         }
176                 }
177
178                 _dst->storage_type = _src->storage_type;
179
180                 *dst = (media_storage_h)_dst;
181
182                 ret = MEDIA_CONTENT_ERROR_NONE;
183         } else {
184                 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
185                 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
186         }
187
188         return ret;
189 }
190
191 int media_storage_get_id(media_storage_h storage, char **storage_id)
192 {
193         int ret = MEDIA_CONTENT_ERROR_NONE;
194         media_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;
196
197         if (_storage && storage_id) {
198                 if (STRING_VALID(_storage->storage_id)) {
199                         *storage_id = strdup(_storage->storage_id);
200                         media_content_retvm_if(*storage_id == NULL, MEDIA_CONTENT_ERROR_OUT_OF_MEMORY, "OUT_OF_MEMORY");
201                 } else {
202                         *storage_id = NULL;
203                 }
204
205                 ret = MEDIA_CONTENT_ERROR_NONE;
206         } else {
207                 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
208                 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
209         }
210
211         return ret;
212 }
213
214 int media_storage_get_name(media_storage_h storage, char **storage_name)
215 {
216         int ret = MEDIA_CONTENT_ERROR_NONE;
217         media_content_warn("DEPRECATION WARNING: media_storage_get_name() is deprecated and will be removed from next release.");
218         media_storage_s *_storage = (media_storage_s*)storage;
219
220         if (_storage && storage_name) {
221                 *storage_name = NULL;
222         } else {
223                 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
224                 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
225         }
226
227         return ret;
228 }
229
230 int media_storage_get_path(media_storage_h storage, char **storage_path)
231 {
232         int ret = MEDIA_CONTENT_ERROR_NONE;
233         media_content_warn("DEPRECATION WARNING: media_storage_get_path() is deprecated and will be removed from next release.");
234         media_storage_s *_storage = (media_storage_s*)storage;
235
236         if (_storage && storage_path) {
237                 if (STRING_VALID(_storage->storage_path)) {
238                         *storage_path = strdup(_storage->storage_path);
239                         media_content_retvm_if(*storage_path == NULL, MEDIA_CONTENT_ERROR_OUT_OF_MEMORY, "OUT_OF_MEMORY");
240                 } else {
241                         *storage_path = NULL;
242                 }
243
244                 ret = MEDIA_CONTENT_ERROR_NONE;
245         } else {
246                 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
247                 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
248         }
249
250         return ret;
251 }
252
253 int media_storage_get_type(media_storage_h storage, media_content_storage_e *storage_type)
254 {
255         int ret = MEDIA_CONTENT_ERROR_NONE;
256         media_content_warn("DEPRECATION WARNING: media_storage_get_type() is deprecated and will be removed from next release. Use storage_get_type_dev() instead.");
257         media_storage_s *_storage = (media_storage_s*)storage;
258
259         if (_storage && storage_type) {
260                 *storage_type = _storage->storage_type;
261                 ret = MEDIA_CONTENT_ERROR_NONE;
262         } else {
263                 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
264                 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
265         }
266
267         return ret;
268 }
269
270 #ifdef _USE_TVPD_MODE
271 int media_storage_get_scan_status(const char *storage_uuid, media_storage_scan_status_e *scan_status)
272 {
273         int ret = MEDIA_CONTENT_ERROR_NONE;
274         media_svc_scan_status_type_e status = MEDIA_STORAGE_SCAN_NONE;
275
276         if (STRING_VALID(storage_uuid)) {
277                 ret = media_svc_get_storage_scan_status(_content_get_db_handle(), storage_uuid, &status);
278                 if (ret != MS_MEDIA_ERR_NONE) {
279                         media_content_error("media_svc_get_storage_scan_status failed");
280                         ret = _content_error_capi(MEDIA_CONTENT_TYPE, ret);
281                 } else {
282                         *scan_status = status;
283                 }
284         } else {
285                 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
286                 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
287         }
288
289         return ret;
290 }
291 #endif