summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormvglasow <michael -at- vonglasow.com>2018-04-24 21:07:50 +0200
committermvglasow <michael -at- vonglasow.com>2018-04-24 21:07:50 +0200
commiteb60f241ea80195390aa3b63369e47fd8403e2e1 (patch)
tree16e867d9bfa4f17488f386c09b715a64110dc1de
parent878c60807b6e35a8f1d7c49899fb4fce8c941cb3 (diff)
downloadnavit-eb60f241ea80195390aa3b63369e47fd8403e2e1.tar.gz
Refactor:traffic:Skeleton code for traffic-based route changes
Signed-off-by: mvglasow <michael -at- vonglasow.com>
-rw-r--r--navit/route.c31
-rw-r--r--navit/route_protected.h1
-rw-r--r--navit/traffic.c13
3 files changed, 43 insertions, 2 deletions
diff --git a/navit/route.c b/navit/route.c
index 473a20dbd..428f2488c 100644
--- a/navit/route.c
+++ b/navit/route.c
@@ -2473,6 +2473,37 @@ route_graph_flood(struct route_graph *this, struct route_info *dst, struct vehic
}
/**
+ * @brief Recalculates the route based on changes in the traffic situation.
+ *
+ * This re-evaluates segments in the route graph for which traffic distortions have been added,
+ * removed or changed, as well as nodes affected by this change. After that, the route path is
+ * updated as needed.
+ *
+ * The list pointed to by `changes` is emptied and its elements are freed by this function.
+ *
+ * @param this_ The route
+ * @param changes Points to a `GList` of `struct route_traffic_distortion_change` elements describing
+ * the segments for which the traffic situation has changed
+ */
+void route_process_traffic_changes(struct route *this_, GList ** changes) {
+ struct route_traffic_distortion_change *curr = NULL;
+
+ if (!changes)
+ return;
+
+ while (*changes) {
+ curr = g_list_nth_data(*changes, 0);
+ *changes = g_list_remove(*changes, curr);
+
+ /* TODO process changes */
+
+ g_free(curr);
+ }
+
+ g_free(changes);
+}
+
+/**
* @brief Starts an "offroad" path
*
* This starts a path that is not located on a street. It creates a new route path
diff --git a/navit/route_protected.h b/navit/route_protected.h
index 3f8ff6c90..6950480ad 100644
--- a/navit/route_protected.h
+++ b/navit/route_protected.h
@@ -183,6 +183,7 @@ void route_graph_add_segment(struct route_graph *this, struct route_graph_point
int route_graph_segment_is_duplicate(struct route_graph_point *start, struct route_graph_segment_data *data);
void route_graph_free_segments(struct route_graph *this);
void route_graph_build_done(struct route_graph *rg, int cancel);
+void route_process_traffic_changes(struct route *this_, GList ** changes);
void * route_segment_data_field_pos(struct route_segment_data *seg, enum attr_type type);
/* end of prototypes */
#ifdef __cplusplus
diff --git a/navit/traffic.c b/navit/traffic.c
index 6efaa272a..8e414e98d 100644
--- a/navit/traffic.c
+++ b/navit/traffic.c
@@ -3215,7 +3215,13 @@ static int traffic_process_messages_int(struct traffic * this_, struct traffic_m
/* Changed items to pass to the route */
GList ** changes = NULL;
- /* TODO if we are routing, assign changes */
+ /* Current route status */
+ struct attr route_status_attr;
+
+ if (route_get_attr(this_->rt, attr_route_status, &route_status_attr, NULL)
+ && (route_status_attr.u.num >= route_status_path_done_new))
+ /* if we are routing, assign changes */
+ changes = g_new0(GList *, 1);
for (i = 0; messages && messages[i]; i++)
if (messages[i]->expiration_time >= time(NULL)) {
@@ -3323,7 +3329,10 @@ static int traffic_process_messages_int(struct traffic * this_, struct traffic_m
if ((ret & MESSAGE_UPDATE_SEGMENTS) && (navit_get_ready(this_->navit) == 3))
navit_draw_async(this_->navit, 1);
- /* TODO send `changes` to route if non-NULL */
+ /* FIXME this is probably not thread-safe: if route calculation and traffic message processing
+ * happen concurrently, changes introduced by the messages may not be considered */
+ if (changes)
+ route_process_traffic_changes(this_->rt, changes);
return ret;
}