sync with master
[platform/core/multimedia/libmedia-service.git] / plugin / media-content-plugin.c
1 /*
2  * libmedia-service
3  *
4  * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
5  *
6  * Contact: Hyunjun Ko <zzoon.ko@samsung.com>, Haejeong Kim <backto.kim@samsung.com>
7  *
8  * Licensed under the Apache License, Version 2.0 (the "License");
9  * you may not use this file except in compliance with the License.
10  * You may obtain a copy of the License at
11  *
12  * http://www.apache.org/licenses/LICENSE-2.0
13  *
14  * Unless required by applicable law or agreed to in writing, software
15  * distributed under the License is distributed on an "AS IS" BASIS,
16  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17  * See the License for the specific language governing permissions and
18  * limitations under the License.
19  *
20  */
21
22 #include <string.h>
23 #include <mm_file.h>
24 #include <media-thumbnail.h>
25 #include "media-svc.h"
26
27 #define MEDIA_SVC_PLUGIN_ERROR_NONE             0
28 #define MEDIA_SVC_PLUGIN_ERROR                  -1
29
30 #define STRING_VALID(str)       \
31         ((str != NULL && strlen(str) > 0) ? TRUE : FALSE)
32 #define STORAGE_VALID(storage)\
33         (((storage == MEDIA_SVC_STORAGE_INTERNAL) || (storage == MEDIA_SVC_STORAGE_EXTERNAL)) ? TRUE : FALSE)
34
35
36 typedef enum{
37         ERR_HANDLE = 1,
38         ERR_FILE_PATH,
39         ERR_FOLDER_PATH,
40         ERR_MIME_TYPE,
41         ERR_NOT_MEDIAFILE,
42         ERR_STORAGE_TYPE,
43         ERR_CHECK_ITEM,
44         ERR_MAX,
45 }media_svc_error_type_e;
46
47 #define MS_CATEGORY_UNKNOWN     0x00000000      /**< Default */
48 #define MS_CATEGORY_ETC         0x00000001      /**< ETC category */
49 #define MS_CATEGORY_IMAGE               0x00000002      /**< Image category */
50 #define MS_CATEGORY_VIDEO               0x00000004      /**< Video category */
51 #define MS_CATEGORY_MUSIC               0x00000008      /**< Music category */
52 #define MS_CATEGORY_SOUND       0x00000010      /**< Sound category */
53
54 #define CONTENT_TYPE_NUM 4
55 #define MUSIC_MIME_NUM 29
56 #define SOUND_MIME_NUM 1
57 #define MIME_TYPE_LENGTH 255
58 #define MIME_LENGTH 50
59 #define _3GP_FILE ".3gp"
60 #define _MP4_FILE ".mp4"
61
62
63 typedef struct {
64         char content_type[15];
65         int category_by_mime;
66 } fex_content_table_t;
67
68 static const fex_content_table_t content_category[CONTENT_TYPE_NUM] = {
69         {"audio", MS_CATEGORY_SOUND},
70         {"image", MS_CATEGORY_IMAGE},
71         {"video", MS_CATEGORY_VIDEO},
72         {"application", MS_CATEGORY_ETC},
73 };
74
75 static const char music_mime_table[MUSIC_MIME_NUM][MIME_LENGTH] = {
76         /*known mime types of normal files*/
77         "mpeg",
78         "ogg",
79         "x-ms-wma",
80         "x-flac",
81         "mp4",
82         /* known mime types of drm files*/
83         "mp3",
84         "x-mp3", /*alias of audio/mpeg*/
85         "x-mpeg", /*alias of audio/mpeg*/
86         "3gpp",
87         "x-ogg", /*alias of  audio/ogg*/
88         "vnd.ms-playready.media.pya:*.pya", /*playready*/
89         "wma",
90         "aac",
91         "x-m4a", /*alias of audio/mp4*/
92         /* below mimes are rare*/
93         "x-vorbis+ogg",
94         "x-flac+ogg",
95         "x-matroska",
96         "ac3",
97         "mp2",
98         "x-ape",
99         "x-ms-asx",
100         "vnd.rn-realaudio",
101
102         "x-vorbis", /*alias of audio/x-vorbis+ogg*/
103         "vorbis", /*alias of audio/x-vorbis+ogg*/
104         "x-oggflac",
105         "x-mp2", /*alias of audio/mp2*/
106         "x-pn-realaudio", /*alias of audio/vnd.rn-realaudio*/
107         "vnd.m-realaudio", /*alias of audio/vnd.rn-realaudio*/
108         "x-wav",
109 };
110
111 static const char sound_mime_table[SOUND_MIME_NUM][MIME_LENGTH] = {
112         "x-smaf",
113 };
114
115 static int __get_content_type_from_mime(const char * path, const char * mimetype, int * category);
116 static int __get_content_type(const char * file_path, const char * mime_type);
117 static void __set_error_message(int err_type, char ** err_msg);
118
119 static int __get_content_type_from_mime(const char * path, const char * mimetype, int * category)
120 {
121         int i = 0;
122         int err = 0;
123
124         *category = MS_CATEGORY_UNKNOWN;
125
126         //MS_DBG("mime type : %s", mimetype);
127
128         /*categorize from mimetype */
129         for (i = 0; i < CONTENT_TYPE_NUM; i++) {
130                 if (strstr(mimetype, content_category[i].content_type) != NULL) {
131                         *category = (*category | content_category[i].category_by_mime);
132                         break;
133                 }
134         }
135
136         /*in application type, exitst sound file ex) x-smafs */
137         if (*category & MS_CATEGORY_ETC) {
138                 int prefix_len = strlen(content_category[0].content_type);
139
140                 for (i = 0; i < SOUND_MIME_NUM; i++) {
141                         if (strstr(mimetype + prefix_len, sound_mime_table[i]) != NULL) {
142                                 *category ^= MS_CATEGORY_ETC;
143                                 *category |= MS_CATEGORY_SOUND;
144                                 break;
145                         }
146                 }
147         }
148
149         /*check music file in soun files. */
150         if (*category & MS_CATEGORY_SOUND) {
151                 int prefix_len = strlen(content_category[0].content_type) + 1;
152
153                 //MS_DBG("mime_type : %s", mimetype + prefix_len);
154
155                 for (i = 0; i < MUSIC_MIME_NUM; i++) {
156                         if (strcmp(mimetype + prefix_len, music_mime_table[i]) == 0) {
157                                 *category ^= MS_CATEGORY_SOUND;
158                                 *category |= MS_CATEGORY_MUSIC;
159                                 break;
160                         }
161                 }
162
163                 /*m3u file is playlist but mime type is "audio/x-mpegurl". but It has to be classified into MS_CATEGORY_ETC since playlist is not a sound track*/
164                 if(strncasecmp(mimetype, "audio/x-mpegurl", strlen("audio/x-mpegurl")) == 0) {
165                         *category ^= MS_CATEGORY_SOUND;
166                         *category |= MS_CATEGORY_ETC;
167                 }
168         } else if (*category & MS_CATEGORY_VIDEO) {
169                 /*some video files don't have video stream. in this case it is categorize as music. */
170                 /*"3gp" and "mp4" must check video stream and then categorize in directly. */
171                 char file_ext[10] = {0};
172                 memset(file_ext, 0, sizeof(file_ext));
173                 if((_media_svc_get_file_ext(path, file_ext)) && strlen(file_ext) > 0) {
174                         if ((strncasecmp(file_ext, _3GP_FILE, 4) == 0) || (strncasecmp(file_ext, _MP4_FILE, 5) == 0)) {
175                                 int audio = 0;
176                                 int video = 0;
177
178                                 err = mm_file_get_stream_info(path, &audio, &video);
179                                 if (err == 0) {
180                                         if (audio > 0 && video == 0) {
181                                                 *category ^= MS_CATEGORY_VIDEO;
182                                                 *category |= MS_CATEGORY_MUSIC;
183                                         }
184                                 }
185                         }
186                 }
187         }
188
189         //MS_DBG("category_from_ext : %d", *category);
190
191         return err;
192 }
193
194 static int __get_content_type(const char * file_path, const char * mime_type)
195 {
196         int ret = MEDIA_SVC_PLUGIN_ERROR_NONE;
197         int category = 0;
198
199         ret = __get_content_type_from_mime(file_path, mime_type, &category);
200
201         if (category & MS_CATEGORY_SOUND)               return MEDIA_SVC_MEDIA_TYPE_SOUND;
202         else if (category & MS_CATEGORY_MUSIC)  return MEDIA_SVC_MEDIA_TYPE_MUSIC;
203         else if (category & MS_CATEGORY_IMAGE)  return MEDIA_SVC_MEDIA_TYPE_IMAGE;
204         else if (category & MS_CATEGORY_VIDEO)  return MEDIA_SVC_MEDIA_TYPE_VIDEO;
205         else    return MEDIA_SVC_MEDIA_TYPE_OTHER;
206 }
207
208 static void __set_error_message(int err_type, char ** err_msg)
209 {
210         if (err_msg)
211                 *err_msg = NULL;
212         else
213                 return;
214
215         if(err_type == ERR_HANDLE)
216                 *err_msg = strdup("invalid handle");
217         else if(err_type == ERR_FILE_PATH)
218                 *err_msg = strdup("invalid file path");
219         else if(err_type == ERR_FOLDER_PATH)
220                 *err_msg = strdup("invalid folder path");
221         else if(err_type == ERR_MIME_TYPE)
222                 *err_msg = strdup("invalid mime type");
223         else if(err_type == ERR_NOT_MEDIAFILE)
224                 *err_msg = strdup("not media content");
225         else if(err_type == ERR_STORAGE_TYPE)
226                 *err_msg = strdup("invalid storage type");
227         else if(err_type == ERR_CHECK_ITEM)
228                 *err_msg = strdup("item does not exist");
229         else if(err_type == MEDIA_INFO_ERROR_DATABASE_CONNECT)
230                 *err_msg = strdup("DB connect error");
231         else if(err_type == MEDIA_INFO_ERROR_DATABASE_DISCONNECT)
232                 *err_msg = strdup("DB disconnect error");
233         else if(err_type == MEDIA_INFO_ERROR_INVALID_PARAMETER)
234                 *err_msg = strdup("invalid parameter");
235         else if(err_type == MEDIA_INFO_ERROR_DATABASE_INTERNAL)
236                 *err_msg = strdup("DB internal error");
237         else if(err_type == MEDIA_INFO_ERROR_DATABASE_NO_RECORD)
238                 *err_msg = strdup("not found in DB");
239         else if(err_type == MEDIA_INFO_ERROR_INTERNAL)
240                 *err_msg = strdup("media service internal error");
241         else
242                 *err_msg = strdup("error unknown");
243
244         return;
245 }
246
247 int check_item(const char *file_path, const char * mime_type, char ** err_msg)
248 {
249         if (!STRING_VALID(file_path)) {
250                 __set_error_message(ERR_FILE_PATH, err_msg);
251                 return MEDIA_SVC_PLUGIN_ERROR;
252         }
253
254         if (!STRING_VALID(mime_type)) {
255                 __set_error_message(ERR_MIME_TYPE, err_msg);
256                 return MEDIA_SVC_PLUGIN_ERROR;
257         }
258
259         return MEDIA_SVC_PLUGIN_ERROR_NONE;
260 }
261
262 int connect(void ** handle, char ** err_msg)
263 {
264         int ret = media_svc_connect(handle);
265
266         if(ret < 0) {
267                 __set_error_message(ret, err_msg);
268                 return MEDIA_SVC_PLUGIN_ERROR;
269         }
270
271         return MEDIA_SVC_PLUGIN_ERROR_NONE;
272 }
273
274 int disconnect(void * handle, char ** err_msg)
275 {
276         int ret = MEDIA_SVC_PLUGIN_ERROR_NONE;
277
278         if(handle == NULL) {
279                 __set_error_message(ERR_HANDLE, err_msg);
280                 return MEDIA_SVC_PLUGIN_ERROR;
281         }
282
283         ret = media_svc_disconnect(handle);
284         if(ret < 0) {
285                 __set_error_message(ret, err_msg);
286                 return MEDIA_SVC_PLUGIN_ERROR;
287         }
288
289         return MEDIA_SVC_PLUGIN_ERROR_NONE;
290 }
291
292 int check_item_exist(void* handle, const char *file_path, int storage_type, char ** err_msg)
293 {
294         int ret = MEDIA_SVC_PLUGIN_ERROR_NONE;
295
296         if(handle == NULL) {
297                 __set_error_message(ERR_HANDLE, err_msg);
298                 return MEDIA_SVC_PLUGIN_ERROR;
299         }
300
301         if (!STRING_VALID(file_path)) {
302                 __set_error_message(ERR_FILE_PATH, err_msg);
303                 return MEDIA_SVC_PLUGIN_ERROR;
304         }
305
306         if(!STORAGE_VALID(storage_type)) {
307                 __set_error_message(ERR_STORAGE_TYPE, err_msg);
308                 return MEDIA_SVC_PLUGIN_ERROR;
309         }
310
311         ret = media_svc_check_item_exist_by_path(handle, file_path);
312         if(ret == MEDIA_INFO_ERROR_NONE)
313                 return MEDIA_SVC_PLUGIN_ERROR_NONE;     //exist
314
315         __set_error_message(ERR_CHECK_ITEM, err_msg);
316
317         return MEDIA_SVC_PLUGIN_ERROR;          //not exist
318 }
319
320 int insert_item_begin(void * handle, int item_cnt, int with_noti, int from_pid, char ** err_msg)
321 {
322         int ret = MEDIA_SVC_PLUGIN_ERROR_NONE;
323
324         if(handle == NULL) {
325                 __set_error_message(ERR_HANDLE, err_msg);
326                 return MEDIA_SVC_PLUGIN_ERROR;
327         }
328
329         ret = media_svc_insert_item_begin(handle, item_cnt, with_noti, from_pid);
330         if(ret < 0) {
331                 __set_error_message(ret, err_msg);
332                 return MEDIA_SVC_PLUGIN_ERROR;
333         }
334
335         return MEDIA_SVC_PLUGIN_ERROR_NONE;
336 }
337
338 int insert_item_end(void * handle, char ** err_msg)
339 {
340         int ret = MEDIA_SVC_PLUGIN_ERROR_NONE;
341
342         if(handle == NULL) {
343                 __set_error_message(ERR_HANDLE, err_msg);
344                 return MEDIA_SVC_PLUGIN_ERROR;
345         }
346
347         ret = media_svc_insert_item_end(handle);
348         if(ret < 0) {
349                 __set_error_message(ret, err_msg);
350                 return MEDIA_SVC_PLUGIN_ERROR;
351         }
352
353         return MEDIA_SVC_PLUGIN_ERROR_NONE;
354 }
355
356 int insert_item(void * handle, const char *file_path, int storage_type, const char * mime_type, char ** err_msg)
357 {
358         int ret = MEDIA_SVC_PLUGIN_ERROR_NONE;
359
360         if(handle == NULL) {
361                 __set_error_message(ERR_HANDLE, err_msg);
362                 return MEDIA_SVC_PLUGIN_ERROR;
363         }
364
365         if (!STRING_VALID(file_path)) {
366                 __set_error_message(ERR_FILE_PATH, err_msg);
367                 return MEDIA_SVC_PLUGIN_ERROR;
368         }
369
370         if (!STRING_VALID(mime_type)) {
371                 __set_error_message(ERR_MIME_TYPE, err_msg);
372                 return MEDIA_SVC_PLUGIN_ERROR;
373         }
374
375         if(!STORAGE_VALID(storage_type)) {
376                 __set_error_message(ERR_STORAGE_TYPE, err_msg);
377                 return MEDIA_SVC_PLUGIN_ERROR;
378         }
379
380         media_svc_media_type_e content_type = __get_content_type(file_path, mime_type);
381
382         ret = media_svc_insert_item_bulk(handle, storage_type, file_path, mime_type, content_type, FALSE);
383         if(ret < 0) {
384                 __set_error_message(ret, err_msg);
385                 return MEDIA_SVC_PLUGIN_ERROR;
386         }
387
388         return MEDIA_SVC_PLUGIN_ERROR_NONE;
389 }
390
391 int insert_item_immediately(void * handle, const char *file_path, int storage_type, const char * mime_type, char ** err_msg)
392 {
393         int ret = MEDIA_SVC_PLUGIN_ERROR_NONE;
394
395         if(handle == NULL) {
396                 __set_error_message(ERR_HANDLE, err_msg);
397                 return MEDIA_SVC_PLUGIN_ERROR;
398         }
399
400         if (!STRING_VALID(file_path)) {
401                 __set_error_message(ERR_FILE_PATH, err_msg);
402                 return MEDIA_SVC_PLUGIN_ERROR;
403         }
404
405         if (!STRING_VALID(mime_type)) {
406                 __set_error_message(ERR_MIME_TYPE, err_msg);
407                 return MEDIA_SVC_PLUGIN_ERROR;
408         }
409
410         if(!STORAGE_VALID(storage_type)) {
411                 __set_error_message(ERR_STORAGE_TYPE, err_msg);
412                 return MEDIA_SVC_PLUGIN_ERROR;
413         }
414
415         media_svc_media_type_e content_type = __get_content_type(file_path, mime_type);
416
417         ret = media_svc_insert_item_immediately(handle, storage_type, file_path, mime_type, content_type);
418
419         if(ret < 0) {
420                 __set_error_message(ret, err_msg);
421                 return MEDIA_SVC_PLUGIN_ERROR;
422         }
423
424         return MEDIA_SVC_PLUGIN_ERROR_NONE;
425 }
426
427 int insert_burst_item(void * handle, const char *file_path, int storage_type, const char * mime_type, char ** err_msg)
428 {
429         int ret = MEDIA_SVC_PLUGIN_ERROR_NONE;
430
431         if(handle == NULL) {
432                 __set_error_message(ERR_HANDLE, err_msg);
433                 return MEDIA_SVC_PLUGIN_ERROR;
434         }
435
436         if (!STRING_VALID(file_path)) {
437                 __set_error_message(ERR_FILE_PATH, err_msg);
438                 return MEDIA_SVC_PLUGIN_ERROR;
439         }
440
441         if (!STRING_VALID(mime_type)) {
442                 __set_error_message(ERR_MIME_TYPE, err_msg);
443                 return MEDIA_SVC_PLUGIN_ERROR;
444         }
445
446         if(!STORAGE_VALID(storage_type)) {
447                 __set_error_message(ERR_STORAGE_TYPE, err_msg);
448                 return MEDIA_SVC_PLUGIN_ERROR;
449         }
450
451         media_svc_media_type_e content_type = __get_content_type(file_path, mime_type);
452
453         ret = media_svc_insert_item_bulk(handle, storage_type, file_path, mime_type, content_type, TRUE);
454         if(ret < 0) {
455                 __set_error_message(ret, err_msg);
456                 return MEDIA_SVC_PLUGIN_ERROR;
457         }
458
459         return MEDIA_SVC_PLUGIN_ERROR_NONE;
460 }
461
462 int move_item_begin(void * handle, int item_cnt, char ** err_msg)
463 {
464         int ret = MEDIA_SVC_PLUGIN_ERROR_NONE;
465
466         if(handle == NULL) {
467                 __set_error_message(ERR_HANDLE, err_msg);
468                 return MEDIA_SVC_PLUGIN_ERROR;
469         }
470
471         ret = media_svc_move_item_begin(handle, item_cnt);
472         if(ret < 0) {
473                 __set_error_message(ret, err_msg);
474                 return MEDIA_SVC_PLUGIN_ERROR;
475         }
476
477         return MEDIA_SVC_PLUGIN_ERROR_NONE;
478 }
479
480 int move_item_end(void * handle, char ** err_msg)
481 {
482         int ret = MEDIA_SVC_PLUGIN_ERROR_NONE;
483
484         if(handle == NULL) {
485                 __set_error_message(ERR_HANDLE, err_msg);
486                 return MEDIA_SVC_PLUGIN_ERROR;
487         }
488
489         ret = media_svc_move_item_end(handle);
490         if(ret < 0) {
491                 __set_error_message(ret, err_msg);
492                 return MEDIA_SVC_PLUGIN_ERROR;
493         }
494
495         return MEDIA_SVC_PLUGIN_ERROR_NONE;
496 }
497
498 int move_item(void * handle, const char *src_path, int src_storage_type, const char *dest_path, int dest_storage_type, const char * mime_type, char ** err_msg)
499 {
500         int ret = MEDIA_SVC_PLUGIN_ERROR_NONE;
501
502         if(handle == NULL) {
503                 __set_error_message(ERR_HANDLE, err_msg);
504                 return MEDIA_SVC_PLUGIN_ERROR;
505         }
506
507         if ((!STRING_VALID(src_path)) || (!STRING_VALID(dest_path))) {
508                 __set_error_message(ERR_FILE_PATH, err_msg);
509                 return MEDIA_SVC_PLUGIN_ERROR;
510         }
511
512         if (!STRING_VALID(mime_type)) {
513                 __set_error_message(ERR_MIME_TYPE, err_msg);
514                 return MEDIA_SVC_PLUGIN_ERROR;
515         }
516
517         if((!STORAGE_VALID(src_storage_type)) || (!STORAGE_VALID(dest_storage_type))) {
518                 __set_error_message(ERR_STORAGE_TYPE, err_msg);
519                 return MEDIA_SVC_PLUGIN_ERROR;
520         }
521
522         ret = media_svc_move_item(handle, src_storage_type, src_path, dest_storage_type, dest_path);
523         if(ret < 0) {
524                 __set_error_message(ret, err_msg);
525                 return MEDIA_SVC_PLUGIN_ERROR;
526         }
527
528         return MEDIA_SVC_PLUGIN_ERROR_NONE;
529 }
530
531 int set_all_storage_items_validity(void * handle, int storage_type, int validity, char ** err_msg)
532 {
533         int ret = MEDIA_SVC_PLUGIN_ERROR_NONE;
534
535         if(handle == NULL) {
536                 __set_error_message(ERR_HANDLE, err_msg);
537                 return MEDIA_SVC_PLUGIN_ERROR;
538         }
539
540         if(!STORAGE_VALID(storage_type)) {
541                 __set_error_message(ERR_STORAGE_TYPE, err_msg);
542                 return MEDIA_SVC_PLUGIN_ERROR;
543         }
544
545         ret = media_svc_set_all_storage_items_validity(handle, storage_type, validity);
546         if(ret < 0) {
547                 __set_error_message(ret, err_msg);
548                 return MEDIA_SVC_PLUGIN_ERROR;
549         }
550
551         return MEDIA_SVC_PLUGIN_ERROR_NONE;
552 }
553
554 int set_folder_item_validity(void * handle, const char * folder_path, int validity, int recursive, char ** err_msg)
555 {
556         int ret = MEDIA_SVC_PLUGIN_ERROR_NONE;
557
558         if(handle == NULL) {
559                 __set_error_message(ERR_HANDLE, err_msg);
560                 return MEDIA_SVC_PLUGIN_ERROR;
561         }
562
563         if (!STRING_VALID(folder_path)) {
564                 __set_error_message(ERR_FOLDER_PATH, err_msg);
565                 return MEDIA_SVC_PLUGIN_ERROR;
566         }
567
568         ret = media_svc_set_folder_items_validity(handle, folder_path, validity, recursive);
569         if(ret < 0) {
570                 __set_error_message(ret, err_msg);
571                 return MEDIA_SVC_PLUGIN_ERROR;
572         }
573
574         return MEDIA_SVC_PLUGIN_ERROR_NONE;
575 }
576
577 int set_item_validity_begin(void * handle, int item_cnt, char ** err_msg)
578 {
579         int ret = MEDIA_SVC_PLUGIN_ERROR_NONE;
580
581         if(handle == NULL) {
582                 __set_error_message(ERR_HANDLE, err_msg);
583                 return MEDIA_SVC_PLUGIN_ERROR;
584         }
585
586         ret = media_svc_set_item_validity_begin(handle, item_cnt);
587         if(ret < 0) {
588                 __set_error_message(ret, err_msg);
589                 return MEDIA_SVC_PLUGIN_ERROR;
590         }
591
592         return MEDIA_SVC_PLUGIN_ERROR_NONE;
593 }
594
595 int set_item_validity_end(void * handle, char ** err_msg)
596 {
597         int ret = MEDIA_SVC_PLUGIN_ERROR_NONE;
598
599         if(handle == NULL) {
600                 __set_error_message(ERR_HANDLE, err_msg);
601                 return MEDIA_SVC_PLUGIN_ERROR;
602         }
603
604         ret = media_svc_set_item_validity_end(handle);
605         if(ret < 0) {
606                 __set_error_message(ret, err_msg);
607                 return MEDIA_SVC_PLUGIN_ERROR;
608         }
609
610         return MEDIA_SVC_PLUGIN_ERROR_NONE;
611 }
612
613 int set_item_validity(void * handle, const char *file_path, int storage_type, const char * mime_type, int validity, char ** err_msg)
614 {
615         int ret = MEDIA_SVC_PLUGIN_ERROR_NONE;
616
617         if(handle == NULL) {
618                 __set_error_message(ERR_HANDLE, err_msg);
619                 return MEDIA_SVC_PLUGIN_ERROR;
620         }
621
622         if (!STRING_VALID(file_path)) {
623                 __set_error_message(ERR_FILE_PATH, err_msg);
624                 return MEDIA_SVC_PLUGIN_ERROR;
625         }
626
627         if (!STRING_VALID(mime_type)) {
628                 __set_error_message(ERR_MIME_TYPE, err_msg);
629                 return MEDIA_SVC_PLUGIN_ERROR;
630         }
631
632         if(!STORAGE_VALID(storage_type)) {
633                 __set_error_message(ERR_STORAGE_TYPE, err_msg);
634                 return MEDIA_SVC_PLUGIN_ERROR;
635         }
636
637         ret = media_svc_set_item_validity(handle, file_path, validity);
638
639         if(ret < 0) {
640                 __set_error_message(ret, err_msg);
641                 return MEDIA_SVC_PLUGIN_ERROR;
642         }
643
644         return MEDIA_SVC_PLUGIN_ERROR_NONE;
645 }
646
647 int delete_item(void * handle, const char *file_path, int storage_type, char ** err_msg)
648 {
649         int ret = MEDIA_SVC_PLUGIN_ERROR_NONE;
650
651         if(handle == NULL) {
652                 __set_error_message(ERR_HANDLE, err_msg);
653                 return MEDIA_SVC_PLUGIN_ERROR;
654         }
655
656         if (!STRING_VALID(file_path)) {
657                 __set_error_message(ERR_FILE_PATH, err_msg);
658                 return MEDIA_SVC_PLUGIN_ERROR;
659         }
660
661         if(!STORAGE_VALID(storage_type)) {
662                 __set_error_message(ERR_STORAGE_TYPE, err_msg);
663                 return MEDIA_SVC_PLUGIN_ERROR;
664         }
665
666         ret = media_svc_check_item_exist_by_path(handle, file_path);
667         if(ret == 0) {
668                 ret = media_svc_delete_item_by_path(handle, file_path);
669
670                 if(ret < 0) {
671                         __set_error_message(ret, err_msg);
672                         return MEDIA_SVC_PLUGIN_ERROR;
673                 }
674                 else
675                         return MEDIA_SVC_PLUGIN_ERROR_NONE;
676         }
677
678         __set_error_message(ERR_CHECK_ITEM, err_msg);   //not exist in DB so can't delete item.
679         return MEDIA_SVC_PLUGIN_ERROR;
680 }
681
682 int delete_all_items_in_storage(void * handle, int storage_type, char ** err_msg)
683 {
684         int ret = MEDIA_SVC_PLUGIN_ERROR_NONE;
685
686         if(handle == NULL) {
687                 __set_error_message(ERR_HANDLE, err_msg);
688                 return MEDIA_SVC_PLUGIN_ERROR;
689         }
690
691         if(!STORAGE_VALID(storage_type)) {
692                 __set_error_message(ERR_STORAGE_TYPE, err_msg);
693                 return MEDIA_SVC_PLUGIN_ERROR;
694         }
695
696         ret = media_svc_delete_all_items_in_storage(handle, storage_type);
697         if(ret < 0) {
698                         __set_error_message(ret, err_msg);
699                         return MEDIA_SVC_PLUGIN_ERROR;
700         }
701
702         return MEDIA_SVC_PLUGIN_ERROR_NONE;
703 }
704
705 int delete_all_invalid_items_in_storage(void * handle, int storage_type, char ** err_msg)
706 {
707         int ret = MEDIA_SVC_PLUGIN_ERROR_NONE;
708
709         if(handle == NULL) {
710                 __set_error_message(ERR_HANDLE, err_msg);
711                 return MEDIA_SVC_PLUGIN_ERROR;
712         }
713
714         if(!STORAGE_VALID(storage_type)) {
715                 __set_error_message(ERR_STORAGE_TYPE, err_msg);
716                 return MEDIA_SVC_PLUGIN_ERROR;
717         }
718
719         ret = media_svc_delete_invalid_items_in_storage(handle, storage_type);
720         if(ret < 0) {
721                         __set_error_message(ret, err_msg);
722                         return MEDIA_SVC_PLUGIN_ERROR;
723         }
724
725         return MEDIA_SVC_PLUGIN_ERROR_NONE;
726 }
727
728 int delete_all_invalid_items_in_folder(void * handle, const char *folder_path, char ** err_msg)
729 {
730         int ret = MEDIA_SVC_PLUGIN_ERROR_NONE;
731
732         if(handle == NULL) {
733                 __set_error_message(ERR_HANDLE, err_msg);
734                 return MEDIA_SVC_PLUGIN_ERROR;
735         }
736
737         if (!STRING_VALID(folder_path)) {
738                 __set_error_message(ERR_FOLDER_PATH, err_msg);
739                 return MEDIA_SVC_PLUGIN_ERROR;
740         }
741
742         ret = media_svc_delete_invalid_items_in_folder(handle, folder_path);
743         if(ret < 0) {
744                 __set_error_message(ret, err_msg);
745                 return MEDIA_SVC_PLUGIN_ERROR;
746         }
747
748         return MEDIA_SVC_PLUGIN_ERROR_NONE;
749 }
750
751 int delete_all_items(void * handle, char ** err_msg)
752 {
753         int ret = MEDIA_SVC_PLUGIN_ERROR_NONE;
754
755         if(handle == NULL) {
756                 __set_error_message(ERR_HANDLE, err_msg);
757                 return MEDIA_SVC_PLUGIN_ERROR;
758         }
759
760         ret = delete_all_items_in_storage(handle, MEDIA_SVC_STORAGE_INTERNAL, err_msg);
761         if(ret < 0)
762                 return MEDIA_SVC_PLUGIN_ERROR;
763
764         ret = delete_all_items_in_storage(handle, MEDIA_SVC_STORAGE_EXTERNAL, err_msg);
765         if(ret < 0)
766                 return MEDIA_SVC_PLUGIN_ERROR;
767
768         return MEDIA_SVC_PLUGIN_ERROR_NONE;
769 }
770
771 int refresh_item(void * handle, const char *file_path, int storage_type, const char * mime_type, char ** err_msg)
772 {
773         int ret = MEDIA_SVC_PLUGIN_ERROR_NONE;
774
775         if(handle == NULL) {
776                 __set_error_message(ERR_HANDLE, err_msg);
777                 return MEDIA_SVC_PLUGIN_ERROR;
778         }
779
780         if (!STRING_VALID(file_path)) {
781                 __set_error_message(ERR_FILE_PATH, err_msg);
782                 return MEDIA_SVC_PLUGIN_ERROR;
783         }
784
785         if (!STRING_VALID(mime_type)) {
786                 __set_error_message(ERR_MIME_TYPE, err_msg);
787                 return MEDIA_SVC_PLUGIN_ERROR;
788         }
789
790         if(!STORAGE_VALID(storage_type)) {
791                 __set_error_message(ERR_STORAGE_TYPE, err_msg);
792                 return MEDIA_SVC_PLUGIN_ERROR;
793         }
794
795         media_svc_media_type_e content_type = __get_content_type(file_path, mime_type);
796
797         ret = media_svc_refresh_item(handle, storage_type, file_path, content_type);
798
799         if(ret < 0) {
800                 __set_error_message(ret, err_msg);
801                 return MEDIA_SVC_PLUGIN_ERROR;
802         }
803
804         return MEDIA_SVC_PLUGIN_ERROR_NONE;
805 }
806
807 int update_begin(void)
808 {
809         return MEDIA_SVC_PLUGIN_ERROR_NONE;
810 }
811
812 int update_end(void)
813 {
814         int ret = MEDIA_SVC_PLUGIN_ERROR_NONE;
815
816         ret = thumbnail_request_extract_all_thumbs();
817         if (ret < 0) {
818                 return MEDIA_SVC_PLUGIN_ERROR;
819         }
820
821         return MEDIA_SVC_PLUGIN_ERROR_NONE;
822 }
823
824 int send_dir_update_noti(void * handle, const char *dir_path, char **err_msg)
825 {
826         int ret = MEDIA_SVC_PLUGIN_ERROR_NONE;
827
828         if (!STRING_VALID(dir_path)) {
829                 __set_error_message(ERR_FOLDER_PATH, err_msg);
830                 return MEDIA_SVC_PLUGIN_ERROR;
831         }
832
833         ret = media_svc_send_dir_update_noti(handle, dir_path);
834         if (ret < 0) {
835                 __set_error_message(ret, err_msg);
836                 return MEDIA_SVC_PLUGIN_ERROR;
837         }
838
839         return MEDIA_SVC_PLUGIN_ERROR_NONE;
840 }