summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormartin-s <martin-s@ffa7fe5e-494d-0410-b361-a75ebd5db220>2013-05-24 19:45:35 +0000
committermartin-s <martin-s@ffa7fe5e-494d-0410-b361-a75ebd5db220>2013-05-24 19:45:35 +0000
commitdba622cdd8c17cdc64aba50482f662f101c1c089 (patch)
tree18a99f54cfa635c2bb68148e802d8d98753502a3
parentb7c6731bddb1749962ebd95af7cc5153388caaa6 (diff)
downloadnavit-dba622cdd8c17cdc64aba50482f662f101c1c089.tar.gz
Add:Core:New xml tag for adding scripts to objects
git-svn-id: https://navit.svn.sourceforge.net/svnroot/navit/trunk@5503 ffa7fe5e-494d-0410-b361-a75ebd5db220
-rw-r--r--navit/navit/CMakeLists.txt2
-rw-r--r--navit/navit/Makefile.am2
-rw-r--r--navit/navit/attr_def.h1
-rw-r--r--navit/navit/navit.c1
-rw-r--r--navit/navit/script.c100
-rw-r--r--navit/navit/xmlconfig.c9
-rw-r--r--navit/navit/xmlconfig.h4
7 files changed, 114 insertions, 5 deletions
diff --git a/navit/navit/CMakeLists.txt b/navit/navit/CMakeLists.txt
index 310aac0cc..5bef49138 100644
--- a/navit/navit/CMakeLists.txt
+++ b/navit/navit/CMakeLists.txt
@@ -8,7 +8,7 @@ include_directories( "${CMAKE_CURRENT_SOURCE_DIR}/support")
set(NAVIT_SRC announcement.c atom.c attr.c cache.c callback.c command.c compass.c config_.c coord.c country.c data_window.c debug.c
event.c file.c geom.c graphics.c gui.c item.c layout.c log.c main.c map.c maps.c
linguistics.c mapset.c maptype.c menu.c messages.c bookmarks.c navit.c navit_nls.c navigation.c osd.c param.c phrase.c plugin.c popup.c
- profile.c profile_option.c projection.c roadprofile.c route.c routech.c search.c speech.c start_real.c sunriset.c transform.c track.c
+ profile.c profile_option.c projection.c roadprofile.c route.c routech.c script.c search.c speech.c start_real.c sunriset.c transform.c track.c
util.c vehicle.c vehicleprofile.c xmlconfig.c )
if(NOT USE_PLUGINS)
diff --git a/navit/navit/Makefile.am b/navit/navit/Makefile.am
index 99daddfe0..c153c421b 100644
--- a/navit/navit/Makefile.am
+++ b/navit/navit/Makefile.am
@@ -51,7 +51,7 @@ EXTRA_DIST = navit_shipped.xml navit.dtd
lib@LIBNAVIT@_la_SOURCES = announcement.c atom.c attr.c cache.c callback.c command.c compass.c config_.c coord.c country.c data_window.c debug.c \
event.c event_glib.h file.c geom.c graphics.c gui.c item.c layout.c log.c main.c map.c maps.c \
linguistics.c mapset.c maptype.c menu.c messages.c bookmarks.c bookmarks.h navit.c navigation.c osd.c param.c phrase.c plugin.c popup.c \
- profile.c profile_option.c projection.c roadprofile.c route.c routech.c search.c speech.c start_real.c transform.c track.c \
+ profile.c profile_option.c projection.c roadprofile.c route.c routech.c search.c script.c speech.c start_real.c transform.c track.c \
util.c vehicle.c vehicleprofile.c xmlconfig.c announcement.h atom.h attr.h attr_def.h cache.h callback.h color.h command.h compass.h config_.h coord.h country.h \
android.h data.h data_window.h data_window_int.h debug.h destination.h draw_info.h endianess.h event.h \
file.h geom.h graphics.h gtkext.h gui.h item.h item_def.h keys.h log.h layer.h layout.h linguistics.h main.h map-share.h map.h\
diff --git a/navit/navit/attr_def.h b/navit/navit/attr_def.h
index 7862b6158..cdb7a0e5d 100644
--- a/navit/navit/attr_def.h
+++ b/navit/navit/attr_def.h
@@ -450,6 +450,7 @@ ATTR(config)
ATTR(maps)
ATTR(layout)
ATTR(profile_option)
+ATTR(script)
ATTR2(0x0008ffff,type_object_end)
ATTR2(0x00090000,type_coord_begin)
ATTR2(0x0009ffff,type_coord_end)
diff --git a/navit/navit/navit.c b/navit/navit/navit.c
index 68f7f15ba..f4213ce50 100644
--- a/navit/navit/navit.c
+++ b/navit/navit/navit.c
@@ -2883,6 +2883,7 @@ navit_add_attr(struct navit *this_, struct attr *attr)
this_->autozoom_min = attr->u.num;
break;
case attr_layer:
+ case attr_script:
break;
default:
return 0;
diff --git a/navit/navit/script.c b/navit/navit/script.c
new file mode 100644
index 000000000..f9d395047
--- /dev/null
+++ b/navit/navit/script.c
@@ -0,0 +1,100 @@
+/**
+ * Navit, a modular navigation system.
+ * Copyright (C) 2005-2012 Navit Team
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terscr of the GNU General Public License
+ * version 2 as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the
+ * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301, USA.
+ */
+
+#include <glib.h>
+#include "item.h"
+#include "debug.h"
+#include "event.h"
+#include "callback.h"
+#include "xmlconfig.h"
+
+struct script
+{
+ NAVIT_OBJECT
+ char *text;
+ struct callback *cb;
+ struct event_timeout *timeout;
+};
+
+static void
+script_run(struct script *scr)
+{
+ struct attr *xml_text=attr_search(scr->attrs, NULL, attr_xml_text);
+ if (!xml_text || !xml_text->u.str) {
+ dbg(0,"no text\n");
+ return;
+ }
+ dbg(0,"running '%s'\n",xml_text->u.str);
+}
+
+static int
+script_set_attr_int(struct script *scr, struct attr *attr)
+{
+ switch (attr->type) {
+ case attr_update_period:
+ if (scr->timeout)
+ event_remove_timeout(scr->timeout);
+ scr->timeout=event_add_timeout(attr->u.num, 1, scr->cb);
+ return 1;
+ default:
+ return 0;
+ }
+}
+
+struct script *
+script_new(struct attr *parent, struct attr **attrs)
+{
+ struct script *scr=g_new0(struct script, 1);
+ scr->func=&script_func;
+ navit_object_ref((struct navit_object *)scr);
+ scr->attrs=attr_list_dup(attrs);
+ attrs=scr->attrs;
+ scr->cb=callback_new_1(callback_cast(script_run), scr);
+ while (attrs && *attrs)
+ script_set_attr_int(scr, *attrs++);
+ dbg(0,"return %p\n",scr);
+ return scr;
+}
+
+void
+script_destroy(struct script *scr)
+{
+ dbg(0,"enter %p\n",scr);
+ if (scr->timeout)
+ event_remove_timeout(scr->timeout);
+ callback_destroy(scr->cb);
+ attr_list_free(scr->attrs);
+ g_free(scr);
+}
+
+struct object_func script_func = {
+ attr_script,
+ (object_func_new)script_new,
+ (object_func_get_attr)navit_object_get_attr,
+ (object_func_iter_new)navit_object_attr_iter_new,
+ (object_func_iter_destroy)navit_object_attr_iter_destroy,
+ (object_func_set_attr)navit_object_set_attr,
+ (object_func_add_attr)navit_object_add_attr,
+ (object_func_remove_attr)navit_object_remove_attr,
+ (object_func_init)NULL,
+ (object_func_destroy)script_destroy,
+ (object_func_dup)NULL,
+ (object_func_ref)navit_object_ref,
+ (object_func_unref)navit_object_unref,
+};
diff --git a/navit/navit/xmlconfig.c b/navit/navit/xmlconfig.c
index 7896c03f9..337687895 100644
--- a/navit/navit/xmlconfig.c
+++ b/navit/navit/xmlconfig.c
@@ -301,6 +301,8 @@ object_func_lookup(enum attr_type type)
return &profile_option_func;
case attr_roadprofile:
return &roadprofile_func;
+ case attr_script:
+ return &script_func;
case attr_osd:
return &osd_func;
case attr_trackingo:
@@ -358,7 +360,7 @@ static char *element_fixmes[]={
};
static void initStatic(void) {
- elements=g_new0(struct element_func,43); //42 is a number of elements + ending NULL element
+ elements=g_new0(struct element_func,44); //43 is a number of elements + ending NULL element
elements[0].name="config";
elements[0].parent=NULL;
@@ -568,6 +570,11 @@ static void initStatic(void) {
elements[41].parent="profile_option";
elements[41].func=NULL;
elements[41].type=attr_roadprofile;
+
+ elements[42].name="script";
+ elements[42].parent="navit";
+ elements[42].func=NULL;
+ elements[42].type=attr_script;
}
/**
diff --git a/navit/navit/xmlconfig.h b/navit/navit/xmlconfig.h
index 26ac0233a..1a2ee3691 100644
--- a/navit/navit/xmlconfig.h
+++ b/navit/navit/xmlconfig.h
@@ -54,9 +54,9 @@ struct object_func {
void *(*unref)(void *);
};
-extern struct object_func map_func, mapset_func, navit_func, osd_func, tracking_func, vehicle_func, maps_func, layout_func, roadprofile_func, vehicleprofile_func, layer_func, config_func, profile_option_func;
+extern struct object_func map_func, mapset_func, navit_func, osd_func, tracking_func, vehicle_func, maps_func, layout_func, roadprofile_func, vehicleprofile_func, layer_func, config_func, profile_option_func, script_func;
-#define HAS_OBJECT_FUNC(x) ((x) == attr_map || (x) == attr_mapset || (x) == attr_navit || (x) == attr_osd || (x) == attr_trackingo || (x) == attr_vehicle || (x) == attr_maps || (x) == attr_layout || (x) == attr_roadprofile || (x) == attr_vehicleprofile || (x) == attr_layer || (x) == attr_config || (x) == attr_profile_option)
+#define HAS_OBJECT_FUNC(x) ((x) == attr_map || (x) == attr_mapset || (x) == attr_navit || (x) == attr_osd || (x) == attr_trackingo || (x) == attr_vehicle || (x) == attr_maps || (x) == attr_layout || (x) == attr_roadprofile || (x) == attr_vehicleprofile || (x) == attr_layer || (x) == attr_config || (x) == attr_profile_option || (x) == attr_script)
#define NAVIT_OBJECT struct object_func *func; int refcount; struct attr **attrs;
struct navit_object {