summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormartin-s <martin-s@ffa7fe5e-494d-0410-b361-a75ebd5db220>2013-01-19 18:56:41 +0000
committermartin-s <martin-s@ffa7fe5e-494d-0410-b361-a75ebd5db220>2013-01-19 18:56:41 +0000
commit2d29d64f234eb731550f88b6b8007ea38d060da2 (patch)
treed82deab6a23f8cc81cc7bb1d618e465431df0991
parent55f4463abda76761be9e0fa284ad96d56916a51d (diff)
downloadnavit-2d29d64f234eb731550f88b6b8007ea38d060da2.tar.gz
Add:Core:Allow layer tag to reference layers within navit context, object handling cleanup
git-svn-id: http://svn.code.sf.net/p/navit/code/trunk/navit@5340 ffa7fe5e-494d-0410-b361-a75ebd5db220
-rw-r--r--navit/attr.h1
-rw-r--r--navit/attr_def.h1
-rw-r--r--navit/binding/dbus/binding_dbus.c1
-rw-r--r--navit/graphics.c8
-rw-r--r--navit/gui/gtk/gui_gtk_window.c1
-rw-r--r--navit/gui/internal/gui_internal.c3
-rw-r--r--navit/gui/internal/gui_internal_command.c1
-rw-r--r--navit/gui/internal/gui_internal_poi.c1
-rw-r--r--navit/layout.c68
-rw-r--r--navit/layout.h17
-rw-r--r--navit/map.c28
-rw-r--r--navit/maps.c2
-rw-r--r--navit/mapset.c26
-rw-r--r--navit/navigation.c1
-rw-r--r--navit/navit.c40
-rw-r--r--navit/osd/core/osd_core.c1
-rw-r--r--navit/route.c3
-rw-r--r--navit/search.c1
-rw-r--r--navit/track.c29
-rw-r--r--navit/vehicle.c31
-rw-r--r--navit/vehicleprofile.c8
-rw-r--r--navit/vehicleprofile.h2
-rw-r--r--navit/xmlconfig.c29
-rw-r--r--navit/xmlconfig.h10
24 files changed, 168 insertions, 145 deletions
diff --git a/navit/attr.h b/navit/attr.h
index b0a3bbba4..735d4853a 100644
--- a/navit/attr.h
+++ b/navit/attr.h
@@ -159,6 +159,7 @@ struct attr {
struct config *config;
struct osd *osd;
struct range range;
+ struct navit_object *navit_object;
int *dash;
enum item_type *item_types;
enum attr_type *attr_types;
diff --git a/navit/attr_def.h b/navit/attr_def.h
index 5160bcdd0..1a9c38d6f 100644
--- a/navit/attr_def.h
+++ b/navit/attr_def.h
@@ -358,6 +358,7 @@ ATTR(item_name)
ATTR(state_file)
ATTR(on_map_click)
ATTR(route_depth)
+ATTR(ref)
ATTR2(0x0003ffff,type_string_end)
ATTR2(0x00040000,type_special_begin)
ATTR(order)
diff --git a/navit/binding/dbus/binding_dbus.c b/navit/binding/dbus/binding_dbus.c
index 01b2e3624..0703bbe0a 100644
--- a/navit/binding/dbus/binding_dbus.c
+++ b/navit/binding/dbus/binding_dbus.c
@@ -30,6 +30,7 @@
#include "plugin.h"
#include "debug.h"
#include "item.h"
+#include "xmlconfig.h"
#include "attr.h"
#include "layout.h"
#include "navigation.h"
diff --git a/navit/graphics.c b/navit/graphics.c
index 2bd81b09e..8daaf7129 100644
--- a/navit/graphics.c
+++ b/navit/graphics.c
@@ -38,6 +38,7 @@
#include "graphics.h"
#include "projection.h"
#include "item.h"
+#include "xmlconfig.h"
#include "map.h"
#include "coord.h"
#include "transform.h"
@@ -2105,8 +2106,11 @@ static void xdisplay_draw(struct displaylist *display_list, struct graphics *gra
lays=l->layers;
while (lays) {
lay=lays->data;
- if (lay->active)
+ if (lay->active) {
+ if (lay->ref)
+ lay=lay->ref;
xdisplay_draw_layer(display_list, gra, lay, order);
+ }
lays=g_list_next(lays);
}
}
@@ -2124,6 +2128,8 @@ displaylist_update_layers(struct displaylist *displaylist, GList *layers, int or
{
while (layers) {
struct layer *layer=layers->data;
+ if (layer->ref)
+ layer=layer->ref;
GList *itemgras=layer->itemgras;
while (itemgras) {
struct itemgra *itemgra=itemgras->data;
diff --git a/navit/gui/gtk/gui_gtk_window.c b/navit/gui/gtk/gui_gtk_window.c
index b725cf944..e9e55551a 100644
--- a/navit/gui/gtk/gui_gtk_window.c
+++ b/navit/gui/gtk/gui_gtk_window.c
@@ -29,6 +29,7 @@
#include <gtk/gtk.h>
#include "config.h"
#include "item.h"
+#include "xmlconfig.h"
#include "navit.h"
#include "debug.h"
#include "gui.h"
diff --git a/navit/gui/internal/gui_internal.c b/navit/gui/internal/gui_internal.c
index bd1da6e21..b39fbfa0a 100644
--- a/navit/gui/internal/gui_internal.c
+++ b/navit/gui/internal/gui_internal.c
@@ -41,6 +41,7 @@
#include <sys/time.h>
#endif /* _MSC_VER */
#include "item.h"
+#include "xmlconfig.h"
#include "file.h"
#include "navit.h"
#include "navit_nls.h"
@@ -52,7 +53,6 @@
#include "transform.h"
#include "color.h"
#include "map.h"
-#include "layout.h"
#include "callback.h"
#include "vehicle.h"
#include "vehicleprofile.h"
@@ -70,7 +70,6 @@
#include "navigation.h"
#include "gui_internal.h"
#include "command.h"
-#include "xmlconfig.h"
#include "util.h"
#include "bookmarks.h"
#include "linguistics.h"
diff --git a/navit/gui/internal/gui_internal_command.c b/navit/gui/internal/gui_internal_command.c
index 99350089c..be11e576a 100644
--- a/navit/gui/internal/gui_internal_command.c
+++ b/navit/gui/internal/gui_internal_command.c
@@ -15,6 +15,7 @@
#include "navit_nls.h"
#include "command.h"
#include "attr.h"
+#include "xmlconfig.h"
#include "event.h"
#include "config_.h"
#include "map.h"
diff --git a/navit/gui/internal/gui_internal_poi.c b/navit/gui/internal/gui_internal_poi.c
index be59201b3..5cfdc9e39 100644
--- a/navit/gui/internal/gui_internal_poi.c
+++ b/navit/gui/internal/gui_internal_poi.c
@@ -9,6 +9,7 @@
#include "navit.h"
#include "navit_nls.h"
#include "item.h"
+#include "xmlconfig.h"
#include "map.h"
#include "mapset.h"
#include "layout.h"
diff --git a/navit/layout.c b/navit/layout.c
index 85623a1d7..7f5f8220f 100644
--- a/navit/layout.c
+++ b/navit/layout.c
@@ -21,10 +21,10 @@
#include <string.h>
#include "item.h"
#include "attr.h"
+#include "xmlconfig.h"
#include "layout.h"
#include "coord.h"
#include "debug.h"
-#include "xmlconfig.h"
struct layout * layout_new(struct attr *parent, struct attr **attrs)
@@ -36,6 +36,8 @@ struct layout * layout_new(struct attr *parent, struct attr **attrs)
if (! (name_attr=attr_search(attrs, NULL, attr_name)))
return NULL;
l = g_new0(struct layout, 1);
+ l->func=&layout_func;
+ navit_object_ref((struct navit_object *)l);
l->name = g_strdup(name_attr->u.str);
if ((font_attr=attr_search(attrs, NULL, attr_font))) {
l->font = g_strdup(font_attr->u.str);
@@ -54,9 +56,20 @@ struct layout * layout_new(struct attr *parent, struct attr **attrs)
l->order_delta=order_delta_attr->u.num;
if ((active_attr=attr_search(attrs, NULL, attr_active)))
l->active = active_attr->u.num;
+ l->navit=parent->u.navit;
return l;
}
+void
+layout_destroy(struct layout *layout)
+{
+ attr_list_free(layout->attrs);
+ g_free(layout->font);
+ g_free(layout->dayname);
+ g_free(layout->nightname);
+ g_free(layout);
+}
+
struct attr_iter {
GList *last;
};
@@ -123,13 +136,15 @@ layout_add_attr(struct layout *layout, struct attr *attr)
switch (attr->type) {
case attr_cursor:
layout->cursors = g_list_append(layout->cursors, attr->u.cursor);
- return 1;
+ break;
case attr_layer:
layout->layers = g_list_append(layout->layers, attr->u.layer);
- return 1;
+ break;
default:
return 0;
}
+ layout->attrs=attr_generic_add_attr(layout->attrs, attr);
+ return 1;
}
/**
@@ -222,6 +237,9 @@ cursor_add_attr(struct cursor *this_, struct attr *attr)
static int
layer_set_attr_do(struct layer *l, struct attr *attr, int init)
{
+ struct attr_iter *iter;
+ struct navit_object *obj;
+ struct attr layer;
switch (attr->type) {
case attr_active:
l->active = attr->u.num;
@@ -233,6 +251,18 @@ layer_set_attr_do(struct layer *l, struct attr *attr, int init)
g_free(l->name);
l->name = g_strdup(attr->u.str);
return 1;
+ case attr_ref:
+ navit_object_unref((struct navit_object *)l->ref);
+ l->ref=NULL;
+ obj=(struct navit_object *)l->navit;
+ iter=obj->func->iter_new(obj);
+ while (obj->func->get_attr(obj, attr_layer, &layer, iter)) {
+ if (!strcmp(layer.u.layer->name, attr->u.str)) {
+ l->ref=navit_object_ref(layer.u.navit_object);
+ break;
+ }
+ }
+ obj->func->iter_destroy(iter);
default:
return 0;
}
@@ -245,6 +275,10 @@ struct layer * layer_new(struct attr *parent, struct attr **attrs)
struct layer *l;
l = g_new0(struct layer, 1);
+ if (parent->type == attr_layout)
+ l->navit=parent->u.layout->navit;
+ l->func=&layer_func;
+ navit_object_ref((struct navit_object *)l);
l->active=1;
for (;*attrs; attrs++) {
layer_set_attr_do(l, *attrs, 1);
@@ -293,6 +327,14 @@ layer_set_attr(struct layer *layer, struct attr *attr)
return layer_set_attr_do(layer, attr, 0);
}
+void
+layer_destroy(struct layer *layer)
+{
+ attr_list_free(layer->attrs);
+ g_free(layer->name);
+ g_free(layer);
+}
+
struct itemgra * itemgra_new(struct attr *parent, struct attr **attrs)
{
struct itemgra *itm;
@@ -588,7 +630,23 @@ struct object_func layout_func = {
(object_func_init)NULL,
(object_func_destroy)NULL,
(object_func_dup)NULL,
- (object_func_ref)NULL,
- (object_func_unref)NULL,
+ (object_func_ref)navit_object_ref,
+ (object_func_unref)navit_object_unref,
};
+
+struct object_func layer_func = {
+ attr_layer,
+ (object_func_new)layer_new,
+ (object_func_get_attr)layer_get_attr,
+ (object_func_iter_new)NULL,
+ (object_func_iter_destroy)NULL,
+ (object_func_set_attr)layer_set_attr,
+ (object_func_add_attr)layer_add_attr,
+ (object_func_remove_attr)NULL,
+ (object_func_init)NULL,
+ (object_func_destroy)layer_destroy,
+ (object_func_dup)NULL,
+ (object_func_ref)navit_object_ref,
+ (object_func_unref)navit_object_unref,
+};
diff --git a/navit/layout.h b/navit/layout.h
index 1f36459d0..a17d8e279 100644
--- a/navit/layout.h
+++ b/navit/layout.h
@@ -75,10 +75,13 @@ struct itemgra {
};
struct layer {
+ NAVIT_OBJECT
+ struct navit *navit;
char *name;
int details;
GList *itemgras;
int active;
+ struct layer *ref;
};
struct cursor {
@@ -89,7 +92,19 @@ struct cursor {
int interval;
};
-struct layout { char *name; char* dayname; char* nightname; char *font; struct color color; GList *layers; GList *cursors; int order_delta; int active; };
+struct layout {
+ NAVIT_OBJECT
+ struct navit *navit;
+ char *name;
+ char* dayname;
+ char* nightname;
+ char *font;
+ struct color color;
+ GList *layers;
+ GList *cursors;
+ int order_delta;
+ int active;
+};
/* prototypes */
enum attr_type;
diff --git a/navit/map.c b/navit/map.c
index 900e3da49..e64de77d9 100644
--- a/navit/map.c
+++ b/navit/map.c
@@ -58,9 +58,7 @@
* This structure holds information about a map.
*/
struct map {
- struct object_func *func; /**< Object functions */
- int refcount; /**< Reference count */
- struct attr **attrs; /**< Attributes of this map */
+ NAVIT_OBJECT
struct map_methods meth; /**< Structure with pointers to the map plugin's functions */
struct map_priv *priv; /**< Private data of the map, only known to the map plugin */
struct callback_list *attr_cbl; /**< List of callbacks that are called when attributes change */
@@ -110,7 +108,7 @@ map_new(struct attr *parent, struct attr **attrs)
m=g_new0(struct map, 1);
m->attrs=attr_list_dup(attrs);
m->func=&map_func;
- m->refcount = 1;
+ navit_object_ref((struct navit_object *)m);
m->attr_cbl=callback_list_new();
m->priv=maptype_new(&m->meth, attrs, m->attr_cbl);
if (! m->priv) {
@@ -120,14 +118,6 @@ map_new(struct attr *parent, struct attr **attrs)
return m;
}
-struct map *
-map_ref(struct map* m)
-{
- m->refcount++;
- return m;
-}
-
-
/**
* @brief Gets an attribute from a map
*
@@ -289,16 +279,6 @@ map_destroy(struct map *m)
g_free(m);
}
-void
-map_unref(struct map *m)
-{
- if(!m)
- return;
- m->refcount--;
- if (m->refcount <= 0)
- map_destroy(m);
-}
-
/**
* @brief Creates a new map rect
*
@@ -733,8 +713,8 @@ struct object_func map_func = {
(object_func_init)NULL,
(object_func_destroy)map_destroy,
(object_func_dup)NULL,
- (object_func_ref)map_ref,
- (object_func_unref)map_unref,
+ (object_func_ref)navit_object_ref,
+ (object_func_unref)navit_object_unref,
};
diff --git a/navit/maps.c b/navit/maps.c
index bba0a8020..54723917b 100644
--- a/navit/maps.c
+++ b/navit/maps.c
@@ -73,7 +73,7 @@ maps_new(struct attr *parent, struct attr **attrs)
if (map.u.map) {
mapset_add_attr(parent->u.mapset, &map);
- map_unref(map.u.map);
+ navit_object_unref(map.u.navit_object);
}
}
diff --git a/navit/mapset.c b/navit/mapset.c
index 9748f88d4..df4fcfb00 100644
--- a/navit/mapset.c
+++ b/navit/mapset.c
@@ -42,9 +42,7 @@
* This structure holds a complete mapset
*/
struct mapset {
- struct object_func *func;
- int refcount;
- struct attr **attrs;
+ NAVIT_OBJECT
GList *maps; /**< Linked list of all the maps in the mapset */
};
@@ -63,7 +61,7 @@ struct mapset *mapset_new(struct attr *parent, struct attr **attrs)
ms=g_new0(struct mapset, 1);
ms->func=&mapset_func;
- ms->refcount=1;
+ navit_object_ref((struct navit_object *)ms);
ms->attrs=attr_list_dup(attrs);
return ms;
@@ -160,22 +158,6 @@ void mapset_destroy(struct mapset *ms)
g_free(ms);
}
-struct mapset *
-mapset_ref(struct mapset* m)
-{
- m->refcount++;
- return m;
-}
-
-
-void
-mapset_unref(struct mapset *m)
-{
- m->refcount--;
- if (m->refcount <= 0)
- mapset_destroy(m);
-}
-
/**
* @brief Handle for a mapset in use
*
@@ -410,8 +392,8 @@ struct object_func mapset_func = {
(object_func_init)NULL,
(object_func_destroy)mapset_destroy,
(object_func_dup)mapset_dup,
- (object_func_ref)mapset_ref,
- (object_func_unref)mapset_unref,
+ (object_func_ref)navit_object_ref,
+ (object_func_unref)navit_object_unref,
};
diff --git a/navit/navigation.c b/navit/navigation.c
index 8fa1a8740..31b350664 100644
--- a/navit/navigation.c
+++ b/navit/navigation.c
@@ -28,6 +28,7 @@
#include "navigation.h"
#include "coord.h"
#include "item.h"
+#include "xmlconfig.h"
#include "route.h"
#include "transform.h"
#include "mapset.h"
diff --git a/navit/navit.c b/navit/navit.c
index ef2d53209..aa9d82c65 100644
--- a/navit/navit.c
+++ b/navit/navit.c
@@ -36,6 +36,7 @@
#include "callback.h"
#include "gui.h"
#include "item.h"
+#include "xmlconfig.h"
#include "projection.h"
#include "map.h"
#include "mapset.h"
@@ -67,7 +68,6 @@
#include "vehicleprofile.h"
#include "sunriset.h"
#include "bookmarks.h"
-#include "xmlconfig.h"
#ifdef HAVE_API_WIN32_BASE
#include <windows.h>
#include "util.h"
@@ -100,9 +100,7 @@ struct navit_vehicle {
};
struct navit {
- struct object_func *func;
- int refcount;
- struct attr **attrs;
+ NAVIT_OBJECT
struct attr self;
GList *mapsets;
GList *layouts;
@@ -165,7 +163,6 @@ struct navit {
int imperial;
int waypoints_flag;
struct coord_geo center;
- struct attr **attr_list;
};
struct gui *main_loop_gui;
@@ -1386,7 +1383,7 @@ navit_new(struct attr *parent, struct attr **attrs)
g.lng=11.70;
this_->func=&navit_func;
- this_->refcount=1;
+ navit_object_ref((struct navit_object *)this_);
this_->attrs=attr_list_dup(attrs);
this_->self.type=attr_navit;
this_->self.u.navit=this_;
@@ -2683,6 +2680,9 @@ navit_get_attr(struct navit *this_, enum attr_type type, struct attr *attr, stru
attr->u.gui=this_->gui;
ret=(attr->u.gui != NULL);
break;
+ case attr_layer:
+ ret=attr_generic_get_attr(this_->attrs, NULL, type, attr, iter?(struct attr_iter *)&iter->iter:NULL);
+ break;
case attr_layout:
if (iter) {
if (iter->u.list) {
@@ -2722,7 +2722,7 @@ navit_get_attr(struct navit *this_, enum attr_type type, struct attr *attr, stru
attr->u.num=this_->orientation;
break;
case attr_osd:
- ret=attr_generic_get_attr(this_->attr_list, NULL, type, attr, iter?(struct attr_iter *)&iter->iter:NULL);
+ ret=attr_generic_get_attr(this_->attrs, NULL, type, attr, iter?(struct attr_iter *)&iter->iter:NULL);
break;
case attr_osd_configuration:
attr->u.num=this_->osd_configuration;
@@ -2851,7 +2851,7 @@ navit_add_attr(struct navit *this_, struct attr *attr)
ret=navit_set_graphics(this_, attr->u.graphics);
break;
case attr_layout:
- ret=navit_add_layout(this_, attr->u.layout);
+ navit_add_layout(this_, attr->u.layout);
break;
case attr_route:
this_->route=attr->u.route;
@@ -2863,7 +2863,6 @@ navit_add_attr(struct navit *this_, struct attr *attr)
this_->navigation=attr->u.navigation;
break;
case attr_osd:
- this_->attr_list=attr_generic_add_attr(this_->attr_list, attr);
break;
case attr_recent_dest:
this_->recentdest_count = attr->u.num;
@@ -2883,6 +2882,8 @@ navit_add_attr(struct navit *this_, struct attr *attr)
case attr_autozoom_min:
this_->autozoom_min = attr->u.num;
break;
+ case attr_layer:
+ break;
default:
return 0;
}
@@ -3436,23 +3437,6 @@ navit_destroy(struct navit *this_)
g_free(this_);
}
-struct navit *
-navit_ref(struct navit *this_)
-{
- this_->refcount++;
- dbg(1,"refcount %d\n",this_->refcount);
- return this_;
-}
-
-void
-navit_unref(struct navit *this_)
-{
- this_->refcount--;
- dbg(1,"refcount %d\n",this_->refcount);
- if (this_->refcount <= 0)
- navit_destroy(this_);
-}
-
struct object_func navit_func = {
attr_navit,
(object_func_new)navit_new,
@@ -3465,8 +3449,8 @@ struct object_func navit_func = {
(object_func_init)navit_init,
(object_func_destroy)navit_destroy,
(object_func_dup)NULL,
- (object_func_ref)navit_ref,
- (object_func_unref)navit_unref,
+ (object_func_ref)navit_object_ref,
+ (object_func_unref)navit_object_unref,
};
/** @} */
diff --git a/navit/osd/core/osd_core.c b/navit/osd/core/osd_core.c
index 436281318..519f83d58 100644
--- a/navit/osd/core/osd_core.c
+++ b/navit/osd/core/osd_core.c
@@ -31,6 +31,7 @@
#endif
#include <string.h>
#include "item.h"
+#include "xmlconfig.h"
#include "point.h"
#include "coord.h"
#include "graphics.h"
diff --git a/navit/route.c b/navit/route.c
index d2165995f..9e1ae96cf 100644
--- a/navit/route.c
+++ b/navit/route.c
@@ -57,6 +57,7 @@
#include "coord.h"
#include "projection.h"
#include "item.h"
+#include "xmlconfig.h"
#include "map.h"
#include "mapset.h"
#include "route.h"
@@ -3680,7 +3681,7 @@ route_get_map_helper(struct route *this_, struct map **map, char *type, char *de
if (! *map) {
*map=map_new(NULL, attrs);
- map_ref(*map);
+ navit_object_ref((struct navit_object *)*map);
}
return *map;
diff --git a/navit/search.c b/navit/search.c
index 984df4634..167deff55 100644
--- a/navit/search.c
+++ b/navit/search.c
@@ -24,6 +24,7 @@
#include "debug.h"
#include "projection.h"
#include "item.h"
+#include "xmlconfig.h"
#include "map.h"
#include "mapset.h"
#include "coord.h"
diff --git a/navit/track.c b/navit/track.c
index 7ee12a8f6..4ff616def 100644
--- a/navit/track.c
+++ b/navit/track.c
@@ -24,6 +24,7 @@
#include "item.h"
#include "attr.h"
#include "track.h"
+#include "xmlconfig.h"
#include "debug.h"
#include "transform.h"
#include "coord.h"
@@ -37,7 +38,6 @@
#include "roadprofile.h"
#include "util.h"
#include "config.h"
-#include "xmlconfig.h"
#include "callback.h"
struct object_func tracking_func;
@@ -83,9 +83,7 @@ struct cdf_data {
};
struct tracking {
- struct object_func *func;
- int refcount;
- struct attr *attrs;
+ NAVIT_OBJECT
struct callback_list *callback_list;
struct mapset *ms;
struct route *rt;
@@ -863,23 +861,6 @@ tracking_remove_attr(struct tracking *this_, struct attr *attr)
}
}
-struct tracking *
-tracking_ref(struct tracking *this_)
-{
- this_->refcount++;
- dbg(1,"refcount %d\n",this_->refcount);
- return this_;
-}
-
-void
-tracking_unref(struct tracking *this_)
-{
- this_->refcount--;
- dbg(1,"refcount %d\n",this_->refcount);
- if (this_->refcount <= 0)
- tracking_destroy(this_);
-}
-
struct object_func tracking_func = {
attr_trackingo,
(object_func_new)tracking_new,
@@ -892,8 +873,8 @@ struct object_func tracking_func = {
(object_func_init)tracking_init,
(object_func_destroy)tracking_destroy,
(object_func_dup)NULL,
- (object_func_ref)tracking_ref,
- (object_func_unref)tracking_unref,
+ (object_func_ref)navit_object_ref,
+ (object_func_unref)navit_object_unref,
};
@@ -903,7 +884,7 @@ 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;
+ navit_object_ref((struct navit_object *)this);
this->angle_pref=10;
this->connected_pref=10;
this->nostop_pref=10;
diff --git a/navit/vehicle.c b/navit/vehicle.c
index 331042d9a..7e49a6d19 100644
--- a/navit/vehicle.c
+++ b/navit/vehicle.c
@@ -25,6 +25,7 @@
#include "debug.h"
#include "coord.h"
#include "item.h"
+#include "xmlconfig.h"
#include "log.h"
#include "plugin.h"
#include "transform.h"
@@ -39,17 +40,14 @@
#include "color.h"
#include "layout.h"
#include "vehicle.h"
-#include "xmlconfig.h"
struct vehicle {
- struct object_func *func;
- int refcount;
+ NAVIT_OBJECT
struct vehicle_methods meth;
struct vehicle_priv *priv;
struct callback_list *cbl;
struct log *nmea_log, *gpx_log;
char *gpx_desc;
- struct attr **attrs;
// cursor
struct cursor *cursor;
@@ -115,7 +113,7 @@ vehicle_new(struct attr *parent, struct attr **attrs)
g_free(type);
this_ = g_new0(struct vehicle, 1);
this_->func=&vehicle_func;
- this_->refcount = 1;
+ navit_object_ref((struct navit_object *)this_);
this_->cbl = callback_list_new();
this_->priv = vehicletype_new(&this_->meth, this_->cbl, attrs);
if (!this_->priv) {
@@ -169,25 +167,6 @@ 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_)
-{
- if(!this_)
- return;
- 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
*/
@@ -731,6 +710,6 @@ struct object_func vehicle_func = {
(object_func_init)NULL,
(object_func_destroy)vehicle_destroy,
(object_func_dup)NULL,
- (object_func_ref)vehicle_ref,
- (object_func_unref)vehicle_unref,
+ (object_func_ref)navit_object_ref,
+ (object_func_unref)navit_object_unref,
};
diff --git a/navit/vehicleprofile.c b/navit/vehicleprofile.c
index bae828e0e..a51ecb34f 100644
--- a/navit/vehicleprofile.c
+++ b/navit/vehicleprofile.c
@@ -22,9 +22,9 @@
#include <string.h>
#include "debug.h"
#include "item.h"
+#include "xmlconfig.h"
#include "roadprofile.h"
#include "vehicleprofile.h"
-#include "xmlconfig.h"
static void
vehicleprofile_set_attr_do(struct vehicleprofile *this_, struct attr *attr)
@@ -93,6 +93,8 @@ vehicleprofile_new(struct attr *parent, struct attr **attrs)
return NULL;
}
this_=g_new0(struct vehicleprofile, 1);
+ this_->func=&vehicleprofile_func;
+ navit_object_ref((struct navit_object *)this_);
this_->attrs=attr_list_dup(attrs);
this_->roadprofile_hash=g_hash_table_new(NULL, NULL);
this_->length=-1;
@@ -189,6 +191,6 @@ struct object_func vehicleprofile_func = {
(object_func_init)NULL,
(object_func_destroy)NULL,
(object_func_dup)NULL,
- (object_func_ref)NULL,
- (object_func_unref)NULL,
+ (object_func_ref)navit_object_ref,
+ (object_func_unref)navit_object_unref,
};
diff --git a/navit/vehicleprofile.h b/navit/vehicleprofile.h
index 2d407b35a..39f9cff6a 100644
--- a/navit/vehicleprofile.h
+++ b/navit/vehicleprofile.h
@@ -22,6 +22,7 @@
extern "C" {
#endif
struct vehicleprofile {
+ NAVIT_OBJECT
int mode; /**< 0 = Auto, 1 = On-Road, 2 = Off-Road */
int flags_forward_mask; /**< Flags mask for moving in positive direction */
int flags_reverse_mask; /**< Flags mask for moving in reverse direction */
@@ -37,7 +38,6 @@ struct vehicleprofile {
int axle_weight; /**< Axle Weight of the vehicle in kg */
int dangerous_goods; /**< Flags of dangerous goods present */
int through_traffic_penalty; /**< Penalty when driving on a through traffic limited road */
- struct attr **attrs;
GHashTable *roadprofile_hash;
};
diff --git a/navit/xmlconfig.c b/navit/xmlconfig.c
index 4b58999d0..4cca8f34d 100644
--- a/navit/xmlconfig.c
+++ b/navit/xmlconfig.c
@@ -30,6 +30,8 @@
#include "config.h"
#include "file.h"
#include "coord.h"
+#include "item.h"
+#include "xmlconfig.h"
#include "layout.h"
#include "mapset.h"
#include "projection.h"
@@ -50,7 +52,6 @@
#include "vehicleprofile.h"
#include "roadprofile.h"
#include "config_.h"
-#include "xmlconfig.h"
#if (defined __MINGW32__) || (defined _MSC_VER)
/* This only works if a is a string constant, i.e. "name" */
@@ -254,7 +255,6 @@ static struct object_func object_funcs[] = {
{ attr_icon, NEW(icon_new), NULL, NULL, NULL, NULL, ADD(element_add_attr)},
{ attr_image, NEW(image_new)},
{ attr_itemgra, NEW(itemgra_new), NULL, NULL, NULL, NULL, ADD(itemgra_add_attr)},
- { attr_layer, NEW(layer_new), NULL, NULL, NULL, NULL, ADD(layer_add_attr)},
{ attr_log, NEW(log_new)},
{ attr_navigation, NEW(navigation_new), GET(navigation_get_attr)},
{ attr_osd, NEW(osd_new), GET(osd_get_attr), NULL, NULL, SET(osd_set_attr) },
@@ -273,6 +273,8 @@ object_func_lookup(enum attr_type type)
{
int i;
switch (type) {
+ case attr_layer:
+ return &layer_func;
case attr_layout:
return &layout_func;
case attr_map:
@@ -533,6 +535,11 @@ static void initStatic(void) {
elements[38].parent="mapset";
elements[38].func=NULL;
elements[38].type=attr_maps;
+
+ elements[39].name="layer";
+ elements[39].parent="navit";
+ elements[39].func=NULL;
+ elements[39].type=attr_layer;
}
/**
@@ -1220,3 +1227,21 @@ gboolean config_load(const char *filename, xmlerror **error)
return result;
}
+struct navit_object *
+navit_object_ref(struct navit_object *obj)
+{
+ obj->refcount++;
+ dbg(1,"refcount %s %p %d\n",attr_to_name(obj->func->type),obj,obj->refcount);
+ return obj;
+}
+
+void
+navit_object_unref(struct navit_object *obj)
+{
+ if (obj) {
+ obj->refcount--;
+ dbg(1,"refcount %s %p %d\n",attr_to_name(obj->func->type),obj,obj->refcount);
+ if (obj->refcount <= 0 && obj->func && obj->func->destroy)
+ obj->func->destroy(obj);
+ }
+}
diff --git a/navit/xmlconfig.h b/navit/xmlconfig.h
index e916eb481..06bc4bf0c 100644
--- a/navit/xmlconfig.h
+++ b/navit/xmlconfig.h
@@ -54,15 +54,17 @@ struct object_func {
void *(*unref)(void *);
};
-extern struct object_func map_func, mapset_func, navit_func, tracking_func, vehicle_func, maps_func, layout_func, vehicleprofile_func;
+extern struct object_func map_func, mapset_func, navit_func, tracking_func, vehicle_func, maps_func, layout_func, vehicleprofile_func, layer_func;
-#define HAS_OBJECT_FUNC(x) ((x) == attr_map || (x) == attr_mapset || (x) == attr_navit || (x) == attr_trackingo || (x) == attr_vehicle)
+#define HAS_OBJECT_FUNC(x) ((x) == attr_map || (x) == attr_mapset || (x) == attr_navit || (x) == attr_trackingo || (x) == attr_vehicle || (x) == attr_maps || (x) == attr_layout || (x) == attr_vehicleprofile || (x) == attr_layer)
+#define NAVIT_OBJECT struct object_func *func; int refcount; struct attr **attrs;
struct navit_object {
- struct object_func *func;
- int refcount;
+ NAVIT_OBJECT
};
+struct navit_object *navit_object_ref(struct navit_object *obj);
+void navit_object_unref(struct navit_object *obj);
typedef GError xmlerror;