2 * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
18 #include <media_content.h>
19 #include <media_info_private.h>
20 #include <media_util_private.h>
21 #include <media_content_internal.h>
23 #include <unicode/uscript.h>
24 #include <unicode/uloc.h>
25 #include <unicode/ucol.h>
26 #include <sys/types.h>
31 static attribute_h g_attr_handle = NULL;
32 static attribute_h g_alias_attr_handle = NULL;
33 static MediaSvcHandle *db_handle = NULL;
34 static int ref_count = 0;
35 static GMutex db_mutex;
37 static __thread media_noti_cb_s *g_noti_info = NULL;
39 static int __media_content_create_attr_handle(void);
40 static int __media_content_create_alias_attr_handle(void);
41 static int __media_content_create_attribute_handle(void);
42 static int __media_content_destroy_attribute_handle(void);
44 static int __media_content_create_attr_handle(void)
46 int ret = MEDIA_CONTENT_ERROR_NONE;
48 ret = _media_filter_attribute_create(&g_attr_handle);
49 media_content_retv_if(ret != MEDIA_CONTENT_ERROR_NONE, ret);
52 ret = _media_filter_attribute_add(g_attr_handle, MEDIA_ID, DB_FIELD_MEDIA_ID);
53 media_content_retv_if(ret != MEDIA_CONTENT_ERROR_NONE, ret);
55 ret = _media_filter_attribute_add(g_attr_handle, MEDIA_PATH, DB_FIELD_MEDIA_PATH);
56 media_content_retv_if(ret != MEDIA_CONTENT_ERROR_NONE, ret);
58 ret = _media_filter_attribute_add(g_attr_handle, MEDIA_DISPLAY_NAME, DB_FIELD_MEDIA_DISPLAY_NAME);
59 media_content_retv_if(ret != MEDIA_CONTENT_ERROR_NONE, ret);
61 ret = _media_filter_attribute_add(g_attr_handle, MEDIA_TYPE, DB_FIELD_MEDIA_TYPE);
62 media_content_retv_if(ret != MEDIA_CONTENT_ERROR_NONE, ret);
64 ret = _media_filter_attribute_add(g_attr_handle, MEDIA_MIME_TYPE, DB_FIELD_MEDIA_MIME_TYPE);
65 media_content_retv_if(ret != MEDIA_CONTENT_ERROR_NONE, ret);
67 ret = _media_filter_attribute_add(g_attr_handle, MEDIA_SIZE, DB_FIELD_MEDIA_SIZE);
68 media_content_retv_if(ret != MEDIA_CONTENT_ERROR_NONE, ret);
70 ret = _media_filter_attribute_add(g_attr_handle, MEDIA_ADDED_TIME, DB_FIELD_MEDIA_ADDED_TIME);
71 media_content_retv_if(ret != MEDIA_CONTENT_ERROR_NONE, ret);
73 ret = _media_filter_attribute_add(g_attr_handle, MEDIA_MODIFIED_TIME, DB_FIELD_MEDIA_MODIFIED_TIME);
74 media_content_retv_if(ret != MEDIA_CONTENT_ERROR_NONE, ret);
76 ret = _media_filter_attribute_add(g_attr_handle, MEDIA_TIMELINE, DB_FIELD_MEDIA_TIMELINE);
77 media_content_retv_if(ret != MEDIA_CONTENT_ERROR_NONE, ret);
79 ret = _media_filter_attribute_add(g_attr_handle, MEDIA_THUMBNAIL_PATH, DB_FIELD_MEDIA_THUMBNAIL_PATH);
80 media_content_retv_if(ret != MEDIA_CONTENT_ERROR_NONE, ret);
82 ret = _media_filter_attribute_add(g_attr_handle, MEDIA_TITLE, DB_FIELD_MEDIA_TITLE);
83 media_content_retv_if(ret != MEDIA_CONTENT_ERROR_NONE, ret);
85 ret = _media_filter_attribute_add(g_attr_handle, MEDIA_ALBUM, DB_FIELD_MEDIA_ALBUM);
86 media_content_retv_if(ret != MEDIA_CONTENT_ERROR_NONE, ret);
88 ret = _media_filter_attribute_add(g_attr_handle, MEDIA_ARTIST, DB_FIELD_MEDIA_ARTIST);
89 media_content_retv_if(ret != MEDIA_CONTENT_ERROR_NONE, ret);
91 ret = _media_filter_attribute_add(g_attr_handle, MEDIA_ALBUM_ARTIST, DB_FIELD_MEDIA_ALBUM_ARTIST);
92 media_content_retv_if(ret != MEDIA_CONTENT_ERROR_NONE, ret);
94 ret = _media_filter_attribute_add(g_attr_handle, MEDIA_GENRE, DB_FIELD_MEDIA_GENRE);
95 media_content_retv_if(ret != MEDIA_CONTENT_ERROR_NONE, ret);
97 ret = _media_filter_attribute_add(g_attr_handle, MEDIA_COMPOSER, DB_FIELD_MEDIA_COMPOSER);
98 media_content_retv_if(ret != MEDIA_CONTENT_ERROR_NONE, ret);
100 ret = _media_filter_attribute_add(g_attr_handle, MEDIA_YEAR, DB_FIELD_MEDIA_YEAR);
101 media_content_retv_if(ret != MEDIA_CONTENT_ERROR_NONE, ret);
103 ret = _media_filter_attribute_add(g_attr_handle, MEDIA_RECORDED_DATE, DB_FIELD_MEDIA_RECORDED_DATE);
104 media_content_retv_if(ret != MEDIA_CONTENT_ERROR_NONE, ret);
106 ret = _media_filter_attribute_add(g_attr_handle, MEDIA_COPYRIGHT, DB_FIELD_MEDIA_COPYRIGHT);
107 media_content_retv_if(ret != MEDIA_CONTENT_ERROR_NONE, ret);
109 ret = _media_filter_attribute_add(g_attr_handle, MEDIA_TRACK_NUM, DB_FIELD_MEDIA_TRACK_NUM);
110 media_content_retv_if(ret != MEDIA_CONTENT_ERROR_NONE, ret);
112 ret = _media_filter_attribute_add(g_attr_handle, MEDIA_DESCRIPTION, DB_FIELD_MEDIA_DESCRIPTION);
113 media_content_retv_if(ret != MEDIA_CONTENT_ERROR_NONE, ret);
115 ret = _media_filter_attribute_add(g_attr_handle, MEDIA_BITRATE, DB_FIELD_MEDIA_BITRATE);
116 media_content_retv_if(ret != MEDIA_CONTENT_ERROR_NONE, ret);
118 ret = _media_filter_attribute_add(g_attr_handle, MEDIA_BITPERSAMPLE, DB_FIELD_MEDIA_BITPERSAMPLE);
119 media_content_retv_if(ret != MEDIA_CONTENT_ERROR_NONE, ret);
121 ret = _media_filter_attribute_add(g_attr_handle, MEDIA_SAMPLERATE, DB_FIELD_MEDIA_SAMPLERATE);
122 media_content_retv_if(ret != MEDIA_CONTENT_ERROR_NONE, ret);
124 ret = _media_filter_attribute_add(g_attr_handle, MEDIA_CHANNEL, DB_FIELD_MEDIA_CHANNEL);
125 media_content_retv_if(ret != MEDIA_CONTENT_ERROR_NONE, ret);
127 ret = _media_filter_attribute_add(g_attr_handle, MEDIA_DURATION, DB_FIELD_MEDIA_DURATION);
128 media_content_retv_if(ret != MEDIA_CONTENT_ERROR_NONE, ret);
130 ret = _media_filter_attribute_add(g_attr_handle, MEDIA_LONGITUDE, DB_FIELD_MEDIA_LONGITUDE);
131 media_content_retv_if(ret != MEDIA_CONTENT_ERROR_NONE, ret);
133 ret = _media_filter_attribute_add(g_attr_handle, MEDIA_LATITUDE, DB_FIELD_MEDIA_LATITUDE);
134 media_content_retv_if(ret != MEDIA_CONTENT_ERROR_NONE, ret);
136 ret = _media_filter_attribute_add(g_attr_handle, MEDIA_ALTITUDE, DB_FIELD_MEDIA_ALTITUDE);
137 media_content_retv_if(ret != MEDIA_CONTENT_ERROR_NONE, ret);
139 ret = _media_filter_attribute_add(g_attr_handle, MEDIA_WIDTH, DB_FIELD_MEDIA_WIDTH);
140 media_content_retv_if(ret != MEDIA_CONTENT_ERROR_NONE, ret);
142 ret = _media_filter_attribute_add(g_attr_handle, MEDIA_HEIGHT, DB_FIELD_MEDIA_HEIGHT);
143 media_content_retv_if(ret != MEDIA_CONTENT_ERROR_NONE, ret);
145 ret = _media_filter_attribute_add(g_attr_handle, MEDIA_DATETAKEN, DB_FIELD_MEDIA_DATETAKEN);
146 media_content_retv_if(ret != MEDIA_CONTENT_ERROR_NONE, ret);
148 ret = _media_filter_attribute_add(g_attr_handle, MEDIA_ORIENTATION, DB_FIELD_MEDIA_ORIENTATION);
149 media_content_retv_if(ret != MEDIA_CONTENT_ERROR_NONE, ret);
151 ret = _media_filter_attribute_add(g_attr_handle, MEDIA_BURST_ID, DB_FIELD_MEDIA_BURST_ID);
152 media_content_retv_if(ret != MEDIA_CONTENT_ERROR_NONE, ret);
154 ret = _media_filter_attribute_add(g_attr_handle, MEDIA_PLAYED_COUNT, DB_FIELD_MEDIA_PLAYED_COUNT);
155 media_content_retv_if(ret != MEDIA_CONTENT_ERROR_NONE, ret);
157 ret = _media_filter_attribute_add(g_attr_handle, MEDIA_LAST_PLAYED_TIME, DB_FIELD_MEDIA_LAST_PLAYED_TIME);
158 media_content_retv_if(ret != MEDIA_CONTENT_ERROR_NONE, ret);
160 ret = _media_filter_attribute_add(g_attr_handle, MEDIA_LAST_PLAYED_POSITION, DB_FIELD_MEDIA_LAST_PLAYED_POSITION);
161 media_content_retv_if(ret != MEDIA_CONTENT_ERROR_NONE, ret);
163 ret = _media_filter_attribute_add(g_attr_handle, MEDIA_RATING, DB_FIELD_MEDIA_RATING);
164 media_content_retv_if(ret != MEDIA_CONTENT_ERROR_NONE, ret);
166 ret = _media_filter_attribute_add(g_attr_handle, MEDIA_FAVOURITE, DB_FIELD_MEDIA_FAVOURITE);
167 media_content_retv_if(ret != MEDIA_CONTENT_ERROR_NONE, ret);
169 ret = _media_filter_attribute_add(g_attr_handle, MEDIA_AUTHOR, DB_FIELD_MEDIA_AUTHOR);
170 media_content_retv_if(ret != MEDIA_CONTENT_ERROR_NONE, ret);
172 ret = _media_filter_attribute_add(g_attr_handle, MEDIA_PROVIDER, DB_FIELD_MEDIA_PROVIDER);
173 media_content_retv_if(ret != MEDIA_CONTENT_ERROR_NONE, ret);
175 ret = _media_filter_attribute_add(g_attr_handle, MEDIA_CONTENT_NAME, DB_FIELD_MEDIA_CONTENT_NAME);
176 media_content_retv_if(ret != MEDIA_CONTENT_ERROR_NONE, ret);
178 ret = _media_filter_attribute_add(g_attr_handle, MEDIA_CATEGORY, DB_FIELD_MEDIA_CATEGORY);
179 media_content_retv_if(ret != MEDIA_CONTENT_ERROR_NONE, ret);
181 ret = _media_filter_attribute_add(g_attr_handle, MEDIA_LOCATION_TAG, DB_FIELD_MEDIA_LOCATION_TAG);
182 media_content_retv_if(ret != MEDIA_CONTENT_ERROR_NONE, ret);
184 ret = _media_filter_attribute_add(g_attr_handle, MEDIA_AGE_RATING, DB_FIELD_MEDIA_AGE_RATING);
185 media_content_retv_if(ret != MEDIA_CONTENT_ERROR_NONE, ret);
187 ret = _media_filter_attribute_add(g_attr_handle, MEDIA_KEYWORD, DB_FIELD_MEDIA_KEYWORD);
188 media_content_retv_if(ret != MEDIA_CONTENT_ERROR_NONE, ret);
190 ret = _media_filter_attribute_add(g_attr_handle, MEDIA_WEATHER, DB_FIELD_MEDIA_WEATHER);
191 media_content_retv_if(ret != MEDIA_CONTENT_ERROR_NONE, ret);
193 ret = _media_filter_attribute_add(g_attr_handle, MEDIA_IS_DRM, DB_FIELD_MEDIA_IS_DRM);
194 media_content_retv_if(ret != MEDIA_CONTENT_ERROR_NONE, ret);
196 ret = _media_filter_attribute_add(g_attr_handle, MEDIA_STORAGE_TYPE, DB_FIELD_MEDIA_STORAGE_TYPE);
197 media_content_retv_if(ret != MEDIA_CONTENT_ERROR_NONE, ret);
200 ret = _media_filter_attribute_add(g_attr_handle, MEDIA_FILE_NAME_PINYIN, DB_FIELD_MEDIA_FILE_NAME_PINYIN);
201 media_content_retv_if(ret != MEDIA_CONTENT_ERROR_NONE, ret);
203 ret = _media_filter_attribute_add(g_attr_handle, MEDIA_TITLE_PINYIN, DB_FIELD_MEDIA_TITLE_PINYIN);
204 media_content_retv_if(ret != MEDIA_CONTENT_ERROR_NONE, ret);
206 ret = _media_filter_attribute_add(g_attr_handle, MEDIA_ALBUM_PINYIN, DB_FIELD_MEDIA_ALBUM_PINYIN);
207 media_content_retv_if(ret != MEDIA_CONTENT_ERROR_NONE, ret);
209 ret = _media_filter_attribute_add(g_attr_handle, MEDIA_ARTIST_PINYIN, DB_FIELD_MEDIA_ARTIST_PINYIN);
210 media_content_retv_if(ret != MEDIA_CONTENT_ERROR_NONE, ret);
212 ret = _media_filter_attribute_add(g_attr_handle, MEDIA_ALBUM_ARTIST_PINYIN, DB_FIELD_MEDIA_ALBUM_ARTIST_PINYIN);
213 media_content_retv_if(ret != MEDIA_CONTENT_ERROR_NONE, ret);
215 ret = _media_filter_attribute_add(g_attr_handle, MEDIA_GENRE_PINYIN, DB_FIELD_MEDIA_GENRE_PINYIN);
216 media_content_retv_if(ret != MEDIA_CONTENT_ERROR_NONE, ret);
218 ret = _media_filter_attribute_add(g_attr_handle, MEDIA_COMPOSER_PINYIN, DB_FIELD_MEDIA_COMPOSER_PINYIN);
219 media_content_retv_if(ret != MEDIA_CONTENT_ERROR_NONE, ret);
221 ret = _media_filter_attribute_add(g_attr_handle, MEDIA_COPYRIGHT_PINYIN, DB_FIELD_MEDIA_COPYRIGHT_PINYIN);
222 media_content_retv_if(ret != MEDIA_CONTENT_ERROR_NONE, ret);
224 ret = _media_filter_attribute_add(g_attr_handle, MEDIA_DESCRIPTION_PINYIN, DB_FIELD_MEDIA_DESCRIPTION_PINYIN);
225 media_content_retv_if(ret != MEDIA_CONTENT_ERROR_NONE, ret);
227 ret = _media_filter_attribute_add(g_attr_handle, MEDIA_AUTHOR_PINYIN, DB_FIELD_MEDIA_AUTHOR_PINYIN);
228 media_content_retv_if(ret != MEDIA_CONTENT_ERROR_NONE, ret);
230 ret = _media_filter_attribute_add(g_attr_handle, MEDIA_PROVIDER_PINYIN, DB_FIELD_MEDIA_PROVIDER_PINYIN);
231 media_content_retv_if(ret != MEDIA_CONTENT_ERROR_NONE, ret);
233 ret = _media_filter_attribute_add(g_attr_handle, MEDIA_CONTENT_NAME_PINYIN, DB_FIELD_MEDIA_CONTENT_NAME_PINYIN);
234 media_content_retv_if(ret != MEDIA_CONTENT_ERROR_NONE, ret);
236 ret = _media_filter_attribute_add(g_attr_handle, MEDIA_CATEGORY_PINYIN, DB_FIELD_MEDIA_CATEGORY_PINYIN);
237 media_content_retv_if(ret != MEDIA_CONTENT_ERROR_NONE, ret);
239 ret = _media_filter_attribute_add(g_attr_handle, MEDIA_LOCATION_TAG_PINYIN, DB_FIELD_MEDIA_LOCATION_TAG_PINYIN);
240 media_content_retv_if(ret != MEDIA_CONTENT_ERROR_NONE, ret);
242 ret = _media_filter_attribute_add(g_attr_handle, MEDIA_AGE_RATING_PINYIN, DB_FIELD_MEDIA_AGE_RATING_PINYIN);
243 media_content_retv_if(ret != MEDIA_CONTENT_ERROR_NONE, ret);
245 ret = _media_filter_attribute_add(g_attr_handle, MEDIA_KEYWORD_PINYIN, DB_FIELD_MEDIA_KEYWORD_PINYIN);
246 media_content_retv_if(ret != MEDIA_CONTENT_ERROR_NONE, ret);
249 ret = _media_filter_attribute_add(g_attr_handle, PLAYLIST_NAME, DB_FIELD_PLAYLIST_NAME);
250 media_content_retv_if(ret != MEDIA_CONTENT_ERROR_NONE, ret);
252 ret = _media_filter_attribute_add(g_attr_handle, PLAYLIST_MEMBER_ORDER, DB_FIELD_PLAYLIST_MEMBER_ORDER);
253 media_content_retv_if(ret != MEDIA_CONTENT_ERROR_NONE, ret);
256 ret = _media_filter_attribute_add(g_attr_handle, PLAYLIST_MEDIA_COUNT, DB_FIELD_PLAYLIST_MEDIA_COUNT);
257 media_content_retv_if(ret != MEDIA_CONTENT_ERROR_NONE, ret);
260 ret = _media_filter_attribute_add(g_attr_handle, TAG_NAME, DB_FIELD_TAG_NAME);
261 media_content_retv_if(ret != MEDIA_CONTENT_ERROR_NONE, ret);
264 ret = _media_filter_attribute_add(g_attr_handle, TAG_MEDIA_COUNT, DB_FIELD_TAG_MEDIA_COUNT);
265 media_content_retv_if(ret != MEDIA_CONTENT_ERROR_NONE, ret);
268 ret = _media_filter_attribute_add(g_attr_handle, BOOKMARK_MARKED_TIME, DB_FIELD_BOOKMARK_MARKED_TIME);
269 media_content_retv_if(ret != MEDIA_CONTENT_ERROR_NONE, ret);
272 ret = _media_filter_attribute_add(g_attr_handle, MEDIA_STORAGE_ID, DB_FIELD_STORAGE_ID);
273 media_content_retv_if(ret != MEDIA_CONTENT_ERROR_NONE, ret);
275 ret = _media_filter_attribute_add(g_attr_handle, MEDIA_STORAGE_PATH, DB_FIELD_STORAGE_PATH);
276 media_content_retv_if(ret != MEDIA_CONTENT_ERROR_NONE, ret);
279 ret = _media_filter_attribute_add(g_attr_handle, MEDIA_FACE_TAG, DB_FIELD_FACE_TAG);
280 media_content_retv_if(ret != MEDIA_CONTENT_ERROR_NONE, ret);
285 static int __media_content_create_alias_attr_handle(void)
287 int ret = MEDIA_CONTENT_ERROR_NONE;
289 ret = _media_filter_attribute_create(&g_alias_attr_handle);
290 media_content_retv_if(ret != MEDIA_CONTENT_ERROR_NONE, ret);
293 ret = _media_filter_attribute_add(g_alias_attr_handle, MEDIA_ID, DB_TABLE_ALIAS_MEDIA"."DB_FIELD_MEDIA_ID);
294 media_content_retv_if(ret != MEDIA_CONTENT_ERROR_NONE, ret);
296 ret = _media_filter_attribute_add(g_alias_attr_handle, MEDIA_PATH, DB_TABLE_ALIAS_MEDIA"."DB_FIELD_MEDIA_PATH);
297 media_content_retv_if(ret != MEDIA_CONTENT_ERROR_NONE, ret);
299 ret = _media_filter_attribute_add(g_alias_attr_handle, MEDIA_DISPLAY_NAME, DB_TABLE_ALIAS_MEDIA"."DB_FIELD_MEDIA_DISPLAY_NAME);
300 media_content_retv_if(ret != MEDIA_CONTENT_ERROR_NONE, ret);
302 ret = _media_filter_attribute_add(g_alias_attr_handle, MEDIA_TYPE, DB_TABLE_ALIAS_MEDIA"."DB_FIELD_MEDIA_TYPE);
303 media_content_retv_if(ret != MEDIA_CONTENT_ERROR_NONE, ret);
305 ret = _media_filter_attribute_add(g_alias_attr_handle, MEDIA_MIME_TYPE, DB_TABLE_ALIAS_MEDIA"."DB_FIELD_MEDIA_MIME_TYPE);
306 media_content_retv_if(ret != MEDIA_CONTENT_ERROR_NONE, ret);
308 ret = _media_filter_attribute_add(g_alias_attr_handle, MEDIA_SIZE, DB_TABLE_ALIAS_MEDIA"."DB_FIELD_MEDIA_SIZE);
309 media_content_retv_if(ret != MEDIA_CONTENT_ERROR_NONE, ret);
311 ret = _media_filter_attribute_add(g_alias_attr_handle, MEDIA_ADDED_TIME, DB_TABLE_ALIAS_MEDIA"."DB_FIELD_MEDIA_ADDED_TIME);
312 media_content_retv_if(ret != MEDIA_CONTENT_ERROR_NONE, ret);
314 ret = _media_filter_attribute_add(g_alias_attr_handle, MEDIA_MODIFIED_TIME, DB_TABLE_ALIAS_MEDIA"."DB_FIELD_MEDIA_MODIFIED_TIME);
315 media_content_retv_if(ret != MEDIA_CONTENT_ERROR_NONE, ret);
317 ret = _media_filter_attribute_add(g_alias_attr_handle, MEDIA_TIMELINE, DB_TABLE_ALIAS_MEDIA"."DB_FIELD_MEDIA_TIMELINE);
318 media_content_retv_if(ret != MEDIA_CONTENT_ERROR_NONE, ret);
320 ret = _media_filter_attribute_add(g_alias_attr_handle, MEDIA_THUMBNAIL_PATH, DB_TABLE_ALIAS_MEDIA"."DB_FIELD_MEDIA_THUMBNAIL_PATH);
321 media_content_retv_if(ret != MEDIA_CONTENT_ERROR_NONE, ret);
323 ret = _media_filter_attribute_add(g_alias_attr_handle, MEDIA_TITLE, DB_TABLE_ALIAS_MEDIA"."DB_FIELD_MEDIA_TITLE);
324 media_content_retv_if(ret != MEDIA_CONTENT_ERROR_NONE, ret);
326 ret = _media_filter_attribute_add(g_alias_attr_handle, MEDIA_ALBUM, DB_TABLE_ALIAS_MEDIA"."DB_FIELD_MEDIA_ALBUM);
327 media_content_retv_if(ret != MEDIA_CONTENT_ERROR_NONE, ret);
329 ret = _media_filter_attribute_add(g_alias_attr_handle, MEDIA_ARTIST, DB_TABLE_ALIAS_MEDIA"."DB_FIELD_MEDIA_ARTIST);
330 media_content_retv_if(ret != MEDIA_CONTENT_ERROR_NONE, ret);
332 ret = _media_filter_attribute_add(g_alias_attr_handle, MEDIA_ALBUM_ARTIST, DB_TABLE_ALIAS_MEDIA"."DB_FIELD_MEDIA_ALBUM_ARTIST);
333 media_content_retv_if(ret != MEDIA_CONTENT_ERROR_NONE, ret);
335 ret = _media_filter_attribute_add(g_alias_attr_handle, MEDIA_GENRE, DB_TABLE_ALIAS_MEDIA"."DB_FIELD_MEDIA_GENRE);
336 media_content_retv_if(ret != MEDIA_CONTENT_ERROR_NONE, ret);
338 ret = _media_filter_attribute_add(g_alias_attr_handle, MEDIA_COMPOSER, DB_TABLE_ALIAS_MEDIA"."DB_FIELD_MEDIA_COMPOSER);
339 media_content_retv_if(ret != MEDIA_CONTENT_ERROR_NONE, ret);
341 ret = _media_filter_attribute_add(g_alias_attr_handle, MEDIA_YEAR, DB_TABLE_ALIAS_MEDIA"."DB_FIELD_MEDIA_YEAR);
342 media_content_retv_if(ret != MEDIA_CONTENT_ERROR_NONE, ret);
344 ret = _media_filter_attribute_add(g_alias_attr_handle, MEDIA_RECORDED_DATE, DB_TABLE_ALIAS_MEDIA"."DB_FIELD_MEDIA_RECORDED_DATE);
345 media_content_retv_if(ret != MEDIA_CONTENT_ERROR_NONE, ret);
347 ret = _media_filter_attribute_add(g_alias_attr_handle, MEDIA_COPYRIGHT, DB_TABLE_ALIAS_MEDIA"."DB_FIELD_MEDIA_COPYRIGHT);
348 media_content_retv_if(ret != MEDIA_CONTENT_ERROR_NONE, ret);
350 ret = _media_filter_attribute_add(g_alias_attr_handle, MEDIA_TRACK_NUM, DB_TABLE_ALIAS_MEDIA"."DB_FIELD_MEDIA_TRACK_NUM);
351 media_content_retv_if(ret != MEDIA_CONTENT_ERROR_NONE, ret);
353 ret = _media_filter_attribute_add(g_alias_attr_handle, MEDIA_DESCRIPTION, DB_TABLE_ALIAS_MEDIA"."DB_FIELD_MEDIA_DESCRIPTION);
354 media_content_retv_if(ret != MEDIA_CONTENT_ERROR_NONE, ret);
356 ret = _media_filter_attribute_add(g_alias_attr_handle, MEDIA_BITRATE, DB_TABLE_ALIAS_MEDIA"."DB_FIELD_MEDIA_BITRATE);
357 media_content_retv_if(ret != MEDIA_CONTENT_ERROR_NONE, ret);
359 ret = _media_filter_attribute_add(g_alias_attr_handle, MEDIA_BITPERSAMPLE, DB_TABLE_ALIAS_MEDIA"."DB_FIELD_MEDIA_BITPERSAMPLE);
360 media_content_retv_if(ret != MEDIA_CONTENT_ERROR_NONE, ret);
362 ret = _media_filter_attribute_add(g_alias_attr_handle, MEDIA_SAMPLERATE, DB_TABLE_ALIAS_MEDIA"."DB_FIELD_MEDIA_SAMPLERATE);
363 media_content_retv_if(ret != MEDIA_CONTENT_ERROR_NONE, ret);
365 ret = _media_filter_attribute_add(g_alias_attr_handle, MEDIA_CHANNEL, DB_TABLE_ALIAS_MEDIA"."DB_FIELD_MEDIA_CHANNEL);
366 media_content_retv_if(ret != MEDIA_CONTENT_ERROR_NONE, ret);
368 ret = _media_filter_attribute_add(g_alias_attr_handle, MEDIA_DURATION, DB_TABLE_ALIAS_MEDIA"."DB_FIELD_MEDIA_DURATION);
369 media_content_retv_if(ret != MEDIA_CONTENT_ERROR_NONE, ret);
371 ret = _media_filter_attribute_add(g_alias_attr_handle, MEDIA_LONGITUDE, DB_TABLE_ALIAS_MEDIA"."DB_FIELD_MEDIA_LONGITUDE);
372 media_content_retv_if(ret != MEDIA_CONTENT_ERROR_NONE, ret);
374 ret = _media_filter_attribute_add(g_alias_attr_handle, MEDIA_LATITUDE, DB_TABLE_ALIAS_MEDIA"."DB_FIELD_MEDIA_LATITUDE);
375 media_content_retv_if(ret != MEDIA_CONTENT_ERROR_NONE, ret);
377 ret = _media_filter_attribute_add(g_alias_attr_handle, MEDIA_ALTITUDE, DB_TABLE_ALIAS_MEDIA"."DB_FIELD_MEDIA_ALTITUDE);
378 media_content_retv_if(ret != MEDIA_CONTENT_ERROR_NONE, ret);
380 ret = _media_filter_attribute_add(g_alias_attr_handle, MEDIA_WIDTH, DB_TABLE_ALIAS_MEDIA"."DB_FIELD_MEDIA_WIDTH);
381 media_content_retv_if(ret != MEDIA_CONTENT_ERROR_NONE, ret);
383 ret = _media_filter_attribute_add(g_alias_attr_handle, MEDIA_HEIGHT, DB_TABLE_ALIAS_MEDIA"."DB_FIELD_MEDIA_HEIGHT);
384 media_content_retv_if(ret != MEDIA_CONTENT_ERROR_NONE, ret);
386 ret = _media_filter_attribute_add(g_alias_attr_handle, MEDIA_DATETAKEN, DB_TABLE_ALIAS_MEDIA"."DB_FIELD_MEDIA_DATETAKEN);
387 media_content_retv_if(ret != MEDIA_CONTENT_ERROR_NONE, ret);
389 ret = _media_filter_attribute_add(g_alias_attr_handle, MEDIA_ORIENTATION, DB_TABLE_ALIAS_MEDIA"."DB_FIELD_MEDIA_ORIENTATION);
390 media_content_retv_if(ret != MEDIA_CONTENT_ERROR_NONE, ret);
392 ret = _media_filter_attribute_add(g_alias_attr_handle, MEDIA_BURST_ID, DB_TABLE_ALIAS_MEDIA"."DB_FIELD_MEDIA_BURST_ID);
393 media_content_retv_if(ret != MEDIA_CONTENT_ERROR_NONE, ret);
395 ret = _media_filter_attribute_add(g_alias_attr_handle, MEDIA_PLAYED_COUNT, DB_TABLE_ALIAS_MEDIA"."DB_FIELD_MEDIA_PLAYED_COUNT);
396 media_content_retv_if(ret != MEDIA_CONTENT_ERROR_NONE, ret);
398 ret = _media_filter_attribute_add(g_alias_attr_handle, MEDIA_LAST_PLAYED_TIME, DB_TABLE_ALIAS_MEDIA"."DB_FIELD_MEDIA_LAST_PLAYED_TIME);
399 media_content_retv_if(ret != MEDIA_CONTENT_ERROR_NONE, ret);
401 ret = _media_filter_attribute_add(g_alias_attr_handle, MEDIA_LAST_PLAYED_POSITION, DB_TABLE_ALIAS_MEDIA"."DB_FIELD_MEDIA_LAST_PLAYED_POSITION);
402 media_content_retv_if(ret != MEDIA_CONTENT_ERROR_NONE, ret);
404 ret = _media_filter_attribute_add(g_alias_attr_handle, MEDIA_RATING, DB_TABLE_ALIAS_MEDIA"."DB_FIELD_MEDIA_RATING);
405 media_content_retv_if(ret != MEDIA_CONTENT_ERROR_NONE, ret);
407 ret = _media_filter_attribute_add(g_alias_attr_handle, MEDIA_FAVOURITE, DB_TABLE_ALIAS_MEDIA"."DB_FIELD_MEDIA_FAVOURITE);
408 media_content_retv_if(ret != MEDIA_CONTENT_ERROR_NONE, ret);
410 ret = _media_filter_attribute_add(g_alias_attr_handle, MEDIA_AUTHOR, DB_TABLE_ALIAS_MEDIA"."DB_FIELD_MEDIA_AUTHOR);
411 media_content_retv_if(ret != MEDIA_CONTENT_ERROR_NONE, ret);
413 ret = _media_filter_attribute_add(g_alias_attr_handle, MEDIA_PROVIDER, DB_TABLE_ALIAS_MEDIA"."DB_FIELD_MEDIA_PROVIDER);
414 media_content_retv_if(ret != MEDIA_CONTENT_ERROR_NONE, ret);
416 ret = _media_filter_attribute_add(g_alias_attr_handle, MEDIA_CONTENT_NAME, DB_TABLE_ALIAS_MEDIA"."DB_FIELD_MEDIA_CONTENT_NAME);
417 media_content_retv_if(ret != MEDIA_CONTENT_ERROR_NONE, ret);
419 ret = _media_filter_attribute_add(g_alias_attr_handle, MEDIA_CATEGORY, DB_TABLE_ALIAS_MEDIA"."DB_FIELD_MEDIA_CATEGORY);
420 media_content_retv_if(ret != MEDIA_CONTENT_ERROR_NONE, ret);
422 ret = _media_filter_attribute_add(g_alias_attr_handle, MEDIA_LOCATION_TAG, DB_TABLE_ALIAS_MEDIA"."DB_FIELD_MEDIA_LOCATION_TAG);
423 media_content_retv_if(ret != MEDIA_CONTENT_ERROR_NONE, ret);
425 ret = _media_filter_attribute_add(g_alias_attr_handle, MEDIA_AGE_RATING, DB_TABLE_ALIAS_MEDIA"."DB_FIELD_MEDIA_AGE_RATING);
426 media_content_retv_if(ret != MEDIA_CONTENT_ERROR_NONE, ret);
428 ret = _media_filter_attribute_add(g_alias_attr_handle, MEDIA_KEYWORD, DB_TABLE_ALIAS_MEDIA"."DB_FIELD_MEDIA_KEYWORD);
429 media_content_retv_if(ret != MEDIA_CONTENT_ERROR_NONE, ret);
431 ret = _media_filter_attribute_add(g_alias_attr_handle, MEDIA_WEATHER, DB_TABLE_ALIAS_MEDIA"."DB_FIELD_MEDIA_WEATHER);
432 media_content_retv_if(ret != MEDIA_CONTENT_ERROR_NONE, ret);
434 ret = _media_filter_attribute_add(g_alias_attr_handle, MEDIA_IS_DRM, DB_TABLE_ALIAS_MEDIA"."DB_FIELD_MEDIA_IS_DRM);
435 media_content_retv_if(ret != MEDIA_CONTENT_ERROR_NONE, ret);
437 ret = _media_filter_attribute_add(g_alias_attr_handle, MEDIA_STORAGE_TYPE, DB_TABLE_ALIAS_MEDIA"."DB_FIELD_MEDIA_STORAGE_TYPE);
438 media_content_retv_if(ret != MEDIA_CONTENT_ERROR_NONE, ret);
441 ret = _media_filter_attribute_add(g_alias_attr_handle, MEDIA_FILE_NAME_PINYIN, DB_TABLE_ALIAS_MEDIA"."DB_FIELD_MEDIA_FILE_NAME_PINYIN);
442 media_content_retv_if(ret != MEDIA_CONTENT_ERROR_NONE, ret);
444 ret = _media_filter_attribute_add(g_alias_attr_handle, MEDIA_TITLE_PINYIN, DB_TABLE_ALIAS_MEDIA"."DB_FIELD_MEDIA_TITLE_PINYIN);
445 media_content_retv_if(ret != MEDIA_CONTENT_ERROR_NONE, ret);
447 ret = _media_filter_attribute_add(g_alias_attr_handle, MEDIA_ALBUM_PINYIN, DB_TABLE_ALIAS_MEDIA"."DB_FIELD_MEDIA_ALBUM_PINYIN);
448 media_content_retv_if(ret != MEDIA_CONTENT_ERROR_NONE, ret);
450 ret = _media_filter_attribute_add(g_alias_attr_handle, MEDIA_ARTIST_PINYIN, DB_TABLE_ALIAS_MEDIA"."DB_FIELD_MEDIA_ARTIST_PINYIN);
451 media_content_retv_if(ret != MEDIA_CONTENT_ERROR_NONE, ret);
453 ret = _media_filter_attribute_add(g_alias_attr_handle, MEDIA_ALBUM_ARTIST_PINYIN, DB_TABLE_ALIAS_MEDIA"."DB_FIELD_MEDIA_ALBUM_ARTIST_PINYIN);
454 media_content_retv_if(ret != MEDIA_CONTENT_ERROR_NONE, ret);
456 ret = _media_filter_attribute_add(g_alias_attr_handle, MEDIA_GENRE_PINYIN, DB_TABLE_ALIAS_MEDIA"."DB_FIELD_MEDIA_GENRE_PINYIN);
457 media_content_retv_if(ret != MEDIA_CONTENT_ERROR_NONE, ret);
459 ret = _media_filter_attribute_add(g_alias_attr_handle, MEDIA_COMPOSER_PINYIN, DB_TABLE_ALIAS_MEDIA"."DB_FIELD_MEDIA_COMPOSER_PINYIN);
460 media_content_retv_if(ret != MEDIA_CONTENT_ERROR_NONE, ret);
462 ret = _media_filter_attribute_add(g_alias_attr_handle, MEDIA_COPYRIGHT_PINYIN, DB_TABLE_ALIAS_MEDIA"."DB_FIELD_MEDIA_COPYRIGHT_PINYIN);
463 media_content_retv_if(ret != MEDIA_CONTENT_ERROR_NONE, ret);
465 ret = _media_filter_attribute_add(g_alias_attr_handle, MEDIA_DESCRIPTION_PINYIN, DB_TABLE_ALIAS_MEDIA"."DB_FIELD_MEDIA_DESCRIPTION_PINYIN);
466 media_content_retv_if(ret != MEDIA_CONTENT_ERROR_NONE, ret);
468 ret = _media_filter_attribute_add(g_alias_attr_handle, MEDIA_AUTHOR_PINYIN, DB_TABLE_ALIAS_MEDIA"."DB_FIELD_MEDIA_AUTHOR_PINYIN);
469 media_content_retv_if(ret != MEDIA_CONTENT_ERROR_NONE, ret);
471 ret = _media_filter_attribute_add(g_alias_attr_handle, MEDIA_PROVIDER_PINYIN, DB_TABLE_ALIAS_MEDIA"."DB_FIELD_MEDIA_PROVIDER_PINYIN);
472 media_content_retv_if(ret != MEDIA_CONTENT_ERROR_NONE, ret);
474 ret = _media_filter_attribute_add(g_alias_attr_handle, MEDIA_CONTENT_NAME_PINYIN, DB_TABLE_ALIAS_MEDIA"."DB_FIELD_MEDIA_CONTENT_NAME_PINYIN);
475 media_content_retv_if(ret != MEDIA_CONTENT_ERROR_NONE, ret);
477 ret = _media_filter_attribute_add(g_alias_attr_handle, MEDIA_CATEGORY_PINYIN, DB_TABLE_ALIAS_MEDIA"."DB_FIELD_MEDIA_CATEGORY_PINYIN);
478 media_content_retv_if(ret != MEDIA_CONTENT_ERROR_NONE, ret);
480 ret = _media_filter_attribute_add(g_alias_attr_handle, MEDIA_LOCATION_TAG_PINYIN, DB_TABLE_ALIAS_MEDIA"."DB_FIELD_MEDIA_LOCATION_TAG_PINYIN);
481 media_content_retv_if(ret != MEDIA_CONTENT_ERROR_NONE, ret);
483 ret = _media_filter_attribute_add(g_alias_attr_handle, MEDIA_AGE_RATING_PINYIN, DB_TABLE_ALIAS_MEDIA"."DB_FIELD_MEDIA_AGE_RATING_PINYIN);
484 media_content_retv_if(ret != MEDIA_CONTENT_ERROR_NONE, ret);
486 ret = _media_filter_attribute_add(g_alias_attr_handle, MEDIA_KEYWORD_PINYIN, DB_TABLE_ALIAS_MEDIA"."DB_FIELD_MEDIA_KEYWORD_PINYIN);
487 media_content_retv_if(ret != MEDIA_CONTENT_ERROR_NONE, ret);
490 ret = _media_filter_attribute_add(g_alias_attr_handle, FOLDER_ID, DB_TABLE_ALIAS_FOLDER"."DB_FIELD_FOLDER_ID);
491 media_content_retv_if(ret != MEDIA_CONTENT_ERROR_NONE, ret);
493 ret = _media_filter_attribute_add(g_alias_attr_handle, FOLDER_PATH, DB_TABLE_ALIAS_FOLDER"."DB_FIELD_FOLDER_PATH);
494 media_content_retv_if(ret != MEDIA_CONTENT_ERROR_NONE, ret);
496 ret = _media_filter_attribute_add(g_alias_attr_handle, FOLDER_NAME, DB_TABLE_ALIAS_FOLDER"."DB_FIELD_FOLDER_NAME);
497 media_content_retv_if(ret != MEDIA_CONTENT_ERROR_NONE, ret);
499 ret = _media_filter_attribute_add(g_alias_attr_handle, FOLDER_MODIFIED_TIME, DB_TABLE_ALIAS_FOLDER"."DB_FIELD_FOLDER_MODIFIED_TIME);
500 media_content_retv_if(ret != MEDIA_CONTENT_ERROR_NONE, ret);
502 ret = _media_filter_attribute_add(g_alias_attr_handle, FOLDER_STORAGE_TYPE, DB_TABLE_ALIAS_FOLDER"."DB_FIELD_FOLDER_STORAGE_TYPE);
503 media_content_retv_if(ret != MEDIA_CONTENT_ERROR_NONE, ret);
505 ret = _media_filter_attribute_add(g_alias_attr_handle, FOLDER_NAME_PINYIN, DB_TABLE_ALIAS_FOLDER"."DB_FIELD_FOLDER_NAME_PINYIN);
506 media_content_retv_if(ret != MEDIA_CONTENT_ERROR_NONE, ret);
508 ret = _media_filter_attribute_add(g_alias_attr_handle, FOLDER_ORDER, DB_TABLE_ALIAS_FOLDER"."DB_FIELD_FOLDER_ORDER);
509 media_content_retv_if(ret != MEDIA_CONTENT_ERROR_NONE, ret);
511 ret = _media_filter_attribute_add(g_alias_attr_handle, FOLDER_PARENT_FOLDER_ID, DB_TABLE_ALIAS_FOLDER"."DB_FIELD_FOLDER_PARENT_FOLDER_ID);
512 media_content_retv_if(ret != MEDIA_CONTENT_ERROR_NONE, ret);
514 ret = _media_filter_attribute_add(g_alias_attr_handle, PLAYLIST_NAME, DB_TABLE_ALIAS_PLAYLIST"."DB_FIELD_PLAYLIST_NAME);
515 media_content_retv_if(ret != MEDIA_CONTENT_ERROR_NONE, ret);
517 ret = _media_filter_attribute_add(g_alias_attr_handle, PLAYLIST_MEMBER_ORDER, DB_TABLE_ALIAS_PLAYLIST_MAP"."DB_FIELD_PLAYLIST_MEMBER_ORDER);
518 media_content_retv_if(ret != MEDIA_CONTENT_ERROR_NONE, ret);
521 ret = _media_filter_attribute_add(g_alias_attr_handle, TAG_NAME, DB_TABLE_ALIAS_TAG"."DB_FIELD_TAG_NAME);
522 media_content_retv_if(ret != MEDIA_CONTENT_ERROR_NONE, ret);
525 ret = _media_filter_attribute_add(g_alias_attr_handle, BOOKMARK_MARKED_TIME, DB_TABLE_ALIAS_BOOKMARK"."DB_FIELD_BOOKMARK_MARKED_TIME);
526 media_content_retv_if(ret != MEDIA_CONTENT_ERROR_NONE, ret);
531 static int __media_content_create_attribute_handle(void)
533 int ret = MEDIA_CONTENT_ERROR_NONE;
535 ret = __media_content_create_attr_handle();
536 media_content_retv_if(ret != MEDIA_CONTENT_ERROR_NONE, ret);
538 ret = __media_content_create_alias_attr_handle();
539 if (ret != MEDIA_CONTENT_ERROR_NONE)
540 _media_filter_attribute_destory(g_attr_handle);
545 static int __media_content_destroy_attribute_handle(void)
547 int ret = MEDIA_CONTENT_ERROR_NONE;
549 ret = _media_filter_attribute_destory(g_attr_handle);
550 ret = _media_filter_attribute_destory(g_alias_attr_handle);
552 g_attr_handle = NULL;
553 g_alias_attr_handle = NULL;
558 attribute_h _content_get_attirbute_handle(void)
560 return g_attr_handle;
563 attribute_h _content_get_alias_attirbute_handle(void)
565 return g_alias_attr_handle;
568 MediaSvcHandle* _content_get_db_handle(void)
573 int _content_query_prepare(sqlite3_stmt **stmt, char *select_query, char *condition_query, char *option_query)
576 int err = MEDIA_CONTENT_ERROR_NONE;
577 char query[MAX_QUERY_SIZE] = {0, };
578 memset(query, '\0', sizeof(query));
580 media_content_retvm_if(db_handle == NULL, MEDIA_CONTENT_ERROR_DB_FAILED, "database is not connected");
581 media_content_retvm_if(!STRING_VALID(select_query), MEDIA_CONTENT_ERROR_INVALID_PARAMETER, "invalid select_query");
583 if (!STRING_VALID(condition_query))
584 condition_query = (char *)" ";
586 if (!STRING_VALID(option_query))
587 option_query = (char *)" ";
589 /*query = sqlite3_mprintf("%s %s %s", select_query, condition_query, option_query);*/
590 len = snprintf(query, sizeof(query), "%s %s %s", select_query, condition_query, option_query);
591 if (len > 0 && len < MAX_QUERY_SIZE)
593 else if (len >= MAX_QUERY_SIZE)
594 query[MAX_QUERY_SIZE -1] = '\0';
596 media_content_error("snprintf failed");
597 return MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
600 media_content_sec_debug("Query : [%s]", query);
602 err = sqlite3_prepare_v2((sqlite3*)db_handle, query, strlen(query), stmt, NULL);
603 if (err != SQLITE_OK) {
604 media_content_error("DB_FAILED(0x%08x) fail to sqlite3_prepare(), %s", MEDIA_CONTENT_ERROR_DB_FAILED, sqlite3_errmsg((sqlite3*)db_handle));
606 if (err == SQLITE_BUSY) {
607 media_content_error(" BUSY ERROR");
608 return MEDIA_CONTENT_ERROR_DB_BUSY;
609 } else if (err == SQLITE_PERM) {
610 media_content_error("PERMISSION EROR");
611 return MEDIA_CONTENT_ERROR_PERMISSION_DENIED;
613 media_content_error("OTHER ERROR");
614 return MEDIA_CONTENT_ERROR_DB_FAILED;
618 return MEDIA_CONTENT_ERROR_NONE;
621 int _content_error_capi(int type, int content_error)
623 if (content_error != MEDIA_CONTENT_ERROR_NONE)
624 media_content_error("[type : %d] content_error : %d ", type, content_error);
627 if (content_error == MS_MEDIA_ERR_NONE)
628 return MEDIA_CONTENT_ERROR_NONE;
630 /* Internal operation error*/
631 else if ((content_error == MS_MEDIA_ERR_INVALID_PARAMETER) ||
632 (content_error == MS_MEDIA_ERR_INVALID_PATH) ||
633 (content_error == MS_MEDIA_ERR_THUMB_DUPLICATED_REQUEST))
634 return MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
636 else if (content_error == MS_MEDIA_ERR_OUT_OF_MEMORY)
637 return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY;
639 /* DB operation error*/
640 else if (content_error == MS_MEDIA_ERR_DB_BUSY_FAIL)
641 return MEDIA_CONTENT_ERROR_DB_BUSY;
643 else if ((content_error <= MS_MEDIA_ERR_DB_CONNECT_FAIL) && (content_error >= MS_MEDIA_ERR_DB_INTERNAL))
644 return MEDIA_CONTENT_ERROR_DB_FAILED;
646 /* IPC operation error*/
647 else if ((content_error <= MS_MEDIA_ERR_SOCKET_CONN) && (content_error >= MS_MEDIA_ERR_SOCKET_INTERNAL))
648 return MEDIA_CONTENT_ERROR_NETWORK;
650 /* MEDIA SERVER error*/
651 else if (content_error == MS_MEDIA_ERR_PERMISSION_DENIED)
652 return MEDIA_CONTENT_ERROR_PERMISSION_DENIED;
655 else if (content_error == MS_MEDIA_ERR_THUMB_TOO_BIG)
656 return MEDIA_CONTENT_ERROR_UNSUPPORTED_CONTENT;
659 return MEDIA_CONTENT_ERROR_INVALID_OPERATION;
662 int _content_query_sql(char *query_str)
664 int ret = MEDIA_CONTENT_ERROR_NONE;
666 /*DB will be updated by Media Server.*/
667 ret = media_svc_request_update_db(query_str, tzplatform_getuid(TZ_USER_NAME));
669 return _content_error_capi(MEDIA_CONTENT_TYPE, ret);
672 int media_content_connect(void)
674 int ret = MEDIA_CONTENT_ERROR_NONE;
676 if (g_mutex_trylock(&db_mutex)) {
677 media_content_info("ref count : %d", ref_count);
679 if (ref_count == 0) {
680 if (db_handle == NULL) {
681 ret = __media_content_create_attribute_handle();
682 if (ret == MEDIA_CONTENT_ERROR_NONE) {
683 ret = media_svc_connect(&db_handle, tzplatform_getuid(TZ_USER_NAME), false);
684 ret = _content_error_capi(MEDIA_CONTENT_TYPE, ret);
685 if (ret == MEDIA_CONTENT_ERROR_NONE)
688 __media_content_destroy_attribute_handle();
691 media_content_error("Internal DB Connection Error");
694 media_content_error("Wrong DB Connection status");
695 ret = MEDIA_CONTENT_ERROR_DB_FAILED;
698 if (db_handle != NULL) {
701 media_content_error("Wrong DB Handle status");
702 ret = MEDIA_CONTENT_ERROR_DB_FAILED;
706 media_content_info("ref count changed to: %d", ref_count);
707 g_mutex_unlock(&db_mutex);
709 media_content_error("mutex is NULL");
710 ret = MEDIA_CONTENT_ERROR_DB_FAILED;
716 int media_content_disconnect(void)
718 int ret = MEDIA_CONTENT_ERROR_NONE;
720 if (g_mutex_trylock(&db_mutex)) {
721 media_content_debug("ref count : %d", ref_count);
723 if (db_handle != NULL) {
726 media_content_error("Wrong DB Handle status");
727 ret = MEDIA_CONTENT_ERROR_DB_FAILED;
730 media_content_error("DB_FAILED(0x%08x) database is not connected", MEDIA_CONTENT_ERROR_DB_FAILED);
731 g_mutex_unlock(&db_mutex);
732 return MEDIA_CONTENT_ERROR_DB_FAILED;
735 if (ref_count == 0) {
736 if (db_handle != NULL) {
737 ret = media_svc_disconnect(db_handle);
738 ret = _content_error_capi(MEDIA_CONTENT_TYPE, ret);
739 if (ret == MEDIA_CONTENT_ERROR_NONE) {
740 ret = __media_content_destroy_attribute_handle();
743 media_content_error("database disconnect fail");
747 media_content_error("Wrong DB Handle status");
748 ret = MEDIA_CONTENT_ERROR_DB_FAILED;
751 g_mutex_unlock(&db_mutex);
753 media_content_info("ref count changed to: %d", ref_count);
758 g_mutex_unlock(&db_mutex);
760 media_content_error("mutex is NULL");
761 ret = MEDIA_CONTENT_ERROR_INVALID_OPERATION;
764 media_content_info("ref count changed to: %d", ref_count);
769 int media_content_scan_file(const char *path)
771 int ret = MEDIA_CONTENT_ERROR_NONE;
772 bool ignore_file = FALSE;
773 bool ignore_dir = FALSE;
774 char *folder_path = NULL;
775 int check_file = MEDIA_CONTENT_ERROR_NONE;
776 char storage_id[MEDIA_CONTENT_UUID_SIZE+1] = {0,};
778 media_content_retvm_if(!STRING_VALID(path), MEDIA_CONTENT_ERROR_INVALID_PARAMETER, "invalid path");
780 media_content_sec_debug("Path : %s", path);
782 ret = _media_util_check_ignore_file(path, &ignore_file);
783 media_content_retvm_if(ignore_file == TRUE, MEDIA_CONTENT_ERROR_INVALID_PARAMETER, "Invalid path");
785 memset(storage_id, 0x00, sizeof(storage_id));
786 ret = media_svc_get_storage_id(_content_get_db_handle(), path, storage_id);
787 if (ret != MS_MEDIA_ERR_NONE) {
788 media_content_error("media_svc_get_storage_id failed : %d", ret);
789 return _content_error_capi(MEDIA_CONTENT_TYPE, ret);
792 check_file = _media_util_check_file_exist(path);
793 if (check_file == MEDIA_CONTENT_ERROR_NONE) {
794 /* This means this path has to be inserted or refreshed */
795 folder_path = g_path_get_dirname(path);
796 ret = _media_util_check_ignore_dir(folder_path, &ignore_dir);
797 SAFE_FREE(folder_path);
799 media_content_retvm_if(ignore_dir == TRUE, MEDIA_CONTENT_ERROR_INVALID_PARAMETER, "Invalid folder path");
801 media_svc_storage_type_e storage_type;
803 ret = media_svc_get_storage_type(path, &storage_type, tzplatform_getuid(TZ_USER_NAME));
804 if (ret != MS_MEDIA_ERR_NONE) {
805 media_content_sec_error("media_svc_get_storage_type failed : %d (%s)", ret, path);
806 return _content_error_capi(MEDIA_CONTENT_TYPE, ret);
808 ret = media_svc_check_item_exist_by_path(_content_get_db_handle(), storage_id, path);
809 if (ret == MS_MEDIA_ERR_NONE) {
811 ret = media_svc_refresh_item(_content_get_db_handle(), storage_id, storage_type, path, tzplatform_getuid(TZ_USER_NAME));
812 if (ret != MS_MEDIA_ERR_NONE) {
813 media_content_error("media_svc_refresh_item failed : %d", ret);
814 return _content_error_capi(MEDIA_CONTENT_TYPE, ret);
817 } else if (ret == MS_MEDIA_ERR_DB_NO_RECORD) {
819 ret = media_svc_insert_item_immediately(_content_get_db_handle(), storage_id, storage_type, path, tzplatform_getuid(TZ_USER_NAME));
820 if (ret != MS_MEDIA_ERR_NONE) {
821 if (ret == MS_MEDIA_ERR_DB_CONSTRAINT_FAIL) {
822 media_content_sec_error("This item is already inserted. This may be normal operation because other process already did this (%s)", path);
823 ret = MEDIA_CONTENT_ERROR_NONE;
825 media_content_sec_error("media_svc_insert_item_immediately failed : %d (%s)", ret, path);
828 return _content_error_capi(MEDIA_CONTENT_TYPE, ret);
831 media_content_error("media_svc_check_item_exist_by_path failed : %d", ret);
832 return _content_error_capi(MEDIA_CONTENT_TYPE, ret);
834 } else if (check_file == MEDIA_CONTENT_ERROR_PERMISSION_DENIED) {
835 media_content_error("You have no permission for this file %d", ret);
836 return MEDIA_CONTENT_ERROR_PERMISSION_DENIED;
838 /* This means this path has to be deleted */
839 media_content_debug("This path doesn't exists in file system... So now start to delete it from DB");
840 ret = media_svc_delete_item_by_path(_content_get_db_handle(), storage_id, path, tzplatform_getuid(TZ_USER_NAME));
841 if (ret != MS_MEDIA_ERR_NONE) {
842 media_content_error("media_svc_delete_item_by_path failed : %d", ret);
843 return _content_error_capi(MEDIA_CONTENT_TYPE, ret);
847 return _content_error_capi(MEDIA_CONTENT_TYPE, ret);
850 void _media_content_scan_cb(media_request_result_s* result, void *user_data)
853 media_content_scan_cb_data *cb_data = user_data;
855 err = result->result;
857 if (cb_data && cb_data->callback) {
858 media_content_debug("User callback is being called now");
859 cb_data->callback(err, cb_data->user_data);
867 static int __media_content_check_dir(const char *path)
873 media_content_sec_error("path [%s]", path);
874 media_content_stderror("open dir fail");
876 if (errno == EACCES || errno == EPERM)
877 return MEDIA_CONTENT_ERROR_PERMISSION_DENIED;
879 return MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
884 return MEDIA_CONTENT_ERROR_NONE;
887 int media_content_scan_folder(const char *path, bool is_recursive, media_scan_completed_cb callback, void *user_data)
889 int ret = MEDIA_CONTENT_ERROR_NONE;
890 bool ignore_dir = FALSE;
891 char storage_id[MEDIA_CONTENT_UUID_SIZE+1] = {0, };
893 media_content_retvm_if(!STRING_VALID(path), MEDIA_CONTENT_ERROR_INVALID_PARAMETER, "Invalid path");
894 memset(storage_id, 0x00, sizeof(storage_id));
896 ret = __media_content_check_dir(path);
897 media_content_retvm_if(ret == MEDIA_CONTENT_ERROR_PERMISSION_DENIED, ret, "Permission Denied");
899 if (ret == MEDIA_CONTENT_ERROR_NONE) {
900 /* If directory exist check that's ignore directory or not*/
901 ret = _media_util_check_ignore_dir(path, &ignore_dir);
902 media_content_retvm_if(ignore_dir == TRUE, MEDIA_CONTENT_ERROR_INVALID_PARAMETER, "Invalid folder path");
904 /* This means this folder has to be deleted */
905 media_content_debug("This path doesn't exists in file system... So will be deleted it from DB");
908 media_content_scan_cb_data *cb_data = NULL;
909 cb_data = (media_content_scan_cb_data *)malloc(sizeof(media_content_scan_cb_data));
910 media_content_retvm_if(cb_data == NULL, MEDIA_CONTENT_ERROR_OUT_OF_MEMORY, "OUT_OF_MEMORY");
912 cb_data->callback = callback;
913 cb_data->user_data = user_data;
915 ret = media_svc_get_storage_id(_content_get_db_handle(), path, storage_id);
916 /*FIX ME. need to check ret value?*/
918 ret = media_directory_scanning_async(path, storage_id, is_recursive, _media_content_scan_cb, cb_data, tzplatform_getuid(TZ_USER_NAME));
919 if (ret != MS_MEDIA_ERR_NONE)
920 media_content_error("media_directory_scanning_async failed : %d", ret);
922 return _content_error_capi(MEDIA_REGISTER_TYPE, ret);
925 int media_content_cancel_scan_folder(const char *path)
927 int ret = MEDIA_CONTENT_ERROR_NONE;
929 ret = media_directory_scanning_cancel(path, tzplatform_getuid(TZ_USER_NAME));
930 if (ret != MS_MEDIA_ERR_NONE)
931 media_content_error("media_directory_scanning_async failed : %d", ret);
933 return _content_error_capi(MEDIA_REGISTER_TYPE, ret);
936 void _media_content_db_update_noti_cb(
938 media_item_type_e item,
939 media_item_update_type_e update_type,
942 media_type_e content_type,
946 int error_value = MEDIA_CONTENT_ERROR_NONE;
948 media_noti_cb_s *_noti_info = (media_noti_cb_s *)user_data;
950 if (_noti_info != NULL) {
951 if (_noti_info->update_noti_cb)
952 _noti_info->update_noti_cb(error_value, pid, item, update_type, content_type, uuid, path, mime_type, _noti_info->user_data);
958 int media_content_set_db_updated_cb(media_content_db_update_cb callback, void *user_data)
960 int ret = MEDIA_CONTENT_ERROR_NONE;
962 media_content_retvm_if(callback == NULL, MEDIA_CONTENT_ERROR_INVALID_PARAMETER, "Invalid callback");
963 media_content_retvm_if(g_noti_info != NULL, MEDIA_CONTENT_ERROR_INVALID_OPERATION, "Noti callback is already set");
965 g_noti_info = (media_noti_cb_s *)calloc(1, sizeof(media_noti_cb_s));
966 media_content_retvm_if(g_noti_info == NULL, MEDIA_CONTENT_ERROR_OUT_OF_MEMORY, "OUT_OF_MEMORY");
968 g_noti_info->update_noti_cb = callback;
969 g_noti_info->user_data = user_data;
971 ret = media_db_update_subscribe(_media_content_db_update_noti_cb, (void *)g_noti_info);
973 return _content_error_capi(MEDIA_REGISTER_TYPE, ret);
976 int media_content_unset_db_updated_cb(void)
978 int ret = MEDIA_CONTENT_ERROR_NONE;
980 SAFE_FREE(g_noti_info);
981 ret = media_db_update_unsubscribe();
983 return _content_error_capi(MEDIA_REGISTER_TYPE, ret);
986 int media_content_set_db_updated_cb_v2(media_content_noti_h *noti_handle, media_content_db_update_cb callback, void *user_data)
988 int ret = MEDIA_CONTENT_ERROR_NONE;
989 media_noti_cb_s *noti_info = NULL;
991 if (noti_handle == NULL) {
992 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
993 return MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
996 if (callback == NULL) {
997 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
998 return MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
1001 noti_info = (media_noti_cb_s *)calloc(1, sizeof(media_noti_cb_s));
1002 if (noti_info == NULL) {
1003 media_content_error("Failed to create noti info");
1004 return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY;
1007 noti_info->update_noti_cb = callback;
1008 noti_info->user_data = user_data;
1010 ret = media_db_update_subscribe_internal((MediaNotiHandle*)noti_handle, _media_content_db_update_noti_cb, (void *)noti_info);
1012 return _content_error_capi(MEDIA_REGISTER_TYPE, ret);
1015 int media_content_add_db_updated_cb(media_content_db_update_cb callback, void *user_data, media_content_noti_h *noti_handle)
1017 int ret = MEDIA_CONTENT_ERROR_NONE;
1018 media_noti_cb_s *noti_info = NULL;
1020 if (noti_handle == NULL) {
1021 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
1022 return MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
1025 if (callback == NULL) {
1026 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
1027 return MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
1030 noti_info = (media_noti_cb_s *)calloc(1, sizeof(media_noti_cb_s));
1031 if (noti_info == NULL) {
1032 media_content_error("Failed to create noti info");
1033 return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY;
1036 noti_info->update_noti_cb = callback;
1037 noti_info->user_data = user_data;
1039 ret = media_db_update_subscribe_internal((MediaNotiHandle*)noti_handle, _media_content_db_update_noti_cb, (void *)noti_info);
1041 return _content_error_capi(MEDIA_REGISTER_TYPE, ret);
1044 void __media_content_clear_user_data(void *user_data)
1046 media_noti_cb_s *noti_info = user_data;
1048 SAFE_FREE(noti_info);
1053 int media_content_unset_db_updated_cb_v2(media_content_noti_h noti_handle)
1055 int ret = MEDIA_CONTENT_ERROR_NONE;
1057 ret = media_db_update_unsubscribe_internal((MediaNotiHandle)noti_handle, __media_content_clear_user_data);
1059 return _content_error_capi(MEDIA_REGISTER_TYPE, ret);
1063 int media_content_remove_db_updated_cb(media_content_noti_h noti_handle)
1065 int ret = MEDIA_CONTENT_ERROR_NONE;
1067 ret = media_db_update_unsubscribe_internal((MediaNotiHandle)noti_handle, __media_content_clear_user_data);
1069 return _content_error_capi(MEDIA_REGISTER_TYPE, ret);