diff options
-rw-r--r-- | navit/attr.c | 4 | ||||
-rw-r--r-- | navit/navit.c | 2 | ||||
-rw-r--r-- | navit/track.c | 71 | ||||
-rw-r--r-- | navit/xmlconfig.c | 9 |
4 files changed, 80 insertions, 6 deletions
diff --git a/navit/attr.c b/navit/attr.c index 894f01bff..530586a43 100644 --- a/navit/attr.c +++ b/navit/attr.c @@ -569,7 +569,7 @@ attr_free(struct attr *attr) { if (!attr) return; - if (attr->type == attr_navit || attr->type == attr_vehicle) { + if (attr->type == attr_navit || attr->type == attr_trackingo || attr->type == attr_vehicle) { struct navit_object *obj=attr->u.data; if (obj && obj->func && obj->func->unref) obj->func->unref(obj); @@ -588,7 +588,7 @@ attr_dup_content(struct attr *src, struct attr *dst) if (src->type >= attr_type_int_begin && src->type <= attr_type_int_end) dst->u.num=src->u.num; else if (src->type >= attr_type_object_begin && src->type <= attr_type_object_end) { - if (src->type == attr_navit || src->type == attr_vehicle) { + if (src->type == attr_navit || src->type == attr_trackingo || src->type == attr_vehicle) { struct navit_object *obj=src->u.data; if (obj && obj->func && obj->func->ref) { dst->u.data=obj->func->ref(obj); diff --git a/navit/navit.c b/navit/navit.c index 183d23cee..e7a6377f9 100644 --- a/navit/navit.c +++ b/navit/navit.c @@ -2708,7 +2708,7 @@ navit_add_attr(struct navit *this_, struct attr *attr) case attr_speech: this_->speech=attr->u.speech; break; - case attr_tracking: + case attr_trackingo: this_->tracking=attr->u.tracking; break; case attr_vehicle: diff --git a/navit/track.c b/navit/track.c index bfe3a8ea2..c75b77e44 100644 --- a/navit/track.c +++ b/navit/track.c @@ -37,6 +37,10 @@ #include "roadprofile.h" #include "util.h" #include "config.h" +#include "xmlconfig.h" +#include "callback.h" + +struct object_func tracking_func; struct tracking_line { @@ -79,6 +83,10 @@ struct cdf_data { }; struct tracking { + struct object_func *func; + int refcount; + struct attr *attrs; + struct callback_list *callback_list; struct mapset *ms; struct route *rt; struct map *map; @@ -789,6 +797,7 @@ tracking_update(struct tracking *tr, struct vehicle *v, struct vehicleprofile *v tr->speed=0; } dbg(1,"found 0x%x,0x%x\n", tr->curr_out.x, tr->curr_out.y); + callback_list_call_attr_0(tr->callback_list, attr_position_coord_geo); } static int @@ -830,16 +839,77 @@ tracking_set_attr(struct tracking *tr, struct attr *attr) return tracking_set_attr_do(tr, attr, 0); } +int +tracking_add_attr(struct tracking *this_, struct attr *attr) +{ + switch (attr->type) { + case attr_callback: + callback_list_add(this_->callback_list, attr->u.callback); + return 1; + default: + return 0; + } +} + +int +tracking_remove_attr(struct tracking *this_, struct attr *attr) +{ + switch (attr->type) { + case attr_callback: + callback_list_remove(this_->callback_list, attr->u.callback); + return 1; + default: + return 0; + } +} + +struct tracking * +tracking_ref(struct tracking *this_) +{ + this_->refcount++; + dbg(0,"refcount %d\n",this_->refcount); + return this_; +} + +void +tracking_unref(struct tracking *this_) +{ + this_->refcount--; + dbg(0,"refcount %d\n",this_->refcount); + if (this_->refcount <= 0) + tracking_destroy(this_); +} + +struct object_func tracking_func = { + attr_trackingo, + (object_func_new)tracking_new, + (object_func_get_attr)tracking_get_attr, + (object_func_iter_new)NULL, + (object_func_iter_destroy)NULL, + (object_func_set_attr)tracking_set_attr, + (object_func_add_attr)tracking_add_attr, + (object_func_remove_attr)tracking_remove_attr, + (object_func_init)tracking_init, + (object_func_destroy)tracking_destroy, + (object_func_dup)NULL, + (object_func_ref)tracking_ref, + (object_func_unref)tracking_unref, +}; + + struct tracking * tracking_new(struct attr *parent, struct attr **attrs) { struct tracking *this=g_new0(struct tracking, 1); struct attr hist_size; + this->func=&tracking_func; + this->refcount=1; this->angle_pref=10; this->connected_pref=10; this->nostop_pref=10; this->offroad_limit_pref=5000; this->route_pref=300; + this->callback_list=callback_list_new(); if (! attr_generic_get_attr(attrs, NULL, attr_cdf_histsize, &hist_size, NULL)) { @@ -873,6 +943,7 @@ tracking_destroy(struct tracking *tr) if (tr->attr) attr_free(tr->attr); tracking_flush(tr); + callback_list_destroy(tr->callback_list); g_free(tr); } diff --git a/navit/xmlconfig.c b/navit/xmlconfig.c index 86df7e8df..c37c69c23 100644 --- a/navit/xmlconfig.c +++ b/navit/xmlconfig.c @@ -264,11 +264,10 @@ static struct object_func object_funcs[] = { { attr_route, NEW(route_new), GET(route_get_attr), NULL, NULL, SET(route_set_attr), ADD(route_add_attr), REMOVE(route_remove_attr)}, { attr_speech, NEW(speech_new), GET(speech_get_attr), NULL, NULL, SET(speech_set_attr)}, { attr_text, NEW(text_new)}, - { attr_tracking, NEW(tracking_new)}, { attr_vehicleprofile, NEW(vehicleprofile_new), GET(vehicleprofile_get_attr), NULL, NULL, SET(vehicleprofile_set_attr), ADD(vehicleprofile_add_attr) }, }; -extern struct object_func navit_func, vehicle_func; +extern struct object_func navit_func, tracking_func, vehicle_func; struct object_func * object_func_lookup(enum attr_type type) @@ -277,6 +276,8 @@ object_func_lookup(enum attr_type type) switch (type) { case attr_navit: return &navit_func; + case attr_trackingo: + return &tracking_func; case attr_vehicle: return &vehicle_func; default: @@ -347,7 +348,7 @@ static void initStatic(void) { elements[3].name="tracking"; elements[3].parent="navit"; elements[3].func=NULL; - elements[3].type=attr_tracking; + elements[3].type=attr_trackingo; elements[4].name="route"; elements[4].parent="navit"; @@ -640,6 +641,8 @@ start_element(GMarkupParseContext *context, new->element_attr.type=attr_from_name(element_name); if (new->element_attr.type == attr_none) dbg(0,"failed to create object of type '%s'\n", element_name); + if (new->element_attr.type == attr_tracking) + new->element_attr.type=attr_trackingo; if (new->parent && new->parent->object_func && new->parent->object_func->add_attr) new->parent->object_func->add_attr(new->parent->element_attr.u.data, &new->element_attr); } |