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)
457 int ret = MEDIA_SVC_PLUGIN_ERROR_NONE;
459 ret = thumbnail_request_extract_all_thumbs(uid);
461 return MEDIA_SVC_PLUGIN_ERROR;
465 ret = dcm_svc_request_extract_all(uid);
467 return MEDIA_SVC_PLUGIN_ERROR;
470 return MEDIA_SVC_PLUGIN_ERROR_NONE;
473 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)
475 int ret = MEDIA_SVC_PLUGIN_ERROR_NONE;
477 if (!STRING_VALID(dir_path)) {
478 __set_error_message(ERR_FOLDER_PATH, err_msg);
479 return MEDIA_SVC_PLUGIN_ERROR;
482 ret = media_svc_send_dir_update_noti(handle, storage_id, dir_path, folder_id, (media_item_update_type_e)update_type, pid);
484 __set_error_message(ret, err_msg);
485 return MEDIA_SVC_PLUGIN_ERROR;
488 return MEDIA_SVC_PLUGIN_ERROR_NONE;
491 int count_delete_items_in_folder(void *handle, const char *storage_id, const char *folder_path, int *count, char **err_msg)
493 int ret = MEDIA_SVC_PLUGIN_ERROR_NONE;
495 if (handle == NULL) {
496 __set_error_message(ERR_HANDLE, err_msg);
497 return MEDIA_SVC_PLUGIN_ERROR;
501 __set_error_message(ERR_HANDLE, err_msg);
502 return MEDIA_SVC_PLUGIN_ERROR;
505 if (!STRING_VALID(folder_path)) {
506 __set_error_message(ERR_FOLDER_PATH, err_msg);
507 return MEDIA_SVC_PLUGIN_ERROR;
510 ret = media_svc_count_invalid_items_in_folder(handle, storage_id, folder_path, count);
512 __set_error_message(ret, err_msg);
513 return MEDIA_SVC_PLUGIN_ERROR;
516 return MEDIA_SVC_PLUGIN_ERROR_NONE;
519 int check_db(void *handle, uid_t uid, char **err_msg)
521 int ret = MEDIA_SVC_PLUGIN_ERROR_NONE;
522 int user_version = -1;
524 ret = media_svc_get_user_version(handle, &user_version);
526 __set_error_message(ret, err_msg);
527 return MEDIA_SVC_PLUGIN_ERROR;
530 if (user_version == 0) {
532 ret = media_svc_create_table(uid);
534 __set_error_message(ret, err_msg);
535 return MEDIA_SVC_PLUGIN_ERROR;
539 ret = media_svc_check_db_upgrade(handle, user_version, uid);
541 __set_error_message(ret, err_msg);
542 return MEDIA_SVC_PLUGIN_ERROR;
546 return MEDIA_SVC_PLUGIN_ERROR_NONE;
549 int check_db_corrupt(void *handle, char **err_msg)
551 int ret = MEDIA_SVC_PLUGIN_ERROR_NONE;
554 ret = media_svc_check_db_corrupt(handle);
556 __set_error_message(ret, err_msg);
557 return MEDIA_SVC_PLUGIN_ERROR;
560 return MEDIA_SVC_PLUGIN_ERROR_NONE;
563 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)
565 int ret = MEDIA_SVC_PLUGIN_ERROR_NONE;
567 if (handle == NULL) {
568 __set_error_message(ERR_HANDLE, err_msg);
569 return MEDIA_SVC_PLUGIN_ERROR;
573 __set_error_message(ERR_HANDLE, err_msg);
574 return MEDIA_SVC_PLUGIN_ERROR;
577 ret = media_svc_get_folder_list(handle, start_path, folder_list, (time_t **)modified_time_list, item_num_list, count);
579 __set_error_message(ret, err_msg);
580 return MEDIA_SVC_PLUGIN_ERROR;
583 return MEDIA_SVC_PLUGIN_ERROR_NONE;
586 int update_folder_time(void *handle, const char *storage_id, char *folder_path, uid_t uid, char **err_msg)
588 int ret = MEDIA_SVC_PLUGIN_ERROR_NONE;
590 if (handle == NULL) {
591 __set_error_message(ERR_HANDLE, err_msg);
592 return MEDIA_SVC_PLUGIN_ERROR;
595 if (folder_path == NULL) {
596 __set_error_message(ERR_HANDLE, err_msg);
597 return MEDIA_SVC_PLUGIN_ERROR;
600 ret = media_svc_update_folder_time(handle, storage_id, folder_path, uid);
602 __set_error_message(ret, err_msg);
603 return MEDIA_SVC_PLUGIN_ERROR;
606 return MEDIA_SVC_PLUGIN_ERROR_NONE;
609 int get_uuid(void * handle, char **uuid, char **err_msg)
611 int ret = MEDIA_SVC_PLUGIN_ERROR_NONE;
613 ret = media_svc_generate_uuid(uuid);
615 __set_error_message(ret, err_msg);
616 return MEDIA_SVC_PLUGIN_ERROR;
619 return MEDIA_SVC_PLUGIN_ERROR_NONE;
622 int get_mmc_info(void * handle, char **storage_name, char **storage_path, int *validity, bool *info_exist, char **err_msg)
624 int ret = MEDIA_SVC_PLUGIN_ERROR_NONE;
626 if (handle == NULL) {
627 __set_error_message(ERR_HANDLE, err_msg);
628 return MEDIA_SVC_PLUGIN_ERROR;
631 ret = media_svc_get_mmc_info(handle, storage_name, storage_path, validity, info_exist);
633 __set_error_message(MS_MEDIA_ERR_DB_NO_RECORD, err_msg);
634 return MEDIA_SVC_PLUGIN_ERROR;
637 return MEDIA_SVC_PLUGIN_ERROR_NONE;
640 int check_storage(void * handle, const char *storage_id, const char *storage_name, char **storage_path, int *validity, char **err_msg)
642 int ret = MEDIA_SVC_PLUGIN_ERROR_NONE;
644 if (handle == NULL) {
645 __set_error_message(ERR_HANDLE, err_msg);
646 return MEDIA_SVC_PLUGIN_ERROR;
649 ret = media_svc_check_storage(handle, storage_id, storage_name, storage_path, validity);
651 __set_error_message(ret, err_msg);
652 return MEDIA_SVC_PLUGIN_ERROR;
655 return MEDIA_SVC_PLUGIN_ERROR_NONE;
658 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)
660 int ret = MEDIA_SVC_PLUGIN_ERROR_NONE;
662 if (handle == NULL) {
663 __set_error_message(ERR_HANDLE, err_msg);
664 return MEDIA_SVC_PLUGIN_ERROR;
667 ret = media_svc_insert_storage(handle, storage_id, storage_name, storage_path, NULL, storage_type, uid);
669 __set_error_message(ret, err_msg);
670 return MEDIA_SVC_PLUGIN_ERROR;
673 return MEDIA_SVC_PLUGIN_ERROR_NONE;
676 int update_storage(void *handle, const char *storage_id, const char *storage_path, uid_t uid, char **err_msg)
678 int ret = MEDIA_SVC_PLUGIN_ERROR_NONE;
680 if (handle == NULL) {
681 __set_error_message(ERR_HANDLE, err_msg);
682 return MEDIA_SVC_PLUGIN_ERROR;
685 ret = media_svc_update_storage(handle, storage_id, storage_path, uid);
687 __set_error_message(ret, err_msg);
688 return MEDIA_SVC_PLUGIN_ERROR;
691 return MEDIA_SVC_PLUGIN_ERROR_NONE;
694 int delete_storage(void * handle, const char *storage_id, const char *storage_name, uid_t uid, char **err_msg)
696 int ret = MEDIA_SVC_PLUGIN_ERROR_NONE;
698 if (handle == NULL) {
699 __set_error_message(ERR_HANDLE, err_msg);
700 return MEDIA_SVC_PLUGIN_ERROR;
703 ret = media_svc_delete_storage(handle, storage_id, storage_name, uid);
705 __set_error_message(ret, err_msg);
706 return MEDIA_SVC_PLUGIN_ERROR;
709 return MEDIA_SVC_PLUGIN_ERROR_NONE;
712 int set_storage_validity(void * handle, const char *storage_id, int validity, uid_t uid, char **err_msg)
714 int ret = MEDIA_SVC_PLUGIN_ERROR_NONE;
716 if (handle == NULL) {
717 __set_error_message(ERR_HANDLE, err_msg);
718 return MEDIA_SVC_PLUGIN_ERROR;
721 ret = media_svc_set_storage_validity(handle, storage_id, validity, uid);
723 __set_error_message(ret, err_msg);
724 return MEDIA_SVC_PLUGIN_ERROR;
727 return MEDIA_SVC_PLUGIN_ERROR_NONE;
730 int set_all_storage_validity(void * handle, int validity, uid_t uid, char **err_msg)
732 int ret = MEDIA_SVC_PLUGIN_ERROR_NONE;
734 if (handle == NULL) {
735 __set_error_message(ERR_HANDLE, err_msg);
736 return MEDIA_SVC_PLUGIN_ERROR;
739 ret = media_svc_set_storage_validity(handle, NULL, validity, uid);
741 __set_error_message(ret, err_msg);
742 return MEDIA_SVC_PLUGIN_ERROR;
745 return MEDIA_SVC_PLUGIN_ERROR_NONE;
748 int get_storage_id(void * handle, const char *path, char *storage_id, char **err_msg)
750 int ret = MEDIA_SVC_PLUGIN_ERROR_NONE;
752 if (handle == NULL) {
753 __set_error_message(ERR_HANDLE, err_msg);
754 return MEDIA_SVC_PLUGIN_ERROR;
757 ret = media_svc_get_storage_id(handle, path, storage_id);
759 __set_error_message(ret, err_msg);
760 return MEDIA_SVC_PLUGIN_ERROR;
763 return MEDIA_SVC_PLUGIN_ERROR_NONE;
766 int get_storage_scan_status(void * handle, const char *storage_id, int *status, char **err_msg)
768 int ret = MEDIA_SVC_PLUGIN_ERROR_NONE;
769 media_svc_scan_status_type_e storage_status = 0;
771 if (handle == NULL) {
772 __set_error_message(ERR_HANDLE, err_msg);
773 return MEDIA_SVC_PLUGIN_ERROR;
776 ret = media_svc_get_storage_scan_status(handle, storage_id, &storage_status);
778 __set_error_message(ret, err_msg);
779 return MEDIA_SVC_PLUGIN_ERROR;
782 *status = storage_status;
784 return MEDIA_SVC_PLUGIN_ERROR_NONE;
787 int set_storage_scan_status(void *handle, const char *storage_id, int status, uid_t uid, char **err_msg)
789 int ret = MEDIA_SVC_PLUGIN_ERROR_NONE;
790 media_svc_scan_status_type_e storage_status = status;
792 ret = media_svc_set_storage_scan_status(storage_id, storage_status, uid);
794 __set_error_message(ret, err_msg);
795 return MEDIA_SVC_PLUGIN_ERROR;
798 return MEDIA_SVC_PLUGIN_ERROR_NONE;
801 int get_storage_list(void *handle, char ***storage_list, char ***storage_id_list, int **scan_status_list, int *count, char **err_msg)
803 int ret = MEDIA_SVC_PLUGIN_ERROR_NONE;
805 if (handle == NULL) {
806 __set_error_message(ERR_HANDLE, err_msg);
807 return MEDIA_SVC_PLUGIN_ERROR;
811 __set_error_message(ERR_HANDLE, err_msg);
812 return MEDIA_SVC_PLUGIN_ERROR;
815 ret = media_svc_get_storage_list(handle, storage_list, storage_id_list, scan_status_list, count);
817 __set_error_message(ret, err_msg);
818 return MEDIA_SVC_PLUGIN_ERROR;
821 return MEDIA_SVC_PLUGIN_ERROR_NONE;
824 int update_item_begin(void *handle, int item_cnt, char **err_msg)
826 int ret = MEDIA_SVC_PLUGIN_ERROR_NONE;
828 ret = media_svc_update_item_begin(item_cnt);
830 __set_error_message(ret, err_msg);
831 return MEDIA_SVC_PLUGIN_ERROR;
834 return MEDIA_SVC_PLUGIN_ERROR_NONE;
837 int update_item_end(void *handle, uid_t uid, char **err_msg)
839 int ret = MEDIA_SVC_PLUGIN_ERROR_NONE;
841 ret = media_svc_update_item_end(uid);
843 __set_error_message(ret, err_msg);
844 return MEDIA_SVC_PLUGIN_ERROR;
847 return MEDIA_SVC_PLUGIN_ERROR_NONE;
850 int update_item_meta(void *handle, const char *file_path, const char *storage_id, int storage_type, uid_t uid, char **err_msg)
852 int ret = MEDIA_SVC_PLUGIN_ERROR_NONE;
854 if (handle == NULL) {
855 __set_error_message(ERR_HANDLE, err_msg);
856 return MEDIA_SVC_PLUGIN_ERROR;
859 if (file_path == NULL) {
860 __set_error_message(ERR_HANDLE, err_msg);
861 return MEDIA_SVC_PLUGIN_ERROR;
864 if (storage_id == NULL) {
865 __set_error_message(ERR_HANDLE, err_msg);
866 return MEDIA_SVC_PLUGIN_ERROR;
869 ret = media_svc_update_item_meta(handle, file_path, storage_id, storage_type, uid);
871 __set_error_message(ret, err_msg);
872 return MEDIA_SVC_PLUGIN_ERROR;
875 return MEDIA_SVC_PLUGIN_ERROR_NONE;
878 int insert_item_scan(void * handle, const char *storage_id, const char *file_path, int storage_type, uid_t uid, char **err_msg)
880 int ret = MEDIA_SVC_PLUGIN_ERROR_NONE;
882 if (handle == NULL) {
883 __set_error_message(ERR_HANDLE, err_msg);
884 return MEDIA_SVC_PLUGIN_ERROR;
887 if (!STRING_VALID(file_path)) {
888 __set_error_message(ERR_FILE_PATH, err_msg);
889 return MEDIA_SVC_PLUGIN_ERROR;
892 if (!STORAGE_VALID(storage_type)) {
893 __set_error_message(ERR_STORAGE_TYPE, err_msg);
894 return MEDIA_SVC_PLUGIN_ERROR;
897 ret = media_svc_insert_item_pass1(handle, storage_id, storage_type, file_path, FALSE, uid);
899 __set_error_message(ret, err_msg);
900 return MEDIA_SVC_PLUGIN_ERROR;
903 return MEDIA_SVC_PLUGIN_ERROR_NONE;
906 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)
908 int ret = MEDIA_SVC_PLUGIN_ERROR_NONE;
910 if (handle == NULL) {
911 __set_error_message(ERR_HANDLE, err_msg);
912 return MEDIA_SVC_PLUGIN_ERROR;
915 if (!STORAGE_VALID(storage_type)) {
916 __set_error_message(ERR_STORAGE_TYPE, err_msg);
917 return MEDIA_SVC_PLUGIN_ERROR;
920 ret = media_svc_insert_item_pass2(handle, storage_id, storage_type, scan_type, path, burst, uid);
922 __set_error_message(ret, err_msg);
923 return MEDIA_SVC_PLUGIN_ERROR;
926 return MEDIA_SVC_PLUGIN_ERROR_NONE;
929 int insert_folder_begin(void * handle, int item_cnt, char **err_msg)
931 int ret = MEDIA_SVC_PLUGIN_ERROR_NONE;
933 ret = media_svc_insert_folder_begin(item_cnt);
935 __set_error_message(ret, err_msg);
936 return MEDIA_SVC_PLUGIN_ERROR;
939 return MEDIA_SVC_PLUGIN_ERROR_NONE;
942 int insert_folder_end(void *handle, uid_t uid, char **err_msg)
944 int ret = MEDIA_SVC_PLUGIN_ERROR_NONE;
946 ret = media_svc_insert_folder_end(uid);
948 __set_error_message(ret, err_msg);
949 return MEDIA_SVC_PLUGIN_ERROR;
952 return MEDIA_SVC_PLUGIN_ERROR_NONE;
955 int insert_folder(void * handle, const char *storage_id, const char *file_path, int storage_type, uid_t uid, char **err_msg)
957 int ret = MEDIA_SVC_PLUGIN_ERROR_NONE;
959 if (handle == NULL) {
960 __set_error_message(ERR_HANDLE, err_msg);
961 return MEDIA_SVC_PLUGIN_ERROR;
964 if (!STRING_VALID(file_path)) {
965 __set_error_message(ERR_FILE_PATH, err_msg);
966 return MEDIA_SVC_PLUGIN_ERROR;
969 if (!STORAGE_VALID(storage_type)) {
970 __set_error_message(ERR_STORAGE_TYPE, err_msg);
971 return MEDIA_SVC_PLUGIN_ERROR;
974 ret = media_svc_insert_folder(handle, storage_id, storage_type, file_path, uid);
976 __set_error_message(ret, err_msg);
977 return MEDIA_SVC_PLUGIN_ERROR;
980 return MEDIA_SVC_PLUGIN_ERROR_NONE;
983 int delete_invalid_folder(void * handle, const char *storage_id, uid_t uid, char **err_msg)
985 int ret = MEDIA_SVC_PLUGIN_ERROR_NONE;
987 ret = media_svc_delete_invalid_folder(storage_id, uid);
989 __set_error_message(ret, err_msg);
990 return MEDIA_SVC_PLUGIN_ERROR;
993 return MEDIA_SVC_PLUGIN_ERROR_NONE;
996 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)
998 int ret = MEDIA_SVC_PLUGIN_ERROR_NONE;
1000 if (handle == NULL) {
1001 __set_error_message(ERR_HANDLE, err_msg);
1002 return MEDIA_SVC_PLUGIN_ERROR;
1005 ret = media_svc_set_folder_validity(handle, storage_id, start_path, validity, is_recursive, uid);
1007 __set_error_message(ret, err_msg);
1008 return MEDIA_SVC_PLUGIN_ERROR;
1011 return MEDIA_SVC_PLUGIN_ERROR_NONE;
1014 int get_folder_scan_status(void *handle, const char *storage_id, const char *path, int *status, char **err_msg)
1016 int ret = MEDIA_SVC_PLUGIN_ERROR_NONE;
1017 int storage_status = 0;
1019 if (handle == NULL) {
1020 __set_error_message(ERR_HANDLE, err_msg);
1021 return MEDIA_SVC_PLUGIN_ERROR;
1024 ret = media_svc_get_folder_scan_status(handle, storage_id, path, &storage_status);
1026 __set_error_message(ret, err_msg);
1027 return MEDIA_SVC_PLUGIN_ERROR;
1030 *status = storage_status;
1035 int set_folder_scan_status(void *handle, const char *storage_id, const char *path, int status, uid_t uid, char **err_msg)
1037 int ret = MEDIA_SVC_PLUGIN_ERROR_NONE;
1038 int storage_status = status;
1040 ret = media_svc_set_folder_scan_status(storage_id, path, storage_status, uid);
1042 __set_error_message(ret, err_msg);
1043 return MEDIA_SVC_PLUGIN_ERROR;
1049 int check_folder_modified(void *handle, const char *path, const char *storage_id, bool *modified, char **err_msg)
1051 int ret = MEDIA_SVC_PLUGIN_ERROR_NONE;
1054 if (handle == NULL) {
1055 __set_error_message(ERR_HANDLE, err_msg);
1056 return MEDIA_SVC_PLUGIN_ERROR;
1059 if (!STRING_VALID(path)) {
1060 __set_error_message(ERR_FILE_PATH, err_msg);
1061 return MEDIA_SVC_PLUGIN_ERROR;
1064 ret = media_svc_get_folder_modified_time(handle, path, storage_id, modified);
1066 __set_error_message(ret, err_msg);
1067 return MEDIA_SVC_PLUGIN_ERROR;
1073 int get_null_scan_folder_list(void *handle, const char *storage_id, const char *folder_path, char ***folder_list, int *count, char **err_msg)
1075 int ret = MEDIA_SVC_PLUGIN_ERROR_NONE;
1077 if (handle == NULL) {
1078 __set_error_message(ERR_HANDLE, err_msg);
1079 return MEDIA_SVC_PLUGIN_ERROR;
1082 if (count == NULL) {
1083 __set_error_message(ERR_HANDLE, err_msg);
1084 return MEDIA_SVC_PLUGIN_ERROR;
1087 ret = media_svc_get_null_scan_folder_list(handle, storage_id, folder_path, folder_list, count);
1089 __set_error_message(ret, err_msg);
1090 return MEDIA_SVC_PLUGIN_ERROR;
1096 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)
1098 int ret = MEDIA_SVC_PLUGIN_ERROR_NONE;
1100 ret = media_svc_change_validity_item_batch(storage_id, path, des_validity, src_validity, uid);
1102 __set_error_message(ret, err_msg);
1103 return MEDIA_SVC_PLUGIN_ERROR;
1109 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)
1111 int ret = MEDIA_SVC_PLUGIN_ERROR_NONE;
1113 if (handle == NULL) {
1114 __set_error_message(ERR_HANDLE, err_msg);
1115 return MEDIA_SVC_PLUGIN_ERROR;
1118 ret = media_svc_delete_invalid_folder_by_path(handle, storage_id, folder_path, uid, delete_count);
1120 __set_error_message(ret, err_msg);
1121 return MEDIA_SVC_PLUGIN_ERROR;
1124 return MEDIA_SVC_PLUGIN_ERROR_NONE;
1127 int check_folder_exist(void * handle, const char *storage_id, const char *folder_path, char **err_msg)
1129 int ret = MEDIA_SVC_PLUGIN_ERROR_NONE;
1131 if (handle == NULL) {
1132 __set_error_message(ERR_HANDLE, err_msg);
1133 return MEDIA_SVC_PLUGIN_ERROR;
1136 ret = media_svc_check_folder_exist_by_path(handle, storage_id, folder_path);
1138 __set_error_message(ret, err_msg);
1139 return MEDIA_SVC_PLUGIN_ERROR;
1142 return MEDIA_SVC_PLUGIN_ERROR_NONE;
1145 int count_subfolder(void *handle, const char *storage_id, const char *folder_path, int *count, char **err_msg)
1147 int ret = MEDIA_SVC_PLUGIN_ERROR_NONE;
1150 if (handle == NULL) {
1151 __set_error_message(ERR_HANDLE, err_msg);
1152 return MEDIA_SVC_PLUGIN_ERROR;
1155 ret = media_svc_check_subfolder_by_path(handle, storage_id, folder_path, &cnt);
1157 __set_error_message(ret, err_msg);
1158 return MEDIA_SVC_PLUGIN_ERROR;
1163 return MEDIA_SVC_PLUGIN_ERROR_NONE;
1166 int get_folder_id(void * handle, const char *storage_id, const char *path, char *folder_id, char **err_msg)
1168 int ret = MEDIA_SVC_PLUGIN_ERROR_NONE;
1170 if (handle == NULL) {
1171 __set_error_message(ERR_HANDLE, err_msg);
1172 return MEDIA_SVC_PLUGIN_ERROR;
1175 ret = media_svc_get_folder_id(handle, storage_id, path, folder_id);
1177 __set_error_message(ret, err_msg);
1178 return MEDIA_SVC_PLUGIN_ERROR;
1181 return MEDIA_SVC_PLUGIN_ERROR_NONE;