]> git.street.me.uk Git - andy/viking.git/blame - src/osrm.c
Remove uneeded (and wrong) finalize functions
[andy/viking.git] / src / osrm.c
CommitLineData
5ae894dc
GB
1/*
2 * viking -- GPS Data and Topo Analyzer, Explorer, and Manager
3 *
4 * Copyright (c) 2013, Guilhem Bonnefille <guilhem.bonnefille@gmail.com>
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 *
20 */
21
22/**
23 * SECTION:osrm
24 * @short_description: the class for OSRM
25 *
26 * The #OsrmRouting class handles OSRM
27 * service as routing engine.
28 *
29 * Technical details are available here:
30 * http://project-osrm.org/
31 */
32
33#ifdef HAVE_CONFIG_H
34#include "config.h"
35#endif
36
37#include <string.h>
38
39#include <glib.h>
40#include <glib/gstdio.h>
41
42#include "osrm.h"
43
44/* See API references: https://github.com/DennisOSRM/Project-OSRM/wiki/Server-api */
45#define OSRM_DIRECTIONS_STRING "router.project-osrm.org/viaroute?loc=%s,%s&loc=%s,%s&output=gpx"
46
47static DownloadMapOptions osrms_routing_options = { FALSE, FALSE, "http://map.project-osrm.org/", 0, NULL };
48
5ae894dc
GB
49static gchar *osrm_routing_get_url_for_coords ( VikRoutingEngine *self, struct LatLon start, struct LatLon end );
50static DownloadMapOptions *osrm_routing_get_download_options ( VikRoutingEngine *self );
51
52G_DEFINE_TYPE (OsrmRouting, osrm_routing, VIK_ROUTING_ENGINE_TYPE)
53
54static void osrm_routing_class_init ( OsrmRoutingClass *klass )
55{
56 GObjectClass *object_class;
57 VikRoutingEngineClass *parent_class;
58
59 object_class = G_OBJECT_CLASS (klass);
60
5ae894dc
GB
61 parent_class = VIK_ROUTING_ENGINE_CLASS (klass);
62
63 parent_class->get_url_for_coords = osrm_routing_get_url_for_coords;
64 parent_class->get_download_options = osrm_routing_get_download_options;
65}
66
67OsrmRouting *osrm_routing_new ()
68{
69 return OSRM_ROUTING ( g_object_new ( OSRM_ROUTING_TYPE,
70 "id", "osrm",
71 "label", "OSRM",
72 "format", "gpx",
73 NULL ) );
74}
75
76static void osrm_routing_init ( OsrmRouting *vlp )
77{
78}
79
5ae894dc
GB
80static DownloadMapOptions *
81osrm_routing_get_download_options ( VikRoutingEngine *self )
82{
83 return &osrms_routing_options;
84}
85
4291d3d3 86static gchar *
5ae894dc
GB
87osrm_routing_get_url_for_coords ( VikRoutingEngine *self, struct LatLon start, struct LatLon end )
88{
89 gchar startlat[G_ASCII_DTOSTR_BUF_SIZE], startlon[G_ASCII_DTOSTR_BUF_SIZE];
90 gchar endlat[G_ASCII_DTOSTR_BUF_SIZE], endlon[G_ASCII_DTOSTR_BUF_SIZE];
91 gchar *url;
92 url = g_strdup_printf(OSRM_DIRECTIONS_STRING,
93 g_ascii_dtostr (startlat, G_ASCII_DTOSTR_BUF_SIZE, (gdouble) start.lat),
94 g_ascii_dtostr (startlon, G_ASCII_DTOSTR_BUF_SIZE, (gdouble) start.lon),
95 g_ascii_dtostr (endlat, G_ASCII_DTOSTR_BUF_SIZE, (gdouble) end.lat),
96 g_ascii_dtostr (endlon, G_ASCII_DTOSTR_BUF_SIZE, (gdouble) end.lon));
97
98 return url;
99}