Routino SVN Repository Browser

Check out the latest version of Routino: svn co http://routino.org/svn/trunk routino

ViewVC logotype

Contents of /branches/destination-access/doc/LIBRARY.txt

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1809 - (show annotations) (download)
Thu Sep 24 17:30:16 2015 UTC (9 years, 5 months ago) by amb
File MIME type: text/plain
File size: 21073 byte(s)
Add the allow_destination options to the API.

1 Routino : Library
2 =================
3
4
5 Library Usage
6 -------------
7
8 This page describes the libroutino shared library that can be compiled
9 from the Routino source code and used in other programs.
10
11 Compilation
12 - - - - - -
13
14 The libroutino shared library is compiled by default when the Routino
15 source code is compiled. There are two versions; a normal version and a
16 'slim' version that uses less memory but is slower. The names of the
17 libraries are libroutino.so and libroutino-slim.so
18
19 Including
20 - - - - -
21
22 To use the Routino library in another program the source code for that
23 program should include the routino.h file. The functions that are
24 available in the library (both versions) are listed in this file along
25 with all of the constants and data types that are required.
26
27 Linking
28 - - - -
29
30 After compiling the program that uses the library it needs to be linked
31 to the library. For gcc this requires adding -lroutino or
32 -lroutino-slim to the linker command line, possibly with a -L...
33 parameter to specify the location of the library.
34
35 Example Library Interface Code
36 - - - - - - - - - - - - - - -
37
38 An example of a program that can link to the libroutino library is
39 provided in the Routino source code called router+lib.c. This is an
40 almost exact re-implementation of the standard Routino router program
41 using the libroutino library.
42
43
44 Library License
45 ---------------
46
47 The source code for the libroutino and libroutino-slim libraries is the
48 GNU Affero General Public License v3 the same as for the rest of the
49 Routino software.
50
51 Linking with AGPLv3 Source Code
52 - - - - - - - - - - - - - - - -
53
54 If libroutino is linked with other APGLv3 code then the same license
55 applies to the combination as to the two parts.
56
57 Linking with GPLv3 Source Code
58 - - - - - - - - - - - - - - -
59
60 The AGPLv3 license is almost identical to the GNU General Public
61 License v3 except that network interaction with an AGPLv3 program
62 requires the same source code access as distributing compiled GPLv3
63 programs. This means that libroutino can be linked or combined with
64 code that is released under the GPLv3 without changing the license of
65 that code.
66
67 If there is no network interaction with the resulting program then the
68 Routino source code can be treated as if it was GPLv3 code for the
69 purposes of distribution and use.
70
71 If there is network interaction with the resulting program then the
72 AGPLv3 license will apply since this is required by section 13 of the
73 GPLv3.
74 The Software Freedom Law Center description of the GPLv3 and AGPLv3
75 licenses describes combining GPLv3 and APGLv3.
76 My understanding is that only when modified Routino code is linked with
77 GPLv3 code does network interaction require the modified Routino code
78 to be released.
79
80 Linking with Other Source Code
81 - - - - - - - - - - - - - - -
82
83 Linking libroutino with code released under any other license must
84 preserve the terms of the Routino license on the combination if the
85 software is distributed or interacted with over a network.
86
87
88 Routino Library API
89 -------------------
90
91 Preprocessor Definitions
92 - - - - - - - - - - - -
93
94 A version number for the Routino API.
95 #define ROUTINO_API_VERSION 8
96
97 Error Definitions
98
99 No error.
100 #define ROUTINO_ERROR_NONE 0
101
102 A function was called without the database variable set.
103 #define ROUTINO_ERROR_NO_DATABASE 1
104
105 A function was called without the profile variable set.
106 #define ROUTINO_ERROR_NO_PROFILE 2
107
108 A function was called without the translation variable set.
109 #define ROUTINO_ERROR_NO_TRANSLATION 3
110
111 The specified database to load did not exist.
112 #define ROUTINO_ERROR_NO_DATABASE_FILES 11
113
114 The specified database could not be loaded.
115 #define ROUTINO_ERROR_BAD_DATABASE_FILES 12
116
117 The specified profiles XML file did not exist.
118 #define ROUTINO_ERROR_NO_PROFILES_XML 13
119
120 The specified profiles XML file could not be loaded.
121 #define ROUTINO_ERROR_BAD_PROFILES_XML 14
122
123 The specified translations XML file did not exist.
124 #define ROUTINO_ERROR_NO_TRANSLATIONS_XML 15
125
126 The specified translations XML file could not be loaded.
127 #define ROUTINO_ERROR_BAD_TRANSLATIONS_XML 16
128
129 The requested profile name does not exist in the loaded XML file.
130 #define ROUTINO_ERROR_NO_SUCH_PROFILE 21
131
132 The requested translation language does not exist in the loaded XML
133 file.
134 #define ROUTINO_ERROR_NO_SUCH_TRANSLATION 22
135
136 There is no highway near the coordinates to place a waypoint.
137 #define ROUTINO_ERROR_NO_NEARBY_HIGHWAY 31
138
139 The profile and database do not work together.
140 #define ROUTINO_ERROR_PROFILE_DATABASE_ERR 41
141
142 The profile being used has not been validated.
143 #define ROUTINO_ERROR_NOTVALID_PROFILE 42
144
145 The user specified profile contained invalid data.
146 #define ROUTINO_ERROR_BAD_USER_PROFILE 43
147
148 The routing options specified are not consistent with each other.
149 #define ROUTINO_ERROR_BAD_OPTIONS 51
150
151 There is a mismatch between the library and caller API version.
152 #define ROUTINO_ERROR_WRONG_API_VERSION 61
153
154 The progress function returned false.
155 #define ROUTINO_ERROR_PROGRESS_ABORTED 71
156
157 A route could not be found to waypoint 1.
158 #define ROUTINO_ERROR_NO_ROUTE_1 1001
159
160 A route could not be found to waypoint 2.
161 #define ROUTINO_ERROR_NO_ROUTE_2 1002
162
163 A route could not be found to waypoint 3.
164 #define ROUTINO_ERROR_NO_ROUTE_3 1003
165
166 Routino Option Definitions
167
168 Calculate the shortest route.
169 #define ROUTINO_ROUTE_SHORTEST 0
170
171 Calculate the quickest route.
172 #define ROUTINO_ROUTE_QUICKEST 1
173
174 Output an HTML route file.
175 #define ROUTINO_ROUTE_FILE_HTML 2
176
177 Output a GPX track file.
178 #define ROUTINO_ROUTE_FILE_GPX_TRACK 4
179
180 Output a GPX route file.
181 #define ROUTINO_ROUTE_FILE_GPX_ROUTE 8
182
183 Output a text file with important junctions.
184 #define ROUTINO_ROUTE_FILE_TEXT 16
185
186 Output a text file with all nodes and segments.
187 #define ROUTINO_ROUTE_FILE_TEXT_ALL 32
188
189 Output a single file type to stdout.
190 #define ROUTINO_ROUTE_FILE_STDOUT 64
191
192 Output a linked list of points containing the HTML file information but
193 as plain text.
194 #define ROUTINO_ROUTE_LIST_HTML 128
195
196 Output a linked list of points containing the HTML file information as
197 plain text and with all points.
198 #define ROUTINO_ROUTE_LIST_HTML_ALL 256
199
200 Output a linked list of points containing the text file information.
201 #define ROUTINO_ROUTE_LIST_TEXT 512
202
203 Output a linked list of points containing the text all file
204 information.
205 #define ROUTINO_ROUTE_LIST_TEXT_ALL 1024
206
207 Linked List Output Point Definitions
208
209 An unimportant, intermediate, node.
210 #define ROUTINO_POINT_UNIMPORTANT 0
211
212 A roundabout exit that is not taken.
213 #define ROUTINO_POINT_RB_NOT_EXIT 1
214
215 An un-interesting junction where the route continues without comment.
216 #define ROUTINO_POINT_JUNCT_CONT 2
217
218 The highway changes type but nothing else happens.
219 #define ROUTINO_POINT_CHANGE 3
220
221 An interesting junction to be described.
222 #define ROUTINO_POINT_JUNCT_IMPORT 4
223
224 The entrance to a roundabout.
225 #define ROUTINO_POINT_RB_ENTRY 5
226
227 The exit from a roundabout.
228 #define ROUTINO_POINT_RB_EXIT 6
229
230 The location of a mini-roundabout.
231 #define ROUTINO_POINT_MINI_RB 7
232
233 The location of a U-turn.
234 #define ROUTINO_POINT_UTURN 8
235
236 A waypoint.
237 #define ROUTINO_POINT_WAYPOINT 9
238
239 Profile Definitions
240
241 A Motorway highway.
242 #define ROUTINO_HIGHWAY_MOTORWAY 1
243
244 A Trunk highway.
245 #define ROUTINO_HIGHWAY_TRUNK 2
246
247 A Primary highway.
248 #define ROUTINO_HIGHWAY_PRIMARY 3
249
250 A Secondary highway.
251 #define ROUTINO_HIGHWAY_SECONDARY 4
252
253 A Tertiary highway.
254 #define ROUTINO_HIGHWAY_TERTIARY 5
255
256 A Unclassified highway.
257 #define ROUTINO_HIGHWAY_UNCLASSIFIED 6
258
259 A Residential highway.
260 #define ROUTINO_HIGHWAY_RESIDENTIAL 7
261
262 A Service highway.
263 #define ROUTINO_HIGHWAY_SERVICE 8
264
265 A Track highway.
266 #define ROUTINO_HIGHWAY_TRACK 9
267
268 A Cycleway highway.
269 #define ROUTINO_HIGHWAY_CYCLEWAY 10
270
271 A Path highway.
272 #define ROUTINO_HIGHWAY_PATH 11
273
274 A Steps highway.
275 #define ROUTINO_HIGHWAY_STEPS 12
276
277 A Ferry highway.
278 #define ROUTINO_HIGHWAY_FERRY 13
279
280 A Paved highway.
281 #define ROUTINO_PROPERTY_PAVED 1
282
283 A Multilane highway.
284 #define ROUTINO_PROPERTY_MULTILANE 2
285
286 A Bridge highway.
287 #define ROUTINO_PROPERTY_BRIDGE 3
288
289 A Tunnel highway.
290 #define ROUTINO_PROPERTY_TUNNEL 4
291
292 A Footroute highway.
293 #define ROUTINO_PROPERTY_FOOTROUTE 5
294
295 A Bicycleroute highway.
296 #define ROUTINO_PROPERTY_BICYCLEROUTE 6
297
298 Type Definitions
299 - - - - - - - -
300
301 Typedef Routino_Database
302
303 A data structure to hold a Routino database loaded from a file (the
304 contents are private).
305
306 typedef struct _Routino_Database Routino_Database
307
308 Typedef Routino_Waypoint
309
310 A data structure to hold a Routino waypoint found within the database
311 (the contents are private).
312
313 typedef struct _Routino_Waypoint Routino_Waypoint
314
315 Typedef Routino_Profile
316
317 A data structure to hold a Routino routing profile (the contents are
318 private).
319
320 typedef struct _Routino_Profile Routino_Profile
321
322 Typedef Routino_Translation
323
324 A data structure to hold a Routino translation (the contents are
325 private).
326
327 typedef struct _Routino_Translation Routino_Translation
328
329 Typedef Routino_UserProfile
330
331 A data structure to hold a routing profile that can be defined by the
332 user.
333
334 typedef struct _Routino_UserProfile Routino_UserProfile
335 struct _Routino_UserProfile
336 {
337 int transport; The type of transport.
338 float highway[14]; A floating point preference for travel on the
339 highway (range 0 to 1).
340 float speed[14]; The maximum speed on each type of highway
341 (km/hour).
342 float props[7]; A floating point preference for ways with this
343 attribute (range 0 to 1).
344 int oneway; A flag to indicate if one-way restrictions apply.
345 int turns; A flag to indicate if turn restrictions apply.
346 float weight; The weight of the vehicle (in tonnes).
347 float height; The height of the vehicle (in metres).
348 float width; The width of vehicle (in metres).
349 float length; The length of vehicle (in metres).
350 }
351
352 Typedef Routino_Output
353
354 Forward declaration of the Routino_Output data type.
355
356 typedef struct _Routino_Output Routino_Output
357
358 Type struct _Routino_Output
359
360 A linked list output of the calculated route whose contents depend on
361 the ROUTINO_ROUTE_LIST_* options selected.
362
363 struct _Routino_Output
364 {
365 Routino_Output* next; A pointer to the next route section.
366 float lon; The longitude of the point (radians).
367 float lat; The latitude of the point (radians).
368 float dist; The total distance travelled (kilometres) up to the
369 point.
370 float time; The total journey time (seconds) up to the point.
371 float speed; The speed (km/hr) for this section of the route
372 (ROUTINO_ROUTE_LIST_TEXT_ALL format only).
373 int type; The type of point (one of the ROUTINO_POINT_* values).
374 int turn; The amount to turn (degrees) for the next section of the
375 route (ROUTINO_ROUTE_LIST_TEXT or ROUTINO_ROUTE_LIST_HTML
376 or ROUTINO_ROUTE_LIST_HTML_ALL format).
377
378 int bearing; The compass direction (degrees) for the next section
379 of the route.
380 char* name; The name of the next section of the route
381 (ROUTINO_ROUTE_LIST_TEXT or ROUTINO_ROUTE_LIST_HTML
382 or ROUTINO_ROUTE_LIST_HTML_ALL format) or previous
383 section of the route (ROUTINO_ROUTE_LIST_TEXT_ALL
384 format).
385 char* desc1; The first part of the description of the next
386 section of route (ROUTINO_ROUTE_LIST_HTML or
387 ROUTINO_ROUTE_LIST_HTML format).
388 char* desc2; The second part of the description of the next
389 section of route (ROUTINO_ROUTE_LIST_HTML or
390 ROUTINO_ROUTE_LIST_HTML format).
391 char* desc3; The third part of the description, the total
392 distance and time at the end of the next section of
393 route (ROUTINO_ROUTE_LIST_HTML or
394 ROUTINO_ROUTE_LIST_HTML format).
395 }
396
397 Typedef Routino_ProgressFunc
398
399 A type of function that can be used as a callback to indicate routing
400 progress, if it returns false the router stops.
401
402 typedef int (*Routino_ProgressFunc)(double complete)
403
404 Variable Definitions
405 - - - - - - - - - -
406
407 Global Variable Routino_APIVersion
408
409 Contains the libroutino API version number.
410
411 int Routino_APIVersion
412
413 Global Variable Routino_errno
414
415 Contains the error number of the most recent Routino function (one of
416 the ROUTINO_ERROR_* values).
417
418 int Routino_errno
419
420 Function Definitions
421 - - - - - - - - - -
422
423 Global Function Routino_CalculateRoute()
424
425 Calculate a route using a loaded database, chosen profile, chosen
426 translation and set of waypoints.
427
428 Routino_Output* Routino_CalculateRoute ( Routino_Database* database,
429 Routino_Profile* profile, Routino_Translation* translation,
430 Routino_Waypoint** waypoints, int nwaypoints, int options,
431 Routino_ProgressFunc progress )
432
433 Routino_Output* Routino_CalculateRoute
434 Returns the head of a linked list of route data (if requested)
435 or NULL.
436
437 Routino_Database* database
438 The loaded database to use.
439
440 Routino_Profile* profile
441 The chosen routing profile to use.
442
443 Routino_Translation* translation
444 The chosen translation information to use.
445
446 Routino_Waypoint** waypoints
447 The set of waypoints.
448
449 int nwaypoints
450 The number of waypoints.
451
452 int options
453 The set of routing options (ROUTINO_ROUTE_*) ORed together.
454
455 Routino_ProgressFunc progress
456 A function to be called occasionally to report progress or NULL.
457
458 Global Function Routino_Check_API_Version()
459
460 Check the version of the library used by the caller against the library
461 version
462
463 int Routino_Check_API_Version ( int caller_version )
464
465 int Routino_Check_API_Version
466 Returns ROUTINO_ERROR_NONE if OK or ROUTINO_ERROR_WRONG_VERSION
467 if there is an error.
468
469 int caller_version
470 The version of the API used in the caller.
471
472 This function should not be called directly, use the macro
473 Routino_CheckAPIVersion() which takes no arguments.
474
475 A wrapper function to simplify the API version check.
476 #define Routino_CheckAPIVersion()
477
478 Global Function Routino_CreateProfileFromUserProfile()
479
480 Create a fully formed Routino Profile from a Routino User Profile.
481
482 Routino_Profile* Routino_CreateProfileFromUserProfile (
483 Routino_UserProfile* profile )
484
485 Routino_Profile* Routino_CreateProfileFromUserProfile
486 Returns an allocated Routino Profile.
487
488 Routino_UserProfile* profile
489 The user specified profile to convert (not modified by this).
490
491 Global Function Routino_CreateUserProfileFromProfile()
492
493 Create a Routino User Profile from a Routino Profile loaded from an XML
494 file.
495
496 Routino_UserProfile* Routino_CreateUserProfileFromProfile (
497 Routino_Profile* profile )
498
499 Routino_UserProfile* Routino_CreateUserProfileFromProfile
500 Returns an allocated Routino User Profile.
501
502 Routino_Profile* profile
503 The Routino Profile to convert (not modified by this).
504
505 Global Function Routino_DeleteRoute()
506
507 Delete the linked list created by Routino_CalculateRoute.
508
509 void Routino_DeleteRoute ( Routino_Output* output )
510
511 Routino_Output* output
512 The output to be deleted.
513
514 Global Function Routino_FindWaypoint()
515
516 Finds the nearest point in the database to the specified latitude and
517 longitude.
518
519 Routino_Waypoint* Routino_FindWaypoint ( Routino_Database* database,
520 Routino_Profile* profile, double latitude, double longitude, int
521 allow_destination )
522
523 Routino_Waypoint* Routino_FindWaypoint
524 Returns a pointer to a newly allocated Routino waypoint or NULL
525 if none could be found.
526
527 Routino_Database* database
528 The Routino database to use.
529
530 Routino_Profile* profile
531 The Routino profile to use.
532
533 double latitude
534 The latitude in degrees of the point.
535
536 double longitude
537 The longitude in degrees of the point.
538
539 int allow_destination
540 The option to allow routing to follow highways tagged as
541 'destination'.
542
543 Global Function Routino_FreeXMLProfiles()
544
545 Free the internal memory that was allocated for the Routino profiles
546 loaded from the XML file.
547
548 void Routino_FreeXMLProfiles ( void )
549
550 Global Function Routino_FreeXMLTranslations()
551
552 Free the internal memory that was allocated for the Routino
553 translations loaded from the XML file.
554
555 void Routino_FreeXMLTranslations ( void )
556
557 Global Function Routino_GetProfile()
558
559 Select a specific routing profile from the set of Routino profiles that
560 have been loaded from the XML file or NULL in case of an error.
561
562 Routino_Profile* Routino_GetProfile ( const char* name )
563
564 Routino_Profile* Routino_GetProfile
565 Returns a pointer to an internal data structure - do not free.
566
567 const char* name
568 The name of the profile to select.
569
570 Global Function Routino_GetProfileNames()
571
572 Return a list of the profile names that have been loaded from the XML
573 file.
574
575 char** Routino_GetProfileNames ( void )
576
577 char** Routino_GetProfileNames
578 Returns a NULL terminated list of strings - all allocated.
579
580 Global Function Routino_GetTranslation()
581
582 Select a specific translation from the set of Routino translations that
583 have been loaded from the XML file or NULL in case of an error.
584
585 Routino_Translation* Routino_GetTranslation ( const char* language )
586
587 Routino_Translation* Routino_GetTranslation
588 Returns a pointer to an internal data structure - do not free.
589
590 const char* language
591 The language to select (as a country code, e.g. 'en', 'de') or
592 an empty string for the first in the file or NULL for the
593 built-in English version.
594
595 Global Function Routino_GetTranslationLanguageFullNames()
596
597 Return a list of the full names of the translation languages that have
598 been loaded from the XML file.
599
600 char** Routino_GetTranslationLanguageFullNames ( void )
601
602 char** Routino_GetTranslationLanguageFullNames
603 Returns a NULL terminated list of strings - all allocated.
604
605 Global Function Routino_GetTranslationLanguages()
606
607 Return a list of the translation languages that have been loaded from
608 the XML file.
609
610 char** Routino_GetTranslationLanguages ( void )
611
612 char** Routino_GetTranslationLanguages
613 Returns a NULL terminated list of strings - all allocated.
614
615 Global Function Routino_LoadDatabase()
616
617 Load a database of files for Routino to use for routing.
618
619 Routino_Database* Routino_LoadDatabase ( const char* dirname, const
620 char* prefix )
621
622 Routino_Database* Routino_LoadDatabase
623 Returns a pointer to the database.
624
625 const char* dirname
626 The pathname of the directory containing the database files.
627
628 const char* prefix
629 The prefix of the database files.
630
631 Global Function Routino_ParseXMLProfiles()
632
633 Parse a Routino XML file containing profiles, must be called before
634 selecting a profile.
635
636 int Routino_ParseXMLProfiles ( const char* filename )
637
638 int Routino_ParseXMLProfiles
639 Returns non-zero in case of an error or zero if there was no
640 error.
641
642 const char* filename
643 The full pathname of the file to read.
644
645 Global Function Routino_ParseXMLTranslations()
646
647 Parse a Routino XML file containing translations, must be called before
648 selecting a translation.
649
650 int Routino_ParseXMLTranslations ( const char* filename )
651
652 int Routino_ParseXMLTranslations
653 Returns non-zero in case of an error or zero if there was no
654 error.
655
656 const char* filename
657 The full pathname of the file to read.
658
659 Global Function Routino_UnloadDatabase()
660
661 Close the database files that were opened by a call to
662 Routino_LoadDatabase().
663
664 void Routino_UnloadDatabase ( Routino_Database* database )
665
666 Routino_Database* database
667 The database to close.
668
669 Global Function Routino_ValidateProfile()
670
671 Validates that a selected routing profile is valid for use with the
672 selected routing database.
673
674 int Routino_ValidateProfile ( Routino_Database* database,
675 Routino_Profile* profile )
676
677 int Routino_ValidateProfile
678 Returns zero if OK or something else in case of an error.
679
680 Routino_Database* database
681 The Routino database to use.
682
683 Routino_Profile* profile
684 The Routino profile to validate.
685
686 --------
687
688 Copyright 2015 Andrew M. Bishop.