tizen 2.4 release
[framework/multimedia/media-server.git] / src / scanner-v2 / media-scanner-device-block-v2.c
1 /*
2  *  Media Server
3  *
4  * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
5  *
6  * Contact: Yong Yeon Kim <yy9875.kim@samsung.com>
7  *
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
11  *
12  * http://www.apache.org/licenses/LICENSE-2.0
13  *
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.
19  *
20  */
21
22 #include <vconf.h>
23
24 #include "media-util.h"
25
26 #include "media-common-utils.h"
27 #include "media-common-db-svc.h"
28 #include "media-common-external-storage.h"
29
30 #include "media-util-err.h"
31 #include "media-scanner-dbg-v2.h"
32 #include "media-scanner-scan-v2.h"
33 #include "media-scanner-extract-v2.h"
34 #include "media-scanner-device-block-v2.h"
35
36 static void __msc_usb_remove_event(const char *mount_path)
37 {
38         MS_DBG_ERR("===========================================================");
39         MS_DBG_ERR("USB REMOVED, mountpath : %s", mount_path);
40         MS_DBG_ERR("===========================================================");
41         int update_status  = -1;
42         int remain_request = 0;
43         bool status = FALSE;
44
45         if(!ms_config_get_int(VCONFKEY_FILEMANAGER_DB_STATUS, &update_status)) {
46                 MS_DBG_ERR("ms_config_get_int[VCONFKEY_FILEMANAGER_DB_STATUS]");
47         }
48
49         if (msc_get_remain_scan_request(MS_SCAN_STORAGE, &remain_request) == MS_MEDIA_ERR_NONE) {
50                 if (!(remain_request == 0 && update_status == VCONFKEY_FILEMANAGER_DB_UPDATED)) {
51                         msc_set_blocked_path(mount_path);
52                 }
53                 remain_request = 0;
54         }
55
56
57         if (msc_get_dir_scan_status(&status) == MS_MEDIA_ERR_NONE) {
58                 if (status == TRUE) {
59                         MS_DBG_ERR("Doing directory scanning. Set cancel path");
60                         msc_set_cancel_path(mount_path);
61                 }
62                 status = FALSE;
63         }
64
65         if (msc_get_remain_extract_request(MS_EXTRACT_STORAGE, &remain_request) == MS_MEDIA_ERR_NONE) {
66                 if (!(remain_request == 0 && update_status == VCONFKEY_FILEMANAGER_DB_UPDATED)) {
67                         msc_set_extract_blocked_path(mount_path);
68                 }
69                 remain_request = 0;
70         }
71
72         if (msc_get_dir_scan_status(&status) == MS_MEDIA_ERR_NONE) {
73                 if (status == true) {
74                         MS_DBG_ERR("Doing directory extracting. Set cancel path");
75                         msc_set_extract_cancel_path(mount_path);
76                 }
77                 status = FALSE;
78         }
79
80         return;
81 }
82
83 int msc_mmc_remove_handler(const char *mount_path)
84 {
85         return MS_MEDIA_ERR_NONE;
86 }
87
88 void _msc_mmc_changed_event(const char *mount_path, ms_stg_status_e mount_status)
89 {
90         /* If scanner is not working, media server executes media scanner and sends request. */
91         /* If scanner is working, it detects changing status of SD card. */
92         if (mount_status == MS_STG_INSERTED) {
93                 /*DO NOT THING*/
94         } else if (mount_status == MS_STG_REMOVED) {
95                 msc_set_mmc_status(MS_STG_REMOVED);
96                 msc_mmc_remove_handler(mount_path);
97         }
98
99         return;
100 }
101
102
103 void msc_device_block_changed_cb(ms_block_info_s *block_info, void *user_data)
104 {
105         if (block_info->block_type == 0) {
106                 MS_DBG_ERR("GET THE USB EVENT");
107                 if (block_info->state == MS_STG_INSERTED) {
108                         /*DO NOT THING*/
109                 } else {
110                         __msc_usb_remove_event(block_info->mount_path);
111                 }
112         } else {
113                 MS_DBG_ERR("GET THE MMC EVENT");
114                 _msc_mmc_changed_event(block_info->mount_path, block_info->state);
115         }
116 }