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