Remove Tapi dependendy
[platform/core/connectivity/data-router.git] / src / dr-noti-handler.c
1 /*
2  * Data-Router
3  *
4  * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
5  *
6  * Contact:  Hocheol Seo <hocheol.seo@samsung.com>
7  *               Injun Yang <injun.yang@samsung.com>
8  *
9  * Licensed under the Apache License, Version 2.0 (the "License");
10  * you may not use this file except in compliance with the License.
11  * You may obtain a copy of the License at
12  *
13  *              http://www.apache.org/licenses/LICENSE-2.0
14  *
15  * Unless required by applicable law or agreed to in writing, software
16  * distributed under the License is distributed on an "AS IS" BASIS,
17  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18  * See the License for the specific language governing permissions and
19  * limitations under the License.
20  *
21  */
22
23
24 #include <glib.h>
25 #include <sys/wait.h>
26
27 #include "dr-main.h"
28 #include "dr-usb.h"
29 #include "dr-modem.h"
30 #include "dr-common.h"
31
32
33
34 #define ACM_WAIT_TIME 300000
35
36 extern dr_info_t dr_info;
37 volatile gboolean dsr_status = FALSE;
38
39 static void __usb_status_noti_handler(void *data)
40 {
41         int usb_state = -1;
42         int usb_mode = -1;
43         int ret;
44
45         if (_get_usb_state(&usb_state) < 0) {
46                 ERR(" Unable to get usb status !\n");
47                 return;
48         }
49
50         ret = vconf_get_int(VCONFKEY_SETAPPL_USB_MODE_INT, &usb_mode);
51         if (ret != 0) {
52                 DBG("Vconf get failed\n");
53                 return;
54         }
55
56         DBG("USB noti handler, USB state : %d, Mode : %d\n", usb_state, usb_mode);
57         DBG("usb_fd = 0x%x\n", dr_info.usb.usb_fd);
58
59
60         /*
61          * If USB driver builted in the Kernel, VCONFKEY_SYSMAN_USB_CONNECTED is not used.
62          * If USB driver loaded in DR/MTP then need to check VCONFKEY_SYSMAN_USB_CONNECTED.
63          * After usb driver loaded, MTP will be set vconf value as VCONFKEY_SYSMAN_USB_CONNECTED
64          */
65         if (usb_state != VCONFKEY_SYSMAN_USB_DISCONNECTED &&
66                 usb_mode == SETTING_USB_DEFAULT_MODE) {
67                 _init_usb();
68         } else if (usb_state == VCONFKEY_SYSMAN_USB_DISCONNECTED) {
69                 _deinit_usb();
70                 _deinit_dr();
71         }
72         return;
73 }
74
75 static void __usb_mode_noti_handler(void *data)
76 {
77         int usb_state = -1;
78         int usb_mode = -1;
79         int ret;
80
81         ret = vconf_get_int(VCONFKEY_SETAPPL_USB_MODE_INT, &usb_mode);
82         if (ret != 0) {
83                 DBG("Vconf get failed\n");
84                 return;
85         }
86
87         DBG("USB Mode noti handler, USB  Mode : %d\n", usb_mode);
88         DBG("usb_fd = 0x%x\n", dr_info.usb.usb_fd);
89
90         if (usb_mode != SETTING_USB_DEFAULT_MODE) {
91                 _deinit_usb();
92                 _deinit_dr();
93         }
94
95         return;
96 }
97
98
99 gboolean _register_vconf_notification(void)
100 {
101         int ret;
102
103         ret =
104             vconf_notify_key_changed(VCONFKEY_SYSMAN_USB_STATUS, (vconf_callback_fn) __usb_status_noti_handler, NULL);
105         if (ret < 0) {
106                 ERR("Error !!! VCONFKEY reg noti  : %s\n", VCONFKEY_SYSMAN_USB_STATUS);
107         }
108
109         ret =
110             vconf_notify_key_changed(VCONFKEY_SETAPPL_USB_MODE_INT,
111                                      (vconf_callback_fn) __usb_mode_noti_handler, NULL);
112         if (ret < 0) {
113                 ERR("Error !!! VCONFKEY reg noti  : %s\n", VCONFKEY_SETAPPL_USB_MODE_INT);
114         }
115
116         return TRUE;
117 }
118
119 void _unregister_vconf_notification(void)
120 {
121         vconf_ignore_key_changed(VCONFKEY_SYSMAN_USB_STATUS, (vconf_callback_fn) __usb_status_noti_handler);
122         vconf_ignore_key_changed(VCONFKEY_SETAPPL_USB_MODE_INT, (vconf_callback_fn) __usb_mode_noti_handler);
123         return;
124 }
125
126 gboolean _register_telephony_event(void)
127 {
128         return TRUE;
129 }
130
131 void _unregister_telephony_event(void)
132 {
133         return;
134 }
135