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;
550 int user_version = -1;
552 ret = media_svc_get_user_version(handle, &user_version);
554 __set_error_message(ret, err_msg);
555 return MEDIA_SVC_PLUGIN_ERROR;
558 if (user_version == 0) {
560 ret = media_svc_create_table(handle, uid);
562 __set_error_message(ret, err_msg);
563 return MEDIA_SVC_PLUGIN_ERROR;
567 ret = media_svc_check_db_upgrade(handle, need_full_scan, user_version, uid);
569 __set_error_message(ret, err_msg);
570 return MEDIA_SVC_PLUGIN_ERROR;
574 return MEDIA_SVC_PLUGIN_ERROR_NONE;
577 int check_db_corrupt(void *handle, char **err_msg)
579 int ret = MEDIA_SVC_PLUGIN_ERROR_NONE;
582 ret = media_svc_check_db_corrupt(handle);
584 __set_error_message(ret, err_msg);
585 return MEDIA_SVC_PLUGIN_ERROR;
588 return MEDIA_SVC_PLUGIN_ERROR_NONE;
591 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)
593 int ret = MEDIA_SVC_PLUGIN_ERROR_NONE;
595 if (handle == NULL) {
596 __set_error_message(ERR_HANDLE, err_msg);
597 return MEDIA_SVC_PLUGIN_ERROR;
601 __set_error_message(ERR_HANDLE, err_msg);
602 return MEDIA_SVC_PLUGIN_ERROR;
605 ret = media_svc_get_folder_list(handle, start_path, folder_list, (time_t **)modified_time_list, item_num_list, count);
607 __set_error_message(ret, err_msg);
608 return MEDIA_SVC_PLUGIN_ERROR;
611 return MEDIA_SVC_PLUGIN_ERROR_NONE;
614 int update_folder_time(void *handle, const char *storage_id, char *folder_path, uid_t uid, char **err_msg)
616 int ret = MEDIA_SVC_PLUGIN_ERROR_NONE;
618 if (handle == NULL) {
619 __set_error_message(ERR_HANDLE, err_msg);
620 return MEDIA_SVC_PLUGIN_ERROR;
623 if (folder_path == NULL) {
624 __set_error_message(ERR_HANDLE, err_msg);
625 return MEDIA_SVC_PLUGIN_ERROR;
628 ret = media_svc_update_folder_time(handle, storage_id, folder_path, uid);
630 __set_error_message(ret, err_msg);
631 return MEDIA_SVC_PLUGIN_ERROR;
634 return MEDIA_SVC_PLUGIN_ERROR_NONE;
637 int get_uuid(void * handle, char **uuid, char **err_msg)
639 int ret = MEDIA_SVC_PLUGIN_ERROR_NONE;
641 if (handle == NULL) {
642 __set_error_message(ERR_HANDLE, err_msg);
643 return MEDIA_SVC_PLUGIN_ERROR;
646 ret = media_svc_generate_uuid(uuid);
648 __set_error_message(ret, err_msg);
649 return MEDIA_SVC_PLUGIN_ERROR;
652 return MEDIA_SVC_PLUGIN_ERROR_NONE;
655 int get_mmc_info(void * handle, char **storage_name, char **storage_path, int *validity, bool *info_exist, char **err_msg)
657 int ret = MEDIA_SVC_PLUGIN_ERROR_NONE;
659 if (handle == NULL) {
660 __set_error_message(ERR_HANDLE, err_msg);
661 return MEDIA_SVC_PLUGIN_ERROR;
664 ret = media_svc_get_mmc_info(handle, storage_name, storage_path, validity, info_exist);
666 __set_error_message(MS_MEDIA_ERR_DB_NO_RECORD, err_msg);
667 return MEDIA_SVC_PLUGIN_ERROR;
670 return MEDIA_SVC_PLUGIN_ERROR_NONE;
673 int check_storage(void * handle, const char *storage_id, const char *storage_name, char **storage_path, int *validity, char **err_msg)
675 int ret = MEDIA_SVC_PLUGIN_ERROR_NONE;
677 if (handle == NULL) {
678 __set_error_message(ERR_HANDLE, err_msg);
679 return MEDIA_SVC_PLUGIN_ERROR;
682 ret = media_svc_check_storage(handle, storage_id, storage_name, storage_path, validity);
684 __set_error_message(ret, err_msg);
685 return MEDIA_SVC_PLUGIN_ERROR;
688 return MEDIA_SVC_PLUGIN_ERROR_NONE;
691 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)
693 int ret = MEDIA_SVC_PLUGIN_ERROR_NONE;
695 if (handle == NULL) {
696 __set_error_message(ERR_HANDLE, err_msg);
697 return MEDIA_SVC_PLUGIN_ERROR;
700 ret = media_svc_insert_storage(handle, storage_id, storage_name, storage_path, NULL, storage_type, uid);
702 __set_error_message(ret, err_msg);
703 return MEDIA_SVC_PLUGIN_ERROR;
706 return MEDIA_SVC_PLUGIN_ERROR_NONE;
709 int update_storage(void *handle, const char *storage_id, const char *storage_path, uid_t uid, char **err_msg)
711 int ret = MEDIA_SVC_PLUGIN_ERROR_NONE;
713 if (handle == NULL) {
714 __set_error_message(ERR_HANDLE, err_msg);
715 return MEDIA_SVC_PLUGIN_ERROR;
718 ret = media_svc_update_storage(handle, storage_id, storage_path, uid);
720 __set_error_message(ret, err_msg);
721 return MEDIA_SVC_PLUGIN_ERROR;
724 return MEDIA_SVC_PLUGIN_ERROR_NONE;
727 int delete_storage(void * handle, const char *storage_id, const char *storage_name, uid_t uid, char **err_msg)
729 int ret = MEDIA_SVC_PLUGIN_ERROR_NONE;
731 if (handle == NULL) {
732 __set_error_message(ERR_HANDLE, err_msg);
733 return MEDIA_SVC_PLUGIN_ERROR;
736 ret = media_svc_delete_storage(handle, storage_id, storage_name, uid);
738 __set_error_message(ret, err_msg);
739 return MEDIA_SVC_PLUGIN_ERROR;
742 return MEDIA_SVC_PLUGIN_ERROR_NONE;
745 int set_storage_validity(void * handle, const char *storage_id, int validity, uid_t uid, char **err_msg)
747 int ret = MEDIA_SVC_PLUGIN_ERROR_NONE;
749 if (handle == NULL) {
750 __set_error_message(ERR_HANDLE, err_msg);
751 return MEDIA_SVC_PLUGIN_ERROR;
754 ret = media_svc_set_storage_validity(handle, storage_id, validity, uid);
756 __set_error_message(ret, err_msg);
757 return MEDIA_SVC_PLUGIN_ERROR;
760 return MEDIA_SVC_PLUGIN_ERROR_NONE;
763 int set_all_storage_validity(void * handle, int validity, char **err_msg, uid_t uid)
765 int ret = MEDIA_SVC_PLUGIN_ERROR_NONE;
767 if (handle == NULL) {
768 __set_error_message(ERR_HANDLE, err_msg);
769 return MEDIA_SVC_PLUGIN_ERROR;
772 ret = media_svc_set_storage_validity(handle, NULL, validity, uid);
774 __set_error_message(ret, err_msg);
775 return MEDIA_SVC_PLUGIN_ERROR;
778 return MEDIA_SVC_PLUGIN_ERROR_NONE;
781 int get_storage_id(void * handle, const char *path, char *storage_id, char **err_msg)
783 int ret = MEDIA_SVC_PLUGIN_ERROR_NONE;
785 if (handle == NULL) {
786 __set_error_message(ERR_HANDLE, err_msg);
787 return MEDIA_SVC_PLUGIN_ERROR;
790 ret = media_svc_get_storage_id(handle, path, storage_id);
792 __set_error_message(ret, err_msg);
793 return MEDIA_SVC_PLUGIN_ERROR;
796 return MEDIA_SVC_PLUGIN_ERROR_NONE;
799 int get_storage_scan_status(void * handle, const char *storage_id, int *status, char **err_msg)
801 int ret = MEDIA_SVC_PLUGIN_ERROR_NONE;
802 media_svc_scan_status_type_e storage_status = 0;
804 if (handle == NULL) {
805 __set_error_message(ERR_HANDLE, err_msg);
806 return MEDIA_SVC_PLUGIN_ERROR;
809 ret = media_svc_get_storage_scan_status(handle, storage_id, &storage_status);
811 __set_error_message(ret, err_msg);
812 return MEDIA_SVC_PLUGIN_ERROR;
815 *status = storage_status;
817 return MEDIA_SVC_PLUGIN_ERROR_NONE;
820 int set_storage_scan_status(void *handle, const char *storage_id, int status, uid_t uid, char **err_msg)
822 int ret = MEDIA_SVC_PLUGIN_ERROR_NONE;
823 media_svc_scan_status_type_e storage_status = status;
825 if (handle == NULL) {
826 __set_error_message(ERR_HANDLE, err_msg);
827 return MEDIA_SVC_PLUGIN_ERROR;
830 ret = media_svc_set_storage_scan_status(handle, storage_id, storage_status, uid);
832 __set_error_message(ret, err_msg);
833 return MEDIA_SVC_PLUGIN_ERROR;
836 return MEDIA_SVC_PLUGIN_ERROR_NONE;
839 int get_storage_list(void *handle, char ***storage_list, char ***storage_id_list, int **scan_status_list, int *count, char **err_msg)
841 int ret = MEDIA_SVC_PLUGIN_ERROR_NONE;
843 if (handle == NULL) {
844 __set_error_message(ERR_HANDLE, err_msg);
845 return MEDIA_SVC_PLUGIN_ERROR;
849 __set_error_message(ERR_HANDLE, err_msg);
850 return MEDIA_SVC_PLUGIN_ERROR;
853 ret = media_svc_get_storage_list(handle, storage_list, storage_id_list, scan_status_list, count);
855 __set_error_message(ret, err_msg);
856 return MEDIA_SVC_PLUGIN_ERROR;
859 return MEDIA_SVC_PLUGIN_ERROR_NONE;
862 int update_item_begin(void *handle, int item_cnt, char **err_msg)
864 int ret = MEDIA_SVC_PLUGIN_ERROR_NONE;
866 if (handle == NULL) {
867 __set_error_message(ERR_HANDLE, err_msg);
868 return MEDIA_SVC_PLUGIN_ERROR;
871 ret = media_svc_update_item_begin(handle, item_cnt);
873 __set_error_message(ret, err_msg);
874 return MEDIA_SVC_PLUGIN_ERROR;
877 return MEDIA_SVC_PLUGIN_ERROR_NONE;
880 int update_item_end(void *handle, uid_t uid, char **err_msg)
882 int ret = MEDIA_SVC_PLUGIN_ERROR_NONE;
884 if (handle == NULL) {
885 __set_error_message(ERR_HANDLE, err_msg);
886 return MEDIA_SVC_PLUGIN_ERROR;
889 ret = media_svc_update_item_end(handle, uid);
891 __set_error_message(ret, err_msg);
892 return MEDIA_SVC_PLUGIN_ERROR;
895 return MEDIA_SVC_PLUGIN_ERROR_NONE;
898 int update_item_meta(void *handle, const char *file_path, int storage_type, uid_t uid, char **err_msg)
900 int ret = MEDIA_SVC_PLUGIN_ERROR_NONE;
902 if (handle == NULL) {
903 __set_error_message(ERR_HANDLE, err_msg);
904 return MEDIA_SVC_PLUGIN_ERROR;
907 if (file_path == NULL) {
908 __set_error_message(ERR_HANDLE, err_msg);
909 return MEDIA_SVC_PLUGIN_ERROR;
912 ret = media_svc_update_item_meta(handle, file_path, storage_type, uid);
914 __set_error_message(ret, err_msg);
915 return MEDIA_SVC_PLUGIN_ERROR;
918 return MEDIA_SVC_PLUGIN_ERROR_NONE;
921 int insert_item_scan(void * handle, const char *storage_id, const char *file_path, int storage_type, uid_t uid, char **err_msg)
923 int ret = MEDIA_SVC_PLUGIN_ERROR_NONE;
925 if (handle == NULL) {
926 __set_error_message(ERR_HANDLE, err_msg);
927 return MEDIA_SVC_PLUGIN_ERROR;
930 if (!STRING_VALID(file_path)) {
931 __set_error_message(ERR_FILE_PATH, err_msg);
932 return MEDIA_SVC_PLUGIN_ERROR;
935 if (!STORAGE_VALID(storage_type)) {
936 __set_error_message(ERR_STORAGE_TYPE, err_msg);
937 return MEDIA_SVC_PLUGIN_ERROR;
940 ret = media_svc_insert_item_pass1(handle, storage_id, storage_type, file_path, FALSE, uid);
942 __set_error_message(ret, err_msg);
943 return MEDIA_SVC_PLUGIN_ERROR;
946 return MEDIA_SVC_PLUGIN_ERROR_NONE;
949 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)
951 int ret = MEDIA_SVC_PLUGIN_ERROR_NONE;
953 if (handle == NULL) {
954 __set_error_message(ERR_HANDLE, 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_item_pass2(handle, storage_id, storage_type, scan_type, path, FALSE, uid);
965 __set_error_message(ret, err_msg);
966 return MEDIA_SVC_PLUGIN_ERROR;
969 return MEDIA_SVC_PLUGIN_ERROR_NONE;
972 int insert_folder_begin(void * handle, int item_cnt, char **err_msg)
974 int ret = MEDIA_SVC_PLUGIN_ERROR_NONE;
976 if (handle == NULL) {
977 __set_error_message(ERR_HANDLE, err_msg);
978 return MEDIA_SVC_PLUGIN_ERROR;
981 ret = media_svc_insert_folder_begin(handle, item_cnt);
983 __set_error_message(ret, err_msg);
984 return MEDIA_SVC_PLUGIN_ERROR;
987 return MEDIA_SVC_PLUGIN_ERROR_NONE;
990 int insert_folder_end(void *handle, uid_t uid, char **err_msg)
992 int ret = MEDIA_SVC_PLUGIN_ERROR_NONE;
994 if (handle == NULL) {
995 __set_error_message(ERR_HANDLE, err_msg);
996 return MEDIA_SVC_PLUGIN_ERROR;
999 ret = media_svc_insert_folder_end(handle, uid);
1001 __set_error_message(ret, err_msg);
1002 return MEDIA_SVC_PLUGIN_ERROR;
1005 return MEDIA_SVC_PLUGIN_ERROR_NONE;
1008 int insert_folder(void * handle, const char *storage_id, const char *file_path, int storage_type, uid_t uid, char **err_msg)
1010 int ret = MEDIA_SVC_PLUGIN_ERROR_NONE;
1012 if (handle == NULL) {
1013 __set_error_message(ERR_HANDLE, err_msg);
1014 return MEDIA_SVC_PLUGIN_ERROR;
1017 if (!STRING_VALID(file_path)) {
1018 __set_error_message(ERR_FILE_PATH, err_msg);
1019 return MEDIA_SVC_PLUGIN_ERROR;
1022 if (!STORAGE_VALID(storage_type)) {
1023 __set_error_message(ERR_STORAGE_TYPE, err_msg);
1024 return MEDIA_SVC_PLUGIN_ERROR;
1027 ret = media_svc_insert_folder(handle, storage_id, storage_type, file_path, uid);
1029 __set_error_message(ret, err_msg);
1030 return MEDIA_SVC_PLUGIN_ERROR;
1033 return MEDIA_SVC_PLUGIN_ERROR_NONE;
1036 int delete_invalid_folder(void * handle, const char *storage_id, uid_t uid, char **err_msg)
1038 int ret = MEDIA_SVC_PLUGIN_ERROR_NONE;
1040 if (handle == NULL) {
1041 __set_error_message(ERR_HANDLE, err_msg);
1042 return MEDIA_SVC_PLUGIN_ERROR;
1045 ret = media_svc_delete_invalid_folder(handle, storage_id, uid);
1047 __set_error_message(ret, err_msg);
1048 return MEDIA_SVC_PLUGIN_ERROR;
1051 return MEDIA_SVC_PLUGIN_ERROR_NONE;
1054 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)
1056 int ret = MEDIA_SVC_PLUGIN_ERROR_NONE;
1058 if (handle == NULL) {
1059 __set_error_message(ERR_HANDLE, err_msg);
1060 return MEDIA_SVC_PLUGIN_ERROR;
1063 ret = media_svc_set_folder_validity(handle, storage_id, start_path, validity, is_recursive, uid);
1065 __set_error_message(ret, err_msg);
1066 return MEDIA_SVC_PLUGIN_ERROR;
1069 return MEDIA_SVC_PLUGIN_ERROR_NONE;
1072 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)
1074 int ret = MEDIA_SVC_PLUGIN_ERROR_NONE;
1076 if (handle == NULL) {
1077 __set_error_message(ERR_HANDLE, err_msg);
1078 return MEDIA_SVC_PLUGIN_ERROR;
1081 ret = media_svc_delete_invalid_folder_by_path(handle, storage_id, folder_path, uid, delete_count);
1083 __set_error_message(ret, err_msg);
1084 return MEDIA_SVC_PLUGIN_ERROR;
1087 return MEDIA_SVC_PLUGIN_ERROR_NONE;
1090 int check_folder_exist(void * handle, const char *storage_id, const char *folder_path, char **err_msg)
1092 int ret = MEDIA_SVC_PLUGIN_ERROR_NONE;
1094 if (handle == NULL) {
1095 __set_error_message(ERR_HANDLE, err_msg);
1096 return MEDIA_SVC_PLUGIN_ERROR;
1099 ret = media_svc_check_folder_exist_by_path(handle, storage_id, folder_path);
1101 __set_error_message(ret, err_msg);
1102 return MEDIA_SVC_PLUGIN_ERROR;
1105 return MEDIA_SVC_PLUGIN_ERROR_NONE;
1108 int count_subfolder(void * handle, const char *storage_id, const char *folder_path, int *count, char **err_msg)
1110 int ret = MEDIA_SVC_PLUGIN_ERROR_NONE;
1113 if (handle == NULL) {
1114 __set_error_message(ERR_HANDLE, err_msg);
1115 return MEDIA_SVC_PLUGIN_ERROR;
1118 ret = media_svc_check_subfolder_by_path(handle, storage_id, folder_path, &cnt);
1120 __set_error_message(ret, err_msg);
1121 return MEDIA_SVC_PLUGIN_ERROR;
1126 return MEDIA_SVC_PLUGIN_ERROR_NONE;
1129 int get_folder_id(void * handle, const char *storage_id, const char *path, char *folder_id, char **err_msg)
1131 int ret = MEDIA_SVC_PLUGIN_ERROR_NONE;
1133 if (handle == NULL) {
1134 __set_error_message(ERR_HANDLE, err_msg);
1135 return MEDIA_SVC_PLUGIN_ERROR;
1138 ret = media_svc_get_folder_id(handle, storage_id, path, folder_id);
1140 __set_error_message(ret, err_msg);
1141 return MEDIA_SVC_PLUGIN_ERROR;
1144 return MEDIA_SVC_PLUGIN_ERROR_NONE;