4 * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
6 * Contact: Hyunjun Ko <zzoon.ko@samsung.com>, Haejeong Kim <backto.kim@samsung.com>
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
12 * http://www.apache.org/licenses/LICENSE-2.0
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.
25 #include <media-thumbnail.h>
26 #include <media-util.h>
27 #include "media-svc.h"
28 #include "media-svc-util.h"
30 #define MEDIA_SVC_PLUGIN_ERROR_NONE 0
31 #define MEDIA_SVC_PLUGIN_ERROR -1
33 #define STRING_VALID(str) \
34 ((str != NULL && strlen(str) > 0) ? TRUE : FALSE)
35 #define STORAGE_VALID(storage)\
36 (((storage == MEDIA_SVC_STORAGE_INTERNAL) || (storage == MEDIA_SVC_STORAGE_EXTERNAL) || (storage == MEDIA_SVC_STORAGE_EXTERNAL_USB)) ? TRUE : FALSE)
48 } media_svc_error_type_e;
50 static void __set_error_message(int err_type, char **err_msg);
52 static void __set_error_message(int err_type, char **err_msg)
59 if (err_type == ERR_HANDLE)
60 *err_msg = strdup("invalid handle");
61 else if (err_type == ERR_FILE_PATH)
62 *err_msg = strdup("invalid file path");
63 else if (err_type == ERR_FOLDER_PATH)
64 *err_msg = strdup("invalid folder path");
65 else if (err_type == ERR_MIME_TYPE)
66 *err_msg = strdup("invalid mime type");
67 else if (err_type == ERR_NOT_MEDIAFILE)
68 *err_msg = strdup("not media content");
69 else if (err_type == ERR_STORAGE_TYPE)
70 *err_msg = strdup("invalid storage type");
71 else if (err_type == ERR_CHECK_ITEM)
72 *err_msg = strdup("item does not exist");
73 else if (err_type == MS_MEDIA_ERR_DB_CONNECT_FAIL)
74 *err_msg = strdup("DB connect error");
75 else if (err_type == MS_MEDIA_ERR_DB_DISCONNECT_FAIL)
76 *err_msg = strdup("DB disconnect error");
77 else if (err_type == MS_MEDIA_ERR_INVALID_PARAMETER)
78 *err_msg = strdup("invalid parameter");
79 else if (err_type == MS_MEDIA_ERR_DB_INTERNAL)
80 *err_msg = strdup("DB internal error");
81 else if (err_type == MS_MEDIA_ERR_DB_NO_RECORD)
82 *err_msg = strdup("not found in DB");
83 else if (err_type == MS_MEDIA_ERR_INTERNAL)
84 *err_msg = strdup("media service internal error");
85 else if (err_type == MS_MEDIA_ERR_DB_CORRUPT)
86 *err_msg = strdup("DB corrupt error");
88 *err_msg = strdup("error unknown");
93 int connect_db(void **handle, uid_t uid, char **err_msg)
95 int ret = media_svc_connect(handle, uid, true);
98 __set_error_message(ret, err_msg);
99 return MEDIA_SVC_PLUGIN_ERROR;
102 return MEDIA_SVC_PLUGIN_ERROR_NONE;
105 int disconnect_db(void *handle, char **err_msg)
107 int ret = MEDIA_SVC_PLUGIN_ERROR_NONE;
109 if (handle == NULL) {
110 __set_error_message(ERR_HANDLE, err_msg);
111 return MEDIA_SVC_PLUGIN_ERROR;
114 ret = media_svc_disconnect(handle);
116 __set_error_message(ret, err_msg);
117 return MEDIA_SVC_PLUGIN_ERROR;
120 return MEDIA_SVC_PLUGIN_ERROR_NONE;
123 int check_item_exist(void *handle, const char *storage_id, const char *file_path, bool *modified, char **err_msg)
125 int ret = MEDIA_SVC_PLUGIN_ERROR_NONE;
128 if (handle == NULL) {
129 __set_error_message(ERR_HANDLE, err_msg);
130 return MEDIA_SVC_PLUGIN_ERROR;
133 if (!STRING_VALID(file_path)) {
134 __set_error_message(ERR_FILE_PATH, err_msg);
135 return MEDIA_SVC_PLUGIN_ERROR;
138 time_t modified_time = 0;
139 unsigned long long file_size = 0;
142 ret = media_svc_get_file_info(handle, storage_id, file_path, &modified_time, &file_size);
143 if (ret == MS_MEDIA_ERR_NONE) {
144 memset(&st, 0, sizeof(struct stat));
145 if (stat(file_path, &st) == 0) {
146 if ((st.st_mtime != modified_time) || (st.st_size != file_size))
152 return MEDIA_SVC_PLUGIN_ERROR_NONE; /*exist */
155 __set_error_message(ERR_CHECK_ITEM, err_msg);
157 return MEDIA_SVC_PLUGIN_ERROR; /*not exist */
160 int insert_item_begin(void *handle, int item_cnt, int with_noti, int from_pid, char **err_msg)
162 int ret = MEDIA_SVC_PLUGIN_ERROR_NONE;
164 ret = media_svc_insert_item_begin(item_cnt, with_noti, from_pid);
166 __set_error_message(ret, err_msg);
167 return MEDIA_SVC_PLUGIN_ERROR;
170 return MEDIA_SVC_PLUGIN_ERROR_NONE;
173 int insert_item_end(void *handle, uid_t uid, char **err_msg)
175 int ret = MEDIA_SVC_PLUGIN_ERROR_NONE;
177 ret = media_svc_insert_item_end(uid);
179 __set_error_message(ret, err_msg);
180 return MEDIA_SVC_PLUGIN_ERROR;
183 return MEDIA_SVC_PLUGIN_ERROR_NONE;
186 int insert_item(void *handle, const char *storage_id, const char *file_path, int storage_type, uid_t uid, char **err_msg)
188 int ret = MEDIA_SVC_PLUGIN_ERROR_NONE;
190 if (handle == NULL) {
191 __set_error_message(ERR_HANDLE, err_msg);
192 return MEDIA_SVC_PLUGIN_ERROR;
195 if (!STRING_VALID(file_path)) {
196 __set_error_message(ERR_FILE_PATH, err_msg);
197 return MEDIA_SVC_PLUGIN_ERROR;
200 if (!STORAGE_VALID(storage_type)) {
201 __set_error_message(ERR_STORAGE_TYPE, err_msg);
202 return MEDIA_SVC_PLUGIN_ERROR;
205 ret = media_svc_insert_item_bulk(handle, storage_id, storage_type, file_path, FALSE, uid);
207 __set_error_message(ret, err_msg);
208 return MEDIA_SVC_PLUGIN_ERROR;
211 return MEDIA_SVC_PLUGIN_ERROR_NONE;
214 int insert_item_immediately(void *handle, const char *storage_id, const char *file_path, int storage_type, uid_t uid, char **err_msg)
216 int ret = MEDIA_SVC_PLUGIN_ERROR_NONE;
218 if (handle == NULL) {
219 __set_error_message(ERR_HANDLE, err_msg);
220 return MEDIA_SVC_PLUGIN_ERROR;
223 if (!STRING_VALID(file_path)) {
224 __set_error_message(ERR_FILE_PATH, err_msg);
225 return MEDIA_SVC_PLUGIN_ERROR;
228 if (!STORAGE_VALID(storage_type)) {
229 __set_error_message(ERR_STORAGE_TYPE, err_msg);
230 return MEDIA_SVC_PLUGIN_ERROR;
233 ret = media_svc_insert_item_immediately(handle, storage_id, storage_type, file_path, uid);
235 __set_error_message(ret, err_msg);
236 return MEDIA_SVC_PLUGIN_ERROR;
239 return MEDIA_SVC_PLUGIN_ERROR_NONE;
242 int insert_burst_item(void *handle, const char *storage_id, const char *file_path, int storage_type, uid_t uid, char **err_msg)
244 int ret = MEDIA_SVC_PLUGIN_ERROR_NONE;
246 if (handle == NULL) {
247 __set_error_message(ERR_HANDLE, err_msg);
248 return MEDIA_SVC_PLUGIN_ERROR;
251 if (!STRING_VALID(file_path)) {
252 __set_error_message(ERR_FILE_PATH, err_msg);
253 return MEDIA_SVC_PLUGIN_ERROR;
256 if (!STORAGE_VALID(storage_type)) {
257 __set_error_message(ERR_STORAGE_TYPE, err_msg);
258 return MEDIA_SVC_PLUGIN_ERROR;
261 ret = media_svc_insert_item_bulk(handle, storage_id, storage_type, file_path, TRUE, uid);
263 __set_error_message(ret, err_msg);
264 return MEDIA_SVC_PLUGIN_ERROR;
267 return MEDIA_SVC_PLUGIN_ERROR_NONE;
270 int set_all_storage_items_validity(void *handle, const char *storage_id, int storage_type, int validity, uid_t uid, char **err_msg)
272 int ret = MEDIA_SVC_PLUGIN_ERROR_NONE;
274 if (!STORAGE_VALID(storage_type)) {
275 __set_error_message(ERR_STORAGE_TYPE, err_msg);
276 return MEDIA_SVC_PLUGIN_ERROR;
279 ret = media_svc_set_all_storage_items_validity(storage_id, storage_type, validity, uid);
281 __set_error_message(ret, err_msg);
282 return MEDIA_SVC_PLUGIN_ERROR;
285 return MEDIA_SVC_PLUGIN_ERROR_NONE;
288 int set_folder_item_validity(void *handle, const char *storage_id, const char *folder_path, int validity, int recursive, uid_t uid, char **err_msg)
290 int ret = MEDIA_SVC_PLUGIN_ERROR_NONE;
292 if (handle == NULL) {
293 __set_error_message(ERR_HANDLE, err_msg);
294 return MEDIA_SVC_PLUGIN_ERROR;
297 if (!STRING_VALID(folder_path)) {
298 __set_error_message(ERR_FOLDER_PATH, err_msg);
299 return MEDIA_SVC_PLUGIN_ERROR;
302 ret = media_svc_set_folder_items_validity(handle, storage_id, folder_path, validity, recursive, uid);
304 __set_error_message(ret, err_msg);
305 return MEDIA_SVC_PLUGIN_ERROR;
308 return MEDIA_SVC_PLUGIN_ERROR_NONE;
311 int set_item_validity_begin(void *handle, int item_cnt, char **err_msg)
313 int ret = MEDIA_SVC_PLUGIN_ERROR_NONE;
315 ret = media_svc_set_item_validity_begin(item_cnt);
317 __set_error_message(ret, err_msg);
318 return MEDIA_SVC_PLUGIN_ERROR;
321 return MEDIA_SVC_PLUGIN_ERROR_NONE;
324 int set_item_validity_end(void *handle, uid_t uid, char **err_msg)
326 int ret = MEDIA_SVC_PLUGIN_ERROR_NONE;
328 ret = media_svc_set_item_validity_end(uid);
330 __set_error_message(ret, err_msg);
331 return MEDIA_SVC_PLUGIN_ERROR;
334 return MEDIA_SVC_PLUGIN_ERROR_NONE;
337 int set_item_validity(void *handle, const char *storage_id, const char *file_path, int storage_type, int validity, uid_t uid, char **err_msg)
339 int ret = MEDIA_SVC_PLUGIN_ERROR_NONE;
341 if (!STRING_VALID(file_path)) {
342 __set_error_message(ERR_FILE_PATH, err_msg);
343 return MEDIA_SVC_PLUGIN_ERROR;
346 ret = media_svc_set_item_validity(storage_id, file_path, validity, uid);
349 __set_error_message(ret, err_msg);
350 return MEDIA_SVC_PLUGIN_ERROR;
353 return MEDIA_SVC_PLUGIN_ERROR_NONE;
356 int delete_item(void *handle, const char *storage_id, const char *file_path, uid_t uid, char **err_msg)
358 int ret = MEDIA_SVC_PLUGIN_ERROR_NONE;
360 if (handle == NULL) {
361 __set_error_message(ERR_HANDLE, err_msg);
362 return MEDIA_SVC_PLUGIN_ERROR;
365 if (!STRING_VALID(file_path)) {
366 __set_error_message(ERR_FILE_PATH, err_msg);
367 return MEDIA_SVC_PLUGIN_ERROR;
370 ret = media_svc_check_item_exist_by_path(handle, storage_id, file_path);
372 ret = media_svc_delete_item_by_path(handle, storage_id, file_path, uid);
375 __set_error_message(ret, err_msg);
376 return MEDIA_SVC_PLUGIN_ERROR;
378 return MEDIA_SVC_PLUGIN_ERROR_NONE;
381 __set_error_message(ERR_CHECK_ITEM, err_msg); /*not exist in DB so can't delete item. */
382 return MEDIA_SVC_PLUGIN_ERROR;
385 int delete_all_items_in_storage(void *handle, const char *storage_id, int storage_type, uid_t uid, char **err_msg)
387 int ret = MEDIA_SVC_PLUGIN_ERROR_NONE;
389 if (!STORAGE_VALID(storage_type)) {
390 __set_error_message(ERR_STORAGE_TYPE, err_msg);
391 return MEDIA_SVC_PLUGIN_ERROR;
394 ret = media_svc_delete_all_items_in_storage(storage_id, storage_type, uid);
396 __set_error_message(ret, err_msg);
397 return MEDIA_SVC_PLUGIN_ERROR;
400 return MEDIA_SVC_PLUGIN_ERROR_NONE;
403 int delete_all_invalid_items_in_storage(void *handle, const char *storage_id, int storage_type, uid_t uid, char **err_msg)
405 int ret = MEDIA_SVC_PLUGIN_ERROR_NONE;
407 if (handle == NULL) {
408 __set_error_message(ERR_HANDLE, err_msg);
409 return MEDIA_SVC_PLUGIN_ERROR;
412 if (!STORAGE_VALID(storage_type)) {
413 __set_error_message(ERR_STORAGE_TYPE, err_msg);
414 return MEDIA_SVC_PLUGIN_ERROR;
417 ret = media_svc_delete_invalid_items_in_storage(handle, storage_id, storage_type, uid);
419 __set_error_message(ret, err_msg);
420 return MEDIA_SVC_PLUGIN_ERROR;
423 return MEDIA_SVC_PLUGIN_ERROR_NONE;
426 int delete_all_invalid_items_in_folder(void *handle, const char *storage_id, const char *folder_path, bool is_recursve, uid_t uid, char **err_msg)
428 int ret = MEDIA_SVC_PLUGIN_ERROR_NONE;
430 if (handle == NULL) {
431 __set_error_message(ERR_HANDLE, err_msg);
432 return MEDIA_SVC_PLUGIN_ERROR;
435 if (!STRING_VALID(folder_path)) {
436 __set_error_message(ERR_FOLDER_PATH, err_msg);
437 return MEDIA_SVC_PLUGIN_ERROR;
440 ret = media_svc_delete_invalid_items_in_folder(handle, storage_id, folder_path, is_recursve, uid);
442 __set_error_message(ret, err_msg);
443 return MEDIA_SVC_PLUGIN_ERROR;
446 return MEDIA_SVC_PLUGIN_ERROR_NONE;
450 int update_begin(void)
452 return MEDIA_SVC_PLUGIN_ERROR_NONE;
455 int update_end(uid_t uid)
458 int ret = MEDIA_SVC_PLUGIN_ERROR_NONE;
460 ret = thumbnail_request_extract_all_thumbs(uid);
462 return MEDIA_SVC_PLUGIN_ERROR;
464 ret = dcm_svc_request_extract_all(uid);
466 return MEDIA_SVC_PLUGIN_ERROR;
468 return MEDIA_SVC_PLUGIN_ERROR_NONE;
471 int send_dir_update_noti(void *handle, const char *storage_id, const char *dir_path, const char *folder_id, int update_type, int pid, char **err_msg)
473 int ret = MEDIA_SVC_PLUGIN_ERROR_NONE;
475 if (!STRING_VALID(dir_path)) {
476 __set_error_message(ERR_FOLDER_PATH, err_msg);
477 return MEDIA_SVC_PLUGIN_ERROR;
480 ret = media_svc_send_dir_update_noti(handle, storage_id, dir_path, folder_id, (media_item_update_type_e)update_type, pid);
482 __set_error_message(ret, err_msg);
483 return MEDIA_SVC_PLUGIN_ERROR;
486 return MEDIA_SVC_PLUGIN_ERROR_NONE;
489 int count_delete_items_in_folder(void *handle, const char *storage_id, const char *folder_path, int *count, char **err_msg)
491 int ret = MEDIA_SVC_PLUGIN_ERROR_NONE;
493 if (handle == NULL) {
494 __set_error_message(ERR_HANDLE, err_msg);
495 return MEDIA_SVC_PLUGIN_ERROR;
499 __set_error_message(ERR_HANDLE, err_msg);
500 return MEDIA_SVC_PLUGIN_ERROR;
503 if (!STRING_VALID(folder_path)) {
504 __set_error_message(ERR_FOLDER_PATH, err_msg);
505 return MEDIA_SVC_PLUGIN_ERROR;
508 ret = media_svc_count_invalid_items_in_folder(handle, storage_id, folder_path, count);
510 __set_error_message(ret, err_msg);
511 return MEDIA_SVC_PLUGIN_ERROR;
514 return MEDIA_SVC_PLUGIN_ERROR_NONE;
517 int check_db(void *handle, uid_t uid, char **err_msg)
519 int ret = MEDIA_SVC_PLUGIN_ERROR_NONE;
520 int user_version = -1;
522 ret = media_svc_get_user_version(handle, &user_version);
524 __set_error_message(ret, err_msg);
525 return MEDIA_SVC_PLUGIN_ERROR;
528 if (user_version == 0) {
530 ret = media_svc_create_table(uid);
532 __set_error_message(ret, err_msg);
533 return MEDIA_SVC_PLUGIN_ERROR;
537 ret = media_svc_check_db_upgrade(handle, user_version, uid);
539 __set_error_message(ret, err_msg);
540 return MEDIA_SVC_PLUGIN_ERROR;
544 return MEDIA_SVC_PLUGIN_ERROR_NONE;
547 int check_db_corrupt(void *handle, char **err_msg)
549 int ret = MEDIA_SVC_PLUGIN_ERROR_NONE;
552 ret = media_svc_check_db_corrupt(handle);
554 __set_error_message(ret, err_msg);
555 return MEDIA_SVC_PLUGIN_ERROR;
558 return MEDIA_SVC_PLUGIN_ERROR_NONE;
561 int get_folder_list(void *handle, const char *storage_id, char *start_path, char ***folder_list, int **modified_time_list, int **item_num_list, int *count, char **err_msg)
563 int ret = MEDIA_SVC_PLUGIN_ERROR_NONE;
565 if (handle == NULL) {
566 __set_error_message(ERR_HANDLE, err_msg);
567 return MEDIA_SVC_PLUGIN_ERROR;
571 __set_error_message(ERR_HANDLE, err_msg);
572 return MEDIA_SVC_PLUGIN_ERROR;
575 ret = media_svc_get_folder_list(handle, start_path, folder_list, (time_t **)modified_time_list, item_num_list, count);
577 __set_error_message(ret, err_msg);
578 return MEDIA_SVC_PLUGIN_ERROR;
581 return MEDIA_SVC_PLUGIN_ERROR_NONE;
584 int update_folder_time(void *handle, const char *storage_id, char *folder_path, uid_t uid, char **err_msg)
586 int ret = MEDIA_SVC_PLUGIN_ERROR_NONE;
588 if (handle == NULL) {
589 __set_error_message(ERR_HANDLE, err_msg);
590 return MEDIA_SVC_PLUGIN_ERROR;
593 if (folder_path == NULL) {
594 __set_error_message(ERR_HANDLE, err_msg);
595 return MEDIA_SVC_PLUGIN_ERROR;
598 ret = media_svc_update_folder_time(handle, storage_id, folder_path, uid);
600 __set_error_message(ret, err_msg);
601 return MEDIA_SVC_PLUGIN_ERROR;
604 return MEDIA_SVC_PLUGIN_ERROR_NONE;
607 int get_uuid(void * handle, char **uuid, char **err_msg)
609 int ret = MEDIA_SVC_PLUGIN_ERROR_NONE;
611 ret = media_svc_generate_uuid(uuid);
613 __set_error_message(ret, err_msg);
614 return MEDIA_SVC_PLUGIN_ERROR;
617 return MEDIA_SVC_PLUGIN_ERROR_NONE;
620 int get_mmc_info(void * handle, char **storage_name, char **storage_path, int *validity, bool *info_exist, char **err_msg)
622 int ret = MEDIA_SVC_PLUGIN_ERROR_NONE;
624 if (handle == NULL) {
625 __set_error_message(ERR_HANDLE, err_msg);
626 return MEDIA_SVC_PLUGIN_ERROR;
629 ret = media_svc_get_mmc_info(handle, storage_name, storage_path, validity, info_exist);
631 __set_error_message(MS_MEDIA_ERR_DB_NO_RECORD, err_msg);
632 return MEDIA_SVC_PLUGIN_ERROR;
635 return MEDIA_SVC_PLUGIN_ERROR_NONE;
638 int check_storage(void * handle, const char *storage_id, const char *storage_name, char **storage_path, int *validity, uid_t uid, char **err_msg)
640 int ret = MEDIA_SVC_PLUGIN_ERROR_NONE;
642 if (handle == NULL) {
643 __set_error_message(ERR_HANDLE, err_msg);
644 return MEDIA_SVC_PLUGIN_ERROR;
647 ret = media_svc_check_storage(handle, storage_id, storage_name, storage_path, validity, uid);
649 __set_error_message(ret, err_msg);
650 return MEDIA_SVC_PLUGIN_ERROR;
653 return MEDIA_SVC_PLUGIN_ERROR_NONE;
656 int insert_storage(void *handle, const char *storage_id, int storage_type, const char *storage_name, const char *storage_path, uid_t uid, char **err_msg)
658 int ret = MEDIA_SVC_PLUGIN_ERROR_NONE;
660 if (handle == NULL) {
661 __set_error_message(ERR_HANDLE, err_msg);
662 return MEDIA_SVC_PLUGIN_ERROR;
665 ret = media_svc_insert_storage(handle, storage_id, storage_name, storage_path, NULL, storage_type, uid);
667 __set_error_message(ret, err_msg);
668 return MEDIA_SVC_PLUGIN_ERROR;
671 return MEDIA_SVC_PLUGIN_ERROR_NONE;
674 int update_storage(void *handle, const char *storage_id, const char *storage_path, uid_t uid, char **err_msg)
676 int ret = MEDIA_SVC_PLUGIN_ERROR_NONE;
678 if (handle == NULL) {
679 __set_error_message(ERR_HANDLE, err_msg);
680 return MEDIA_SVC_PLUGIN_ERROR;
683 ret = media_svc_update_storage(handle, storage_id, storage_path, uid);
685 __set_error_message(ret, err_msg);
686 return MEDIA_SVC_PLUGIN_ERROR;
689 return MEDIA_SVC_PLUGIN_ERROR_NONE;
692 int delete_storage(void * handle, const char *storage_id, const char *storage_name, uid_t uid, char **err_msg)
694 int ret = MEDIA_SVC_PLUGIN_ERROR_NONE;
696 if (handle == NULL) {
697 __set_error_message(ERR_HANDLE, err_msg);
698 return MEDIA_SVC_PLUGIN_ERROR;
701 ret = media_svc_delete_storage(handle, storage_id, storage_name, uid);
703 __set_error_message(ret, err_msg);
704 return MEDIA_SVC_PLUGIN_ERROR;
707 return MEDIA_SVC_PLUGIN_ERROR_NONE;
710 int set_storage_validity(void * handle, const char *storage_id, int validity, uid_t uid, char **err_msg)
712 int ret = MEDIA_SVC_PLUGIN_ERROR_NONE;
714 if (handle == NULL) {
715 __set_error_message(ERR_HANDLE, err_msg);
716 return MEDIA_SVC_PLUGIN_ERROR;
719 ret = media_svc_set_storage_validity(handle, storage_id, validity, uid);
721 __set_error_message(ret, err_msg);
722 return MEDIA_SVC_PLUGIN_ERROR;
725 return MEDIA_SVC_PLUGIN_ERROR_NONE;
728 int set_all_storage_validity(void * handle, int validity, uid_t uid, char **err_msg)
730 int ret = MEDIA_SVC_PLUGIN_ERROR_NONE;
732 if (handle == NULL) {
733 __set_error_message(ERR_HANDLE, err_msg);
734 return MEDIA_SVC_PLUGIN_ERROR;
737 ret = media_svc_set_storage_validity(handle, NULL, validity, uid);
739 __set_error_message(ret, err_msg);
740 return MEDIA_SVC_PLUGIN_ERROR;
743 return MEDIA_SVC_PLUGIN_ERROR_NONE;
746 int get_storage_id(void * handle, const char *path, char *storage_id, uid_t uid, char **err_msg)
748 int ret = MEDIA_SVC_PLUGIN_ERROR_NONE;
750 if (handle == NULL) {
751 __set_error_message(ERR_HANDLE, err_msg);
752 return MEDIA_SVC_PLUGIN_ERROR;
755 ret = media_svc_get_storage_id(handle, path, storage_id, uid);
757 __set_error_message(ret, err_msg);
758 return MEDIA_SVC_PLUGIN_ERROR;
761 return MEDIA_SVC_PLUGIN_ERROR_NONE;
764 int get_storage_scan_status(void * handle, const char *storage_id, int *status, char **err_msg)
766 int ret = MEDIA_SVC_PLUGIN_ERROR_NONE;
767 media_svc_scan_status_type_e storage_status = 0;
769 if (handle == NULL) {
770 __set_error_message(ERR_HANDLE, err_msg);
771 return MEDIA_SVC_PLUGIN_ERROR;
774 ret = media_svc_get_storage_scan_status(handle, storage_id, &storage_status);
776 __set_error_message(ret, err_msg);
777 return MEDIA_SVC_PLUGIN_ERROR;
780 *status = storage_status;
782 return MEDIA_SVC_PLUGIN_ERROR_NONE;
785 int set_storage_scan_status(void *handle, const char *storage_id, int status, uid_t uid, char **err_msg)
787 int ret = MEDIA_SVC_PLUGIN_ERROR_NONE;
788 media_svc_scan_status_type_e storage_status = status;
790 ret = media_svc_set_storage_scan_status(storage_id, storage_status, uid);
792 __set_error_message(ret, err_msg);
793 return MEDIA_SVC_PLUGIN_ERROR;
796 return MEDIA_SVC_PLUGIN_ERROR_NONE;
799 int get_storage_list(void *handle, char ***storage_list, char ***storage_id_list, int **scan_status_list, int *count, char **err_msg)
801 int ret = MEDIA_SVC_PLUGIN_ERROR_NONE;
803 if (handle == NULL) {
804 __set_error_message(ERR_HANDLE, err_msg);
805 return MEDIA_SVC_PLUGIN_ERROR;
809 __set_error_message(ERR_HANDLE, err_msg);
810 return MEDIA_SVC_PLUGIN_ERROR;
813 ret = media_svc_get_storage_list(handle, storage_list, storage_id_list, scan_status_list, count);
815 __set_error_message(ret, err_msg);
816 return MEDIA_SVC_PLUGIN_ERROR;
819 return MEDIA_SVC_PLUGIN_ERROR_NONE;
822 int update_item_begin(void *handle, int item_cnt, char **err_msg)
824 int ret = MEDIA_SVC_PLUGIN_ERROR_NONE;
826 ret = media_svc_update_item_begin(item_cnt);
828 __set_error_message(ret, err_msg);
829 return MEDIA_SVC_PLUGIN_ERROR;
832 return MEDIA_SVC_PLUGIN_ERROR_NONE;
835 int update_item_end(void *handle, uid_t uid, char **err_msg)
837 int ret = MEDIA_SVC_PLUGIN_ERROR_NONE;
839 ret = media_svc_update_item_end(uid);
841 __set_error_message(ret, err_msg);
842 return MEDIA_SVC_PLUGIN_ERROR;
845 return MEDIA_SVC_PLUGIN_ERROR_NONE;
848 int update_item_meta(void *handle, const char *file_path, const char *storage_id, int storage_type, uid_t uid, char **err_msg)
850 int ret = MEDIA_SVC_PLUGIN_ERROR_NONE;
852 if (handle == NULL) {
853 __set_error_message(ERR_HANDLE, err_msg);
854 return MEDIA_SVC_PLUGIN_ERROR;
857 if (file_path == NULL) {
858 __set_error_message(ERR_HANDLE, err_msg);
859 return MEDIA_SVC_PLUGIN_ERROR;
862 if (storage_id == NULL) {
863 __set_error_message(ERR_HANDLE, err_msg);
864 return MEDIA_SVC_PLUGIN_ERROR;
867 ret = media_svc_update_item_meta(handle, file_path, storage_id, storage_type, uid);
869 __set_error_message(ret, err_msg);
870 return MEDIA_SVC_PLUGIN_ERROR;
873 return MEDIA_SVC_PLUGIN_ERROR_NONE;
876 int insert_item_scan(void * handle, const char *storage_id, const char *file_path, int storage_type, uid_t uid, char **err_msg)
878 int ret = MEDIA_SVC_PLUGIN_ERROR_NONE;
880 if (handle == NULL) {
881 __set_error_message(ERR_HANDLE, err_msg);
882 return MEDIA_SVC_PLUGIN_ERROR;
885 if (!STRING_VALID(file_path)) {
886 __set_error_message(ERR_FILE_PATH, err_msg);
887 return MEDIA_SVC_PLUGIN_ERROR;
890 if (!STORAGE_VALID(storage_type)) {
891 __set_error_message(ERR_STORAGE_TYPE, err_msg);
892 return MEDIA_SVC_PLUGIN_ERROR;
895 ret = media_svc_insert_item_pass1(handle, storage_id, storage_type, file_path, FALSE, uid);
897 __set_error_message(ret, err_msg);
898 return MEDIA_SVC_PLUGIN_ERROR;
901 return MEDIA_SVC_PLUGIN_ERROR_NONE;
904 int update_item_extract(void * handle, const char *storage_id, int storage_type, int scan_type, uid_t uid, const char *path, int burst, char **err_msg)
906 int ret = MEDIA_SVC_PLUGIN_ERROR_NONE;
908 if (handle == NULL) {
909 __set_error_message(ERR_HANDLE, err_msg);
910 return MEDIA_SVC_PLUGIN_ERROR;
913 if (!STORAGE_VALID(storage_type)) {
914 __set_error_message(ERR_STORAGE_TYPE, err_msg);
915 return MEDIA_SVC_PLUGIN_ERROR;
918 ret = media_svc_insert_item_pass2(handle, storage_id, storage_type, scan_type, path, burst, uid);
920 __set_error_message(ret, err_msg);
921 return MEDIA_SVC_PLUGIN_ERROR;
924 return MEDIA_SVC_PLUGIN_ERROR_NONE;
927 int get_extract_list(void* handle, const char* storage_id, int storage_type, int scan_type, const char* path, int burst, uid_t uid, void* array, char** err_msg)
930 int ret = MEDIA_SVC_PLUGIN_ERROR_NONE;
932 if (handle == NULL) {
933 __set_error_message(ERR_HANDLE, err_msg);
934 return MEDIA_SVC_PLUGIN_ERROR;
937 if (!STORAGE_VALID(storage_type)) {
938 __set_error_message(ERR_STORAGE_TYPE, err_msg);
939 return MEDIA_SVC_PLUGIN_ERROR;
942 ret = media_svc_pass2_get_extract_list(handle, storage_id, storage_type, scan_type, path, burst, uid, array);
944 __set_error_message(ret, err_msg);
945 return MEDIA_SVC_PLUGIN_ERROR;
948 return MEDIA_SVC_PLUGIN_ERROR_NONE;
951 int update_one_extract_item(void* handle, const char* storage_id, int storage_type, void* data, int burst, char** err_msg)
954 int ret = MEDIA_SVC_PLUGIN_ERROR_NONE;
956 if (handle == NULL) {
957 __set_error_message(ERR_HANDLE, err_msg);
958 return MEDIA_SVC_PLUGIN_ERROR;
961 if (!STORAGE_VALID(storage_type)) {
962 __set_error_message(ERR_STORAGE_TYPE, err_msg);
963 return MEDIA_SVC_PLUGIN_ERROR;
966 ret = media_svc_insert_one_item_pass2(handle, storage_id, storage_type, data, burst);
968 __set_error_message(ret, err_msg);
969 return MEDIA_SVC_PLUGIN_ERROR;
972 return MEDIA_SVC_PLUGIN_ERROR_NONE;
975 int query_do_update_list(void* handle, char** err_msg)
978 int ret = MEDIA_SVC_PLUGIN_ERROR_NONE;
980 if (handle == NULL) {
981 __set_error_message(ERR_HANDLE, err_msg);
982 return MEDIA_SVC_PLUGIN_ERROR;
985 ret = media_svc_query_do_update_list(handle);
987 __set_error_message(ret, err_msg);
988 return MEDIA_SVC_PLUGIN_ERROR;
991 return MEDIA_SVC_PLUGIN_ERROR_NONE;
994 int insert_folder_begin(void * handle, int item_cnt, char **err_msg)
996 int ret = MEDIA_SVC_PLUGIN_ERROR_NONE;
998 ret = media_svc_insert_folder_begin(item_cnt);
1000 __set_error_message(ret, err_msg);
1001 return MEDIA_SVC_PLUGIN_ERROR;
1004 return MEDIA_SVC_PLUGIN_ERROR_NONE;
1007 int insert_folder_end(void *handle, uid_t uid, char **err_msg)
1009 int ret = MEDIA_SVC_PLUGIN_ERROR_NONE;
1011 ret = media_svc_insert_folder_end(uid);
1013 __set_error_message(ret, err_msg);
1014 return MEDIA_SVC_PLUGIN_ERROR;
1017 return MEDIA_SVC_PLUGIN_ERROR_NONE;
1020 int insert_folder(void * handle, const char *storage_id, const char *file_path, int storage_type, uid_t uid, char **err_msg)
1022 int ret = MEDIA_SVC_PLUGIN_ERROR_NONE;
1024 if (handle == NULL) {
1025 __set_error_message(ERR_HANDLE, err_msg);
1026 return MEDIA_SVC_PLUGIN_ERROR;
1029 if (!STRING_VALID(file_path)) {
1030 __set_error_message(ERR_FILE_PATH, err_msg);
1031 return MEDIA_SVC_PLUGIN_ERROR;
1034 if (!STORAGE_VALID(storage_type)) {
1035 __set_error_message(ERR_STORAGE_TYPE, err_msg);
1036 return MEDIA_SVC_PLUGIN_ERROR;
1039 ret = media_svc_insert_folder(handle, storage_id, storage_type, file_path, uid);
1041 __set_error_message(ret, err_msg);
1042 return MEDIA_SVC_PLUGIN_ERROR;
1045 return MEDIA_SVC_PLUGIN_ERROR_NONE;
1048 int delete_invalid_folder(void * handle, const char *storage_id, int storage_type, uid_t uid, char **err_msg)
1050 int ret = MEDIA_SVC_PLUGIN_ERROR_NONE;
1052 ret = media_svc_delete_invalid_folder(storage_id, storage_type, uid);
1054 __set_error_message(ret, err_msg);
1055 return MEDIA_SVC_PLUGIN_ERROR;
1058 return MEDIA_SVC_PLUGIN_ERROR_NONE;
1061 int set_folder_validity(void * handle, const char *storage_id, const char* start_path, int validity, bool is_recursive, uid_t uid, char **err_msg)
1063 int ret = MEDIA_SVC_PLUGIN_ERROR_NONE;
1065 if (handle == NULL) {
1066 __set_error_message(ERR_HANDLE, err_msg);
1067 return MEDIA_SVC_PLUGIN_ERROR;
1070 ret = media_svc_set_folder_validity(handle, storage_id, start_path, validity, is_recursive, uid);
1072 __set_error_message(ret, err_msg);
1073 return MEDIA_SVC_PLUGIN_ERROR;
1076 return MEDIA_SVC_PLUGIN_ERROR_NONE;
1079 int delete_invalid_folder_by_path(void * handle, const char *storage_id, const char *folder_path, uid_t uid, int *delete_count, char **err_msg)
1081 int ret = MEDIA_SVC_PLUGIN_ERROR_NONE;
1083 if (handle == NULL) {
1084 __set_error_message(ERR_HANDLE, err_msg);
1085 return MEDIA_SVC_PLUGIN_ERROR;
1088 ret = media_svc_delete_invalid_folder_by_path(handle, storage_id, folder_path, uid, delete_count);
1090 __set_error_message(ret, err_msg);
1091 return MEDIA_SVC_PLUGIN_ERROR;
1094 return MEDIA_SVC_PLUGIN_ERROR_NONE;
1097 int get_folder_scan_status(void *handle, const char *storage_id, const char *path, int *status, char **err_msg)
1099 int ret = MEDIA_SVC_PLUGIN_ERROR_NONE;
1100 int storage_status = 0;
1102 if (handle == NULL) {
1103 __set_error_message(ERR_HANDLE, err_msg);
1104 return MEDIA_SVC_PLUGIN_ERROR;
1107 ret = media_svc_get_folder_scan_status(handle, storage_id, path, &storage_status);
1109 __set_error_message(ret, err_msg);
1110 return MEDIA_SVC_PLUGIN_ERROR;
1113 *status = storage_status;
1118 int set_folder_scan_status(void *handle, const char *storage_id, const char *path, int status, uid_t uid, char **err_msg)
1120 int ret = MEDIA_SVC_PLUGIN_ERROR_NONE;
1121 int storage_status = status;
1123 ret = media_svc_set_folder_scan_status(storage_id, path, storage_status, uid);
1125 __set_error_message(ret, err_msg);
1126 return MEDIA_SVC_PLUGIN_ERROR;
1132 int check_folder_modified(void *handle, const char *path, const char *storage_id, bool *modified, char **err_msg)
1134 int ret = MEDIA_SVC_PLUGIN_ERROR_NONE;
1137 if (handle == NULL) {
1138 __set_error_message(ERR_HANDLE, err_msg);
1139 return MEDIA_SVC_PLUGIN_ERROR;
1142 if (!STRING_VALID(path)) {
1143 __set_error_message(ERR_FILE_PATH, err_msg);
1144 return MEDIA_SVC_PLUGIN_ERROR;
1147 ret = media_svc_get_folder_modified_time(handle, path, storage_id, modified);
1149 __set_error_message(ret, err_msg);
1150 return MEDIA_SVC_PLUGIN_ERROR;
1156 int get_null_scan_folder_list(void *handle, const char *storage_id, const char *folder_path, char ***folder_list, int *count, char **err_msg)
1158 int ret = MEDIA_SVC_PLUGIN_ERROR_NONE;
1160 if (handle == NULL) {
1161 __set_error_message(ERR_HANDLE, err_msg);
1162 return MEDIA_SVC_PLUGIN_ERROR;
1165 if (count == NULL) {
1166 __set_error_message(ERR_HANDLE, err_msg);
1167 return MEDIA_SVC_PLUGIN_ERROR;
1170 ret = media_svc_get_null_scan_folder_list(handle, storage_id, folder_path, folder_list, count);
1172 __set_error_message(ret, err_msg);
1173 return MEDIA_SVC_PLUGIN_ERROR;
1179 int change_validity_item_batch(void **handle, const char *storage_id, const char *path, int des_validity, int src_validity, uid_t uid, char **err_msg)
1181 int ret = MEDIA_SVC_PLUGIN_ERROR_NONE;
1183 ret = media_svc_change_validity_item_batch(storage_id, path, des_validity, src_validity, uid);
1185 __set_error_message(ret, err_msg);
1186 return MEDIA_SVC_PLUGIN_ERROR;
1192 int check_folder_exist(void * handle, const char *storage_id, const char *folder_path, char **err_msg)
1194 int ret = MEDIA_SVC_PLUGIN_ERROR_NONE;
1196 if (handle == NULL) {
1197 __set_error_message(ERR_HANDLE, err_msg);
1198 return MEDIA_SVC_PLUGIN_ERROR;
1201 ret = media_svc_check_folder_exist_by_path(handle, storage_id, folder_path);
1203 __set_error_message(ret, err_msg);
1204 return MEDIA_SVC_PLUGIN_ERROR;
1207 return MEDIA_SVC_PLUGIN_ERROR_NONE;
1210 int count_subfolder(void *handle, const char *storage_id, const char *folder_path, int *count, char **err_msg)
1212 int ret = MEDIA_SVC_PLUGIN_ERROR_NONE;
1215 if (handle == NULL) {
1216 __set_error_message(ERR_HANDLE, err_msg);
1217 return MEDIA_SVC_PLUGIN_ERROR;
1220 ret = media_svc_check_subfolder_by_path(handle, storage_id, folder_path, &cnt);
1222 __set_error_message(ret, err_msg);
1223 return MEDIA_SVC_PLUGIN_ERROR;
1228 return MEDIA_SVC_PLUGIN_ERROR_NONE;
1231 int get_folder_id(void * handle, const char *storage_id, const char *path, char *folder_id, char **err_msg)
1233 int ret = MEDIA_SVC_PLUGIN_ERROR_NONE;
1235 if (handle == NULL) {
1236 __set_error_message(ERR_HANDLE, err_msg);
1237 return MEDIA_SVC_PLUGIN_ERROR;
1240 ret = media_svc_get_folder_id(handle, storage_id, path, folder_id);
1242 __set_error_message(ret, err_msg);
1243 return MEDIA_SVC_PLUGIN_ERROR;
1246 return MEDIA_SVC_PLUGIN_ERROR_NONE;
1249 int get_media_type(void *handle, const char *path, int *mediatype, char **err_msg)
1251 int ret = MEDIA_SVC_PLUGIN_ERROR_NONE;
1253 if (handle == NULL) {
1254 __set_error_message(ERR_HANDLE, err_msg);
1255 return MEDIA_SVC_PLUGIN_ERROR;
1258 ret = media_svc_get_media_type(path, mediatype);
1260 __set_error_message(ret, err_msg);
1261 return MEDIA_SVC_PLUGIN_ERROR;
1264 return MEDIA_SVC_PLUGIN_ERROR_NONE;