]> err.no Git - mapper/blobdiff - src/iap.c
Include settings.h so the banner macro hildon version works.
[mapper] / src / iap.c
index 1125aa49fe21f30e51beae0ec3a34a15248bb36c..61d243be517e89889093eb51fea772966451e8a8 100644 (file)
--- a/src/iap.c
+++ b/src/iap.c
@@ -1,70 +1,98 @@
+/*
+ * This file is part of mapper
+ *
+ * Copyright (C) 2007 Kaj-Michael Lang
+ * Copyright (C) 2006-2007 John Costigan.
+ *
+ * POI and GPS-Info code originally written by Cezary Jackiewicz.
+ *
+ * Default map data provided by http://www.openstreetmap.org/
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ */
+
 #include <config.h>
 
-#ifdef WITH_HILDON
+#include <glib.h>
 
+#ifdef WITH_OSSO
 #include <libosso.h>
-#include <osso-helplib.h>
-#include <osso-ic-dbus.h>
+
+#ifdef WITH_OSSO_IC
 #include <osso-ic.h>
+#include <osso-ic-dbus.h>
+#endif
+
+#ifdef WITH_CONIC
+#include <conic.h>
+#endif
 
 #include "iap.h"
-#include "map.h"
+#include "map-download.h"
 #include "gps.h"
+#include "config-gconf.h"
 
 gboolean iap_connecting=FALSE;
-gboolean iap_connected=TRUE;
+gboolean iap_connected=FALSE;
+
+/*************************************************************/
 
-void iap_callback(struct iap_event_t *event, void *arg)
+/**
+ * Old OSSO IC 
+ */
+#ifdef WITH_OSSO_IC
+
+void 
+iap_callback(struct iap_event_t *event, void *arg)
 {
-       printf("%s()\n", __PRETTY_FUNCTION__);
-       iap_connecting = FALSE;
-       if (event->type == OSSO_IAP_CONNECTED && !iap_connected) {
-               iap_connected = TRUE;
-               config_update_proxy();
-               if (!_curl_sid)
-                       _curl_sid = g_timeout_add(100,
-                                                 (GSourceFunc)
-                                                 curl_download_timeout, NULL);
-       }
-       vprintf("%s(): return\n", __PRETTY_FUNCTION__);
+iap_connecting = FALSE;
+if (event->type == OSSO_IAP_CONNECTED && !iap_connected) {
+       iap_connected = TRUE;
+       config_update_proxy();
+       if (!_curl_sid)
+               _curl_sid = g_timeout_add(100, (GSourceFunc)map_download_timeout, NULL);
+}
 }
 
 DBusHandlerResult
-get_connection_status_signal_cb(DBusConnection * connection,
-                               DBusMessage * message, void *user_data)
+get_connection_status_signal_cb(DBusConnection * connection, DBusMessage * message, void *user_data)
 {
-       gchar *iap_name = NULL, *iap_nw_type = NULL, *iap_state = NULL;
-       printf("%s()\n", __PRETTY_FUNCTION__);
-
-       /* check signal */
-       if (!dbus_message_is_signal(message,
-                                   ICD_DBUS_INTERFACE,
-                                   ICD_STATUS_CHANGED_SIG)) {
-               vprintf("%s(): return DBUS_HANDLER_RESULT_NOT_YET_HANDLED\n",
-                       __PRETTY_FUNCTION__);
-               return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
-       }
+gchar *iap_name = NULL, *iap_nw_type = NULL, *iap_state = NULL;
+
+/* check signal */
+if (!dbus_message_is_signal(message, ICD_DBUS_INTERFACE, ICD_STATUS_CHANGED_SIG)) {
+       g_printf("%s(): return DBUS_HANDLER_RESULT_NOT_YET_HANDLED\n", __PRETTY_FUNCTION__);
+       return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
+}
 
-       if (!dbus_message_get_args(message, NULL,
-                                  DBUS_TYPE_STRING, &iap_name,
-                                  DBUS_TYPE_STRING, &iap_nw_type,
-                                  DBUS_TYPE_STRING, &iap_state,
-                                  DBUS_TYPE_INVALID)) {
-               vprintf("%s(): return DBUS_HANDLER_RESULT_NOT_YET_HANDLED\n",
-                       __PRETTY_FUNCTION__);
+if (!dbus_message_get_args(message, NULL,
+                  DBUS_TYPE_STRING, &iap_name,
+                  DBUS_TYPE_STRING, &iap_nw_type,
+                  DBUS_TYPE_STRING, &iap_state,
+                  DBUS_TYPE_INVALID)) {
+               g_printf("%s(): return DBUS_HANDLER_RESULT_NOT_YET_HANDLED\n", __PRETTY_FUNCTION__);
                return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
-       }
+}
 
-       printf("  > iap_state = %s\n", iap_state);
-       if (!strcmp(iap_state, "CONNECTED")) {
-               if (!iap_connected) {
-                       iap_connected = TRUE;
-                       config_update_proxy();
-                       if (!_curl_sid)
-                               _curl_sid = g_timeout_add(100,
-                                                         (GSourceFunc)
-                                                         curl_download_timeout,
-                                                         NULL);
+g_printf("  > iap_state = %s\n", iap_state);
+if (!strcmp(iap_state, "CONNECTED")) {
+       if (!iap_connected) {
+               iap_connected = TRUE;
+               config_update_proxy();
+               if (!_curl_sid)
+                       _curl_sid = g_timeout_add(100, (GSourceFunc)map_download_timeout, NULL);
                }
        } else if (iap_connected) {
                iap_connected = FALSE;
@@ -73,27 +101,108 @@ get_connection_status_signal_cb(DBusConnection * connection,
                        _curl_sid = 0;
                }
        }
-
-       vprintf("%s(): return DBUS_HANDLER_RESULT_HANDLED\n",
-               __PRETTY_FUNCTION__);
-       return DBUS_HANDLER_RESULT_HANDLED;
+g_printf("%s(): return DBUS_HANDLER_RESULT_HANDLED\n", __PRETTY_FUNCTION__);
+return DBUS_HANDLER_RESULT_HANDLED;
 }
 
-void
+gboolean
 iap_connect(void) 
 {
 if (!iap_connected && !iap_connecting) {
        iap_connecting = TRUE;
        osso_iap_connect(OSSO_IAP_ANY, OSSO_IAP_REQUESTED_CONNECT, NULL);
+       return TRUE;
+}
+return FALSE;
+}
+
+gboolean
+iap_is_connected(void)
+{
+return iap_connected;
+}
+
+#endif
+
+/*************************************************************/
+/*
+ * libconic
+ *
+ */
+
+#ifdef WITH_CONIC
+static ConIcConnection *connection=NULL;
+
+static void 
+iap_connection_cb(ConIcConnection *connection, ConIcConnectionEvent *event, gpointer user_data)
+{
+ConIcConnectionStatus status;
+ConIcConnectionError error;
+
+g_assert(CON_IC_IS_CONNECTION_EVENT(event));
+
+status=con_ic_connection_event_get_status(event);
+
+switch (status) {
+       case CON_IC_STATUS_CONNECTED:
+               g_printf("Connected\n");
+               iap_connected=TRUE;
+               iap_connecting=FALSE;
+       break;
+        case CON_IC_STATUS_DISCONNECTED:
+               g_printf("Disconnected\n");
+               iap_connected=FALSE;
+               iap_connecting=FALSE;
+       break;
+        case CON_IC_STATUS_DISCONNECTING:
+               g_printf("Disconnecting\n");
+               iap_connecting=FALSE;
+       break;
+        default:
+       break;
+}
+
+}
+
+gboolean
+iap_connect(void)
+{
+if (connection==NULL) {
+       connection=con_ic_connection_new();
+       g_signal_connect(G_OBJECT(connection), "connection-event", G_CALLBACK(iap_connection_cb), NULL);
 }
+if (iap_connecting==TRUE)
+       return TRUE;
+g_printf("Requesting connection\n");
+iap_connecting=TRUE;
+return con_ic_connection_connect(connection, CON_IC_CONNECT_FLAG_NONE);
 }
 
 gboolean
 iap_is_connected(void)
 {
+#ifdef MAEMO_SDK_DEBUG
+g_printerr("SDK: Assuming connection is ok.\n");
+return TRUE;
+#endif
 return iap_connected;
 }
 
+#endif
+
 #else
+/* !WITH_OSSO */
+
+gboolean
+iap_connect(void)
+{
+return TRUE;
+}
+
+gboolean
+iap_is_connected(void)
+{
+return TRUE;
+}
 
 #endif