summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormartin-s <martin-s@ffa7fe5e-494d-0410-b361-a75ebd5db220>2009-03-23 14:50:23 +0000
committermartin-s <martin-s@ffa7fe5e-494d-0410-b361-a75ebd5db220>2009-03-23 14:50:23 +0000
commit4221fdbdf9227227d7a874cd2e69b4d945df1fb6 (patch)
tree668c4879d861703276666c1af9063ba15180fec6
parent5383d3128a5a960f4b09ee0ba3fd5108232e664b (diff)
downloadnavit-svn-4221fdbdf9227227d7a874cd2e69b4d945df1fb6.tar.gz
Fix:vehicle_gpsd:Converted to event system
git-svn-id: http://svn.code.sf.net/p/navit/code/trunk/navit/navit@2165 ffa7fe5e-494d-0410-b361-a75ebd5db220
-rw-r--r--vehicle/gpsd/vehicle_gpsd.c54
1 files changed, 24 insertions, 30 deletions
diff --git a/vehicle/gpsd/vehicle_gpsd.c b/vehicle/gpsd/vehicle_gpsd.c
index 7e93bd48..9165d6ad 100644
--- a/vehicle/gpsd/vehicle_gpsd.c
+++ b/vehicle/gpsd/vehicle_gpsd.c
@@ -32,12 +32,14 @@
#include "coord.h"
#include "item.h"
#include "vehicle.h"
+#include "event.h"
static struct vehicle_priv {
char *source;
char *gpsd_query;
struct callback_list *cbl;
- GIOChannel *iochan;
+ struct callback *cb;
+ struct event_watch *evwatch;
guint retry_interval;
guint watch;
struct gps_data_t *gps;
@@ -65,10 +67,7 @@ static struct vehicle_priv {
#define DEFAULT_RETRY_INTERVAL 10 // seconds
#define MIN_RETRY_INTERVAL 1 // seconds
-static gboolean vehicle_gpsd_io(GIOChannel * iochan,
- GIOCondition condition, gpointer t);
-
-
+static void vehicle_gpsd_io(struct vehicle_priv *priv);
static void
vehicle_gpsd_callback(struct gps_data_t *data, char *buf, size_t len,
@@ -182,11 +181,9 @@ vehicle_gpsd_try_open(gpointer *data)
}
gps_query(priv->gps, priv->gpsd_query);
gps_set_raw_hook(priv->gps, vehicle_gpsd_callback);
- priv->iochan = g_io_channel_unix_new(priv->gps->gps_fd);
- priv->watch =
- g_io_add_watch(priv->iochan, G_IO_IN | G_IO_ERR | G_IO_HUP,
- vehicle_gpsd_io, priv);
- dbg(0,"Connected to gpsd fd=%d iochan=%p watch=%p\n", priv->gps->gps_fd, priv->iochan, priv->watch);
+ priv->cb = callback_new_1(callback_cast(vehicle_gpsd_io), priv);
+ priv->evwatch = event_add_watch((void *)priv->gps->gps_fd, event_watch_cond_read, priv->cb);
+ dbg(0,"Connected to gpsd fd=%d evwatch=%p watch=%p\n", priv->gps->gps_fd, priv->evwatch, priv->watch);
return FALSE;
}
@@ -218,7 +215,6 @@ vehicle_gpsd_open(struct vehicle_priv *priv)
static void
vehicle_gpsd_close(struct vehicle_priv *priv)
{
- GError *error = NULL;
#ifdef HAVE_GPSBT
int err;
#endif
@@ -231,9 +227,13 @@ vehicle_gpsd_close(struct vehicle_priv *priv)
g_source_remove(priv->retry_timer);
priv->retry_timer=0;
}
- if (priv->iochan) {
- g_io_channel_shutdown(priv->iochan, 0, &error);
- priv->iochan = NULL;
+ if (priv->evwatch) {
+ event_remove_watch(priv->evwatch);
+ priv->evwatch = NULL;
+ }
+ if (priv->cb) {
+ callback_destroy(priv->cb);
+ priv->cb = NULL;
}
if (priv->gps) {
gps_close(priv->gps);
@@ -248,24 +248,18 @@ vehicle_gpsd_close(struct vehicle_priv *priv)
#endif
}
-static gboolean
-vehicle_gpsd_io(GIOChannel * iochan, GIOCondition condition, gpointer t)
+static void
+vehicle_gpsd_io(struct vehicle_priv *priv)
{
- struct vehicle_priv *priv = t;
-
- dbg(1, "enter condition=%d\n", condition);
- if (condition == G_IO_IN) {
- if (priv->gps) {
- vehicle_last = priv;
- if (gps_poll(priv->gps)) {
- g_warning("gps_poll failed\n");
- vehicle_gpsd_close(priv);
- vehicle_gpsd_open(priv);
- }
- }
- return TRUE;
+ dbg(1, "enter\n");
+ if (priv->gps) {
+ vehicle_last = priv;
+ if (gps_poll(priv->gps)) {
+ g_warning("gps_poll failed\n");
+ vehicle_gpsd_close(priv);
+ vehicle_gpsd_open(priv);
+ }
}
- return FALSE;
}
static void