Add:Core:New vehicle type null
[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 "null.h"
36 #include "vehicle.h"
37
38 struct vehicle_priv {
39         struct callback_list *cbl;
40         struct coord_geo geo;
41         double speed;
42         double direction;
43         double height;
44         double radius;
45         int fix_type;
46         time_t fix_time;
47         char fixiso8601[128];
48         int sats;
49         int sats_used;
50         int have_coords;
51         struct attr ** attrs;
52 };
53
54 /**
55  * @brief Free the null_vehicle
56  * 
57  * @param priv
58  * @returns nothing
59  */
60 static void
61 vehicle_null_destroy(struct vehicle_priv *priv)
62 {
63         dbg(0,"enter\n");
64         g_free(priv);
65 }
66
67 /**
68  * @brief Provide the outside with information
69  * 
70  * @param priv
71  * @param type TODO: What can this be?
72  * @param attr
73  * @returns true/false
74  */
75 static int
76 vehicle_null_position_attr_get(struct vehicle_priv *priv,
77                                enum attr_type type, struct attr *attr)
78 {
79         dbg(1,"enter %s\n",attr_to_name(type));
80         switch (type) {
81 #if 0
82         case attr_position_fix_type:
83                 attr->u.num = priv->fix_type;
84                 break;
85 #endif
86         case attr_position_height:
87                 attr->u.numd = &priv->height;
88                 break;
89         case attr_position_speed:
90                 attr->u.numd = &priv->speed;
91                 break;
92         case attr_position_direction:
93                 attr->u.numd = &priv->direction;
94                 break;
95         case attr_position_radius:
96                 attr->u.numd = &priv->radius;
97                 break;
98
99 #if 0
100         case attr_position_qual:
101                 attr->u.num = priv->sats;
102                 break;
103         case attr_position_sats_used:
104                 attr->u.num = priv->sats_used;
105                 break;
106 #endif
107         case attr_position_coord_geo:
108                 attr->u.coord_geo = &priv->geo;
109                 if (!priv->have_coords)
110                         return 0;
111                 break;
112         case attr_position_time_iso8601:
113                 attr->u.str=priv->fixiso8601;
114                 break;
115         default:
116                 return 0;
117         }
118         dbg(1,"ok\n");
119         attr->type = type;
120         return 1;
121 }
122
123 int vehicle_null_set_attr(struct vehicle_priv *priv, struct attr *attr, struct attr **attrs)
124 {
125         return 1;
126 }
127
128
129 struct vehicle_methods vehicle_null_methods = {
130         vehicle_null_destroy,
131         vehicle_null_position_attr_get,
132         vehicle_null_set_attr,
133 };
134
135 /**
136  * @brief Create null_vehicle
137  * 
138  * @param meth
139  * @param cbl
140  * @param attrs
141  * @returns vehicle_priv
142  */
143 static struct vehicle_priv *
144 vehicle_null_new_null(struct vehicle_methods *meth,
145                         struct callback_list *cbl,
146                         struct attr **attrs)
147 {
148         struct vehicle_priv *ret;
149
150         dbg(0, "enter\n");
151         ret = g_new0(struct vehicle_priv, 1);
152         ret->cbl = cbl;
153         *meth = vehicle_null_methods;
154         dbg(0, "return\n");
155         return ret;
156 }
157
158 /**
159  * @brief register vehicle_null
160  * 
161  * @returns nothing
162  */
163 void
164 plugin_init(void)
165 {
166         dbg(0, "enter\n");
167         plugin_register_vehicle_type("null", vehicle_null_new_null);
168 }