diff options
Diffstat (limited to 'navit/traffic.c')
-rw-r--r-- | navit/traffic.c | 70 |
1 files changed, 43 insertions, 27 deletions
diff --git a/navit/traffic.c b/navit/traffic.c index f19560829..85bef0baa 100644 --- a/navit/traffic.c +++ b/navit/traffic.c @@ -198,7 +198,7 @@ struct parsed_item { struct attr **attrs; /**< The attributes for the item, `NULL`-terminated */ struct coord *coords; /**< The coordinates for the item */ int coord_count; /**< The number of elements in `coords` */ - int length; /**< The length of the segment in meters */ + int delay; /**< Delay in deciseconds */ int is_matched; /**< Whether any of the maps has a matching item */ }; @@ -731,6 +731,7 @@ static struct item * tm_find_item(struct map_rect *mr, enum item_type type, stru if (attr_generic_get_attr(attrs, NULL, attr_flags, &wanted_flags_attr, NULL)) { if (!item_attr_get(curr, attr_flags, &curr_flags_attr)) continue; + item_attr_rewind(curr); if ((wanted_flags_attr.u.num & AF_ALL) != (curr_flags_attr.u.num & AF_ALL)) continue; continue; @@ -954,10 +955,6 @@ static struct map_rect_priv * tm_rect_new(struct map_priv *priv, struct map_sele int dirty = 0; dbg(lvl_debug,"enter"); - mr=g_new0(struct map_rect_priv, 1); - mr->mpriv = priv; - mr->next_item = priv->items; - /* all other pointers are initially NULL */ /* lazy location matching */ if (sel != NULL) @@ -990,6 +987,12 @@ static struct map_rect_priv * tm_rect_new(struct map_priv *priv, struct map_sele map_selection_destroy(msg_sel); } } + + mr=g_new0(struct map_rect_priv, 1); + mr->mpriv = priv; + mr->next_item = priv->items; + /* all other pointers are initially NULL */ + if (dirty) /* dump message store if new messages have been received */ traffic_dump_messages_to_xml(priv->shared); @@ -1379,6 +1382,7 @@ static int traffic_location_match_attributes(struct traffic_location * this_, st /* road_ref */ if (this_->road_ref) { maxscore += 400; + item_attr_rewind(item); if (item_attr_get(item, attr_street_name_systematic, &attr)) score += (400 * (MAX_MISMATCH - compare_name_systematic(this_->road_ref, attr.u.str))) / MAX_MISMATCH; } @@ -1386,6 +1390,7 @@ static int traffic_location_match_attributes(struct traffic_location * this_, st /* road_name */ if (this_->road_name) { maxscore += 200; + item_attr_rewind(item); if (item_attr_get(item, attr_street_name, &attr)) { // TODO crude comparison in need of refinement if (!strcmp(this_->road_name, attr.u.str)) @@ -1430,12 +1435,14 @@ static int traffic_point_match_attributes(struct traffic_point * this_, struct i /* junction_ref */ if (this_->junction_ref) { maxscore += 400; + item_attr_rewind(item); if (item_attr_get(item, attr_ref, &attr)) score += (400 * (MAX_MISMATCH - compare_name_systematic(this_->junction_ref, attr.u.str))) / MAX_MISMATCH; } /* junction_name */ if (this_->junction_name) { + item_attr_rewind(item); if (item_attr_get(item, attr_label, &attr)) { maxscore += 400; // TODO crude comparison in need of refinement @@ -1560,6 +1567,7 @@ static int traffic_point_match_segment_attributes(struct traffic_point * this_, if (!strcmp(this_->junction_name, attr.u.str)) has_start_match = 1; } + item_attr_rewind(item); if (item_attr_get(item, attr_street_name_systematic, &attr)) start_ref = g_strdup(attr.u.str); } @@ -1576,6 +1584,7 @@ static int traffic_point_match_segment_attributes(struct traffic_point * this_, if (!strcmp(this_->junction_name, attr.u.str)) has_end_match = 1; } + item_attr_rewind(item); if (item_attr_get(item, attr_street_name_systematic, &attr)) end_ref = g_strdup(attr.u.str); } @@ -1620,6 +1629,7 @@ static int traffic_point_match_segment_attributes(struct traffic_point * this_, if (end_name) route_leaves_road |= !strcmp(end_name, attr.u.str); } + item_attr_rewind(item); if (!route_leaves_road && item_attr_get(item, attr_street_name_systematic, &attr)) { if (start_ref) route_leaves_road |= !compare_name_systematic(start_ref, attr.u.str); @@ -1645,6 +1655,7 @@ static int traffic_point_match_segment_attributes(struct traffic_point * this_, if (end_name) route_leaves_road |= !strcmp(end_name, attr.u.str); } + item_attr_rewind(item); if (!route_leaves_road && item_attr_get(item, attr_street_name_systematic, &attr)) { if (start_ref) route_leaves_road |= !compare_name_systematic(start_ref, attr.u.str); @@ -1981,6 +1992,7 @@ static void traffic_location_populate_route_graph(struct traffic_location * this } else data.flags = *default_flags; + item_attr_rewind(item); if ((data.flags & AF_SPEED_LIMIT) && (item_attr_get(item, attr_maxspeed, &attr))) data.maxspeed = attr.u.num; @@ -3424,9 +3436,6 @@ static int traffic_message_restore_segments(struct traffic_message * this_, stru struct parsed_item * pitem; struct item * item; - /* Location length */ - int loc_len = 0; - /* List of parsed items */ GList * items = NULL, * curr_item; @@ -3529,6 +3538,8 @@ static int traffic_message_restore_segments(struct traffic_message * this_, stru pitem->coord_count = ccnt; pitem->attrs = attr_list_dup(attrs); for (i = 0; attrs[i]; i++) { + if (attrs[i]->type == attr_delay) + pitem->delay = attrs[i]->u.num; g_free(attrs[i]); attrs[i] = NULL; } @@ -3614,6 +3625,7 @@ static int traffic_message_restore_segments(struct traffic_message * this_, stru segmented = 0; } /* Get maxspeed, if any */ + item_attr_rewind(map_item); if ((item_flags & AF_SPEED_LIMIT) && (item_attr_get(map_item, attr_maxspeed, &attr))) maxspeed = attr.u.num; else @@ -3649,12 +3661,8 @@ static int traffic_message_restore_segments(struct traffic_message * this_, stru dbg(lvl_debug, "*****checkpoint RESTORE-6.1, restoring segmented items is not supported yet"); map_item = NULL; } - if (map_item) { + if (map_item) pitem->is_matched = 1; - for (i = 1; i < pitem->coord_count; i++) - pitem->length += transform_distance(map_projection(m), &(ca[i-1]), &(ca[i])); - loc_len += pitem->length; - } } } @@ -3689,11 +3697,10 @@ static int traffic_message_restore_segments(struct traffic_message * this_, stru pitem = (struct parsed_item *) curr_item->data; item = tm_add_item(map, pitem->type, pitem->id_hi, pitem->id_lo, pitem->flags, pitem->attrs, pitem->coords, pitem->coord_count, this_->id); - parsed_item_destroy(pitem); tm_item_add_message_data(item, this_->id, traffic_get_item_speed(item, seg_data, maxspeed), - traffic_get_item_delay(seg_data->delay, pitem->length, loc_len), - NULL, route); + pitem->delay, NULL, route); + parsed_item_destroy(pitem); this_->priv->items[i] = item; i++; } @@ -3842,31 +3849,33 @@ static int traffic_message_is_valid(struct traffic_message * this_) { return 0; } if (!this_->receive_time || !this_->update_time) { - dbg(lvl_debug, "receive_time or update_time not supplied"); + dbg(lvl_debug, "%s: receive_time or update_time not supplied", this_->id); return 0; } if (!this_->is_cancellation) { if (!this_->expiration_time && !this_->end_time) { - dbg(lvl_debug, "not a cancellation, but neither expiration_time nor end_time supplied"); + dbg(lvl_debug, "%s: not a cancellation, but neither expiration_time nor end_time supplied", + this_->id); return 0; } if (!this_->location) { - dbg(lvl_debug, "not a cancellation, but no location supplied"); + dbg(lvl_debug, "%s: not a cancellation, but no location supplied", this_->id); return 0; } if (!traffic_location_is_valid(this_->location)) { - dbg(lvl_debug, "not a cancellation, but location is invalid"); + dbg(lvl_debug, "%s: not a cancellation, but location is invalid", this_->id); return 0; } if (!this_->event_count || !this_->events) { - dbg(lvl_debug, "not a cancellation, but no events supplied"); + dbg(lvl_debug, "%s: not a cancellation, but no events supplied", this_->id); return 0; } for (i = 0; i < this_->event_count; i++) if (this_->events[i]) has_valid_events |= traffic_event_is_valid(this_->events[i]); if (!has_valid_events) { - dbg(lvl_debug, "not a cancellation, but all events (%d in total) are invalid", this_->event_count); + dbg(lvl_debug, "%s: not a cancellation, but all events (%d in total) are invalid", + this_->id, this_->event_count); return 0; } } @@ -4626,7 +4635,6 @@ static struct traffic * traffic_new(struct attr *parent, struct attr **attrs) { navit_object_destroy((struct navit_object *) this_); return NULL; } - navit_object_ref((struct navit_object *) this_); dbg(lvl_debug,"return %p", this_); // TODO do this once and cycle through all plugins @@ -4888,7 +4896,7 @@ static void traffic_xml_end(xml_context *dummy, const char *tag_name, void *data count, (struct traffic_event **) children); if (!traffic_message_is_valid(message)) { - dbg(lvl_error, "malformed message detected, skipping"); + dbg(lvl_error, "%s: malformed message detected, skipping", message->id); traffic_message_destroy(message); } else state->messages = g_list_append(state->messages, message); @@ -4945,7 +4953,9 @@ static void traffic_xml_end(xml_context *dummy, const char *tag_name, void *data state->si = NULL; /* TODO preserve unknown (and thus invalid) events if they have maxspeed set */ if (!traffic_event_is_valid(event)) { - dbg(lvl_debug, "invalid or unknown event detected, skipping"); + dbg(lvl_debug, "invalid or unknown event %s/%s detected, skipping", + traffic_xml_get_attr("class", el->names, el->values), + traffic_xml_get_attr("type", el->names, el->values)); traffic_event_destroy(event); } else state->events = g_list_append(state->events, event); @@ -5800,7 +5810,6 @@ struct map * traffic_get_map(struct traffic *this_) { attrs[4] = NULL; this_->shared->map = map_new(NULL, attrs); - navit_object_ref((struct navit_object *) this_->shared->map); /* populate map with previously stored messages */ filename = g_strjoin(NULL, navit_get_user_data_directory(TRUE), "/traffic.xml", NULL); @@ -5938,6 +5947,13 @@ void traffic_set_route(struct traffic *this_, struct route *rt) { this_->shared->rt = rt; } +void traffic_destroy(struct traffic *this_) { + if (this_->meth.destroy) + this_->meth.destroy(this_->priv); + attr_list_free(this_->attrs); + g_free(this_); +} + struct object_func traffic_func = { attr_traffic, (object_func_new)traffic_new, @@ -5948,7 +5964,7 @@ struct object_func traffic_func = { (object_func_add_attr)navit_object_add_attr, (object_func_remove_attr)navit_object_remove_attr, (object_func_init)NULL, - (object_func_destroy)navit_object_destroy, + (object_func_destroy)traffic_destroy, (object_func_dup)NULL, (object_func_ref)navit_object_ref, (object_func_unref)navit_object_unref, |