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_burst_item(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_bulk(handle, storage_id, storage_type, file_path, TRUE, uid);
235 __set_error_message(ret, err_msg);
236 return MEDIA_SVC_PLUGIN_ERROR;
239 return MEDIA_SVC_PLUGIN_ERROR_NONE;
242 int set_all_storage_items_validity(void *handle, const char *storage_id, int storage_type, int validity, uid_t uid, char **err_msg)
244 int ret = MEDIA_SVC_PLUGIN_ERROR_NONE;
246 if (!STORAGE_VALID(storage_type)) {
247 __set_error_message(ERR_STORAGE_TYPE, err_msg);
248 return MEDIA_SVC_PLUGIN_ERROR;
251 ret = media_svc_set_all_storage_items_validity(storage_id, storage_type, validity, uid);
253 __set_error_message(ret, err_msg);
254 return MEDIA_SVC_PLUGIN_ERROR;
257 return MEDIA_SVC_PLUGIN_ERROR_NONE;
260 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)
262 int ret = MEDIA_SVC_PLUGIN_ERROR_NONE;
264 if (handle == NULL) {
265 __set_error_message(ERR_HANDLE, err_msg);
266 return MEDIA_SVC_PLUGIN_ERROR;
269 if (!STRING_VALID(folder_path)) {
270 __set_error_message(ERR_FOLDER_PATH, err_msg);
271 return MEDIA_SVC_PLUGIN_ERROR;
274 ret = media_svc_set_folder_items_validity(handle, storage_id, folder_path, validity, recursive, uid);
276 __set_error_message(ret, err_msg);
277 return MEDIA_SVC_PLUGIN_ERROR;
280 return MEDIA_SVC_PLUGIN_ERROR_NONE;
283 int set_item_validity_begin(void *handle, int item_cnt, char **err_msg)
285 int ret = MEDIA_SVC_PLUGIN_ERROR_NONE;
287 ret = media_svc_set_item_validity_begin(item_cnt);
289 __set_error_message(ret, err_msg);
290 return MEDIA_SVC_PLUGIN_ERROR;
293 return MEDIA_SVC_PLUGIN_ERROR_NONE;
296 int set_item_validity_end(void *handle, uid_t uid, char **err_msg)
298 int ret = MEDIA_SVC_PLUGIN_ERROR_NONE;
300 ret = media_svc_set_item_validity_end(uid);
302 __set_error_message(ret, err_msg);
303 return MEDIA_SVC_PLUGIN_ERROR;
306 return MEDIA_SVC_PLUGIN_ERROR_NONE;
309 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)
311 int ret = MEDIA_SVC_PLUGIN_ERROR_NONE;
313 if (!STRING_VALID(file_path)) {
314 __set_error_message(ERR_FILE_PATH, err_msg);
315 return MEDIA_SVC_PLUGIN_ERROR;
318 ret = media_svc_set_item_validity(storage_id, file_path, validity, uid);
321 __set_error_message(ret, err_msg);
322 return MEDIA_SVC_PLUGIN_ERROR;
325 return MEDIA_SVC_PLUGIN_ERROR_NONE;
328 int delete_item(void *handle, const char *storage_id, const char *file_path, uid_t uid, char **err_msg)
330 int ret = MEDIA_SVC_PLUGIN_ERROR_NONE;
332 if (handle == NULL) {
333 __set_error_message(ERR_HANDLE, err_msg);
334 return MEDIA_SVC_PLUGIN_ERROR;
337 if (!STRING_VALID(file_path)) {
338 __set_error_message(ERR_FILE_PATH, err_msg);
339 return MEDIA_SVC_PLUGIN_ERROR;
342 ret = media_svc_check_item_exist_by_path(handle, storage_id, file_path);
344 ret = media_svc_delete_item_by_path(handle, storage_id, file_path, uid);
347 __set_error_message(ret, err_msg);
348 return MEDIA_SVC_PLUGIN_ERROR;
350 return MEDIA_SVC_PLUGIN_ERROR_NONE;
353 __set_error_message(ERR_CHECK_ITEM, err_msg); /*not exist in DB so can't delete item. */
354 return MEDIA_SVC_PLUGIN_ERROR;
357 int delete_all_items_in_storage(void *handle, const char *storage_id, int storage_type, uid_t uid, char **err_msg)
359 int ret = MEDIA_SVC_PLUGIN_ERROR_NONE;
361 if (!STORAGE_VALID(storage_type)) {
362 __set_error_message(ERR_STORAGE_TYPE, err_msg);
363 return MEDIA_SVC_PLUGIN_ERROR;
366 ret = media_svc_delete_all_items_in_storage(storage_id, storage_type, uid);
368 __set_error_message(ret, err_msg);
369 return MEDIA_SVC_PLUGIN_ERROR;
372 return MEDIA_SVC_PLUGIN_ERROR_NONE;
375 int delete_all_invalid_items_in_storage(void *handle, const char *storage_id, int storage_type, uid_t uid, char **err_msg)
377 int ret = MEDIA_SVC_PLUGIN_ERROR_NONE;
379 if (handle == NULL) {
380 __set_error_message(ERR_HANDLE, err_msg);
381 return MEDIA_SVC_PLUGIN_ERROR;
384 if (!STORAGE_VALID(storage_type)) {
385 __set_error_message(ERR_STORAGE_TYPE, err_msg);
386 return MEDIA_SVC_PLUGIN_ERROR;
389 ret = media_svc_delete_invalid_items_in_storage(handle, storage_id, storage_type, uid);
391 __set_error_message(ret, err_msg);
392 return MEDIA_SVC_PLUGIN_ERROR;
395 return MEDIA_SVC_PLUGIN_ERROR_NONE;
398 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)
400 int ret = MEDIA_SVC_PLUGIN_ERROR_NONE;
402 if (handle == NULL) {
403 __set_error_message(ERR_HANDLE, err_msg);
404 return MEDIA_SVC_PLUGIN_ERROR;
407 if (!STRING_VALID(folder_path)) {
408 __set_error_message(ERR_FOLDER_PATH, err_msg);
409 return MEDIA_SVC_PLUGIN_ERROR;
412 ret = media_svc_delete_invalid_items_in_folder(handle, storage_id, folder_path, is_recursve, uid);
414 __set_error_message(ret, err_msg);
415 return MEDIA_SVC_PLUGIN_ERROR;
418 return MEDIA_SVC_PLUGIN_ERROR_NONE;
421 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)
423 int ret = MEDIA_SVC_PLUGIN_ERROR_NONE;
425 if (!STRING_VALID(dir_path)) {
426 __set_error_message(ERR_FOLDER_PATH, err_msg);
427 return MEDIA_SVC_PLUGIN_ERROR;
430 ret = media_svc_send_dir_update_noti(handle, storage_id, dir_path, folder_id, (media_item_update_type_e)update_type, pid);
432 __set_error_message(ret, err_msg);
433 return MEDIA_SVC_PLUGIN_ERROR;
436 return MEDIA_SVC_PLUGIN_ERROR_NONE;
439 int count_delete_items_in_folder(void *handle, const char *storage_id, const char *folder_path, int *count, char **err_msg)
441 int ret = MEDIA_SVC_PLUGIN_ERROR_NONE;
443 if (handle == NULL) {
444 __set_error_message(ERR_HANDLE, err_msg);
445 return MEDIA_SVC_PLUGIN_ERROR;
449 __set_error_message(ERR_HANDLE, err_msg);
450 return MEDIA_SVC_PLUGIN_ERROR;
453 if (!STRING_VALID(folder_path)) {
454 __set_error_message(ERR_FOLDER_PATH, err_msg);
455 return MEDIA_SVC_PLUGIN_ERROR;
458 ret = media_svc_count_invalid_items_in_folder(handle, storage_id, folder_path, count);
460 __set_error_message(ret, err_msg);
461 return MEDIA_SVC_PLUGIN_ERROR;
464 return MEDIA_SVC_PLUGIN_ERROR_NONE;
467 int check_db(void *handle, uid_t uid, char **err_msg)
469 int ret = MEDIA_SVC_PLUGIN_ERROR_NONE;
470 int user_version = -1;
472 ret = media_svc_get_user_version(handle, &user_version);
474 __set_error_message(ret, err_msg);
475 return MEDIA_SVC_PLUGIN_ERROR;
478 if (user_version == 0) {
480 ret = media_svc_create_table(uid);
482 __set_error_message(ret, err_msg);
483 return MEDIA_SVC_PLUGIN_ERROR;
487 ret = media_svc_check_db_upgrade(handle, user_version, uid);
489 __set_error_message(ret, err_msg);
490 return MEDIA_SVC_PLUGIN_ERROR;
494 return MEDIA_SVC_PLUGIN_ERROR_NONE;
497 int check_db_corrupt(void *handle, char **err_msg)
499 int ret = MEDIA_SVC_PLUGIN_ERROR_NONE;
502 ret = media_svc_check_db_corrupt(handle);
504 __set_error_message(ret, err_msg);
505 return MEDIA_SVC_PLUGIN_ERROR;
508 return MEDIA_SVC_PLUGIN_ERROR_NONE;
511 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)
513 int ret = MEDIA_SVC_PLUGIN_ERROR_NONE;
515 if (handle == NULL) {
516 __set_error_message(ERR_HANDLE, err_msg);
517 return MEDIA_SVC_PLUGIN_ERROR;
521 __set_error_message(ERR_HANDLE, err_msg);
522 return MEDIA_SVC_PLUGIN_ERROR;
525 ret = media_svc_get_folder_list(handle, start_path, folder_list, (time_t **)modified_time_list, item_num_list, count);
527 __set_error_message(ret, err_msg);
528 return MEDIA_SVC_PLUGIN_ERROR;
531 return MEDIA_SVC_PLUGIN_ERROR_NONE;
534 int update_folder_time(void *handle, const char *storage_id, char *folder_path, uid_t uid, char **err_msg)
536 int ret = MEDIA_SVC_PLUGIN_ERROR_NONE;
538 if (handle == NULL) {
539 __set_error_message(ERR_HANDLE, err_msg);
540 return MEDIA_SVC_PLUGIN_ERROR;
543 if (folder_path == NULL) {
544 __set_error_message(ERR_HANDLE, err_msg);
545 return MEDIA_SVC_PLUGIN_ERROR;
548 ret = media_svc_update_folder_time(handle, storage_id, folder_path, uid);
550 __set_error_message(ret, err_msg);
551 return MEDIA_SVC_PLUGIN_ERROR;
554 return MEDIA_SVC_PLUGIN_ERROR_NONE;
557 int get_uuid(void * handle, char **uuid, char **err_msg)
559 int ret = MEDIA_SVC_PLUGIN_ERROR_NONE;
561 ret = media_svc_generate_uuid(uuid);
563 __set_error_message(ret, err_msg);
564 return MEDIA_SVC_PLUGIN_ERROR;
567 return MEDIA_SVC_PLUGIN_ERROR_NONE;
570 int get_mmc_info(void * handle, char **storage_name, char **storage_path, int *validity, bool *info_exist, char **err_msg)
572 int ret = MEDIA_SVC_PLUGIN_ERROR_NONE;
574 if (handle == NULL) {
575 __set_error_message(ERR_HANDLE, err_msg);
576 return MEDIA_SVC_PLUGIN_ERROR;
579 ret = media_svc_get_mmc_info(handle, storage_name, storage_path, validity, info_exist);
581 __set_error_message(MS_MEDIA_ERR_DB_NO_RECORD, err_msg);
582 return MEDIA_SVC_PLUGIN_ERROR;
585 return MEDIA_SVC_PLUGIN_ERROR_NONE;
588 int check_storage(void * handle, const char *storage_id, const char *storage_name, char **storage_path, int *validity, uid_t uid, char **err_msg)
590 int ret = MEDIA_SVC_PLUGIN_ERROR_NONE;
592 if (handle == NULL) {
593 __set_error_message(ERR_HANDLE, err_msg);
594 return MEDIA_SVC_PLUGIN_ERROR;
597 ret = media_svc_check_storage(handle, storage_id, storage_name, storage_path, validity, uid);
599 __set_error_message(ret, err_msg);
600 return MEDIA_SVC_PLUGIN_ERROR;
603 return MEDIA_SVC_PLUGIN_ERROR_NONE;
606 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)
608 int ret = MEDIA_SVC_PLUGIN_ERROR_NONE;
610 if (handle == NULL) {
611 __set_error_message(ERR_HANDLE, err_msg);
612 return MEDIA_SVC_PLUGIN_ERROR;
615 ret = media_svc_insert_storage(handle, storage_id, storage_name, storage_path, storage_type, uid);
617 __set_error_message(ret, err_msg);
618 return MEDIA_SVC_PLUGIN_ERROR;
621 return MEDIA_SVC_PLUGIN_ERROR_NONE;
624 int update_storage(void *handle, const char *storage_id, const char *storage_path, uid_t uid, char **err_msg)
626 int ret = MEDIA_SVC_PLUGIN_ERROR_NONE;
628 if (handle == NULL) {
629 __set_error_message(ERR_HANDLE, err_msg);
630 return MEDIA_SVC_PLUGIN_ERROR;
633 ret = media_svc_update_storage(handle, storage_id, storage_path, uid);
635 __set_error_message(ret, err_msg);
636 return MEDIA_SVC_PLUGIN_ERROR;
639 return MEDIA_SVC_PLUGIN_ERROR_NONE;
642 int delete_storage(void * handle, const char *storage_id, const char *storage_name, uid_t uid, char **err_msg)
644 int ret = MEDIA_SVC_PLUGIN_ERROR_NONE;
646 if (handle == NULL) {
647 __set_error_message(ERR_HANDLE, err_msg);
648 return MEDIA_SVC_PLUGIN_ERROR;
651 ret = media_svc_delete_storage(handle, storage_id, storage_name, uid);
653 __set_error_message(ret, err_msg);
654 return MEDIA_SVC_PLUGIN_ERROR;
657 return MEDIA_SVC_PLUGIN_ERROR_NONE;
660 int set_storage_validity(void * handle, const char *storage_id, int validity, uid_t uid, char **err_msg)
662 int ret = MEDIA_SVC_PLUGIN_ERROR_NONE;
664 if (handle == NULL) {
665 __set_error_message(ERR_HANDLE, err_msg);
666 return MEDIA_SVC_PLUGIN_ERROR;
669 ret = media_svc_set_storage_validity(handle, storage_id, validity, uid);
671 __set_error_message(ret, err_msg);
672 return MEDIA_SVC_PLUGIN_ERROR;
675 return MEDIA_SVC_PLUGIN_ERROR_NONE;
678 int set_all_storage_validity(void * handle, int validity, uid_t uid, char **err_msg)
680 int ret = MEDIA_SVC_PLUGIN_ERROR_NONE;
682 if (handle == NULL) {
683 __set_error_message(ERR_HANDLE, err_msg);
684 return MEDIA_SVC_PLUGIN_ERROR;
687 ret = media_svc_set_storage_validity(handle, NULL, validity, uid);
689 __set_error_message(ret, err_msg);
690 return MEDIA_SVC_PLUGIN_ERROR;
693 return MEDIA_SVC_PLUGIN_ERROR_NONE;
696 int get_storage_id(void * handle, const char *path, char *storage_id, uid_t uid, char **err_msg)
698 int ret = MEDIA_SVC_PLUGIN_ERROR_NONE;
700 if (handle == NULL) {
701 __set_error_message(ERR_HANDLE, err_msg);
702 return MEDIA_SVC_PLUGIN_ERROR;
705 ret = media_svc_get_storage_id(handle, path, storage_id, uid);
707 __set_error_message(ret, err_msg);
708 return MEDIA_SVC_PLUGIN_ERROR;
711 return MEDIA_SVC_PLUGIN_ERROR_NONE;
714 int set_storage_scan_status(void *handle, const char *storage_id, int status, uid_t uid, char **err_msg)
716 int ret = MEDIA_SVC_PLUGIN_ERROR_NONE;
717 media_svc_scan_status_type_e storage_status = status;
719 ret = media_svc_set_storage_scan_status(storage_id, storage_status, uid);
721 __set_error_message(ret, err_msg);
722 return MEDIA_SVC_PLUGIN_ERROR;
725 return MEDIA_SVC_PLUGIN_ERROR_NONE;
728 int get_storage_list(void *handle, char ***storage_list, char ***storage_id_list, int **scan_status_list, int *count, 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;
738 __set_error_message(ERR_HANDLE, err_msg);
739 return MEDIA_SVC_PLUGIN_ERROR;
742 ret = media_svc_get_storage_list(handle, storage_list, storage_id_list, scan_status_list, count);
744 __set_error_message(ret, err_msg);
745 return MEDIA_SVC_PLUGIN_ERROR;
748 return MEDIA_SVC_PLUGIN_ERROR_NONE;
751 int update_item_begin(void *handle, int item_cnt, char **err_msg)
753 int ret = MEDIA_SVC_PLUGIN_ERROR_NONE;
755 ret = media_svc_update_item_begin(item_cnt);
757 __set_error_message(ret, err_msg);
758 return MEDIA_SVC_PLUGIN_ERROR;
761 return MEDIA_SVC_PLUGIN_ERROR_NONE;
764 int update_item_end(void *handle, uid_t uid, char **err_msg)
766 int ret = MEDIA_SVC_PLUGIN_ERROR_NONE;
768 ret = media_svc_update_item_end(uid);
770 __set_error_message(ret, err_msg);
771 return MEDIA_SVC_PLUGIN_ERROR;
774 return MEDIA_SVC_PLUGIN_ERROR_NONE;
777 int update_item_meta(void *handle, const char *file_path, const char *storage_id, int storage_type, uid_t uid, char **err_msg)
779 int ret = MEDIA_SVC_PLUGIN_ERROR_NONE;
781 if (handle == NULL) {
782 __set_error_message(ERR_HANDLE, err_msg);
783 return MEDIA_SVC_PLUGIN_ERROR;
786 if (file_path == NULL) {
787 __set_error_message(ERR_HANDLE, err_msg);
788 return MEDIA_SVC_PLUGIN_ERROR;
791 if (storage_id == NULL) {
792 __set_error_message(ERR_HANDLE, err_msg);
793 return MEDIA_SVC_PLUGIN_ERROR;
796 ret = media_svc_update_item_meta(handle, file_path, storage_id, storage_type, uid);
798 __set_error_message(ret, err_msg);
799 return MEDIA_SVC_PLUGIN_ERROR;
802 return MEDIA_SVC_PLUGIN_ERROR_NONE;
805 int insert_item_scan(void * handle, const char *storage_id, const char *file_path, int storage_type, uid_t uid, char **err_msg)
807 int ret = MEDIA_SVC_PLUGIN_ERROR_NONE;
809 if (handle == NULL) {
810 __set_error_message(ERR_HANDLE, err_msg);
811 return MEDIA_SVC_PLUGIN_ERROR;
814 if (!STRING_VALID(file_path)) {
815 __set_error_message(ERR_FILE_PATH, err_msg);
816 return MEDIA_SVC_PLUGIN_ERROR;
819 if (!STORAGE_VALID(storage_type)) {
820 __set_error_message(ERR_STORAGE_TYPE, err_msg);
821 return MEDIA_SVC_PLUGIN_ERROR;
824 ret = media_svc_insert_item_pass1(handle, storage_id, storage_type, file_path, FALSE, uid);
826 __set_error_message(ret, err_msg);
827 return MEDIA_SVC_PLUGIN_ERROR;
830 return MEDIA_SVC_PLUGIN_ERROR_NONE;
833 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)
836 int ret = MEDIA_SVC_PLUGIN_ERROR_NONE;
838 if (handle == NULL) {
839 __set_error_message(ERR_HANDLE, err_msg);
840 return MEDIA_SVC_PLUGIN_ERROR;
843 if (!STORAGE_VALID(storage_type)) {
844 __set_error_message(ERR_STORAGE_TYPE, err_msg);
845 return MEDIA_SVC_PLUGIN_ERROR;
848 ret = media_svc_pass2_get_extract_list(handle, storage_id, storage_type, scan_type, path, burst, uid, array);
850 __set_error_message(ret, err_msg);
851 return MEDIA_SVC_PLUGIN_ERROR;
854 return MEDIA_SVC_PLUGIN_ERROR_NONE;
857 int update_one_extract_item(void* handle, const char* storage_id, int storage_type, void* data, int burst, char** err_msg)
860 int ret = MEDIA_SVC_PLUGIN_ERROR_NONE;
862 if (handle == NULL) {
863 __set_error_message(ERR_HANDLE, err_msg);
864 return MEDIA_SVC_PLUGIN_ERROR;
867 if (!STORAGE_VALID(storage_type)) {
868 __set_error_message(ERR_STORAGE_TYPE, err_msg);
869 return MEDIA_SVC_PLUGIN_ERROR;
872 ret = media_svc_insert_one_item_pass2(handle, storage_id, storage_type, data, burst);
874 __set_error_message(ret, err_msg);
875 return MEDIA_SVC_PLUGIN_ERROR;
878 return MEDIA_SVC_PLUGIN_ERROR_NONE;
881 int query_do_update_list(void* handle, char** err_msg)
884 int ret = MEDIA_SVC_PLUGIN_ERROR_NONE;
886 if (handle == NULL) {
887 __set_error_message(ERR_HANDLE, err_msg);
888 return MEDIA_SVC_PLUGIN_ERROR;
891 ret = media_svc_query_do_update_list(handle);
893 __set_error_message(ret, err_msg);
894 return MEDIA_SVC_PLUGIN_ERROR;
897 return MEDIA_SVC_PLUGIN_ERROR_NONE;
900 int insert_folder_begin(void * handle, int item_cnt, char **err_msg)
902 int ret = MEDIA_SVC_PLUGIN_ERROR_NONE;
904 ret = media_svc_insert_folder_begin(item_cnt);
906 __set_error_message(ret, err_msg);
907 return MEDIA_SVC_PLUGIN_ERROR;
910 return MEDIA_SVC_PLUGIN_ERROR_NONE;
913 int insert_folder_end(void *handle, uid_t uid, char **err_msg)
915 int ret = MEDIA_SVC_PLUGIN_ERROR_NONE;
917 ret = media_svc_insert_folder_end(uid);
919 __set_error_message(ret, err_msg);
920 return MEDIA_SVC_PLUGIN_ERROR;
923 return MEDIA_SVC_PLUGIN_ERROR_NONE;
926 int insert_folder(void * handle, const char *storage_id, const char *file_path, int storage_type, uid_t uid, char **err_msg)
928 int ret = MEDIA_SVC_PLUGIN_ERROR_NONE;
930 if (handle == NULL) {
931 __set_error_message(ERR_HANDLE, err_msg);
932 return MEDIA_SVC_PLUGIN_ERROR;
935 if (!STRING_VALID(file_path)) {
936 __set_error_message(ERR_FILE_PATH, err_msg);
937 return MEDIA_SVC_PLUGIN_ERROR;
940 if (!STORAGE_VALID(storage_type)) {
941 __set_error_message(ERR_STORAGE_TYPE, err_msg);
942 return MEDIA_SVC_PLUGIN_ERROR;
945 ret = media_svc_insert_folder(handle, storage_id, storage_type, file_path, uid);
947 __set_error_message(ret, err_msg);
948 return MEDIA_SVC_PLUGIN_ERROR;
951 return MEDIA_SVC_PLUGIN_ERROR_NONE;
954 int delete_invalid_folder(void * handle, const char *storage_id, int storage_type, uid_t uid, char **err_msg)
956 int ret = MEDIA_SVC_PLUGIN_ERROR_NONE;
958 ret = media_svc_delete_invalid_folder(storage_id, storage_type, uid);
960 __set_error_message(ret, err_msg);
961 return MEDIA_SVC_PLUGIN_ERROR;
964 return MEDIA_SVC_PLUGIN_ERROR_NONE;
967 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)
969 int ret = MEDIA_SVC_PLUGIN_ERROR_NONE;
971 if (handle == NULL) {
972 __set_error_message(ERR_HANDLE, err_msg);
973 return MEDIA_SVC_PLUGIN_ERROR;
976 ret = media_svc_set_folder_validity(handle, storage_id, start_path, validity, is_recursive, uid);
978 __set_error_message(ret, err_msg);
979 return MEDIA_SVC_PLUGIN_ERROR;
982 return MEDIA_SVC_PLUGIN_ERROR_NONE;
985 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)
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_delete_invalid_folder_by_path(handle, storage_id, folder_path, uid, delete_count);
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 check_folder_exist(void * handle, const char *storage_id, const char *folder_path, 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_check_folder_exist_by_path(handle, storage_id, folder_path);
1109 __set_error_message(ret, err_msg);
1110 return MEDIA_SVC_PLUGIN_ERROR;
1113 return MEDIA_SVC_PLUGIN_ERROR_NONE;
1116 int count_subfolder(void *handle, const char *storage_id, const char *folder_path, int *count, char **err_msg)
1118 int ret = MEDIA_SVC_PLUGIN_ERROR_NONE;
1121 if (handle == NULL) {
1122 __set_error_message(ERR_HANDLE, err_msg);
1123 return MEDIA_SVC_PLUGIN_ERROR;
1126 ret = media_svc_check_subfolder_by_path(handle, storage_id, folder_path, &cnt);
1128 __set_error_message(ret, err_msg);
1129 return MEDIA_SVC_PLUGIN_ERROR;
1134 return MEDIA_SVC_PLUGIN_ERROR_NONE;
1137 int get_folder_id(void * handle, const char *storage_id, const char *path, char *folder_id, char **err_msg)
1139 int ret = MEDIA_SVC_PLUGIN_ERROR_NONE;
1141 if (handle == NULL) {
1142 __set_error_message(ERR_HANDLE, err_msg);
1143 return MEDIA_SVC_PLUGIN_ERROR;
1146 ret = media_svc_get_folder_id(handle, storage_id, path, folder_id);
1148 __set_error_message(ret, err_msg);
1149 return MEDIA_SVC_PLUGIN_ERROR;
1152 return MEDIA_SVC_PLUGIN_ERROR_NONE;
1155 int get_media_type(void *handle, const char *path, int *mediatype, 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_media_type(path, mediatype);
1166 __set_error_message(ret, err_msg);
1167 return MEDIA_SVC_PLUGIN_ERROR;
1170 return MEDIA_SVC_PLUGIN_ERROR_NONE;