Add:Core:Made routing optionally asynchronous
authormartin-s <martin-s@ffa7fe5e-494d-0410-b361-a75ebd5db220>
Tue, 5 May 2009 18:42:04 +0000 (18:42 +0000)
committermartin-s <martin-s@ffa7fe5e-494d-0410-b361-a75ebd5db220>
Tue, 5 May 2009 18:42:04 +0000 (18:42 +0000)
git-svn-id: https://navit.svn.sourceforge.net/svnroot/navit/trunk/navit@2254 ffa7fe5e-494d-0410-b361-a75ebd5db220

navit/binding/dbus/binding_dbus.c
navit/binding/python/navit.c
navit/gui/gtk/destination.c
navit/gui/gtk/gui_gtk_action.c
navit/gui/gtk/gui_gtk_window.c
navit/gui/internal/gui_internal.c
navit/navit.c
navit/navit.h
navit/popup.c
navit/route.c
navit/route.h

index 677e27a..b4ead6d 100644 (file)
@@ -681,7 +681,7 @@ request_navit_set_destination(DBusConnection *connection, DBusMessage *message)
        dbus_message_iter_get_basic(&iter, &description);
        dbg(0, " destination -> %s\n", description);
        
-       navit_set_destination(navit, &pc, description);
+       navit_set_destination(navit, &pc, description, 1);
        return empty_reply(connection, message);
 }
 
index e83619b..0a92210 100644 (file)
@@ -56,9 +56,10 @@ navit_set_destination_py(navitObject *self, PyObject *args)
 {
        PyObject *pcoord;
        const char *description;
-       if (!PyArg_ParseTuple(args, "O!s", &pcoord_Type, &pcoord, &description))
+       int async;
+       if (!PyArg_ParseTuple(args, "O!si", &pcoord_Type, &pcoord, &description, &async))
                return NULL;
-       navit_set_destination(self->navit, pcoord_py_get(pcoord), description);
+       navit_set_destination(self->navit, pcoord_py_get(pcoord), description, async);
        Py_RETURN_NONE;
 }
 
index e7f95fe..b65cba5 100644 (file)
@@ -101,7 +101,7 @@ static void button_destination(GtkWidget *widget, struct search_param *search)
        gtk_tree_model_get (GTK_TREE_MODEL (search->liststore2), &iter, COL_COUNT, &c, -1);
        if (c) {
                desc=description(search, &iter);
-               navit_set_destination(search->nav, c, desc);
+               navit_set_destination(search->nav, c, desc, 1);
                g_free(desc);
        }
 }
index 37c99ba..144a827 100644 (file)
@@ -176,7 +176,7 @@ info_action(GtkWidget *w, struct gui_priv *gui, void *dummy)
 static void
 route_clear_action(GtkWidget *w, struct gui_priv *gui, void *dummy)
 {
-       navit_set_destination(gui->nav, NULL, NULL);
+       navit_set_destination(gui->nav, NULL, NULL, 0);
 }
 
 static void
index 29dafe2..05e2129 100644 (file)
@@ -305,7 +305,7 @@ gui_gtk_action_activate(GtkAction *action, struct action_cb_data *data)
        if(data->attr.type == attr_destination) {
                char * label;
                g_object_get(G_OBJECT(action), "label", &label,NULL);
-               navit_set_destination(data->gui->nav, data->attr.u.pcoord, label);
+               navit_set_destination(data->gui->nav, data->attr.u.pcoord, label, 1);
                g_free(label);
        }
 }
index cd35fbf..bd9d6a1 100644 (file)
@@ -1646,7 +1646,7 @@ gui_internal_cmd_set_destination(struct gui_priv *this, struct widget *wm, void
 {
        struct widget *w=wm->data;
        dbg(0,"c=%d:0x%x,0x%x\n", w->c.pro, w->c.x, w->c.y);
-       navit_set_destination(this->nav, &w->c, w->name);
+       navit_set_destination(this->nav, &w->c, w->name, 1);
        if (this->flags & 512) {
                struct attr follow;
                follow.type=attr_follow;
@@ -2865,7 +2865,7 @@ gui_internal_cmd_quit(struct gui_priv *this, struct widget *wm, void *data)
 static void
 gui_internal_cmd_abort_navigation(struct gui_priv *this, struct widget *wm, void *data)
 {
-       navit_set_destination(this->nav, NULL, NULL);
+       navit_set_destination(this->nav, NULL, NULL, 0);
 }
 
 
index 039e2fb..3ba6180 100644 (file)
@@ -934,7 +934,7 @@ navit_write_center_to_file(struct navit *this_, char *file)
  * @returns nothing
  */
 void
-navit_set_destination(struct navit *this_, struct pcoord *c, const char *description)
+navit_set_destination(struct navit *this_, struct pcoord *c, const char *description, int async)
 {
        if (c) {
                this_->destination=*c;
@@ -946,7 +946,7 @@ navit_set_destination(struct navit *this_, struct pcoord *c, const char *descrip
        g_free(destination_file);
        callback_list_call_attr_0(this_->attr_cbl, attr_destination);
        if (this_->route) {
-               route_set_destination(this_->route, c);
+               route_set_destination(this_->route, c, async);
 
                if (this_->ready == 3)
                        navit_draw(this_);
@@ -1047,7 +1047,7 @@ navit_add_former_destinations_from_file(struct navit *this_)
        pc.x=c.x;
        pc.y=c.y;
        if (valid) {
-               route_set_destination(this_->route, &pc);
+               route_set_destination(this_->route, &pc, 1);
                this_->destination=pc;
                this_->destination_valid=1;
        }
@@ -2065,7 +2065,7 @@ navit_vehicle_update(struct navit *this_, struct navit_vehicle *nv)
 
        /* Finally, if we reached our destination, stop navigation. */
        if (this_->route && route_destination_reached(this_->route)) {
-               navit_set_destination(this_, NULL, NULL);
+               navit_set_destination(this_, NULL, NULL, 0);
        }
        profile(0,"return 5\n");
 }
index d0d6d9b..3208b69 100644 (file)
@@ -63,7 +63,7 @@ void navit_zoom_in(struct navit *this_, int factor, struct point *p);
 void navit_zoom_out(struct navit *this_, int factor, struct point *p);
 struct navit *navit_new(struct attr *parent, struct attr **attrs);
 struct graphics *navit_get_graphics(struct navit *this_);
-void navit_set_destination(struct navit *this_, struct pcoord *c, const char *description);
+void navit_set_destination(struct navit *this_, struct pcoord *c, const char *description, int async);
 void navit_add_bookmark(struct navit *this_, struct pcoord *c, const char *description);
 void navit_say(struct navit *this_, char *text);
 int navit_speech_estimate(struct navit *this_, char *str);
index 67f8ecd..1f347c1 100644 (file)
@@ -72,7 +72,7 @@ popup_set_destination(struct navit *nav, struct pcoord *pc)
        transform_to_geo(transform_get_projection(navit_get_trans(nav)), &c, &g);
        coord_format(g.lat,g.lng,DEGREES_MINUTES_SECONDS,buffer_geo,sizeof(buffer_geo));
        sprintf(buffer,"Map Point %s", buffer_geo);
-       navit_set_destination(nav, pc, buffer);
+       navit_set_destination(nav, pc, buffer, 1);
 }
 
 static void
index 19e833d..375225d 100644 (file)
@@ -251,12 +251,12 @@ struct route_graph_point_iterator {
 
 static struct route_info * route_find_nearest_street(struct vehicleprofile *vehicleprofile, struct mapset *ms, struct pcoord *c);
 static struct route_graph_point *route_graph_get_point(struct route_graph *this, struct coord *c);
-static void route_graph_update(struct route *this, struct callback *cb);
+static void route_graph_update(struct route *this, struct callback *cb, int async);
 static void route_graph_build_done(struct route_graph *rg, int cancel);
 static struct route_path *route_path_new(struct route_graph *this, struct route_path *oldpath, struct route_info *pos, struct route_info *dst, struct vehicleprofile *profile);
 static void route_process_street_graph(struct route_graph *this, struct item *item);
 static void route_graph_destroy(struct route_graph *this);
-static void route_path_update(struct route *this, int cancel);
+static void route_path_update(struct route *this, int cancel, int async);
 
 /**
  * @brief Returns the projection used for this route
@@ -651,7 +651,7 @@ route_path_update_done(struct route *this, int new_graph)
  * @param this The route to update
  */
 static void
-route_path_update(struct route *this, int cancel)
+route_path_update(struct route *this, int cancel, int async)
 {
        dbg(1,"enter %d\n", cancel);
        if (! this->pos || ! this->dst) {
@@ -682,7 +682,7 @@ route_path_update(struct route *this, int cancel)
                if (! this->route_graph_flood_done_cb)
                        this->route_graph_flood_done_cb=callback_new_2(callback_cast(route_path_update_done), this, 1);
                dbg(1,"route_graph_update\n");
-               route_graph_update(this, this->route_graph_flood_done_cb);
+               route_graph_update(this, this->route_graph_flood_done_cb, async);
        }
 }
 
@@ -727,7 +727,7 @@ route_set_position(struct route *this, struct pcoord *pos)
        if (! this->pos)
                return;
        route_info_distances(this->pos, pos->pro);
-       route_path_update(this, 0);
+       route_path_update(this, 0, 1);
 }
 
 /**
@@ -767,7 +767,7 @@ route_set_position_from_tracking(struct route *this, struct tracking *tracking)
        dbg(3,"street 0=(0x%x,0x%x) %d=(0x%x,0x%x)\n", ret->street->c[0].x, ret->street->c[0].y, ret->street->count-1, ret->street->c[ret->street->count-1].x, ret->street->c[ret->street->count-1].y);
        this->pos=ret;
        if (this->dst) 
-               route_path_update(this, 0);
+               route_path_update(this, 0, 1);
        dbg(2,"ret\n");
 }
 
@@ -875,7 +875,7 @@ route_free_selection(struct map_selection *sel)
  * @param dst Coordinates to set as destination
  */
 void
-route_set_destination(struct route *this, struct pcoord *dst)
+route_set_destination(struct route *this, struct pcoord *dst, int async)
 {
        profile(0,NULL);
        if (this->dst)
@@ -896,7 +896,7 @@ route_set_destination(struct route *this, struct pcoord *dst)
        /* The graph has to be destroyed and set to NULL, otherwise route_path_update() doesn't work */
        route_graph_destroy(this->graph);
        this->graph=NULL;
-       route_path_update(this, 1);
+       route_path_update(this, 1, async);
        profile(0,"end");
 }
 
@@ -1889,7 +1889,7 @@ route_graph_build_idle(struct route_graph *rg)
  * @return The new route graph.
  */
 static struct route_graph *
-route_graph_build(struct mapset *ms, struct coord *c1, struct coord *c2, struct callback *done_cb)
+route_graph_build(struct mapset *ms, struct coord *c1, struct coord *c2, struct callback *done_cb, int async)
 {
        struct route_graph *ret=g_new0(struct route_graph, 1);
 
@@ -1900,8 +1900,13 @@ route_graph_build(struct mapset *ms, struct coord *c1, struct coord *c2, struct
        ret->done_cb=done_cb;
        ret->busy=1;
        if (route_graph_build_next_map(ret)) {
-               ret->idle_cb=callback_new_1(callback_cast(route_graph_build_idle), ret);
-               ret->idle_ev=event_add_idle(50, ret->idle_cb);
+               if (async) {
+                       ret->idle_cb=callback_new_1(callback_cast(route_graph_build_idle), ret);
+                       ret->idle_ev=event_add_idle(50, ret->idle_cb);
+               } else {
+                       while (ret->busy) 
+                               route_graph_build_idle(ret);
+               }
        } else
                route_graph_build_done(ret, 0);
 
@@ -1923,7 +1928,7 @@ route_graph_update_done(struct route *this, struct callback *cb)
  * @param this The route to update the graph for
  */
 static void
-route_graph_update(struct route *this, struct callback *cb)
+route_graph_update(struct route *this, struct callback *cb, int async)
 {
        struct attr route_status;
 
@@ -1933,7 +1938,7 @@ route_graph_update(struct route *this, struct callback *cb)
        this->route_graph_done_cb=callback_new_2(callback_cast(route_graph_update_done), this, cb);
        route_status.u.num=route_status_building_graph;
        route_set_attr(this, &route_status);
-       this->graph=route_graph_build(this->ms, &this->pos->c, &this->dst->c, this->route_graph_done_cb);
+       this->graph=route_graph_build(this->ms, &this->pos->c, &this->dst->c, this->route_graph_done_cb, async);
 }
 
 /**
index 19cf069..b629581 100644 (file)
@@ -91,7 +91,7 @@ int route_contains(struct route *this, struct item *item);
 void route_set_position(struct route *this, struct pcoord *pos);
 void route_set_position_from_tracking(struct route *this, struct tracking *tracking);
 struct map_selection *route_rect(int order, struct coord *c1, struct coord *c2, int rel, int abs);
-void route_set_destination(struct route *this, struct pcoord *dst);
+void route_set_destination(struct route *this, struct pcoord *dst, int async);
 struct route_path_handle *route_path_open(struct route *this);
 struct route_path_segment *route_path_get_segment(struct route_path_handle *h);
 struct coord *route_path_segment_get_start(struct route_path_segment *s);