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.
24 #include <media-thumbnail.h>
25 #include "media-svc.h"
26 #include "media-svc-util.h"
28 #define MEDIA_SVC_PLUGIN_ERROR_NONE 0
29 #define MEDIA_SVC_PLUGIN_ERROR -1
31 #define STRING_VALID(str) \
32 ((str != NULL && strlen(str) > 0) ? TRUE : FALSE)
33 #define STORAGE_VALID(storage)\
34 (((storage == MEDIA_SVC_STORAGE_INTERNAL) || (storage == MEDIA_SVC_STORAGE_EXTERNAL)) ? TRUE : FALSE)
46 }media_svc_error_type_e;
48 static void __set_error_message(int err_type, char ** err_msg);
50 static void __set_error_message(int err_type, char ** err_msg)
57 if(err_type == ERR_HANDLE)
58 *err_msg = strdup("invalid handle");
59 else if(err_type == ERR_FILE_PATH)
60 *err_msg = strdup("invalid file path");
61 else if(err_type == ERR_FOLDER_PATH)
62 *err_msg = strdup("invalid folder path");
63 else if(err_type == ERR_MIME_TYPE)
64 *err_msg = strdup("invalid mime type");
65 else if(err_type == ERR_NOT_MEDIAFILE)
66 *err_msg = strdup("not media content");
67 else if(err_type == ERR_STORAGE_TYPE)
68 *err_msg = strdup("invalid storage type");
69 else if(err_type == ERR_CHECK_ITEM)
70 *err_msg = strdup("item does not exist");
71 else if(err_type == MS_MEDIA_ERR_DB_CONNECT_FAIL)
72 *err_msg = strdup("DB connect error");
73 else if(err_type == MS_MEDIA_ERR_DB_DISCONNECT_FAIL)
74 *err_msg = strdup("DB disconnect error");
75 else if(err_type == MS_MEDIA_ERR_INVALID_PARAMETER)
76 *err_msg = strdup("invalid parameter");
77 else if(err_type == MS_MEDIA_ERR_DB_INTERNAL)
78 *err_msg = strdup("DB internal error");
79 else if(err_type == MS_MEDIA_ERR_DB_NO_RECORD)
80 *err_msg = strdup("not found in DB");
81 else if(err_type == MS_MEDIA_ERR_INTERNAL)
82 *err_msg = strdup("media service internal error");
83 else if(err_type == MS_MEDIA_ERR_DB_CORRUPT)
84 *err_msg = strdup("DB corrupt error");
86 *err_msg = strdup("error unknown");
91 int check_item(const char *file_path, char ** err_msg)
93 if (!STRING_VALID(file_path)) {
94 __set_error_message(ERR_FILE_PATH, err_msg);
95 return MEDIA_SVC_PLUGIN_ERROR;
98 return MEDIA_SVC_PLUGIN_ERROR_NONE;
101 int connect_db(void ** handle, uid_t uid, char ** err_msg)
103 int ret = media_svc_connect(handle,uid);
106 __set_error_message(ret, err_msg);
107 return MEDIA_SVC_PLUGIN_ERROR;
110 return MEDIA_SVC_PLUGIN_ERROR_NONE;
113 int disconnect_db(void * handle, char ** err_msg)
115 int ret = MEDIA_SVC_PLUGIN_ERROR_NONE;
118 __set_error_message(ERR_HANDLE, err_msg);
119 return MEDIA_SVC_PLUGIN_ERROR;
122 ret = media_svc_disconnect(handle);
124 __set_error_message(ret, err_msg);
125 return MEDIA_SVC_PLUGIN_ERROR;
128 return MEDIA_SVC_PLUGIN_ERROR_NONE;
131 int check_item_exist(void* handle, const char *file_path, int storage_type, char ** err_msg)
133 int ret = MEDIA_SVC_PLUGIN_ERROR_NONE;
136 __set_error_message(ERR_HANDLE, err_msg);
137 return MEDIA_SVC_PLUGIN_ERROR;
140 if (!STRING_VALID(file_path)) {
141 __set_error_message(ERR_FILE_PATH, err_msg);
142 return MEDIA_SVC_PLUGIN_ERROR;
145 if(!STORAGE_VALID(storage_type)) {
146 __set_error_message(ERR_STORAGE_TYPE, err_msg);
147 return MEDIA_SVC_PLUGIN_ERROR;
150 ret = media_svc_check_item_exist_by_path(handle, file_path);
151 if(ret == MS_MEDIA_ERR_NONE) {
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;
165 __set_error_message(ERR_HANDLE, err_msg);
166 return MEDIA_SVC_PLUGIN_ERROR;
169 ret = media_svc_insert_item_begin(handle, item_cnt, with_noti, from_pid);
171 __set_error_message(ret, err_msg);
172 return MEDIA_SVC_PLUGIN_ERROR;
175 return MEDIA_SVC_PLUGIN_ERROR_NONE;
178 int insert_item_end(void * handle, uid_t uid, char ** err_msg)
180 int ret = MEDIA_SVC_PLUGIN_ERROR_NONE;
183 __set_error_message(ERR_HANDLE, err_msg);
184 return MEDIA_SVC_PLUGIN_ERROR;
187 ret = media_svc_insert_item_end(handle, uid);
189 __set_error_message(ret, err_msg);
190 return MEDIA_SVC_PLUGIN_ERROR;
193 return MEDIA_SVC_PLUGIN_ERROR_NONE;
196 int insert_item(void * handle, const char *file_path, int storage_type, uid_t uid, char ** err_msg)
198 int ret = MEDIA_SVC_PLUGIN_ERROR_NONE;
201 __set_error_message(ERR_HANDLE, err_msg);
202 return MEDIA_SVC_PLUGIN_ERROR;
205 if (!STRING_VALID(file_path)) {
206 __set_error_message(ERR_FILE_PATH, err_msg);
207 return MEDIA_SVC_PLUGIN_ERROR;
210 if(!STORAGE_VALID(storage_type)) {
211 __set_error_message(ERR_STORAGE_TYPE, err_msg);
212 return MEDIA_SVC_PLUGIN_ERROR;
215 ret = media_svc_insert_item_bulk(handle, storage_type, file_path, FALSE, uid);
217 __set_error_message(ret, err_msg);
218 return MEDIA_SVC_PLUGIN_ERROR;
221 return MEDIA_SVC_PLUGIN_ERROR_NONE;
224 int insert_item_immediately(void * handle, const char *file_path, int storage_type, uid_t uid, char ** err_msg)
226 int ret = MEDIA_SVC_PLUGIN_ERROR_NONE;
229 __set_error_message(ERR_HANDLE, err_msg);
230 return MEDIA_SVC_PLUGIN_ERROR;
233 if (!STRING_VALID(file_path)) {
234 __set_error_message(ERR_FILE_PATH, err_msg);
235 return MEDIA_SVC_PLUGIN_ERROR;
238 if(!STORAGE_VALID(storage_type)) {
239 __set_error_message(ERR_STORAGE_TYPE, err_msg);
240 return MEDIA_SVC_PLUGIN_ERROR;
243 ret = media_svc_insert_item_immediately(handle, storage_type, file_path, uid);
245 __set_error_message(ret, err_msg);
246 return MEDIA_SVC_PLUGIN_ERROR;
249 return MEDIA_SVC_PLUGIN_ERROR_NONE;
252 int insert_burst_item(void * handle, const char *file_path, int storage_type, uid_t uid, char ** err_msg)
254 int ret = MEDIA_SVC_PLUGIN_ERROR_NONE;
257 __set_error_message(ERR_HANDLE, err_msg);
258 return MEDIA_SVC_PLUGIN_ERROR;
261 if (!STRING_VALID(file_path)) {
262 __set_error_message(ERR_FILE_PATH, err_msg);
263 return MEDIA_SVC_PLUGIN_ERROR;
266 if(!STORAGE_VALID(storage_type)) {
267 __set_error_message(ERR_STORAGE_TYPE, err_msg);
268 return MEDIA_SVC_PLUGIN_ERROR;
271 ret = media_svc_insert_item_bulk(handle, storage_type, file_path, TRUE, uid);
273 __set_error_message(ret, err_msg);
274 return MEDIA_SVC_PLUGIN_ERROR;
277 return MEDIA_SVC_PLUGIN_ERROR_NONE;
280 int move_item_begin(void * handle, int item_cnt, char ** err_msg)
282 int ret = MEDIA_SVC_PLUGIN_ERROR_NONE;
285 __set_error_message(ERR_HANDLE, err_msg);
286 return MEDIA_SVC_PLUGIN_ERROR;
289 ret = media_svc_move_item_begin(handle, item_cnt);
291 __set_error_message(ret, err_msg);
292 return MEDIA_SVC_PLUGIN_ERROR;
295 return MEDIA_SVC_PLUGIN_ERROR_NONE;
298 int move_item_end(void * handle, uid_t uid, char ** err_msg)
300 int ret = MEDIA_SVC_PLUGIN_ERROR_NONE;
303 __set_error_message(ERR_HANDLE, err_msg);
304 return MEDIA_SVC_PLUGIN_ERROR;
307 ret = media_svc_move_item_end(handle, uid);
309 __set_error_message(ret, err_msg);
310 return MEDIA_SVC_PLUGIN_ERROR;
313 return MEDIA_SVC_PLUGIN_ERROR_NONE;
316 int move_item(void * handle, const char *src_path, int src_storage_type, const char *dest_path, int dest_storage_type, uid_t uid, char ** err_msg)
318 int ret = MEDIA_SVC_PLUGIN_ERROR_NONE;
321 __set_error_message(ERR_HANDLE, err_msg);
322 return MEDIA_SVC_PLUGIN_ERROR;
325 if ((!STRING_VALID(src_path)) || (!STRING_VALID(dest_path))) {
326 __set_error_message(ERR_FILE_PATH, err_msg);
327 return MEDIA_SVC_PLUGIN_ERROR;
330 if((!STORAGE_VALID(src_storage_type)) || (!STORAGE_VALID(dest_storage_type))) {
331 __set_error_message(ERR_STORAGE_TYPE, err_msg);
332 return MEDIA_SVC_PLUGIN_ERROR;
335 ret = media_svc_move_item(handle, src_storage_type, src_path, dest_storage_type, dest_path, uid);
337 __set_error_message(ret, err_msg);
338 return MEDIA_SVC_PLUGIN_ERROR;
341 return MEDIA_SVC_PLUGIN_ERROR_NONE;
344 int set_all_storage_items_validity(void * handle, int storage_type, int validity, uid_t uid, char ** err_msg)
346 int ret = MEDIA_SVC_PLUGIN_ERROR_NONE;
349 __set_error_message(ERR_HANDLE, err_msg);
350 return MEDIA_SVC_PLUGIN_ERROR;
353 if(!STORAGE_VALID(storage_type)) {
354 __set_error_message(ERR_STORAGE_TYPE, err_msg);
355 return MEDIA_SVC_PLUGIN_ERROR;
358 ret = media_svc_set_all_storage_items_validity(handle, storage_type, validity, uid);
360 __set_error_message(ret, err_msg);
361 return MEDIA_SVC_PLUGIN_ERROR;
364 return MEDIA_SVC_PLUGIN_ERROR_NONE;
367 int set_folder_item_validity(void * handle, const char * folder_path, int validity, int recursive, uid_t uid, char ** err_msg)
369 int ret = MEDIA_SVC_PLUGIN_ERROR_NONE;
372 __set_error_message(ERR_HANDLE, err_msg);
373 return MEDIA_SVC_PLUGIN_ERROR;
376 if (!STRING_VALID(folder_path)) {
377 __set_error_message(ERR_FOLDER_PATH, err_msg);
378 return MEDIA_SVC_PLUGIN_ERROR;
381 ret = media_svc_set_folder_items_validity(handle, folder_path, validity, recursive, uid);
383 __set_error_message(ret, err_msg);
384 return MEDIA_SVC_PLUGIN_ERROR;
387 return MEDIA_SVC_PLUGIN_ERROR_NONE;
390 int set_item_validity_begin(void * handle, int item_cnt, char ** err_msg)
392 int ret = MEDIA_SVC_PLUGIN_ERROR_NONE;
395 __set_error_message(ERR_HANDLE, err_msg);
396 return MEDIA_SVC_PLUGIN_ERROR;
399 ret = media_svc_set_item_validity_begin(handle, item_cnt);
401 __set_error_message(ret, err_msg);
402 return MEDIA_SVC_PLUGIN_ERROR;
405 return MEDIA_SVC_PLUGIN_ERROR_NONE;
408 int set_item_validity_end(void * handle, uid_t uid, char ** err_msg)
410 int ret = MEDIA_SVC_PLUGIN_ERROR_NONE;
413 __set_error_message(ERR_HANDLE, err_msg);
414 return MEDIA_SVC_PLUGIN_ERROR;
417 ret = media_svc_set_item_validity_end(handle, uid);
419 __set_error_message(ret, err_msg);
420 return MEDIA_SVC_PLUGIN_ERROR;
423 return MEDIA_SVC_PLUGIN_ERROR_NONE;
426 int set_item_validity(void * handle, const char *file_path, int storage_type, int validity, uid_t uid, char ** err_msg)
428 int ret = MEDIA_SVC_PLUGIN_ERROR_NONE;
431 __set_error_message(ERR_HANDLE, err_msg);
432 return MEDIA_SVC_PLUGIN_ERROR;
435 if (!STRING_VALID(file_path)) {
436 __set_error_message(ERR_FILE_PATH, err_msg);
437 return MEDIA_SVC_PLUGIN_ERROR;
440 if(!STORAGE_VALID(storage_type)) {
441 __set_error_message(ERR_STORAGE_TYPE, err_msg);
442 return MEDIA_SVC_PLUGIN_ERROR;
445 ret = media_svc_set_item_validity(handle, file_path, validity, uid);
448 __set_error_message(ret, err_msg);
449 return MEDIA_SVC_PLUGIN_ERROR;
452 return MEDIA_SVC_PLUGIN_ERROR_NONE;
455 int delete_item(void * handle, const char *file_path, int storage_type, uid_t uid, char ** err_msg)
457 int ret = MEDIA_SVC_PLUGIN_ERROR_NONE;
460 __set_error_message(ERR_HANDLE, err_msg);
461 return MEDIA_SVC_PLUGIN_ERROR;
464 if (!STRING_VALID(file_path)) {
465 __set_error_message(ERR_FILE_PATH, err_msg);
466 return MEDIA_SVC_PLUGIN_ERROR;
469 if(!STORAGE_VALID(storage_type)) {
470 __set_error_message(ERR_STORAGE_TYPE, err_msg);
471 return MEDIA_SVC_PLUGIN_ERROR;
474 ret = media_svc_check_item_exist_by_path(handle, file_path);
476 ret = media_svc_delete_item_by_path(handle, file_path, uid);
479 __set_error_message(ret, err_msg);
480 return MEDIA_SVC_PLUGIN_ERROR;
483 return MEDIA_SVC_PLUGIN_ERROR_NONE;
486 __set_error_message(ERR_CHECK_ITEM, err_msg); //not exist in DB so can't delete item.
487 return MEDIA_SVC_PLUGIN_ERROR;
490 int delete_all_items_in_storage(void * handle, int storage_type, uid_t uid, char ** err_msg)
492 int ret = MEDIA_SVC_PLUGIN_ERROR_NONE;
495 __set_error_message(ERR_HANDLE, err_msg);
496 return MEDIA_SVC_PLUGIN_ERROR;
499 if(!STORAGE_VALID(storage_type)) {
500 __set_error_message(ERR_STORAGE_TYPE, err_msg);
501 return MEDIA_SVC_PLUGIN_ERROR;
504 ret = media_svc_delete_all_items_in_storage(handle, storage_type, uid);
506 __set_error_message(ret, err_msg);
507 return MEDIA_SVC_PLUGIN_ERROR;
510 return MEDIA_SVC_PLUGIN_ERROR_NONE;
513 int delete_all_invalid_items_in_storage(void * handle, int storage_type, uid_t uid, char ** err_msg)
515 int ret = MEDIA_SVC_PLUGIN_ERROR_NONE;
518 __set_error_message(ERR_HANDLE, err_msg);
519 return MEDIA_SVC_PLUGIN_ERROR;
522 if(!STORAGE_VALID(storage_type)) {
523 __set_error_message(ERR_STORAGE_TYPE, err_msg);
524 return MEDIA_SVC_PLUGIN_ERROR;
527 ret = media_svc_delete_invalid_items_in_storage(handle, storage_type, uid);
529 __set_error_message(ret, err_msg);
530 return MEDIA_SVC_PLUGIN_ERROR;
533 return MEDIA_SVC_PLUGIN_ERROR_NONE;
536 int delete_all_invalid_items_in_folder(void * handle, const char *folder_path, uid_t uid, char ** err_msg)
538 int ret = MEDIA_SVC_PLUGIN_ERROR_NONE;
541 __set_error_message(ERR_HANDLE, err_msg);
542 return MEDIA_SVC_PLUGIN_ERROR;
545 if (!STRING_VALID(folder_path)) {
546 __set_error_message(ERR_FOLDER_PATH, err_msg);
547 return MEDIA_SVC_PLUGIN_ERROR;
550 ret = media_svc_delete_invalid_items_in_folder(handle, folder_path, uid);
552 __set_error_message(ret, err_msg);
553 return MEDIA_SVC_PLUGIN_ERROR;
556 return MEDIA_SVC_PLUGIN_ERROR_NONE;
559 int delete_all_items(void * handle, uid_t uid ,char ** err_msg)
561 int ret = MEDIA_SVC_PLUGIN_ERROR_NONE;
564 __set_error_message(ERR_HANDLE, err_msg);
565 return MEDIA_SVC_PLUGIN_ERROR;
568 ret = delete_all_items_in_storage(handle, MEDIA_SVC_STORAGE_INTERNAL, uid, err_msg);
570 return MEDIA_SVC_PLUGIN_ERROR;
572 ret = delete_all_items_in_storage(handle, MEDIA_SVC_STORAGE_EXTERNAL, uid, err_msg);
574 return MEDIA_SVC_PLUGIN_ERROR;
576 return MEDIA_SVC_PLUGIN_ERROR_NONE;
579 int refresh_item(void * handle, const char *file_path, int storage_type, uid_t uid, char ** err_msg)
581 int ret = MEDIA_SVC_PLUGIN_ERROR_NONE;
584 __set_error_message(ERR_HANDLE, err_msg);
585 return MEDIA_SVC_PLUGIN_ERROR;
588 if (!STRING_VALID(file_path)) {
589 __set_error_message(ERR_FILE_PATH, err_msg);
590 return MEDIA_SVC_PLUGIN_ERROR;
593 if(!STORAGE_VALID(storage_type)) {
594 __set_error_message(ERR_STORAGE_TYPE, err_msg);
595 return MEDIA_SVC_PLUGIN_ERROR;
598 ret = media_svc_refresh_item(handle, storage_type, file_path, uid);
600 __set_error_message(ret, err_msg);
601 return MEDIA_SVC_PLUGIN_ERROR;
604 return MEDIA_SVC_PLUGIN_ERROR_NONE;
607 int update_begin(void)
609 return MEDIA_SVC_PLUGIN_ERROR_NONE;
612 int update_end(uid_t uid)
614 int ret = MEDIA_SVC_PLUGIN_ERROR_NONE;
616 ret = thumbnail_request_extract_all_thumbs(uid);
618 return MEDIA_SVC_PLUGIN_ERROR;
621 return MEDIA_SVC_PLUGIN_ERROR_NONE;
624 int send_dir_update_noti(void * handle, const char *dir_path, char **err_msg)
626 int ret = MEDIA_SVC_PLUGIN_ERROR_NONE;
628 if (!STRING_VALID(dir_path)) {
629 __set_error_message(ERR_FOLDER_PATH, err_msg);
630 return MEDIA_SVC_PLUGIN_ERROR;
633 ret = media_svc_send_dir_update_noti(handle, dir_path);
635 __set_error_message(ret, err_msg);
636 return MEDIA_SVC_PLUGIN_ERROR;
639 return MEDIA_SVC_PLUGIN_ERROR_NONE;
642 int count_delete_items_in_folder(void * handle, const char *folder_path, int *count, char ** err_msg)
644 int ret = MEDIA_SVC_PLUGIN_ERROR_NONE;
647 __set_error_message(ERR_HANDLE, err_msg);
648 return MEDIA_SVC_PLUGIN_ERROR;
652 __set_error_message(ERR_HANDLE, err_msg);
653 return MEDIA_SVC_PLUGIN_ERROR;
656 if (!STRING_VALID(folder_path)) {
657 __set_error_message(ERR_FOLDER_PATH, err_msg);
658 return MEDIA_SVC_PLUGIN_ERROR;
661 ret = media_svc_count_invalid_items_in_folder(handle, folder_path, count);
663 __set_error_message(ret, err_msg);
664 return MEDIA_SVC_PLUGIN_ERROR;
667 return MEDIA_SVC_PLUGIN_ERROR_NONE;