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 cleanup_db(void *handle, uid_t uid, char **err_msg)
125 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 ret = media_svc_cleanup_db(handle, uid);
134 __set_error_message(ret, err_msg);
135 return MEDIA_SVC_PLUGIN_ERROR;
138 return MEDIA_SVC_PLUGIN_ERROR_NONE;
141 int check_item_exist(void *handle, const char *storage_id, const char *file_path, bool *modified, char **err_msg)
143 int ret = MEDIA_SVC_PLUGIN_ERROR_NONE;
146 if (handle == NULL) {
147 __set_error_message(ERR_HANDLE, err_msg);
148 return MEDIA_SVC_PLUGIN_ERROR;
151 if (!STRING_VALID(file_path)) {
152 __set_error_message(ERR_FILE_PATH, err_msg);
153 return MEDIA_SVC_PLUGIN_ERROR;
156 time_t modified_time = 0;
157 unsigned long long file_size = 0;
160 ret = media_svc_get_file_info(handle, storage_id, file_path, &modified_time, &file_size);
161 if (ret == MS_MEDIA_ERR_NONE) {
162 memset(&st, 0, sizeof(struct stat));
163 if (stat(file_path, &st) == 0) {
164 if ((st.st_mtime != modified_time) || (st.st_size != file_size))
170 return MEDIA_SVC_PLUGIN_ERROR_NONE; /*exist */
173 __set_error_message(ERR_CHECK_ITEM, err_msg);
175 return MEDIA_SVC_PLUGIN_ERROR; /*not exist */
178 int insert_item_begin(void *handle, int item_cnt, int with_noti, int from_pid, char **err_msg)
180 int ret = MEDIA_SVC_PLUGIN_ERROR_NONE;
182 ret = media_svc_insert_item_begin(item_cnt, with_noti, from_pid);
184 __set_error_message(ret, err_msg);
185 return MEDIA_SVC_PLUGIN_ERROR;
188 return MEDIA_SVC_PLUGIN_ERROR_NONE;
191 int insert_item_end(void *handle, uid_t uid, char **err_msg)
193 int ret = MEDIA_SVC_PLUGIN_ERROR_NONE;
195 ret = media_svc_insert_item_end(uid);
197 __set_error_message(ret, err_msg);
198 return MEDIA_SVC_PLUGIN_ERROR;
201 return MEDIA_SVC_PLUGIN_ERROR_NONE;
204 int insert_item(void *handle, const char *storage_id, const char *file_path, int storage_type, uid_t uid, char **err_msg)
206 int ret = MEDIA_SVC_PLUGIN_ERROR_NONE;
208 if (handle == NULL) {
209 __set_error_message(ERR_HANDLE, err_msg);
210 return MEDIA_SVC_PLUGIN_ERROR;
213 if (!STRING_VALID(file_path)) {
214 __set_error_message(ERR_FILE_PATH, err_msg);
215 return MEDIA_SVC_PLUGIN_ERROR;
218 if (!STORAGE_VALID(storage_type)) {
219 __set_error_message(ERR_STORAGE_TYPE, err_msg);
220 return MEDIA_SVC_PLUGIN_ERROR;
223 ret = media_svc_insert_item_bulk(handle, storage_id, storage_type, file_path, FALSE, uid);
225 __set_error_message(ret, err_msg);
226 return MEDIA_SVC_PLUGIN_ERROR;
229 return MEDIA_SVC_PLUGIN_ERROR_NONE;
232 int insert_burst_item(void *handle, const char *storage_id, const char *file_path, int storage_type, uid_t uid, char **err_msg)
234 int ret = MEDIA_SVC_PLUGIN_ERROR_NONE;
236 if (handle == NULL) {
237 __set_error_message(ERR_HANDLE, err_msg);
238 return MEDIA_SVC_PLUGIN_ERROR;
241 if (!STRING_VALID(file_path)) {
242 __set_error_message(ERR_FILE_PATH, err_msg);
243 return MEDIA_SVC_PLUGIN_ERROR;
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_insert_item_bulk(handle, storage_id, storage_type, file_path, TRUE, uid);
253 __set_error_message(ret, err_msg);
254 return MEDIA_SVC_PLUGIN_ERROR;
257 return MEDIA_SVC_PLUGIN_ERROR_NONE;
260 int set_all_storage_items_validity(void *handle, const char *storage_id, int storage_type, int validity, uid_t uid, char **err_msg)
262 int ret = MEDIA_SVC_PLUGIN_ERROR_NONE;
264 if (!STORAGE_VALID(storage_type)) {
265 __set_error_message(ERR_STORAGE_TYPE, err_msg);
266 return MEDIA_SVC_PLUGIN_ERROR;
269 ret = media_svc_set_all_storage_items_validity(storage_id, storage_type, validity, uid);
271 __set_error_message(ret, err_msg);
272 return MEDIA_SVC_PLUGIN_ERROR;
275 return MEDIA_SVC_PLUGIN_ERROR_NONE;
278 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)
280 int ret = MEDIA_SVC_PLUGIN_ERROR_NONE;
282 if (handle == NULL) {
283 __set_error_message(ERR_HANDLE, err_msg);
284 return MEDIA_SVC_PLUGIN_ERROR;
287 if (!STRING_VALID(folder_path)) {
288 __set_error_message(ERR_FOLDER_PATH, err_msg);
289 return MEDIA_SVC_PLUGIN_ERROR;
292 ret = media_svc_set_folder_items_validity(handle, storage_id, folder_path, validity, recursive, uid);
294 __set_error_message(ret, err_msg);
295 return MEDIA_SVC_PLUGIN_ERROR;
298 return MEDIA_SVC_PLUGIN_ERROR_NONE;
301 int set_item_validity_begin(void *handle, int item_cnt, char **err_msg)
303 int ret = MEDIA_SVC_PLUGIN_ERROR_NONE;
305 ret = media_svc_set_item_validity_begin(item_cnt);
307 __set_error_message(ret, err_msg);
308 return MEDIA_SVC_PLUGIN_ERROR;
311 return MEDIA_SVC_PLUGIN_ERROR_NONE;
314 int set_item_validity_end(void *handle, uid_t uid, char **err_msg)
316 int ret = MEDIA_SVC_PLUGIN_ERROR_NONE;
318 ret = media_svc_set_item_validity_end(uid);
320 __set_error_message(ret, err_msg);
321 return MEDIA_SVC_PLUGIN_ERROR;
324 return MEDIA_SVC_PLUGIN_ERROR_NONE;
327 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)
329 int ret = MEDIA_SVC_PLUGIN_ERROR_NONE;
331 if (!STRING_VALID(file_path)) {
332 __set_error_message(ERR_FILE_PATH, err_msg);
333 return MEDIA_SVC_PLUGIN_ERROR;
336 ret = media_svc_set_item_validity(storage_id, file_path, validity, uid);
339 __set_error_message(ret, err_msg);
340 return MEDIA_SVC_PLUGIN_ERROR;
343 return MEDIA_SVC_PLUGIN_ERROR_NONE;
346 int delete_item(void *handle, const char *storage_id, const char *file_path, uid_t uid, char **err_msg)
348 int ret = MEDIA_SVC_PLUGIN_ERROR_NONE;
350 if (handle == NULL) {
351 __set_error_message(ERR_HANDLE, err_msg);
352 return MEDIA_SVC_PLUGIN_ERROR;
355 if (!STRING_VALID(file_path)) {
356 __set_error_message(ERR_FILE_PATH, err_msg);
357 return MEDIA_SVC_PLUGIN_ERROR;
360 ret = media_svc_check_item_exist_by_path(handle, storage_id, file_path);
362 ret = media_svc_delete_item_by_path(handle, storage_id, file_path, uid);
365 __set_error_message(ret, err_msg);
366 return MEDIA_SVC_PLUGIN_ERROR;
368 return MEDIA_SVC_PLUGIN_ERROR_NONE;
371 __set_error_message(ERR_CHECK_ITEM, err_msg); /*not exist in DB so can't delete item. */
372 return MEDIA_SVC_PLUGIN_ERROR;
375 int delete_all_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 (!STORAGE_VALID(storage_type)) {
380 __set_error_message(ERR_STORAGE_TYPE, err_msg);
381 return MEDIA_SVC_PLUGIN_ERROR;
384 ret = media_svc_delete_all_items_in_storage(storage_id, storage_type, uid);
386 __set_error_message(ret, err_msg);
387 return MEDIA_SVC_PLUGIN_ERROR;
390 return MEDIA_SVC_PLUGIN_ERROR_NONE;
393 int delete_all_invalid_items_in_storage(void *handle, const char *storage_id, int storage_type, uid_t uid, char **err_msg)
395 int ret = MEDIA_SVC_PLUGIN_ERROR_NONE;
397 if (handle == NULL) {
398 __set_error_message(ERR_HANDLE, err_msg);
399 return MEDIA_SVC_PLUGIN_ERROR;
402 if (!STORAGE_VALID(storage_type)) {
403 __set_error_message(ERR_STORAGE_TYPE, err_msg);
404 return MEDIA_SVC_PLUGIN_ERROR;
407 ret = media_svc_delete_invalid_items_in_storage(handle, storage_id, storage_type, uid);
409 __set_error_message(ret, err_msg);
410 return MEDIA_SVC_PLUGIN_ERROR;
413 return MEDIA_SVC_PLUGIN_ERROR_NONE;
416 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)
418 int ret = MEDIA_SVC_PLUGIN_ERROR_NONE;
420 if (!STRING_VALID(dir_path)) {
421 __set_error_message(ERR_FOLDER_PATH, err_msg);
422 return MEDIA_SVC_PLUGIN_ERROR;
425 ret = media_svc_send_dir_update_noti(handle, storage_id, dir_path, folder_id, (media_item_update_type_e)update_type, pid);
427 __set_error_message(ret, err_msg);
428 return MEDIA_SVC_PLUGIN_ERROR;
431 return MEDIA_SVC_PLUGIN_ERROR_NONE;
434 int check_db(void *handle, uid_t uid, char **err_msg)
436 int ret = MEDIA_SVC_PLUGIN_ERROR_NONE;
437 int user_version = -1;
439 ret = media_svc_get_user_version(handle, &user_version);
441 __set_error_message(ret, err_msg);
442 return MEDIA_SVC_PLUGIN_ERROR;
445 if (user_version == 0) {
447 ret = media_svc_create_table(uid);
449 __set_error_message(ret, err_msg);
450 return MEDIA_SVC_PLUGIN_ERROR;
454 ret = media_svc_check_db_upgrade(handle, user_version, uid);
456 __set_error_message(ret, err_msg);
457 return MEDIA_SVC_PLUGIN_ERROR;
461 return MEDIA_SVC_PLUGIN_ERROR_NONE;
464 int update_folder_time(void *handle, const char *storage_id, char *folder_path, uid_t uid, char **err_msg)
466 int ret = MEDIA_SVC_PLUGIN_ERROR_NONE;
468 if (handle == NULL) {
469 __set_error_message(ERR_HANDLE, err_msg);
470 return MEDIA_SVC_PLUGIN_ERROR;
473 if (folder_path == NULL) {
474 __set_error_message(ERR_HANDLE, err_msg);
475 return MEDIA_SVC_PLUGIN_ERROR;
478 ret = media_svc_update_folder_time(handle, storage_id, folder_path, uid);
480 __set_error_message(ret, err_msg);
481 return MEDIA_SVC_PLUGIN_ERROR;
484 return MEDIA_SVC_PLUGIN_ERROR_NONE;
487 int get_uuid(void * handle, char **uuid, char **err_msg)
489 int ret = MEDIA_SVC_PLUGIN_ERROR_NONE;
491 ret = media_svc_generate_uuid(uuid);
493 __set_error_message(ret, err_msg);
494 return MEDIA_SVC_PLUGIN_ERROR;
497 return MEDIA_SVC_PLUGIN_ERROR_NONE;
500 int get_mmc_info(void * handle, char **storage_name, char **storage_path, int *validity, bool *info_exist, char **err_msg)
502 int ret = MEDIA_SVC_PLUGIN_ERROR_NONE;
504 if (handle == NULL) {
505 __set_error_message(ERR_HANDLE, err_msg);
506 return MEDIA_SVC_PLUGIN_ERROR;
509 ret = media_svc_get_mmc_info(handle, storage_name, storage_path, validity, info_exist);
511 __set_error_message(MS_MEDIA_ERR_DB_NO_RECORD, err_msg);
512 return MEDIA_SVC_PLUGIN_ERROR;
515 return MEDIA_SVC_PLUGIN_ERROR_NONE;
518 int check_storage(void * handle, const char *storage_id, char **storage_path, int *validity, uid_t uid, char **err_msg)
520 int ret = MEDIA_SVC_PLUGIN_ERROR_NONE;
522 if (handle == NULL) {
523 __set_error_message(ERR_HANDLE, err_msg);
524 return MEDIA_SVC_PLUGIN_ERROR;
527 ret = media_svc_check_storage(handle, storage_id, storage_path, validity, uid);
529 __set_error_message(ret, err_msg);
530 return MEDIA_SVC_PLUGIN_ERROR;
533 return MEDIA_SVC_PLUGIN_ERROR_NONE;
536 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)
538 int ret = MEDIA_SVC_PLUGIN_ERROR_NONE;
540 if (handle == NULL) {
541 __set_error_message(ERR_HANDLE, err_msg);
542 return MEDIA_SVC_PLUGIN_ERROR;
545 ret = media_svc_insert_storage(handle, storage_id, storage_name, storage_path, storage_type, uid);
547 __set_error_message(ret, err_msg);
548 return MEDIA_SVC_PLUGIN_ERROR;
551 return MEDIA_SVC_PLUGIN_ERROR_NONE;
554 int update_storage(void *handle, const char *storage_id, const char *storage_path, uid_t uid, char **err_msg)
556 int ret = MEDIA_SVC_PLUGIN_ERROR_NONE;
558 if (handle == NULL) {
559 __set_error_message(ERR_HANDLE, err_msg);
560 return MEDIA_SVC_PLUGIN_ERROR;
563 ret = media_svc_update_storage(handle, storage_id, storage_path, uid);
565 __set_error_message(ret, err_msg);
566 return MEDIA_SVC_PLUGIN_ERROR;
569 return MEDIA_SVC_PLUGIN_ERROR_NONE;
572 int delete_storage(void * handle, const char *storage_id, uid_t uid, char **err_msg)
574 int ret = MEDIA_SVC_PLUGIN_ERROR_NONE;
576 if (handle == NULL) {
577 __set_error_message(ERR_HANDLE, err_msg);
578 return MEDIA_SVC_PLUGIN_ERROR;
581 ret = media_svc_delete_storage(handle, storage_id, uid);
583 __set_error_message(ret, err_msg);
584 return MEDIA_SVC_PLUGIN_ERROR;
587 return MEDIA_SVC_PLUGIN_ERROR_NONE;
590 int set_storage_validity(void * handle, const char *storage_id, int validity, uid_t uid, char **err_msg)
592 int ret = MEDIA_SVC_PLUGIN_ERROR_NONE;
594 if (handle == NULL) {
595 __set_error_message(ERR_HANDLE, err_msg);
596 return MEDIA_SVC_PLUGIN_ERROR;
599 ret = media_svc_set_storage_validity(handle, storage_id, validity, uid);
601 __set_error_message(ret, err_msg);
602 return MEDIA_SVC_PLUGIN_ERROR;
605 return MEDIA_SVC_PLUGIN_ERROR_NONE;
608 int set_all_storage_validity(void * handle, int validity, uid_t uid, char **err_msg)
610 int ret = MEDIA_SVC_PLUGIN_ERROR_NONE;
612 if (handle == NULL) {
613 __set_error_message(ERR_HANDLE, err_msg);
614 return MEDIA_SVC_PLUGIN_ERROR;
617 ret = media_svc_set_storage_validity(handle, NULL, validity, uid);
619 __set_error_message(ret, err_msg);
620 return MEDIA_SVC_PLUGIN_ERROR;
623 return MEDIA_SVC_PLUGIN_ERROR_NONE;
626 int get_storage_id(void * handle, const char *path, char *storage_id, uid_t uid, char **err_msg)
628 int ret = MEDIA_SVC_PLUGIN_ERROR_NONE;
630 if (handle == NULL) {
631 __set_error_message(ERR_HANDLE, err_msg);
632 return MEDIA_SVC_PLUGIN_ERROR;
635 ret = media_svc_get_storage_id(handle, path, storage_id, uid);
637 __set_error_message(ret, err_msg);
638 return MEDIA_SVC_PLUGIN_ERROR;
641 return MEDIA_SVC_PLUGIN_ERROR_NONE;
644 int set_storage_scan_status(void *handle, const char *storage_id, int status, uid_t uid, char **err_msg)
646 int ret = MEDIA_SVC_PLUGIN_ERROR_NONE;
647 media_svc_scan_status_type_e storage_status = status;
649 ret = media_svc_set_storage_scan_status(storage_id, storage_status, uid);
651 __set_error_message(ret, err_msg);
652 return MEDIA_SVC_PLUGIN_ERROR;
655 return MEDIA_SVC_PLUGIN_ERROR_NONE;
658 int get_storage_list(void *handle, char ***storage_list, char ***storage_id_list, int **scan_status_list, int *count, 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;
668 __set_error_message(ERR_HANDLE, err_msg);
669 return MEDIA_SVC_PLUGIN_ERROR;
672 ret = media_svc_get_storage_list(handle, storage_list, storage_id_list, scan_status_list, count);
674 __set_error_message(ret, err_msg);
675 return MEDIA_SVC_PLUGIN_ERROR;
678 return MEDIA_SVC_PLUGIN_ERROR_NONE;
681 int update_item_begin(void *handle, int item_cnt, char **err_msg)
683 int ret = MEDIA_SVC_PLUGIN_ERROR_NONE;
685 ret = media_svc_update_item_begin(item_cnt);
687 __set_error_message(ret, err_msg);
688 return MEDIA_SVC_PLUGIN_ERROR;
691 return MEDIA_SVC_PLUGIN_ERROR_NONE;
694 int update_item_end(void *handle, uid_t uid, char **err_msg)
696 int ret = MEDIA_SVC_PLUGIN_ERROR_NONE;
698 ret = media_svc_update_item_end(uid);
700 __set_error_message(ret, err_msg);
701 return MEDIA_SVC_PLUGIN_ERROR;
704 return MEDIA_SVC_PLUGIN_ERROR_NONE;
707 int update_item_meta(void *handle, const char *file_path, const char *storage_id, int storage_type, uid_t uid, char **err_msg)
709 int ret = MEDIA_SVC_PLUGIN_ERROR_NONE;
711 if (handle == NULL) {
712 __set_error_message(ERR_HANDLE, err_msg);
713 return MEDIA_SVC_PLUGIN_ERROR;
716 if (file_path == NULL) {
717 __set_error_message(ERR_HANDLE, err_msg);
718 return MEDIA_SVC_PLUGIN_ERROR;
721 if (storage_id == NULL) {
722 __set_error_message(ERR_HANDLE, err_msg);
723 return MEDIA_SVC_PLUGIN_ERROR;
726 ret = media_svc_update_item_meta(handle, file_path, storage_id, storage_type, uid);
728 __set_error_message(ret, err_msg);
729 return MEDIA_SVC_PLUGIN_ERROR;
732 return MEDIA_SVC_PLUGIN_ERROR_NONE;
735 int insert_item_scan(void * handle, const char *storage_id, const char *file_path, int storage_type, uid_t uid, char **err_msg)
737 int ret = MEDIA_SVC_PLUGIN_ERROR_NONE;
739 if (handle == NULL) {
740 __set_error_message(ERR_HANDLE, err_msg);
741 return MEDIA_SVC_PLUGIN_ERROR;
744 if (!STRING_VALID(file_path)) {
745 __set_error_message(ERR_FILE_PATH, err_msg);
746 return MEDIA_SVC_PLUGIN_ERROR;
749 if (!STORAGE_VALID(storage_type)) {
750 __set_error_message(ERR_STORAGE_TYPE, err_msg);
751 return MEDIA_SVC_PLUGIN_ERROR;
754 ret = media_svc_insert_item_pass1(handle, storage_id, storage_type, file_path, FALSE, uid);
756 __set_error_message(ret, err_msg);
757 return MEDIA_SVC_PLUGIN_ERROR;
760 return MEDIA_SVC_PLUGIN_ERROR_NONE;
763 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)
766 int ret = MEDIA_SVC_PLUGIN_ERROR_NONE;
768 if (handle == NULL) {
769 __set_error_message(ERR_HANDLE, err_msg);
770 return MEDIA_SVC_PLUGIN_ERROR;
773 if (!STORAGE_VALID(storage_type)) {
774 __set_error_message(ERR_STORAGE_TYPE, err_msg);
775 return MEDIA_SVC_PLUGIN_ERROR;
778 ret = media_svc_pass2_get_extract_list(handle, storage_id, storage_type, scan_type, path, burst, uid, array);
780 __set_error_message(ret, err_msg);
781 return MEDIA_SVC_PLUGIN_ERROR;
784 return MEDIA_SVC_PLUGIN_ERROR_NONE;
787 int update_one_extract_item(void* handle, const char* storage_id, int storage_type, void* data, int burst, char** err_msg)
790 int ret = MEDIA_SVC_PLUGIN_ERROR_NONE;
792 if (handle == NULL) {
793 __set_error_message(ERR_HANDLE, err_msg);
794 return MEDIA_SVC_PLUGIN_ERROR;
797 if (!STORAGE_VALID(storage_type)) {
798 __set_error_message(ERR_STORAGE_TYPE, err_msg);
799 return MEDIA_SVC_PLUGIN_ERROR;
802 ret = media_svc_insert_one_item_pass2(handle, storage_id, storage_type, data, burst);
804 __set_error_message(ret, err_msg);
805 return MEDIA_SVC_PLUGIN_ERROR;
808 return MEDIA_SVC_PLUGIN_ERROR_NONE;
811 int query_do_update_list(void* handle, char** err_msg)
814 int ret = MEDIA_SVC_PLUGIN_ERROR_NONE;
816 if (handle == NULL) {
817 __set_error_message(ERR_HANDLE, err_msg);
818 return MEDIA_SVC_PLUGIN_ERROR;
821 ret = media_svc_query_do_update_list(handle);
823 __set_error_message(ret, err_msg);
824 return MEDIA_SVC_PLUGIN_ERROR;
827 return MEDIA_SVC_PLUGIN_ERROR_NONE;
830 int insert_folder_begin(void * handle, int item_cnt, char **err_msg)
832 int ret = MEDIA_SVC_PLUGIN_ERROR_NONE;
834 ret = media_svc_insert_folder_begin(item_cnt);
836 __set_error_message(ret, err_msg);
837 return MEDIA_SVC_PLUGIN_ERROR;
840 return MEDIA_SVC_PLUGIN_ERROR_NONE;
843 int insert_folder_end(void *handle, uid_t uid, char **err_msg)
845 int ret = MEDIA_SVC_PLUGIN_ERROR_NONE;
847 ret = media_svc_insert_folder_end(uid);
849 __set_error_message(ret, err_msg);
850 return MEDIA_SVC_PLUGIN_ERROR;
853 return MEDIA_SVC_PLUGIN_ERROR_NONE;
856 int insert_folder(void * handle, const char *storage_id, const char *file_path, int storage_type, uid_t uid, char **err_msg)
858 int ret = MEDIA_SVC_PLUGIN_ERROR_NONE;
860 if (handle == NULL) {
861 __set_error_message(ERR_HANDLE, err_msg);
862 return MEDIA_SVC_PLUGIN_ERROR;
865 if (!STRING_VALID(file_path)) {
866 __set_error_message(ERR_FILE_PATH, err_msg);
867 return MEDIA_SVC_PLUGIN_ERROR;
870 if (!STORAGE_VALID(storage_type)) {
871 __set_error_message(ERR_STORAGE_TYPE, err_msg);
872 return MEDIA_SVC_PLUGIN_ERROR;
875 ret = media_svc_insert_folder(handle, storage_id, storage_type, file_path, uid);
877 __set_error_message(ret, err_msg);
878 return MEDIA_SVC_PLUGIN_ERROR;
881 return MEDIA_SVC_PLUGIN_ERROR_NONE;
884 int delete_invalid_folder(void * handle, const char *storage_id, int storage_type, uid_t uid, char **err_msg)
886 int ret = MEDIA_SVC_PLUGIN_ERROR_NONE;
888 ret = media_svc_delete_invalid_folder(storage_id, storage_type, uid);
890 __set_error_message(ret, err_msg);
891 return MEDIA_SVC_PLUGIN_ERROR;
894 return MEDIA_SVC_PLUGIN_ERROR_NONE;
897 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)
899 int ret = MEDIA_SVC_PLUGIN_ERROR_NONE;
901 if (handle == NULL) {
902 __set_error_message(ERR_HANDLE, err_msg);
903 return MEDIA_SVC_PLUGIN_ERROR;
906 ret = media_svc_set_folder_validity(handle, storage_id, start_path, validity, is_recursive, uid);
908 __set_error_message(ret, err_msg);
909 return MEDIA_SVC_PLUGIN_ERROR;
912 return MEDIA_SVC_PLUGIN_ERROR_NONE;
915 int get_folder_scan_status(void *handle, const char *storage_id, const char *path, int *status, char **err_msg)
917 int ret = MEDIA_SVC_PLUGIN_ERROR_NONE;
918 int storage_status = 0;
920 if (handle == NULL) {
921 __set_error_message(ERR_HANDLE, err_msg);
922 return MEDIA_SVC_PLUGIN_ERROR;
925 ret = media_svc_get_folder_scan_status(handle, storage_id, path, &storage_status);
927 __set_error_message(ret, err_msg);
928 return MEDIA_SVC_PLUGIN_ERROR;
931 *status = storage_status;
936 int set_folder_scan_status(void *handle, const char *storage_id, const char *path, int status, uid_t uid, char **err_msg)
938 int ret = MEDIA_SVC_PLUGIN_ERROR_NONE;
939 int storage_status = status;
941 ret = media_svc_set_folder_scan_status(storage_id, path, storage_status, uid);
943 __set_error_message(ret, err_msg);
944 return MEDIA_SVC_PLUGIN_ERROR;
950 int check_folder_modified(void *handle, const char *path, const char *storage_id, bool *modified, char **err_msg)
952 int ret = MEDIA_SVC_PLUGIN_ERROR_NONE;
955 if (handle == NULL) {
956 __set_error_message(ERR_HANDLE, err_msg);
957 return MEDIA_SVC_PLUGIN_ERROR;
960 if (!STRING_VALID(path)) {
961 __set_error_message(ERR_FILE_PATH, err_msg);
962 return MEDIA_SVC_PLUGIN_ERROR;
965 ret = media_svc_get_folder_modified_time(handle, path, storage_id, modified);
967 __set_error_message(ret, err_msg);
968 return MEDIA_SVC_PLUGIN_ERROR;
974 int get_null_scan_folder_list(void *handle, const char *storage_id, const char *folder_path, char ***folder_list, int *count, char **err_msg)
976 int ret = MEDIA_SVC_PLUGIN_ERROR_NONE;
978 if (handle == NULL) {
979 __set_error_message(ERR_HANDLE, err_msg);
980 return MEDIA_SVC_PLUGIN_ERROR;
984 __set_error_message(ERR_HANDLE, err_msg);
985 return MEDIA_SVC_PLUGIN_ERROR;
988 ret = media_svc_get_null_scan_folder_list(handle, storage_id, folder_path, folder_list, count);
990 __set_error_message(ret, err_msg);
991 return MEDIA_SVC_PLUGIN_ERROR;
997 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)
999 int ret = MEDIA_SVC_PLUGIN_ERROR_NONE;
1001 ret = media_svc_change_validity_item_batch(storage_id, path, des_validity, src_validity, uid);
1003 __set_error_message(ret, err_msg);
1004 return MEDIA_SVC_PLUGIN_ERROR;
1010 int check_folder_exist(void * handle, const char *storage_id, const char *folder_path, char **err_msg)
1012 int ret = MEDIA_SVC_PLUGIN_ERROR_NONE;
1014 if (handle == NULL) {
1015 __set_error_message(ERR_HANDLE, err_msg);
1016 return MEDIA_SVC_PLUGIN_ERROR;
1019 ret = media_svc_check_folder_exist_by_path(handle, storage_id, folder_path);
1021 __set_error_message(ret, err_msg);
1022 return MEDIA_SVC_PLUGIN_ERROR;
1025 return MEDIA_SVC_PLUGIN_ERROR_NONE;
1028 int get_folder_id(void * handle, const char *storage_id, const char *path, char *folder_id, char **err_msg)
1030 int ret = MEDIA_SVC_PLUGIN_ERROR_NONE;
1032 if (handle == NULL) {
1033 __set_error_message(ERR_HANDLE, err_msg);
1034 return MEDIA_SVC_PLUGIN_ERROR;
1037 ret = media_svc_get_folder_id(handle, storage_id, path, folder_id);
1039 __set_error_message(ret, err_msg);
1040 return MEDIA_SVC_PLUGIN_ERROR;
1043 return MEDIA_SVC_PLUGIN_ERROR_NONE;
1046 int get_media_type(void *handle, const char *path, int *mediatype, char **err_msg)
1048 int ret = MEDIA_SVC_PLUGIN_ERROR_NONE;
1050 if (handle == NULL) {
1051 __set_error_message(ERR_HANDLE, err_msg);
1052 return MEDIA_SVC_PLUGIN_ERROR;
1055 ret = media_svc_get_media_type(path, mediatype);
1057 __set_error_message(ret, err_msg);
1058 return MEDIA_SVC_PLUGIN_ERROR;
1061 return MEDIA_SVC_PLUGIN_ERROR_NONE;