Remove unused internal API
[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_content.h>
19 #include <media_info_private.h>
20 #include <media_content_internal.h>
21
22 static void __media_storage_get_detail(sqlite3_stmt* stmt, media_storage_h storage)
23 {
24         media_storage_s *_storage = (media_storage_s*)storage;
25
26         _storage->storage_id = g_strdup((const char *)sqlite3_column_text(stmt, 0));
27         _storage->storage_name = g_strdup((const char *)sqlite3_column_text(stmt, 1));
28         _storage->storage_path = g_strdup((const char *)sqlite3_column_text(stmt, 2));
29         _storage->storage_account = g_strdup((const char *)sqlite3_column_text(stmt, 3));
30         _storage->storage_type = (int)sqlite3_column_int(stmt, 4);
31
32         return;
33 }
34
35 int media_storage_get_storage_info_from_db(const char *storage_id, media_storage_h *storage)
36 {
37         int ret = MEDIA_CONTENT_ERROR_NONE;
38         char select_query[DEFAULT_QUERY_SIZE];
39         sqlite3_stmt *stmt = NULL;
40
41         if (!STRING_VALID(storage_id) || (storage == NULL)) {
42                 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
43                 return MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
44         }
45
46         memset(select_query, 0x00, sizeof(select_query));
47         snprintf(select_query, sizeof(select_query), SELECT_STORAGE_INFO_FROM_STORAGE, storage_id);
48
49         ret = _content_query_prepare(&stmt, select_query, NULL, NULL);
50         media_content_retv_if(ret != MEDIA_CONTENT_ERROR_NONE, ret);
51
52         while (sqlite3_step(stmt) == SQLITE_ROW) {
53                 media_storage_s *_storage = (media_storage_s*)calloc(1, sizeof(media_storage_s));
54
55                 if (_storage == NULL) {
56                         media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY);
57                         SQLITE3_FINALIZE(stmt);
58                         return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY;
59                 }
60
61                 __media_storage_get_detail(stmt, (media_storage_h)_storage);
62
63                 *storage = (media_storage_h)_storage;
64         }
65
66         SQLITE3_FINALIZE(stmt);
67
68         return ret;
69 }
70
71 int media_storage_get_storage_count_from_db(filter_h filter, int *storage_count)
72 {
73         int ret = MEDIA_CONTENT_ERROR_NONE;
74
75         if (storage_count) {
76                 ret = _media_db_get_group_count(filter, MEDIA_GROUP_STORAGE, storage_count);
77         } else {
78                 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
79                 return MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
80         }
81
82         return ret;
83 }
84
85 int media_storage_foreach_storage_from_db(filter_h filter, media_storage_cb callback, void *user_data)
86 {
87         int ret = MEDIA_CONTENT_ERROR_NONE;
88
89         if (callback != NULL) {
90                 ret = _media_db_get_storage(filter, callback, user_data);
91         } else {
92                 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
93                 return MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
94         }
95
96         return ret;
97 }
98
99 int media_storage_get_media_count_from_db(const char *storage_id, filter_h filter, int *media_count)
100 {
101         int ret = MEDIA_CONTENT_ERROR_NONE;
102
103         if (STRING_VALID(storage_id) && media_count) {
104                 ret = _media_db_get_group_item_count(storage_id, filter, MEDIA_GROUP_STORAGE, media_count);
105         } else {
106                 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
107                 return MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
108         }
109
110         return ret;
111 }
112
113 int media_storage_foreach_media_from_db(const char *storage_id, filter_h filter, media_info_cb callback, void *user_data)
114 {
115         int ret = MEDIA_CONTENT_ERROR_NONE;
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_storage_s *_storage = (media_storage_s*)storage;
131         if (_storage) {
132                 SAFE_FREE(_storage->storage_id);
133                 SAFE_FREE(_storage->storage_path);
134                 SAFE_FREE(_storage->storage_name);
135                 SAFE_FREE(_storage->storage_account);
136                 SAFE_FREE(_storage);
137
138                 ret = MEDIA_CONTENT_ERROR_NONE;
139         } else {
140                 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
141                 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
142         }
143
144         return ret;
145 }
146
147 int media_storage_clone(media_storage_h *dst, media_storage_h src)
148 {
149         int ret = MEDIA_CONTENT_ERROR_NONE;
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_name)) {
166                         _dst->storage_name = strdup(_src->storage_name);
167                         if (_dst->storage_name == 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                 if (STRING_VALID(_src->storage_path)) {
175                         _dst->storage_path = strdup(_src->storage_path);
176                         if (_dst->storage_path == NULL) {
177                                 media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY);
178                                 media_storage_destroy((media_storage_h)_dst);
179                                 return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY;
180                         }
181                 }
182
183                 if (STRING_VALID(_src->storage_account)) {
184                         _dst->storage_account = strdup(_src->storage_account);
185                         if (_dst->storage_account == NULL) {
186                                 media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY);
187                                 media_storage_destroy((media_storage_h)_dst);
188                                 return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY;
189                         }
190                 }
191
192                 _dst->storage_type = _src->storage_type;
193
194                 *dst = (media_storage_h)_dst;
195
196                 ret = MEDIA_CONTENT_ERROR_NONE;
197         } else {
198                 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
199                 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
200         }
201
202         return ret;
203 }
204
205 int media_storage_get_id(media_storage_h storage, char **storage_id)
206 {
207         int ret = MEDIA_CONTENT_ERROR_NONE;
208         media_storage_s *_storage = (media_storage_s*)storage;
209
210         if (_storage && storage_id) {
211                 if (STRING_VALID(_storage->storage_id)) {
212                         *storage_id = strdup(_storage->storage_id);
213                         media_content_retvm_if(*storage_id == NULL, MEDIA_CONTENT_ERROR_OUT_OF_MEMORY, "OUT_OF_MEMORY");
214                 } else {
215                         *storage_id = NULL;
216                 }
217
218                 ret = MEDIA_CONTENT_ERROR_NONE;
219         } else {
220                 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
221                 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
222         }
223
224         return ret;
225 }
226
227 int media_storage_get_name(media_storage_h storage, char **storage_name)
228 {
229         int ret = MEDIA_CONTENT_ERROR_NONE;
230         media_storage_s *_storage = (media_storage_s*)storage;
231
232         if (_storage && storage_name) {
233                 if (STRING_VALID(_storage->storage_name)) {
234                         *storage_name = strdup(_storage->storage_name);
235                         media_content_retvm_if(*storage_name == NULL, MEDIA_CONTENT_ERROR_OUT_OF_MEMORY, "OUT_OF_MEMORY");
236                 } else {
237                         *storage_name = 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_path(media_storage_h storage, char **storage_path)
250 {
251         int ret = MEDIA_CONTENT_ERROR_NONE;
252         media_storage_s *_storage = (media_storage_s*)storage;
253
254         if (_storage && storage_path) {
255                 if (STRING_VALID(_storage->storage_path)) {
256                         *storage_path = strdup(_storage->storage_path);
257                         media_content_retvm_if(*storage_path == NULL, MEDIA_CONTENT_ERROR_OUT_OF_MEMORY, "OUT_OF_MEMORY");
258                 } else {
259                         *storage_path = NULL;
260                 }
261
262                 ret = MEDIA_CONTENT_ERROR_NONE;
263         } else {
264                 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
265                 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
266         }
267
268         return ret;
269 }
270
271 int media_storage_get_type(media_storage_h storage, media_content_storage_e *storage_type)
272 {
273         int ret = MEDIA_CONTENT_ERROR_NONE;
274         media_storage_s *_storage = (media_storage_s*)storage;
275
276         if (_storage && storage_type) {
277                 *storage_type = _storage->storage_type;
278                 ret = MEDIA_CONTENT_ERROR_NONE;
279         } else {
280                 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
281                 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
282         }
283
284         return ret;
285 }
286
287 #ifdef _USE_TV_PROFILE
288 int media_storage_get_scan_status(const char *storage_uuid, media_storage_scan_status_e *scan_status)
289 {
290         int ret = MEDIA_CONTENT_ERROR_NONE;
291         media_svc_scan_status_type_e status = MEDIA_STORAGE_SCAN_NONE;
292
293         if (STRING_VALID(storage_uuid)) {
294                 ret = media_svc_get_storage_scan_status(_content_get_db_handle(), storage_uuid, &status);
295                 if (ret != MS_MEDIA_ERR_NONE) {
296                         media_content_error("media_svc_get_storage_scan_status failed");
297                         ret = _content_error_capi(MEDIA_CONTENT_TYPE, ret);
298                 } else {
299                         *scan_status = status;
300                 }
301         } else {
302                 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
303                 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
304         }
305
306         return ret;
307 }
308 #endif