acb72eb135e94290f19e5bb913160a5e222b28d1
[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_get_result(select_query, &stmt);
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(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);
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_path(media_storage_h storage, char **storage_path)
215 {
216         int ret = MEDIA_CONTENT_ERROR_NONE;
217         media_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;
219
220         if (_storage && storage_path) {
221                 if (STRING_VALID(_storage->storage_path)) {
222                         *storage_path = strdup(_storage->storage_path);
223                         media_content_retvm_if(*storage_path == NULL, MEDIA_CONTENT_ERROR_OUT_OF_MEMORY, "OUT_OF_MEMORY");
224                 } else {
225                         *storage_path = NULL;
226                 }
227
228                 ret = MEDIA_CONTENT_ERROR_NONE;
229         } else {
230                 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
231                 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
232         }
233
234         return ret;
235 }
236
237 int media_storage_get_type(media_storage_h storage, media_content_storage_e *storage_type)
238 {
239         int ret = MEDIA_CONTENT_ERROR_NONE;
240         media_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;
242
243         if (_storage && storage_type) {
244                 *storage_type = _storage->storage_type;
245                 ret = MEDIA_CONTENT_ERROR_NONE;
246         } else {
247                 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
248                 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
249         }
250
251         return ret;
252 }
253
254 #ifdef _USE_TVPD_MODE
255 int media_storage_get_scan_status(const char *storage_uuid, media_storage_scan_status_e *scan_status)
256 {
257         int ret = MEDIA_CONTENT_ERROR_NONE;
258         media_svc_scan_status_type_e status = MEDIA_STORAGE_SCAN_NONE;
259
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                         media_content_error("media_svc_get_storage_scan_status failed");
264                         ret = _content_error_capi(ret);
265                 } else {
266                         *scan_status = status;
267                 }
268         } else {
269                 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
270                 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
271         }
272
273         return ret;
274 }
275 #endif