Tizen 2.0 beta
[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 #include "audio-svc.h"
27 #include "visual-svc.h"
28
29 #define MEDIA_SVC_PLUGIN_ERROR_NONE             0
30 #define MEDIA_SVC_PLUGIN_ERROR                  -1
31
32 #define STRING_VALID(str)       \
33         ((str != NULL && strlen(str) > 0) ? TRUE : FALSE)
34 #define STORAGE_VALID(storage)\
35         (((storage == MEDIA_SVC_STORAGE_INTERNAL) || (storage == MEDIA_SVC_STORAGE_EXTERNAL)) ? TRUE : FALSE)
36
37
38 typedef enum{
39         ERR_FILE_PATH = 1,
40         ERR_HANDLE,
41         ERR_MIME_TYPE,
42         ERR_NOT_MEDIAFILE,
43         ERR_STORAGE_TYPE,
44         ERR_CHECK_ITEM,
45         ERR_MAX,
46 }media_svc_error_type_e;
47
48 #define MS_CATEGORY_UNKNOWN     0x00000000      /**< Default */
49 #define MS_CATEGORY_ETC         0x00000001      /**< ETC category */
50 #define MS_CATEGORY_IMAGE               0x00000002      /**< Image category */
51 #define MS_CATEGORY_VIDEO               0x00000004      /**< Video category */
52 #define MS_CATEGORY_MUSIC               0x00000008      /**< Music category */
53 #define MS_CATEGORY_SOUND       0x00000010      /**< Sound category */
54
55 #define CONTENT_TYPE_NUM 4
56 #define MUSIC_MIME_NUM 28
57 #define SOUND_MIME_NUM 1
58 #define MIME_TYPE_LENGTH 255
59 #define MIME_LENGTH 50
60 #define _3GP_FILE ".3gp"
61 #define _MP4_FILE ".mp4"
62
63
64 typedef struct {
65         char content_type[15];
66         int category_by_mime;
67 } fex_content_table_t;
68
69 static const fex_content_table_t content_category[CONTENT_TYPE_NUM] = {
70         {"audio", MS_CATEGORY_SOUND},
71         {"image", MS_CATEGORY_IMAGE},
72         {"video", MS_CATEGORY_VIDEO},
73         {"application", MS_CATEGORY_ETC},
74 };
75
76 static const char music_mime_table[MUSIC_MIME_NUM][MIME_LENGTH] = {
77         /*known mime types of normal files*/
78         "mpeg",
79         "ogg",
80         "x-ms-wma",
81         "x-flac",
82         "mp4",
83         /* known mime types of drm files*/
84         "mp3",
85         "x-mp3", /*alias of audio/mpeg*/
86         "x-mpeg", /*alias of audio/mpeg*/
87         "3gpp",
88         "x-ogg", /*alias of  audio/ogg*/
89         "vnd.ms-playready.media.pya:*.pya", /*playready*/
90         "wma",
91         "aac",
92         "x-m4a", /*alias of audio/mp4*/
93         /* below mimes are rare*/
94         "x-vorbis+ogg",
95         "x-flac+ogg",
96         "x-matroska",
97         "ac3",
98         "mp2",
99         "x-ape",
100         "x-ms-asx",
101         "vnd.rn-realaudio",
102
103         "x-vorbis", /*alias of audio/x-vorbis+ogg*/
104         "vorbis", /*alias of audio/x-vorbis+ogg*/
105         "x-oggflac",
106         "x-mp2", /*alias of audio/mp2*/
107         "x-pn-realaudio", /*alias of audio/vnd.rn-realaudio*/
108         "vnd.m-realaudio", /*alias of audio/vnd.rn-realaudio*/
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         } else if (*category & MS_CATEGORY_VIDEO) {
163                 /*some video files don't have video stream. in this case it is categorize as music. */
164                 char *ext;
165                 /*"3gp" and "mp4" must check video stream and then categorize in directly. */
166                 ext = strrchr(path, '.');
167                 if (ext != NULL) {
168                         if ((strncasecmp(ext, _3GP_FILE, 4) == 0) || (strncasecmp(ext, _MP4_FILE, 5) == 0)) {
169                                 int audio = 0;
170                                 int video = 0;
171
172                                 err = mm_file_get_stream_info(path, &audio, &video);
173                                 if (err == 0) {
174                                         if (audio > 0 && video == 0) {
175                                                 *category ^= MS_CATEGORY_VIDEO;
176                                                 *category |= MS_CATEGORY_MUSIC;
177                                         }
178                                 }
179                         }
180                 }
181         }
182
183         //MS_DBG("category_from_ext : %d", *category);
184
185         return err;
186 }
187
188 static int __get_content_type(const char * file_path, const char * mime_type)
189 {
190         int ret = MEDIA_SVC_PLUGIN_ERROR_NONE;
191         int category = 0;
192
193         ret = __get_content_type_from_mime(file_path, mime_type, &category);
194         if(ret < 0)
195                 return ret;
196
197         if (category & MS_CATEGORY_SOUND)               return MEDIA_SVC_MEDIA_TYPE_SOUND;
198         else if (category & MS_CATEGORY_MUSIC)  return MEDIA_SVC_MEDIA_TYPE_MUSIC;
199         else if (category & MS_CATEGORY_IMAGE)  return MEDIA_SVC_MEDIA_TYPE_IMAGE;
200         else if (category & MS_CATEGORY_VIDEO)  return MEDIA_SVC_MEDIA_TYPE_VIDEO;
201         else    return MEDIA_SVC_MEDIA_TYPE_OTHER;
202 }
203
204 static void __set_error_message(int err_type, char ** err_msg)
205 {
206         if (err_msg)
207                 *err_msg = NULL;
208
209         if(err_type == ERR_FILE_PATH)
210                 *err_msg = strdup("invalid file path");
211         if(err_type == ERR_HANDLE)
212                 *err_msg = strdup("invalid handle");
213         else if(err_type == ERR_MIME_TYPE)
214                 *err_msg = strdup("invalid mime type");
215         else if(err_type == ERR_NOT_MEDIAFILE)
216                 *err_msg = strdup("not media content");
217         else if(err_type == ERR_STORAGE_TYPE)
218                         *err_msg = strdup("invalid storage type");
219         else if(err_type == ERR_CHECK_ITEM)
220                 *err_msg = strdup("item does not exist");
221         else if(err_type == MEDIA_INFO_ERROR_DATABASE_CONNECT)
222                 *err_msg = strdup("DB connect error");
223         else if(err_type == MEDIA_INFO_ERROR_DATABASE_DISCONNECT)
224                 *err_msg = strdup("DB disconnect error");
225         else if((err_type == AUDIO_SVC_ERROR_INVALID_PARAMETER) || (err_type == MB_SVC_ERROR_INVALID_PARAMETER) || (err_type == MEDIA_INFO_ERROR_INVALID_PARAMETER))
226                 *err_msg = strdup("invalid parameter");
227         else if((err_type == AUDIO_SVC_ERROR_DB_INTERNAL) ||(err_type == MB_SVC_ERROR_DB_INTERNAL) ||(err_type == MEDIA_INFO_ERROR_DATABASE_INTERNAL))
228                 *err_msg = strdup("DB internal error");
229         else if((err_type == AUDIO_SVC_ERROR_INTERNAL) ||(err_type == MB_SVC_ERROR_INTERNAL) || (err_type == MEDIA_INFO_ERROR_INTERNAL))
230                 *err_msg = strdup("media service internal error");
231         else
232                 *err_msg = strdup("error unknown");
233
234 }
235
236 int check_item(const char *file_path, const char * mime_type, char ** err_msg)
237 {
238         if (!STRING_VALID(file_path)) {
239                 __set_error_message(ERR_FILE_PATH, err_msg);
240                 return MEDIA_SVC_PLUGIN_ERROR;
241         }
242
243         if (!STRING_VALID(mime_type)) {
244                 __set_error_message(ERR_MIME_TYPE, err_msg);
245                 return MEDIA_SVC_PLUGIN_ERROR;
246         }
247
248         return MEDIA_SVC_PLUGIN_ERROR_NONE;
249 }
250
251 int connect(void ** handle, char ** err_msg)
252 {
253         int ret = media_svc_connect(handle);
254
255         if(ret < 0) {
256                 __set_error_message(ret, err_msg);
257                 return MEDIA_SVC_PLUGIN_ERROR;
258         }
259
260         return MEDIA_SVC_PLUGIN_ERROR_NONE;
261 }
262
263 int disconnect(void * handle, char ** err_msg)
264 {
265         int ret = MEDIA_SVC_PLUGIN_ERROR_NONE;
266
267         if(handle == NULL) {
268                 __set_error_message(ERR_HANDLE, err_msg);
269                 return MEDIA_SVC_PLUGIN_ERROR;
270         }
271
272         ret = media_svc_disconnect(handle);
273         if(ret < 0) {
274                 __set_error_message(ret, err_msg);
275                 return MEDIA_SVC_PLUGIN_ERROR;
276         }
277
278         return MEDIA_SVC_PLUGIN_ERROR_NONE;
279 }
280
281 int check_item_exist(void* handle, const char *file_path, int storage_type, char ** err_msg)
282 {
283         int ret = MEDIA_SVC_PLUGIN_ERROR_NONE;
284
285         if(handle == NULL) {
286                 __set_error_message(ERR_HANDLE, err_msg);
287                 return MEDIA_SVC_PLUGIN_ERROR;
288         }
289
290         if (!STRING_VALID(file_path)) {
291                 __set_error_message(ERR_FILE_PATH, err_msg);
292                 return MEDIA_SVC_PLUGIN_ERROR;
293         }
294
295         if(!STORAGE_VALID(storage_type)) {
296                 __set_error_message(ERR_STORAGE_TYPE, err_msg);
297                 return MEDIA_SVC_PLUGIN_ERROR;
298         }
299
300         ret = media_svc_check_item_exist_by_path(handle, file_path);
301         if(ret == MEDIA_INFO_ERROR_NONE)
302                 return MEDIA_SVC_PLUGIN_ERROR_NONE;     //exist
303
304         __set_error_message(ERR_CHECK_ITEM, err_msg);
305
306         return MEDIA_SVC_PLUGIN_ERROR;          //not exist
307 }
308
309 int insert_item_begin(void * handle, int item_cnt, char ** err_msg)
310 {
311         int ret = MEDIA_SVC_PLUGIN_ERROR_NONE;
312
313         if(handle == NULL) {
314                 __set_error_message(ERR_HANDLE, err_msg);
315                 return MEDIA_SVC_PLUGIN_ERROR;
316         }
317
318         ret = media_svc_insert_item_begin(handle, item_cnt);
319         if(ret < 0) {
320                 __set_error_message(ret, err_msg);
321                 return MEDIA_SVC_PLUGIN_ERROR;
322         }
323
324         return MEDIA_SVC_PLUGIN_ERROR_NONE;
325 }
326
327 int insert_item_end(void * handle, char ** err_msg)
328 {
329         int ret = MEDIA_SVC_PLUGIN_ERROR_NONE;
330
331         if(handle == NULL) {
332                 __set_error_message(ERR_HANDLE, err_msg);
333                 return MEDIA_SVC_PLUGIN_ERROR;
334         }
335
336         ret = media_svc_insert_item_end(handle);
337         if(ret < 0) {
338                 __set_error_message(ret, err_msg);
339                 return MEDIA_SVC_PLUGIN_ERROR;
340         }
341
342         return MEDIA_SVC_PLUGIN_ERROR_NONE;
343 }
344
345 int insert_item(void * handle, const char *file_path, int storage_type, const char * mime_type, char ** err_msg)
346 {
347         int ret = MEDIA_SVC_PLUGIN_ERROR_NONE;
348
349         if(handle == NULL) {
350                 __set_error_message(ERR_HANDLE, err_msg);
351                 return MEDIA_SVC_PLUGIN_ERROR;
352         }
353
354         if (!STRING_VALID(file_path)) {
355                 __set_error_message(ERR_FILE_PATH, err_msg);
356                 return MEDIA_SVC_PLUGIN_ERROR;
357         }
358
359         if (!STRING_VALID(mime_type)) {
360                 __set_error_message(ERR_MIME_TYPE, err_msg);
361                 return MEDIA_SVC_PLUGIN_ERROR;
362         }
363
364         if(!STORAGE_VALID(storage_type)) {
365                 __set_error_message(ERR_STORAGE_TYPE, err_msg);
366                 return MEDIA_SVC_PLUGIN_ERROR;
367         }
368
369         media_svc_media_type_e content_type = __get_content_type(file_path, mime_type);
370
371         ret = media_svc_insert_item_bulk(handle, storage_type, file_path, mime_type, content_type);
372         if(ret < 0) {
373                 __set_error_message(ret, err_msg);
374                 return MEDIA_SVC_PLUGIN_ERROR;
375         }
376
377         return MEDIA_SVC_PLUGIN_ERROR_NONE;
378 }
379
380 int insert_item_immediately(void * handle, const char *file_path, int storage_type, const char * mime_type, char ** err_msg)
381 {
382         int ret = MEDIA_SVC_PLUGIN_ERROR_NONE;
383
384         if(handle == NULL) {
385                 __set_error_message(ERR_HANDLE, err_msg);
386                 return MEDIA_SVC_PLUGIN_ERROR;
387         }
388
389         if (!STRING_VALID(file_path)) {
390                 __set_error_message(ERR_FILE_PATH, err_msg);
391                 return MEDIA_SVC_PLUGIN_ERROR;
392         }
393
394         if (!STRING_VALID(mime_type)) {
395                 __set_error_message(ERR_MIME_TYPE, err_msg);
396                 return MEDIA_SVC_PLUGIN_ERROR;
397         }
398
399         if(!STORAGE_VALID(storage_type)) {
400                 __set_error_message(ERR_STORAGE_TYPE, err_msg);
401                 return MEDIA_SVC_PLUGIN_ERROR;
402         }
403
404         media_svc_media_type_e content_type = __get_content_type(file_path, mime_type);
405
406         ret = media_svc_insert_item_immediately(handle, storage_type, file_path, mime_type, content_type);
407
408         if(ret < 0) {
409                 __set_error_message(ret, err_msg);
410                 return MEDIA_SVC_PLUGIN_ERROR;
411         }
412
413         return MEDIA_SVC_PLUGIN_ERROR_NONE;
414 }
415
416 int move_item_begin(void * handle, int item_cnt, char ** err_msg)
417 {
418         int ret = MEDIA_SVC_PLUGIN_ERROR_NONE;
419
420         if(handle == NULL) {
421                 __set_error_message(ERR_HANDLE, err_msg);
422                 return MEDIA_SVC_PLUGIN_ERROR;
423         }
424
425         ret = media_svc_move_item_begin(handle, item_cnt);
426         if(ret < 0) {
427                 __set_error_message(ret, err_msg);
428                 return MEDIA_SVC_PLUGIN_ERROR;
429         }
430
431         return MEDIA_SVC_PLUGIN_ERROR_NONE;
432 }
433
434 int move_item_end(void * handle, char ** err_msg)
435 {
436         int ret = MEDIA_SVC_PLUGIN_ERROR_NONE;
437
438         if(handle == NULL) {
439                 __set_error_message(ERR_HANDLE, err_msg);
440                 return MEDIA_SVC_PLUGIN_ERROR;
441         }
442
443         ret = media_svc_move_item_end(handle);
444         if(ret < 0) {
445                 __set_error_message(ret, err_msg);
446                 return MEDIA_SVC_PLUGIN_ERROR;
447         }
448
449         return MEDIA_SVC_PLUGIN_ERROR_NONE;
450 }
451
452 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)
453 {
454         int ret = MEDIA_SVC_PLUGIN_ERROR_NONE;
455
456         if(handle == NULL) {
457                 __set_error_message(ERR_HANDLE, err_msg);
458                 return MEDIA_SVC_PLUGIN_ERROR;
459         }
460
461         if ((!STRING_VALID(src_path)) || (!STRING_VALID(dest_path))) {
462                 __set_error_message(ERR_FILE_PATH, err_msg);
463                 return MEDIA_SVC_PLUGIN_ERROR;
464         }
465
466         if (!STRING_VALID(mime_type)) {
467                 __set_error_message(ERR_MIME_TYPE, err_msg);
468                 return MEDIA_SVC_PLUGIN_ERROR;
469         }
470
471         if((!STORAGE_VALID(src_storage_type)) || (!STORAGE_VALID(dest_storage_type))) {
472                 __set_error_message(ERR_STORAGE_TYPE, err_msg);
473                 return MEDIA_SVC_PLUGIN_ERROR;
474         }
475
476         ret = media_svc_move_item(handle, src_storage_type, src_path, dest_storage_type, dest_path);
477         if(ret < 0) {
478                 __set_error_message(ret, err_msg);
479                 return MEDIA_SVC_PLUGIN_ERROR;
480         }
481
482         return MEDIA_SVC_PLUGIN_ERROR_NONE;
483 }
484
485 int set_all_storage_items_validity(void * handle, int storage_type, int validity, char ** err_msg)
486 {
487         int ret = MEDIA_SVC_PLUGIN_ERROR_NONE;
488
489         if(handle == NULL) {
490                 __set_error_message(ERR_HANDLE, err_msg);
491                 return MEDIA_SVC_PLUGIN_ERROR;
492         }
493
494         if(!STORAGE_VALID(storage_type)) {
495                 __set_error_message(ERR_STORAGE_TYPE, err_msg);
496                 return MEDIA_SVC_PLUGIN_ERROR;
497         }
498
499         ret = media_svc_set_all_storage_items_validity(handle, storage_type, validity);
500         if(ret < 0) {
501                 __set_error_message(ret, err_msg);
502                 return MEDIA_SVC_PLUGIN_ERROR;
503         }
504
505         return MEDIA_SVC_PLUGIN_ERROR_NONE;
506 }
507
508 int set_item_validity_begin(void * handle, int item_cnt, char ** err_msg)
509 {
510         int ret = MEDIA_SVC_PLUGIN_ERROR_NONE;
511
512         if(handle == NULL) {
513                 __set_error_message(ERR_HANDLE, err_msg);
514                 return MEDIA_SVC_PLUGIN_ERROR;
515         }
516
517         ret = media_svc_set_item_validity_begin(handle, item_cnt);
518         if(ret < 0) {
519                 __set_error_message(ret, err_msg);
520                 return MEDIA_SVC_PLUGIN_ERROR;
521         }
522
523         return MEDIA_SVC_PLUGIN_ERROR_NONE;
524 }
525
526 int set_item_validity_end(void * handle, char ** err_msg)
527 {
528         int ret = MEDIA_SVC_PLUGIN_ERROR_NONE;
529
530         if(handle == NULL) {
531                 __set_error_message(ERR_HANDLE, err_msg);
532                 return MEDIA_SVC_PLUGIN_ERROR;
533         }
534
535         ret = media_svc_set_item_validity_end(handle);
536         if(ret < 0) {
537                 __set_error_message(ret, err_msg);
538                 return MEDIA_SVC_PLUGIN_ERROR;
539         }
540
541         return MEDIA_SVC_PLUGIN_ERROR_NONE;
542 }
543
544 int set_item_validity(void * handle, const char *file_path, int storage_type, const char * mime_type, int validity, char ** err_msg)
545 {
546         int ret = MEDIA_SVC_PLUGIN_ERROR_NONE;
547
548         if(handle == NULL) {
549                 __set_error_message(ERR_HANDLE, err_msg);
550                 return MEDIA_SVC_PLUGIN_ERROR;
551         }
552
553         if (!STRING_VALID(file_path)) {
554                 __set_error_message(ERR_FILE_PATH, err_msg);
555                 return MEDIA_SVC_PLUGIN_ERROR;
556         }
557
558         if (!STRING_VALID(mime_type)) {
559                 __set_error_message(ERR_MIME_TYPE, err_msg);
560                 return MEDIA_SVC_PLUGIN_ERROR;
561         }
562
563         if(!STORAGE_VALID(storage_type)) {
564                 __set_error_message(ERR_STORAGE_TYPE, err_msg);
565                 return MEDIA_SVC_PLUGIN_ERROR;
566         }
567
568         ret = media_svc_set_item_validity(handle, file_path, validity);
569
570         if(ret < 0) {
571                 __set_error_message(ret, err_msg);
572                 return MEDIA_SVC_PLUGIN_ERROR;
573         }
574
575         return MEDIA_SVC_PLUGIN_ERROR_NONE;
576 }
577
578 int delete_item(void * handle, const char *file_path, int storage_type, char ** err_msg)
579 {
580         int ret = MEDIA_SVC_PLUGIN_ERROR_NONE;
581
582         if(handle == NULL) {
583                 __set_error_message(ERR_HANDLE, err_msg);
584                 return MEDIA_SVC_PLUGIN_ERROR;
585         }
586
587         if (!STRING_VALID(file_path)) {
588                 __set_error_message(ERR_FILE_PATH, err_msg);
589                 return MEDIA_SVC_PLUGIN_ERROR;
590         }
591
592         if(!STORAGE_VALID(storage_type)) {
593                 __set_error_message(ERR_STORAGE_TYPE, err_msg);
594                 return MEDIA_SVC_PLUGIN_ERROR;
595         }
596
597         ret = media_svc_check_item_exist_by_path(handle, file_path);
598         if(ret == 0) {
599                 ret = media_svc_delete_item_by_path(handle, file_path);
600
601                 if(ret < 0) {
602                         __set_error_message(ret, err_msg);
603                         return MEDIA_SVC_PLUGIN_ERROR;
604                 }
605                 else
606                         return MEDIA_SVC_PLUGIN_ERROR_NONE;
607         }
608
609         __set_error_message(ERR_CHECK_ITEM, err_msg);   //not exist in DB so can't delete item.
610         return MEDIA_SVC_PLUGIN_ERROR;
611 }
612
613 int delete_all_items_in_storage(void * handle, int storage_type, 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(!STORAGE_VALID(storage_type)) {
623                 __set_error_message(ERR_STORAGE_TYPE, err_msg);
624                 return MEDIA_SVC_PLUGIN_ERROR;
625         }
626
627         ret = media_svc_delete_all_items_in_storage(handle, storage_type);
628         if(ret < 0) {
629                         __set_error_message(ret, err_msg);
630                         return MEDIA_SVC_PLUGIN_ERROR;
631         }
632
633         return MEDIA_SVC_PLUGIN_ERROR_NONE;
634 }
635
636 int delete_all_invalid_items_in_storage(void * handle, int storage_type, char ** err_msg)
637 {
638         int ret = MEDIA_SVC_PLUGIN_ERROR_NONE;
639
640         if(handle == NULL) {
641                 __set_error_message(ERR_HANDLE, err_msg);
642                 return MEDIA_SVC_PLUGIN_ERROR;
643         }
644
645         if(!STORAGE_VALID(storage_type)) {
646                 __set_error_message(ERR_STORAGE_TYPE, err_msg);
647                 return MEDIA_SVC_PLUGIN_ERROR;
648         }
649
650         ret = media_svc_delete_invalid_items_in_storage(handle, storage_type);
651         if(ret < 0) {
652                         __set_error_message(ret, err_msg);
653                         return MEDIA_SVC_PLUGIN_ERROR;
654         }
655
656         return MEDIA_SVC_PLUGIN_ERROR_NONE;
657 }
658
659 int delete_all_items(void * handle, char ** err_msg)
660 {
661         int ret = MEDIA_SVC_PLUGIN_ERROR_NONE;
662
663         if(handle == NULL) {
664                 __set_error_message(ERR_HANDLE, err_msg);
665                 return MEDIA_SVC_PLUGIN_ERROR;
666         }
667
668         ret = delete_all_items_in_storage(handle, MEDIA_SVC_STORAGE_INTERNAL, err_msg);
669         if(ret < 0)
670                 return MEDIA_SVC_PLUGIN_ERROR;
671
672         ret = delete_all_items_in_storage(handle, MEDIA_SVC_STORAGE_EXTERNAL, err_msg);
673         if(ret < 0)
674                 return MEDIA_SVC_PLUGIN_ERROR;
675
676         return MEDIA_SVC_PLUGIN_ERROR_NONE;
677 }
678
679 int refresh_item(void * handle, const char *file_path, int storage_type, const char * mime_type, char ** err_msg)
680 {
681         int ret = MEDIA_SVC_PLUGIN_ERROR_NONE;
682
683         if(handle == NULL) {
684                 __set_error_message(ERR_HANDLE, err_msg);
685                 return MEDIA_SVC_PLUGIN_ERROR;
686         }
687
688         if (!STRING_VALID(file_path)) {
689                 __set_error_message(ERR_FILE_PATH, err_msg);
690                 return MEDIA_SVC_PLUGIN_ERROR;
691         }
692
693         if (!STRING_VALID(mime_type)) {
694                 __set_error_message(ERR_MIME_TYPE, err_msg);
695                 return MEDIA_SVC_PLUGIN_ERROR;
696         }
697
698         if(!STORAGE_VALID(storage_type)) {
699                 __set_error_message(ERR_STORAGE_TYPE, err_msg);
700                 return MEDIA_SVC_PLUGIN_ERROR;
701         }
702
703         media_svc_media_type_e content_type = __get_content_type(file_path, mime_type);
704
705         ret = media_svc_refresh_item(handle, storage_type, file_path, content_type);
706
707         if(ret < 0) {
708                 __set_error_message(ret, err_msg);
709                 return MEDIA_SVC_PLUGIN_ERROR;
710         }
711
712         return MEDIA_SVC_PLUGIN_ERROR_NONE;
713 }
714
715 int update_begin(void)
716 {
717         return MEDIA_SVC_PLUGIN_ERROR_NONE;
718 }
719
720 int update_end(void)
721 {
722         return MEDIA_SVC_PLUGIN_ERROR_NONE;
723 }