]> err.no Git - mapper/commitdiff
Remodelling of GPS handling for hildon. Work in progress still.
authorKaj-Michael Lang <milang@onion.tal.org>
Sat, 26 Jan 2008 13:40:57 +0000 (15:40 +0200)
committerKaj-Michael Lang <milang@onion.tal.org>
Sat, 26 Jan 2008 13:40:57 +0000 (15:40 +0200)
12 files changed:
src/gps-bluetooth-maemo.c [moved from src/gps-bluetooth-hildon.c with 70% similarity]
src/gps-conn.c
src/gps.c
src/gps.h
src/map.c
src/mapper-types.h
src/mapper.c
src/osm-db.c
src/osm-db.h
src/settings.h
src/ui-common.c
src/ui-common.h

similarity index 70%
rename from src/gps-bluetooth-hildon.c
rename to src/gps-bluetooth-maemo.c
index 50337d89939322e64890031ce17796d3ae7abca7..ab87909080b7d0c1b4845200a4bcba1dc5c9c828 100644 (file)
 #include "hildon-mapper.h"
 
 #include "mapper.h"
-#include "bt-maemo-marshal.h"
-#include "bt.h"
+#include "gps-bluetooth-maemo-marshal.h"
 #include "gps.h"
 #include "settings.h"
 #include "ui-common.h"
 #include "gps-conn.h"
-
-void
-gps_connect_response(DBusGProxy * proxy, DBusGProxyCall * call_id)
-{
-GError *error = NULL;
-gchar *fdpath = NULL;
-
-if (_gps->io.conn==RCVR_DOWN && _gps->io.address) {
-       if (!dbus_g_proxy_end_call(_gps->io.rfcomm_req_proxy, call_id, &error, G_TYPE_STRING, &fdpath, G_TYPE_INVALID)) {
-               if (error->domain == DBUS_GERROR && error->code == DBUS_GERROR_REMOTE_EXCEPTION) {
-                       /* If we're already connected, it's not an error, unless
-                        * they don't give us the file descriptor path, in which
-                        * case we re-connect.*/
-                       if (!strcmp(BTCOND_ERROR_CONNECTED, dbus_g_error_get_name(error)) || !fdpath) {
-                               GtkWidget *confirm;
-                               printf("Caught remote method exception %s: %s", dbus_g_error_get_name(error), error->message);
-                               gps_disconnect(_gps);
-
-                               /* Ask user to re-connect. */
-                               confirm = hildon_note_new_confirmation(GTK_WINDOW(_window), _("Failed to connect to GPS receiver. Retry?"));
-
-                               if (GTK_RESPONSE_OK == gtk_dialog_run(GTK_DIALOG(confirm)))
-                                       gps_connect_later();    /* Try again later. */
-                               else {
-                                       gps_conn_set_state(RCVR_OFF);
-                                       _enable_gps=FALSE;
-                                       set_action_activate("gps_enabled", !_enable_gps);
-                               }
-
-                               gtk_widget_destroy(confirm);
-                               return;
-                       }
-               } else {
-                       /* Unknown error. */
-                       g_printerr("Error: %s\n", error->message);
-                       gps_disconnect(_gps);
-                       gps_connect_later(_gps);        /* Try again later. */
-                       return;
-               }
-       }
-       gps_connect_fd(fdpath);
-}
-/* else { Looks like the middle of a disconnect.  Do nothing. } */
-}
+#include "bluetooth-scan.h"
 
 /**
  * Bluetooth device scanning functions below
index 6a37a1e2bb39fe80b150ad8b989b874fb032b47d..d7f84de653f775de40a18dc585251211167ee187 100644 (file)
@@ -57,6 +57,8 @@ gps_conn_set_state(Gps *gps, GpsConnState new_conn_state)
 {
 switch (gps->io.conn=new_conn_state) {
        case RCVR_OFF:
+               _enable_gps=FALSE;
+               set_action_activate("gps_enabled", !_enable_gps);
        case RCVR_FIXED:
                if (connect_banner) {
                        gtk_widget_destroy(connect_banner);
index 274b62afcfdf50346c4308a384c7e112a0de2105..06c9ac9a711cd31739e453162a7a6c90e0609294 100644 (file)
--- a/src/gps.c
+++ b/src/gps.c
@@ -36,6 +36,8 @@
 #include <errno.h>
 #include <sys/wait.h>
 #include <glib/gstdio.h>
+#include <dbus/dbus.h>
+#include <dbus/dbus-glib.h>
 #include <fcntl.h>
 
 #include "gps.h"
 #include "gps-conn.h"
 #include "track.h"
 
+#ifdef WITH_HILDON_DBUS_BT
+#include <bt-dbus.h>
+#endif
+
 #ifdef WITH_GPSBT
 #include <gpsbt.h>
 static gpsbt_t ctx = {0};
@@ -54,7 +60,7 @@ static gboolean gps_channel_cb_error(GIOChannel *src, GIOCondition condition, gp
 static gboolean gps_channel_cb_input(GIOChannel *src, GIOCondition condition, gpointer data);
 static gboolean gps_channel_cb_connect(GIOChannel * src, GIOCondition condition, gpointer data);
 static gboolean gps_connect_socket(Gps *gps);
-static gboolean gps_connect_file(Gps *gps);
+static gboolean gps_connect_file(Gps *gps, gchar *file);
 
 #define GPSD_NMEA "r+\r\n"
 #define GPSD_PORT (2947)
@@ -75,6 +81,8 @@ gps->io.type=type;
 gps->io.conn=RCVR_OFF;
 gps->data.lat=60.20;
 gps->data.lon=22.20;
+gps->connection_error=NULL;
+gps->connection_retry=NULL;
 gps_data_integerize(&gps->data);
 return gps;
 }
@@ -119,6 +127,47 @@ gpsdata->vel_offsetx=(gint)(floor(gpsdata->speed*sin(tmp)+0.5f));
 gpsdata->vel_offsety=-(gint)(floor(gpsdata->speed*cos(tmp)+0.5f));
 }
 
+#ifdef WITH_HILDON_DBUS_BT
+void
+gps_connect_response(DBusGProxy *proxy, DBusGProxyCall *call_id, Gps *gps)
+{
+GError *error = NULL;
+gchar *fdpath = NULL;
+
+if (gps->io.conn==RCVR_DOWN && gps->io.address) {
+       if (!dbus_g_proxy_end_call(gps->io.rfcomm_req_proxy, call_id, &error, G_TYPE_STRING, &fdpath, G_TYPE_INVALID)) {
+               if (error->domain == DBUS_GERROR && error->code == DBUS_GERROR_REMOTE_EXCEPTION) {
+                       /* If we're already connected, it's not an error, unless
+                        * they don't give us the file descriptor path, in which
+                        * case we re-connect.*/
+                       if (!strcmp(BTCOND_ERROR_CONNECTED, dbus_g_error_get_name(error)) || !fdpath) {
+                               g_printerr("Caught remote method exception %s: %s", dbus_g_error_get_name(error), error->message);
+                               gps_disconnect(gps);
+
+                               if (gps->connection_retry==NULL)
+                                       return;
+
+                               if (gps->connection_retry(gps, error->message)==TRUE) {
+                                       gps_connect_later(gps);
+                               } else {
+                                       gps_conn_set_state(gps, RCVR_OFF);
+                               }
+                               return;
+                       }
+               } else {
+                       /* Unknown error. */
+                       g_printerr("Error: %s\n", error->message);
+                       gps_disconnect(_gps);
+                       gps_connect_later(_gps);        /* Try again later. */
+                       return;
+               }
+       }
+       gps_connect_fd(fdpath);
+}
+/* else { Looks like the middle of a disconnect.  Do nothing. } */
+}
+#endif
+
 /**
  * Place a request to connect about 1 second after the function is called.
  */
@@ -135,7 +184,7 @@ gps_connect(Gps *gps)
 {
 switch (gps->io.type) {
        case GPS_IO_FILE:
-               return gps_connect_file(gps);
+               return TRUE;
        break;
        case GPS_IO_RFCOMM:
        case GPS_IO_TCP:
@@ -155,11 +204,12 @@ return FALSE;
  * Helper to open a file or device node
  */
 static gboolean 
-gps_connect_file(Gps *gps)
+gps_connect_file(Gps *gps, gchar *file)
 {
-if (-1==(gps->io.fd=open(gps->io.address, O_RDONLY))) {
+if (-1==(gps->io.fd=open(file, O_RDONLY))) {
        gps_disconnect(gps);
        gps_connect_later(gps);
+       /* Add retry cb */
        return FALSE;
 }
 return TRUE;
@@ -275,18 +325,17 @@ if (gps->io.type==GPS_IO_GPSD) {
 
 #ifdef WITH_HILDON_DBUS_BT
 if (gps->io.type==GPS_IO_HILDON_DBUS && gps->io.rfcomm_req_proxy) {
-               GError *error = NULL;
+       GError *error = NULL;
 
-               dbus_g_proxy_call(gps->io.rfcomm_req_proxy, BTCOND_RFCOMM_CANCEL_CONNECT_REQ, &error, G_TYPE_STRING, gps->io.address, G_TYPE_STRING, "SPP", G_TYPE_INVALID, G_TYPE_INVALID);
-               error = NULL;
-               dbus_g_proxy_call(gps->io.rfcomm_req_proxy,     BTCOND_RFCOMM_DISCONNECT_REQ, &error,G_TYPE_STRING, gps->io.address, G_TYPE_STRING, "SPP", G_TYPE_INVALID, G_TYPE_INVALID);
+       dbus_g_proxy_call(gps->io.rfcomm_req_proxy, BTCOND_RFCOMM_CANCEL_CONNECT_REQ, &error, G_TYPE_STRING, gps->io.address, G_TYPE_STRING, "SPP", G_TYPE_INVALID, G_TYPE_INVALID);
+       error = NULL;
+       dbus_g_proxy_call(gps->io.rfcomm_req_proxy, BTCOND_RFCOMM_DISCONNECT_REQ, &error,G_TYPE_STRING, gps->io.address, G_TYPE_STRING, "SPP", G_TYPE_INVALID, G_TYPE_INVALID);
 }
 #endif
 
 #ifdef WITH_BLUEZ_DBUS_BT
 if (gps->io.type==GPS_IO_BLUEZ_DBUS && gps->io.rfcomm_req_proxy) {
        GError *error = NULL;
-
        
 }
 #endif
@@ -371,6 +420,8 @@ gps->io.clater_sid=0;
 gboolean 
 gps_connect_now(Gps *gps)
 {
+GError *error = NULL;
+
 g_assert(gps);
 g_debug("GPS: Connecting GPS type %d to %s:%d\n", gps->io.type, gps->io.address, gps->io.port);
 
@@ -378,10 +429,8 @@ switch (gps->io.type) {
        case GPS_IO_FILE:
                if (!gps->io.address)
                        return FALSE;
-               if (*gps->io.address=='/')
-                       gps->io.fd=open(gps->io.address, O_RDONLY);
-               else
-                       return FALSE;
+               gps_connect_file(gps, gps->io.address);
+               return FALSE;
        break;
        case GPS_IO_TCP:
        case GPS_IO_GPSD:
@@ -412,18 +461,26 @@ switch (gps->io.type) {
        break;
        case GPS_IO_HILDON_DBUS:
 #ifdef WITH_HILDON_DBUS_BT
+               if (NULL == (gps->io.dbus_conn=dbus_g_bus_get(DBUS_BUS_SYSTEM, &error))) {
+                       g_printerr("Failed to get D-Bus connection.");
+                       return FALSE;
+               }
+               if (NULL == (gps->io.rfcomm_req_proxy = dbus_g_proxy_new_for_name(gps->io.dbus_conn, BTCOND_SERVICE, BTCOND_REQ_PATH, BTCOND_REQ_INTERFACE))) {
+                       g_printerr("Failed to open connection to %s.\n", BTCOND_REQ_INTERFACE);
+                       return FALSE;
+                }
+
                if (gps->io.rfcomm_req_proxy) {
                        gboolean mybool = TRUE;
-                       dbus_g_proxy_begin_call(_rfcomm_req_proxy,
-                               BTCOND_RFCOMM_CONNECT_REQ, (DBusGProxyCallNotify)gps_connect_response, NULL, NULL,
+                       dbus_g_proxy_begin_call(gps->io.rfcomm_req_proxy,
+                               BTCOND_RFCOMM_CONNECT_REQ, (DBusGProxyCallNotify)gps_connect_response, gps, NULL,
                                G_TYPE_STRING, gps->io.address,
                                G_TYPE_STRING, "SPP",
                                G_TYPE_BOOLEAN, &mybool,
                                G_TYPE_INVALID);
                }
-#else
-               return FALSE;
 #endif
+               return FALSE;
        break;
        case GPS_IO_RFCOMM:
 #ifdef WITH_BLUEZ
index 760b370fdea73bc5af0e55148f2c744d0a4b6779..694a9bd0f6d35860385f01b464bd51db07f3637d 100644 (file)
--- a/src/gps.h
+++ b/src/gps.h
@@ -14,6 +14,7 @@
 #include <sys/wait.h>
 #include <glib/gstdio.h>
 #include <gtk/gtk.h>
+#include <dbus/dbus.h>
 #include <dbus/dbus-glib.h>
 #include <sys/types.h>
 #include <sys/socket.h>
@@ -70,16 +71,19 @@ struct _GpsIO {
        GpsIOSourceType type;
        GpsConnState conn;
        GIOChannel *channel;
+       DBusConnection *dbus_conn;
        DBusGProxy *rfcomm_req_proxy;
 #ifdef WITH_BLUEZ
        struct sockaddr_rc rcvr_addr_rc;
 #endif
        struct sockaddr_in rcvr_addr_in;
+       /* Channel callback IDs*/
        guint connect_sid;
        guint error_sid;
        guint input_sid;
        guint clater_sid;
        guint errors;
+       /* Input buffer */
        gchar buffer[GPS_READ_BUF_SIZE];
        gchar *curr;
        gchar *last;
@@ -94,6 +98,11 @@ struct _Gps {
        gchar *name;    /* Name of the connection */
        GpsIO io;
        GpsData data;
+       /* Event callbacks */
+       /* On errors */
+       gboolean(* connection_error) (Gps *gps, const gchar *error_str);
+       /* Connection retry */
+       gboolean(* connection_retry) (Gps *gps, const gchar *error_str);
 };
 
 Gps *_gps;
index 9c8840ab1cc30565229484d6000afecdd1493fdb..fb2a3251bf18165aaf683e9ec84e42e636b8c582 100644 (file)
--- a/src/map.c
+++ b/src/map.c
@@ -1201,7 +1201,7 @@ else
        osm_set_way_range(OSM_RANGE_WAY/4);
 
 osm_progress_set_widget(_db, _progress_item);
-osm_get_location_data(ilat, ilon, &map_loc);
+osm_get_location_data(ilat, ilon, _gps->data.heading, &map_loc);
 if (map_loc.valid)
        map_set_place_information(map_loc.street, map_loc.primary, map_loc.secondary);
 else
index fd6b391b74b9551e82d6eb87354e3e58a2a2c6ee..17abe329f6e071fbf4416dc238a08a3fb7574383 100644 (file)
@@ -1,11 +1,12 @@
 #include "config.h"
 
-#include <math.h>
-#include <gtk/gtk.h>
-
 #ifndef _MAPPER_TYPES_H
 #define _MAPPER_TYPES_H
 
+#include <math.h>
+#include <gtk/gtk.h>
+#include <curl/multi.h>
+
 /** Generic search item list indexes */
 typedef enum {
        ITEM_ID,
index e31e94c5b2571f7d84f8d6915176f24f67bdb996..60374a704a3b8a48afa64fab2f56cd5b41d42773 100644 (file)
@@ -286,6 +286,7 @@ switch (mis) {
                gnome_vfs_init();
                /* XXX: Load GPS configuration, then create gps */
                _gps=gps_new(GPS_IO_SIMULATION);
+               _gps->connection_retry=gps_retry_connection;
                timezone_init();
                gpx_init();
                variables_init();
@@ -339,6 +340,7 @@ switch (mis) {
                /* Initialize D-Bus system connection. */
                if (NULL == (dbus_conn = dbus_g_bus_get(DBUS_BUS_SYSTEM, &error))) {
                        g_printerr("Failed to open connection to D-Bus: %s.\n", error->message);
+                       popup_error(_window, "Failed to connect to D-Bus.");
                        error = NULL;
                }
 
@@ -347,12 +349,6 @@ switch (mis) {
                osso_hw_set_event_cb(_osso, NULL, osso_cb_hw_state, NULL);
                #endif
 
-               #ifdef WITH_HILDON_DBUS_BT
-               if (NULL == (_rfcomm_req_proxy = dbus_g_proxy_new_for_name(dbus_conn, BTCOND_SERVICE, BTCOND_REQ_PATH, BTCOND_REQ_INTERFACE))) {
-                       g_printerr("Failed to open connection to %s.\n", BTCOND_REQ_INTERFACE);
-                       popup_error(_window, "Bluetooth connection handling failed.");
-               }
-               #endif
                mis=MAPPER_INIT_UI;
                p=0.9;
                w="Misc";
@@ -375,7 +371,7 @@ switch (mis) {
        case MAPPER_INIT_DONE:
                progress_dialog_remove(init_dialog);
                if (_enable_gps)   
-               gps_connect_now(_gps);
+                       gps_connect_now(_gps);
                return FALSE;
        break;
 }
index be7537f00b1f5f34fbb1cddacbce9f42c7e87e27..4fa4183f17de5be6d486fe626d9f7427f0c9f165 100644 (file)
@@ -31,7 +31,6 @@
 
 #include "osm.h"
 #include "latlon.h"
-#include "gps.h"
 #include "osm-db.h"
 #include "settings.h"
 
@@ -890,7 +889,7 @@ return FALSE;
  *
  */
 gboolean 
-osm_get_location_data(gint lat, gint lon, osm_location *map_loc)
+osm_get_location_data(gint lat, gint lon, gfloat heading, osm_location *map_loc)
 {
 gdouble dist;
 gboolean check_place=FALSE;
@@ -908,7 +907,7 @@ if (map_loc->valid==FALSE) {
 /* Check if we are still near the same way as last time */
 if (map_loc->street && osm_way_distance(lat, lon, map_loc->street->node_f, map_loc->street->node_t, &dist)==TRUE) {
        /* We are probably on the same way as last time */
-       if ( (dist>(gdouble)way_dist_range) || (fabs(_gps->data.heading-map_loc->heading)>10.0)) {
+       if ( (dist>(gdouble)way_dist_range) || (fabs(heading-map_loc->heading)>10.0)) {
                /* We have moved a large amount, check way again */
                g_printf("*** dist %f over range, checking again\n", dist);
                osm_way_free(map_loc->street);
@@ -951,8 +950,7 @@ if (map_loc->street && osm_way_distance(lat, lon, map_loc->street->node_f, map_l
 }
 
 if (map_loc->changed==TRUE) {
-       map_loc->heading=_gps->data.heading;
-       map_loc->speed=_gps->data.speed;
+       map_loc->heading=heading;
 }
 
 #if 0
index 92d97d5065e4b381075f30e9ce7ab5fedbeed97a..a83662229da6b61ec325ac49df51d5fe70cb8a38 100644 (file)
@@ -56,7 +56,7 @@ gboolean osm_way_distance(gint lat, gint lon, osm_way_node *f, osm_way_node *t,
 
 gboolean osm_place_get(guint32 id, gint lat, gint lon, osm_place **nr);
 
-gboolean osm_get_location_data(gint lat, gint lon, osm_location *map_loc);
+gboolean osm_get_location_data(gint lat, gint lon, gfloat heading, osm_location *map_loc);
 
 osm_way_node *osm_way_node_new(guint id, gint lat, gint lon, gint flags);
 
index 8d1de743a231be6671c820959e44b935d214d157..29a03e57939c16abd9ec63208d0aae6fb07d6bbc 100644 (file)
@@ -6,6 +6,7 @@
 #define _MAPPER_SETTINGS_H
 
 #include "settings-gconf.h"
+#include "mapper-types.h"
 
 /** CONFIGURATION INFORMATION. */
 gchar *_route_dir_uri;
index 635d5ae9cf90f785c5f0af5284d6b9a22f428c71..221bf6ad051a84d92bd488af3f670509b5b2afd1 100644 (file)
@@ -792,3 +792,19 @@ progress_dialog_remove(GtkWidget *dialog)
 if (dialog)
        gtk_widget_destroy(dialog);
 }
+
+/**
+ * Simple dialog to ask if we should try to reconnect to GPS
+ * returns TRUE or FALSE
+ */
+gboolean
+gps_retry_connection(Gps *gps, const gchar *error)
+{
+GtkWidget *confirm;
+gboolean r;
+
+confirm=hildon_note_new_confirmation(GTK_WINDOW(_window), _("Failed to connect to GPS receiver. Retry?"));
+r=(GTK_RESPONSE_OK==gtk_dialog_run(GTK_DIALOG(confirm))) ? TRUE : FALSE;
+gtk_widget_destroy(confirm);
+return r;
+}
index b0adddf9d446ded65a400950aa870c941a98bed3..f4359eef674e3acdad7c3074a067b6cfb20eeaaf 100644 (file)
@@ -21,6 +21,7 @@
 #include <gconf/gconf-client.h>
 #include <libxml/parser.h>
 
+#include "gps.h"
 #include "mapper-types.h"
 #include "ui-maemo.h"
 #include "hildon-wrappers.h"
@@ -29,7 +30,6 @@
 
 /** The main GtkContainer of the application. */
 GtkWidget *_window;
-
 GtkWidget *_gps_widget;
 
 /* GPS Tab widget */
@@ -132,4 +132,6 @@ void set_action_activate(const char *name, gboolean active);
 GtkWidget *progress_dialog(const gchar *title, GtkWidget *progress);
 void progress_dialog_remove(GtkWidget *dialog);
 
+gboolean gps_retry_connection(Gps *gps, const gchar *error);
+
 #endif