navit  0.5.3-trunk
traffic.c File Reference

Contains code related to processing traffic messages into map items. More...

#include <string.h>
#include <stdlib.h>
#include <time.h>
#include <sys/time.h>
#include "glib_slice.h"
#include "config.h"
#include "navit.h"
#include "util.h"
#include "coord.h"
#include "item.h"
#include "map.h"
#include "mapset.h"
#include "route_protected.h"
#include "route.h"
#include "transform.h"
#include "xmlconfig.h"
#include "traffic.h"
#include "plugin.h"
#include "fib.h"
#include "event.h"
#include "callback.h"
#include "vehicleprofile.h"
#include "debug.h"

Data Structures

struct  traffic_shared_priv
 Private data shared between all traffic instances. More...
 
struct  traffic
 A traffic plugin instance. More...
 
struct  traffic_location_priv
 
struct  traffic_message_priv
 
struct  map_priv
 Represents the map from a single binfile. More...
 
struct  map_rect_priv
 Implementation-specific map rect data. More...
 
struct  item_msg_priv
 Message-specific map private data. More...
 
struct  item_priv
 Implementation-specific item data for traffic map items. More...
 
struct  parsed_item
 Parsed data for a cached item. More...
 
struct  seg_data
 Data for segments affected by a traffic message. More...
 
struct  point_data
 
struct  xml_state
 State for the XML parser. More...
 
struct  xml_element
 Data for an XML element. More...
 

Macros

#define MESSAGE_UPDATE_MESSAGES   1 << 0
 
#define MESSAGE_UPDATE_SEGMENTS   1 << 1
 
#define PENALTY_OFFROAD   8
 
#define PENALTY_SEGMENT_MATCH   4
 
#define PENALTY_POINT_MATCH   24
 
#define PROCESS_MESSAGES_PURGE_EXPIRED   1 << 0
 
#define PROCESS_MESSAGES_NO_DUMP_STORE   1 << 1
 
#define ROUTE_ORDER(x)
 
#define ROUTE_RECT_DIST_ABS(x)   ((x == location_fuzziness_low_res) ? 1000 : 100)
 
#define ROUTE_RECT_DIST_REL(x)   0
 
#define TEXTFILE_LINE_SIZE   512
 
#define TIME_SLICE   40
 

Functions

static struct seg_dataseg_data_new (void)
 Creates a new struct seg_data and initializes it with default values. More...
 
static struct itemtm_add_item (struct map *map, enum item_type type, int id_hi, int id_lo, int flags, struct attr **attrs, struct coord *c, int count, char *id)
 Adds an item to the map. More...
 
static void tm_destroy (struct map_priv *priv)
 Destroys (closes) the traffic map. More...
 
static void tm_coord_rewind (void *priv_data)
 Rewinds the coordinates of the currently selected item. More...
 
static void tm_item_destroy (struct item *item)
 Destroys a traffic map item. More...
 
static struct itemtm_item_ref (struct item *item)
 References a traffic map item. More...
 
static struct itemtm_item_unref (struct item *item)
 Unreferences a traffic map item. More...
 
static void tm_item_update_attrs (struct item *item, struct route *route)
 Updates the attributes of an item. More...
 
static int tm_coord_get (void *priv_data, struct coord *c, int count)
 Returns the coordinates of a traffic item. More...
 
static void tm_attr_rewind (void *priv_data)
 Rewinds the attributes of the currently selected item. More...
 
static int tm_attr_get (void *priv_data, enum attr_type attr_type, struct attr *attr)
 
static int tm_type_set (void *priv_data, enum item_type type)
 Sets the type of a traffic item. More...
 
static struct map_selectiontraffic_location_get_rect (struct traffic_location *this_, enum projection projection)
 
static struct route_graphtraffic_location_get_route_graph (struct traffic_location *this_, struct mapset *ms)
 Builds a new route graph for traffic location matching. More...
 
static int traffic_location_match_attributes (struct traffic_location *this_, struct item *item)
 Determines the degree to which the attributes of a location and a map item match. More...
 
static int traffic_message_add_segments (struct traffic_message *this_, struct mapset *ms, struct seg_data *data, struct map *map, struct route *route)
 Generates segments affected by a traffic message. More...
 
static int traffic_message_restore_segments (struct traffic_message *this_, struct mapset *ms, struct map *map, struct route *route)
 Restores segments associated with a traffic message from cached data. More...
 
static void traffic_location_populate_route_graph (struct traffic_location *this_, struct route_graph *rg, struct mapset *ms)
 Populates a route graph. More...
 
static void traffic_location_set_enclosing_rect (struct traffic_location *this_, struct coord_geo **coords)
 Sets the rectangle enclosing all points of a location. More...
 
static void traffic_dump_messages_to_xml (struct traffic_shared_priv *shared)
 Dumps all currently active traffic messages to an XML file. More...
 
static void traffic_loop (struct traffic *this_)
 The loop function for the traffic module. More...
 
static struct traffictraffic_new (struct attr *parent, struct attr **attrs)
 Instantiates the traffic plugin. More...
 
static int traffic_process_messages_int (struct traffic *this_, int flags)
 Processes new traffic messages. More...
 
static void traffic_message_dump_to_stderr (struct traffic_message *this_)
 Prints a dump of a message to debug output. More...
 
static struct seg_datatraffic_message_parse_events (struct traffic_message *this_)
 Parses the events of a traffic message. More...
 
static struct route_graph_pointtraffic_route_flood_graph (struct route_graph *rg, struct seg_data *data, struct coord *c_start, struct coord *c_dst, struct route_graph_point *start_existing)
 Determines the path between two reference points in a route graph. More...
 
static void traffic_message_remove_item_data (struct traffic_message *old, struct traffic_message *new, struct route *route)
 Removes message data from the items associated with a message. More...
 
static int boolean_new (const char *string, int deflt)
 Creates a Boolean value from its string representation. More...
 
static void parsed_item_destroy (struct parsed_item *this_)
 Destructor for struct parsed_item More...
 
static time_t time_new (char *string)
 Creates a timestamp from its ISO8601 representation. More...
 
static int seg_data_equals (struct seg_data *l, struct seg_data *r)
 Whether two struct seg_data contain the same data. More...
 
static int tm_item_add_message_data (struct item *item, char *msgid, int speed, int delay, struct attr **attrs, struct route *route)
 Adds message data to a traffic map item. More...
 
static struct itemtm_find_item (struct map_rect *mr, enum item_type type, struct attr **attrs, struct coord *c, int count)
 Returns an item from the map which matches the supplied data. More...
 
static void tm_item_dump_to_file (struct item *item, FILE *f)
 Dumps an item to a file in textfile format. More...
 
static void tm_dump_item_to_textfile (struct item *item)
 Dumps an item to a textfile map. More...
 
static void tm_dump_to_textfile (struct map *map)
 Dumps the traffic map to a textfile map. More...
 
static struct map_rect_privtm_rect_new (struct map_priv *priv, struct map_selection *sel)
 Opens a new map rectangle on the traffic map. More...
 
static void tm_rect_destroy (struct map_rect_priv *mr)
 Destroys a map rectangle on the traffic map. More...
 
static struct itemtm_get_item (struct map_rect_priv *mr)
 Returns the next item from the traffic map. More...
 
static struct itemtm_get_item_byid (struct map_rect_priv *mr, int id_hi, int id_lo)
 Returns the next item with the supplied ID from the traffic map. More...
 
static struct itemtm_rect_create_item (struct map_rect_priv *mr, enum item_type type)
 Creates a new item of the specified type and inserts it into the map. More...
 
static int tm_get_attr (struct map_priv *priv, enum attr_type type, struct attr *attr)
 Gets an attribute from the traffic map. More...
 
static int tm_attr_get (void *priv_data, enum attr_type attr_type, struct attr *attr)
 Returns the next attribute of a traffic item which matches the specified type. More...
 
static int traffic_event_is_valid (struct traffic_event *this_)
 Whether the contents of an event are valid. More...
 
static int traffic_point_match_attributes (struct traffic_point *this_, struct item *item)
 Determines the degree to which the attributes of a point and a map item match. More...
 
static int traffic_point_match_segment_attributes (struct traffic_point *this_, struct route_graph_point *p, struct route_graph_point *start, int match_start)
 Determines the degree to which the attributes of a point match those of the segments connecting to it. More...
 
static int traffic_route_get_seg_cost (struct route_graph_segment *over, struct seg_data *data, int dir)
 Returns the cost of the segment in the given direction. More...
 
static int traffic_location_get_point_triple (struct traffic_location *this_, struct coord_geo **coords)
 Determines the “point triple” for a traffic location. More...
 
static struct map_selectiontraffic_location_get_rect (struct traffic_location *this_, enum projection projection)
 Obtains a map selection for the traffic location. More...
 
static struct map_recttraffic_location_open_map_rect (struct traffic_location *this_, struct route_graph *rg)
 Opens a map rectangle around the end points of the traffic location. More...
 
static int traffic_point_equals (struct traffic_point *l, struct traffic_point *r)
 Whether two traffic points are equal. More...
 
static int traffic_location_equals (struct traffic_location *l, struct traffic_location *r)
 Whether two traffic locations are equal. More...
 
static struct route_graph_segmenttraffic_route_append (struct route_graph *rg, struct route_graph_segment *last, struct route_graph_point *end)
 Extends the route beyond its end point. More...
 
static struct route_graph_pointtraffic_route_prepend (struct route_graph *rg, struct route_graph_point *start)
 Extends the route beyond its start point. More...
 
static struct traffic_pointtraffic_location_get_point (struct traffic_location *this_, int point)
 Returns one of the traffic location’s points. More...
 
static int traffic_location_get_point_match (struct traffic_location *this_, struct route_graph_point *p, int point, struct route_graph *rg, struct route_graph_point *start, int match_start, struct mapset *ms)
 Compares a given point to the traffic location and returns a score. More...
 
static GListtraffic_location_get_matching_points (struct traffic_location *this_, int point, struct route_graph *rg, struct route_graph_point *start, int match_start, struct mapset *ms)
 Returns points from the route graph which match a traffic location. More...
 
static int traffic_location_is_valid (struct traffic_location *this_)
 Whether the contents of a location are valid. More...
 
static int route_graph_point_is_endpoint_candidate (struct route_graph_point *this_, struct route_graph_segment *s_prev)
 Whether the current point is a candidate for low-res endpoint matching. More...
 
static int traffic_get_item_speed (struct item *item, struct seg_data *data, int item_maxspeed)
 Gets the speed for a traffic distortion item. More...
 
static int traffic_get_item_delay (int delay, int item_len, int len)
 Gets the delay for a traffic distortion item. More...
 
static int traffic_message_is_valid (struct traffic_message *this_)
 Whether the contents of a message are valid. More...
 
static void traffic_set_shared (struct traffic *this_)
 Ensures the traffic instance points to valid shared data. More...
 
static struct xml_elementtraffic_xml_element_new (const char *tag_name, const char **names, const char **values)
 Creates a new XML element structure. More...
 
static void traffic_xml_element_destroy (struct xml_element *this_)
 Frees up an XML element structure. More...
 
static char * traffic_xml_get_attr (const char *attr, char **names, char **values)
 Retrieves the value of an XML attribute. More...
 
static int traffic_xml_is_tagstack_valid (struct xml_state *state)
 Whether the tag stack represents a hierarchy of elements which is recognized. More...
 
static void traffic_xml_start (xml_context *dummy, const char *tag_name, const char **names, const char **values, void *data, GError **error)
 Callback function which gets called when an opening tag is encountered. More...
 
static void traffic_xml_end (xml_context *dummy, const char *tag_name, void *data, GError **error)
 Callback function which gets called when a closing tag is encountered. More...
 
static void traffic_xml_text (xml_context *dummy, const char *text, gsize len, void *data, GError **error)
 Callback function which gets called when character data is encountered. More...
 
enum event_class event_class_new (char *string)
 Creates an event class from its string representation. More...
 
const char * event_class_to_string (enum event_class this_)
 Translates an event class to its string representation. More...
 
enum event_type event_type_new (char *string)
 Creates an event type from its string representation. More...
 
const char * event_type_to_string (enum event_type this_)
 Translates an event type to its string representation. More...
 
enum item_type item_type_from_road_type (char *string, int is_urban)
 Creates an item type from a road type. More...
 
enum location_dir location_dir_new (char *string)
 Creates a location directionality from its string representation. More...
 
enum location_fuzziness location_fuzziness_new (char *string)
 Creates a location fuzziness from its string representation. More...
 
const char * location_fuzziness_to_string (enum location_fuzziness this_)
 Translates location fuzziness to its string representation. More...
 
enum location_ramps location_ramps_new (char *string)
 Creates an enum location_ramps from its string representation. More...
 
const char * location_ramps_to_string (enum location_ramps this_)
 Translates an enum location_ramps to its string representation. More...
 
enum si_class si_class_new (char *string)
 Creates a supplementary information class from its string representation. More...
 
const char * si_class_to_string (enum si_class this_)
 Translates a supplementary information class to its string representation. More...
 
enum si_type si_type_new (char *string)
 Creates a supplementary information type from its string representation. More...
 
const char * si_type_to_string (enum si_type this_)
 Translates a supplementary information type to its string representation. More...
 
struct traffic_pointtraffic_point_new (float lon, float lat, char *junction_name, char *junction_ref, char *tmc_id)
 Creates a new traffic_point. More...
 
struct traffic_pointtraffic_point_new_short (float lon, float lat)
 Creates a new traffic_point. More...
 
void traffic_point_destroy (struct traffic_point *this_)
 Destroys a traffic_point. More...
 
struct traffic_locationtraffic_location_new (struct traffic_point *at, struct traffic_point *from, struct traffic_point *to, struct traffic_point *via, struct traffic_point *not_via, char *destination, char *direction, enum location_dir directionality, enum location_fuzziness fuzziness, enum location_ramps ramps, enum item_type road_type, char *road_name, char *road_ref, char *tmc_table, int tmc_direction)
 Creates a new traffic_location. More...
 
struct traffic_locationtraffic_location_new_short (struct traffic_point *at, struct traffic_point *from, struct traffic_point *to, struct traffic_point *via, struct traffic_point *not_via, enum location_dir directionality, enum location_fuzziness fuzziness)
 Creates a new traffic_location. More...
 
void traffic_location_destroy (struct traffic_location *this_)
 Destroys a traffic_location. More...
 
struct traffic_suppl_infotraffic_suppl_info_new (enum si_class si_class, enum si_type type, struct quantifier *quantifier)
 Creates a new traffic_suppl_info. More...
 
void traffic_suppl_info_destroy (struct traffic_suppl_info *this_)
 Destroys a traffic_suppl_info. More...
 
struct traffic_eventtraffic_event_new (enum event_class event_class, enum event_type type, int length, int speed, struct quantifier *quantifier, int si_count, struct traffic_suppl_info **si)
 Creates a new traffic_event. More...
 
struct traffic_eventtraffic_event_new_short (enum event_class event_class, enum event_type type)
 Creates a new traffic_event. More...
 
void traffic_event_destroy (struct traffic_event *this_)
 Destroys a traffic_event. More...
 
void traffic_event_add_suppl_info (struct traffic_event *this_, struct traffic_suppl_info *si)
 Adds a supplementary information item to an event. More...
 
struct traffic_suppl_infotraffic_event_get_suppl_info (struct traffic_event *this_, int index)
 Retrieves a supplementary information item associated with an event. More...
 
struct traffic_messagetraffic_message_new (char *id, time_t receive_time, time_t update_time, time_t expiration_time, time_t start_time, time_t end_time, int is_cancellation, int is_forecast, int replaced_count, char **replaces, struct traffic_location *location, int event_count, struct traffic_event **events)
 Creates a new traffic_message. More...
 
struct traffic_messagetraffic_message_new_short (char *id, time_t receive_time, time_t update_time, time_t expiration_time, int is_forecast, struct traffic_location *location, int event_count, struct traffic_event **events)
 Creates a new traffic_message. More...
 
struct traffic_messagetraffic_message_new_single_event (char *id, time_t receive_time, time_t update_time, time_t expiration_time, int is_forecast, struct traffic_location *location, enum event_class event_class, enum event_type type)
 Creates a new single-event traffic_message. More...
 
struct traffic_messagetraffic_message_new_cancellation (char *id, time_t receive_time, time_t update_time, time_t expiration_time, struct traffic_location *location)
 Creates a new cancellation traffic_message. More...
 
void traffic_message_destroy (struct traffic_message *this_)
 Destroys a traffic_message. More...
 
void traffic_message_add_event (struct traffic_message *this_, struct traffic_event *event)
 Adds an event to a message. More...
 
struct traffic_eventtraffic_message_get_event (struct traffic_message *this_, int index)
 Retrieves an event associated with a message. More...
 
struct item ** traffic_message_get_items (struct traffic_message *this_)
 Returns the items associated with a message. More...
 
static struct map_privtraffic_map_new (struct map_methods *meth, struct attr **attrs, struct callback_list *cbl)
 Registers a new traffic map plugin. More...
 
void traffic_init (void)
 Initializes the traffic plugin. More...
 
struct maptraffic_get_map (struct traffic *this_)
 Returns the map for the traffic plugin. More...
 
static struct traffic_message ** traffic_get_messages_from_parsed_xml (struct xml_state *state)
 Reads previously stored traffic messages from parsed XML data. More...
 
struct traffic_message ** traffic_get_messages_from_xml_file (struct traffic *this_, char *filename)
 Reads previously stored traffic messages from an XML file. More...
 
struct traffic_message ** traffic_get_messages_from_xml_string (struct traffic *this_, char *xml)
 Reads traffic messages from an XML string. More...
 
struct traffic_message ** traffic_get_stored_messages (struct traffic *this_)
 Returns currently active traffic messages. More...
 
void traffic_process_messages (struct traffic *this_, struct traffic_message **messages)
 Processes new traffic messages. More...
 
void traffic_set_mapset (struct traffic *this_, struct mapset *ms)
 Sets the mapset for the traffic plugin. More...
 
void traffic_set_route (struct traffic *this_, struct route *rt)
 Sets the route for the traffic plugin. More...
 
void traffic_destroy (struct traffic *this_)
 Destructor. More...
 

Variables

int item_default_flags_value = AF_ALL
 
static struct map_methods traffic_map_meth
 
static struct item_methods methods_traffic_item
 
struct object_func traffic_func
 

Detailed Description

Contains code related to processing traffic messages into map items.

Navit, a modular navigation system. Copyright (C) 2005-2017 Navit Team

This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License version 2 as published by the Free Software Foundation.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.

Currently the only map items supported are traffic distortions. More may be added in the future.

Traffic distortions are used by Navit to route around traffic problems.

Macro Definition Documentation

◆ MESSAGE_UPDATE_MESSAGES

#define MESSAGE_UPDATE_MESSAGES   1 << 0

Flag to indicate new messages have been received

◆ MESSAGE_UPDATE_SEGMENTS

#define MESSAGE_UPDATE_SEGMENTS   1 << 1

Flag to indicate segments have changed

◆ PENALTY_OFFROAD

#define PENALTY_OFFROAD   8

The penalty applied to an off-road link

◆ PENALTY_POINT_MATCH

#define PENALTY_POINT_MATCH   24

The maximum penalty applied to points with non-matching attributes

◆ PENALTY_SEGMENT_MATCH

#define PENALTY_SEGMENT_MATCH   4

The penalty applied to segments with non-matching attributes

◆ PROCESS_MESSAGES_NO_DUMP_STORE

#define PROCESS_MESSAGES_NO_DUMP_STORE   1 << 1

Flag to indicate the message store should not be exported

◆ PROCESS_MESSAGES_PURGE_EXPIRED

#define PROCESS_MESSAGES_PURGE_EXPIRED   1 << 0

Flag to indicate expired messages should be purged

◆ ROUTE_ORDER

#define ROUTE_ORDER (   x)
Value:
(((x == type_highway_land) || (x == type_highway_city) || (x == type_street_n_lanes)) \
? 10 : ((x == type_street_4_land) || (x == type_street_4_city)) ? 12 : 18)

The lowest order of items to consider (always the default order for the next-lower road type)

◆ ROUTE_RECT_DIST_ABS

#define ROUTE_RECT_DIST_ABS (   x)    ((x == location_fuzziness_low_res) ? 1000 : 100)

The buffer zone around the enclosing rectangle used in route calculations, absolute distance

◆ ROUTE_RECT_DIST_REL

#define ROUTE_RECT_DIST_REL (   x)    0

The buffer zone around the enclosing rectangle used in route calculations, relative to rect size

◆ TEXTFILE_LINE_SIZE

#define TEXTFILE_LINE_SIZE   512

Maximum textfile line size

◆ TIME_SLICE

#define TIME_SLICE   40

Time slice for idle loops, in milliseconds

Function Documentation

◆ boolean_new()

static int boolean_new ( const char *  string,
int  deflt 
)
static

Creates a Boolean value from its string representation.

If the string equals true, yes or can be parsed to a nonzero integer, the result is true.

If the string equals false, no or begins with the digit 0 and returns zero when parsed to an integer, the result is false.

If NULL is supplied, or if the string does not match any known value, the result is the default value.

String comparison is case-insensitive.

Since true is always represented by a return value of 1, passing a deflt other than 0 or 1 allows the caller to determine if the string could be parsed correctly.

Parameters
stringThe string representation
defltThe default value to return if string is not a valid representation of a Boolean value.
Returns
The corresponding enum event_class, or event_class_invalid if string does not match a known identifier

Referenced by traffic_xml_end().

◆ event_class_new()

enum event_class event_class_new ( char *  string)

Creates an event class from its string representation.

Parameters
stringThe string representation (case is ignored)
Returns
The corresponding enum event_class, or event_class_invalid if string does not match a known identifier

References data, dbg, xml_state::is_opened, xml_state::is_valid, lvl_debug, xml_state::tagstack, and xml_element::text.

Referenced by traffic_xml_end().

◆ event_class_to_string()

const char* event_class_to_string ( enum event_class  this_)

Translates an event class to its string representation.

Returns
The string representation of the event class

References event_class_congestion, event_class_delay, and event_class_restriction.

Referenced by traffic_dump_messages_to_xml(), and traffic_message_dump_to_stderr().

◆ event_type_new()

enum event_type event_type_new ( char *  string)

Creates an event type from its string representation.

Parameters
stringThe string representation (case is ignored)
Returns
The corresponding enum event_type, or event_invalid if string does not match a known identifier

Referenced by event_request_system(), and traffic_xml_end().

◆ event_type_to_string()

const char* event_type_to_string ( enum event_type  this_)

Translates an event type to its string representation.

Returns
The string representation of the event type

References event_congestion_cleared, event_congestion_forecast_withdrawn, event_congestion_heavy_traffic, event_congestion_long_queue, event_congestion_none, event_congestion_normal_traffic, event_congestion_queue, event_congestion_queue_likely, event_congestion_slow_traffic, event_congestion_stationary_traffic, event_congestion_stationary_traffic_likely, event_congestion_traffic_building_up, event_congestion_traffic_congestion, event_congestion_traffic_easing, event_congestion_traffic_flowing_freely, event_congestion_traffic_heavier_than_normal, event_congestion_traffic_lighter_than_normal, event_congestion_traffic_much_heavier_than_normal, event_congestion_traffic_problem, event_delay_clearance, event_delay_delay, event_delay_delay_possible, event_delay_forecast_withdrawn, event_delay_long_delay, event_delay_several_hours, event_delay_uncertain_duration, event_delay_very_long_delay, event_restriction_access_restrictions_lifted, event_restriction_all_carriageways_cleared, event_restriction_all_carriageways_reopened, event_restriction_batch_service, event_restriction_blocked, event_restriction_blocked_ahead, event_restriction_carriageway_blocked, event_restriction_carriageway_closed, event_restriction_closed, event_restriction_closed_ahead, event_restriction_contraflow, event_restriction_entry_blocked, event_restriction_entry_reopened, event_restriction_exit_blocked, event_restriction_exit_reopened, event_restriction_intermittent_closures, event_restriction_lane_blocked, event_restriction_lane_closed, event_restriction_open, event_restriction_ramp_blocked, event_restriction_ramp_closed, event_restriction_ramp_reopened, event_restriction_reduced_lanes, event_restriction_reopened, event_restriction_road_cleared, event_restriction_single_alternate_line_traffic, event_restriction_speed_limit, and event_restriction_speed_limit_lifted.

Referenced by traffic_dump_messages_to_xml(), and traffic_message_dump_to_stderr().

◆ item_type_from_road_type()

enum item_type item_type_from_road_type ( char *  string,
int  is_urban 
)

Creates an item type from a road type.

This is guaranteed to return either a routable type (i.e. route_item_first <= type <= route_item_last) or type_line_unspecified. The latter is also returned if string refers to a Navit item type which is not routable.

Parameters
stringA TraFF road type or the string representation of a Navit item type
is_urbanWhether the road is in a built-up area (ignored if string is a Navit item type)
Returns
The corresponding enum item_type, or type_line_unspecified if string does not match a known and routable identifier

Referenced by traffic_xml_end().

◆ location_dir_new()

enum location_dir location_dir_new ( char *  string)

Creates a location directionality from its string representation.

Parameters
stringThe string representation (case is ignored)
Returns
The corresponding enum location_dir, or location_dir_both if string does not match a known identifier

Referenced by traffic_xml_end().

◆ location_fuzziness_new()

enum location_fuzziness location_fuzziness_new ( char *  string)

Creates a location fuzziness from its string representation.

Parameters
stringThe string representation (case is ignored)
Returns
The corresponding enum location_fuzziness, or location_fuzziness_none if string does not match a known identifier

Referenced by traffic_xml_end().

◆ location_fuzziness_to_string()

const char* location_fuzziness_to_string ( enum location_fuzziness  this_)

Translates location fuzziness to its string representation.

Returns
The string representation of the location fuzziness, or NULL for location_fuzziness_none

References location_fuzziness_end_unknown, location_fuzziness_extent_unknown, location_fuzziness_low_res, and location_fuzziness_start_unknown.

Referenced by traffic_dump_messages_to_xml(), and traffic_message_dump_to_stderr().

◆ location_ramps_new()

enum location_ramps location_ramps_new ( char *  string)

Creates an enum location_ramps from its string representation.

Parameters
stringThe string representation (case is ignored)
Returns
The corresponding enum location_ramps, or location_ramps_none if string does not match a known identifier

Referenced by traffic_xml_end().

◆ location_ramps_to_string()

const char* location_ramps_to_string ( enum location_ramps  this_)

Translates an enum location_ramps to its string representation.

Returns
The string representation

References location_ramps_all, location_ramps_entry, location_ramps_exit, and location_ramps_none.

Referenced by traffic_dump_messages_to_xml(), and traffic_message_dump_to_stderr().

◆ parsed_item_destroy()

static void parsed_item_destroy ( struct parsed_item this_)
static

Destructor for struct parsed_item

This frees up the struct parsed_item and all associated data. The pointer passed to this function will be invalid after it returns.

References attr_list_free(), parsed_item::attrs, and parsed_item::coords.

Referenced by traffic_message_restore_segments().

◆ route_graph_point_is_endpoint_candidate()

static int route_graph_point_is_endpoint_candidate ( struct route_graph_point this_,
struct route_graph_segment s_prev 
)
static

Whether the current point is a candidate for low-res endpoint matching.

Parameters
this_The point to examine
s_prevThe route segment leading to this_ (NULL for the start point)

References AF_UNDERGROUND, route_graph_segment::data, route_graph_point::end, route_graph_segment::end_next, route_segment_data::flags, route_graph_point::seg, route_graph_point::start, and route_graph_segment::start_next.

Referenced by traffic_message_add_segments().

◆ seg_data_equals()

static int seg_data_equals ( struct seg_data l,
struct seg_data r 
)
static

Whether two struct seg_data contain the same data.

Returns
true if l and r are equal, false if not. Two NULL values are considered equal; a NULL value and a non-NULL value are not.

References attr_search(), attr::attrs, seg_data::attrs, attr::data, seg_data::delay, seg_data::dir, seg_data::flags, seg_data::speed, seg_data::speed_factor, seg_data::speed_penalty, attr::type, seg_data::type, and attr::u.

Referenced by traffic_process_messages_int().

◆ seg_data_new()

static struct seg_data * seg_data_new ( void  )
static

Creates a new struct seg_data and initializes it with default values.

References seg_data::speed, seg_data::speed_factor, and seg_data::type.

Referenced by traffic_message_parse_events().

◆ si_class_new()

enum si_class si_class_new ( char *  string)

Creates a supplementary information class from its string representation.

Parameters
stringThe string representation (case is ignored)
Returns
The corresponding enum si_class, or si_class_invalid if string does not match a known identifier

Referenced by traffic_xml_start().

◆ si_class_to_string()

const char* si_class_to_string ( enum si_class  this_)

Translates a supplementary information class to its string representation.

Returns
The string representation of the supplementary information class

References si_class_place, si_class_tendency, and si_class_vehicle.

Referenced by traffic_dump_messages_to_xml(), and traffic_message_dump_to_stderr().

◆ si_type_new()

enum si_type si_type_new ( char *  string)

Creates a supplementary information type from its string representation.

Parameters
stringThe string representation (case is ignored)
Returns
The corresponding enum si_type, or si_invalid if string does not match a known identifier

Referenced by traffic_xml_start().

◆ si_type_to_string()

const char* si_type_to_string ( enum si_type  this_)

◆ time_new()

static time_t time_new ( char *  string)
static

Creates a timestamp from its ISO8601 representation.

Parameters
stringThe ISO8601 timestamp
Returns
The timestamp, or 0 if string is NULL.

References iso8601_to_time().

Referenced by traffic_xml_end().

◆ tm_add_item()

static struct item * tm_add_item ( struct map map,
enum item_type  type,
int  id_hi,
int  id_lo,
int  flags,
struct attr **  attrs,
struct coord c,
int  count,
char *  id 
)
static

Adds an item to the map.

If a matching item is already in the map, that item will be returned.

All data passed to this method is safe to free after the method returns, and doing so is the responsibility of the caller.

Parameters
mapThe traffic map
typeType of the item
id_hiFirst part of the ID of the item (item IDs have two parts)
id_loSecond part of the ID of the item
flagsFlags used as a matching criterion, and added to newly-created items
attrsThe attributes for the item
cPoints to an array of coordinates for the item
countNumber of items in c
idMessage ID for the associated message
Returns
The map item

References attr_generic_set_attr(), attr_list_dup(), attr_list_free(), attr::attrs, item_priv::attrs, c, item_priv::coord_count, item_priv::coords, item::id_hi, item::id_lo, attr::map, item::map, map_rect_create_item(), map_rect_destroy(), map_rect_new(), item::meth, methods_traffic_item, item_priv::mr, item_priv::next_attr, item_priv::next_coord, attr::num, item::priv_data, tm_find_item(), attr::type, type, and attr::u.

Referenced by traffic_message_add_segments(), and traffic_message_restore_segments().

◆ tm_attr_get() [1/2]

static int tm_attr_get ( void *  priv_data,
enum attr_type  attr_type,
struct attr attr 
)
static

◆ tm_attr_get() [2/2]

static int tm_attr_get ( void *  priv_data,
enum attr_type  attr_type,
struct attr attr 
)
static

Returns the next attribute of a traffic item which matches the specified type.

Parameters
priv_dataThe item's private data
attr_typeThe attribute type to retrieve, or attr_any to retrieve the next attribute, regardless of type
attrReceives the attribute
Returns
True on success, false on failure

References attr_dup_content(), and item_priv::next_attr.

◆ tm_attr_rewind()

static void tm_attr_rewind ( void *  priv_data)
static

Rewinds the attributes of the currently selected item.

After rewinding, the next call to tm_attr_get() will return the first attribute.

Parameters
priv_dataThe item's private data

References item_priv::attrs, and item_priv::next_attr.

Referenced by tm_get_item().

◆ tm_coord_get()

static int tm_coord_get ( void *  priv_data,
struct coord c,
int  count 
)
static

Returns the coordinates of a traffic item.

Parameters
priv_dataThe item's private data
cPointer to a struct coord array where coordinates will be stored
countThe maximum number of coordinates to retrieve (must be less than or equal to the number of items c can hold)
Returns
The number of coordinates retrieved

References c, item_priv::coord_count, item_priv::coords, and item_priv::next_coord.

◆ tm_coord_rewind()

static void tm_coord_rewind ( void *  priv_data)
static

Rewinds the coordinates of the currently selected item.

After rewinding, the next call to the tm_coord_get() will return the first coordinate of the current item.

Parameters
priv_dataThe item's private data

References item_priv::next_coord.

Referenced by tm_get_item().

◆ tm_destroy()

static void tm_destroy ( struct map_priv priv)
static

Destroys (closes) the traffic map.

Parameters
privThe private data for the traffic map instance

◆ tm_dump_item_to_textfile()

static void tm_dump_item_to_textfile ( struct item item)
static

Dumps an item to a textfile map.

This method writes the item to a textfile map named distortion.txt in the default data folder. This map can be added to the active mapset in order for the distortions to be rendered on the map and considered for routing.

All data passed to this method is safe to free after the method returns, and doing so is the responsibility of the caller.

Parameters
itemThe item

References item_priv::attrs, c, item_priv::coords, dbg, lvl_error, navit_get_user_data_directory(), item::priv_data, and tm_item_dump_to_file().

Referenced by tm_dump_to_textfile().

◆ tm_dump_to_textfile()

static void tm_dump_to_textfile ( struct map map)
static

Dumps the traffic map to a textfile map.

This method writes all items to a textfile map named distortion.txt in the default data folder. This map can be added to the active mapset in order for the distortions to be rendered on the map and considered for routing.

Parameters
mapThe traffic map

References item, map_rect_destroy(), map_rect_get_item(), map_rect_new(), and tm_dump_item_to_textfile().

Referenced by traffic_process_messages_int().

◆ tm_find_item()

static struct item* tm_find_item ( struct map_rect mr,
enum item_type  type,
struct attr **  attrs,
struct coord c,
int  count 
)
static

Returns an item from the map which matches the supplied data.

Comparison criteria are as follows:

  • The item type must match
  • Start and end coordinates must match (inverted coordinates will also match)
  • If attr_flags is supplied in attrs, the item must have this attribute and the rules listed below are applied
  • Flags in AF_ALL must match
  • Flags in AF_ONEWAYMASK must be set either on both sides or neither side
  • If set, flags in AF_ONEWAYMASK must effectively match (equal for same direction, inverted for opposite directions)
  • Other attributes are currently ignored

This is due to the way different reports for the same segment are handled:

  • If multiple reports with the same access flags exist, one item is created; speed and delay are evaluated across all currently active reports in tm_item_update_attrs() (lowest speed and longest delay wins)
  • If multiple reports exist and access flags differ, one item is created for each set of flags; items are deduplicated in route_get_traffic_distortion()
Parameters
mrA map rectangle in the traffic map
typeType of the item
attrsThe attributes for the item
cPoints to an array of coordinates for the item
countNumber of items in c

References AF_ALL, AF_ONEWAYMASK, attr_generic_get_attr(), attr::attrs, c, item_priv::coord_count, item_priv::coords, item_attr_get(), item_attr_rewind(), map_rect_get_item(), attr::num, item::priv_data, attr::type, item::type, type, attr::u, coord::x, pcoord::x, coord::y, and pcoord::y.

Referenced by tm_add_item().

◆ tm_get_attr()

static int tm_get_attr ( struct map_priv priv,
enum attr_type  type,
struct attr attr 
)
static

Gets an attribute from the traffic map.

This only supports the attr_traffic attribute, which is currently only used for the purpose of identifying the map as a traffic map. Note, however, that for now the attribute will have a null pointer.

Parameters
map_privPrivate data of the traffic map
typeThe type of the attribute to be read
attrPointer to an attrib-structure where the attribute should be written to
Returns
True if the attribute type was found, false if not

References attr::traffic, attr::type, and attr::u.

◆ tm_get_item()

static struct item* tm_get_item ( struct map_rect_priv mr)
static

Returns the next item from the traffic map.

Parameters
mrThe map rect to search for items
Returns
The next item, or NULL if the last item has already been retrieved.

References map_rect_priv::item, item_priv::mr, map_rect_priv::next_item, item::priv_data, tm_attr_rewind(), and tm_coord_rewind().

Referenced by tm_get_item_byid().

◆ tm_get_item_byid()

static struct item* tm_get_item_byid ( struct map_rect_priv mr,
int  id_hi,
int  id_lo 
)
static

Returns the next item with the supplied ID from the traffic map.

Parameters
mrThe map rect to search for items
id_hiThe high-order portion of the ID
id_loThe low-order portion of the ID
Returns
The next item matching the ID; NULL if there are no matching items or the last matching item has already been retrieved.

References item::id_hi, item::id_lo, and tm_get_item().

◆ tm_item_add_message_data()

static int tm_item_add_message_data ( struct item item,
char *  msgid,
int  speed,
int  delay,
struct attr **  attrs,
struct route route 
)
static

Adds message data to a traffic map item.

This method checks if the item already has data for the message specified in msgid. If so, the existing data is updated, else a new entry is added.

Data changes also trigger an update of the affected item’s attributes.

Parameters
itemThe item (its priv_data member must point to a struct item_priv)
msgidThe message ID
speedThe maximum speed for the segment (INT_MAX if none given)
delayThe delay for the segment, in tenths of seconds (0 for none)
attrsAdditional attributes specified by the message, can be NULL
routeThe route affected by the changes
Returns
true if data was changed, false if not

References item_msg_priv::delay, item_priv::message_data, item_msg_priv::message_id, item::priv_data, item_msg_priv::speed, and tm_item_update_attrs().

Referenced by traffic_message_add_segments(), and traffic_message_restore_segments().

◆ tm_item_destroy()

static void tm_item_destroy ( struct item item)
static

Destroys a traffic map item.

This function should never be called directly. Instead, be sure to obtain all references by calling tm_item_ref() and destroying them by calling tm_item_unref().

Parameters
itemThe item (its priv_data member must point to a struct item_priv)

References attr_list_free(), item_msg_priv::attrs, item_priv::attrs, item_priv::coords, item_priv::message_data, item_msg_priv::message_id, and item::priv_data.

Referenced by tm_item_unref().

◆ tm_item_dump_to_file()

static void tm_item_dump_to_file ( struct item item,
FILE *  f 
)
static

Dumps an item to a file in textfile format.

All data passed to this method is safe to free after the method returns, and doing so is the responsibility of the caller.

Parameters
itemThe item
fThe file to write to

References attr_to_name(), attr_to_text(), item_priv::attrs, c, item_priv::coord_count, item_priv::coords, item::id_hi, item::id_lo, item_to_name(), item::priv_data, and item::type.

Referenced by tm_dump_item_to_textfile(), and traffic_dump_messages_to_xml().

◆ tm_item_ref()

static struct item * tm_item_ref ( struct item item)
static

References a traffic map item.

Storing a reference to a traffic map item should always be done by calling this function, passing the item as its argument. This will return the item and increase its reference count by one.

Never store a pointer to a traffic item not obtained via this function. Doing so may have undesired side effects as the item will not be aware of the reference to it, and the reference may unexpectedly become invalid, leading to a segmentation fault.

Parameters
itemThe item (its priv_data member must point to a struct item_priv)
Returns
The item. NULL will be returned if the argument is NULL or points to an item whose priv_data member is NULL.

References item, and item::priv_data.

Referenced by traffic_message_add_segments().

◆ tm_item_unref()

static struct item * tm_item_unref ( struct item item)
static

Unreferences a traffic map item.

This must be called when destroying a reference to a traffic map item. It will decrease the reference count of the item by one, and destroy the item if the last reference to is is removed.

The map itself (and only the map) holds weak references to its items, which are not considered in the reference count. Consequently, when the reference count reaches zero, the item is also removed from the map.

Unreferencing an item with a zero reference count (which is only possible for an item which has never been referenced since its creation) is equivalent to dropping the last reference, i.e. it will destroy the item.

When the last reference is removed (or an item with a zero reference count is unreferenced) and the item’s rt member is set (indicating the route to which the item was added), the item is removed from that route.

If the unreference operation is successful, this function returns NULL. This allows one-line operations such as:

some_item = tm_item_unref(some_item);
static struct item * tm_item_unref(struct item *item)
Unreferences a traffic map item.
Definition: traffic.c:572
Parameters
itemThe item (its priv_data member must point to a struct item_priv)
Returns
NULL if the item was unreferenced successfully, item if it points to an item whose priv_data member is NULL.

References item, item_type_set(), item::map, map_rect_destroy(), map_rect_get_item(), map_rect_new(), item_priv::mr, item::priv_data, item_priv::refcount, route_remove_traffic_distortion(), item_priv::rt, and tm_item_destroy().

Referenced by traffic_message_destroy().

◆ tm_item_update_attrs()

static void tm_item_update_attrs ( struct item item,
struct route route 
)
static

Updates the attributes of an item.

This method must be called after changing the message data associated with an item, i.e. adding, removing or modifying message data.

Parameters
itemThe item
routeThe route affected by the changes

References attr_generic_add_attr(), attr_generic_remove_attr(), attr_search(), item_priv::attrs, attr::data, item_msg_priv::delay, item_priv::message_data, attr::num, item::priv_data, route_add_traffic_distortion(), route_change_traffic_distortion(), item_priv::rt, item_msg_priv::speed, attr::type, and attr::u.

Referenced by tm_item_add_message_data(), and traffic_message_remove_item_data().

◆ tm_rect_create_item()

static struct item* tm_rect_create_item ( struct map_rect_priv mr,
enum item_type  type 
)
static

Creates a new item of the specified type and inserts it into the map.

Parameters
mrThe map rect in which to create the item
typeThe type of item to create
Returns
The new item. The item is of type type and has an allocated priv_data member; all other members of both structs are NULL.

References map_priv::items, map_rect_priv::mpriv, item::priv_data, item::type, and type.

◆ tm_rect_destroy()

static void tm_rect_destroy ( struct map_rect_priv mr)
static

Destroys a map rectangle on the traffic map.

◆ tm_rect_new()

static struct map_rect_priv* tm_rect_new ( struct map_priv priv,
struct map_selection sel 
)
static

Opens a new map rectangle on the traffic map.

This function opens a new map rectangle on the route graph's map.

Parameters
privThe traffic graph map's private data
selThe map selection (to restrict search to a rectangle, order and/or item types)
Returns
A new map rect's private data

References map_selection::c_rect, coord_rect_overlap(), data, dbg, traffic_message_priv::items, lvl_debug, map_selection_destroy(), traffic_shared_priv::messages, map_rect_priv::mpriv, map_selection::next, map_rect_priv::next_item, traffic_message::priv, map_methods::pro, map_priv::shared, traffic_dump_messages_to_xml(), traffic_location_get_rect(), traffic_location_set_enclosing_rect(), traffic_map_meth, traffic_message_add_segments(), traffic_message_parse_events(), traffic_message_restore_segments(), and map_selection::u.

◆ tm_type_set()

static int tm_type_set ( void *  priv_data,
enum item_type  type 
)
static

Sets the type of a traffic item.

Parameters
priv_dataThe item's private data
typeThe new type for the item. Setting it to type_none deletes the item from the map.
Returns
0 on failure, nonzero on success

References dbg, map_rect_priv::item, map_priv::items, lvl_error, map_rect_priv::mpriv, item_priv::mr, map_rect_priv::next_item, item::priv_data, item::type, and type.

◆ traffic_destroy()

void traffic_destroy ( struct traffic this_)

◆ traffic_dump_messages_to_xml()

◆ traffic_event_add_suppl_info()

void traffic_event_add_suppl_info ( struct traffic_event this_,
struct traffic_suppl_info si 
)

Adds a supplementary information item to an event.

The traffic_suppl_info instance is destroyed when the traffic_event is destroyed, and therefore cannot be shared between multiple traffic_event instances.

Parameters
this_The event
siThe supplementary information item

References traffic_event::si, and traffic_event::si_count.

◆ traffic_event_destroy()

void traffic_event_destroy ( struct traffic_event this_)

Destroys a traffic_event.

This will release the memory used by the traffic_event and all related data.

A traffic_event is usually destroyed together with its parent traffic_message, thus it is usually not necessary to call this destructor directly.

Parameters
this_The event

References traffic_event::quantifier, traffic_event::si, traffic_event::si_count, and traffic_suppl_info_destroy().

Referenced by traffic_message_destroy(), and traffic_xml_end().

◆ traffic_event_get_suppl_info()

struct traffic_suppl_info* traffic_event_get_suppl_info ( struct traffic_event this_,
int  index 
)

Retrieves a supplementary information item associated with an event.

Parameters
this_The event
indexThe index of the supplementary information item, zero-based
Returns
The supplementary information item at the specified position, or NULL if out of bounds

References traffic_event::si.

◆ traffic_event_is_valid()

static int traffic_event_is_valid ( struct traffic_event this_)
static

Whether the contents of an event are valid.

This identifies any malformed events in which mandatory members are not set.

Returns
true if the event is valid, false if it is malformed

References dbg, traffic_event::event_class, event_class_congestion, event_class_delay, event_class_restriction, event_congestion_cleared, event_delay_clearance, event_restriction_access_restrictions_lifted, event_restriction_speed_limit_lifted, lvl_debug, traffic_event::si, traffic_event::si_count, and traffic_event::type.

Referenced by traffic_message_is_valid(), and traffic_xml_end().

◆ traffic_event_new()

struct traffic_event* traffic_event_new ( enum event_class  event_class,
enum event_type  type,
int  length,
int  speed,
struct quantifier quantifier,
int  si_count,
struct traffic_suppl_info **  si 
)

Creates a new traffic_event.

The traffic_suppl_info instances are destroyed when the traffic_event is destroyed, and therefore cannot be shared between multiple traffic_event instances.

It is the responsibility of the caller to destroy all other references passed to this function (including the si buffer but not the traffic_suppl_info instances). This can be done immediately after the function returns.

Parameters
event_classThe event class (generic category)
typeThe event type, which can be mapped to a string to be displayed to the user
lengthThe length of the affected route in meters, -1 if not known
speedThe speed in km/h at which vehicles can expect to pass through the affected stretch of road (either a temporary speed limit or average speed in practice, whichever is less); INT_MAX if unknown
quantifierAdditional quantifier for supplementary information types allowing this, or NULL
si_countNumber of supplementary information items in si_count
siPoints to an array of pointers to supplementary information items

References traffic_event::event_class, length, traffic_event::length, traffic_event::quantifier, traffic_event::si, traffic_event::si_count, traffic_event::speed, type, and traffic_event::type.

Referenced by traffic_event_new_short(), and traffic_xml_end().

◆ traffic_event_new_short()

struct traffic_event* traffic_event_new_short ( enum event_class  event_class,
enum event_type  type 
)

Creates a new traffic_event.

This is the short version of the constructor, which sets only mandatory members. Other members can be set after the instance is created.

Parameters
event_classThe event class (generic category)
typeThe event type, which can be mapped to a string to be displayed to the user

References traffic_event_new(), and type.

Referenced by traffic_message_new_single_event().

◆ traffic_get_item_delay()

static int traffic_get_item_delay ( int  delay,
int  item_len,
int  len 
)
static

Gets the delay for a traffic distortion item.

Parameters
delayTotal delay for all items associated with the same message and direction
item_lenLength of the current item
lenCombined length of all items associated with the same message and direction

Referenced by traffic_message_add_segments().

◆ traffic_get_item_speed()

static int traffic_get_item_speed ( struct item item,
struct seg_data data,
int  item_maxspeed 
)
static

Gets the speed for a traffic distortion item.

Parameters
itemThe road item to which the traffic distortion refers (not the traffic distortion item)
dataSegment data
item_maxspeedSpeed limit for the item, INT_MAX if none

References data, and item::type.

Referenced by traffic_message_add_segments(), and traffic_message_restore_segments().

◆ traffic_get_map()

struct map* traffic_get_map ( struct traffic this_)

Returns the map for the traffic plugin.

The map is created by the first traffic plugin loaded. If multiple traffic plugin instances are active at the same time, they share the map created by the first instance.

Parameters
this_The traffic plugin instance
Returns
The traffic map

References attr::attrs, callback_cast, callback_new_2, data, event_add_idle(), filename, traffic::idle_cb, traffic::idle_ev, traffic_shared_priv::map, map_new(), traffic_shared_priv::message_queue, navit_get_user_data_directory(), PROCESS_MESSAGES_NO_DUMP_STORE, traffic::shared, attr::str, attr::traffic, traffic_get_messages_from_xml_file(), traffic_process_messages_int(), attr::type, and attr::u.

Referenced by navit_init().

◆ traffic_get_messages_from_parsed_xml()

static struct traffic_message** traffic_get_messages_from_parsed_xml ( struct xml_state state)
static

Reads previously stored traffic messages from parsed XML data.

Parameters
stateThe XML parser state after parsing the XML data
Returns
A NULL-terminated pointer array. Each element points to one struct traffic_message. NULL is returned (rather than an empty pointer array) if there are no messages to report.

References xml_state::messages.

Referenced by traffic_get_messages_from_xml_file(), and traffic_get_messages_from_xml_string().

◆ traffic_get_messages_from_xml_file()

struct traffic_message** traffic_get_messages_from_xml_file ( struct traffic this_,
char *  filename 
)

Reads previously stored traffic messages from an XML file.

Parameters
this_The traffic instance
filenameThe full path to the XML file to parse
Returns
A NULL-terminated pointer array. Each element points to one struct traffic_message. NULL is returned (rather than an empty pointer array) if there are no messages to report.

References dbg, filename, lvl_error, traffic_get_messages_from_parsed_xml(), traffic_xml_end(), traffic_xml_start(), traffic_xml_text(), and xml_parse_file().

Referenced by request_navit_traffic_inject(), and traffic_get_map().

◆ traffic_get_messages_from_xml_string()

struct traffic_message** traffic_get_messages_from_xml_string ( struct traffic this_,
char *  xml 
)

Reads traffic messages from an XML string.

Parameters
this_The traffic instance
filenameThe XML document to parse, as a string
Returns
A NULL-terminated pointer array. Each element points to one struct traffic_message. NULL is returned (rather than an empty pointer array) if there are no messages to report.

References dbg, lvl_error, traffic_get_messages_from_parsed_xml(), traffic_xml_end(), traffic_xml_start(), traffic_xml_text(), and xml_parse_text().

Referenced by traffic_traff_android_on_feed_received().

◆ traffic_get_stored_messages()

struct traffic_message** traffic_get_stored_messages ( struct traffic this_)

Returns currently active traffic messages.

If multiple plugin instances are active, this will give the same result for any plugin, as traffic messages are shared between instances.

Parameters
this_The traffic plugin instance
Returns
A null-terminated array of traffic messages. The caller is responsible for freeing the array (not its elements) when it is no longer needed. This method will always return a valid pointer—if the message store is empty, an empty array (with just one single NULL element) will be returned.

References data, traffic_shared_priv::map, traffic_shared_priv::messages, traffic_shared_priv::ms, traffic_shared_priv::rt, traffic::shared, traffic_message_add_segments(), and traffic_message_parse_events().

Referenced by request_navit_traffic_export_gpx().

◆ traffic_init()

void traffic_init ( void  )

Initializes the traffic plugin.

This function is called once on startup.

References dbg, lvl_debug, and traffic_map_new().

Referenced by main_real().

◆ traffic_location_destroy()

void traffic_location_destroy ( struct traffic_location this_)

◆ traffic_location_equals()

static int traffic_location_equals ( struct traffic_location l,
struct traffic_location r 
)
static

Whether two traffic locations are equal.

Only directionality, the ramps member and reference points are considered for comparison; auxiliary data (such as road names, road types and additional TMC information) is ignored.

When in doubt, this function errs on the side of inequality, i.e. when equivalence cannot be reliably determined, the locations will be reported as not equal, even though they may translate to the same segments later.

Returns
true if l and r are equal, false if not

References traffic_location::at, traffic_location::directionality, traffic_location::from, traffic_location::not_via, traffic_location::ramps, traffic_location::to, traffic_point_equals(), and traffic_location::via.

Referenced by traffic_process_messages_int().

◆ traffic_location_get_matching_points()

static GList* traffic_location_get_matching_points ( struct traffic_location this_,
int  point,
struct route_graph rg,
struct route_graph_point start,
int  match_start,
struct mapset ms 
)
static

Returns points from the route graph which match a traffic location.

This method obtains point items from the map_rect from which the route graph was built and compares their attributes to those supplied with the location. Each point is assigned a match score, from 0 (no matching attributes) to 100 (all supplied attributes match), and a list of all points with a nonzero score is returned.

Points which have no corresponding map item (i.e. points which have no additional attributes) are not included in the result and must be analyzed separately if needed.

Parameters
this_The traffic location
pointThe point of the traffic location to use for matching (0 = from, 1 = at, 2 = to, 16 = start, 17 = end)
rgThe route graph
startThe first point of the path
match_startTrue to evaluate for the start point of a route, false for the end point
msThe mapset to read the items from
Returns
The matched points as a GList. The data member of each item points to a struct point_data for the point.

References c, data, dbg, route_graph::h, item, item_coord_get(), lvl_debug, route_graph::m, map_get_attr(), map_rect_destroy(), map_rect_get_item(), map_selection_destroy(), mapset_next(), mapset_open(), route_graph::mr, p, route_graph_build_done(), route_graph_get_point(), route_graph_get_point_next(), RP_TURN_RESTRICTION, point_data::score, route_graph::sel, traffic_location_get_point(), traffic_location_open_map_rect(), traffic_location_set_enclosing_rect(), traffic_point_match_attributes(), and item::type.

Referenced by traffic_message_add_segments().

◆ traffic_location_get_point()

static struct traffic_point* traffic_location_get_point ( struct traffic_location this_,
int  point 
)
static

Returns one of the traffic location’s points.

Parameters
this_The traffic location
pointThe point of the traffic location to retrieve (0 = from, 1 = at, 2 = to, 16 = start, 17 = end)
Returns
The matched points, or NULL if the requested point does not exist

References traffic_location::at, traffic_location::from, and traffic_location::to.

Referenced by traffic_location_get_matching_points(), and traffic_location_get_point_match().

◆ traffic_location_get_point_match()

static int traffic_location_get_point_match ( struct traffic_location this_,
struct route_graph_point p,
int  point,
struct route_graph rg,
struct route_graph_point start,
int  match_start,
struct mapset ms 
)
static

Compares a given point to the traffic location and returns a score.

This method obtains all points at coordinates c from the map_rect used to build the route graph, compares their attributes to those supplied with the location, assigns a match score from 0 (no matching attributes) to 100 (all supplied attributes match) and returns the highest score obtained. If no matching point is found, 0 is returned.

Parameters
this_The traffic location
pThe route graph point to examine for matches
pointThe point of the traffic location to use for matching (0 = from, 1 = at, 2 = to, 16 = start, 17 = end)
rgThe route graph
startThe first point of the path
match_startTrue to evaluate for the start point of a route, false for the end point
msThe mapset to read the items from
Returns
A score from 0 (worst) to 100 (best).

References p, traffic_location_get_point(), and traffic_point_match_segment_attributes().

Referenced by traffic_message_add_segments().

◆ traffic_location_get_point_triple()

static int traffic_location_get_point_triple ( struct traffic_location this_,
struct coord_geo **  coords 
)
static

Determines the “point triple” for a traffic location.

Each traffic location is defined by up to three points:

  • a start and end point, and an optional auxiliary point in between
  • a single point, with one or two auxiliary points (one before, one after)
  • a start and end point, and a third point which is outside the location

This method determines these three points, puts them in the order in which they are encountered and returns a bit field indicating the end points. If a point in the array is NULL or refers to an auxiliary point, its corresponding bit is not set. The following values are returned:

  • 2: Point location, the middle point is the actual point
  • 3: Point-to-point location from the first to the second point; the third point is an auxiliary point outside the location
  • 5: Point-to-point location from the first to the last point; the second point (if not NULL) is an auxiliary point located in between
  • 6: Point-to-point location from the second to the third point; the first point is an auxiliary point outside the location
Parameters
this_The location
coordsPoints to an array which will receive pointers to the coordinates. The array must be able to store three pointers.
Returns
A bit field indicating the end points for the location

References traffic_location::at, traffic_point::coord, traffic_location::from, traffic_location::not_via, projection_mg, traffic_location::to, transform_distance(), transform_from_geo(), and traffic_location::via.

Referenced by traffic_location_set_enclosing_rect(), and traffic_message_add_segments().

◆ traffic_location_get_rect() [1/2]

static struct map_selection* traffic_location_get_rect ( struct traffic_location this_,
enum projection  projection 
)
static

◆ traffic_location_get_rect() [2/2]

static struct map_selection* traffic_location_get_rect ( struct traffic_location this_,
enum projection  projection 
)
static

Obtains a map selection for the traffic location.

The map selection is a rectangle around the points of the traffic location, with some extra padding as specified in ROUTE_RECT_DIST_REL and ROUTE_RECT_DIST_ABS, with a map order specified in ROUTE_ORDER.

Parameters
this_The traffic location
projectionThe projection to be used by coordinates of the selection (should correspond to the projection of the target map)
Returns
A map selection

References c1, c2, traffic_location::fuzziness, traffic_location_priv::ne, traffic_location::priv, traffic_location::road_type, ROUTE_ORDER, route_rect(), ROUTE_RECT_DIST_ABS, ROUTE_RECT_DIST_REL, traffic_location_priv::sw, and transform_from_geo().

◆ traffic_location_get_route_graph()

static struct route_graph * traffic_location_get_route_graph ( struct traffic_location this_,
struct mapset ms 
)
static

Builds a new route graph for traffic location matching.

Traffic location matching is done by using a modified routing algorithm to identify the segments affected by a traffic message.

Parameters
this_The location to match to the map
msThe mapset to use for the route graph
Returns
A route graph. The caller is responsible for destroying the route graph and all related data when it is no longer needed.

References route_graph::busy, route_graph::done_cb, traffic_location_populate_route_graph(), and traffic_location_set_enclosing_rect().

Referenced by traffic_message_add_segments().

◆ traffic_location_is_valid()

static int traffic_location_is_valid ( struct traffic_location this_)
static

Whether the contents of a location are valid.

This identifies any malformed locations in which mandatory members are not set.

Returns
true if the locations is valid, false if it is malformed

References traffic_location::at, traffic_location::from, and traffic_location::to.

Referenced by traffic_message_is_valid().

◆ traffic_location_match_attributes()

static int traffic_location_match_attributes ( struct traffic_location this_,
struct item item 
)
static

Determines the degree to which the attributes of a location and a map item match.

The result of this method is used to match a location to a map item. Its result is a score—the higher the score, the better the match.

To calculate the score, all supplied attributes are examined and points are given for each attribute which is defined for the location. An exact match adds 4 points, a partial match adds 2. Values of 1 and 3 are added where additional granularity is needed. The number of points attained is divided by the maximum number of points attainable, and the result is returned as a percentage value.

If no points can be attained (because no attributes which must match are supplied), the score is 100 for any item supplied.

Parameters
this_The location
itemThe map item
Returns
The score, as a percentage value

References compare_name_systematic(), item_attr_get(), item_attr_rewind(), MAX_MISMATCH, traffic_location::road_name, traffic_location::road_ref, traffic_location::road_type, attr::str, item::type, and attr::u.

Referenced by traffic_location_populate_route_graph().

◆ traffic_location_new()

struct traffic_location* traffic_location_new ( struct traffic_point at,
struct traffic_point from,
struct traffic_point to,
struct traffic_point via,
struct traffic_point not_via,
char *  destination,
char *  direction,
enum location_dir  directionality,
enum location_fuzziness  fuzziness,
enum location_ramps  ramps,
enum item_type  road_type,
char *  road_name,
char *  road_ref,
char *  tmc_table,
int  tmc_direction 
)

Creates a new traffic_location.

The traffic_point instances are destroyed when the traffic_location is destroyed, and therefore cannot be shared between multiple traffic_location instances.

It is the responsibility of the caller to destroy all other references passed to this function. This can be done immediately after the function returns.

If at is non-NULL, the location is a point location, and from and to are interpreted as auxiliary locations.

Of from and to, one is mandatory for a unidirectional point location; both are mandatory for a linear location.

ramps is mainly intended for compatibility with TMC, where junctions with all their ramps are represented by a single point. Other sources should use coordinate pairs instead.

Parameters
atThe coordinates for a point location, NULL for a linear location
fromThe start of a linear location, or a point before at
toThe end of a linear location, or a point after at
viaA point between from and to, needed only on ring roads
not_viaA point not between from and to, needed only on ring roads
destinationA destination, preferably the one given on road signs, indicating that the message applies only to traffic going in that direction; can be NULL, do not use for bidirectional locations
directionA compass direction indicating the direction of travel which this location refers to; can be NULL, do not use where ambiguous
directionalityWhether the location is unidirectional or bidirectional
fuzzinessA precision indicator for from and to
rampsWhether the main carriageway or the ramps are affected
road_typeThe importance of the road within the road network, must be a road item type, type_line_unspecified if not known or not consistent
road_nameA road name, if consistent throughout the location; NULL if not known or inconsistent
road_refA road number, if consistent throughout the location; NULL if not known or inconsistent
tmc_tableFor messages received via TMC, the CID and LTN; NULL otherwise
tmc_directionFor messages received via TMC, the direction of the road; ignored for bidirectional or non-TMC messages

References traffic_location::at, traffic_location::destination, traffic_location::direction, traffic_location::directionality, traffic_location::from, traffic_location::fuzziness, traffic_location_priv::ne, traffic_location::not_via, traffic_location::priv, traffic_location::ramps, traffic_location::road_name, traffic_location::road_ref, traffic_location::road_type, traffic_location_priv::sw, traffic_location::tmc_direction, traffic_location::tmc_table, traffic_location::to, and traffic_location::via.

Referenced by traffic_dummy_get_messages(), traffic_location_new_short(), and traffic_xml_end().

◆ traffic_location_new_short()

struct traffic_location* traffic_location_new_short ( struct traffic_point at,
struct traffic_point from,
struct traffic_point to,
struct traffic_point via,
struct traffic_point not_via,
enum location_dir  directionality,
enum location_fuzziness  fuzziness 
)

Creates a new traffic_location.

This is the short version of the constructor, which sets only mandatory members. Other members can be set after the instance is created.

The traffic_point instances are destroyed when the traffic_location is destroyed, and therefore cannot be shared between multiple traffic_location instances.

If at is non-NULL, the location is a point location, and from and to are interpreted as auxiliary locations.

Of from and to, one is mandatory for a unidirectional point location; both are mandatory for a linear location.

Parameters
atThe coordinates for a point location, NULL for a linear location
fromThe start of a linear location, or a point before at
toThe end of a linear location, or a point after at
viaA point between from and to, needed only on ring roads
not_viaA point not between from and to, needed only on ring roads
directionalityWhether the location is unidirectional or bidirectional
fuzzinessA precision indicator for from and to

References traffic_location::at, traffic_location::directionality, traffic_location::from, traffic_location::fuzziness, location_ramps_none, traffic_location::not_via, traffic_location::to, traffic_location_new(), and traffic_location::via.

◆ traffic_location_open_map_rect()

static struct map_rect* traffic_location_open_map_rect ( struct traffic_location this_,
struct route_graph rg 
)
static

Opens a map rectangle around the end points of the traffic location.

Prior to calling this function, the caller must ensure rg->m points to the map to be used, and the enclosing rectangle for the traffic location has been set (e.g. by calling traffic_location_set_enclosing_rect()).

Parameters
this_The traffic location
rgThe route graph
Returns
NULL on failure, the map selection on success

References route_graph::m, map_projection(), map_rect_new(), map_selection_destroy(), route_graph::mr, route_graph::sel, and traffic_location_get_rect().

Referenced by traffic_location_get_matching_points(), and traffic_location_populate_route_graph().

◆ traffic_location_populate_route_graph()

◆ traffic_location_set_enclosing_rect()

static void traffic_location_set_enclosing_rect ( struct traffic_location this_,
struct coord_geo **  coords 
)
static

◆ traffic_loop()

static void traffic_loop ( struct traffic this_)
static

The loop function for the traffic module.

This function polls backends for new messages and processes them by inserting, removing or modifying traffic distortions and triggering route recalculations as needed.

References callback_cast, callback_destroy(), callback_new_2, event_add_idle(), event_remove_idle(), traffic_methods::get_messages, traffic::idle_cb, traffic::idle_ev, traffic_shared_priv::message_queue, traffic::meth, traffic::priv, PROCESS_MESSAGES_PURGE_EXPIRED, traffic::shared, and traffic_process_messages_int().

Referenced by traffic_new().

◆ traffic_map_new()

static struct map_priv* traffic_map_new ( struct map_methods meth,
struct attr **  attrs,
struct callback_list cbl 
)
static

Registers a new traffic map plugin.

Parameters
methReceives the map methods
attrsThe attributes for the map
cbl
Returns
A pointer to a map_priv structure for the map

References attr_search(), attr::attrs, dbg, lvl_error, traffic::shared, map_priv::shared, attr::traffic, traffic_map_meth, and attr::u.

Referenced by traffic_init().

◆ traffic_message_add_event()

void traffic_message_add_event ( struct traffic_message this_,
struct traffic_event event 
)

Adds an event to a message.

The traffic_event instance is destroyed when the traffic_message is destroyed, and therefore cannot be shared between multiple traffic_message instances.

Parameters
this_The message
eventThe event to add to this message

References traffic_message::event_count, and traffic_message::events.

◆ traffic_message_add_segments()

static int traffic_message_add_segments ( struct traffic_message this_,
struct mapset ms,
struct seg_data data,
struct map map,
struct route route 
)
static

Generates segments affected by a traffic message.

This translates the approximate coordinates in the from, at, to, via and not_via members of the location to one or more map segments, using both the raw coordinates and the auxiliary information contained in the location. Each segment is stored in the map, if not already present, and a link is stored with the message.

Parameters
this_The traffic message
msThe mapset to use for matching
dataData for the segments added to the map
mapThe traffic map
routeThe route affected by the changes
Returns
true if the locations were matched successfully, false if there was a failure.

References AF_ONEWAY, AF_ONEWAYMASK, AF_ONEWAYREV, AF_SPEED_LIMIT, traffic_location::at, c, route_graph_point::c, data, route_graph_segment::data, dbg, traffic_location::directionality, route_graph_segment::end, route_segment_data::flags, traffic_location::from, traffic_location::fuzziness, traffic_message::id, item::id_hi, item::id_lo, item, route_segment_data::item, item_coord_get_within_range(), traffic_message_priv::items, coord_geo::lat, route_segment_data::len, coord_geo::lng, traffic_message::location, location_dir_one, location_fuzziness_low_res, location_ramps_none, lvl_debug, lvl_error, traffic_location::not_via, point_data::p, PENALTY_POINT_MATCH, traffic_message::priv, projection_mg, traffic_location::ramps, route_graph_free_points(), route_graph_free_segments(), route_graph_point_is_endpoint_candidate(), RSD_MAXSPEED, point_data::score, route_graph_point::seg, route_graph_segment::start, tm_add_item(), tm_item_add_message_data(), tm_item_ref(), traffic_location::to, traffic_get_item_delay(), traffic_get_item_speed(), traffic_location_get_matching_points(), traffic_location_get_point_match(), traffic_location_get_point_triple(), traffic_location_get_route_graph(), traffic_location_set_enclosing_rect(), traffic_route_append(), traffic_route_flood_graph(), traffic_route_prepend(), transform_distance(), transform_from_geo(), transform_to_geo(), and route_graph_point::value.

Referenced by tm_rect_new(), traffic_get_stored_messages(), and traffic_process_messages_int().

◆ traffic_message_destroy()

void traffic_message_destroy ( struct traffic_message this_)

Destroys a traffic_message.

This will release the memory used by the traffic_message and all related data.

A traffic_message is usually destroyed by the traffic plugin, thus it is usually not necessary to call this destructor directly.

Parameters
this_The message

References traffic_message::event_count, traffic_message::events, traffic_message::id, traffic_message_priv::items, traffic_message::location, traffic_message::priv, traffic_message::replaced_count, traffic_message::replaces, tm_item_unref(), traffic_event_destroy(), and traffic_location_destroy().

Referenced by traffic_process_messages_int(), and traffic_xml_end().

◆ traffic_message_dump_to_stderr()

static void traffic_message_dump_to_stderr ( struct traffic_message this_)
static

◆ traffic_message_get_event()

struct traffic_event* traffic_message_get_event ( struct traffic_message this_,
int  index 
)

Retrieves an event associated with a message.

Parameters
this_The message
indexThe index of the event, zero-based
Returns
The event at the specified position, or NULL if out of bounds

References traffic_message::events.

◆ traffic_message_get_items()

struct item** traffic_message_get_items ( struct traffic_message this_)

Returns the items associated with a message.

Note that no map rectangle is required to obtain traffic items. This behavior is particular to traffic items, which do not rely on a map rectangle. Items obtained from other maps may behave differently.

Parameters
this_The message
Returns
Items as a NULL-terminated array. The caller is responsible for freeing the array (not its elements) when it is no longer needed. This method will always return a valid pointer—if no items are associated with the message, an empty array (with just one single NULL element) will be returned. No particular order is guaranteed for the items.

References traffic_message_priv::items, and traffic_message::priv.

Referenced by request_navit_traffic_export_gpx().

◆ traffic_message_is_valid()

static int traffic_message_is_valid ( struct traffic_message this_)
static

Whether the contents of a message are valid.

This identifies any malformed messages in which mandatory members are not set.

Returns
true if the message is valid, false if it is malformed

References dbg, traffic_message::end_time, traffic_message::event_count, traffic_message::events, traffic_message::expiration_time, traffic_message::id, traffic_message::is_cancellation, traffic_message::location, lvl_debug, traffic_message::receive_time, traffic_event_is_valid(), traffic_location_is_valid(), and traffic_message::update_time.

Referenced by traffic_xml_end().

◆ traffic_message_new()

struct traffic_message* traffic_message_new ( char *  id,
time_t  receive_time,
time_t  update_time,
time_t  expiration_time,
time_t  start_time,
time_t  end_time,
int  is_cancellation,
int  is_Forecast,
int  replaced_count,
char **  replaces,
struct traffic_location location,
int  event_count,
struct traffic_event **  events 
)

Creates a new traffic_message.

The traffic_event and traffic_location instances are destroyed when the traffic_message is destroyed, and therefore cannot be shared between multiple traffic_message instances.

It is the responsibility of the caller to destroy all other references passed to this function (including the events buffer but not the traffic_event instances). This can be done immediately after the function returns.

Parameters
idThe message identifier; existing messages with the same identifier will be replaced by the new message
receive_timeWhen the message was first received by the source, should be kept stable across all updates
update_timeWhen the last update to this message was received by the source
expiration_timeHow long the message should be considered valid
start_timeWhen the condition is expected to begin (optional, 0 if not set)
end_timeHow long the condition is expected to last (optional, 0 if not set)
isCancellationIf true, create a cancellation message (existing messages with the same ID should be deleted or no longer considered current, and all other attributes ignored)
isForecastIf false, the message describes a current situation; if true, it describes an expected situation in the future
replaced_countThe number of entries in replaces
replacesPoints to an array of identifiers of messages which the current message replaces
locationThe location to which this message refers
event_countThe number of events in events
eventsPoints to an array of pointers to the events for this message

References traffic_message::end_time, traffic_message::event_count, traffic_message::events, traffic_message::expiration_time, traffic_message::id, traffic_message::is_cancellation, traffic_message::is_forecast, traffic_message_priv::items, traffic_message::location, traffic_message::priv, traffic_message::receive_time, traffic_message::replaced_count, traffic_message::replaces, traffic_message::start_time, and traffic_message::update_time.

Referenced by traffic_message_new_cancellation(), traffic_message_new_short(), and traffic_xml_end().

◆ traffic_message_new_cancellation()

struct traffic_message* traffic_message_new_cancellation ( char *  id,
time_t  receive_time,
time_t  update_time,
time_t  expiration_time,
struct traffic_location location 
)

Creates a new cancellation traffic_message.

This is a convenience constructor, which creates a cancellation message, without the need to supply members which are not required for cancellation messages. Upon receiving a cancellation message, existing messages with the same ID should be deleted or no longer considered current, and all other attributes ignored.

The traffic_location instances are destroyed when the traffic_message is destroyed, and therefore cannot be shared between multiple traffic_message instances.

It is the responsibility of the caller to destroy all other references passed to this function. This can be done immediately after the function returns.

Parameters
idThe message identifier; existing messages with the same identifier will be replaced by the new message
receive_timeWhen the message was first received by the source, should be kept stable across all updates
update_timeWhen the last update to this message was received by the source
expiration_timeHow long the message should be considered valid
locationThe location to which this message refers

References traffic_message::expiration_time, traffic_message::location, traffic_message::receive_time, traffic_message_new(), and traffic_message::update_time.

Referenced by traffic_dummy_get_messages().

◆ traffic_message_new_short()

struct traffic_message* traffic_message_new_short ( char *  id,
time_t  receive_time,
time_t  update_time,
time_t  expiration_time,
int  is_forecast,
struct traffic_location location,
int  event_count,
struct traffic_event **  events 
)

Creates a new traffic_message.

This is the short version of the constructor, which sets only mandatory members. Other members can be set after the instance is created.

The traffic_event and traffic_location instances are destroyed when the traffic_message is destroyed, and therefore cannot be shared between multiple traffic_message instances.

It is the responsibility of the caller to destroy all other references passed to this function (including the events buffer but not the traffic_event instances). This can be done immediately after the function returns.

Parameters
idThe message identifier; existing messages with the same identifier will be replaced by the new message
receive_timeWhen the message was first received by the source, should be kept stable across all updates
update_timeWhen the last update to this message was received by the source
expiration_timeHow long the message should be considered valid
is_forecastIf false, the message describes a current situation; if true, it describes an expected situation in the future
locationThe location to which this message refers
event_countThe number of events in events
eventsPoints to an array of pointers to the events for this message

References traffic_message::event_count, traffic_message::events, traffic_message::expiration_time, traffic_message::is_forecast, traffic_message::location, traffic_message::receive_time, traffic_message_new(), and traffic_message::update_time.

Referenced by traffic_message_new_single_event().

◆ traffic_message_new_single_event()

struct traffic_message* traffic_message_new_single_event ( char *  id,
time_t  receive_time,
time_t  update_time,
time_t  expiration_time,
int  is_forecast,
struct traffic_location location,
enum event_class  event_class,
enum event_type  type 
)

Creates a new single-event traffic_message.

This is a convenience constructor, which sets only mandatory members. Other members can be set after the instance is created.

The traffic_location instances are destroyed when the traffic_message is destroyed, and therefore cannot be shared between multiple traffic_message instances.

It is the responsibility of the caller to destroy all other references passed to this function. This can be done immediately after the function returns.

Parameters
idThe message identifier; existing messages with the same identifier will be replaced by the new message
receive_timeWhen the message was first received by the source, should be kept stable across all updates
update_timeWhen the last update to this message was received by the source
expiration_timeHow long the message should be considered valid
is_forecastIf false, the message describes a current situation; if true, it describes an expected situation in the future
locationThe location to which this message refers
event_classThe event class (generic category)
typeThe event type, which can be mapped to a string to be displayed to the user

References traffic_event_new_short(), traffic_message_new_short(), and type.

Referenced by traffic_dummy_get_messages().

◆ traffic_message_parse_events()

static struct seg_data * traffic_message_parse_events ( struct traffic_message this_)
static

Parses the events of a traffic message.

Parameters
messageThe message to parse
Returns
A struct seg_data, or NULL if the message contains no usable information

References AF_ALL, AF_CAR, AF_DANGEROUS_GOODS, AF_DELIVERY_TRUCK, AF_MOPED, AF_MOTORIZED_FAST, AF_PUBLIC_BUS, AF_TRANSPORT_TRUCK, seg_data::delay, seg_data::dir, traffic_location::directionality, traffic_event::event_class, event_class_congestion, event_class_delay, event_class_restriction, event_congestion_heavy_traffic, event_congestion_long_queue, event_congestion_queue, event_congestion_slow_traffic, event_congestion_stationary_traffic, event_congestion_traffic_building_up, event_congestion_traffic_congestion, event_congestion_traffic_heavier_than_normal, event_congestion_traffic_much_heavier_than_normal, event_congestion_traffic_problem, traffic_message::event_count, event_delay_delay, event_delay_long_delay, event_delay_several_hours, event_delay_uncertain_duration, event_delay_very_long_delay, event_restriction_batch_service, event_restriction_blocked, event_restriction_blocked_ahead, event_restriction_carriageway_blocked, event_restriction_carriageway_closed, event_restriction_closed, event_restriction_closed_ahead, event_restriction_contraflow, event_restriction_intermittent_closures, event_restriction_lane_blocked, event_restriction_lane_closed, event_restriction_reduced_lanes, event_restriction_single_alternate_line_traffic, traffic_message::events, seg_data::flags, traffic_message::location, quantifier::q_duration, traffic_event::quantifier, traffic_location::road_type, seg_data_new(), traffic_event::si, traffic_event::si_count, si_vehicle_all, si_vehicle_bus, si_vehicle_car, si_vehicle_car_with_caravan, si_vehicle_car_with_trailer, si_vehicle_hazmat, si_vehicle_hgv, si_vehicle_motor, si_vehicle_with_trailer, seg_data::speed, traffic_event::speed, seg_data::speed_factor, seg_data::speed_penalty, traffic_suppl_info::type, traffic_event::type, and quantifier::u.

Referenced by tm_rect_new(), traffic_get_stored_messages(), traffic_message_restore_segments(), and traffic_process_messages_int().

◆ traffic_message_remove_item_data()

static void traffic_message_remove_item_data ( struct traffic_message old,
struct traffic_message new,
struct route route 
)
static

Removes message data from the items associated with a message.

Removing message data also triggers an update of the affected items’ attributes.

It is possible to skip items associated with a particular message from being removed by passing that message as the new argument. This is used for message updates, as this function is called after the items associated with both the old and the new message have already been updated. Skipping items referenced by new ensures that message data is only stripped from items which are no longer being referenced by the updated message.

If the IDs of old and new differ, new is ignored.

Parameters
oldThe message whose data it so be removed from its associated items
newIf non-NULL, items referenced by this message will be skipped, see description
routeThe route affected by the changes

References traffic_message::id, traffic_message_priv::items, item_priv::message_data, item_msg_priv::message_id, traffic_message::priv, item::priv_data, and tm_item_update_attrs().

Referenced by traffic_process_messages_int().

◆ traffic_message_restore_segments()

static int traffic_message_restore_segments ( struct traffic_message this_,
struct mapset ms,
struct map map,
struct route route 
)
static

Restores segments associated with a traffic message from cached data.

This reads textfile map data and compares it to data in the current map set. If one or more items (identified by their ID) are no longer present in the map, or their coordinates no longer match, the cached data is discarded and the location needs to be expanded into a set of segments as for a new message. Otherwise the cached segments are added to the traffic map.

While this operation does require extensive examination of map data, it is still less expensive than expanding the location from scratch, as the most expensive operation in the latter is routing between the points involved.

Parameters
this_The traffic message
msThe mapset to use for matching
dataData for the segments to be added to the map, in textfile format
mapThe traffic map
routeThe route affected by the changes
Returns
true if the locations were matched successfully, false if there was a failure.

References AF_SEGMENTED, AF_SPEED_LIMIT, attr_from_line(), attr_list_dup(), attr_new_from_text(), attr::attrs, parsed_item::attrs, seg_data::attrs, parsed_item::coord_count, coord_parse(), parsed_item::coords, dbg, default_flags, parsed_item::delay, parsed_item::flags, traffic_message::id, item::id_hi, parsed_item::id_hi, item::id_lo, parsed_item::id_lo, parsed_item::is_matched, item, item_attr_get(), item_attr_rewind(), item_coord_get(), item_coord_rewind(), item_default_flags_value, item_from_name(), item_get_default_flags(), traffic_message_priv::items, traffic_message::location, lvl_debug, lvl_warning, map_get_attr(), map_projection(), map_rect_destroy(), map_rect_get_item(), map_rect_new(), map_selection_destroy(), mapset_close(), mapset_next(), mapset_open(), name, attr::num, parsed_item_destroy(), startup::pos, traffic_location::priv, traffic_message::priv, projection_mg, traffic_location::road_type, route_item_first, route_item_last, TEXTFILE_LINE_SIZE, tm_add_item(), tm_item_add_message_data(), traffic_get_item_speed(), traffic_location_get_rect(), traffic_location_set_enclosing_rect(), traffic_message_parse_events(), traffic_location_priv::txt_data, item::type, type, parsed_item::type, attr::u, value, coord::x, and coord::y.

Referenced by tm_rect_new(), and traffic_process_messages_int().

◆ traffic_new()

static struct traffic * traffic_new ( struct attr parent,
struct attr **  attrs 
)
static

Instantiates the traffic plugin.

At a minimum, attrs must contain a type attribute matching one of the available traffic plugins.

Parameters
parentThe parent, usually the Navit instance
attrsThe attributes for the plugin
Returns
A traffic instance.

References attr_search(), attr_to_name(), attr::attrs, traffic::callback, callback_cast, callback_new_1, cbl, dbg, event_add_timeout(), traffic_methods::get_messages, lvl_debug, lvl_error, traffic::meth, traffic::navit, navit_object_destroy(), navit_object_new(), traffic::priv, traffic::shared, attr::str, traffic::timeout, traffic_func, traffic_loop(), traffic_set_shared(), and attr::u.

◆ traffic_point_destroy()

void traffic_point_destroy ( struct traffic_point this_)

Destroys a traffic_point.

This will release the memory used by the traffic_point and all related data.

A traffic_point is usually destroyed together with its parent traffic_location, thus it is usually not necessary to call this destructor directly.

Parameters
this_The point

References traffic_point::junction_name, traffic_point::junction_ref, and traffic_point::tmc_id.

Referenced by traffic_location_destroy().

◆ traffic_point_equals()

static int traffic_point_equals ( struct traffic_point l,
struct traffic_point r 
)
static

Whether two traffic points are equal.

Comparison is done solely on coordinates and requires a precise match. This can result in two points being reported as not equal, even though the locations using these points may translate to the same segments later.

Returns
true if l and r are equal, false if not

References traffic_point::coord, coord_geo::lat, and coord_geo::lng.

Referenced by traffic_location_equals().

◆ traffic_point_match_attributes()

static int traffic_point_match_attributes ( struct traffic_point this_,
struct item item 
)
static

Determines the degree to which the attributes of a point and a map item match.

The result of this method is used to match a location to a map item. Its result is a score—the higher the score, the better the match.

To calculate the score, all supplied attributes are examined and points are given for each attribute which is defined for the location. An exact match adds 4 points, a partial match adds 2. Values of 1 and 3 are added where additional granularity is needed. The number of points attained is divided by the maximum number of points attainable, and the result is returned as a percentage value.

If no points can be attained (because no attributes which must match are supplied), the score is 0 for any item supplied.

Parameters
this_The traffic point
itemThe map item
Returns
The score, as a percentage value

References compare_name_systematic(), item_attr_get(), item_attr_rewind(), traffic_point::junction_name, traffic_point::junction_ref, MAX_MISMATCH, attr::str, and attr::u.

Referenced by traffic_location_get_matching_points().

◆ traffic_point_match_segment_attributes()

static int traffic_point_match_segment_attributes ( struct traffic_point this_,
struct route_graph_point p,
struct route_graph_point start,
int  match_start 
)
static

Determines the degree to which the attributes of a point match those of the segments connecting to it.

The result of this method is used to match a location to a map item. Its result is a score—the higher the score, the better the match.

To calculate the score, this method iterates over all segments which begin or end at p. The junction_name member of the location is compared against the name of the segment, and the highest score for any segment is returned. Currently the name must match completely, resulting in a score of 100, while everything else is considered a mismatch (with a score of 0). Future versions may introduce support for partial matches, with the score indicating the quality of the match.

Segments which are part of the route are treated in a different manner, as the direction in which the segment is traversed (not the direction of the segment itself) is taken into account, which is needed to govern whether the matched segment ends up being part of the route or not.

In some cases, this_ refers to a point which is actually a segment (such as a bridge or tunnel), which we want to include in the route. In other cases, this_ refers to an intersection with another road, and the junction name is the name of the other road; these segments need to be excluded from the route.

This is controlled by the match_start argument: if true, we are evaluating the start point of a route, else we are evaluating its end point. To include the matched segment in the route, only the first point (whose seg member points to the segment) will match for the start point, the opposite is true for the end point. To exclude the matched segment, this logic is reversed.

A heuristic is in place to distinguish whether or not we want the matched segment included.

If no points can be attained (because no attributes which must match are supplied), the score is 0 for any point.

Parameters
this_The traffic point
pThe point shared by all segments to examine
startThe first point of the path
match_startTrue to evaluate for the start point of a route, false for the end point
Returns
The score, as a percentage value

References compare_name_systematic(), route_graph_segment::data, dbg, route_graph_segment::end, route_graph_segment::end_next, item::id_hi, item::id_lo, item, route_segment_data::item, item_attr_get(), item_attr_rewind(), traffic_point::junction_name, lvl_debug, item::map, map_rect_destroy(), map_rect_get_item_byid(), map_rect_new(), p, route_graph_point::seg, route_graph_point::start, route_graph_segment::start, route_graph_segment::start_next, attr::str, and attr::u.

Referenced by traffic_location_get_point_match().

◆ traffic_point_new()

struct traffic_point* traffic_point_new ( float  lon,
float  lat,
char *  junction_name,
char *  junction_ref,
char *  tmc_id 
)

Creates a new traffic_point.

It is the responsibility of the caller to destroy all references passed to this function. This can be done immediately after the function returns.

Parameters
lonThe longitude, as reported by the source, in GPS coordinates
latThe latitude, as reported by the source, in GPS coordinates
junction_nameThe name of the motorway junction this point refers to, NULL if not applicable
junction_refThe reference number of the motorway junction this point refers to, NULL if not applicable
tmc_idThe TMC identifier of the point, if the location was obtained via TMC, or NULL if not applicable

References traffic_point::coord, traffic_point::junction_name, traffic_point::junction_ref, coord_geo::lat, lat, coord_geo::lng, and traffic_point::tmc_id.

Referenced by traffic_dummy_get_messages(), traffic_point_new_short(), and traffic_xml_end().

◆ traffic_point_new_short()

struct traffic_point* traffic_point_new_short ( float  lon,
float  lat 
)

Creates a new traffic_point.

This is the short version of the constructor, which sets only mandatory members. Other members can be set after the instance is created.

Parameters
lonThe longitude, as reported by the source, in GPS coordinates
latThe latitude, as reported by the source, in GPS coordinates

References lat, and traffic_point_new().

◆ traffic_process_messages()

void traffic_process_messages ( struct traffic this_,
struct traffic_message **  messages 
)

Processes new traffic messages.

Calling this method delivers new messages in a “push” manner (as opposed to the “pull” fashion of calling a plugin method).

Messages which are past their expiration timestamp are skipped, and the flags in the return value are set only if at least one valid message is found.

Parameters
this_The traffic instance
messagesThe new messages

References callback_cast, callback_destroy(), callback_new_2, event_add_idle(), event_remove_idle(), traffic::idle_cb, traffic::idle_ev, traffic_shared_priv::message_queue, traffic::shared, and traffic_process_messages_int().

Referenced by request_navit_traffic_inject(), and traffic_traff_android_on_feed_received().

◆ traffic_process_messages_int()

static int traffic_process_messages_int ( struct traffic this_,
int  flags 
)
static

Processes new traffic messages.

This is the internal backend for traffic_process_messages(). It is also used internally.

The behavior of this function can be controlled via flags.

PROCESS_MESSAGES_PURGE_EXPIRED causes expired messages to be purged from the message store after new messages have been processed. It is intended to be used with timer-triggered calls.

PROCESS_MESSAGES_NO_DUMP_STORE prevents saving of the message store to disk, intended to be used when reading stored message data on startup.

Traffic messages are always read from this->shared->message_queue. It can be empty, which makes sense e.g. when the PROCESS_MESSAGES_PURGE_EXPIRED flag is used, to just purge expired messages.

Parameters
this_The traffic instance
flagsFlags, see description
Returns
A combination of flags, MESSAGE_UPDATE_MESSAGES indicating that new messages were processed and MESSAGE_UPDATE_SEGMENTS that segments were changed

References map_selection::c_rect, callback_destroy(), coord_rect_overlap(), data, dbg, event_remove_idle(), traffic_message::expiration_time, message::id, traffic_message::id, traffic::idle_cb, traffic::idle_ev, traffic_message_priv::items, traffic_message::location, lvl_debug, traffic_shared_priv::map, map_selection_destroy(), traffic_shared_priv::message_queue, MESSAGE_UPDATE_MESSAGES, MESSAGE_UPDATE_SEGMENTS, traffic_shared_priv::messages, traffic_shared_priv::ms, traffic::navit, navit_draw_async(), navit_get_ready(), map_selection::next, attr::num, traffic_message::priv, map_methods::pro, PROCESS_MESSAGES_NO_DUMP_STORE, PROCESS_MESSAGES_PURGE_EXPIRED, traffic_message::replaces, route_get_attr(), route_get_pos(), route_get_selection(), route_recalculate_partial(), route_status_destination_set, traffic_shared_priv::rt, seg_data_equals(), traffic::shared, TIME_SLICE, tm_dump_to_textfile(), traffic_dump_messages_to_xml(), traffic_location_equals(), traffic_location_get_rect(), traffic_location_set_enclosing_rect(), traffic_map_meth, traffic_message_add_segments(), traffic_message_destroy(), traffic_message_dump_to_stderr(), traffic_message_parse_events(), traffic_message_remove_item_data(), traffic_message_restore_segments(), attr::u, and map_selection::u.

Referenced by traffic_get_map(), traffic_loop(), and traffic_process_messages().

◆ traffic_route_append()

static struct route_graph_segment* traffic_route_append ( struct route_graph rg,
struct route_graph_segment last,
struct route_graph_point end 
)
static

Extends the route beyond its end point.

This function follows the road beginning at end, stopping at the next junction. It can be called again on the result, again extending it to the next junction.

To follow the road, each segment is compared to last and the segment whose attributes match it is chosen, provided such a segment can be determined without ambiguity.

When the function returns, all points added to the route will have their seg member set. To append the new stretch to the route, set the seg member of its last point to the return value. After that, the extended route can be walked in the usual manner.

The value of each new point is the value of its predecessor on the route mins the length of the segment which links the two points. Point values thus continue to decrease along the route, allowing comparisons or difference calculations to be performed on the extended route. Note that this may result in points having negative values.

Parameters
rgThe flooded route graph
lastThe last segment in the current route graph (either the start or the end member of this segment must be equal to the end argument)
endThe last point of the current route graph (the seg member of this point must be NULL)
Returns
The next segment in the route, or NULL if the route cannot be extended.

References AF_ONEWAY, AF_ONEWAYREV, dbg, route_graph_point::end, route_graph_segment::end, item_is_equal_id, lvl_debug, lvl_error, p, RP_TURN_RESTRICTION, route_graph_segment::start, and route_graph_point::value.

Referenced by traffic_message_add_segments().

◆ traffic_route_flood_graph()

static struct route_graph_point * traffic_route_flood_graph ( struct route_graph rg,
struct seg_data data,
struct coord c_start,
struct coord c_dst,
struct route_graph_point start_existing 
)
static

Determines the path between two reference points in a route graph.

The reference points from and to are the beginning and end of the path and do not necessarily coincide with the from and to members of the location. For a point location with an auxiliary point, one will instead be the at member of the location; when examining the opposite direction of a bidirectional location, from and to will be swapped with respect to the location.

The coordinates contained in the reference points are typically approximate, i.e. they do not precisely coincide with a point in the route graph.

When this function returns, the route graph will be flooded, i.e. every point will have a cost assigned to it and the seg member for each point will be set, indicating the next segment on which to proceed in order to reach the destination. For the last point in the graph, seg will be NULL. Unlike in common routing, the last point will have a nonzero cost if to does not coincide with a point in the route graph.

The cost of each node represents the cost to reach to. The cost is calculated in traffic_route_get_seg_cost() for actual segments, and distance (with a penalty factor) for the offroad connection from the last point in the graph to to.

To obtain the path, start with the return value. Its seg member points to the next segment. Either the start or the end value of that segment will coincide with the point currently being examined; the other of the two is the point at the other end. Repeat this until you reach a point whose seg member is NULL.

This function can be run multiple times against the same route graph but with different reference points. It is safe to call with NULL passed for one or both reference points, in which case NULL will be returned.

The caller is responsible for freeing up the data structures passed to this function when they are no longer needed.

Parameters
rgThe route graph
dataData for the segments added to the map
c_startStart coordinates
c_dstDestination coordinates
start_existingStart point of an existing route (whose points will not be used)
Returns
The point in the route graph at which the path begins, or NULL if no path was found.

References route_graph_point::c, data, dbg, route_graph_point::el, route_graph_segment::end, route_graph_segment::end_next, fh_deleteheap(), fh_extractmin(), fh_insertkey(), fh_makekeyheap(), fh_replacekey(), route_graph::hash, HASH_SIZE, lvl_debug, p, PENALTY_OFFROAD, projection_mg, RP_TURN_RESTRICTION, route_graph_point::seg, route_graph_segment::start, route_graph_segment::start_next, traffic_route_get_seg_cost(), transform_distance(), and route_graph_point::value.

Referenced by traffic_message_add_segments().

◆ traffic_route_get_seg_cost()

static int traffic_route_get_seg_cost ( struct route_graph_segment over,
struct seg_data data,
int  dir 
)
static

Returns the cost of the segment in the given direction.

The cost is calculated based on the length of the segment and a penalty which depends on the score. A segment with the maximum score of 100 is not penalized, i.e. its cost is equal to its length. A segment with a zero score is penalized with a factor of PENALTY_SEGMENT_MATCH. For scores in between, a penalty factor between 1 and PENALTY_SEGMENT_MATCH is applied.

If the segment is impassable in the given direction, the cost is always INT_MAX.

Parameters
overThe segment
dataData for the segments added to the map
dirThe direction (positive numbers indicate positive direction)
Returns
The cost of the segment

References AF_ALL, AF_ONEWAY, AF_ONEWAYREV, data, route_graph_segment::data, route_graph_segment::end, route_graph_point::flags, route_segment_data::flags, route_segment_data::item, route_segment_data::len, PENALTY_SEGMENT_MATCH, route_item_first, route_item_last, RP_TURN_RESTRICTION, route_segment_data::score, route_graph_segment::start, and item::type.

Referenced by traffic_route_flood_graph().

◆ traffic_route_prepend()

static struct route_graph_point* traffic_route_prepend ( struct route_graph rg,
struct route_graph_point start 
)
static

Extends the route beyond its start point.

This function follows the road leading towards start backwards, stopping at the next junction. It can be called again on the result, again extending it to the next junction.

To follow the road, each segment is compared to start->seg and the segment whose attributes match it is chosen, provided such a segment can be determined without ambiguity.

When the function returns, all points added to the route will have their seg member set so the extended route can be walked in the usual manner.

Parameters
rgThe flooded route graph
startThe current start of the route
Returns
The start of the extended route, or NULL if the route cannot be extended (in which case start continues to be the start of the route).

References AF_ONEWAY, AF_ONEWAYREV, route_graph_segment::data, dbg, route_graph_point::end, route_graph_segment::end, route_graph_segment::end_next, route_segment_data::flags, route_segment_data::item, item_is_equal_id, route_segment_data::len, lvl_debug, route_graph_point::seg, route_graph_point::start, route_graph_segment::start, route_graph_segment::start_next, item::type, and route_graph_point::value.

Referenced by traffic_message_add_segments().

◆ traffic_set_mapset()

void traffic_set_mapset ( struct traffic this_,
struct mapset ms 
)

Sets the mapset for the traffic plugin.

This sets the mapset from which the segments affected by a traffic report will be retrieved.

Parameters
this_The traffic plugin instance
msThe mapset

References traffic_shared_priv::ms, and traffic::shared.

Referenced by navit_init().

◆ traffic_set_route()

void traffic_set_route ( struct traffic this_,
struct route rt 
)

Sets the route for the traffic plugin.

This sets the route which may get notified by the traffic plugin if traffic distortions change.

References traffic_shared_priv::rt, and traffic::shared.

Referenced by navit_init().

◆ traffic_set_shared()

static void traffic_set_shared ( struct traffic this_)
static

Ensures the traffic instance points to valid shared data.

This method first examines all registered traffic instances to see if one of them has the shared member set. If that is the case, the current instance copies the shared pointer of the other instance. Otherwise a new struct traffic_shared_priv is created and its address stored in shared.

Calling this method on a traffic instance with a non-NULL shared member has no effect.

Parameters
this_The traffic instance

References dbg, attr_iter::iter, lvl_debug, traffic::navit, navit_attr_iter_destroy(), navit_attr_iter_new(), navit_get_attr(), attr::navit_object, traffic::shared, and attr::u.

Referenced by traffic_new().

◆ traffic_suppl_info_destroy()

void traffic_suppl_info_destroy ( struct traffic_suppl_info this_)

Destroys a traffic_suppl_info.

This will release the memory used by the traffic_suppl_info and all related data.

A traffic_suppl_info is usually destroyed together with its parent traffic_event, thus it is usually not necessary to call this destructor directly.

Parameters
this_The supplementary information item

References traffic_suppl_info::quantifier.

Referenced by traffic_event_destroy().

◆ traffic_suppl_info_new()

struct traffic_suppl_info* traffic_suppl_info_new ( enum si_class  si_class,
enum si_type  type,
struct quantifier quantifier 
)

Creates a new traffic_suppl_info.

It is the responsibility of the caller to destroy all references passed to this function. This can be done immediately after the function returns.

Parameters
si_classThe supplementary information class (generic category)
typeThe supplementary information type, which can be mapped to a string to be displayed to the user
quantifierAdditional quantifier for supplementary information types allowing this, or NULL

References traffic_suppl_info::quantifier, traffic_suppl_info::si_class, type, and traffic_suppl_info::type.

Referenced by traffic_xml_start().

◆ traffic_xml_element_destroy()

static void traffic_xml_element_destroy ( struct xml_element this_)
static

Frees up an XML element structure.

This will free up the memory used by the struct and all its members.

References xml_element::names, xml_element::tag_name, xml_element::text, and xml_element::values.

Referenced by traffic_xml_end().

◆ traffic_xml_element_new()

static struct xml_element* traffic_xml_element_new ( const char *  tag_name,
const char **  names,
const char **  values 
)
static

Creates a new XML element structure.

Note that the structure of names and values may differ between XML libraries. Behavior is indicated by the XML_ATTR_DISTANCE constant.

If XML_ATTR_DISTANCE == 1, names and values are two separate arrays, and values[n] is the value that corresponds to names[n].

If XML_ATTR_DISTANCE == 2, attribute names and values are kept in a single array in which names and values alternate, names first. In this case, names points to the array while values points to its second element, i.e. the first value. In this case, value is invalid for an empty array, and dereferencing it may segfault.

Parameters
tag_nameThe tag name
namesAttribute names
valuesAttribute values

References xml_element::names, xml_element::tag_name, xml_element::values, and XML_ATTR_DISTANCE.

Referenced by traffic_xml_start().

◆ traffic_xml_end()

◆ traffic_xml_get_attr()

static char* traffic_xml_get_attr ( const char *  attr,
char **  names,
char **  values 
)
static

Retrieves the value of an XML attribute.

Parameters
nameThe name of the attribute to retrieve
namesAll attribute names
valuesAttribute values (indices correspond to names)
Returns
If names contains name, the corresponding value is returned, else NULL

References xml_element::names, and xml_element::values.

Referenced by traffic_xml_end(), and traffic_xml_start().

◆ traffic_xml_is_tagstack_valid()

static int traffic_xml_is_tagstack_valid ( struct xml_state state)
static

Whether the tag stack represents a hierarchy of elements which is recognized.

Parameters
stateThe XML parser state
Returns
True if the stack is valid, false if invalid. An empty stack is considered invalid.

References xml_element::tag_name, and xml_state::tagstack.

Referenced by traffic_xml_end(), and traffic_xml_start().

◆ traffic_xml_start()

static void traffic_xml_start ( xml_context dummy,
const char *  tag_name,
const char **  names,
const char **  values,
void *  data,
GError **  error 
)
static

Callback function which gets called when an opening tag is encountered.

Parameters
tag_nameThe tag name
namesAttribute names
valuesAttribute values (indices correspond to names)
dataPoints to a struct xml_state holding parser state

References data, dbg, xml_state::is_opened, xml_state::is_valid, lvl_debug, xml_element::names, xml_state::si, si_class_new(), si_type_new(), xml_element::tag_name, xml_state::tagstack, traffic_suppl_info_new(), traffic_xml_element_new(), traffic_xml_get_attr(), traffic_xml_is_tagstack_valid(), and xml_element::values.

Referenced by traffic_get_messages_from_xml_file(), and traffic_get_messages_from_xml_string().

◆ traffic_xml_text()

static void traffic_xml_text ( xml_context dummy,
const char *  text,
gsize  len,
void *  data,
GError **  error 
)
static

Callback function which gets called when character data is encountered.

Parameters
textThe character data (note that the data is not NULL-terminated!)
lenThe number of characters in text
dataPoints to a struct xml_state holding parser state

Referenced by traffic_get_messages_from_xml_file(), and traffic_get_messages_from_xml_string().

Variable Documentation

◆ item_default_flags_value

int item_default_flags_value = AF_ALL

Default value assumed for access flags if we cannot get flags for the item, nor for the item type

Referenced by traffic_location_populate_route_graph(), and traffic_message_restore_segments().

◆ methods_traffic_item

struct item_methods methods_traffic_item
static
Initial value:
= {
NULL,
NULL,
NULL,
}
static void tm_coord_rewind(void *priv_data)
Rewinds the coordinates of the currently selected item.
Definition: traffic.c:1109
static void tm_attr_rewind(void *priv_data)
Rewinds the attributes of the currently selected item.
Definition: traffic.c:1146
static int tm_coord_get(void *priv_data, struct coord *c, int count)
Returns the coordinates of a traffic item.
Definition: traffic.c:1124
static int tm_attr_get(void *priv_data, enum attr_type attr_type, struct attr *attr)
static int tm_type_set(void *priv_data, enum item_type type)
Sets the type of a traffic item.
Definition: traffic.c:1185

Referenced by tm_add_item().

◆ traffic_func

struct object_func traffic_func
Initial value:
= {
attr_traffic,
}
static struct traffic * traffic_new(struct attr *parent, struct attr **attrs)
Instantiates the traffic plugin.
Definition: traffic.c:4603
void traffic_destroy(struct traffic *this_)
Destructor.
Definition: traffic.c:5950
int navit_object_set_attr(struct navit_object *obj, struct attr *attr)
Definition: xmlconfig.c:1370
int navit_object_remove_attr(struct navit_object *obj, struct attr *attr)
Definition: xmlconfig.c:1399
struct attr_iter * navit_object_attr_iter_new(void *unused)
Definition: xmlconfig.c:1328
int navit_object_get_attr(struct navit_object *obj, enum attr_type type, struct attr *attr, struct attr_iter *iter)
Generic get function.
Definition: xmlconfig.c:1361
void navit_object_attr_iter_destroy(struct attr_iter *iter)
Definition: xmlconfig.c:1332
int navit_object_add_attr(struct navit_object *obj, struct attr *attr)
Definition: xmlconfig.c:1377
void * navit_object_unref(struct navit_object *obj)
Definition: xmlconfig.c:1313
struct navit_object * navit_object_ref(struct navit_object *obj)
Definition: xmlconfig.c:1307
void(* object_func_iter_destroy)(struct attr_iter *)
Definition: xmlconfig.h:57
void *(* object_func_new)(struct attr *parent, struct attr **attrs)
Definition: xmlconfig.h:54
int(* object_func_remove_attr)(void *, struct attr *attr)
Definition: xmlconfig.h:60
void *(* object_func_ref)(void *)
Definition: xmlconfig.h:64
struct attr_iter *(* object_func_iter_new)(void *)
Definition: xmlconfig.h:56
int(* object_func_init)(void *)
Definition: xmlconfig.h:61
void *(* object_func_dup)(void *)
Definition: xmlconfig.h:63
int(* object_func_add_attr)(void *, struct attr *attr)
Definition: xmlconfig.h:59
void(* object_func_destroy)(void *)
Definition: xmlconfig.h:62
int(* object_func_set_attr)(void *, struct attr *attr)
Definition: xmlconfig.h:58
int(* object_func_get_attr)(void *, enum attr_type type, struct attr *attr, struct attr_iter *iter)
Definition: xmlconfig.h:55
void *(* object_func_unref)(void *)
Definition: xmlconfig.h:65

Referenced by object_func_lookup(), and traffic_new().

◆ traffic_map_meth

static struct map_methods traffic_map_meth
static
Initial value:
= {
"utf-8",
NULL,
NULL,
NULL,
NULL,
}
@ projection_mg
Definition: projection.h:25
static struct map_rect_priv * tm_rect_new(struct map_priv *priv, struct map_selection *sel)
Opens a new map rectangle on the traffic map.
Definition: traffic.c:939
static void tm_rect_destroy(struct map_rect_priv *mr)
Destroys a map rectangle on the traffic map.
Definition: traffic.c:1005
static int tm_get_attr(struct map_priv *priv, enum attr_type type, struct attr *attr)
Gets an attribute from the traffic map.
Definition: traffic.c:1092
static struct item * tm_get_item_byid(struct map_rect_priv *mr, int id_hi, int id_lo)
Returns the next item with the supplied ID from the traffic map.
Definition: traffic.c:1048
static struct item * tm_get_item(struct map_rect_priv *mr)
Returns the next item from the traffic map.
Definition: traffic.c:1017
static void tm_destroy(struct map_priv *priv)
Destroys (closes) the traffic map.
Definition: traffic.c:926
static struct item * tm_rect_create_item(struct map_rect_priv *mr, enum item_type type)
Creates a new item of the specified type and inserts it into the map.
Definition: traffic.c:1065

Referenced by tm_rect_new(), traffic_map_new(), and traffic_process_messages_int().