2 * Navit, a modular navigation system.
3 * Copyright (C) 2005-2008 Navit Team
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public License
7 * version 2 as published by the Free Software Foundation.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the
16 * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17 * Boston, MA 02110-1301, USA.
35 struct vehicle_priv *priv;
36 struct vehicle_methods meth;
37 struct callback_list *cbl;
38 struct log *nmea_log, *gpx_log;
43 vehicle_log_nmea(struct vehicle *this_, struct log *log)
46 if (!this_->meth.position_attr_get)
48 if (!this_->meth.position_attr_get(this_->priv, attr_position_nmea, &pos_attr))
50 log_write(log, pos_attr.u.str, strlen(pos_attr.u.str));
54 vehicle_log_gpx(struct vehicle *this_, struct log *log)
57 struct attr time_attr;
58 struct attr *profile_attr;
62 if (!this_->meth.position_attr_get)
64 if (!this_->meth.position_attr_get(this_->priv, attr_position_coord_geo, &pos_attr))
66 if (!this_->meth.position_attr_get(this_->priv, attr_position_time_iso8601, &time_attr)) {
67 timep = current_to_iso8601();
70 timep = time_attr.u.str;
73 // get the profile name attribute
74 profile_attr = attr_search(this_->attrs, NULL, attr_profilename);
77 "<trkpt lat=\"%f\" lon=\"%f\">\n"
79 "\t<extensions><navit:profilename>%s</navit:profilename></extensions>\n"
81 pos_attr.u.coord_geo->lat,
82 pos_attr.u.coord_geo->lng,
92 vehicle_log_textfile(struct vehicle *this_, struct log *log)
96 if (!this_->meth.position_attr_get)
98 if (!this_->meth.position_attr_get(this_->priv, attr_position_coord_geo, &pos_attr))
100 sprintf(buffer,"%f %f type=trackpoint\n", pos_attr.u.coord_geo->lng, pos_attr.u.coord_geo->lat);
101 log_write(log, buffer, strlen(buffer));
105 vehicle_add_log(struct vehicle *this_, struct log *log)
108 struct attr type_attr;
109 if (!log_get_attr(log, attr_type, &type_attr, NULL))
112 if (!strcmp(type_attr.u.str, "nmea")) {
113 cb=callback_new_2(callback_cast(vehicle_log_nmea), this_, log);
114 } else if (!strcmp(type_attr.u.str, "gpx")) {
115 char *header = "<?xml version='1.0' encoding='UTF-8'?>\n"
116 "<gpx version='1.1' creator='Navit http://navit.sourceforge.net'\n"
117 " xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'\n"
118 " xmlns:navit='http://www.navit-project.org/schema/navit'\n"
119 " xmlns='http://www.topografix.com/GPX/1/1'\n"
120 " xsi:schemaLocation='http://www.topografix.com/GPX/1/1 http://www.topografix.com/GPX/1/1/gpx.xsd'>\n"
123 char *trailer = "</trkseg>\n</trk>\n</gpx>\n";
124 log_set_header(log, header, strlen(header));
125 log_set_trailer(log, trailer, strlen(trailer));
126 cb=callback_new_2(callback_cast(vehicle_log_gpx), this_, log);
127 } else if (!strcmp(type_attr.u.str, "textfile")) {
128 char *header = "type=track\n";
129 log_set_header(log, header, strlen(header));
130 cb=callback_new_2(callback_cast(vehicle_log_textfile), this_, log);
133 callback_list_add(this_->cbl, cb);
138 vehicle_new(struct attr *parent, struct attr **attrs)
140 struct vehicle *this_;
142 struct vehicle_priv *(*vehicletype_new) (struct vehicle_methods *
144 struct callback_list *
146 struct attr ** attrs);
150 source = attr_search(attrs, NULL, attr_source);
152 dbg(0, "no source\n");
156 type = g_strdup(source->u.str);
157 colon = strchr(type, ':');
160 dbg(1, "source='%s' type='%s'\n", source->u.str, type);
162 vehicletype_new = plugin_get_vehicle_type(type);
163 if (!vehicletype_new) {
164 dbg(0, "invalid type '%s'\n", type);
167 this_ = g_new0(struct vehicle, 1);
168 this_->cbl = callback_list_new();
169 this_->priv = vehicletype_new(&this_->meth, this_->cbl, attrs);
171 dbg(0, "vehicletype_new failed\n");
172 callback_list_destroy(this_->cbl);
176 this_->attrs=attr_list_dup(attrs);
183 vehicle_get_attr(struct vehicle *this_, enum attr_type type, struct attr *attr, struct attr_iter *iter)
186 if (this_->meth.position_attr_get) {
187 ret=this_->meth.position_attr_get(this_->priv, type, attr);
191 return attr_generic_get_attr(this_->attrs, NULL, type, attr, iter);
195 vehicle_set_attr(struct vehicle *this_, struct attr *attr,
199 if (this_->meth.set_attr)
200 ret=this_->meth.set_attr(this_->priv, attr, attrs);
201 if (ret == 1 && attr->type != attr_navit)
202 this_->attrs=attr_generic_set_attr(this_->attrs, attr);
207 vehicle_add_attr(struct vehicle *this_, struct attr *attr)
210 switch (attr->type) {
212 callback_list_add(this_->cbl, attr->u.callback);
215 ret=vehicle_add_log(this_, attr->u.log);
221 this_->attrs=attr_generic_add_attr(this_->attrs, attr);
226 vehicle_remove_attr(struct vehicle *this_, struct attr *attr)
228 switch (attr->type) {
230 callback_list_remove(this_->cbl, attr->u.callback);
239 vehicle_destroy(struct vehicle *this_)
241 this_->meth.destroy(this_->priv);
242 callback_list_destroy(this_->cbl);
243 attr_list_free(this_->attrs);