traffic.c (navit-0.5.5) | : | traffic.c (navit-0.5.6) | ||
---|---|---|---|---|
skipping to change at line 3843 | skipping to change at line 3843 | |||
*/ | */ | |||
static int traffic_message_is_valid(struct traffic_message * this_) { | static int traffic_message_is_valid(struct traffic_message * this_) { | |||
int i; | int i; | |||
int has_valid_events = 0; | int has_valid_events = 0; | |||
if (!this_->id || !this_->id[0]) { | if (!this_->id || !this_->id[0]) { | |||
dbg(lvl_debug, "ID is NULL or empty"); | dbg(lvl_debug, "ID is NULL or empty"); | |||
return 0; | return 0; | |||
} | } | |||
if (!this_->receive_time || !this_->update_time) { | 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; | return 0; | |||
} | } | |||
if (!this_->is_cancellation) { | if (!this_->is_cancellation) { | |||
if (!this_->expiration_time && !this_->end_time) { | if (!this_->expiration_time && !this_->end_time) { | |||
dbg(lvl_debug, "not a cancellation, but neither expiration_time nor | dbg(lvl_debug, "%s: not a cancellation, but neither expiration_time | |||
end_time supplied"); | nor end_time supplied", | |||
this_->id); | ||||
return 0; | return 0; | |||
} | } | |||
if (!this_->location) { | if (!this_->location) { | |||
dbg(lvl_debug, "not a cancellation, but no location supplied"); | dbg(lvl_debug, "%s: not a cancellation, but no location supplied", t his_->id); | |||
return 0; | return 0; | |||
} | } | |||
if (!traffic_location_is_valid(this_->location)) { | 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", th is_->id); | |||
return 0; | return 0; | |||
} | } | |||
if (!this_->event_count || !this_->events) { | 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", thi s_->id); | |||
return 0; | return 0; | |||
} | } | |||
for (i = 0; i < this_->event_count; i++) | for (i = 0; i < this_->event_count; i++) | |||
if (this_->events[i]) | if (this_->events[i]) | |||
has_valid_events |= traffic_event_is_valid(this_->events[i]); | has_valid_events |= traffic_event_is_valid(this_->events[i]); | |||
if (!has_valid_events) { | if (!has_valid_events) { | |||
dbg(lvl_debug, "not a cancellation, but all events (%d in total) are | dbg(lvl_debug, "%s: not a cancellation, but all events (%d in total) | |||
invalid", this_->event_count); | are invalid", | |||
this_->id, this_->event_count); | ||||
return 0; | return 0; | |||
} | } | |||
} | } | |||
return 1; | return 1; | |||
} | } | |||
/** | /** | |||
* @brief Parses the events of a traffic message. | * @brief Parses the events of a traffic message. | |||
* | * | |||
* @param message The message to parse | * @param message The message to parse | |||
skipping to change at line 4627 | skipping to change at line 4629 | |||
} | } | |||
this_->priv = traffic_new(parent->u.navit, &this_->meth, this_->attrs, NULL) ; | this_->priv = traffic_new(parent->u.navit, &this_->meth, this_->attrs, NULL) ; | |||
dbg(lvl_debug, "get_messages=%p", this_->meth.get_messages); | dbg(lvl_debug, "get_messages=%p", this_->meth.get_messages); | |||
dbg(lvl_debug, "priv=%p", this_->priv); | dbg(lvl_debug, "priv=%p", this_->priv); | |||
if (!this_->priv) { | if (!this_->priv) { | |||
dbg(lvl_error, "plugin initialization failed"); | dbg(lvl_error, "plugin initialization failed"); | |||
navit_object_destroy((struct navit_object *) this_); | navit_object_destroy((struct navit_object *) this_); | |||
return NULL; | return NULL; | |||
} | } | |||
navit_object_ref((struct navit_object *) this_); | ||||
dbg(lvl_debug,"return %p", this_); | dbg(lvl_debug,"return %p", this_); | |||
// TODO do this once and cycle through all plugins | // TODO do this once and cycle through all plugins | |||
this_->callback = callback_new_1(callback_cast(traffic_loop), this_); | this_->callback = callback_new_1(callback_cast(traffic_loop), this_); | |||
this_->timeout = event_add_timeout(1000, 1, this_->callback); // TODO make i nterval configurable | this_->timeout = event_add_timeout(1000, 1, this_->callback); // TODO make i nterval configurable | |||
if (!this_->shared) | if (!this_->shared) | |||
traffic_set_shared(this_); | traffic_set_shared(this_); | |||
return this_; | return this_; | |||
skipping to change at line 4889 | skipping to change at line 4890 | |||
time_new(traffic_xml_get_attr("start_t ime", el->names, el->values)), | time_new(traffic_xml_get_attr("start_t ime", el->names, el->values)), | |||
time_new(traffic_xml_get_attr("end_tim e", el->names, el->values)), | time_new(traffic_xml_get_attr("end_tim e", el->names, el->values)), | |||
boolean_new(traffic_xml_get_attr("canc ellation", el->names, el->values), 0), | boolean_new(traffic_xml_get_attr("canc ellation", el->names, el->values), 0), | |||
boolean_new(traffic_xml_get_attr("fore cast", el->names, el->values), 0), | boolean_new(traffic_xml_get_attr("fore cast", el->names, el->values), 0), | |||
/* TODO replaces */ | /* TODO replaces */ | |||
0, NULL, | 0, NULL, | |||
state->location, | state->location, | |||
count, | count, | |||
(struct traffic_event **) children); | (struct traffic_event **) children); | |||
if (!traffic_message_is_valid(message)) { | if (!traffic_message_is_valid(message)) { | |||
dbg(lvl_error, "malformed message detected, skipping"); | dbg(lvl_error, "%s: malformed message detected, skipping", messa ge->id); | |||
traffic_message_destroy(message); | traffic_message_destroy(message); | |||
} else | } else | |||
state->messages = g_list_append(state->messages, message); | state->messages = g_list_append(state->messages, message); | |||
g_free(children); | g_free(children); | |||
state->location = NULL; | state->location = NULL; | |||
g_list_free(state->events); | g_list_free(state->events); | |||
state->events = NULL; | state->events = NULL; | |||
/* TODO replaces */ | /* TODO replaces */ | |||
} else if (!g_ascii_strcasecmp((char *) tag_name, "location")) { | } else if (!g_ascii_strcasecmp((char *) tag_name, "location")) { | |||
tmc_direction = traffic_xml_get_attr("tmc_direction", el->names, el- >values); | tmc_direction = traffic_xml_get_attr("tmc_direction", el->names, el- >values); | |||
skipping to change at line 4946 | skipping to change at line 4947 | |||
speed ? atoi(speed) : INT_MAX, | speed ? atoi(speed) : INT_MAX, | |||
/* TODO quantifier */ | /* TODO quantifier */ | |||
NULL, | NULL, | |||
count, | count, | |||
(struct traffic_suppl_info **) children); | (struct traffic_suppl_info **) children); | |||
g_free(children); | g_free(children); | |||
g_list_free(state->si); | g_list_free(state->si); | |||
state->si = NULL; | state->si = NULL; | |||
/* TODO preserve unknown (and thus invalid) events if they have maxs peed set */ | /* TODO preserve unknown (and thus invalid) events if they have maxs peed set */ | |||
if (!traffic_event_is_valid(event)) { | 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, skippin | |||
g", | ||||
traffic_xml_get_attr("class", el->names, el->values), | ||||
traffic_xml_get_attr("type", el->names, el->values)); | ||||
traffic_event_destroy(event); | traffic_event_destroy(event); | |||
} else | } else | |||
state->events = g_list_append(state->events, event); | state->events = g_list_append(state->events, event); | |||
} else if (!g_ascii_strcasecmp((char *) tag_name, "from")) { | } else if (!g_ascii_strcasecmp((char *) tag_name, "from")) { | |||
point = &state->from; | point = &state->from; | |||
} else if (!g_ascii_strcasecmp((char *) tag_name, "to")) { | } else if (!g_ascii_strcasecmp((char *) tag_name, "to")) { | |||
point = &state->to; | point = &state->to; | |||
} else if (!g_ascii_strcasecmp((char *) tag_name, "at")) { | } else if (!g_ascii_strcasecmp((char *) tag_name, "at")) { | |||
point = &state->at; | point = &state->at; | |||
} else if (!g_ascii_strcasecmp((char *) tag_name, "via")) { | } else if (!g_ascii_strcasecmp((char *) tag_name, "via")) { | |||
skipping to change at line 5801 | skipping to change at line 5804 | |||
a_traffic.type = attr_traffic; | a_traffic.type = attr_traffic; | |||
a_traffic.u.traffic = this_; | a_traffic.u.traffic = this_; | |||
attrs[0] = &a_type; | attrs[0] = &a_type; | |||
attrs[1] = &data; | attrs[1] = &data; | |||
attrs[2] = &a_description; | attrs[2] = &a_description; | |||
attrs[3] = &a_traffic; | attrs[3] = &a_traffic; | |||
attrs[4] = NULL; | attrs[4] = NULL; | |||
this_->shared->map = map_new(NULL, attrs); | this_->shared->map = map_new(NULL, attrs); | |||
navit_object_ref((struct navit_object *) this_->shared->map); | ||||
/* populate map with previously stored messages */ | /* populate map with previously stored messages */ | |||
filename = g_strjoin(NULL, navit_get_user_data_directory(TRUE), "/traffi c.xml", NULL); | filename = g_strjoin(NULL, navit_get_user_data_directory(TRUE), "/traffi c.xml", NULL); | |||
messages = traffic_get_messages_from_xml_file(this_, filename); | messages = traffic_get_messages_from_xml_file(this_, filename); | |||
g_free(filename); | g_free(filename); | |||
if (messages) { | if (messages) { | |||
for (cur_msg = messages; *cur_msg; cur_msg++) | for (cur_msg = messages; *cur_msg; cur_msg++) | |||
this_->shared->message_queue = g_list_append(this_->shared->mess age_queue, *cur_msg); | this_->shared->message_queue = g_list_append(this_->shared->mess age_queue, *cur_msg); | |||
g_free(messages); | g_free(messages); | |||
skipping to change at line 5939 | skipping to change at line 5941 | |||
} | } | |||
void traffic_set_mapset(struct traffic *this_, struct mapset *ms) { | void traffic_set_mapset(struct traffic *this_, struct mapset *ms) { | |||
this_->shared->ms = ms; | this_->shared->ms = ms; | |||
} | } | |||
void traffic_set_route(struct traffic *this_, struct route *rt) { | void traffic_set_route(struct traffic *this_, struct route *rt) { | |||
this_->shared->rt = 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 = { | struct object_func traffic_func = { | |||
attr_traffic, | attr_traffic, | |||
(object_func_new)traffic_new, | (object_func_new)traffic_new, | |||
(object_func_get_attr)navit_object_get_attr, | (object_func_get_attr)navit_object_get_attr, | |||
(object_func_iter_new)navit_object_attr_iter_new, | (object_func_iter_new)navit_object_attr_iter_new, | |||
(object_func_iter_destroy)navit_object_attr_iter_destroy, | (object_func_iter_destroy)navit_object_attr_iter_destroy, | |||
(object_func_set_attr)navit_object_set_attr, | (object_func_set_attr)navit_object_set_attr, | |||
(object_func_add_attr)navit_object_add_attr, | (object_func_add_attr)navit_object_add_attr, | |||
(object_func_remove_attr)navit_object_remove_attr, | (object_func_remove_attr)navit_object_remove_attr, | |||
(object_func_init)NULL, | (object_func_init)NULL, | |||
(object_func_destroy)navit_object_destroy, | (object_func_destroy)traffic_destroy, | |||
(object_func_dup)NULL, | (object_func_dup)NULL, | |||
(object_func_ref)navit_object_ref, | (object_func_ref)navit_object_ref, | |||
(object_func_unref)navit_object_unref, | (object_func_unref)navit_object_unref, | |||
}; | }; | |||
End of changes. 12 change blocks. | ||||
13 lines changed or deleted | 23 lines changed or added |