Fix:Core:Cleaned up useless vehicle parameter
[navit-package] / navit / vehicle / null / vehicle_null.c
1 /** @file vehicle_null.c
2  * @brief null uses dbus signals
3  *
4  * Navit, a modular navigation system.
5  * Copyright (C) 2005-2008 Navit Team
6  *
7  * This program is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU General Public License
9  * version 2 as published by the Free Software Foundation.
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
18  * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
19  * Boston, MA  02110-1301, USA.
20  *
21  * @Author Tim Niemeyer <reddog@mastersword.de>
22  * @date 2008-2009
23  */
24
25 #include <config.h>
26 #include <string.h>
27 #include <glib.h>
28 #include <math.h>
29 #include <time.h>
30 #include "debug.h"
31 #include "callback.h"
32 #include "plugin.h"
33 #include "coord.h"
34 #include "item.h"
35 #include "vehicle.h"
36
37 struct vehicle_priv {
38         struct callback_list *cbl;
39         struct coord_geo geo;
40         double speed;
41         double direction;
42         double height;
43         double radius;
44         int fix_type;
45         time_t fix_time;
46         char fixiso8601[128];
47         int sats;
48         int sats_used;
49         int have_coords;
50         struct attr ** attrs;
51 };
52
53 /**
54  * @brief Free the null_vehicle
55  * 
56  * @param priv
57  * @returns nothing
58  */
59 static void
60 vehicle_null_destroy(struct vehicle_priv *priv)
61 {
62         dbg(0,"enter\n");
63         g_free(priv);
64 }
65
66 /**
67  * @brief Provide the outside with information
68  * 
69  * @param priv
70  * @param type TODO: What can this be?
71  * @param attr
72  * @returns true/false
73  */
74 static int
75 vehicle_null_position_attr_get(struct vehicle_priv *priv,
76                                enum attr_type type, struct attr *attr)
77 {
78         dbg(1,"enter %s\n",attr_to_name(type));
79         switch (type) {
80 #if 0
81         case attr_position_fix_type:
82                 attr->u.num = priv->fix_type;
83                 break;
84 #endif
85         case attr_position_height:
86                 attr->u.numd = &priv->height;
87                 break;
88         case attr_position_speed:
89                 attr->u.numd = &priv->speed;
90                 break;
91         case attr_position_direction:
92                 attr->u.numd = &priv->direction;
93                 break;
94         case attr_position_radius:
95                 attr->u.numd = &priv->radius;
96                 break;
97
98 #if 0
99         case attr_position_qual:
100                 attr->u.num = priv->sats;
101                 break;
102         case attr_position_sats_used:
103                 attr->u.num = priv->sats_used;
104                 break;
105 #endif
106         case attr_position_coord_geo:
107                 attr->u.coord_geo = &priv->geo;
108                 if (!priv->have_coords)
109                         return 0;
110                 break;
111         case attr_position_time_iso8601:
112                 attr->u.str=priv->fixiso8601;
113                 break;
114         default:
115                 return 0;
116         }
117         dbg(1,"ok\n");
118         attr->type = type;
119         return 1;
120 }
121
122 static int
123 vehicle_null_set_attr(struct vehicle_priv *priv, struct attr *attr)
124 {
125         switch (attr->type) {
126         case attr_position_speed:
127                 priv->speed=*attr->u.numd;
128                 break;
129         case attr_position_direction:
130                 priv->direction=*attr->u.numd;
131                 break;
132         case attr_position_coord_geo:
133                 priv->geo=*attr->u.coord_geo;
134                 break;
135         default:
136                 return 0;
137         }
138         callback_list_call_attr_0(priv->cbl, attr->type);
139         return 1;
140 }
141
142
143 struct vehicle_methods vehicle_null_methods = {
144         vehicle_null_destroy,
145         vehicle_null_position_attr_get,
146         vehicle_null_set_attr,
147 };
148
149 /**
150  * @brief Create null_vehicle
151  * 
152  * @param meth
153  * @param cbl
154  * @param attrs
155  * @returns vehicle_priv
156  */
157 static struct vehicle_priv *
158 vehicle_null_new_null(struct vehicle_methods *meth,
159                         struct callback_list *cbl,
160                         struct attr **attrs)
161 {
162         struct vehicle_priv *ret;
163
164         dbg(0, "enter\n");
165         ret = g_new0(struct vehicle_priv, 1);
166         ret->cbl = cbl;
167         *meth = vehicle_null_methods;
168         dbg(0, "return\n");
169         return ret;
170 }
171
172 /**
173  * @brief register vehicle_null
174  * 
175  * @returns nothing
176  */
177 void
178 plugin_init(void)
179 {
180         dbg(0, "enter\n");
181         plugin_register_vehicle_type("null", vehicle_null_new_null);
182 }