]> err.no Git - mapper/blob - src/iap.c
Add header and cast properly.
[mapper] / src / iap.c
1 /*
2  * This file is part of mapper
3  *
4  * Copyright (C) 2007 Kaj-Michael Lang
5  * Copyright (C) 2006-2007 John Costigan.
6  *
7  * POI and GPS-Info code originally written by Cezary Jackiewicz.
8  *
9  * Default map data provided by http://www.openstreetmap.org/
10  *
11  * This program is free software; you can redistribute it and/or modify
12  * it under the terms of the GNU General Public License as published by
13  * the Free Software Foundation; either version 2 of the License, or
14  * (at your option) any later version.
15  *
16  * This program is distributed in the hope that it will be useful,
17  * but WITHOUT ANY WARRANTY; without even the implied warranty of
18  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
19  * GNU General Public License for more details.
20  *
21  * You should have received a copy of the GNU General Public License along
22  * with this program; if not, write to the Free Software Foundation, Inc.,
23  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
24  */
25
26 #include <config.h>
27
28 #include <glib.h>
29
30 #ifdef WITH_OSSO
31 #include <libosso.h>
32
33 #ifdef WITH_OSSO_IC
34 #include <osso-ic.h>
35 #include <osso-ic-dbus.h>
36 #endif
37
38 #ifdef WITH_CONIC
39 #include <conic.h>
40 #endif
41
42 #include "iap.h"
43 #include "map-download.h"
44 #include "gps.h"
45 #include "config-gconf.h"
46
47 gboolean iap_connecting=FALSE;
48 gboolean iap_connected=FALSE;
49
50 /*************************************************************/
51
52 /**
53  * Old OSSO IC 
54  */
55 #ifdef WITH_OSSO_IC
56
57 void 
58 iap_callback(struct iap_event_t *event, void *arg)
59 {
60 iap_connecting = FALSE;
61 if (event->type == OSSO_IAP_CONNECTED && !iap_connected) {
62         iap_connected = TRUE;
63         config_update_proxy();
64         if (!_curl_sid)
65                 _curl_sid = g_timeout_add(100, (GSourceFunc)map_download_timeout, NULL);
66 }
67 }
68
69 DBusHandlerResult
70 get_connection_status_signal_cb(DBusConnection * connection, DBusMessage * message, void *user_data)
71 {
72 gchar *iap_name = NULL, *iap_nw_type = NULL, *iap_state = NULL;
73
74 /* check signal */
75 if (!dbus_message_is_signal(message, ICD_DBUS_INTERFACE, ICD_STATUS_CHANGED_SIG)) {
76         g_printf("%s(): return DBUS_HANDLER_RESULT_NOT_YET_HANDLED\n", __PRETTY_FUNCTION__);
77         return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
78 }
79
80 if (!dbus_message_get_args(message, NULL,
81                    DBUS_TYPE_STRING, &iap_name,
82                    DBUS_TYPE_STRING, &iap_nw_type,
83                    DBUS_TYPE_STRING, &iap_state,
84                    DBUS_TYPE_INVALID)) {
85                 g_printf("%s(): return DBUS_HANDLER_RESULT_NOT_YET_HANDLED\n", __PRETTY_FUNCTION__);
86                 return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
87 }
88
89 g_printf("  > iap_state = %s\n", iap_state);
90 if (!strcmp(iap_state, "CONNECTED")) {
91         if (!iap_connected) {
92                 iap_connected = TRUE;
93                 config_update_proxy();
94                 if (!_curl_sid)
95                         _curl_sid = g_timeout_add(100, (GSourceFunc)map_download_timeout, NULL);
96                 }
97         } else if (iap_connected) {
98                 iap_connected = FALSE;
99                 if (_curl_sid) {
100                         g_source_remove(_curl_sid);
101                         _curl_sid = 0;
102                 }
103         }
104 g_printf("%s(): return DBUS_HANDLER_RESULT_HANDLED\n", __PRETTY_FUNCTION__);
105 return DBUS_HANDLER_RESULT_HANDLED;
106 }
107
108 gboolean
109 iap_connect(void) 
110 {
111 if (!iap_connected && !iap_connecting) {
112         iap_connecting = TRUE;
113         osso_iap_connect(OSSO_IAP_ANY, OSSO_IAP_REQUESTED_CONNECT, NULL);
114         return TRUE;
115 }
116 return FALSE;
117 }
118
119 gboolean
120 iap_is_connected(void)
121 {
122 return iap_connected;
123 }
124
125 #endif
126
127 /*************************************************************/
128 /*
129  * libconic
130  *
131  */
132
133 #ifdef WITH_CONIC
134 static ConIcConnection *connection=NULL;
135
136 static void 
137 iap_connection_cb(ConIcConnection *connection, ConIcConnectionEvent *event, gpointer user_data)
138 {
139 ConIcConnectionStatus status;
140 ConIcConnectionError error;
141
142 g_assert(CON_IC_IS_CONNECTION_EVENT(event));
143
144 status=con_ic_connection_event_get_status(event);
145
146 switch (status) {
147         case CON_IC_STATUS_CONNECTED:
148                 g_printf("Connected\n");
149                 iap_connected=TRUE;
150                 iap_connecting=FALSE;
151         break;
152         case CON_IC_STATUS_DISCONNECTED:
153                 g_printf("Disconnected\n");
154                 iap_connected=FALSE;
155                 iap_connecting=FALSE;
156         break;
157         case CON_IC_STATUS_DISCONNECTING:
158                 g_printf("Disconnecting\n");
159                 iap_connecting=FALSE;
160         break;
161         default:
162         break;
163 }
164
165 }
166
167 gboolean
168 iap_connect(void)
169 {
170 if (connection==NULL) {
171         connection=con_ic_connection_new();
172         g_signal_connect(G_OBJECT(connection), "connection-event", G_CALLBACK(iap_connection_cb), NULL);
173 }
174 if (iap_connecting==TRUE)
175         return TRUE;
176 g_printf("Requesting connection\n");
177 iap_connecting=TRUE;
178 return con_ic_connection_connect(connection, CON_IC_CONNECT_FLAG_NONE);
179 }
180
181 gboolean
182 iap_is_connected(void)
183 {
184 #ifdef MAEMO_SDK_DEBUG
185 g_printerr("SDK: Assuming connection is ok.\n");
186 return TRUE;
187 #endif
188 return iap_connected;
189 }
190
191 #endif
192
193 #else
194 /* !WITH_OSSO */
195
196 gboolean
197 iap_connect(void)
198 {
199 return TRUE;
200 }
201
202 gboolean
203 iap_is_connected(void)
204 {
205 return TRUE;
206 }
207
208 #endif