diff options
-rw-r--r-- | navit/vehicle.c | 39 | ||||
-rw-r--r-- | navit/xmlconfig.c | 20 | ||||
-rw-r--r-- | navit/xmlconfig.h | 16 |
3 files changed, 70 insertions, 5 deletions
diff --git a/navit/vehicle.c b/navit/vehicle.c index 97468351..e15f7610 100644 --- a/navit/vehicle.c +++ b/navit/vehicle.c @@ -39,8 +39,11 @@ #include "color.h" #include "layout.h" #include "vehicle.h" +#include "xmlconfig.h" struct vehicle { + struct object_func *func; + int refcount; struct vehicle_methods meth; struct vehicle_priv *priv; struct callback_list *cbl; @@ -63,6 +66,8 @@ struct vehicle { GHashTable *log_to_cb; }; +struct object_func vehicle_func; + static void vehicle_draw_do(struct vehicle *this_, int lazy); static void vehicle_log_nmea(struct vehicle *this_, struct log *log); static void vehicle_log_gpx(struct vehicle *this_, struct log *log); @@ -109,6 +114,8 @@ vehicle_new(struct attr *parent, struct attr **attrs) } g_free(type); this_ = g_new0(struct vehicle, 1); + this_->func=&vehicle_func; + this_->refcount = 1; this_->cbl = callback_list_new(); this_->priv = vehicletype_new(&this_->meth, this_->cbl, attrs); if (!this_->priv) { @@ -153,6 +160,23 @@ vehicle_destroy(struct vehicle *this_) g_free(this_); } +struct vehicle * +vehicle_ref(struct vehicle *this_) +{ + this_->refcount++; + dbg(0,"refcount %d\n",this_->refcount); + return this_; +} + +void +vehicle_unref(struct vehicle *this_) +{ + this_->refcount--; + dbg(0,"refcount %d\n",this_->refcount); + if (this_->refcount <= 0) + vehicle_destroy(this_); +} + /** * Creates an attribute iterator to be used with vehicles */ @@ -680,3 +704,18 @@ vehicle_add_log(struct vehicle *this_, struct log *log) return 0; } +struct object_func vehicle_func = { + attr_vehicle, + (object_func_new)vehicle_new, + (object_func_get_attr)vehicle_get_attr, + (object_func_iter_new)vehicle_attr_iter_new, + (object_func_iter_destroy)vehicle_attr_iter_destroy, + (object_func_set_attr)vehicle_set_attr, + (object_func_add_attr)vehicle_add_attr, + (object_func_remove_attr)vehicle_remove_attr, + (object_func_init)NULL, + (object_func_destroy)vehicle_destroy, + (object_func_dup)NULL, + (object_func_ref)vehicle_ref, + (object_func_unref)vehicle_unref, +}; diff --git a/navit/xmlconfig.c b/navit/xmlconfig.c index 9d11ec13..90be5946 100644 --- a/navit/xmlconfig.c +++ b/navit/xmlconfig.c @@ -266,19 +266,25 @@ static struct object_func object_funcs[] = { { 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_vehicle, NEW(vehicle_new), GET(vehicle_get_attr), NULL, NULL, SET(vehicle_set_attr), ADD(vehicle_add_attr), REMOVE(vehicle_remove_attr) }, { attr_vehicleprofile, NEW(vehicleprofile_new), GET(vehicleprofile_get_attr), NULL, NULL, SET(vehicleprofile_set_attr), ADD(vehicleprofile_add_attr) }, }; +extern struct object_func vehicle_func; + struct object_func * object_func_lookup(enum attr_type type) { int i; - for (i = 0 ; i < sizeof(object_funcs)/sizeof(struct object_func); i++) { - if (object_funcs[i].type == type) - return &object_funcs[i]; + switch (type) { + case attr_vehicle: + return &vehicle_func; + default: + for (i = 0 ; i < sizeof(object_funcs)/sizeof(struct object_func); i++) { + if (object_funcs[i].type == type) + return &object_funcs[i]; + } + return NULL; } - return NULL; } struct element_func { @@ -655,6 +661,10 @@ end_element (GMarkupParseContext *context, curr=*state; if (curr->object_func && curr->object_func->init) curr->object_func->init(curr->element_attr.u.data); +#if 0 + if (curr->object_func && curr->object_func->unref) + curr->object_func->unref(curr->element_attr.u.data); +#endif *state=curr->parent; g_free(curr); } diff --git a/navit/xmlconfig.h b/navit/xmlconfig.h index 3da9ab4a..9d1c4c6c 100644 --- a/navit/xmlconfig.h +++ b/navit/xmlconfig.h @@ -24,6 +24,19 @@ extern "C" { #endif +typedef void *(*object_func_new)(struct attr *parent, struct attr **attrs); +typedef int (*object_func_get_attr)(void *, enum attr_type type, struct attr *attr, struct attr_iter *iter); +typedef struct attr_iter *(*object_func_iter_new)(void *); +typedef void (*object_func_iter_destroy)(struct attr_iter *); +typedef int (*object_func_set_attr)(void *, struct attr *attr); +typedef int (*object_func_add_attr)(void *, struct attr *attr); +typedef int (*object_func_remove_attr)(void *, struct attr *attr); +typedef int (*object_func_init)(void *); +typedef void (*object_func_destroy)(void *); +typedef void *(*object_func_dup)(void *); +typedef void *(*object_func_ref)(void *); +typedef void *(*object_func_unref)(void *); + struct object_func { enum attr_type type; void *(*create)(struct attr *parent, struct attr **attrs); @@ -35,6 +48,9 @@ struct object_func { int (*remove_attr)(void *, struct attr *attr); int (*init)(void *); void (*destroy)(void *); + void *(*dup)(void *); + void *(*ref)(void *); + void *(*unref)(void *); }; typedef GError xmlerror; |