Define a macro checking feature support
[platform/core/api/runtime-info.git] / src / runtime_info_connectivity.c
1 /*
2  * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved
3  *
4  * Licensed under the Apache License, Version 2.0 (the License);
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an AS IS BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16
17 #include <stdio.h>
18 #include <stdlib.h>
19 #include <string.h>
20
21 #include <vconf.h>
22 #include <dlog.h>
23
24 #include <runtime_info.h>
25 #include <runtime_info_private.h>
26
27 #ifdef LOG_TAG
28 #undef LOG_TAG
29 #endif
30
31 #define LOG_TAG "CAPI_SYSTEM_RUNTIME_INFO"
32
33 static const char *VCONF_WIFI_STATUS = VCONFKEY_WIFI_STATE;
34 static const char *VCONF_BT_ENABLED = VCONFKEY_BT_STATUS;
35 static const char *VCONF_WIFI_HOTSPOT_ENABLED = VCONFKEY_MOBILE_HOTSPOT_MODE;
36 static const char *VCONF_BT_HOTSPOT_ENABLED = VCONFKEY_MOBILE_HOTSPOT_MODE;
37 static const char *VCONF_USB_HOTSPOT_ENABLED = VCONFKEY_MOBILE_HOTSPOT_MODE;
38 static const char *VCONF_PACKET_DATA_ENABLED = VCONFKEY_3G_ENABLE;
39 static const char *VCONF_DATA_ROAMING_ENABLED = VCONFKEY_SETAPPL_STATE_DATA_ROAMING_BOOL;
40 static const char *VCONF_GPS_STATUS = VCONFKEY_LOCATION_GPS_STATE;
41
42 int runtime_info_wifi_status_get_value(runtime_info_value_h value)
43 {
44         int vconf_value;
45         int ret;
46
47         ret = runtime_info_vconf_get_value_int(VCONF_WIFI_STATUS, &vconf_value);
48         if (ret != RUNTIME_INFO_ERROR_NONE)
49                 return ret;
50
51         switch (vconf_value) {
52         case VCONFKEY_WIFI_OFF:
53                 value->i = RUNTIME_INFO_WIFI_STATUS_DISABLED;
54                 break;
55
56         case VCONFKEY_WIFI_UNCONNECTED:
57                 value->i = RUNTIME_INFO_WIFI_STATUS_UNCONNECTED;
58                 break;
59
60         case VCONFKEY_WIFI_CONNECTED:
61         case VCONFKEY_WIFI_TRANSFER:
62                 value->i = RUNTIME_INFO_WIFI_STATUS_CONNECTED;
63                 break;
64
65         default:
66                 return RUNTIME_INFO_ERROR_IO_ERROR;
67         }
68
69         return ret;
70 }
71
72 int runtime_info_wifi_status_set_event_cb()
73 {
74         return runtime_info_vconf_set_event_cb(VCONF_WIFI_STATUS, RUNTIME_INFO_INTERNAL_KEY_WIFI_STATUS, 0);
75 }
76
77 void runtime_info_wifi_status_unset_event_cb()
78 {
79         runtime_info_vconf_unset_event_cb(VCONF_WIFI_STATUS, 0);
80 }
81
82 int runtime_info_bt_enabled_get_value(runtime_info_value_h value)
83 {
84         int vconf_value;
85         int ret;
86
87         ret = runtime_info_vconf_get_value_int(VCONF_BT_ENABLED, &vconf_value);
88         if (ret != RUNTIME_INFO_ERROR_NONE)
89                 return ret;
90
91         switch (vconf_value) {
92         case VCONFKEY_BT_STATUS_OFF:
93                 value->b = false;
94                 break;
95
96         case VCONFKEY_BT_STATUS_ON:
97         case VCONFKEY_BT_STATUS_BT_VISIBLE:
98         case VCONFKEY_BT_STATUS_TRANSFER:
99                 value->b = true;
100                 break;
101
102         default:
103                 return RUNTIME_INFO_ERROR_IO_ERROR;
104         }
105
106         return ret;
107 }
108
109 int runtime_info_bt_enabled_set_event_cb()
110 {
111         return runtime_info_vconf_set_event_cb(VCONF_BT_ENABLED, RUNTIME_INFO_KEY_BLUETOOTH_ENABLED, 0);
112 }
113
114 void runtime_info_bt_enabled_unset_event_cb()
115 {
116         runtime_info_vconf_unset_event_cb(VCONF_BT_ENABLED, 0);
117 }
118
119
120 int runtime_info_wifi_hotspot_get_value(runtime_info_value_h value)
121 {
122         int vconf_value;
123         int ret;
124
125         RETURN_ERROR_IF_NOT_SUPPORTED("http://tizen.org/feature/network.tethering.wifi");
126
127         ret = runtime_info_vconf_get_value_int(VCONF_WIFI_HOTSPOT_ENABLED, &vconf_value);
128         if (ret == RUNTIME_INFO_ERROR_NONE)
129                 value->b = (vconf_value&VCONFKEY_MOBILE_HOTSPOT_MODE_WIFI) ? true : false;
130
131         return ret;
132 }
133
134 int runtime_info_wifi_hotspot_set_event_cb()
135 {
136         return runtime_info_vconf_set_event_cb(VCONF_WIFI_HOTSPOT_ENABLED, RUNTIME_INFO_KEY_WIFI_HOTSPOT_ENABLED, 0);
137 }
138
139 void runtime_info_wifi_hotspot_unset_event_cb()
140 {
141         runtime_info_vconf_unset_event_cb(VCONF_WIFI_HOTSPOT_ENABLED, 0);
142 }
143
144 int runtime_info_bt_hotspot_get_value(runtime_info_value_h value)
145 {
146         int vconf_value;
147         int ret;
148
149         RETURN_ERROR_IF_NOT_SUPPORTED("http://tizen.org/feature/network.tethering.bluetooth");
150
151         ret = runtime_info_vconf_get_value_int(VCONF_BT_HOTSPOT_ENABLED, &vconf_value);
152         if (ret == RUNTIME_INFO_ERROR_NONE)
153                 value->b = (vconf_value&VCONFKEY_MOBILE_HOTSPOT_MODE_BT) ? true : false;
154
155         return ret;
156 }
157
158 int runtime_info_bt_hotspot_set_event_cb()
159 {
160         return runtime_info_vconf_set_event_cb(VCONF_BT_HOTSPOT_ENABLED, RUNTIME_INFO_KEY_BLUETOOTH_TETHERING_ENABLED, 0);
161 }
162
163 void runtime_info_bt_hotspot_unset_event_cb()
164 {
165         runtime_info_vconf_unset_event_cb(VCONF_BT_HOTSPOT_ENABLED, 0);
166 }
167
168 int runtime_info_usb_hotspot_get_value(runtime_info_value_h value)
169 {
170         int vconf_value;
171         int ret;
172
173         RETURN_ERROR_IF_NOT_SUPPORTED("http://tizen.org/feature/network.tethering.usb");
174
175         ret = runtime_info_vconf_get_value_int(VCONF_USB_HOTSPOT_ENABLED, &vconf_value);
176         if (ret == RUNTIME_INFO_ERROR_NONE)
177                 value->b = (vconf_value&VCONFKEY_MOBILE_HOTSPOT_MODE_USB) ? true : false;
178
179         return ret;
180 }
181
182 int runtime_info_usb_hotspot_set_event_cb()
183 {
184         return runtime_info_vconf_set_event_cb(VCONF_USB_HOTSPOT_ENABLED, RUNTIME_INFO_KEY_USB_TETHERING_ENABLED, 0);
185 }
186
187 void runtime_info_usb_hotspot_unset_event_cb()
188 {
189         runtime_info_vconf_unset_event_cb(VCONF_USB_HOTSPOT_ENABLED, 0);
190 }
191
192 int runtime_info_packet_data_get_value(runtime_info_value_h value)
193 {
194         int vconf_value;
195         int ret;
196
197         ret = runtime_info_vconf_get_value_bool(VCONF_PACKET_DATA_ENABLED, &vconf_value);
198         if (ret == RUNTIME_INFO_ERROR_NONE)
199                 value->b = (bool)vconf_value;
200
201         return ret;
202 }
203
204 int runtime_info_packet_data_set_event_cb()
205 {
206         return runtime_info_vconf_set_event_cb(VCONF_PACKET_DATA_ENABLED, RUNTIME_INFO_KEY_PACKET_DATA_ENABLED, 0);
207 }
208
209 void runtime_info_packet_data_unset_event_cb()
210 {
211         runtime_info_vconf_unset_event_cb(VCONF_PACKET_DATA_ENABLED, 0);
212 }
213
214 int runtime_info_data_roaming_get_value(runtime_info_value_h value)
215 {
216         int vconf_value;
217         int ret;
218
219         ret = runtime_info_vconf_get_value_bool(VCONF_DATA_ROAMING_ENABLED, &vconf_value);
220         if (ret == RUNTIME_INFO_ERROR_NONE)
221                 value->b = (bool)vconf_value;
222
223         return ret;
224 }
225
226 int runtime_info_data_roaming_set_event_cb()
227 {
228         return runtime_info_vconf_set_event_cb(VCONF_DATA_ROAMING_ENABLED, RUNTIME_INFO_KEY_DATA_ROAMING_ENABLED, 0);
229 }
230
231 void runtime_info_data_roaming_unset_event_cb()
232 {
233         runtime_info_vconf_unset_event_cb(VCONF_DATA_ROAMING_ENABLED, 0);
234 }
235
236 int runtime_info_gps_status_get_value(runtime_info_value_h value)
237 {
238         int vconf_value;
239         int ret;
240
241         ret = runtime_info_vconf_get_value_int(VCONF_GPS_STATUS, &vconf_value);
242         if (ret != RUNTIME_INFO_ERROR_NONE)
243                 return ret;
244
245         switch (vconf_value) {
246         case VCONFKEY_LOCATION_GPS_OFF:
247                 value->i = RUNTIME_INFO_GPS_STATUS_DISABLED;
248                 break;
249
250         case VCONFKEY_LOCATION_GPS_SEARCHING:
251                 value->i = RUNTIME_INFO_GPS_STATUS_SEARCHING;
252                 break;
253
254         case VCONFKEY_LOCATION_GPS_CONNECTED:
255                 value->i = RUNTIME_INFO_GPS_STATUS_CONNECTED;
256                 break;
257
258         default:
259                 return RUNTIME_INFO_ERROR_IO_ERROR;
260         }
261
262         return ret;
263 }
264
265 int runtime_info_gps_status_set_event_cb()
266 {
267         return runtime_info_vconf_set_event_cb(VCONF_GPS_STATUS, RUNTIME_INFO_KEY_GPS_STATUS, 0);
268 }
269
270 void runtime_info_gps_status_unset_event_cb()
271 {
272         runtime_info_vconf_unset_event_cb(VCONF_GPS_STATUS, 0);
273 }
274