]> git.street.me.uk Git - andy/viking.git/blob - src/vikroutingengine.c
[DOC] Add documentation on new public routing function
[andy/viking.git] / src / vikroutingengine.c
1 /*
2  * viking -- GPS Data and Topo Analyzer, Explorer, and Manager
3  *
4  * Copyright (C) 2012-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  * SECTION:vikroutingengine
23  * @short_description: the base class to describe routing engine
24  * 
25  * The #VikRoutingEngine class is both the interface and the base class
26  * for the hierarchie of routing engines.
27  */
28
29 #ifdef HAVE_CONFIG_H
30 #include "config.h"
31 #endif
32
33 #include <glib.h>
34 #include <glib/gstdio.h>
35 #include <glib/gi18n.h>
36
37 #include "babel.h"
38
39 #include "vikroutingengine.h"
40
41 static void vik_routing_engine_finalize ( GObject *gob );
42 static GObjectClass *parent_class;
43
44 typedef struct _VikRoutingPrivate VikRoutingPrivate;
45 struct _VikRoutingPrivate
46 {
47         gchar *id;
48         gchar *label;
49         gchar *format;
50 };
51
52 #define VIK_ROUTING_ENGINE_PRIVATE(o)  (G_TYPE_INSTANCE_GET_PRIVATE ((o), VIK_ROUTING_ENGINE_TYPE, VikRoutingPrivate))
53
54 /* properties */
55 enum
56 {
57   PROP_0,
58
59   PROP_ID,
60   PROP_LABEL,
61   PROP_FORMAT,
62 };
63
64 G_DEFINE_ABSTRACT_TYPE (VikRoutingEngine, vik_routing_engine, G_TYPE_OBJECT)
65
66 static void
67 vik_routing_engine_set_property (GObject      *object,
68                           guint         property_id,
69                           const GValue *value,
70                           GParamSpec   *pspec)
71 {
72   VikRoutingPrivate *priv = VIK_ROUTING_ENGINE_PRIVATE ( object );
73
74   switch (property_id)
75     {
76     case PROP_ID:
77       g_free (priv->id);
78       priv->id = g_strdup(g_value_get_string (value));
79       break;
80
81     case PROP_LABEL:
82       g_free (priv->label);
83       priv->label = g_strdup(g_value_get_string (value));
84       break;
85
86     case PROP_FORMAT:
87       g_free (priv->format);
88       priv->format = g_strdup(g_value_get_string (value));
89       break;
90
91     default:
92       /* We don't have any other property... */
93       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
94       break;
95     }
96 }
97
98 static void
99 vik_routing_engine_get_property (GObject    *object,
100                           guint       property_id,
101                           GValue     *value,
102                           GParamSpec *pspec)
103 {
104   VikRoutingPrivate *priv = VIK_ROUTING_ENGINE_PRIVATE ( object );
105
106   switch (property_id)
107     {
108     case PROP_ID:
109       g_value_set_string (value, priv->id);
110       break;
111
112     case PROP_LABEL:
113       g_value_set_string (value, priv->label);
114       break;
115
116     case PROP_FORMAT:
117       g_value_set_string (value, priv->format);
118       break;
119
120     default:
121       /* We don't have any other property... */
122       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
123       break;
124     }
125 }
126
127 static void
128 vik_routing_engine_class_init ( VikRoutingEngineClass *klass )
129 {
130   GObjectClass *object_class;
131   VikRoutingEngineClass *routing_class;
132   GParamSpec *pspec = NULL;
133
134   object_class = G_OBJECT_CLASS (klass);
135
136   object_class->set_property = vik_routing_engine_set_property;
137   object_class->get_property = vik_routing_engine_get_property;
138   object_class->finalize = vik_routing_engine_finalize;
139
140   parent_class = g_type_class_peek_parent (klass);
141
142   routing_class = VIK_ROUTING_ENGINE_CLASS ( klass );
143   routing_class->find = NULL;
144
145
146   pspec = g_param_spec_string ("id",
147                                "Identifier",
148                                "The identifier of the routing engine",
149                                "<no-set>" /* default value */,
150                                G_PARAM_CONSTRUCT_ONLY | G_PARAM_READWRITE);
151   g_object_class_install_property (object_class, PROP_ID, pspec);
152   
153   pspec = g_param_spec_string ("label",
154                                "Label",
155                                "The label of the routing engine",
156                                "<no-set>" /* default value */,
157                                G_PARAM_CONSTRUCT_ONLY | G_PARAM_READWRITE);
158   g_object_class_install_property (object_class, PROP_LABEL, pspec);
159     
160   pspec = g_param_spec_string ("format",
161                                "Format",
162                                "The format of the output (see gpsbabel)",
163                                "<no-set>" /* default value */,
164                                G_PARAM_CONSTRUCT_ONLY | G_PARAM_READWRITE);
165   g_object_class_install_property (object_class, PROP_FORMAT, pspec);
166
167   g_type_class_add_private (klass, sizeof (VikRoutingPrivate));
168 }
169
170 static void
171 vik_routing_engine_init ( VikRoutingEngine *self )
172 {
173   VikRoutingPrivate *priv = VIK_ROUTING_ENGINE_PRIVATE (self);
174
175   priv->id = NULL;
176   priv->label = NULL;
177   priv->format = NULL;
178 }
179
180 static void
181 vik_routing_engine_finalize ( GObject *self )
182 {
183   VikRoutingPrivate *priv = VIK_ROUTING_ENGINE_PRIVATE (self);
184
185   g_free (priv->id);
186   priv->id = NULL;
187
188   g_free (priv->label);
189   priv->label = NULL;
190
191   g_free (priv->format);
192   priv->format = NULL;
193
194   G_OBJECT_CLASS(parent_class)->finalize(self);
195 }
196
197 /**
198  * vik_routing_engine_find:
199  * @self: self object
200  * @vtl:
201  * @start: starting point
202  * @end: ending point
203  *
204  * Retrieve a route between two coordinates.
205  * 
206  * Returns: indicates success or not.
207  */
208 int
209 vik_routing_engine_find ( VikRoutingEngine *self, VikTrwLayer *vtl, struct LatLon start, struct LatLon end )
210 {
211         VikRoutingEngineClass *klass;
212         
213         g_return_val_if_fail ( VIK_IS_ROUTING_ENGINE (self), 0 );
214         klass = VIK_ROUTING_ENGINE_GET_CLASS( self );
215         g_return_val_if_fail ( klass->find != NULL, 0 );
216
217         return klass->find( self, vtl, start, end );
218 }
219
220 /**
221  * vik_routing_engine_get_id:
222  * 
223  * Returns: the id of self
224  */
225 gchar *
226 vik_routing_engine_get_id ( VikRoutingEngine *self )
227 {
228   VikRoutingPrivate *priv = VIK_ROUTING_ENGINE_PRIVATE (self);
229
230   return priv->id;
231 }
232
233 /**
234  * vik_routing_engine_get_label:
235  * 
236  * Returns: the label of self
237  */
238 gchar *
239 vik_routing_engine_get_label ( VikRoutingEngine *self )
240 {
241   VikRoutingPrivate *priv = VIK_ROUTING_ENGINE_PRIVATE (self);
242
243   return priv->label;
244 }
245
246 /**
247  * vik_routing_engine_get_format:
248  * 
249  * Returns: the format of self
250  */
251 gchar *
252 vik_routing_engine_get_format ( VikRoutingEngine *self )
253 {
254   VikRoutingPrivate *priv = VIK_ROUTING_ENGINE_PRIVATE (self);
255
256   return priv->format;
257 }