Fix:vehicle_gpsd:Auto-Start gpsd on maemo
authormartin-s <martin-s@ffa7fe5e-494d-0410-b361-a75ebd5db220>
Fri, 19 Dec 2008 22:03:52 +0000 (22:03 +0000)
committermartin-s <martin-s@ffa7fe5e-494d-0410-b361-a75ebd5db220>
Fri, 19 Dec 2008 22:03:52 +0000 (22:03 +0000)
git-svn-id: https://navit.svn.sourceforge.net/svnroot/navit/trunk/navit@1839 ffa7fe5e-494d-0410-b361-a75ebd5db220

configure.in
navit/navit.c
navit/vehicle.c
navit/vehicle/gpsd/Makefile.am
navit/vehicle/gpsd/vehicle_gpsd.c

index fdaa1fe..d6b96c5 100644 (file)
@@ -90,12 +90,19 @@ test x"${AVOID_UNALIGNED}" = xyes && AC_DEFINE(AVOID_UNALIGNED,[],Define to avoi
 AC_ARG_ENABLE(avoid-float, [  --enable-avoid-float              avoid floating point calculations], AVOID_FLOAT=$enableval, AVOID_FLOAT=no)
 test x"${AVOID_FLOAT}" = xyes && AC_DEFINE(AVOID_FLOAT,[],Define to avoid floating point)
 
-AC_ARG_ENABLE(hildon, [  --enable-hildon              build with maemo/hildon support], enable_hildon=$enableval, enable_hildon=no)
+AC_ARG_ENABLE(hildon, [  --disable-hildon              build without maemo/hildon support], enable_hildon=$enableval, enable_hildon=yes)
 if test "x${enable_hildon}" = "xyes" ; then
        PKG_CHECK_MODULES(HILDON, hildon-1 >= 0.9.9, , [
                AC_MSG_RESULT(no)
                enable_hildon=no
        ])
+       PKG_CHECK_MODULES(GPSBT, gpsbt, [
+               AC_DEFINE(HAVE_GPSBT, 1, [Have the gpsbt library])
+               AC_SUBST(GPSBT_CFLAGS)
+               AC_SUBST(GPSBT_LIBS)
+               ], [
+               AC_MSG_RESULT(no)
+       ])
        if test x"${enable_hildon}" = xyes ; then
                AC_DEFINE(USE_HILDON, 1, [Build with maemo/hildon support])
                AC_SUBST(HILDON_CFLAGS)
index f9503fc..8543af6 100644 (file)
@@ -2021,6 +2021,7 @@ void
 navit_destroy(struct navit *this_)
 {
        /* TODO: destroy objects contained in this_ */
+       vehicle_destroy(this_->vehicle->vehicle);
        main_remove_navit(this_);
        char *center_file = navit_get_center_file(TRUE);
        navit_write_center_to_file(this_, center_file);
index f52f9ce..cf63a3c 100644 (file)
@@ -230,6 +230,7 @@ vehicle_remove_attr(struct vehicle *this_, struct attr *attr)
 void
 vehicle_destroy(struct vehicle *this_)
 {
+       this_->meth.destroy(this_->priv);
        callback_list_destroy(this_->cbl);
        attr_list_free(this_->attrs);
        g_free(this_);
index b41529b..7a52b18 100644 (file)
@@ -1,5 +1,5 @@
 include $(top_srcdir)/Makefile.inc
-AM_CPPFLAGS = @NAVIT_CFLAGS@ -I$(top_srcdir)/navit -DMODULE=vehicle_gpsd
+AM_CPPFLAGS = @NAVIT_CFLAGS@ @GPSBT_CFLAGS@ -I$(top_srcdir)/navit -DMODULE=vehicle_gpsd
 modulevehicle_LTLIBRARIES = libvehicle_gpsd.la
 libvehicle_gpsd_la_SOURCES = vehicle_gpsd.c
-libvehicle_gpsd_la_LIBADD = @GPSD_LIBS@
+libvehicle_gpsd_la_LIBADD = @GPSD_LIBS@ @GPSBT_LIBS@
index 2025fda..5d0c62b 100644 (file)
 #include <string.h>
 #include <glib.h>
 #include <math.h>
+#ifdef HAVE_GPSBT
+#include <gpsbt.h>
+#include <errno.h>
+#endif
 #include "debug.h"
 #include "callback.h"
 #include "plugin.h"
@@ -189,6 +193,19 @@ vehicle_gpsd_try_open(gpointer *data)
 static void
 vehicle_gpsd_open(struct vehicle_priv *priv)
 {
+#ifdef HAVE_GPSBT
+       char errstr[256] = "";
+       /* We need to start gpsd (via gpsbt) first. */
+       errno = 0;
+       memset(&priv->context, 0, sizeof(gpsbt_t));
+       if(gpsbt_start(NULL, 1, 0, 0, errstr, sizeof(errstr),
+               0, &priv->context) < 0) {
+              dbg(0,"Error connecting to GPS with gpsbt: (%d) %s (%s)\n",
+                 errno, strerror(errno), errstr);
+       }
+       sleep(1);       /* give gpsd time to start */
+       dbg(1,"gpsbt_start: completed\n");
+#endif
        priv->retry_timer=0;
        if (vehicle_gpsd_try_open((gpointer *)priv)) {
                priv->retry_timer = g_timeout_add(priv->retry_interval*1000, (GSourceFunc)vehicle_gpsd_try_open, (gpointer *)priv);
@@ -199,6 +216,9 @@ static void
 vehicle_gpsd_close(struct vehicle_priv *priv)
 {
        GError *error = NULL;
+#ifdef HAVE_GPSBT
+       int err;
+#endif
 
        if (priv->watch) {
                g_source_remove(priv->watch);
@@ -216,6 +236,13 @@ vehicle_gpsd_close(struct vehicle_priv *priv)
                gps_close(priv->gps);
                priv->gps = NULL;
        }
+#ifdef HAVE_GPSBT
+       err = gpsbt_stop(&priv->context);
+       if (err < 0) {
+               dbg(0,"Error %d while gpsbt_stop", err);
+       }
+       dbg(1,"gpsbt_stop: completed, (%d)",err);
+#endif
 }
 
 static gboolean