Fix:Core:Further cleanups
authormartin-s <martin-s@ffa7fe5e-494d-0410-b361-a75ebd5db220>
Mon, 27 Oct 2008 15:58:27 +0000 (15:58 +0000)
committermartin-s <martin-s@ffa7fe5e-494d-0410-b361-a75ebd5db220>
Mon, 27 Oct 2008 15:58:27 +0000 (15:58 +0000)
git-svn-id: https://navit.svn.sourceforge.net/svnroot/navit/trunk/navit@1580 ffa7fe5e-494d-0410-b361-a75ebd5db220

16 files changed:
navit/attr.h
navit/attr_def.h
navit/navit.c
navit/osm2navit.c
navit/plugin.c
navit/plugin.h
navit/plugin_def.h
navit/route.c
navit/route.h
navit/speech.c
navit/speech.h
navit/speech/cmdline/speech_cmdline.c
navit/speech/speech_dispatcher/speech_speech_dispatcher.c
navit/track.c
navit/track.h
navit/xmlconfig.c

index ee3b6d2..a6b0727 100644 (file)
@@ -73,6 +73,8 @@ struct attr {
                struct graphics *graphics;
                struct tracking *tracking;
                struct itemgra *itemgra;
+               struct plugin *plugin;
+               struct plugins *plugins;
                struct polygon *polygon;
                struct polyline *polyline;
                struct circle *circle;
@@ -81,6 +83,7 @@ struct attr {
                struct image *image;
                struct arrows *arrows;
                struct element *element;
+               struct speech *speech;
                struct order {
                        short min, max;
                } order;
index 7a3102e..f52da8a 100644 (file)
@@ -203,6 +203,8 @@ ATTR(image)
 ATTR(arrows)
 ATTR(mapset)
 ATTR(osd)
+ATTR(plugin)
+ATTR(speech)
 ATTR2(0x0008ffff,type_object_end)
 ATTR2(0x00090000,type_coord_begin)
 ATTR2(0x0009ffff,type_coord_end)
index 0f06d0a..053dad5 100644 (file)
@@ -1537,6 +1537,12 @@ navit_add_attr(struct navit *this_, struct attr *attr)
        case attr_recent_dest:
                this_->recentdest_count = attr->u.num;
                break;
+       case attr_speech:
+               this_->speech=attr->u.speech;
+               break;
+       case attr_tracking:
+               this_->tracking=attr->u.tracking;
+               break;
        case attr_vehicle:
                return navit_add_vehicle(this_, attr->u.vehicle);
        default:
@@ -1744,17 +1750,7 @@ navit_add_vehicle(struct navit *this_, struct vehicle *v)
        return 1;
 }
 
-void
-navit_tracking_add(struct navit *this_, struct tracking *tracking)
-{
-       this_->tracking=tracking;
-}
 
-void
-navit_set_speech(struct navit *this_, struct speech *speech)
-{
-       this_->speech=speech;
-}
 
 
 struct gui *
index 67e272d..eaa753b 100644 (file)
@@ -2744,7 +2744,7 @@ int main(int argc, char **argv)
                                plugins=plugins_new();
                        fprintf(stderr,"optarg=%s\n",optarg);
                        attrs=(struct attr*[]){&(struct attr){attr_path,{optarg}},NULL};
-                       plugins_add_path(plugins, attrs);       
+                       plugin_new(&(struct attr){attr_plugins,.u.plugins=plugins}, attrs);     
                        break;
                case 's':
                        start=atoi(optarg);
index f7c84ac..8152ed4 100644 (file)
@@ -91,13 +91,13 @@ struct plugins {
        GList *list;
 } *pls;
 
-struct plugin *
-plugin_new(char *plugin)
+static struct plugin *
+plugin_new_from_path(char *plugin)
 {
 #ifdef USE_PLUGINS
        struct plugin *ret;
        if (! g_module_supported()) {
-               return NULL;
+              return NULL;
        }
        ret=g_new0(struct plugin, 1);
        ret->name=g_strdup(plugin);
@@ -206,9 +206,9 @@ plugins_new(void)
        return ret;
 }
 
-void
-plugins_add_path(struct plugins *pls, struct attr **attrs) {
-#ifdef USE_PLUGINS 
+struct plugin *
+plugin_new(struct attr *parent, struct attr **attrs) {
+#ifdef USE_PLUGINS
        struct attr *path_attr, *attr;
        struct file_wordexp *we;
        int active=1; // default active
@@ -217,10 +217,13 @@ plugins_add_path(struct plugins *pls, struct attr **attrs) {
        char **array;
        char *name;
        struct plugin *pl;
+       struct plugins *pls;
+
+       pls=parent->u.plugins;
 
        if (! (path_attr=attr_search(attrs, NULL, attr_path))) {
                dbg(0,"missing path\n");
-               return;
+               return NULL;
        }
        if ( (attr=attr_search(attrs, NULL, attr_active))) {
                active=attr->u.num;
@@ -239,7 +242,7 @@ plugins_add_path(struct plugins *pls, struct attr **attrs) {
        for (i = 0 ; i < count ; i++) {
                name=array[i];
                if (! (pl=g_hash_table_lookup(pls->hash, name))) {
-                       pl=plugin_new(name);
+                       pl=plugin_new_from_path(name);
                        if (! pl) {
                                dbg(0,"failed to create plugin '%s'\n", name);
                                continue;
@@ -255,6 +258,7 @@ plugins_add_path(struct plugins *pls, struct attr **attrs) {
                plugin_set_ondemand(pl, ondemand);
        }
        file_wordexp_destroy(we);
+       return pl;
 #endif
 }
 
index 6116f73..4182bd3 100644 (file)
@@ -136,7 +136,6 @@ struct attr;
 
 /* prototypes */
 void plugin_init(void);
-struct plugin *plugin_new(char *plugin);
 int plugin_load(struct plugin *pl);
 char *plugin_get_name(struct plugin *pl);
 int plugin_get_active(struct plugin *pl);
@@ -146,7 +145,7 @@ void plugin_call_init(struct plugin *pl);
 void plugin_unload(struct plugin *pl);
 void plugin_destroy(struct plugin *pl);
 struct plugins *plugins_new(void);
-void plugins_add_path(struct plugins *pls, struct attr ** attrs);
+struct plugin *plugin_new(struct attr *parent, struct attr ** attrs);
 void plugins_init(struct plugins *pls);
 void plugins_destroy(struct plugins *pls);
 void *plugin_get_type(enum plugin_type type, const char *type_name, const char *name);
index 8ebeb24..36d49c7 100644 (file)
@@ -26,7 +26,7 @@ PLUGIN_TYPE(graphics, (struct navit *nav, struct graphics_methods *meth, struct
 PLUGIN_TYPE(gui, (struct navit *nav, struct gui_methods *meth, struct attr **attrs)) 
 PLUGIN_TYPE(map, (struct map_methods *meth, struct attr **attrs)) 
 PLUGIN_TYPE(osd, (struct navit *nav, struct osd_methods *meth, struct attr **attrs))
-PLUGIN_TYPE(speech, (char *data, struct speech_methods *meth)) 
+PLUGIN_TYPE(speech, (struct speech_methods *meth, struct attr **attrs)) 
 PLUGIN_TYPE(vehicle, (struct vehicle_methods *meth, struct callback_list *cbl, struct attr **attrs)) 
 PLUGIN_TYPE(event, (struct event_methods *meth)) 
 PLUGIN_TYPE(font, (void *meth)) 
index 1cbc420..ec3fd29 100644 (file)
@@ -259,7 +259,7 @@ route_path_destroy(struct route_path *this)
  * @return The newly created route
  */
 struct route *
-route_new(struct attr **attrs)
+route_new(struct attr *parent, struct attr **attrs)
 {
        struct route *this=g_new0(struct route, 1);
        struct attr dest_attr;
index c020385..4b8422f 100644 (file)
@@ -69,7 +69,7 @@ struct route_path_segment;
 struct street_data;
 struct tracking;
 struct transformation;
-struct route *route_new(struct attr **attrs);
+struct route *route_new(struct attr *parent, struct attr **attrs);
 void route_set_mapset(struct route *this, struct mapset *ms);
 struct mapset *route_get_mapset(struct route *this);
 struct route_info *route_get_pos(struct route *this);
index c9d44f4..9037129 100644 (file)
@@ -20,6 +20,7 @@
 #include <glib.h>
 #include <string.h>
 #include "debug.h"
+#include "item.h"
 #include "speech.h"
 #include "plugin.h"
 
@@ -29,19 +30,26 @@ struct speech {
 };
 
 struct speech *
-speech_new(const char *type, const char *data) 
+speech_new(struct attr *parent, struct attr **attrs) 
 {
        struct speech *this_;
        struct speech_priv *(*speech_new)(const char *data, struct speech_methods *meth);
+       struct attr *type;
 
-       dbg(1,"enter type=%s data=%s\n", type, data);
-        speech_new=plugin_get_speech_type(type);
+       type=attr_search(attrs, NULL, attr_type);
+       if (! type) {
+               dbg(0,"type missing\n");
+               return NULL;
+       }
+       dbg(1,"type='%s'\n", type->u.str);
+        speech_new=plugin_get_speech_type(type->u.str);
        dbg(1,"new=%p\n", speech_new);
         if (! speech_new) {
+               dbg(0,"wrong type '%s'\n", type->u.str);
                 return NULL;
        }
        this_=g_new0(struct speech, 1);
-       this_->priv=speech_new(data, &this_->meth);
+       this_->priv=speech_new(attrs, &this_->meth);
        dbg(1, "say=%p\n", this_->meth.say);
        dbg(1,"priv=%p\n", this_->priv);
        if (! this_->priv) {
index 8f17aa5..b2893b7 100644 (file)
@@ -28,7 +28,7 @@ struct speech_methods {
 };
 
 /* prototypes */
-struct speech * speech_new(const char *type, const char *data);
+struct speech * speech_new(struct attr *parent, struct attr **attrs);
 int speech_say(struct speech *this_, const char *text);
 int speech_sayf(struct speech *this_, const char *format, ...);
 void speech_destroy(struct speech *this_);
index 037bc84..5576e5d 100644 (file)
@@ -20,6 +20,7 @@
 #include <stdlib.h>
 #include <glib.h>
 #include "config.h"
+#include "item.h"
 #include "plugin.h"
 #include "speech.h"
 
@@ -48,12 +49,14 @@ static struct speech_methods speechd_meth = {
 };
 
 static struct speech_priv *
-speechd_new(char *data, struct speech_methods *meth) {
+speechd_new(struct speech_methods *meth, struct attr **attrs) {
        struct speech_priv *this;
+       struct attr *data;
+       data=attr_search(attrs, NULL, attr_data);
        if (! data)
                return NULL;
        this=g_new(struct speech_priv,1);
-       this->cmdline=g_strdup(data);
+       this->cmdline=g_strdup(data->u.str);
        *meth=speechd_meth;
        return this;
 }
index 524645e..b2c0e2a 100644 (file)
@@ -57,7 +57,7 @@ static struct speech_methods speechd_meth = {
 };
 
 static struct speech_priv *
-speechd_new(char *data, struct speech_methods *meth) {
+speechd_new(struct speech_methods *meth, struct attr **attrs) {
        struct speech_priv *this;
        SPDConnection *conn;
 
index ef5cd03..44fb66b 100644 (file)
@@ -358,10 +358,9 @@ tracking_update(struct tracking *tr, struct coord *c, int angle)
 }
 
 struct tracking *
-tracking_new(struct mapset *ms)
+tracking_new(struct attr *parent, struct attr **attrs)
 {
        struct tracking *this=g_new0(struct tracking, 1);
-       this->ms=ms;
 
        return this;
 }
index 0eb3a5c..03bec6f 100644 (file)
@@ -32,7 +32,7 @@ struct coord *tracking_get_pos(struct tracking *tr);
 int tracking_get_segment_pos(struct tracking *tr);
 struct street_data *tracking_get_street_data(struct tracking *tr);
 int tracking_update(struct tracking *tr, struct coord *c, int angle);
-struct tracking *tracking_new(struct mapset *ms);
+struct tracking *tracking_new(struct attr *parent, struct attr **attrs);
 void tracking_set_mapset(struct tracking *this_, struct mapset *ms);
 void tracking_set_route(struct tracking *this_, struct route *rt);
 int tracking_get_current_attr(struct tracking *_this, enum attr_type type, struct attr *attr);
index a5c41b4..53f5cde 100644 (file)
@@ -59,8 +59,8 @@ struct xistate {
        struct xistate *parent;
        struct xistate *child;
        const gchar *element;
-       gchar **attribute_names;
-       gchar **attribute_values;
+       const gchar **attribute_names;
+       const gchar **attribute_values;
 };
 
 struct xmldocument {
@@ -180,31 +180,6 @@ xmlconfig_config(struct xmlstate *state)
 }
 
 static int
-xmlconfig_plugin(struct xmlstate *state)
-{
-       struct attr **attrs;
-       attrs=convert_to_attrs(state,NULL);
-       plugins_add_path(state->parent->element_attr.u.data, attrs);
-       return 1;
-}
-
-static int
-xmlconfig_speech(struct xmlstate *state)
-{
-       const char *type;
-       const char *data;
-       type=find_attribute(state, "type", 1);
-       if (! type)
-               return 0;
-       data=find_attribute(state, "data", 0);
-       state->element_attr.u.data = speech_new(type, data);
-       if (! state->element_attr.u.data)
-               return 0;
-       navit_set_speech(state->parent->element_attr.u.data, state->element_attr.u.data);
-       return 1;
-}
-
-static int
 xmlconfig_window_items(struct xmlstate *state)
 {
        int distance=-1;
@@ -232,32 +207,6 @@ xmlconfig_window_items(struct xmlstate *state)
        return 1;
 }
 
-
-static int
-xmlconfig_tracking(struct xmlstate *state)
-{
-       state->element_attr.u.data = tracking_new(NULL);
-       navit_tracking_add(state->parent->element_attr.u.data, state->element_attr.u.data);
-       return 1;
-}
-
-static int
-xmlconfig_route(struct xmlstate *state)
-{
-       struct attr **attrs;
-       struct attr route_attr;
-
-       attrs=convert_to_attrs(state,NULL);
-       state->element_attr.u.data = route_new(attrs);
-       if (! state->element_attr.u.data) {
-               dbg(0,"Failed to create route object\n");
-               return 0;
-       }
-       route_attr.type=attr_route;
-       route_attr.u.route=state->element_attr.u.data;
-       return navit_add_attr(state->parent->element_attr.u.data, &route_attr);
-}
-
 static int
 xmlconfig_speed(struct xmlstate *state)
 {
@@ -334,9 +283,9 @@ struct element_func {
 } elements[] = {
        { "config", NULL, xmlconfig_config},
        { "announce", "navigation", xmlconfig_announce},
-       { "speech", "navit", xmlconfig_speech},
-       { "tracking", "navit", xmlconfig_tracking},
-       { "route", "navit", xmlconfig_route},
+       { "speech", "navit", NULL, NEW(speech_new)},
+       { "tracking", "navit", NULL, NEW(tracking_new)},
+       { "route", "navit", NULL, NEW(route_new)},
        { "speed", "route", xmlconfig_speed},
        { "mapset", "navit", NULL, NEW(mapset_new), ADD(mapset_add_attr)},
        { "map",  "mapset", NULL, NEW(map_new)},
@@ -361,7 +310,7 @@ struct element_func {
        { "log", "navit", NULL, NEW(log_new)},
        { "window_items", "navit", xmlconfig_window_items},
        { "plugins", "config", NULL, NEW(plugins_new), NULL, INIT(plugins_init)},
-       { "plugin", "plugins", xmlconfig_plugin},
+       { "plugin", "plugins", NULL, NEW(plugin_new)},
        {},
 };
 
@@ -720,8 +669,8 @@ xi_start_element(GMarkupParseContext *context,
        while (attribute_names[count++*ATTR_DISTANCE]);
        xistate=g_new0(struct xistate, 1);
        xistate->element=element_name;
-       xistate->attribute_names=g_new(char *, count);
-       xistate->attribute_values=g_new(char *, count);
+       xistate->attribute_names=g_new(const char *, count);
+       xistate->attribute_values=g_new(const char *, count);
        for (i = 0 ; i < count ; i++) {
                xistate->attribute_names[i]=g_strdup(attribute_names[i*ATTR_DISTANCE]);
                xistate->attribute_values[i]=g_strdup(attribute_values[i*ATTR_DISTANCE]);
@@ -766,8 +715,8 @@ xi_end_element (GMarkupParseContext *context,
                doc->active--;
        }
        while (xistate->attribute_names[i]) {
-               g_free(xistate->attribute_names[i]);
-               g_free(xistate->attribute_values[i]);
+               g_free((char *)(xistate->attribute_names[i]));
+               g_free((char *)(xistate->attribute_values[i]));
                i++;
        }
        g_free(xistate->attribute_names);