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 if (handle == NULL) {
164 __set_error_message(ERR_HANDLE, err_msg);
165 return MEDIA_SVC_PLUGIN_ERROR;
168 ret = media_svc_insert_item_begin(handle, item_cnt, with_noti, from_pid);
170 __set_error_message(ret, err_msg);
171 return MEDIA_SVC_PLUGIN_ERROR;
174 return MEDIA_SVC_PLUGIN_ERROR_NONE;
177 int insert_item_end(void *handle, uid_t uid, char **err_msg)
179 int ret = MEDIA_SVC_PLUGIN_ERROR_NONE;
181 if (handle == NULL) {
182 __set_error_message(ERR_HANDLE, err_msg);
183 return MEDIA_SVC_PLUGIN_ERROR;
186 ret = media_svc_insert_item_end(handle, uid);
188 __set_error_message(ret, err_msg);
189 return MEDIA_SVC_PLUGIN_ERROR;
192 return MEDIA_SVC_PLUGIN_ERROR_NONE;
195 int insert_item(void *handle, const char *storage_id, const char *file_path, int storage_type, uid_t uid, char **err_msg)
197 int ret = MEDIA_SVC_PLUGIN_ERROR_NONE;
199 if (handle == NULL) {
200 __set_error_message(ERR_HANDLE, err_msg);
201 return MEDIA_SVC_PLUGIN_ERROR;
204 if (!STRING_VALID(file_path)) {
205 __set_error_message(ERR_FILE_PATH, err_msg);
206 return MEDIA_SVC_PLUGIN_ERROR;
209 if (!STORAGE_VALID(storage_type)) {
210 __set_error_message(ERR_STORAGE_TYPE, err_msg);
211 return MEDIA_SVC_PLUGIN_ERROR;
214 ret = media_svc_insert_item_bulk(handle, storage_id, storage_type, file_path, FALSE, uid);
216 __set_error_message(ret, err_msg);
217 return MEDIA_SVC_PLUGIN_ERROR;
220 return MEDIA_SVC_PLUGIN_ERROR_NONE;
223 int insert_item_immediately(void *handle, const char *storage_id, const char *file_path, int storage_type, uid_t uid, char **err_msg)
225 int ret = MEDIA_SVC_PLUGIN_ERROR_NONE;
227 if (handle == NULL) {
228 __set_error_message(ERR_HANDLE, err_msg);
229 return MEDIA_SVC_PLUGIN_ERROR;
232 if (!STRING_VALID(file_path)) {
233 __set_error_message(ERR_FILE_PATH, err_msg);
234 return MEDIA_SVC_PLUGIN_ERROR;
237 if (!STORAGE_VALID(storage_type)) {
238 __set_error_message(ERR_STORAGE_TYPE, err_msg);
239 return MEDIA_SVC_PLUGIN_ERROR;
242 ret = media_svc_insert_item_immediately(handle, storage_id, storage_type, file_path, uid);
244 __set_error_message(ret, err_msg);
245 return MEDIA_SVC_PLUGIN_ERROR;
248 return MEDIA_SVC_PLUGIN_ERROR_NONE;
251 int insert_burst_item(void *handle, const char *storage_id, const char *file_path, int storage_type, uid_t uid, char **err_msg)
253 int ret = MEDIA_SVC_PLUGIN_ERROR_NONE;
255 if (handle == NULL) {
256 __set_error_message(ERR_HANDLE, err_msg);
257 return MEDIA_SVC_PLUGIN_ERROR;
260 if (!STRING_VALID(file_path)) {
261 __set_error_message(ERR_FILE_PATH, err_msg);
262 return MEDIA_SVC_PLUGIN_ERROR;
265 if (!STORAGE_VALID(storage_type)) {
266 __set_error_message(ERR_STORAGE_TYPE, err_msg);
267 return MEDIA_SVC_PLUGIN_ERROR;
270 ret = media_svc_insert_item_bulk(handle, storage_id, storage_type, file_path, TRUE, uid);
272 __set_error_message(ret, err_msg);
273 return MEDIA_SVC_PLUGIN_ERROR;
276 return MEDIA_SVC_PLUGIN_ERROR_NONE;
279 int set_all_storage_items_validity(void *handle, const char *storage_id, int storage_type, int validity, uid_t uid, char **err_msg)
281 int ret = MEDIA_SVC_PLUGIN_ERROR_NONE;
283 if (handle == NULL) {
284 __set_error_message(ERR_HANDLE, err_msg);
285 return MEDIA_SVC_PLUGIN_ERROR;
288 if (!STORAGE_VALID(storage_type)) {
289 __set_error_message(ERR_STORAGE_TYPE, err_msg);
290 return MEDIA_SVC_PLUGIN_ERROR;
293 ret = media_svc_set_all_storage_items_validity(handle, storage_id, storage_type, validity, uid);
295 __set_error_message(ret, err_msg);
296 return MEDIA_SVC_PLUGIN_ERROR;
299 return MEDIA_SVC_PLUGIN_ERROR_NONE;
302 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)
304 int ret = MEDIA_SVC_PLUGIN_ERROR_NONE;
306 if (handle == NULL) {
307 __set_error_message(ERR_HANDLE, err_msg);
308 return MEDIA_SVC_PLUGIN_ERROR;
311 if (!STRING_VALID(folder_path)) {
312 __set_error_message(ERR_FOLDER_PATH, err_msg);
313 return MEDIA_SVC_PLUGIN_ERROR;
316 ret = media_svc_set_folder_items_validity(handle, storage_id, folder_path, validity, recursive, uid);
318 __set_error_message(ret, err_msg);
319 return MEDIA_SVC_PLUGIN_ERROR;
322 return MEDIA_SVC_PLUGIN_ERROR_NONE;
325 int set_item_validity_begin(void *handle, int item_cnt, char **err_msg)
327 int ret = MEDIA_SVC_PLUGIN_ERROR_NONE;
329 if (handle == NULL) {
330 __set_error_message(ERR_HANDLE, err_msg);
331 return MEDIA_SVC_PLUGIN_ERROR;
334 ret = media_svc_set_item_validity_begin(handle, item_cnt);
336 __set_error_message(ret, err_msg);
337 return MEDIA_SVC_PLUGIN_ERROR;
340 return MEDIA_SVC_PLUGIN_ERROR_NONE;
343 int set_item_validity_end(void *handle, uid_t uid, char **err_msg)
345 int ret = MEDIA_SVC_PLUGIN_ERROR_NONE;
347 if (handle == NULL) {
348 __set_error_message(ERR_HANDLE, err_msg);
349 return MEDIA_SVC_PLUGIN_ERROR;
352 ret = media_svc_set_item_validity_end(handle, uid);
354 __set_error_message(ret, err_msg);
355 return MEDIA_SVC_PLUGIN_ERROR;
358 return MEDIA_SVC_PLUGIN_ERROR_NONE;
361 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)
363 int ret = MEDIA_SVC_PLUGIN_ERROR_NONE;
365 if (handle == NULL) {
366 __set_error_message(ERR_HANDLE, err_msg);
367 return MEDIA_SVC_PLUGIN_ERROR;
370 if (!STRING_VALID(file_path)) {
371 __set_error_message(ERR_FILE_PATH, err_msg);
372 return MEDIA_SVC_PLUGIN_ERROR;
375 ret = media_svc_set_item_validity(handle, storage_id, file_path, validity, uid);
378 __set_error_message(ret, err_msg);
379 return MEDIA_SVC_PLUGIN_ERROR;
382 return MEDIA_SVC_PLUGIN_ERROR_NONE;
385 int delete_item(void *handle, const char *storage_id, const char *file_path, uid_t uid, char **err_msg)
387 int ret = MEDIA_SVC_PLUGIN_ERROR_NONE;
389 if (handle == NULL) {
390 __set_error_message(ERR_HANDLE, err_msg);
391 return MEDIA_SVC_PLUGIN_ERROR;
394 if (!STRING_VALID(file_path)) {
395 __set_error_message(ERR_FILE_PATH, err_msg);
396 return MEDIA_SVC_PLUGIN_ERROR;
399 ret = media_svc_check_item_exist_by_path(handle, storage_id, file_path);
401 ret = media_svc_delete_item_by_path(handle, storage_id, file_path, uid);
404 __set_error_message(ret, err_msg);
405 return MEDIA_SVC_PLUGIN_ERROR;
407 return MEDIA_SVC_PLUGIN_ERROR_NONE;
410 __set_error_message(ERR_CHECK_ITEM, err_msg); /*not exist in DB so can't delete item. */
411 return MEDIA_SVC_PLUGIN_ERROR;
414 int delete_all_items_in_storage(void *handle, const char *storage_id, int storage_type, uid_t uid, char **err_msg)
416 int ret = MEDIA_SVC_PLUGIN_ERROR_NONE;
418 if (handle == NULL) {
419 __set_error_message(ERR_HANDLE, err_msg);
420 return MEDIA_SVC_PLUGIN_ERROR;
423 if (!STORAGE_VALID(storage_type)) {
424 __set_error_message(ERR_STORAGE_TYPE, err_msg);
425 return MEDIA_SVC_PLUGIN_ERROR;
428 ret = media_svc_delete_all_items_in_storage(handle, storage_id, storage_type, uid);
430 __set_error_message(ret, err_msg);
431 return MEDIA_SVC_PLUGIN_ERROR;
434 return MEDIA_SVC_PLUGIN_ERROR_NONE;
437 int delete_all_invalid_items_in_storage(void *handle, const char *storage_id, int storage_type, uid_t uid, char **err_msg)
439 int ret = MEDIA_SVC_PLUGIN_ERROR_NONE;
441 if (handle == NULL) {
442 __set_error_message(ERR_HANDLE, err_msg);
443 return MEDIA_SVC_PLUGIN_ERROR;
446 if (!STORAGE_VALID(storage_type)) {
447 __set_error_message(ERR_STORAGE_TYPE, err_msg);
448 return MEDIA_SVC_PLUGIN_ERROR;
451 ret = media_svc_delete_invalid_items_in_storage(handle, storage_id, storage_type, uid);
453 __set_error_message(ret, err_msg);
454 return MEDIA_SVC_PLUGIN_ERROR;
457 return MEDIA_SVC_PLUGIN_ERROR_NONE;
460 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)
462 int ret = MEDIA_SVC_PLUGIN_ERROR_NONE;
464 if (handle == NULL) {
465 __set_error_message(ERR_HANDLE, err_msg);
466 return MEDIA_SVC_PLUGIN_ERROR;
469 if (!STRING_VALID(folder_path)) {
470 __set_error_message(ERR_FOLDER_PATH, err_msg);
471 return MEDIA_SVC_PLUGIN_ERROR;
474 ret = media_svc_delete_invalid_items_in_folder(handle, storage_id, folder_path, is_recursve, uid);
476 __set_error_message(ret, err_msg);
477 return MEDIA_SVC_PLUGIN_ERROR;
480 return MEDIA_SVC_PLUGIN_ERROR_NONE;
484 int update_begin(void)
486 return MEDIA_SVC_PLUGIN_ERROR_NONE;
489 int update_end(const char *start_path, uid_t uid)
491 int ret = MEDIA_SVC_PLUGIN_ERROR_NONE;
493 ret = thumbnail_request_extract_all_thumbs(uid);
495 return MEDIA_SVC_PLUGIN_ERROR;
498 return MEDIA_SVC_PLUGIN_ERROR_NONE;
501 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)
503 int ret = MEDIA_SVC_PLUGIN_ERROR_NONE;
505 if (!STRING_VALID(dir_path)) {
506 __set_error_message(ERR_FOLDER_PATH, err_msg);
507 return MEDIA_SVC_PLUGIN_ERROR;
510 ret = media_svc_send_dir_update_noti(handle, storage_id, dir_path, folder_id, (media_item_update_type_e)update_type, pid);
512 __set_error_message(ret, err_msg);
513 return MEDIA_SVC_PLUGIN_ERROR;
516 return MEDIA_SVC_PLUGIN_ERROR_NONE;
519 int count_delete_items_in_folder(void *handle, const char *storage_id, const char *folder_path, int *count, char **err_msg)
521 int ret = MEDIA_SVC_PLUGIN_ERROR_NONE;
523 if (handle == NULL) {
524 __set_error_message(ERR_HANDLE, err_msg);
525 return MEDIA_SVC_PLUGIN_ERROR;
529 __set_error_message(ERR_HANDLE, err_msg);
530 return MEDIA_SVC_PLUGIN_ERROR;
533 if (!STRING_VALID(folder_path)) {
534 __set_error_message(ERR_FOLDER_PATH, err_msg);
535 return MEDIA_SVC_PLUGIN_ERROR;
538 ret = media_svc_count_invalid_items_in_folder(handle, storage_id, folder_path, count);
540 __set_error_message(ret, err_msg);
541 return MEDIA_SVC_PLUGIN_ERROR;
544 return MEDIA_SVC_PLUGIN_ERROR_NONE;
547 int check_db(void *handle, bool *need_full_scan, uid_t uid, char **err_msg)
549 int ret = MEDIA_SVC_PLUGIN_ERROR_NONE;
552 ret = media_svc_create_table(handle, uid);
554 __set_error_message(ret, err_msg);
555 return MEDIA_SVC_PLUGIN_ERROR;
559 ret = media_svc_check_db_upgrade(handle, need_full_scan, uid);
561 __set_error_message(ret, err_msg);
562 return MEDIA_SVC_PLUGIN_ERROR;
565 return MEDIA_SVC_PLUGIN_ERROR_NONE;
568 int check_db_corrupt(void *handle, char **err_msg)
570 int ret = MEDIA_SVC_PLUGIN_ERROR_NONE;
573 ret = media_svc_check_db_corrupt(handle);
575 __set_error_message(ret, err_msg);
576 return MEDIA_SVC_PLUGIN_ERROR;
579 return MEDIA_SVC_PLUGIN_ERROR_NONE;
582 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)
584 int ret = MEDIA_SVC_PLUGIN_ERROR_NONE;
586 if (handle == NULL) {
587 __set_error_message(ERR_HANDLE, err_msg);
588 return MEDIA_SVC_PLUGIN_ERROR;
592 __set_error_message(ERR_HANDLE, err_msg);
593 return MEDIA_SVC_PLUGIN_ERROR;
596 ret = media_svc_get_folder_list(handle, start_path, folder_list, (time_t **)modified_time_list, item_num_list, count);
598 __set_error_message(ret, err_msg);
599 return MEDIA_SVC_PLUGIN_ERROR;
602 return MEDIA_SVC_PLUGIN_ERROR_NONE;
605 int update_folder_time(void *handle, const char *storage_id, char *folder_path, uid_t uid, char **err_msg)
607 int ret = MEDIA_SVC_PLUGIN_ERROR_NONE;
609 if (handle == NULL) {
610 __set_error_message(ERR_HANDLE, err_msg);
611 return MEDIA_SVC_PLUGIN_ERROR;
614 if (folder_path == NULL) {
615 __set_error_message(ERR_HANDLE, err_msg);
616 return MEDIA_SVC_PLUGIN_ERROR;
619 ret = media_svc_update_folder_time(handle, storage_id, folder_path, uid);
621 __set_error_message(ret, err_msg);
622 return MEDIA_SVC_PLUGIN_ERROR;
625 return MEDIA_SVC_PLUGIN_ERROR_NONE;
628 int get_uuid(void * handle, char **uuid, char **err_msg)
630 int ret = MEDIA_SVC_PLUGIN_ERROR_NONE;
632 if (handle == NULL) {
633 __set_error_message(ERR_HANDLE, err_msg);
634 return MEDIA_SVC_PLUGIN_ERROR;
637 ret = media_svc_generate_uuid(uuid);
639 __set_error_message(ret, err_msg);
640 return MEDIA_SVC_PLUGIN_ERROR;
643 return MEDIA_SVC_PLUGIN_ERROR_NONE;
646 int get_mmc_info(void * handle, char **storage_name, char **storage_path, int *validity, bool *info_exist, char **err_msg)
648 int ret = MEDIA_SVC_PLUGIN_ERROR_NONE;
650 if (handle == NULL) {
651 __set_error_message(ERR_HANDLE, err_msg);
652 return MEDIA_SVC_PLUGIN_ERROR;
655 ret = media_svc_get_mmc_info(handle, storage_name, storage_path, validity, info_exist);
657 __set_error_message(MS_MEDIA_ERR_DB_NO_RECORD, err_msg);
658 return MEDIA_SVC_PLUGIN_ERROR;
661 return MEDIA_SVC_PLUGIN_ERROR_NONE;
664 int check_storage(void * handle, const char *storage_id, const char *storage_name, char **storage_path, int *validity, char **err_msg)
666 int ret = MEDIA_SVC_PLUGIN_ERROR_NONE;
668 if (handle == NULL) {
669 __set_error_message(ERR_HANDLE, err_msg);
670 return MEDIA_SVC_PLUGIN_ERROR;
673 ret = media_svc_check_storage(handle, storage_id, storage_name, storage_path, validity);
675 __set_error_message(ret, err_msg);
676 return MEDIA_SVC_PLUGIN_ERROR;
679 return MEDIA_SVC_PLUGIN_ERROR_NONE;
682 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)
684 int ret = MEDIA_SVC_PLUGIN_ERROR_NONE;
686 if (handle == NULL) {
687 __set_error_message(ERR_HANDLE, err_msg);
688 return MEDIA_SVC_PLUGIN_ERROR;
691 ret = media_svc_insert_storage(handle, storage_id, storage_name, storage_path, NULL, storage_type, uid);
693 __set_error_message(ret, err_msg);
694 return MEDIA_SVC_PLUGIN_ERROR;
697 return MEDIA_SVC_PLUGIN_ERROR_NONE;
700 int update_storage(void *handle, const char *storage_id, const char *storage_path, uid_t uid, char **err_msg)
702 int ret = MEDIA_SVC_PLUGIN_ERROR_NONE;
704 if (handle == NULL) {
705 __set_error_message(ERR_HANDLE, err_msg);
706 return MEDIA_SVC_PLUGIN_ERROR;
709 ret = media_svc_update_storage(handle, storage_id, storage_path, uid);
711 __set_error_message(ret, err_msg);
712 return MEDIA_SVC_PLUGIN_ERROR;
715 return MEDIA_SVC_PLUGIN_ERROR_NONE;
718 int delete_storage(void * handle, const char *storage_id, const char *storage_name, uid_t uid, char **err_msg)
720 int ret = MEDIA_SVC_PLUGIN_ERROR_NONE;
722 if (handle == NULL) {
723 __set_error_message(ERR_HANDLE, err_msg);
724 return MEDIA_SVC_PLUGIN_ERROR;
727 ret = media_svc_delete_storage(handle, storage_id, storage_name, uid);
729 __set_error_message(ret, err_msg);
730 return MEDIA_SVC_PLUGIN_ERROR;
733 return MEDIA_SVC_PLUGIN_ERROR_NONE;
736 int set_storage_validity(void * handle, const char *storage_id, int validity, uid_t uid, char **err_msg)
738 int ret = MEDIA_SVC_PLUGIN_ERROR_NONE;
740 if (handle == NULL) {
741 __set_error_message(ERR_HANDLE, err_msg);
742 return MEDIA_SVC_PLUGIN_ERROR;
745 ret = media_svc_set_storage_validity(handle, storage_id, validity, uid);
747 __set_error_message(ret, err_msg);
748 return MEDIA_SVC_PLUGIN_ERROR;
751 return MEDIA_SVC_PLUGIN_ERROR_NONE;
754 int set_all_storage_validity(void * handle, int validity, char **err_msg, uid_t uid)
756 int ret = MEDIA_SVC_PLUGIN_ERROR_NONE;
758 if (handle == NULL) {
759 __set_error_message(ERR_HANDLE, err_msg);
760 return MEDIA_SVC_PLUGIN_ERROR;
763 ret = media_svc_set_storage_validity(handle, NULL, validity, uid);
765 __set_error_message(ret, err_msg);
766 return MEDIA_SVC_PLUGIN_ERROR;
769 return MEDIA_SVC_PLUGIN_ERROR_NONE;
772 int get_storage_id(void * handle, const char *path, char *storage_id, char **err_msg)
774 int ret = MEDIA_SVC_PLUGIN_ERROR_NONE;
776 if (handle == NULL) {
777 __set_error_message(ERR_HANDLE, err_msg);
778 return MEDIA_SVC_PLUGIN_ERROR;
781 ret = media_svc_get_storage_id(handle, path, storage_id);
783 __set_error_message(ret, err_msg);
784 return MEDIA_SVC_PLUGIN_ERROR;
787 return MEDIA_SVC_PLUGIN_ERROR_NONE;
790 int get_storage_scan_status(void * handle, const char *storage_id, int *status, char **err_msg)
792 int ret = MEDIA_SVC_PLUGIN_ERROR_NONE;
793 media_svc_scan_status_type_e storage_status = 0;
795 if (handle == NULL) {
796 __set_error_message(ERR_HANDLE, err_msg);
797 return MEDIA_SVC_PLUGIN_ERROR;
800 ret = media_svc_get_storage_scan_status(handle, storage_id, &storage_status);
802 __set_error_message(ret, err_msg);
803 return MEDIA_SVC_PLUGIN_ERROR;
806 *status = storage_status;
808 return MEDIA_SVC_PLUGIN_ERROR_NONE;
811 int set_storage_scan_status(void *handle, const char *storage_id, int status, uid_t uid, char **err_msg)
813 int ret = MEDIA_SVC_PLUGIN_ERROR_NONE;
814 media_svc_scan_status_type_e storage_status = status;
816 if (handle == NULL) {
817 __set_error_message(ERR_HANDLE, err_msg);
818 return MEDIA_SVC_PLUGIN_ERROR;
821 ret = media_svc_set_storage_scan_status(handle, storage_id, storage_status, uid);
823 __set_error_message(ret, err_msg);
824 return MEDIA_SVC_PLUGIN_ERROR;
827 return MEDIA_SVC_PLUGIN_ERROR_NONE;
830 int get_storage_list(void *handle, char ***storage_list, char ***storage_id_list, int **scan_status_list, int *count, char **err_msg)
832 int ret = MEDIA_SVC_PLUGIN_ERROR_NONE;
834 if (handle == NULL) {
835 __set_error_message(ERR_HANDLE, err_msg);
836 return MEDIA_SVC_PLUGIN_ERROR;
840 __set_error_message(ERR_HANDLE, err_msg);
841 return MEDIA_SVC_PLUGIN_ERROR;
844 ret = media_svc_get_storage_list(handle, storage_list, storage_id_list, scan_status_list, count);
846 __set_error_message(ret, err_msg);
847 return MEDIA_SVC_PLUGIN_ERROR;
850 return MEDIA_SVC_PLUGIN_ERROR_NONE;
853 int update_item_begin(void *handle, int item_cnt, char **err_msg)
855 int ret = MEDIA_SVC_PLUGIN_ERROR_NONE;
857 if (handle == NULL) {
858 __set_error_message(ERR_HANDLE, err_msg);
859 return MEDIA_SVC_PLUGIN_ERROR;
862 ret = media_svc_update_item_begin(handle, item_cnt);
864 __set_error_message(ret, err_msg);
865 return MEDIA_SVC_PLUGIN_ERROR;
868 return MEDIA_SVC_PLUGIN_ERROR_NONE;
871 int update_item_end(void *handle, uid_t uid, char **err_msg)
873 int ret = MEDIA_SVC_PLUGIN_ERROR_NONE;
875 if (handle == NULL) {
876 __set_error_message(ERR_HANDLE, err_msg);
877 return MEDIA_SVC_PLUGIN_ERROR;
880 ret = media_svc_update_item_end(handle, uid);
882 __set_error_message(ret, err_msg);
883 return MEDIA_SVC_PLUGIN_ERROR;
886 return MEDIA_SVC_PLUGIN_ERROR_NONE;
889 int update_item_meta(void *handle, const char *file_path, int storage_type, uid_t uid, char **err_msg)
891 int ret = MEDIA_SVC_PLUGIN_ERROR_NONE;
893 if (handle == NULL) {
894 __set_error_message(ERR_HANDLE, err_msg);
895 return MEDIA_SVC_PLUGIN_ERROR;
898 if (file_path == NULL) {
899 __set_error_message(ERR_HANDLE, err_msg);
900 return MEDIA_SVC_PLUGIN_ERROR;
903 ret = media_svc_update_item_meta(handle, file_path, storage_type, uid);
905 __set_error_message(ret, err_msg);
906 return MEDIA_SVC_PLUGIN_ERROR;
909 return MEDIA_SVC_PLUGIN_ERROR_NONE;
912 int insert_item_scan(void * handle, const char *storage_id, const char *file_path, int storage_type, uid_t uid, char **err_msg)
914 int ret = MEDIA_SVC_PLUGIN_ERROR_NONE;
916 if (handle == NULL) {
917 __set_error_message(ERR_HANDLE, err_msg);
918 return MEDIA_SVC_PLUGIN_ERROR;
921 if (!STRING_VALID(file_path)) {
922 __set_error_message(ERR_FILE_PATH, err_msg);
923 return MEDIA_SVC_PLUGIN_ERROR;
926 if (!STORAGE_VALID(storage_type)) {
927 __set_error_message(ERR_STORAGE_TYPE, err_msg);
928 return MEDIA_SVC_PLUGIN_ERROR;
931 ret = media_svc_insert_item_pass1(handle, storage_id, storage_type, file_path, FALSE, uid);
933 __set_error_message(ret, err_msg);
934 return MEDIA_SVC_PLUGIN_ERROR;
937 return MEDIA_SVC_PLUGIN_ERROR_NONE;
940 int update_item_extract(void * handle, const char *storage_id, int storage_type, int scan_type, uid_t uid, const char *path, char **err_msg)
942 int ret = MEDIA_SVC_PLUGIN_ERROR_NONE;
944 if (handle == NULL) {
945 __set_error_message(ERR_HANDLE, err_msg);
946 return MEDIA_SVC_PLUGIN_ERROR;
949 if (!STORAGE_VALID(storage_type)) {
950 __set_error_message(ERR_STORAGE_TYPE, err_msg);
951 return MEDIA_SVC_PLUGIN_ERROR;
954 ret = media_svc_insert_item_pass2(handle, storage_id, storage_type, scan_type, path, FALSE, uid);
956 __set_error_message(ret, err_msg);
957 return MEDIA_SVC_PLUGIN_ERROR;
960 return MEDIA_SVC_PLUGIN_ERROR_NONE;
963 int insert_folder_begin(void * handle, int item_cnt, char **err_msg)
965 int ret = MEDIA_SVC_PLUGIN_ERROR_NONE;
967 if (handle == NULL) {
968 __set_error_message(ERR_HANDLE, err_msg);
969 return MEDIA_SVC_PLUGIN_ERROR;
972 ret = media_svc_insert_folder_begin(handle, item_cnt);
974 __set_error_message(ret, err_msg);
975 return MEDIA_SVC_PLUGIN_ERROR;
978 return MEDIA_SVC_PLUGIN_ERROR_NONE;
981 int insert_folder_end(void *handle, uid_t uid, char **err_msg)
983 int ret = MEDIA_SVC_PLUGIN_ERROR_NONE;
985 if (handle == NULL) {
986 __set_error_message(ERR_HANDLE, err_msg);
987 return MEDIA_SVC_PLUGIN_ERROR;
990 ret = media_svc_insert_folder_end(handle, uid);
992 __set_error_message(ret, err_msg);
993 return MEDIA_SVC_PLUGIN_ERROR;
996 return MEDIA_SVC_PLUGIN_ERROR_NONE;
999 int insert_folder(void * handle, const char *storage_id, const char *file_path, int storage_type, uid_t uid, char **err_msg)
1001 int ret = MEDIA_SVC_PLUGIN_ERROR_NONE;
1003 if (handle == NULL) {
1004 __set_error_message(ERR_HANDLE, err_msg);
1005 return MEDIA_SVC_PLUGIN_ERROR;
1008 if (!STRING_VALID(file_path)) {
1009 __set_error_message(ERR_FILE_PATH, err_msg);
1010 return MEDIA_SVC_PLUGIN_ERROR;
1013 if (!STORAGE_VALID(storage_type)) {
1014 __set_error_message(ERR_STORAGE_TYPE, err_msg);
1015 return MEDIA_SVC_PLUGIN_ERROR;
1018 ret = media_svc_insert_folder(handle, storage_id, storage_type, file_path, uid);
1020 __set_error_message(ret, err_msg);
1021 return MEDIA_SVC_PLUGIN_ERROR;
1024 return MEDIA_SVC_PLUGIN_ERROR_NONE;
1027 int delete_invalid_folder(void * handle, const char *storage_id, uid_t uid, char **err_msg)
1029 int ret = MEDIA_SVC_PLUGIN_ERROR_NONE;
1031 if (handle == NULL) {
1032 __set_error_message(ERR_HANDLE, err_msg);
1033 return MEDIA_SVC_PLUGIN_ERROR;
1036 ret = media_svc_delete_invalid_folder(handle, storage_id, uid);
1038 __set_error_message(ret, err_msg);
1039 return MEDIA_SVC_PLUGIN_ERROR;
1042 return MEDIA_SVC_PLUGIN_ERROR_NONE;
1045 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)
1047 int ret = MEDIA_SVC_PLUGIN_ERROR_NONE;
1049 if (handle == NULL) {
1050 __set_error_message(ERR_HANDLE, err_msg);
1051 return MEDIA_SVC_PLUGIN_ERROR;
1054 ret = media_svc_set_folder_validity(handle, storage_id, start_path, validity, is_recursive, uid);
1056 __set_error_message(ret, err_msg);
1057 return MEDIA_SVC_PLUGIN_ERROR;
1060 return MEDIA_SVC_PLUGIN_ERROR_NONE;
1063 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)
1065 int ret = MEDIA_SVC_PLUGIN_ERROR_NONE;
1067 if (handle == NULL) {
1068 __set_error_message(ERR_HANDLE, err_msg);
1069 return MEDIA_SVC_PLUGIN_ERROR;
1072 ret = media_svc_delete_invalid_folder_by_path(handle, storage_id, folder_path, uid, delete_count);
1074 __set_error_message(ret, err_msg);
1075 return MEDIA_SVC_PLUGIN_ERROR;
1078 return MEDIA_SVC_PLUGIN_ERROR_NONE;
1081 int check_folder_exist(void * handle, const char *storage_id, const char *folder_path, char **err_msg)
1083 int ret = MEDIA_SVC_PLUGIN_ERROR_NONE;
1085 if (handle == NULL) {
1086 __set_error_message(ERR_HANDLE, err_msg);
1087 return MEDIA_SVC_PLUGIN_ERROR;
1090 ret = media_svc_check_folder_exist_by_path(handle, storage_id, folder_path);
1092 __set_error_message(ret, err_msg);
1093 return MEDIA_SVC_PLUGIN_ERROR;
1096 return MEDIA_SVC_PLUGIN_ERROR_NONE;
1099 int count_subfolder(void * handle, const char *storage_id, const char *folder_path, int *count, char **err_msg)
1101 int ret = MEDIA_SVC_PLUGIN_ERROR_NONE;
1104 if (handle == NULL) {
1105 __set_error_message(ERR_HANDLE, err_msg);
1106 return MEDIA_SVC_PLUGIN_ERROR;
1109 ret = media_svc_check_subfolder_by_path(handle, storage_id, folder_path, &cnt);
1111 __set_error_message(ret, err_msg);
1112 return MEDIA_SVC_PLUGIN_ERROR;
1117 return MEDIA_SVC_PLUGIN_ERROR_NONE;
1120 int get_folder_id(void * handle, const char *storage_id, const char *path, char *folder_id, char **err_msg)
1122 int ret = MEDIA_SVC_PLUGIN_ERROR_NONE;
1124 if (handle == NULL) {
1125 __set_error_message(ERR_HANDLE, err_msg);
1126 return MEDIA_SVC_PLUGIN_ERROR;
1129 ret = media_svc_get_folder_id(handle, storage_id, path, folder_id);
1131 __set_error_message(ret, err_msg);
1132 return MEDIA_SVC_PLUGIN_ERROR;
1135 return MEDIA_SVC_PLUGIN_ERROR_NONE;