summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormartin-s <martin-s@ffa7fe5e-494d-0410-b361-a75ebd5db220>2008-10-27 15:58:27 +0000
committermartin-s <martin-s@ffa7fe5e-494d-0410-b361-a75ebd5db220>2008-10-27 15:58:27 +0000
commit2d931e8310372023a069ba5499b954f9ae54d206 (patch)
tree36d5f8e215140a1fc7d0225a0f357995c81d75d4
parent8e93295b3b9e42934839ba412cf1df7af3f4b1b3 (diff)
downloadnavit-2d931e8310372023a069ba5499b954f9ae54d206.tar.gz
Fix:Core:Further cleanups
git-svn-id: http://svn.code.sf.net/p/navit/code/trunk/navit@1580 ffa7fe5e-494d-0410-b361-a75ebd5db220
-rw-r--r--navit/attr.h3
-rw-r--r--navit/attr_def.h2
-rw-r--r--navit/navit.c16
-rw-r--r--navit/osm2navit.c2
-rw-r--r--navit/plugin.c20
-rw-r--r--navit/plugin.h3
-rw-r--r--navit/plugin_def.h2
-rw-r--r--navit/route.c2
-rw-r--r--navit/route.h2
-rw-r--r--navit/speech.c16
-rw-r--r--navit/speech.h2
-rw-r--r--navit/speech/cmdline/speech_cmdline.c7
-rw-r--r--navit/speech/speech_dispatcher/speech_speech_dispatcher.c2
-rw-r--r--navit/track.c3
-rw-r--r--navit/track.h2
-rw-r--r--navit/xmlconfig.c71
16 files changed, 59 insertions, 96 deletions
diff --git a/navit/attr.h b/navit/attr.h
index ee3b6d22a..a6b07279a 100644
--- a/navit/attr.h
+++ b/navit/attr.h
@@ -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;
diff --git a/navit/attr_def.h b/navit/attr_def.h
index 7a3102e23..f52da8a26 100644
--- a/navit/attr_def.h
+++ b/navit/attr_def.h
@@ -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)
diff --git a/navit/navit.c b/navit/navit.c
index 0f06d0aa5..053dad55f 100644
--- a/navit/navit.c
+++ b/navit/navit.c
@@ -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 *
diff --git a/navit/osm2navit.c b/navit/osm2navit.c
index 67e272de3..eaa753b2c 100644
--- a/navit/osm2navit.c
+++ b/navit/osm2navit.c
@@ -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);
diff --git a/navit/plugin.c b/navit/plugin.c
index f7c84ac40..8152ed43a 100644
--- a/navit/plugin.c
+++ b/navit/plugin.c
@@ -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
}
diff --git a/navit/plugin.h b/navit/plugin.h
index 6116f732e..4182bd362 100644
--- a/navit/plugin.h
+++ b/navit/plugin.h
@@ -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);
diff --git a/navit/plugin_def.h b/navit/plugin_def.h
index 8ebeb24b3..36d49c7f3 100644
--- a/navit/plugin_def.h
+++ b/navit/plugin_def.h
@@ -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))
diff --git a/navit/route.c b/navit/route.c
index 1cbc4204f..ec3fd29f3 100644
--- a/navit/route.c
+++ b/navit/route.c
@@ -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;
diff --git a/navit/route.h b/navit/route.h
index c020385a1..4b8422f40 100644
--- a/navit/route.h
+++ b/navit/route.h
@@ -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);
diff --git a/navit/speech.c b/navit/speech.c
index c9d44f494..9037129b6 100644
--- a/navit/speech.c
+++ b/navit/speech.c
@@ -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) {
diff --git a/navit/speech.h b/navit/speech.h
index 8f17aa5e2..b2893b7c4 100644
--- a/navit/speech.h
+++ b/navit/speech.h
@@ -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_);
diff --git a/navit/speech/cmdline/speech_cmdline.c b/navit/speech/cmdline/speech_cmdline.c
index 037bc84ef..5576e5dea 100644
--- a/navit/speech/cmdline/speech_cmdline.c
+++ b/navit/speech/cmdline/speech_cmdline.c
@@ -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;
}
diff --git a/navit/speech/speech_dispatcher/speech_speech_dispatcher.c b/navit/speech/speech_dispatcher/speech_speech_dispatcher.c
index 524645ef9..b2c0e2a0e 100644
--- a/navit/speech/speech_dispatcher/speech_speech_dispatcher.c
+++ b/navit/speech/speech_dispatcher/speech_speech_dispatcher.c
@@ -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;
diff --git a/navit/track.c b/navit/track.c
index ef5cd0367..44fb66b6e 100644
--- a/navit/track.c
+++ b/navit/track.c
@@ -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;
}
diff --git a/navit/track.h b/navit/track.h
index 0eb3a5cd5..03bec6fb5 100644
--- a/navit/track.h
+++ b/navit/track.h
@@ -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);
diff --git a/navit/xmlconfig.c b/navit/xmlconfig.c
index a5c41b488..53f5cde06 100644
--- a/navit/xmlconfig.c
+++ b/navit/xmlconfig.c
@@ -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);