Add:Core:Support for position_coord_geo parsing
[navit-package] / src / vehicle / demo / vehicle_demo.c
index 5f0533c..a87e873 100644 (file)
@@ -11,6 +11,7 @@
 
 struct vehicle_priv {
        int interval;
+       int position_set;
        struct callback_list *cbl;
        struct navit *navit;
        struct coord_geo geo;
@@ -37,7 +38,6 @@ vehicle_demo_position_attr_get(struct vehicle_priv *priv,
                attr->u.numd = &priv->direction;
                break;
        case attr_position_coord_geo:
-               dbg(1, "coord %f,%f\n", priv->geo.lat, priv->geo.lng);
                attr->u.coord_geo = &priv->geo;
                break;
        default:
@@ -67,8 +67,8 @@ struct vehicle_methods vehicle_demo_methods = {
 static int
 vehicle_demo_timer(struct vehicle_priv *priv)
 {
-       struct route_path_coord_handle *h;
-       struct coord *c, *pos, ci;
+       struct route_path_coord_handle *h=NULL;
+       struct coord *c, *pos=NULL, ci;
        int slen, len, dx, dy;
 
        len = (priv->speed * priv->interval / 1000)/ 3.6;
@@ -78,19 +78,13 @@ vehicle_demo_timer(struct vehicle_priv *priv)
                return 1;
        }
        struct route *vehicle_route = navit_get_route(priv->navit);
-       if (!vehicle_route) {
-               dbg(1, "navit_get_route NOK\n");
-               return 1;
-       }
-
-       h = route_path_coord_open(vehicle_route);
-       if (!h) {
-               dbg(1, "navit_path_coord_open NOK\n");
-               return 1;
-       }
-       pos = route_path_coord_get(h);
+       if (vehicle_route) 
+               h = route_path_coord_open(vehicle_route);
+       if (h) 
+               pos = route_path_coord_get(h);
        dbg(1, "current pos=%p\n", pos);
        if (pos) {
+               priv->position_set=0;
                dbg(1, "current pos=0x%x,0x%x\n", pos->x, pos->y);
                dbg(1, "last pos=0x%x,0x%x\n", priv->last.x, priv->last.y);
                if (priv->last.x == pos->x && priv->last.y == pos->y) {
@@ -122,6 +116,9 @@ vehicle_demo_timer(struct vehicle_priv *priv)
                                break;
                        }
                }
+       } else {
+               if (priv->position_set) 
+                       callback_list_call_0(priv->cbl);
        }
        return 1;
 }
@@ -134,7 +131,7 @@ vehicle_demo_new(struct vehicle_methods
                 *cbl, struct attr **attrs)
 {
        struct vehicle_priv *ret;
-       struct attr *interval,*speed;
+       struct attr *interval,*speed,*position_coord_geo;
 
        dbg(1, "enter\n");
        ret = g_new0(struct vehicle_priv, 1);
@@ -145,6 +142,11 @@ vehicle_demo_new(struct vehicle_methods
                ret->speed=speed->u.num;
        if ((interval=attr_search(attrs, NULL, attr_interval)))
                ret->interval=speed->u.num;
+       if ((position_coord_geo=attr_search(attrs, NULL, attr_position_coord_geo))) {
+               ret->geo=*(position_coord_geo->u.coord_geo);
+               ret->position_set=1;
+               dbg(0,"position_set %f %f\n", ret->geo.lat, ret->geo.lng);
+       }
        *meth = vehicle_demo_methods;
        g_timeout_add(ret->interval, (GSourceFunc) vehicle_demo_timer, ret);
        return ret;