13 struct vehicle_priv *priv;
14 struct vehicle_methods meth;
15 struct callback_list *cbl;
16 struct log *nmea_log, *gpx_log, *textfile_log;
20 vehicle_add_log(struct vehicle *this_, struct log *log,
24 type = attr_search(attrs, NULL, attr_type);
27 if (!strcmp(type->u.str, "nmea")) {
28 this_->nmea_log = log;
29 } else if (!strcmp(type->u.str, "gpx")) {
31 "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<gpx version=\"1.0\" creator=\"Navit http://navit.sourceforge.net\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns=\"http://www.topografix.com/GPX/1/0\" xsi:schemaLocation=\"http://www.topografix.com/GPX/1/0 http://www.topografix.com/GPX/1/0/gpx.xsd\">\n<trk>\n<trkseg>\n";
32 char *trailer = "</trkseg>\n</trk>\n</gpx>\n";
34 log_set_header(log, header, strlen(header));
35 log_set_trailer(log, trailer, strlen(trailer));
36 } else if (!strcmp(type->u.str, "textfile")) {
37 char *header = "type=track\n";
38 this_->textfile_log = log;
39 log_set_header(log, header, strlen(header));
46 vehicle_new(struct attr **attrs)
48 struct vehicle *this_;
50 struct vehicle_priv *(*vehicletype_new) (struct vehicle_methods *
52 struct callback_list *
54 struct attr ** attrs);
58 source = attr_search(attrs, NULL, attr_source);
60 dbg(0, "no source\n");
64 type = g_strdup(source->u.str);
65 colon = index(type, ':');
68 dbg(0, "source='%s' type='%s'\n", source->u.str, type);
70 vehicletype_new = plugin_get_vehicle_type(type);
71 if (!vehicletype_new) {
72 dbg(0, "invalid type\n");
75 this_ = g_new0(struct vehicle, 1);
76 this_->cbl = callback_list_new();
77 this_->priv = vehicletype_new(&this_->meth, this_->cbl, attrs);
79 dbg(0, "vehicletype_new failed\n");
80 callback_list_destroy(this_->cbl);
90 vehicle_position_attr_get(struct vehicle *this_, enum attr_type type,
93 if (this_->meth.position_attr_get)
94 return this_->meth.position_attr_get(this_->priv, type,
100 vehicle_set_attr(struct vehicle *this_, struct attr *attr,
107 vehicle_add_attr(struct vehicle *this_, struct attr *attr,
110 switch (attr->type) {
112 callback_list_add(this_->cbl, attr->u.callback);
115 return vehicle_add_log(this_, attr->u.log, attrs);
123 vehicle_remove_attr(struct vehicle *this_, struct attr *attr)
125 switch (attr->type) {
127 callback_list_remove(this_->cbl, attr->u.callback);
136 vehicle_destroy(struct vehicle *this_)
138 callback_list_destroy(this_->cbl);