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-svc.h"
27 #include "media-svc-util.h"
29 #define MEDIA_SVC_PLUGIN_ERROR_NONE 0
30 #define MEDIA_SVC_PLUGIN_ERROR -1
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) || (storage == MEDIA_SVC_STORAGE_EXTERNAL_USB)) ? TRUE : FALSE)
47 } media_svc_error_type_e;
49 static void __set_error_message(int err_type, char **err_msg);
51 static void __set_error_message(int err_type, char **err_msg)
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");
87 *err_msg = strdup("error unknown");
92 int connect_db(void **handle, uid_t uid, char **err_msg)
94 int ret = media_svc_connect(handle, uid, true);
97 __set_error_message(ret, err_msg);
98 return MEDIA_SVC_PLUGIN_ERROR;
101 return MEDIA_SVC_PLUGIN_ERROR_NONE;
104 int disconnect_db(void *handle, char **err_msg)
106 int ret = MEDIA_SVC_PLUGIN_ERROR_NONE;
108 if (handle == NULL) {
109 __set_error_message(ERR_HANDLE, err_msg);
110 return MEDIA_SVC_PLUGIN_ERROR;
113 ret = media_svc_disconnect(handle);
115 __set_error_message(ret, err_msg);
116 return MEDIA_SVC_PLUGIN_ERROR;
119 return MEDIA_SVC_PLUGIN_ERROR_NONE;
122 int check_item_exist(void *handle, const char *storage_id, const char *file_path, bool *modified, char **err_msg)
124 int ret = MEDIA_SVC_PLUGIN_ERROR_NONE;
127 if (handle == NULL) {
128 __set_error_message(ERR_HANDLE, err_msg);
129 return MEDIA_SVC_PLUGIN_ERROR;
132 if (!STRING_VALID(file_path)) {
133 __set_error_message(ERR_FILE_PATH, err_msg);
134 return MEDIA_SVC_PLUGIN_ERROR;
137 time_t modified_time = 0;
138 unsigned long long file_size = 0;
141 ret = media_svc_get_file_info(handle, storage_id, file_path, &modified_time, &file_size);
142 if (ret == MS_MEDIA_ERR_NONE) {
143 memset(&st, 0, sizeof(struct stat));
144 if (stat(file_path, &st) == 0) {
145 if ((st.st_mtime != modified_time) || (st.st_size != file_size))
151 return MEDIA_SVC_PLUGIN_ERROR_NONE; /*exist */
154 __set_error_message(ERR_CHECK_ITEM, err_msg);
156 return MEDIA_SVC_PLUGIN_ERROR; /*not exist */
159 int insert_item_begin(void *handle, int item_cnt, int with_noti, int from_pid, char **err_msg)
161 int ret = MEDIA_SVC_PLUGIN_ERROR_NONE;
163 ret = media_svc_insert_item_begin(item_cnt, with_noti, from_pid);
165 __set_error_message(ret, err_msg);
166 return MEDIA_SVC_PLUGIN_ERROR;
169 return MEDIA_SVC_PLUGIN_ERROR_NONE;
172 int insert_item_end(void *handle, uid_t uid, char **err_msg)
174 int ret = MEDIA_SVC_PLUGIN_ERROR_NONE;
176 ret = media_svc_insert_item_end(uid);
178 __set_error_message(ret, err_msg);
179 return MEDIA_SVC_PLUGIN_ERROR;
182 return MEDIA_SVC_PLUGIN_ERROR_NONE;
185 int insert_item(void *handle, const char *storage_id, const char *file_path, int storage_type, uid_t uid, char **err_msg)
187 int ret = MEDIA_SVC_PLUGIN_ERROR_NONE;
189 if (handle == NULL) {
190 __set_error_message(ERR_HANDLE, err_msg);
191 return MEDIA_SVC_PLUGIN_ERROR;
194 if (!STRING_VALID(file_path)) {
195 __set_error_message(ERR_FILE_PATH, err_msg);
196 return MEDIA_SVC_PLUGIN_ERROR;
199 if (!STORAGE_VALID(storage_type)) {
200 __set_error_message(ERR_STORAGE_TYPE, err_msg);
201 return MEDIA_SVC_PLUGIN_ERROR;
204 ret = media_svc_insert_item_bulk(handle, storage_id, storage_type, file_path, FALSE, uid);
206 __set_error_message(ret, err_msg);
207 return MEDIA_SVC_PLUGIN_ERROR;
210 return MEDIA_SVC_PLUGIN_ERROR_NONE;
213 int insert_item_immediately(void *handle, const char *storage_id, const char *file_path, int storage_type, uid_t uid, char **err_msg)
215 int ret = MEDIA_SVC_PLUGIN_ERROR_NONE;
217 if (handle == NULL) {
218 __set_error_message(ERR_HANDLE, err_msg);
219 return MEDIA_SVC_PLUGIN_ERROR;
222 if (!STRING_VALID(file_path)) {
223 __set_error_message(ERR_FILE_PATH, err_msg);
224 return MEDIA_SVC_PLUGIN_ERROR;
227 if (!STORAGE_VALID(storage_type)) {
228 __set_error_message(ERR_STORAGE_TYPE, err_msg);
229 return MEDIA_SVC_PLUGIN_ERROR;
232 ret = media_svc_insert_item_immediately(handle, storage_id, storage_type, file_path, uid);
234 __set_error_message(ret, err_msg);
235 return MEDIA_SVC_PLUGIN_ERROR;
238 return MEDIA_SVC_PLUGIN_ERROR_NONE;
241 int insert_burst_item(void *handle, const char *storage_id, const char *file_path, int storage_type, uid_t uid, char **err_msg)
243 int ret = MEDIA_SVC_PLUGIN_ERROR_NONE;
245 if (handle == NULL) {
246 __set_error_message(ERR_HANDLE, err_msg);
247 return MEDIA_SVC_PLUGIN_ERROR;
250 if (!STRING_VALID(file_path)) {
251 __set_error_message(ERR_FILE_PATH, err_msg);
252 return MEDIA_SVC_PLUGIN_ERROR;
255 if (!STORAGE_VALID(storage_type)) {
256 __set_error_message(ERR_STORAGE_TYPE, err_msg);
257 return MEDIA_SVC_PLUGIN_ERROR;
260 ret = media_svc_insert_item_bulk(handle, storage_id, storage_type, file_path, TRUE, uid);
262 __set_error_message(ret, err_msg);
263 return MEDIA_SVC_PLUGIN_ERROR;
266 return MEDIA_SVC_PLUGIN_ERROR_NONE;
269 int set_all_storage_items_validity(void *handle, const char *storage_id, int storage_type, int validity, uid_t uid, char **err_msg)
271 int ret = MEDIA_SVC_PLUGIN_ERROR_NONE;
273 if (!STORAGE_VALID(storage_type)) {
274 __set_error_message(ERR_STORAGE_TYPE, err_msg);
275 return MEDIA_SVC_PLUGIN_ERROR;
278 ret = media_svc_set_all_storage_items_validity(storage_id, storage_type, validity, uid);
280 __set_error_message(ret, err_msg);
281 return MEDIA_SVC_PLUGIN_ERROR;
284 return MEDIA_SVC_PLUGIN_ERROR_NONE;
287 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)
289 int ret = MEDIA_SVC_PLUGIN_ERROR_NONE;
291 if (handle == NULL) {
292 __set_error_message(ERR_HANDLE, err_msg);
293 return MEDIA_SVC_PLUGIN_ERROR;
296 if (!STRING_VALID(folder_path)) {
297 __set_error_message(ERR_FOLDER_PATH, err_msg);
298 return MEDIA_SVC_PLUGIN_ERROR;
301 ret = media_svc_set_folder_items_validity(handle, storage_id, folder_path, validity, recursive, uid);
303 __set_error_message(ret, err_msg);
304 return MEDIA_SVC_PLUGIN_ERROR;
307 return MEDIA_SVC_PLUGIN_ERROR_NONE;
310 int set_item_validity_begin(void *handle, int item_cnt, char **err_msg)
312 int ret = MEDIA_SVC_PLUGIN_ERROR_NONE;
314 ret = media_svc_set_item_validity_begin(item_cnt);
316 __set_error_message(ret, err_msg);
317 return MEDIA_SVC_PLUGIN_ERROR;
320 return MEDIA_SVC_PLUGIN_ERROR_NONE;
323 int set_item_validity_end(void *handle, uid_t uid, char **err_msg)
325 int ret = MEDIA_SVC_PLUGIN_ERROR_NONE;
327 ret = media_svc_set_item_validity_end(uid);
329 __set_error_message(ret, err_msg);
330 return MEDIA_SVC_PLUGIN_ERROR;
333 return MEDIA_SVC_PLUGIN_ERROR_NONE;
336 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)
338 int ret = MEDIA_SVC_PLUGIN_ERROR_NONE;
340 if (!STRING_VALID(file_path)) {
341 __set_error_message(ERR_FILE_PATH, err_msg);
342 return MEDIA_SVC_PLUGIN_ERROR;
345 ret = media_svc_set_item_validity(storage_id, file_path, validity, uid);
348 __set_error_message(ret, err_msg);
349 return MEDIA_SVC_PLUGIN_ERROR;
352 return MEDIA_SVC_PLUGIN_ERROR_NONE;
355 int delete_item(void *handle, const char *storage_id, const char *file_path, uid_t uid, char **err_msg)
357 int ret = MEDIA_SVC_PLUGIN_ERROR_NONE;
359 if (handle == NULL) {
360 __set_error_message(ERR_HANDLE, err_msg);
361 return MEDIA_SVC_PLUGIN_ERROR;
364 if (!STRING_VALID(file_path)) {
365 __set_error_message(ERR_FILE_PATH, err_msg);
366 return MEDIA_SVC_PLUGIN_ERROR;
369 ret = media_svc_check_item_exist_by_path(handle, storage_id, file_path);
371 ret = media_svc_delete_item_by_path(handle, storage_id, file_path, uid);
374 __set_error_message(ret, err_msg);
375 return MEDIA_SVC_PLUGIN_ERROR;
377 return MEDIA_SVC_PLUGIN_ERROR_NONE;
380 __set_error_message(ERR_CHECK_ITEM, err_msg); /*not exist in DB so can't delete item. */
381 return MEDIA_SVC_PLUGIN_ERROR;
384 int delete_all_items_in_storage(void *handle, const char *storage_id, int storage_type, uid_t uid, char **err_msg)
386 int ret = MEDIA_SVC_PLUGIN_ERROR_NONE;
388 if (!STORAGE_VALID(storage_type)) {
389 __set_error_message(ERR_STORAGE_TYPE, err_msg);
390 return MEDIA_SVC_PLUGIN_ERROR;
393 ret = media_svc_delete_all_items_in_storage(storage_id, storage_type, uid);
395 __set_error_message(ret, err_msg);
396 return MEDIA_SVC_PLUGIN_ERROR;
399 return MEDIA_SVC_PLUGIN_ERROR_NONE;
402 int delete_all_invalid_items_in_storage(void *handle, const char *storage_id, int storage_type, uid_t uid, char **err_msg)
404 int ret = MEDIA_SVC_PLUGIN_ERROR_NONE;
406 if (handle == NULL) {
407 __set_error_message(ERR_HANDLE, err_msg);
408 return MEDIA_SVC_PLUGIN_ERROR;
411 if (!STORAGE_VALID(storage_type)) {
412 __set_error_message(ERR_STORAGE_TYPE, err_msg);
413 return MEDIA_SVC_PLUGIN_ERROR;
416 ret = media_svc_delete_invalid_items_in_storage(handle, storage_id, storage_type, uid);
418 __set_error_message(ret, err_msg);
419 return MEDIA_SVC_PLUGIN_ERROR;
422 return MEDIA_SVC_PLUGIN_ERROR_NONE;
425 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)
427 int ret = MEDIA_SVC_PLUGIN_ERROR_NONE;
429 if (handle == NULL) {
430 __set_error_message(ERR_HANDLE, err_msg);
431 return MEDIA_SVC_PLUGIN_ERROR;
434 if (!STRING_VALID(folder_path)) {
435 __set_error_message(ERR_FOLDER_PATH, err_msg);
436 return MEDIA_SVC_PLUGIN_ERROR;
439 ret = media_svc_delete_invalid_items_in_folder(handle, storage_id, folder_path, is_recursve, uid);
441 __set_error_message(ret, err_msg);
442 return MEDIA_SVC_PLUGIN_ERROR;
445 return MEDIA_SVC_PLUGIN_ERROR_NONE;
449 int update_begin(void)
451 return MEDIA_SVC_PLUGIN_ERROR_NONE;
454 int update_end(const char *start_path, 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;
464 return MEDIA_SVC_PLUGIN_ERROR_NONE;
467 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)
469 int ret = MEDIA_SVC_PLUGIN_ERROR_NONE;
471 if (!STRING_VALID(dir_path)) {
472 __set_error_message(ERR_FOLDER_PATH, err_msg);
473 return MEDIA_SVC_PLUGIN_ERROR;
476 ret = media_svc_send_dir_update_noti(handle, storage_id, dir_path, folder_id, (media_item_update_type_e)update_type, pid);
478 __set_error_message(ret, err_msg);
479 return MEDIA_SVC_PLUGIN_ERROR;
482 return MEDIA_SVC_PLUGIN_ERROR_NONE;
485 int count_delete_items_in_folder(void *handle, const char *storage_id, const char *folder_path, int *count, char **err_msg)
487 int ret = MEDIA_SVC_PLUGIN_ERROR_NONE;
489 if (handle == NULL) {
490 __set_error_message(ERR_HANDLE, err_msg);
491 return MEDIA_SVC_PLUGIN_ERROR;
495 __set_error_message(ERR_HANDLE, err_msg);
496 return MEDIA_SVC_PLUGIN_ERROR;
499 if (!STRING_VALID(folder_path)) {
500 __set_error_message(ERR_FOLDER_PATH, err_msg);
501 return MEDIA_SVC_PLUGIN_ERROR;
504 ret = media_svc_count_invalid_items_in_folder(handle, storage_id, folder_path, count);
506 __set_error_message(ret, err_msg);
507 return MEDIA_SVC_PLUGIN_ERROR;
510 return MEDIA_SVC_PLUGIN_ERROR_NONE;
513 int check_db(void *handle, uid_t uid, char **err_msg)
515 int ret = MEDIA_SVC_PLUGIN_ERROR_NONE;
516 int user_version = -1;
518 ret = media_svc_get_user_version(handle, &user_version);
520 __set_error_message(ret, err_msg);
521 return MEDIA_SVC_PLUGIN_ERROR;
524 if (user_version == 0) {
526 ret = media_svc_create_table(uid);
528 __set_error_message(ret, err_msg);
529 return MEDIA_SVC_PLUGIN_ERROR;
533 ret = media_svc_check_db_upgrade(handle, user_version, uid);
535 __set_error_message(ret, err_msg);
536 return MEDIA_SVC_PLUGIN_ERROR;
540 return MEDIA_SVC_PLUGIN_ERROR_NONE;
543 int check_db_corrupt(void *handle, char **err_msg)
545 int ret = MEDIA_SVC_PLUGIN_ERROR_NONE;
548 ret = media_svc_check_db_corrupt(handle);
550 __set_error_message(ret, err_msg);
551 return MEDIA_SVC_PLUGIN_ERROR;
554 return MEDIA_SVC_PLUGIN_ERROR_NONE;
557 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)
559 int ret = MEDIA_SVC_PLUGIN_ERROR_NONE;
561 if (handle == NULL) {
562 __set_error_message(ERR_HANDLE, err_msg);
563 return MEDIA_SVC_PLUGIN_ERROR;
567 __set_error_message(ERR_HANDLE, err_msg);
568 return MEDIA_SVC_PLUGIN_ERROR;
571 ret = media_svc_get_folder_list(handle, start_path, folder_list, (time_t **)modified_time_list, item_num_list, count);
573 __set_error_message(ret, err_msg);
574 return MEDIA_SVC_PLUGIN_ERROR;
577 return MEDIA_SVC_PLUGIN_ERROR_NONE;
580 int update_folder_time(void *handle, const char *storage_id, char *folder_path, uid_t uid, char **err_msg)
582 int ret = MEDIA_SVC_PLUGIN_ERROR_NONE;
584 if (handle == NULL) {
585 __set_error_message(ERR_HANDLE, err_msg);
586 return MEDIA_SVC_PLUGIN_ERROR;
589 if (folder_path == NULL) {
590 __set_error_message(ERR_HANDLE, err_msg);
591 return MEDIA_SVC_PLUGIN_ERROR;
594 ret = media_svc_update_folder_time(handle, storage_id, folder_path, uid);
596 __set_error_message(ret, err_msg);
597 return MEDIA_SVC_PLUGIN_ERROR;
600 return MEDIA_SVC_PLUGIN_ERROR_NONE;
603 int get_uuid(void * handle, char **uuid, char **err_msg)
605 int ret = MEDIA_SVC_PLUGIN_ERROR_NONE;
607 ret = media_svc_generate_uuid(uuid);
609 __set_error_message(ret, err_msg);
610 return MEDIA_SVC_PLUGIN_ERROR;
613 return MEDIA_SVC_PLUGIN_ERROR_NONE;
616 int get_mmc_info(void * handle, char **storage_name, char **storage_path, int *validity, bool *info_exist, char **err_msg)
618 int ret = MEDIA_SVC_PLUGIN_ERROR_NONE;
620 if (handle == NULL) {
621 __set_error_message(ERR_HANDLE, err_msg);
622 return MEDIA_SVC_PLUGIN_ERROR;
625 ret = media_svc_get_mmc_info(handle, storage_name, storage_path, validity, info_exist);
627 __set_error_message(MS_MEDIA_ERR_DB_NO_RECORD, err_msg);
628 return MEDIA_SVC_PLUGIN_ERROR;
631 return MEDIA_SVC_PLUGIN_ERROR_NONE;
634 int check_storage(void * handle, const char *storage_id, const char *storage_name, char **storage_path, int *validity, char **err_msg)
636 int ret = MEDIA_SVC_PLUGIN_ERROR_NONE;
638 if (handle == NULL) {
639 __set_error_message(ERR_HANDLE, err_msg);
640 return MEDIA_SVC_PLUGIN_ERROR;
643 ret = media_svc_check_storage(handle, storage_id, storage_name, storage_path, validity);
645 __set_error_message(ret, err_msg);
646 return MEDIA_SVC_PLUGIN_ERROR;
649 return MEDIA_SVC_PLUGIN_ERROR_NONE;
652 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)
654 int ret = MEDIA_SVC_PLUGIN_ERROR_NONE;
656 if (handle == NULL) {
657 __set_error_message(ERR_HANDLE, err_msg);
658 return MEDIA_SVC_PLUGIN_ERROR;
661 ret = media_svc_insert_storage(handle, storage_id, storage_name, storage_path, NULL, storage_type, uid);
663 __set_error_message(ret, err_msg);
664 return MEDIA_SVC_PLUGIN_ERROR;
667 return MEDIA_SVC_PLUGIN_ERROR_NONE;
670 int update_storage(void *handle, const char *storage_id, const char *storage_path, uid_t uid, char **err_msg)
672 int ret = MEDIA_SVC_PLUGIN_ERROR_NONE;
674 if (handle == NULL) {
675 __set_error_message(ERR_HANDLE, err_msg);
676 return MEDIA_SVC_PLUGIN_ERROR;
679 ret = media_svc_update_storage(handle, storage_id, storage_path, uid);
681 __set_error_message(ret, err_msg);
682 return MEDIA_SVC_PLUGIN_ERROR;
685 return MEDIA_SVC_PLUGIN_ERROR_NONE;
688 int delete_storage(void * handle, const char *storage_id, const char *storage_name, uid_t uid, char **err_msg)
690 int ret = MEDIA_SVC_PLUGIN_ERROR_NONE;
692 if (handle == NULL) {
693 __set_error_message(ERR_HANDLE, err_msg);
694 return MEDIA_SVC_PLUGIN_ERROR;
697 ret = media_svc_delete_storage(handle, storage_id, storage_name, uid);
699 __set_error_message(ret, err_msg);
700 return MEDIA_SVC_PLUGIN_ERROR;
703 return MEDIA_SVC_PLUGIN_ERROR_NONE;
706 int set_storage_validity(void * handle, const char *storage_id, int validity, uid_t uid, char **err_msg)
708 int ret = MEDIA_SVC_PLUGIN_ERROR_NONE;
710 if (handle == NULL) {
711 __set_error_message(ERR_HANDLE, err_msg);
712 return MEDIA_SVC_PLUGIN_ERROR;
715 ret = media_svc_set_storage_validity(handle, storage_id, validity, uid);
717 __set_error_message(ret, err_msg);
718 return MEDIA_SVC_PLUGIN_ERROR;
721 return MEDIA_SVC_PLUGIN_ERROR_NONE;
724 int set_all_storage_validity(void * handle, int validity, char **err_msg, uid_t uid)
726 int ret = MEDIA_SVC_PLUGIN_ERROR_NONE;
728 if (handle == NULL) {
729 __set_error_message(ERR_HANDLE, err_msg);
730 return MEDIA_SVC_PLUGIN_ERROR;
733 ret = media_svc_set_storage_validity(handle, NULL, validity, uid);
735 __set_error_message(ret, err_msg);
736 return MEDIA_SVC_PLUGIN_ERROR;
739 return MEDIA_SVC_PLUGIN_ERROR_NONE;
742 int get_storage_id(void * handle, const char *path, char *storage_id, char **err_msg)
744 int ret = MEDIA_SVC_PLUGIN_ERROR_NONE;
746 if (handle == NULL) {
747 __set_error_message(ERR_HANDLE, err_msg);
748 return MEDIA_SVC_PLUGIN_ERROR;
751 ret = media_svc_get_storage_id(handle, path, storage_id);
753 __set_error_message(ret, err_msg);
754 return MEDIA_SVC_PLUGIN_ERROR;
757 return MEDIA_SVC_PLUGIN_ERROR_NONE;
760 int get_storage_scan_status(void * handle, const char *storage_id, int *status, char **err_msg)
762 int ret = MEDIA_SVC_PLUGIN_ERROR_NONE;
763 media_svc_scan_status_type_e storage_status = 0;
765 if (handle == NULL) {
766 __set_error_message(ERR_HANDLE, err_msg);
767 return MEDIA_SVC_PLUGIN_ERROR;
770 ret = media_svc_get_storage_scan_status(handle, storage_id, &storage_status);
772 __set_error_message(ret, err_msg);
773 return MEDIA_SVC_PLUGIN_ERROR;
776 *status = storage_status;
778 return MEDIA_SVC_PLUGIN_ERROR_NONE;
781 int set_storage_scan_status(void *handle, const char *storage_id, int status, uid_t uid, char **err_msg)
783 int ret = MEDIA_SVC_PLUGIN_ERROR_NONE;
784 media_svc_scan_status_type_e storage_status = status;
786 ret = media_svc_set_storage_scan_status(storage_id, storage_status, uid);
788 __set_error_message(ret, err_msg);
789 return MEDIA_SVC_PLUGIN_ERROR;
792 return MEDIA_SVC_PLUGIN_ERROR_NONE;
795 int get_storage_list(void *handle, char ***storage_list, char ***storage_id_list, int **scan_status_list, int *count, char **err_msg)
797 int ret = MEDIA_SVC_PLUGIN_ERROR_NONE;
799 if (handle == NULL) {
800 __set_error_message(ERR_HANDLE, err_msg);
801 return MEDIA_SVC_PLUGIN_ERROR;
805 __set_error_message(ERR_HANDLE, err_msg);
806 return MEDIA_SVC_PLUGIN_ERROR;
809 ret = media_svc_get_storage_list(handle, storage_list, storage_id_list, scan_status_list, count);
811 __set_error_message(ret, err_msg);
812 return MEDIA_SVC_PLUGIN_ERROR;
815 return MEDIA_SVC_PLUGIN_ERROR_NONE;
818 int update_item_begin(void *handle, int item_cnt, char **err_msg)
820 int ret = MEDIA_SVC_PLUGIN_ERROR_NONE;
822 ret = media_svc_update_item_begin(item_cnt);
824 __set_error_message(ret, err_msg);
825 return MEDIA_SVC_PLUGIN_ERROR;
828 return MEDIA_SVC_PLUGIN_ERROR_NONE;
831 int update_item_end(void *handle, uid_t uid, char **err_msg)
833 int ret = MEDIA_SVC_PLUGIN_ERROR_NONE;
835 ret = media_svc_update_item_end(uid);
837 __set_error_message(ret, err_msg);
838 return MEDIA_SVC_PLUGIN_ERROR;
841 return MEDIA_SVC_PLUGIN_ERROR_NONE;
844 int update_item_meta(void *handle, const char *file_path, int storage_type, uid_t uid, char **err_msg)
846 int ret = MEDIA_SVC_PLUGIN_ERROR_NONE;
848 if (handle == NULL) {
849 __set_error_message(ERR_HANDLE, err_msg);
850 return MEDIA_SVC_PLUGIN_ERROR;
853 if (file_path == NULL) {
854 __set_error_message(ERR_HANDLE, err_msg);
855 return MEDIA_SVC_PLUGIN_ERROR;
858 ret = media_svc_update_item_meta(handle, file_path, storage_type, uid);
860 __set_error_message(ret, err_msg);
861 return MEDIA_SVC_PLUGIN_ERROR;
864 return MEDIA_SVC_PLUGIN_ERROR_NONE;
867 int insert_item_scan(void * handle, const char *storage_id, const char *file_path, int storage_type, uid_t uid, char **err_msg)
869 int ret = MEDIA_SVC_PLUGIN_ERROR_NONE;
871 if (handle == NULL) {
872 __set_error_message(ERR_HANDLE, err_msg);
873 return MEDIA_SVC_PLUGIN_ERROR;
876 if (!STRING_VALID(file_path)) {
877 __set_error_message(ERR_FILE_PATH, err_msg);
878 return MEDIA_SVC_PLUGIN_ERROR;
881 if (!STORAGE_VALID(storage_type)) {
882 __set_error_message(ERR_STORAGE_TYPE, err_msg);
883 return MEDIA_SVC_PLUGIN_ERROR;
886 ret = media_svc_insert_item_pass1(handle, storage_id, storage_type, file_path, FALSE, uid);
888 __set_error_message(ret, err_msg);
889 return MEDIA_SVC_PLUGIN_ERROR;
892 return MEDIA_SVC_PLUGIN_ERROR_NONE;
895 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)
897 int ret = MEDIA_SVC_PLUGIN_ERROR_NONE;
899 if (handle == NULL) {
900 __set_error_message(ERR_HANDLE, err_msg);
901 return MEDIA_SVC_PLUGIN_ERROR;
904 if (!STORAGE_VALID(storage_type)) {
905 __set_error_message(ERR_STORAGE_TYPE, err_msg);
906 return MEDIA_SVC_PLUGIN_ERROR;
909 ret = media_svc_insert_item_pass2(handle, storage_id, storage_type, scan_type, path, burst, uid);
911 __set_error_message(ret, err_msg);
912 return MEDIA_SVC_PLUGIN_ERROR;
915 return MEDIA_SVC_PLUGIN_ERROR_NONE;
918 int insert_folder_begin(void * handle, int item_cnt, char **err_msg)
920 int ret = MEDIA_SVC_PLUGIN_ERROR_NONE;
922 ret = media_svc_insert_folder_begin(item_cnt);
924 __set_error_message(ret, err_msg);
925 return MEDIA_SVC_PLUGIN_ERROR;
928 return MEDIA_SVC_PLUGIN_ERROR_NONE;
931 int insert_folder_end(void *handle, uid_t uid, char **err_msg)
933 int ret = MEDIA_SVC_PLUGIN_ERROR_NONE;
935 ret = media_svc_insert_folder_end(uid);
937 __set_error_message(ret, err_msg);
938 return MEDIA_SVC_PLUGIN_ERROR;
941 return MEDIA_SVC_PLUGIN_ERROR_NONE;
944 int insert_folder(void * handle, const char *storage_id, const char *file_path, int storage_type, uid_t uid, char **err_msg)
946 int ret = MEDIA_SVC_PLUGIN_ERROR_NONE;
948 if (handle == NULL) {
949 __set_error_message(ERR_HANDLE, err_msg);
950 return MEDIA_SVC_PLUGIN_ERROR;
953 if (!STRING_VALID(file_path)) {
954 __set_error_message(ERR_FILE_PATH, err_msg);
955 return MEDIA_SVC_PLUGIN_ERROR;
958 if (!STORAGE_VALID(storage_type)) {
959 __set_error_message(ERR_STORAGE_TYPE, err_msg);
960 return MEDIA_SVC_PLUGIN_ERROR;
963 ret = media_svc_insert_folder(handle, storage_id, storage_type, file_path, uid);
965 __set_error_message(ret, err_msg);
966 return MEDIA_SVC_PLUGIN_ERROR;
969 return MEDIA_SVC_PLUGIN_ERROR_NONE;
972 int delete_invalid_folder(void * handle, const char *storage_id, uid_t uid, char **err_msg)
974 int ret = MEDIA_SVC_PLUGIN_ERROR_NONE;
976 ret = media_svc_delete_invalid_folder(storage_id, uid);
978 __set_error_message(ret, err_msg);
979 return MEDIA_SVC_PLUGIN_ERROR;
982 return MEDIA_SVC_PLUGIN_ERROR_NONE;
985 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)
987 int ret = MEDIA_SVC_PLUGIN_ERROR_NONE;
989 if (handle == NULL) {
990 __set_error_message(ERR_HANDLE, err_msg);
991 return MEDIA_SVC_PLUGIN_ERROR;
994 ret = media_svc_set_folder_validity(handle, storage_id, start_path, validity, is_recursive, uid);
996 __set_error_message(ret, err_msg);
997 return MEDIA_SVC_PLUGIN_ERROR;
1000 return MEDIA_SVC_PLUGIN_ERROR_NONE;
1003 int get_folder_scan_status(void *handle, const char *storage_id, const char *path, int *status, char **err_msg)
1005 int ret = MEDIA_SVC_PLUGIN_ERROR_NONE;
1006 int storage_status = 0;
1008 if (handle == NULL) {
1009 __set_error_message(ERR_HANDLE, err_msg);
1010 return MEDIA_SVC_PLUGIN_ERROR;
1013 ret = media_svc_get_folder_scan_status(handle, storage_id, path, &storage_status);
1015 __set_error_message(ret, err_msg);
1016 return MEDIA_SVC_PLUGIN_ERROR;
1019 *status = storage_status;
1024 int set_folder_scan_status(void *handle, const char *storage_id, const char *path, int status, uid_t uid, char **err_msg)
1026 int ret = MEDIA_SVC_PLUGIN_ERROR_NONE;
1027 int storage_status = status;
1029 ret = media_svc_set_folder_scan_status(storage_id, path, storage_status, uid);
1031 __set_error_message(ret, err_msg);
1032 return MEDIA_SVC_PLUGIN_ERROR;
1038 int check_folder_modified(void *handle, const char *path, const char *storage_id, bool *modified, char **err_msg)
1040 int ret = MEDIA_SVC_PLUGIN_ERROR_NONE;
1043 if (handle == NULL) {
1044 __set_error_message(ERR_HANDLE, err_msg);
1045 return MEDIA_SVC_PLUGIN_ERROR;
1048 if (!STRING_VALID(path)) {
1049 __set_error_message(ERR_FILE_PATH, err_msg);
1050 return MEDIA_SVC_PLUGIN_ERROR;
1053 ret = media_svc_get_folder_modified_time(handle, path, storage_id, modified);
1055 __set_error_message(ret, err_msg);
1056 return MEDIA_SVC_PLUGIN_ERROR;
1062 int get_null_scan_folder_list(void *handle, const char *storage_id, const char *folder_path, char ***folder_list, int *count, char **err_msg)
1064 int ret = MEDIA_SVC_PLUGIN_ERROR_NONE;
1066 if (handle == NULL) {
1067 __set_error_message(ERR_HANDLE, err_msg);
1068 return MEDIA_SVC_PLUGIN_ERROR;
1071 if (count == NULL) {
1072 __set_error_message(ERR_HANDLE, err_msg);
1073 return MEDIA_SVC_PLUGIN_ERROR;
1076 ret = media_svc_get_null_scan_folder_list(handle, storage_id, folder_path, folder_list, count);
1078 __set_error_message(ret, err_msg);
1079 return MEDIA_SVC_PLUGIN_ERROR;
1085 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)
1087 int ret = MEDIA_SVC_PLUGIN_ERROR_NONE;
1089 ret = media_svc_change_validity_item_batch(storage_id, path, des_validity, src_validity, uid);
1091 __set_error_message(ret, err_msg);
1092 return MEDIA_SVC_PLUGIN_ERROR;
1098 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)
1100 int ret = MEDIA_SVC_PLUGIN_ERROR_NONE;
1102 if (handle == NULL) {
1103 __set_error_message(ERR_HANDLE, err_msg);
1104 return MEDIA_SVC_PLUGIN_ERROR;
1107 ret = media_svc_delete_invalid_folder_by_path(handle, storage_id, folder_path, uid, delete_count);
1109 __set_error_message(ret, err_msg);
1110 return MEDIA_SVC_PLUGIN_ERROR;
1113 return MEDIA_SVC_PLUGIN_ERROR_NONE;
1116 int check_folder_exist(void * handle, const char *storage_id, const char *folder_path, char **err_msg)
1118 int ret = MEDIA_SVC_PLUGIN_ERROR_NONE;
1120 if (handle == NULL) {
1121 __set_error_message(ERR_HANDLE, err_msg);
1122 return MEDIA_SVC_PLUGIN_ERROR;
1125 ret = media_svc_check_folder_exist_by_path(handle, storage_id, folder_path);
1127 __set_error_message(ret, err_msg);
1128 return MEDIA_SVC_PLUGIN_ERROR;
1131 return MEDIA_SVC_PLUGIN_ERROR_NONE;
1134 int count_subfolder(void *handle, const char *storage_id, const char *folder_path, int *count, char **err_msg)
1136 int ret = MEDIA_SVC_PLUGIN_ERROR_NONE;
1139 if (handle == NULL) {
1140 __set_error_message(ERR_HANDLE, err_msg);
1141 return MEDIA_SVC_PLUGIN_ERROR;
1144 ret = media_svc_check_subfolder_by_path(handle, storage_id, folder_path, &cnt);
1146 __set_error_message(ret, err_msg);
1147 return MEDIA_SVC_PLUGIN_ERROR;
1152 return MEDIA_SVC_PLUGIN_ERROR_NONE;
1155 int get_folder_id(void * handle, const char *storage_id, const char *path, char *folder_id, char **err_msg)
1157 int ret = MEDIA_SVC_PLUGIN_ERROR_NONE;
1159 if (handle == NULL) {
1160 __set_error_message(ERR_HANDLE, err_msg);
1161 return MEDIA_SVC_PLUGIN_ERROR;
1164 ret = media_svc_get_folder_id(handle, storage_id, path, folder_id);
1166 __set_error_message(ret, err_msg);
1167 return MEDIA_SVC_PLUGIN_ERROR;
1170 return MEDIA_SVC_PLUGIN_ERROR_NONE;