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