static int vehicle_add_log(struct vehicle *this_, struct log *log, struct attr **attrs) { struct attr *type; struct callback *cb; type = attr_search(attrs, NULL, attr_type); if (!type) return 1; if (!strcmp(type->u.str, "nmea")) { cb=callback_new_2(callback_cast(vehicle_log_nmea), this_, log); } else if (!strcmp(type->u.str, "gpx")) { char *header = "<?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"; char *trailer = "</trkseg>\n</trk>\n</gpx>\n"; log_set_header(log, header, strlen(header)); log_set_trailer(log, trailer, strlen(trailer)); cb=callback_new_2(callback_cast(vehicle_log_gpx), this_, log); } else if (!strcmp(type->u.str, "textfile")) { char *header = "type=track\n"; log_set_header(log, header, strlen(header)); cb=callback_new_2(callback_cast(vehicle_log_textfile), this_, log); } else return 1; callback_list_add(this_->cbl, cb); return 0; }
int vehicle_add_attr(struct vehicle *this_, struct attr *attr, struct attr **attrs) { switch (attr->type) { case attr_callback: callback_list_add(this_->cbl, attr->u.callback); break; case attr_log: return vehicle_add_log(this_, attr->u.log, attrs); default: return 0; } return 1; }
void bookmarks_add_callback(struct bookmarks *this_, struct callback *cb) { callback_list_add(this_->attr_cbl, cb); }
void navit_add_vehicle_cb(struct navit *this_, struct callback *cb) { callback_list_add(this_->vehicle_cbl, cb); }
static struct vehicle_priv * vehicle_wince_new(struct vehicle_methods *meth, struct callback_list *cbl, struct attr **attrs) { struct vehicle_priv *ret; struct attr *source; struct attr *time; struct attr *on_eof; struct attr *baudrate; struct attr *checksum_ignore; struct attr *handle_bluetooth; char *cp; dbg(1, "enter\n"); source = attr_search(attrs, NULL, attr_source); ret = g_new0(struct vehicle_priv, 1); ret->fd = -1; ret->cbl = cbl; ret->file_type = file_type_device; cp = strchr(source->u.str,':'); if (cp) { if ( strncmp(source->u.str, "file", 4) == 0 ) ret->file_type = file_type_file; cp++; } else cp = source->u.str; ret->source = g_strdup(cp); ret->buffer = g_malloc(buffer_size); ret->time=1000; ret->baudrate=0; // do not change the rate if not configured time = attr_search(attrs, NULL, attr_time); if (time) ret->time=time->u.num; baudrate = attr_search(attrs, NULL, attr_baudrate); if (baudrate) { ret->baudrate = baudrate->u.num; } checksum_ignore = attr_search(attrs, NULL, attr_checksum_ignore); if (checksum_ignore) ret->checksum_ignore=checksum_ignore->u.num; ret->attrs = attrs; on_eof = attr_search(attrs, NULL, attr_on_eof); if (on_eof && !strcasecmp(on_eof->u.str, "stop")) ret->on_eof=1; if (on_eof && !strcasecmp(on_eof->u.str, "exit")) ret->on_eof=2; dbg(0,"on_eof=%d\n", ret->on_eof); *meth = vehicle_wince_methods; ret->priv_cbl = callback_list_new(); callback_list_add(ret->priv_cbl, callback_new_1(callback_cast(vehicle_wince_io), ret)); ret->sat_item.type=type_position_sat; ret->sat_item.id_hi=ret->sat_item.id_lo=0; ret->sat_item.priv_data=ret; ret->sat_item.meth=&vehicle_wince_sat_methods; ret->read_buffer = g_malloc(buffer_size); handle_bluetooth = attr_search(attrs, NULL, attr_bluetooth); if ( handle_bluetooth && handle_bluetooth->u.num == 1 ) initBth(ret); if (vehicle_wince_open(ret)) { vehicle_wince_enable_watch(ret); return ret; } dbg(0, "Failed to open '%s'\n", ret->source); vehicle_wince_destroy(ret); return NULL; }