Fix:Core:Further cleanup of xmlconfig
authormartin-s <martin-s@ffa7fe5e-494d-0410-b361-a75ebd5db220>
Sun, 26 Oct 2008 12:57:55 +0000 (12:57 +0000)
committermartin-s <martin-s@ffa7fe5e-494d-0410-b361-a75ebd5db220>
Sun, 26 Oct 2008 12:57:55 +0000 (12:57 +0000)
git-svn-id: https://navit.svn.sourceforge.net/svnroot/navit/trunk/navit@1566 ffa7fe5e-494d-0410-b361-a75ebd5db220

14 files changed:
navit/attr.h
navit/attr_def.h
navit/binding/python/binding_python.c
navit/debug.c
navit/debug.h
navit/map.c
navit/map.h
navit/mapset.c
navit/mapset.h
navit/navigation.c
navit/navit.c
navit/route.c
navit/track.c
navit/xmlconfig.c

index d070a3a..ee3b6d2 100644 (file)
@@ -63,6 +63,7 @@ struct attr {
                struct layout *layout;
                struct layer *layer;
                struct map *map;
+               struct mapset *mapset;
                struct log *log;
                struct route *route;
                struct navigation *navigation;
index 8640970..64b17a9 100644 (file)
@@ -78,6 +78,7 @@ ATTR(offset)
 ATTR(directed)
 ATTR(radius)
 ATTR(text_size)
+ATTR(level)
 ATTR2(0x00028000,type_boolean_begin)
 /* boolean */
 ATTR(overwrite)
@@ -199,6 +200,7 @@ ATTR(text)
 ATTR(icon)
 ATTR(image)
 ATTR(arrows)
+ATTR(mapset)
 ATTR2(0x0008ffff,type_object_end)
 ATTR2(0x00090000,type_coord_begin)
 ATTR2(0x0009ffff,type_coord_end)
index b3e3ec2..4fb623e 100644 (file)
@@ -194,7 +194,7 @@ map_new_py(PyObject *self, PyObject *args)
        if (!PyArg_ParseTuple(args, "ss:navit.map", &type, &filename))
                return NULL;
        ret=PyObject_NEW(mapObject, &map_Type);
-       ret->m=map_new(NULL);
+       ret->m=map_new(NULL,NULL);
        return (PyObject *)ret;
 }
 
@@ -257,7 +257,7 @@ mapset_new_py(PyObject *self, PyObject *args)
        if (!PyArg_ParseTuple(args, ":navit.mapset"))
                return NULL;
        ret=PyObject_NEW(mapsetObject, &mapset_Type);
-       ret->ms=mapset_new();
+       ret->ms=mapset_new(NULL,NULL);
        return (PyObject *)ret;
 }
 
index cfe1420..d83d546 100644 (file)
 #include <time.h>
 #include <glib.h>
 #include "file.h"
+#include "item.h"
 #include "debug.h"
 
 
 int debug_level=0,segv_level=0;
+static int dummy;
 static GHashTable *debug_hash;
 static char *gdb_program;
 
@@ -78,6 +80,19 @@ debug_level_set(const char *name, int level)
        }
 }
 
+struct debug *
+debug_new(struct attr *parent, struct attr **attrs)
+{
+       struct attr *name,*level;
+       name=attr_search(attrs, NULL, attr_name);
+       level=attr_search(attrs, NULL, attr_level);
+       if (!name || !level)
+               return NULL;
+       debug_level_set(name->u.str, level->u.num);
+       return (struct debug *)&dummy;
+}
+
+
 int
 debug_level_get(const char *name)
 {
index 0d95123..5a0317e 100644 (file)
@@ -33,9 +33,11 @@ extern int debug_level;
 #define dbg_assert(expr) ((expr) ? (void) 0 : debug_assert_fail(dbg_module,strlen(dbg_module),__PRETTY_FUNCTION__, strlen(__PRETTY_FUNCTION__),__FILE__,__LINE__,dbg_str1(expr)))
 
 /* prototypes */
+struct attr;
 void debug_init(const char *program_name);
 void debug_level_set(const char *name, int level);
 int debug_level_get(const char *name);
+struct debug *debug_new(struct attr *parent, struct attr **attrs);
 void debug_vprintf(int level, const char *module, const int mlen, const char *function, const int flen, int prefix, const char *fmt, va_list ap);
 void debug_printf(int level, const char *module, const int mlen, const char *function, const int flen, int prefix, const char *fmt, ...);
 void debug_assert_fail(char *module, const int mlen,const char *function, const int flen, char *file, int line, char *expr);
index 934da5f..482665d 100644 (file)
@@ -88,7 +88,7 @@ struct map_rect {
  * @return The opened map or NULL on failure
  */
 struct map *
-map_new(struct attr **attrs)
+map_new(struct attr *parent, struct attr **attrs)
 {
        struct map *m;
        struct map_priv *(*maptype_new)(struct map_methods *meth, struct attr **attrs);
index bcbb102..aac9291 100644 (file)
@@ -224,7 +224,7 @@ struct map_rect;
 struct map_search;
 struct map_selection;
 struct pcoord;
-struct map *map_new(struct attr **attrs);
+struct map *map_new(struct attr *parent, struct attr **attrs);
 int map_get_attr(struct map *this_, enum attr_type type, struct attr *attr, struct attr_iter *iter);
 int map_set_attr(struct map *this_, struct attr *attr);
 void map_add_callback(struct map *this_, struct callback *cb);
index 5001ef2..5ebec02 100644 (file)
@@ -49,7 +49,7 @@ struct mapset {
  *
  * @return The new mapset 
  */
-struct mapset *mapset_new(void)
+struct mapset *mapset_new(struct attr *parent, struct attr **attrs)
 {
        struct mapset *ms;
 
@@ -58,15 +58,23 @@ struct mapset *mapset_new(void)
        return ms;
 }
 
+
 /**
  * @brief Adds a map to a mapset
  *
  * @param ms The mapset to add the map to
  * @param m The map to be added
  */
-void mapset_add(struct mapset *ms, struct map *m)
+int
+mapset_add_attr(struct mapset *ms, struct attr *attr)
 {
-       ms->maps=g_list_append(ms->maps, m);
+       switch (attr->type) {
+       case attr_map:
+               ms->maps=g_list_append(ms->maps, attr->u.map);
+               return 1;
+       default:
+               return 0;
+       }
 }
 
 #if 0
index acba751..0e19010 100644 (file)
@@ -27,8 +27,8 @@ struct map;
 struct mapset;
 struct mapset_handle;
 struct mapset_search;
-struct mapset *mapset_new(void);
-void mapset_add(struct mapset *ms, struct map *m);
+struct mapset *mapset_new(struct attr *parent, struct attr **attrs);
+int mapset_add_attr(struct mapset *ms, struct attr *attr);
 void mapset_destroy(struct mapset *ms);
 struct mapset_handle *mapset_open(struct mapset *ms);
 struct map *mapset_next(struct mapset_handle *msh, int active);
index 1d0e60c..b705ac3 100644 (file)
@@ -935,7 +935,7 @@ struct map *
 navigation_get_map(struct navigation *this_)
 {
        if (! this_->map)
-               this_->map=map_new((struct attr*[]){
+               this_->map=map_new(NULL, (struct attr*[]){
                        &(struct attr){attr_type,{"navigation"}},
                        &(struct attr){attr_navigation,.u.navigation=this_},
                        &(struct attr){attr_data,{""}},
index a74c97d..f0c690f 100644 (file)
@@ -824,10 +824,11 @@ static void
 navit_add_bookmarks_from_file(struct navit *this_)
 {
        char *bookmark_file = navit_get_bookmark_file(FALSE);
+       struct attr parent={attr_navit, .u.navit=this_};
        struct attr type={attr_type, {"textfile"}}, data={attr_data, {bookmark_file}};
        struct attr *attrs[]={&type, &data, NULL};
 
-       this_->bookmark=map_new(attrs);
+       this_->bookmark=map_new(&parent, attrs);
        g_free(bookmark_file);
 }
 
@@ -835,10 +836,11 @@ static void
 navit_add_former_destinations_from_file(struct navit *this_)
 {
        char *destination_file = navit_get_destination_file(FALSE);
+       struct attr parent={attr_navit, .u.navit=this_};
        struct attr type={attr_type, {"textfile"}}, data={attr_data, {destination_file}};
        struct attr *attrs[]={&type, &data, NULL};
 
-       this_->former_destination=map_new(attrs);
+       this_->former_destination=map_new(&parent, attrs);
        g_free(destination_file);
 }
 
@@ -1206,9 +1208,13 @@ navit_init(struct navit *this_)
                ms=this_->mapsets->data;
                if (this_->route) {
                        if ((map=route_get_map(this_->route)))
-                               mapset_add(ms, map);
+                               mapset_add_attr(ms, (struct attr*[]){
+                                       &(struct attr){attr_map,{map}},
+                                NULL});
                        if ((map=route_get_graph_map(this_->route))) {
-                               mapset_add(ms, map);
+                               mapset_add_attr(ms, (struct attr*[]){
+                                       &(struct attr){attr_map,{map}},
+                                NULL});
                                map_set_attr(map, &(struct attr ){attr_active,.u.num=0});
                        }
                        route_set_mapset(this_->route, ms);
@@ -1221,13 +1227,17 @@ navit_init(struct navit *this_)
                }
                if (this_->navigation) {
                        if ((map=navigation_get_map(this_->navigation))) {
-                               mapset_add(ms, map);
+                               mapset_add_attr(ms, (struct attr*[]){
+                                       &(struct attr){attr_map,{map}},
+                                NULL});
                                map_set_attr(map, &(struct attr ){attr_active,.u.num=0});
                        }
                }
                if (this_->tracking) {
                        if ((map=tracking_get_map(this_->tracking))) {
-                               mapset_add(ms, map);
+                               mapset_add_attr(ms, (struct attr*[]){
+                                       &(struct attr){attr_map,{map}},
+                                NULL});
                                map_set_attr(map, &(struct attr ){attr_active,.u.num=0});
                        }
                }
@@ -1505,6 +1515,9 @@ navit_add_attr(struct navit *this_, struct attr *attr)
        case attr_route:
                this_->route=attr->u.route;
                break;
+       case attr_mapset:
+               this_->mapsets = g_list_append(this_->mapsets, attr->u.mapset);
+               break;
        case attr_navigation:
                this_->navigation=attr->u.navigation;
                break;
index 8bb2247..1cbc420 100644 (file)
@@ -2267,7 +2267,7 @@ static struct map *
 route_get_map_helper(struct route *this_, struct map **map, char *type, char *description)
 {
        if (! *map) 
-               *map=map_new((struct attr*[]){
+               *map=map_new(NULL, (struct attr*[]){
                                 &(struct attr){attr_type,{type}},
                                 &(struct attr){attr_route,.u.route=this_},
                                 &(struct attr){attr_data,{""}},
index 6111726..ef5cd03 100644 (file)
@@ -389,7 +389,7 @@ struct map *
 tracking_get_map(struct tracking *this_)
 {
        if (! this_->map)
-               this_->map=map_new((struct attr*[]){
+               this_->map=map_new(NULL, (struct attr*[]){
                        &(struct attr){attr_type,{"tracking"}},
                        &(struct attr){attr_trackingo,.u.tracking=this_},
                        &(struct attr){attr_data,{""}},
index 44f0360..79d06e2 100644 (file)
@@ -205,20 +205,6 @@ xmlconfig_speech(struct xmlstate *state)
 }
 
 static int
-xmlconfig_debug(struct xmlstate *state)
-{
-       const char *name,*level;
-       name=find_attribute(state, "name", 1);
-       if (! name)
-               return 0;
-       level=find_attribute(state, "level", 1);
-       if (! level)
-               return 0;
-       debug_level_set(name, convert_number(level));
-       return 1;
-}
-
-static int
 xmlconfig_window_items(struct xmlstate *state)
 {
        int distance=-1;
@@ -302,35 +288,6 @@ xmlconfig_speed(struct xmlstate *state)
 
 
 static int
-xmlconfig_navigation(struct xmlstate *state)
-{
-       struct attr **attrs;
-       struct attr navigation_attr;
-
-       attrs=convert_to_attrs(state,NULL);
-       state->element_attr.u.data = navigation_new(attrs);
-       if (! state->element_attr.u.data) {
-               dbg(0,"Failed to create navigation object\n");
-               return 0;
-       }
-       navigation_attr.type=attr_navigation;
-       navigation_attr.u.navigation=state->element_attr.u.data;
-       return navit_add_attr(state->parent->element_attr.u.data, &navigation_attr);
-}
-
-static int
-xmlconfig_osd(struct xmlstate *state)
-{
-       struct attr **attrs;
-       const char *type=find_attribute(state, "type", 1);
-       if (! type)
-               return 0;
-       attrs=convert_to_attrs(state,NULL);
-       state->element_attr.u.data = osd_new(state->parent->element_attr.u.data, type, attrs);
-       return 1;
-}
-
-static int
 xmlconfig_announce(struct xmlstate *state)
 {
        const char *type,*value;
@@ -362,30 +319,6 @@ xmlconfig_announce(struct xmlstate *state)
        return 1;
 }
 
-static int
-xmlconfig_mapset(struct xmlstate *state)
-{
-       state->element_attr.u.data = mapset_new();
-       if (! state->element_attr.u.data)
-               return 0;
-       navit_add_mapset(state->parent->element_attr.u.data, state->element_attr.u.data);
-
-       return 1;
-}
-
-static int
-xmlconfig_map(struct xmlstate *state)
-{
-       struct attr **attrs;
-       attrs=convert_to_attrs(state,NULL);
-       state->element_attr.u.data = map_new(attrs);
-       if (! state->element_attr.u.data)
-               return 0;
-       mapset_add(state->parent->element_attr.u.data, state->element_attr.u.data);
-
-       return 1;
-}
-
 #define NEW(x) (void *(*)(struct attr *, struct attr **))(x)
 #define ADD(x) (int (*)(void *, struct attr *attr))(x)
 #define INIT(x) (int (*)(void *))(x)
@@ -400,16 +333,16 @@ struct element_func {
        void (*destroy)(void *);
 } elements[] = {
        { "config", NULL, xmlconfig_config},
-       { "debug", "config", xmlconfig_debug},
-       { "mapset", "navit", xmlconfig_mapset},
-       { "map",  "mapset", xmlconfig_map},
-       { "navigation", "navit", xmlconfig_navigation},
-       { "osd", "navit", xmlconfig_osd},
        { "announce", "navigation", xmlconfig_announce},
        { "speech", "navit", xmlconfig_speech},
        { "tracking", "navit", xmlconfig_tracking},
        { "route", "navit", xmlconfig_route},
        { "speed", "route", xmlconfig_speed},
+       { "mapset", "navit", NULL, NEW(mapset_new), ADD(mapset_add_attr)},
+       { "map",  "mapset", NULL, NEW(map_new)},
+       { "debug", "config", NULL, NEW(debug_new)},
+       { "osd", "navit", NULL, NEW(osd_new)},
+       { "navigation", "navit", NULL, NEW(navigation_new)},
        { "navit", "config", NULL, NEW(navit_new), ADD(navit_add_attr), INIT(navit_init), DESTROY(navit_destroy)},
        { "graphics", "navit", NULL, NEW(graphics_new)},
        { "gui", "navit", NULL, NEW(gui_new)},