Hi all,
Those of you who followed the IRC channel might know that jkoan and I are currently working on adding traffic (i.e. routing around traffic problems) to Navit. Some of it is outlined on the wiki at
https://wiki.navit-project.org/index.php/Category:Traffic.
Currently I am working on matching traffic messages to map segments. A traffic message, simply put, tells us that there is a disruption, say, on the A9 from (coord1) to (coord2). As the source may use a different map than we do, coordinates are only approximate. Attributes (such as road names and categories) can be used to further narrow down the set of candidate ways.
After trying a couple of things, I realized that this will probably require borrowing some route functionality, such as building a route graph and calculating costs. Many of these things are very similar to what route.c does (to the point that some code could be reused), though some things are different.
(Of course there are also TMC location codes, if they are maintained in the map and the message was received via TMC, in which case we’re planning to use them. However, if that particular TMC code is not on the map, or if we’re getting traffic news from a completely different channel, we still need to be able to match coordinates and maybe a few attributes.)
Traffic currently lives in its own core module, traffic.c, with its corresponding header file, traffic.h. The route graph-related code is in route.c but not exported in route.h.
To be able to use this in the traffic module, I currently see three options:
1. Export everything we need, i.e. structs and function prototypes, through route.h: This would do the trick but may not be the cleanest solution.
2. Move all the traffic functionality into route.c/route.h: This would further fatten route.c (which is already quite huge) and is not very clean either, as traffic and route are two quite distinct functionalities that just happen to share some code
3. define a new header file, route_protected.h or the like, from which I export these declarations and which would be included by both route.c and traffic.c, while other modules would import only route.h: Probably cleanest but I’m not sure if this is in any way unexpected for fellow Navit devs.
I have since learned that there is no precedent for two Navit core modules sharing code with each other but not with the rest of the world, so this would be a first. I am leaning towards the third option but would like to hear what other people’s opinions are.