struct vehicle * vehicle_new(struct attr **attrs) { struct vehicle *this_; struct attr *source; struct vehicle_priv *(*vehicletype_new) (struct vehicle_methods * meth, struct callback_list * cbl, struct attr ** attrs); char *type, *colon; dbg(1, "enter\n"); source = attr_search(attrs, NULL, attr_source); if (!source) { dbg(0, "no source\n"); return NULL; } type = g_strdup(source->u.str); colon = index(type, ':'); if (colon) *colon = '\0'; dbg(1, "source='%s' type='%s'\n", source->u.str, type); vehicletype_new = plugin_get_vehicle_type(type); if (!vehicletype_new) { dbg(0, "invalid type\n"); return NULL; } this_ = g_new0(struct vehicle, 1); this_->cbl = callback_list_new(); this_->priv = vehicletype_new(&this_->meth, this_->cbl, attrs); if (!this_->priv) { dbg(0, "vehicletype_new failed\n"); callback_list_destroy(this_->cbl); g_free(this_); return NULL; } dbg(1, "leave\n"); return this_; }
struct vehicle * vehicle_new(struct attr **attrs) { struct vehicle *v; struct attr *name,*update,*follow,*color,*active,*source, *id; struct vehicle_priv *(*vehicletype_new) (struct vehicle_methods * meth, struct callback_list * cbl, struct attr ** attrs); char *type, *colon; dbg(1, "enter\n"); source = attr_search(attrs, NULL, attr_source); if (!source) { dbg(0, "no source\n"); return NULL; } type = g_strdup(source->u.str); colon = index(type, ':'); if (colon) *colon = '\0'; dbg(1, "source='%s' type='%s'\n", source->u.str, type); vehicletype_new = plugin_get_vehicle_type(type); if (!vehicletype_new) { dbg(0, "invalid type\n"); return NULL; } v = g_new0(struct vehicle, 1); v->cbl = callback_list_new(); v->priv = vehicletype_new(&v->meth, v->cbl, attrs); if (!v->priv) { dbg(0, "vehicletype_new failed\n"); callback_list_destroy(v->cbl); g_free(v); return NULL; } v->update = 1; v->follow = 0; v->active = 0; if ((name=attr_search(attrs, NULL, attr_name))) v->name=g_strdup(name->u.str); else v->name=g_strdup("Noname"); if ((id=attr_search(attrs, NULL, attr_vehicle_id))) v->id=id->u.num; if ((update=attr_search(attrs, NULL, attr_update))) v->update=update->u.num; if ((follow=attr_search(attrs, NULL, attr_follow))) v->follow=follow->u.num; if ((color=attr_search(attrs, NULL, attr_color))) v->c=*(color->u.color); if ((active=attr_search(attrs, NULL, attr_active)) && active->u.num) { v->active = 1; // navit_set_vehicle(this_, v); } dbg(1, "leave\n"); return v; }