]> err.no Git - mapper/blob - src/iap.c
Include glib.h
[mapper] / src / iap.c
1 #include <config.h>
2
3 #include <glib.h>
4
5 #ifdef WITH_OSSO
6 #include <libosso.h>
7
8 #ifdef WITH_OSSO_IC
9 #include <osso-ic.h>
10 #include <osso-ic-dbus.h>
11 #endif
12
13 #ifdef WITH_CONIC
14 #include <conic.h>
15 #endif
16
17 #include "iap.h"
18 #include "map-download.h"
19 #include "gps.h"
20 #include "config-gconf.h"
21
22 gboolean iap_connecting=FALSE;
23 gboolean iap_connected=FALSE;
24
25 /*************************************************************/
26
27 /**
28  * Old OSSO IC 
29  */
30 #ifdef WITH_OSSO_IC
31
32 void 
33 iap_callback(struct iap_event_t *event, void *arg)
34 {
35 iap_connecting = FALSE;
36 if (event->type == OSSO_IAP_CONNECTED && !iap_connected) {
37         iap_connected = TRUE;
38         config_update_proxy();
39         if (!_curl_sid)
40                 _curl_sid = g_timeout_add(100, (GSourceFunc)map_download_timeout, NULL);
41 }
42 }
43
44 DBusHandlerResult
45 get_connection_status_signal_cb(DBusConnection * connection, DBusMessage * message, void *user_data)
46 {
47 gchar *iap_name = NULL, *iap_nw_type = NULL, *iap_state = NULL;
48
49 /* check signal */
50 if (!dbus_message_is_signal(message, ICD_DBUS_INTERFACE, ICD_STATUS_CHANGED_SIG)) {
51         g_printf("%s(): return DBUS_HANDLER_RESULT_NOT_YET_HANDLED\n", __PRETTY_FUNCTION__);
52         return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
53 }
54
55 if (!dbus_message_get_args(message, NULL,
56                    DBUS_TYPE_STRING, &iap_name,
57                    DBUS_TYPE_STRING, &iap_nw_type,
58                    DBUS_TYPE_STRING, &iap_state,
59                    DBUS_TYPE_INVALID)) {
60                 g_printf("%s(): return DBUS_HANDLER_RESULT_NOT_YET_HANDLED\n", __PRETTY_FUNCTION__);
61                 return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
62 }
63
64 g_printf("  > iap_state = %s\n", iap_state);
65 if (!strcmp(iap_state, "CONNECTED")) {
66         if (!iap_connected) {
67                 iap_connected = TRUE;
68                 config_update_proxy();
69                 if (!_curl_sid)
70                         _curl_sid = g_timeout_add(100, (GSourceFunc)map_download_timeout, NULL);
71                 }
72         } else if (iap_connected) {
73                 iap_connected = FALSE;
74                 if (_curl_sid) {
75                         g_source_remove(_curl_sid);
76                         _curl_sid = 0;
77                 }
78         }
79 g_printf("%s(): return DBUS_HANDLER_RESULT_HANDLED\n", __PRETTY_FUNCTION__);
80 return DBUS_HANDLER_RESULT_HANDLED;
81 }
82
83 gboolean
84 iap_connect(void) 
85 {
86 if (!iap_connected && !iap_connecting) {
87         iap_connecting = TRUE;
88         osso_iap_connect(OSSO_IAP_ANY, OSSO_IAP_REQUESTED_CONNECT, NULL);
89         return TRUE;
90 }
91 return FALSE;
92 }
93
94 gboolean
95 iap_is_connected(void)
96 {
97 return iap_connected;
98 }
99
100 #endif
101
102 #ifdef WITH_CONIC
103
104 static ConIcConnection *connection=NULL;
105
106 static void 
107 iap_connection_cb(ConIcConnection *connection, ConIcConnectionEvent *event, gpointer user_data)
108 {
109 ConIcConnectionStatus status;
110 ConIcConnectionError error;
111
112 g_assert(CON_IC_IS_CONNECTION_EVENT(event));
113
114 status=con_ic_connection_event_get_status(event);
115
116 switch (status) {
117         case CON_IC_STATUS_CONNECTED:
118                 g_printf("Connected\n");
119                 iap_connected=TRUE;
120                 iap_connecting=FALSE;
121         break;
122         case CON_IC_STATUS_DISCONNECTED:
123                 g_printf("Disconnected\n");
124                 iap_connected=FALSE;
125                 iap_connecting=FALSE;
126         break;
127         case CON_IC_STATUS_DISCONNECTING:
128                 g_printf("Disconnecting\n");
129                 iap_connecting=FALSE;
130         break;
131         default:
132         break;
133 }
134
135 }
136
137 gboolean
138 iap_connect(void)
139 {
140 if (connection==NULL) {
141         connection=con_ic_connection_new();
142         g_signal_connect(G_OBJECT(connection), "connection-event", G_CALLBACK(iap_connection_cb), NULL);
143 }
144 if (iap_connecting==TRUE)
145         return TRUE;
146 g_printf("Requesting connection\n");
147 iap_connecting=TRUE;
148 return con_ic_connection_connect(connection, CON_IC_CONNECT_FLAG_NONE);
149 }
150
151 gboolean
152 iap_is_connected(void)
153 {
154 return iap_connected;
155 }
156
157 #endif
158
159 #else
160 /* !WITH_OSSO */
161
162 gboolean
163 iap_connect(void)
164 {
165 return TRUE;
166 }
167
168 gboolean
169 iap_is_connected(void)
170 {
171 return TRUE;
172 }
173
174 #endif