#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
{
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);
#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};
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)
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;
}
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.
*/
{
switch (gps->io.type) {
case GPS_IO_FILE:
- return gps_connect_file(gps);
+ return TRUE;
break;
case GPS_IO_RFCOMM:
case GPS_IO_TCP:
* 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;
#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
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);
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:
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
#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>
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;
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;
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
#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,
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();
/* 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;
}
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";
case MAPPER_INIT_DONE:
progress_dialog_remove(init_dialog);
if (_enable_gps)
- gps_connect_now(_gps);
+ gps_connect_now(_gps);
return FALSE;
break;
}
#include "osm.h"
#include "latlon.h"
-#include "gps.h"
#include "osm-db.h"
#include "settings.h"
*
*/
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;
/* 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);
}
if (map_loc->changed==TRUE) {
- map_loc->heading=_gps->data.heading;
- map_loc->speed=_gps->data.speed;
+ map_loc->heading=heading;
}
#if 0
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);
#define _MAPPER_SETTINGS_H
#include "settings-gconf.h"
+#include "mapper-types.h"
/** CONFIGURATION INFORMATION. */
gchar *_route_dir_uri;
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;
+}
#include <gconf/gconf-client.h>
#include <libxml/parser.h>
+#include "gps.h"
#include "mapper-types.h"
#include "ui-maemo.h"
#include "hildon-wrappers.h"
/** The main GtkContainer of the application. */
GtkWidget *_window;
-
GtkWidget *_gps_widget;
/* GPS Tab widget */
GtkWidget *progress_dialog(const gchar *title, GtkWidget *progress);
void progress_dialog_remove(GtkWidget *dialog);
+gboolean gps_retry_connection(Gps *gps, const gchar *error);
+
#endif