Update for modification of db utilities.
[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 <sys/stat.h>
24 #include <mm_file.h>
25 #include <media-thumbnail.h>
26 #include "media-svc.h"
27 #include "media-svc-util.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_HANDLE = 1,
40         ERR_FILE_PATH,
41         ERR_FOLDER_PATH,
42         ERR_MIME_TYPE,
43         ERR_NOT_MEDIAFILE,
44         ERR_STORAGE_TYPE,
45         ERR_CHECK_ITEM,
46         ERR_MAX,
47 }media_svc_error_type_e;
48
49 static void __set_error_message(int err_type, char ** err_msg);
50
51 static void __set_error_message(int err_type, char ** err_msg)
52 {
53         if (err_msg)
54                 *err_msg = NULL;
55         else
56                 return;
57
58         if(err_type == ERR_HANDLE)
59                 *err_msg = strdup("invalid handle");
60         else if(err_type == ERR_FILE_PATH)
61                 *err_msg = strdup("invalid file path");
62         else if(err_type == ERR_FOLDER_PATH)
63                 *err_msg = strdup("invalid folder path");
64         else if(err_type == ERR_MIME_TYPE)
65                 *err_msg = strdup("invalid mime type");
66         else if(err_type == ERR_NOT_MEDIAFILE)
67                 *err_msg = strdup("not media content");
68         else if(err_type == ERR_STORAGE_TYPE)
69                 *err_msg = strdup("invalid storage type");
70         else if(err_type == ERR_CHECK_ITEM)
71                 *err_msg = strdup("item does not exist");
72         else if(err_type == MS_MEDIA_ERR_DB_CONNECT_FAIL)
73                 *err_msg = strdup("DB connect error");
74         else if(err_type == MS_MEDIA_ERR_DB_DISCONNECT_FAIL)
75                 *err_msg = strdup("DB disconnect error");
76         else if(err_type == MS_MEDIA_ERR_INVALID_PARAMETER)
77                 *err_msg = strdup("invalid parameter");
78         else if(err_type == MS_MEDIA_ERR_DB_INTERNAL)
79                 *err_msg = strdup("DB internal error");
80         else if(err_type == MS_MEDIA_ERR_DB_NO_RECORD)
81                 *err_msg = strdup("not found in DB");
82         else if(err_type == MS_MEDIA_ERR_INTERNAL)
83                 *err_msg = strdup("media service internal error");
84         else if(err_type == MS_MEDIA_ERR_DB_CORRUPT)
85                 *err_msg = strdup("DB corrupt error");
86         else
87                 *err_msg = strdup("error unknown");
88
89         return;
90 }
91
92 int connect_db(void ** handle, uid_t uid, char ** err_msg)
93 {
94         int ret = media_svc_connect(handle, uid);
95
96         if(ret < 0) {
97                 __set_error_message(ret, err_msg);
98                 return MEDIA_SVC_PLUGIN_ERROR;
99         }
100
101         return MEDIA_SVC_PLUGIN_ERROR_NONE;
102 }
103
104 int disconnect_db(void * handle, char ** err_msg)
105 {
106         int ret = MEDIA_SVC_PLUGIN_ERROR_NONE;
107
108         if(handle == NULL) {
109                 __set_error_message(ERR_HANDLE, err_msg);
110                 return MEDIA_SVC_PLUGIN_ERROR;
111         }
112
113         ret = media_svc_disconnect(handle);
114         if(ret < 0) {
115                 __set_error_message(ret, err_msg);
116                 return MEDIA_SVC_PLUGIN_ERROR;
117         }
118
119         return MEDIA_SVC_PLUGIN_ERROR_NONE;
120 }
121
122 int check_item_exist(void* handle, const char *file_path, bool *modified, char ** err_msg)
123 {
124         int ret = MEDIA_SVC_PLUGIN_ERROR_NONE;
125         *modified = TRUE;
126
127         if(handle == NULL) {
128                 __set_error_message(ERR_HANDLE, err_msg);
129                 return MEDIA_SVC_PLUGIN_ERROR;
130         }
131
132         if (!STRING_VALID(file_path)) {
133                 __set_error_message(ERR_FILE_PATH, err_msg);
134                 return MEDIA_SVC_PLUGIN_ERROR;
135         }
136
137         ret = media_svc_check_item_exist_by_path(handle, file_path);
138         if(ret == MS_MEDIA_ERR_NONE) {
139                 time_t modified_time = 0;
140                 unsigned long long file_size = 0;
141                 struct stat st;
142
143                 ret = media_svc_get_file_info(handle, file_path, &modified_time, &file_size);
144                 if(ret == MS_MEDIA_ERR_NONE) {
145                         memset(&st, 0, sizeof(struct stat));
146                         if (stat(file_path, &st) == 0) {
147                                 if((st.st_mtime != modified_time) || (st.st_size != file_size))
148                                         *modified = TRUE;
149                                 else
150                                         *modified = FALSE;
151                         }
152                 }
153
154                 return MEDIA_SVC_PLUGIN_ERROR_NONE;     //exist
155         }
156
157         __set_error_message(ERR_CHECK_ITEM, err_msg);
158
159         return MEDIA_SVC_PLUGIN_ERROR;          //not exist
160 }
161
162 int insert_item_begin(void * handle, int item_cnt, int with_noti, int from_pid, char ** err_msg)
163 {
164         int ret = MEDIA_SVC_PLUGIN_ERROR_NONE;
165
166         if(handle == NULL) {
167                 __set_error_message(ERR_HANDLE, err_msg);
168                 return MEDIA_SVC_PLUGIN_ERROR;
169         }
170
171         ret = media_svc_insert_item_begin(handle, item_cnt, with_noti, from_pid);
172         if(ret < 0) {
173                 __set_error_message(ret, err_msg);
174                 return MEDIA_SVC_PLUGIN_ERROR;
175         }
176
177         return MEDIA_SVC_PLUGIN_ERROR_NONE;
178 }
179
180 int insert_item_end(void * handle, uid_t uid, char ** err_msg)
181 {
182         int ret = MEDIA_SVC_PLUGIN_ERROR_NONE;
183
184         if(handle == NULL) {
185                 __set_error_message(ERR_HANDLE, err_msg);
186                 return MEDIA_SVC_PLUGIN_ERROR;
187         }
188
189         ret = media_svc_insert_item_end(handle, uid);
190         if(ret < 0) {
191                 __set_error_message(ret, err_msg);
192                 return MEDIA_SVC_PLUGIN_ERROR;
193         }
194
195         return MEDIA_SVC_PLUGIN_ERROR_NONE;
196 }
197
198 int insert_item(void * handle, const char *file_path, int storage_type, uid_t uid, char ** err_msg)
199 {
200         int ret = MEDIA_SVC_PLUGIN_ERROR_NONE;
201
202         if(handle == NULL) {
203                 __set_error_message(ERR_HANDLE, err_msg);
204                 return MEDIA_SVC_PLUGIN_ERROR;
205         }
206
207         if (!STRING_VALID(file_path)) {
208                 __set_error_message(ERR_FILE_PATH, err_msg);
209                 return MEDIA_SVC_PLUGIN_ERROR;
210         }
211
212         if(!STORAGE_VALID(storage_type)) {
213                 __set_error_message(ERR_STORAGE_TYPE, err_msg);
214                 return MEDIA_SVC_PLUGIN_ERROR;
215         }
216
217         ret = media_svc_insert_item_bulk(handle, storage_type, file_path, FALSE, uid);
218         if(ret < 0) {
219                 __set_error_message(ret, err_msg);
220                 return MEDIA_SVC_PLUGIN_ERROR;
221         }
222
223         return MEDIA_SVC_PLUGIN_ERROR_NONE;
224 }
225
226 int insert_item_immediately(void * handle, const char *file_path, int storage_type, uid_t uid, char ** err_msg)
227 {
228         int ret = MEDIA_SVC_PLUGIN_ERROR_NONE;
229
230         if(handle == NULL) {
231                 __set_error_message(ERR_HANDLE, err_msg);
232                 return MEDIA_SVC_PLUGIN_ERROR;
233         }
234
235         if (!STRING_VALID(file_path)) {
236                 __set_error_message(ERR_FILE_PATH, err_msg);
237                 return MEDIA_SVC_PLUGIN_ERROR;
238         }
239
240         if(!STORAGE_VALID(storage_type)) {
241                 __set_error_message(ERR_STORAGE_TYPE, err_msg);
242                 return MEDIA_SVC_PLUGIN_ERROR;
243         }
244
245         ret = media_svc_insert_item_immediately(handle, storage_type, file_path, uid);
246         if(ret < 0) {
247                 __set_error_message(ret, err_msg);
248                 return MEDIA_SVC_PLUGIN_ERROR;
249         }
250
251         return MEDIA_SVC_PLUGIN_ERROR_NONE;
252 }
253
254 int insert_burst_item(void * handle, const char *file_path, int storage_type, uid_t uid, char ** err_msg)
255 {
256         int ret = MEDIA_SVC_PLUGIN_ERROR_NONE;
257
258         if(handle == NULL) {
259                 __set_error_message(ERR_HANDLE, err_msg);
260                 return MEDIA_SVC_PLUGIN_ERROR;
261         }
262
263         if (!STRING_VALID(file_path)) {
264                 __set_error_message(ERR_FILE_PATH, err_msg);
265                 return MEDIA_SVC_PLUGIN_ERROR;
266         }
267
268         if(!STORAGE_VALID(storage_type)) {
269                 __set_error_message(ERR_STORAGE_TYPE, err_msg);
270                 return MEDIA_SVC_PLUGIN_ERROR;
271         }
272
273         ret = media_svc_insert_item_bulk(handle, storage_type, file_path, TRUE, uid);
274         if(ret < 0) {
275                 __set_error_message(ret, err_msg);
276                 return MEDIA_SVC_PLUGIN_ERROR;
277         }
278
279         return MEDIA_SVC_PLUGIN_ERROR_NONE;
280 }
281
282 int set_all_storage_items_validity(void * handle, int storage_type, int validity, uid_t uid, char ** err_msg)
283 {
284         int ret = MEDIA_SVC_PLUGIN_ERROR_NONE;
285
286         if(handle == NULL) {
287                 __set_error_message(ERR_HANDLE, err_msg);
288                 return MEDIA_SVC_PLUGIN_ERROR;
289         }
290
291         if(!STORAGE_VALID(storage_type)) {
292                 __set_error_message(ERR_STORAGE_TYPE, err_msg);
293                 return MEDIA_SVC_PLUGIN_ERROR;
294         }
295
296         ret = media_svc_set_all_storage_items_validity(handle, storage_type, validity, uid);
297         if(ret < 0) {
298                 __set_error_message(ret, err_msg);
299                 return MEDIA_SVC_PLUGIN_ERROR;
300         }
301
302         return MEDIA_SVC_PLUGIN_ERROR_NONE;
303 }
304
305 int set_folder_item_validity(void * handle, const char * folder_path, int validity, int recursive, uid_t uid, char ** err_msg)
306 {
307         int ret = MEDIA_SVC_PLUGIN_ERROR_NONE;
308
309         if(handle == NULL) {
310                 __set_error_message(ERR_HANDLE, err_msg);
311                 return MEDIA_SVC_PLUGIN_ERROR;
312         }
313
314         if (!STRING_VALID(folder_path)) {
315                 __set_error_message(ERR_FOLDER_PATH, err_msg);
316                 return MEDIA_SVC_PLUGIN_ERROR;
317         }
318
319         ret = media_svc_set_folder_items_validity(handle, folder_path, validity, recursive, uid);
320         if(ret < 0) {
321                 __set_error_message(ret, err_msg);
322                 return MEDIA_SVC_PLUGIN_ERROR;
323         }
324
325         return MEDIA_SVC_PLUGIN_ERROR_NONE;
326 }
327
328 int set_item_validity_begin(void * handle, int item_cnt, char ** err_msg)
329 {
330         int ret = MEDIA_SVC_PLUGIN_ERROR_NONE;
331
332         if(handle == NULL) {
333                 __set_error_message(ERR_HANDLE, err_msg);
334                 return MEDIA_SVC_PLUGIN_ERROR;
335         }
336
337         ret = media_svc_set_item_validity_begin(handle, item_cnt);
338         if(ret < 0) {
339                 __set_error_message(ret, err_msg);
340                 return MEDIA_SVC_PLUGIN_ERROR;
341         }
342
343         return MEDIA_SVC_PLUGIN_ERROR_NONE;
344 }
345
346 int set_item_validity_end(void * handle, uid_t uid, char ** err_msg)
347 {
348         int ret = MEDIA_SVC_PLUGIN_ERROR_NONE;
349
350         if(handle == NULL) {
351                 __set_error_message(ERR_HANDLE, err_msg);
352                 return MEDIA_SVC_PLUGIN_ERROR;
353         }
354
355         ret = media_svc_set_item_validity_end(handle, uid);
356         if(ret < 0) {
357                 __set_error_message(ret, err_msg);
358                 return MEDIA_SVC_PLUGIN_ERROR;
359         }
360
361         return MEDIA_SVC_PLUGIN_ERROR_NONE;
362 }
363
364 int set_item_validity(void * handle, const char *file_path, int storage_type, int validity, uid_t uid, char ** err_msg)
365 {
366         int ret = MEDIA_SVC_PLUGIN_ERROR_NONE;
367
368         if(handle == NULL) {
369                 __set_error_message(ERR_HANDLE, err_msg);
370                 return MEDIA_SVC_PLUGIN_ERROR;
371         }
372
373         if (!STRING_VALID(file_path)) {
374                 __set_error_message(ERR_FILE_PATH, err_msg);
375                 return MEDIA_SVC_PLUGIN_ERROR;
376         }
377
378         if(!STORAGE_VALID(storage_type)) {
379                 __set_error_message(ERR_STORAGE_TYPE, err_msg);
380                 return MEDIA_SVC_PLUGIN_ERROR;
381         }
382
383         ret = media_svc_set_item_validity(handle, file_path, validity, uid);
384
385         if(ret < 0) {
386                 __set_error_message(ret, err_msg);
387                 return MEDIA_SVC_PLUGIN_ERROR;
388         }
389
390         return MEDIA_SVC_PLUGIN_ERROR_NONE;
391 }
392
393 int delete_item(void * handle, const char *file_path, uid_t uid, char ** err_msg)
394 {
395         int ret = MEDIA_SVC_PLUGIN_ERROR_NONE;
396
397         if(handle == NULL) {
398                 __set_error_message(ERR_HANDLE, err_msg);
399                 return MEDIA_SVC_PLUGIN_ERROR;
400         }
401
402         if (!STRING_VALID(file_path)) {
403                 __set_error_message(ERR_FILE_PATH, err_msg);
404                 return MEDIA_SVC_PLUGIN_ERROR;
405         }
406
407         ret = media_svc_check_item_exist_by_path(handle, file_path);
408         if(ret == 0) {
409                 ret = media_svc_delete_item_by_path(handle, "media", file_path, uid);
410
411                 if(ret < 0) {
412                         __set_error_message(ret, err_msg);
413                         return MEDIA_SVC_PLUGIN_ERROR;
414                 }
415                 else
416                         return MEDIA_SVC_PLUGIN_ERROR_NONE;
417         }
418
419         __set_error_message(ERR_CHECK_ITEM, err_msg);   //not exist in DB so can't delete item.
420         return MEDIA_SVC_PLUGIN_ERROR;
421 }
422
423 int delete_all_items_in_storage(void * handle, int storage_type, uid_t uid, char ** err_msg)
424 {
425         int ret = MEDIA_SVC_PLUGIN_ERROR_NONE;
426
427         if(handle == NULL) {
428                 __set_error_message(ERR_HANDLE, err_msg);
429                 return MEDIA_SVC_PLUGIN_ERROR;
430         }
431
432         if(!STORAGE_VALID(storage_type)) {
433                 __set_error_message(ERR_STORAGE_TYPE, err_msg);
434                 return MEDIA_SVC_PLUGIN_ERROR;
435         }
436
437         ret = media_svc_delete_all_items_in_storage(handle, storage_type, uid);
438         if(ret < 0) {
439                         __set_error_message(ret, err_msg);
440                         return MEDIA_SVC_PLUGIN_ERROR;
441         }
442
443         return MEDIA_SVC_PLUGIN_ERROR_NONE;
444 }
445
446 int delete_all_invalid_items_in_storage(void * handle, int storage_type, uid_t uid, char ** err_msg)
447 {
448         int ret = MEDIA_SVC_PLUGIN_ERROR_NONE;
449
450         if(handle == NULL) {
451                 __set_error_message(ERR_HANDLE, err_msg);
452                 return MEDIA_SVC_PLUGIN_ERROR;
453         }
454
455         if(!STORAGE_VALID(storage_type)) {
456                 __set_error_message(ERR_STORAGE_TYPE, err_msg);
457                 return MEDIA_SVC_PLUGIN_ERROR;
458         }
459
460         ret = media_svc_delete_invalid_items_in_storage(handle, storage_type, uid);
461         if(ret < 0) {
462                         __set_error_message(ret, err_msg);
463                         return MEDIA_SVC_PLUGIN_ERROR;
464         }
465
466         return MEDIA_SVC_PLUGIN_ERROR_NONE;
467 }
468
469 int delete_all_invalid_items_in_folder(void * handle, const char *folder_path, uid_t uid, char ** err_msg)
470 {
471         int ret = MEDIA_SVC_PLUGIN_ERROR_NONE;
472
473         if(handle == NULL) {
474                 __set_error_message(ERR_HANDLE, err_msg);
475                 return MEDIA_SVC_PLUGIN_ERROR;
476         }
477
478         if (!STRING_VALID(folder_path)) {
479                 __set_error_message(ERR_FOLDER_PATH, err_msg);
480                 return MEDIA_SVC_PLUGIN_ERROR;
481         }
482
483         ret = media_svc_delete_invalid_items_in_folder(handle, folder_path, uid);
484         if(ret < 0) {
485                 __set_error_message(ret, err_msg);
486                 return MEDIA_SVC_PLUGIN_ERROR;
487         }
488
489         return MEDIA_SVC_PLUGIN_ERROR_NONE;
490 }
491
492
493 int update_begin(void)
494 {
495         return MEDIA_SVC_PLUGIN_ERROR_NONE;
496 }
497
498 int update_end(uid_t uid)
499 {
500         int ret = MEDIA_SVC_PLUGIN_ERROR_NONE;
501
502         ret = thumbnail_request_extract_all_thumbs(uid);
503         if (ret < 0) {
504                 return MEDIA_SVC_PLUGIN_ERROR;
505         }
506
507         return MEDIA_SVC_PLUGIN_ERROR_NONE;
508 }
509
510 int send_dir_update_noti(void * handle, const char *dir_path, char **err_msg)
511 {
512         int ret = MEDIA_SVC_PLUGIN_ERROR_NONE;
513
514         if (!STRING_VALID(dir_path)) {
515                 __set_error_message(ERR_FOLDER_PATH, err_msg);
516                 return MEDIA_SVC_PLUGIN_ERROR;
517         }
518
519         ret = media_svc_send_dir_update_noti(handle, dir_path);
520         if (ret < 0) {
521                 __set_error_message(ret, err_msg);
522                 return MEDIA_SVC_PLUGIN_ERROR;
523         }
524
525         return MEDIA_SVC_PLUGIN_ERROR_NONE;
526 }
527
528 int count_delete_items_in_folder(void * handle, const char *folder_path, int *count, char ** err_msg)
529 {
530         int ret = MEDIA_SVC_PLUGIN_ERROR_NONE;
531
532         if(handle == NULL) {
533                 __set_error_message(ERR_HANDLE, err_msg);
534                 return MEDIA_SVC_PLUGIN_ERROR;
535         }
536
537         if(count == NULL) {
538                 __set_error_message(ERR_HANDLE, err_msg);
539                 return MEDIA_SVC_PLUGIN_ERROR;
540         }
541
542         if (!STRING_VALID(folder_path)) {
543                 __set_error_message(ERR_FOLDER_PATH, err_msg);
544                 return MEDIA_SVC_PLUGIN_ERROR;
545         }
546
547         ret = media_svc_count_invalid_items_in_folder(handle, folder_path, count);
548         if(ret < 0) {
549                 __set_error_message(ret, err_msg);
550                 return MEDIA_SVC_PLUGIN_ERROR;
551         }
552
553         return MEDIA_SVC_PLUGIN_ERROR_NONE;
554 }
555
556 int check_db(void * handle, uid_t uid, char **err_msg)
557 {
558         int ret = MEDIA_SVC_PLUGIN_ERROR_NONE;
559
560         /*check db schema*/
561         ret = media_svc_create_table(handle, uid);
562         if(ret < 0) {
563                 __set_error_message(ret, err_msg);
564                 return MEDIA_SVC_PLUGIN_ERROR;
565         }
566
567         /*check db version*/
568         ret = media_svc_check_db_upgrade(handle, uid);
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 check_db_corrupt(void * handle, char **err_msg)
578 {
579         int ret = MEDIA_SVC_PLUGIN_ERROR_NONE;
580
581         /*check db version*/
582         ret = media_svc_check_db_corrupt(handle);
583         if(ret < 0) {
584                 __set_error_message(ret, err_msg);
585                 return MEDIA_SVC_PLUGIN_ERROR;
586         }
587
588         return MEDIA_SVC_PLUGIN_ERROR_NONE;
589 }
590
591 int get_folder_list(void * handle, char* start_path, char ***folder_list, int **modified_time_list, int **item_num_list, int *count, char ** err_msg)
592 {
593         int ret = MEDIA_SVC_PLUGIN_ERROR_NONE;
594
595         if(handle == NULL) {
596                 __set_error_message(ERR_HANDLE, err_msg);
597                 return MEDIA_SVC_PLUGIN_ERROR;
598         }
599
600         if(count == NULL) {
601                 __set_error_message(ERR_HANDLE, err_msg);
602                 return MEDIA_SVC_PLUGIN_ERROR;
603         }
604
605         ret = media_svc_get_folder_list(handle, start_path, folder_list, (time_t**)modified_time_list, item_num_list, count);
606         if(ret < 0) {
607                 __set_error_message(ret, err_msg);
608                 return MEDIA_SVC_PLUGIN_ERROR;
609         }
610
611         return MEDIA_SVC_PLUGIN_ERROR_NONE;
612 }
613
614 int update_folder_time(void * handle, char *folder_path, uid_t uid, char ** err_msg)
615 {
616         int ret = MEDIA_SVC_PLUGIN_ERROR_NONE;
617
618         if(handle == NULL) {
619                 __set_error_message(ERR_HANDLE, err_msg);
620                 return MEDIA_SVC_PLUGIN_ERROR;
621         }
622
623         if(folder_path == NULL) {
624                 __set_error_message(ERR_HANDLE, err_msg);
625                 return MEDIA_SVC_PLUGIN_ERROR;
626         }
627
628         ret = media_svc_update_folder_time(handle, folder_path, uid);
629         if(ret < 0) {
630                 __set_error_message(ret, err_msg);
631                 return MEDIA_SVC_PLUGIN_ERROR;
632         }
633
634         return MEDIA_SVC_PLUGIN_ERROR_NONE;
635 }
636
637 int update_item_begin(void * handle, int item_cnt, char ** err_msg)
638 {
639         int ret = MEDIA_SVC_PLUGIN_ERROR_NONE;
640
641         if(handle == NULL) {
642                 __set_error_message(ERR_HANDLE, err_msg);
643                 return MEDIA_SVC_PLUGIN_ERROR;
644         }
645
646         ret = media_svc_update_item_begin(handle, item_cnt);
647         if(ret < 0) {
648                 __set_error_message(ret, err_msg);
649                 return MEDIA_SVC_PLUGIN_ERROR;
650         }
651
652         return MEDIA_SVC_PLUGIN_ERROR_NONE;
653 }
654
655 int update_item_end(void * handle, uid_t uid, char ** err_msg)
656 {
657         int ret = MEDIA_SVC_PLUGIN_ERROR_NONE;
658
659         if(handle == NULL) {
660                 __set_error_message(ERR_HANDLE, err_msg);
661                 return MEDIA_SVC_PLUGIN_ERROR;
662         }
663
664         ret = media_svc_update_item_end(handle, uid);
665         if(ret < 0) {
666                 __set_error_message(ret, err_msg);
667                 return MEDIA_SVC_PLUGIN_ERROR;
668         }
669
670         return MEDIA_SVC_PLUGIN_ERROR_NONE;
671 }
672
673 int update_item_meta(void * handle, const char *file_path, int storage_type, uid_t uid, char ** err_msg)
674 {
675         int ret = MEDIA_SVC_PLUGIN_ERROR_NONE;
676
677         if(handle == NULL) {
678                 __set_error_message(ERR_HANDLE, err_msg);
679                 return MEDIA_SVC_PLUGIN_ERROR;
680         }
681
682         if(file_path == NULL) {
683                 __set_error_message(ERR_HANDLE, err_msg);
684                 return MEDIA_SVC_PLUGIN_ERROR;
685         }
686
687         ret = media_svc_update_item_meta(handle, file_path, storage_type, uid);
688         if(ret < 0) {
689                 __set_error_message(ret, err_msg);
690                 return MEDIA_SVC_PLUGIN_ERROR;
691         }
692
693         return MEDIA_SVC_PLUGIN_ERROR_NONE;
694 }