summaryrefslogtreecommitdiff
path: root/binding
diff options
context:
space:
mode:
Diffstat (limited to 'binding')
-rw-r--r--binding/Makefile.am10
-rw-r--r--binding/dbus/Makefile.am6
-rw-r--r--binding/dbus/binding_dbus.c960
-rwxr-xr-xbinding/dbus/eval.py12
-rw-r--r--binding/dbus/navit.introspect34
-rwxr-xr-xbinding/dbus/test.py11
-rw-r--r--binding/python/Makefile.am6
-rw-r--r--binding/python/attr.c99
-rw-r--r--binding/python/binding_python.c370
-rw-r--r--binding/python/common.h55
-rw-r--r--binding/python/main.c71
-rw-r--r--binding/python/navigation.c82
-rw-r--r--binding/python/navit.c135
-rw-r--r--binding/python/navit.xml.python7
-rw-r--r--binding/python/pcoord.c88
-rw-r--r--binding/python/route.c84
-rw-r--r--binding/python/startup.py8
-rw-r--r--binding/python/template.c96
18 files changed, 2134 insertions, 0 deletions
diff --git a/binding/Makefile.am b/binding/Makefile.am
new file mode 100644
index 00000000..48e0a8d6
--- /dev/null
+++ b/binding/Makefile.am
@@ -0,0 +1,10 @@
+SUBDIRS=
+if BINDING_PYTHON
+ SUBDIRS+=python
+endif
+if BINDING_DBUS
+ SUBDIRS+=dbus
+endif
+
+DIST_SUBDIRS=python dbus
+
diff --git a/binding/dbus/Makefile.am b/binding/dbus/Makefile.am
new file mode 100644
index 00000000..06e95ab9
--- /dev/null
+++ b/binding/dbus/Makefile.am
@@ -0,0 +1,6 @@
+include $(top_srcdir)/Makefile.inc
+AM_CPPFLAGS = @NAVIT_CFLAGS@ @DBUS_CFLAGS@ -I$(top_srcdir)/navit -DMODULE=binding_dbus
+modulebinding_LTLIBRARIES = libbinding_dbus.la
+libbinding_dbus_la_SOURCES = binding_dbus.c
+libbinding_dbus_la_LIBADD = @DBUS_LIBS@
+libbinding_dbus_la_LDFLAGS = -module -avoid-version
diff --git a/binding/dbus/binding_dbus.c b/binding/dbus/binding_dbus.c
new file mode 100644
index 00000000..0a45d2db
--- /dev/null
+++ b/binding/dbus/binding_dbus.c
@@ -0,0 +1,960 @@
+/**
+ * Navit, a modular navigation system.
+ * Copyright (C) 2005-2008 Navit Team
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms 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 <string.h>
+#define DBUS_API_SUBJECT_TO_CHANGE
+#include <dbus/dbus.h>
+#include <dbus/dbus-glib.h>
+#include <dbus/dbus-glib-lowlevel.h>
+#include "config.h"
+#include "main.h"
+#include "navit.h"
+#include "coord.h"
+#include "point.h"
+#include "plugin.h"
+#include "debug.h"
+#include "item.h"
+#include "attr.h"
+#include "layout.h"
+#include "command.h"
+#include "graphics.h"
+#include "util.h"
+
+
+static DBusConnection *connection;
+
+static char *service_name = "org.navit_project.navit";
+static char *object_path = "/org/navit_project/navit";
+char *navitintrospectxml_head1 = "<!DOCTYPE node PUBLIC \"-//freedesktop//DTD D-BUS Object Introspection 1.0//EN\"\n"
+ "\"http://www.freedesktop.org/standards/dbus/1.0/introspect.dtd\">\n"
+ "<node name=\"";
+
+char *navitintrospectxml_head2 = "\">\n"
+ " <interface name=\"org.freedesktop.DBus.Introspectable\">\n"
+ " <method name=\"Introspect\">\n"
+ " <arg direction=\"out\" type=\"s\" />\n"
+ " </method>\n"
+ " </interface>\n";
+
+
+
+GHashTable *object_hash;
+GHashTable *object_count;
+
+static char *
+object_new(char *type, void *object)
+{
+ int id;
+ char *ret;
+ dbg(0,"enter %s\n", type);
+ id=(int)g_hash_table_lookup(object_count, type);
+ g_hash_table_insert(object_count, type, (void *)(id+1));
+ ret=g_strdup_printf("%s/%s/%d", object_path, type, id);
+ g_hash_table_insert(object_hash, ret, object);
+ dbg(0,"return %s\n", ret);
+ return (ret);
+}
+
+static void *
+object_get(const char *path)
+{
+ return g_hash_table_lookup(object_hash, path);
+}
+
+static void *
+resolve_object(const char *opath, char *type)
+{
+ char *prefix;
+ void *ret=NULL;
+ char *def_navit="/default_navit";
+ char *def_graphics="/default_graphics";
+ struct attr attr;
+
+ if (strncmp(opath, object_path, strlen(object_path))) {
+ dbg(0,"wrong object path %s\n",opath);
+ return NULL;
+ }
+ prefix=g_strdup_printf("%s/%s/", object_path, type);
+ if (!strncmp(prefix, opath, strlen(prefix))) {
+ ret=object_get(opath);
+ g_free(prefix);
+ return ret;
+ }
+ g_free(prefix);
+ prefix=opath+strlen(object_path);
+ if (!strncmp(prefix,def_navit,strlen(def_navit))) {
+ prefix+=strlen(def_navit);
+ struct navit *navit=main_get_navit(NULL);
+ if (!prefix[0]) {
+ dbg(0,"default_navit\n");
+ return navit;
+ }
+ if (!strncmp(prefix,def_graphics,strlen(def_graphics))) {
+ if (navit_get_attr(navit, attr_graphics, &attr, NULL)) {
+ return attr.u.graphics;
+ }
+ return NULL;
+ }
+ }
+ return NULL;
+}
+
+static void *
+object_get_from_message_arg(DBusMessage *message, char *type)
+{
+ char *opath;
+ DBusError error;
+
+ dbus_error_init(&error);
+ if (!dbus_message_get_args(message, &error, DBUS_TYPE_OBJECT_PATH, &opath, DBUS_TYPE_INVALID)) {
+ dbus_error_free(&error);
+ dbg(0,"wrong arg type\n");
+ return NULL;
+ }
+ return resolve_object(opath, type);
+}
+
+static void *
+object_get_from_message(DBusMessage *message, char *type)
+{
+ return resolve_object(dbus_message_get_path(message), type);
+}
+
+static DBusHandlerResult
+reply_simple_as_variant(DBusConnection *connection, DBusMessage *message, int value, int dbus_type)
+{
+ DBusMessage *reply;
+
+ reply = dbus_message_new_method_return(message);
+ dbus_message_append_args(reply,
+ dbus_type, &value,
+ DBUS_TYPE_INVALID);
+ dbus_connection_send (connection, reply, NULL);
+ dbus_message_unref (reply);
+
+ return DBUS_HANDLER_RESULT_HANDLED;
+}
+
+static DBusHandlerResult
+empty_reply(DBusConnection *connection, DBusMessage *message)
+{
+ DBusMessage *reply;
+
+ reply = dbus_message_new_method_return(message);
+ dbus_connection_send (connection, reply, NULL);
+ dbus_message_unref (reply);
+
+ return DBUS_HANDLER_RESULT_HANDLED;
+}
+
+static DBusHandlerResult
+request_main_get_navit(DBusConnection *connection, DBusMessage *message)
+{
+ DBusMessage *reply;
+ DBusError error;
+ struct iter *iter;
+ struct navit *navit;
+ char *opath;
+
+ dbus_error_init(&error);
+
+ if (!dbus_message_get_args(message, &error, DBUS_TYPE_OBJECT_PATH, &opath, DBUS_TYPE_INVALID)) {
+ dbg(0,"Error parsing\n");
+ return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
+ }
+ dbg(0,"opath=%s\n", opath);
+ iter=object_get(opath);
+ navit=main_get_navit(iter);
+ if (navit) {
+ reply = dbus_message_new_method_return(message);
+ opath=object_new("navit",navit);
+ dbus_message_append_args(reply, DBUS_TYPE_OBJECT_PATH, &opath, DBUS_TYPE_INVALID);
+ dbus_connection_send (connection, reply, NULL);
+ dbus_message_unref (reply);
+ return DBUS_HANDLER_RESULT_HANDLED;
+ }
+ return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
+}
+
+static DBusHandlerResult
+request_main_iter(DBusConnection *connection, DBusMessage *message)
+{
+ DBusMessage *reply;
+ struct iter *iter=main_iter_new();
+ dbg(0,"iter=%p\n", iter);
+ char *opath=object_new("main_iter",iter);
+ reply = dbus_message_new_method_return(message);
+ dbus_message_append_args(reply, DBUS_TYPE_OBJECT_PATH, &opath, DBUS_TYPE_INVALID);
+ dbus_connection_send (connection, reply, NULL);
+ dbus_message_unref (reply);
+
+ return DBUS_HANDLER_RESULT_HANDLED;
+}
+
+static DBusHandlerResult
+request_main_iter_destroy(DBusConnection *connection, DBusMessage *message)
+{
+ struct iter *iter;
+
+ iter=object_get_from_message_arg(message, "main_iter");
+ if (! iter)
+ return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
+ main_iter_destroy(iter);
+
+ return empty_reply(connection, message);
+}
+
+/**
+ * Extracts a struct pcoord from a DBus message
+ *
+ * @param message The DBus message
+ * @param iter Sort of pointer that points on that (iii)-object in the message
+ * @param pc Pointer where the data should get stored
+ * @returns Returns 1 when everything went right, otherwise 0
+ */
+static int
+pcoord_get_from_message(DBusMessage *message, DBusMessageIter *iter, struct pcoord *pc)
+{
+
+ if(!strcmp(dbus_message_iter_get_signature(iter), "s")) {
+ char *coordstring;
+
+ dbus_message_iter_get_basic(iter, &coordstring);
+ if(!pcoord_parse(coordstring, projection_mg, pc))
+ return 0;
+
+ return 1;
+ } else {
+
+ DBusMessageIter iter2;
+ dbus_message_iter_recurse(iter, &iter2);
+ if(!strcmp(dbus_message_iter_get_signature(iter), "(is)")) {
+ char *coordstring;
+ int projection;
+
+ dbus_message_iter_get_basic(&iter2, &projection);
+
+ dbus_message_iter_next(&iter2);
+ dbus_message_iter_get_basic(&iter2, &coordstring);
+
+ if(!pcoord_parse(coordstring, projection, pc))
+ return 0;
+
+ return 1;
+ } else if(!strcmp(dbus_message_iter_get_signature(iter), "(iii)")) {
+
+ dbus_message_iter_get_basic(&iter2, &pc->pro);
+
+ dbus_message_iter_next(&iter2);
+ dbus_message_iter_get_basic(&iter2, &pc->x);
+
+ dbus_message_iter_next(&iter2);
+ dbus_message_iter_get_basic(&iter2, &pc->y);
+
+ return 1;
+ }
+ }
+ return 0;
+
+}
+
+static DBusHandlerResult
+request_navit_draw(DBusConnection *connection, DBusMessage *message)
+{
+ struct navit *navit;
+
+ navit=object_get_from_message(message, "navit");
+ if (! navit)
+ return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
+
+ navit_draw(navit);
+
+ return empty_reply(connection, message);
+}
+
+
+/**
+ * Extracts a struct point from a DBus message
+ *
+ * @param message The DBus message
+ * @param iter Sort of pointer that points on that (ii)-object in the message
+ * @param p Pointer where the data should get stored
+ * @returns Returns 1 when everything went right, otherwise 0
+ */
+static int
+point_get_from_message(DBusMessage *message, DBusMessageIter *iter, struct point *p)
+{
+ DBusMessageIter iter2;
+
+ dbg(0,"%s\n", dbus_message_iter_get_signature(iter));
+
+ dbus_message_iter_recurse(iter, &iter2);
+
+ if (dbus_message_iter_get_arg_type(&iter2) != DBUS_TYPE_INT32)
+ return 0;
+ dbus_message_iter_get_basic(&iter2, &p->x);
+
+ dbus_message_iter_next(&iter2);
+
+ if (dbus_message_iter_get_arg_type(&iter2) != DBUS_TYPE_INT32)
+ return 0;
+ dbus_message_iter_get_basic(&iter2, &p->y);
+
+ dbg(0, " x -> %x y -> %x\n", p->x, p->y);
+
+ dbus_message_iter_next(&iter2);
+
+ if (dbus_message_iter_get_arg_type(&iter2) != DBUS_TYPE_INVALID)
+ return 0;
+
+ return 1;
+}
+
+/**
+ * @brief Shows up a message
+ * @param connection The DBusConnection object through which \a message arrived
+ * @param message The DBusMessage containing the coordinates
+ * @returns An empty reply if everything went right, otherwise DBUS_HANDLER_RESULT_NOT_YET_HANDLED
+ */
+
+static DBusHandlerResult
+request_navit_add_message(DBusConnection *connection, DBusMessage *message)
+{
+ struct navit *navit;
+ char *usermessage;
+
+ DBusMessageIter iter;
+
+ navit=object_get_from_message(message, "navit");
+ if (! navit)
+ return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
+
+ dbus_message_iter_init(message, &iter);
+ dbus_message_iter_get_basic(&iter, &usermessage);
+
+ navit_add_message(navit, usermessage);
+
+ return empty_reply(connection, message);
+}
+
+
+/**
+ * @brief Centers the screen on a specified position \a pc on the world
+ * @param connection The DBusConnection object through which \a message arrived
+ * @param message The DBusMessage containing the coordinates
+ * @returns An empty reply if everything went right, otherwise DBUS_HANDLER_RESULT_NOT_YET_HANDLED
+ */
+
+static DBusHandlerResult
+request_navit_set_center(DBusConnection *connection, DBusMessage *message)
+{
+ struct pcoord pc;
+ struct navit *navit;
+ DBusMessageIter iter;
+
+ navit=object_get_from_message(message, "navit");
+ if (! navit)
+ return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
+
+ dbus_message_iter_init(message, &iter);
+
+ if (!pcoord_get_from_message(message, &iter, &pc))
+ return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
+
+ navit_set_center(navit, &pc, 0);
+ return empty_reply(connection, message);
+}
+
+/**
+ * @brief Centers the screen on a specified position \a p shown on the screen
+ * @param connection The DBusConnection object through which \a message arrived
+ * @param message The DBusMessage containing the x and y value
+ * @returns An empty reply if everything went right, otherwise DBUS_HANDLER_RESULT_NOT_YET_HANDLED
+ */
+static DBusHandlerResult
+request_navit_set_center_screen(DBusConnection *connection, DBusMessage *message)
+{
+ struct point p;
+ struct navit *navit;
+ DBusMessageIter iter;
+
+ navit=object_get_from_message(message, "navit");
+ if (! navit)
+ return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
+
+ dbus_message_iter_init(message, &iter);
+
+ if (!point_get_from_message(message, &iter, &p))
+ return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
+ navit_set_center_screen(navit, &p, 0);
+ return empty_reply(connection, message);
+}
+
+/**
+ * @brief Sets the layout to \a new_layout_name extracted from \a message
+ * @param connection The DBusConnection object through which \a message arrived
+ * @param message The DBusMessage containing the name of the layout
+ * @returns An empty reply if everything went right, otherwise DBUS_HANDLER_RESULT_NOT_YET_HANDLED
+ */
+static DBusHandlerResult
+request_navit_set_layout(DBusConnection *connection, DBusMessage *message)
+{
+ char *new_layout_name;
+ struct navit *navit;
+ struct attr attr;
+ struct attr_iter *iter;
+
+ navit=object_get_from_message(message, "navit");
+ if (! navit)
+ return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
+
+ if (!dbus_message_get_args(message, NULL, DBUS_TYPE_STRING, &new_layout_name, DBUS_TYPE_INVALID))
+ return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
+
+ iter=navit_attr_iter_new();
+ while(navit_get_attr(navit, attr_layout, &attr, iter)) {
+ if (strcmp(attr.u.layout->name, new_layout_name) == 0) {
+ navit_set_attr(navit, &attr);
+ }
+ }
+ return empty_reply(connection, message);
+}
+
+static DBusHandlerResult
+request_navit_zoom(DBusConnection *connection, DBusMessage *message)
+{
+ int factor;
+ struct point p;
+ struct navit *navit;
+ DBusMessageIter iter;
+
+ navit = object_get_from_message(message, "navit");
+ if (! navit)
+ return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
+
+ dbus_message_iter_init(message, &iter);
+ dbg(0,"%s\n", dbus_message_iter_get_signature(&iter));
+
+ dbus_message_iter_get_basic(&iter, &factor);
+
+ if (dbus_message_iter_has_next(&iter))
+ {
+ dbus_message_iter_next(&iter);
+ if (!point_get_from_message(message, &iter, &p))
+ return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
+ }
+
+ if (factor > 1)
+ navit_zoom_in(navit, factor, &p);
+ else if (factor < -1)
+ navit_zoom_out(navit, 0-factor, &p);
+
+ return empty_reply(connection, message);
+
+}
+
+static DBusHandlerResult
+request_navit_resize(DBusConnection *connection, DBusMessage *message)
+{
+ struct navit *navit;
+ int w, h;
+ DBusMessageIter iter;
+
+ navit = object_get_from_message(message, "navit");
+ if (! navit)
+ return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
+
+ dbus_message_iter_init(message, &iter);
+ dbg(0,"%s\n", dbus_message_iter_get_signature(&iter));
+
+ if (dbus_message_iter_get_arg_type(&iter) != DBUS_TYPE_INT32)
+ return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
+ dbus_message_iter_get_basic(&iter, &w);
+
+ dbus_message_iter_next(&iter);
+
+ if (dbus_message_iter_get_arg_type(&iter) != DBUS_TYPE_INT32)
+ return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
+ dbus_message_iter_get_basic(&iter, &h);
+
+ dbg(0, " w -> %i h -> %i\n", w, h);
+
+ navit_handle_resize(navit, w, h);
+
+ return empty_reply(connection, message);
+
+}
+
+static DBusHandlerResult
+request_navit_get_attr(DBusConnection *connection, DBusMessage *message)
+{
+ struct navit *navit;
+ DBusMessageIter iter;
+ char * attr_type = NULL;
+ struct attr attr;
+ navit = object_get_from_message(message, "navit");
+ if (! navit)
+ return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
+
+ dbus_message_iter_init(message, &iter);
+ dbus_message_iter_get_basic(&iter, &attr_type);
+ attr.type = attr_from_name(attr_type);
+ dbg(0, "attr value: 0x%x string: %s\n", attr.type, attr_type);
+
+ if (attr.type == attr_none)
+ return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
+
+ if (attr.type > attr_type_item_begin && attr.type < attr_type_item_end)
+ return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
+
+ else if (attr.type > attr_type_int_begin && attr.type < attr_type_boolean_begin)
+ {
+ dbg(0, "int detected\n");
+ if(navit_get_attr(navit, attr.type, &attr, NULL)) {
+ dbg(0, "%s = %i\n", attr_type, attr.u.num);
+ return reply_simple_as_variant(connection, message, attr.u.num, DBUS_TYPE_INT32);
+ }
+ }
+
+ else if(attr.type > attr_type_boolean_begin && attr.type < attr_type_int_end)
+ {
+ dbg(0, "bool detected\n");
+ if(navit_get_attr(navit, attr.type, &attr, NULL)) {
+ dbg(0, "%s = %i\n", attr_type, attr.u.num);
+ return reply_simple_as_variant(connection, message, attr.u.num, DBUS_TYPE_BOOLEAN);
+ }
+ }
+
+ else if(attr.type > attr_type_string_begin && attr.type < attr_type_string_end)
+ {
+ dbg(0, "string detected\n");
+ if(navit_get_attr(navit, attr.type, &attr, NULL)) {
+ dbg(0, "%s = %s\n", attr_type, &attr.u.layout);
+ return reply_simple_as_variant(connection, message, &attr.u.layout, DBUS_TYPE_STRING);
+ }
+ }
+
+#if 0
+ else if(attr.type > attr_type_special_begin && attr.type < attr_type_special_end)
+ return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
+
+ else if(attr.type > attr_type_double_begin && attr.type < attr_type_double_end)
+ return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
+
+ else if(attr.type > attr_type_coord_geo_begin && attr.type < attr_type_coord_geo_end)
+ return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
+
+ else if(attr.type > attr_type_color_begin && attr.type < attr_type_color_end)
+ return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
+
+ else if(attr.type > attr_type_object_begin && attr.type < attr_type_object_end)
+ return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
+
+ else if(attr.type > attr_type_coord_begin && attr.type < attr_type_coord_end)
+ return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
+
+ else if(attr.type > attr_type_pcoord_begin && attr.type < attr_type_pcoord_end)
+ return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
+
+ else if(attr.type > attr_type_callback_begin && attr.type < attr_type_callback_end)
+ return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
+#endif
+ else {
+ dbg(0, "zomg really unhandled111\n");
+ return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
+ }
+
+ return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
+}
+
+
+static DBusHandlerResult
+request_navit_set_attr(DBusConnection *connection, DBusMessage *message)
+{
+ struct navit *navit;
+ DBusMessageIter iter, iterattr;
+ struct attr attr;
+ char *attr_type;
+
+ navit = object_get_from_message(message, "navit");
+ if (! navit)
+ return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
+
+ dbus_message_iter_init(message, &iter);
+ dbus_message_iter_get_basic(&iter, &attr_type);
+ attr.type = attr_from_name(attr_type);
+ dbg(0, "attr value: 0x%x string: %s\n", attr.type, attr_type);
+
+ if (attr.type == attr_none)
+ return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
+
+ dbus_message_iter_next(&iter);
+ dbus_message_iter_recurse(&iter, &iterattr);
+ dbg(0, "seems valid. signature: %s\n", dbus_message_iter_get_signature(&iterattr));
+
+ if (attr.type > attr_type_item_begin && attr.type < attr_type_item_end)
+ return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
+
+ else if (attr.type > attr_type_int_begin && attr.type < attr_type_boolean_begin) {
+ if (dbus_message_iter_get_arg_type(&iterattr) == DBUS_TYPE_INT32)
+ {
+ dbus_message_iter_get_basic(&iterattr, &attr.u.num);
+ if (navit_set_attr(navit, &attr))
+ return empty_reply(connection, message);
+ }
+ }
+ else if(attr.type > attr_type_boolean_begin && attr.type < attr_type_int_end) {
+ if (dbus_message_iter_get_arg_type(&iterattr) == DBUS_TYPE_BOOLEAN)
+ {
+ dbus_message_iter_get_basic(&iterattr, &attr.u.num);
+ if (navit_set_attr(navit, &attr))
+ return empty_reply(connection, message);
+ }
+ }
+#if 0
+ else if(attr.type > attr_type_string_begin && attr.type < attr_type_string_end)
+ return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
+
+ else if(attr.type > attr_type_special_begin && attr.type < attr_type_special_end)
+ return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
+
+ else if(attr.type > attr_type_double_begin && attr.type < attr_type_double_end)
+ return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
+
+ else if(attr.type > attr_type_coord_geo_begin && attr.type < attr_type_coord_geo_end)
+ return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
+
+ else if(attr.type > attr_type_color_begin && attr.type < attr_type_color_end)
+ return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
+
+ else if(attr.type > attr_type_object_begin && attr.type < attr_type_object_end)
+ return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
+
+ else if(attr.type > attr_type_coord_begin && attr.type < attr_type_coord_end)
+ return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
+
+ else if(attr.type > attr_type_pcoord_begin && attr.type < attr_type_pcoord_end)
+ return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
+
+ else if(attr.type > attr_type_callback_begin && attr.type < attr_type_callback_end)
+ return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
+#endif
+ else {
+ dbg(0, "zomg really unhandled111\n");
+ return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
+ }
+
+ return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
+}
+
+static DBusHandlerResult
+request_navit_set_position(DBusConnection *connection, DBusMessage *message)
+{
+ struct pcoord pc;
+ struct navit *navit;
+ DBusMessageIter iter;
+
+ navit = object_get_from_message(message, "navit");
+ if (! navit)
+ return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
+
+ dbus_message_iter_init(message, &iter);
+ if (!pcoord_get_from_message(message, &iter, &pc))
+ return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
+
+ navit_set_position(navit, &pc);
+ return empty_reply(connection, message);
+}
+
+static DBusHandlerResult
+request_navit_set_destination(DBusConnection *connection, DBusMessage *message)
+{
+ struct pcoord pc;
+ struct navit *navit;
+ DBusMessageIter iter;
+ char *description;
+
+ navit = object_get_from_message(message, "navit");
+ if (! navit)
+ return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
+
+ dbus_message_iter_init(message, &iter);
+ if (!pcoord_get_from_message(message, &iter, &pc))
+ return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
+
+ dbus_message_iter_next(&iter);
+ dbus_message_iter_get_basic(&iter, &description);
+ dbg(0, " destination -> %s\n", description);
+
+ navit_set_destination(navit, &pc, description, 1);
+ return empty_reply(connection, message);
+}
+
+static DBusHandlerResult
+request_navit_evaluate(DBusConnection *connection, DBusMessage *message)
+{
+ struct navit *navit;
+ char *command;
+ char *result;
+ struct attr attr;
+ DBusMessage *reply;
+ int *error;
+
+ navit = object_get_from_message(message, "navit");
+ if (! navit)
+ return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
+
+ attr.type=attr_navit;
+ attr.u.navit=navit;
+ if (!dbus_message_get_args(message, NULL, DBUS_TYPE_STRING, &command, DBUS_TYPE_INVALID))
+ return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
+ result=command_evaluate_to_string(&attr, command, &error);
+ reply = dbus_message_new_method_return(message);
+ if (error)
+ dbus_message_append_args(reply, DBUS_TYPE_INT32, error, DBUS_TYPE_INVALID);
+ else
+ dbus_message_append_args(reply, DBUS_TYPE_STRING, &result, DBUS_TYPE_INVALID);
+ dbus_connection_send (connection, reply, NULL);
+ dbus_message_unref (reply);
+ return DBUS_HANDLER_RESULT_HANDLED;
+}
+
+static DBusHandlerResult
+request_graphics_get_data(DBusConnection *connection, DBusMessage *message)
+{
+ struct graphics *graphics;
+ char *data;
+ struct graphics_data_image *image;
+ DBusMessage *reply;
+
+ graphics = object_get_from_message(message, "graphics");
+ if (! graphics)
+ return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
+
+ if (!dbus_message_get_args(message, NULL, DBUS_TYPE_STRING, &data, DBUS_TYPE_INVALID))
+ return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
+ image=graphics_get_data(graphics, data);
+ if (image) {
+ DBusMessageIter iter1,iter2;
+ reply = dbus_message_new_method_return(message);
+#if 0
+ dbus_message_append_args(reply, DBUS_TYPE_STRING, &result, DBUS_TYPE_INVALID);
+#endif
+ dbus_message_iter_init_append(reply, &iter1);
+ dbus_message_iter_open_container(&iter1, DBUS_TYPE_ARRAY, "y", &iter2);
+ if (image->data && image->size)
+ dbus_message_iter_append_fixed_array(&iter2, DBUS_TYPE_BYTE, &image->data, image->size);
+ dbus_message_iter_close_container(&iter1, &iter2);
+ dbus_connection_send (connection, reply, NULL);
+ dbus_message_unref (reply);
+ return DBUS_HANDLER_RESULT_HANDLED;
+ }
+ return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
+}
+
+struct dbus_method {
+ char *path;
+ char *method;
+ char *signature;
+ char *signature_name;
+ char *response;
+ char *response_name;
+ DBusHandlerResult(*func)(DBusConnection *connection, DBusMessage *message);
+} dbus_methods[] = {
+ {"", "iter", "", "", "o", "navit", request_main_iter},
+ {"", "iter_destroy", "o", "navit", "", "", request_main_iter_destroy},
+ {"", "get_navit", "o", "navit", "o", "", request_main_get_navit},
+ {".navit", "draw", "", "", "", "", request_navit_draw},
+ {".navit", "add_message", "s", "message", "", "", request_navit_add_message},
+ {".navit", "set_center", "s", "(coordinates)", "", "", request_navit_set_center},
+ {".navit", "set_center", "(is)", "(projection,coordinates)", "", "", request_navit_set_center},
+ {".navit", "set_center", "(iii)", "(projection,longitude,latitude)", "", "", request_navit_set_center},
+ {".navit", "set_center_screen", "(ii)", "(pixel_x,pixel_y)", "", "", request_navit_set_center_screen},
+ {".navit", "set_layout", "s", "layoutname", "", "", request_navit_set_layout},
+ {".navit", "zoom", "i(ii)", "factor(pixel_x,pixel_y)", "", "", request_navit_zoom},
+ {".navit", "zoom", "i", "factor", "", "", request_navit_zoom},
+ {".navit", "resize", "ii", "upperleft,lowerright", "", "", request_navit_resize},
+ {".navit", "get_attr", "s", "attribute", "v", "value", request_navit_get_attr},
+ {".navit", "set_attr", "sv", "attribute,value", "", "", request_navit_set_attr},
+ {".navit", "set_position", "s", "(coordinates)", "", "", request_navit_set_position},
+ {".navit", "set_position", "(is)", "(projection,coordinated)", "", "", request_navit_set_position},
+ {".navit", "set_position", "(iii)", "(projection,longitude,latitude)", "", "", request_navit_set_position},
+ {".navit", "set_destination", "ss", "coordinates,comment", "", "", request_navit_set_destination},
+ {".navit", "set_destination", "(is)s", "(projection,coordinates)comment", "", "", request_navit_set_destination},
+ {".navit", "set_destination", "(iii)s", "(projection,longitude,latitude)comment", "", "", request_navit_set_destination},
+ {".navit", "evaluate", "s", "command", "s", "", request_navit_evaluate},
+ {".graphics","get_data", "s", "type", "ay", "data", request_graphics_get_data},
+#if 0
+ {".navit", "toggle_announcer", "", "", "", "", request_navit_toggle_announcer},
+ {".navit", "toggle_announcer", "i", "", "", "", request_navit_toggle_announcer},
+#endif
+};
+
+static char *
+introspect_path(char *object)
+{
+ char *ret;
+ int i;
+ char *def=".default_";
+ int def_len=strlen(def);
+ if (strncmp(object, object_path, strlen(object_path)))
+ return NULL;
+ ret=g_strdup(object+strlen(object_path));
+ dbg(0,"path=%s\n",ret);
+ for (i = strlen(ret)-1 ; i >= 0 ; i--) {
+ if (ret[i] == '/' || (ret[i] >= '0' && ret[i] <= '9'))
+ ret[i]='\0';
+ else
+ break;
+ }
+ for (i = 0 ; i < strlen(ret); i++)
+ if (ret[i] == '/')
+ ret[i]='.';
+
+ for (i = strlen(ret)-1 ; i >= 0 ; i--) {
+ if (!strncmp(ret+i, def, def_len)) {
+ memmove(ret+1,ret+i+def_len,strlen(ret+i+def_len)+1);
+ break;
+ }
+ }
+ return ret;
+}
+
+static char *
+generate_navitintrospectxml(char *object)
+{
+ int i,methods_size,n=0;
+ char *navitintrospectxml;
+ char *path=introspect_path(object);
+ if (!path)
+ return NULL;
+ dbg(0,"path=%s\n",path);
+
+ // write header and make navit introspectable
+ navitintrospectxml = g_strdup_printf("%s%s%s\n", navitintrospectxml_head1, object, navitintrospectxml_head2);
+
+ methods_size=sizeof(dbus_methods)/sizeof(struct dbus_method);
+ for (i = 0 ; i < methods_size ; i++) {
+ // start new interface if it's the first method or it changed
+ if (strcmp(dbus_methods[i].path, path))
+ continue;
+ if ((n == 0) || strcmp(dbus_methods[i-1].path, dbus_methods[i].path))
+ navitintrospectxml = g_strconcat_printf(navitintrospectxml, " <interface name=\"%s%s\">\n", service_name, dbus_methods[i].path);
+ n++;
+
+ // start the new method
+ navitintrospectxml = g_strconcat_printf(navitintrospectxml, " <method name=\"%s\">\n", dbus_methods[i].method);
+
+ // set input signature if existent
+ if (strcmp(dbus_methods[i].signature, ""))
+ navitintrospectxml = g_strconcat_printf(navitintrospectxml, " <arg direction=\"in\" name=\"%s\" type=\"%s\" />\n", dbus_methods[i].signature_name, dbus_methods[i].signature);
+
+ // set response signature if existent
+ if (strcmp(dbus_methods[i].response, ""))
+ navitintrospectxml = g_strconcat_printf(navitintrospectxml, " <arg direction=\"out\" name=\"%s\" type=\"%s\" />\n", dbus_methods[i].response_name, dbus_methods[i].response);
+
+ // close the method
+ navitintrospectxml = g_strconcat_printf(navitintrospectxml, " </method>\n");
+
+ // close the interface if we reached the last method or the interface changes
+ if ((methods_size == i+1) || ((methods_size > i+1) && strcmp(dbus_methods[i+1].path, dbus_methods[i].path)))
+ navitintrospectxml = g_strconcat_printf(navitintrospectxml, " </interface>\n\n");
+ }
+ // close the "mother tag"
+ navitintrospectxml = g_strconcat_printf(navitintrospectxml, "</node>\n");
+
+ return navitintrospectxml;
+}
+
+static DBusHandlerResult
+navit_handler_func(DBusConnection *connection, DBusMessage *message, void *user_data)
+{
+ int i;
+ char *path;
+ dbg(0,"type=%s interface=%s path=%s member=%s signature=%s\n", dbus_message_type_to_string(dbus_message_get_type(message)), dbus_message_get_interface(message), dbus_message_get_path(message), dbus_message_get_member(message), dbus_message_get_signature(message));
+ if (dbus_message_is_method_call (message, "org.freedesktop.DBus.Introspectable", "Introspect")) {
+ DBusMessage *reply;
+ char *navitintrospectxml = generate_navitintrospectxml(dbus_message_get_path(message));
+ dbg(0,"Introspect %s:Result:%s\n",dbus_message_get_path(message), navitintrospectxml);
+ if (navitintrospectxml) {
+ reply = dbus_message_new_method_return(message);
+ dbus_message_append_args(reply, DBUS_TYPE_STRING, &navitintrospectxml, DBUS_TYPE_INVALID);
+ dbus_connection_send (connection, reply, NULL);
+ dbus_message_unref (reply);
+ g_free(navitintrospectxml);
+ return DBUS_HANDLER_RESULT_HANDLED;
+ }
+ return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
+ }
+
+ for (i = 0 ; i < sizeof(dbus_methods)/sizeof(struct dbus_method) ; i++) {
+ path=g_strdup_printf("%s%s", service_name, dbus_methods[i].path);
+ if (dbus_message_is_method_call(message, path, dbus_methods[i].method) &&
+ dbus_message_has_signature(message, dbus_methods[i].signature)) {
+ g_free(path);
+ return dbus_methods[i].func(connection, message);
+ }
+ g_free(path);
+ }
+ return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
+}
+
+static DBusObjectPathVTable dbus_navit_vtable = {
+ NULL,
+ navit_handler_func,
+ NULL
+};
+
+#if 0
+DBusHandlerResult
+filter(DBusConnection *connection, DBusMessage *message, void *user_data)
+{
+ dbg(0,"type=%s interface=%s path=%s member=%s signature=%s\n", dbus_message_type_to_string(dbus_message_get_type(message)), dbus_message_get_interface(message), dbus_message_get_path(message), dbus_message_get_member(message), dbus_message_get_signature(message));
+ if (dbus_message_is_signal(message, DBUS_INTERFACE_DBUS, "NameOwnerChanged")) {
+ }
+ return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
+}
+#endif
+
+void plugin_init(void)
+{
+ DBusError error;
+
+ object_hash=g_hash_table_new(g_str_hash, g_str_equal);
+ object_count=g_hash_table_new(g_str_hash, g_str_equal);
+ dbg(0,"enter 1\n");
+ dbus_error_init(&error);
+ connection = dbus_bus_get(DBUS_BUS_SESSION, &error);
+ if (!connection) {
+ dbg(0,"Failed to open connection to session message bus: %s\n", error.message);
+ dbus_error_free(&error);
+ return;
+ }
+ dbus_connection_setup_with_g_main(connection, NULL);
+#if 0
+ dbus_connection_add_filter(connection, filter, NULL, NULL);
+ dbus_bus_add_match(connection, "type='signal',""interface='" DBUS_INTERFACE_DBUS "'", &error);
+#endif
+ dbus_connection_register_fallback(connection, object_path, &dbus_navit_vtable, NULL);
+ dbus_bus_request_name(connection, service_name, 0, &error);
+ if (dbus_error_is_set(&error)) {
+ dbg(0,"Failed to request name: %s", error.message);
+ dbus_error_free (&error);
+ }
+}
diff --git a/binding/dbus/eval.py b/binding/dbus/eval.py
new file mode 100755
index 00000000..2255f968
--- /dev/null
+++ b/binding/dbus/eval.py
@@ -0,0 +1,12 @@
+#! /usr/bin/python
+import dbus
+import sys
+bus = dbus.SessionBus()
+conn = bus.get_object('org.navit_project.navit',
+ '/org/navit_project/navit')
+iface = dbus.Interface(conn, dbus_interface='org.navit_project.navit');
+iter=iface.iter();
+navit=bus.get_object('org.navit_project.navit', conn.get_navit(iter));
+iface.iter_destroy(iter);
+navit_iface = dbus.Interface(navit, dbus_interface='org.navit_project.navit.navit');
+print navit_iface.evaluate(sys.argv[1]);
diff --git a/binding/dbus/navit.introspect b/binding/dbus/navit.introspect
new file mode 100644
index 00000000..9366c0cb
--- /dev/null
+++ b/binding/dbus/navit.introspect
@@ -0,0 +1,34 @@
+<!DOCTYPE node PUBLIC "-//freedesktop//DTD D-BUS Object Introspection 1.0//EN"
+"http://www.freedesktop.org/standards/dbus/1.0/introspect.dtd">
+<node name="/org/navit_project/navit">
+ <interface name="org.freedesktop.DBus.Introspectable">
+ <method name="Introspect">
+ <arg direction="out" type="s" />
+ </method>
+ </interface>
+
+ <interface name="org.navit_project.navit">
+ <method name="get_navit">
+ <arg name="iter" type="o" direction="in"/>
+ <arg name="navit" type="o" direction="out"/>
+ </method>
+ <method name="iter_new">
+ <arg name="iter" type="o" direction="out"/>
+ </method>
+ <method name="iter_destroy">
+ <arg name="iter" type="o" direction="in"/>
+ </method>
+ </interface>
+
+ <interface name="org.navit_project.navit.navit">
+ <method name="zoom">
+ <arg type="i" direction="in" />
+ </method>
+ <method name="zoom">
+ <arg type="i(ii)" direction="in" />
+ </method>
+ <method name="set_center_screen">
+ <arg type="ii" direction="in" />
+ </method>
+ </interface>
+</node>
diff --git a/binding/dbus/test.py b/binding/dbus/test.py
new file mode 100755
index 00000000..6447648c
--- /dev/null
+++ b/binding/dbus/test.py
@@ -0,0 +1,11 @@
+#! /usr/bin/python
+import dbus
+bus = dbus.SessionBus()
+conn = bus.get_object('org.navit_project.navit',
+ '/org/navit_project/navit')
+iface = dbus.Interface(conn, dbus_interface='org.navit_project.navit');
+iter=iface.iter();
+navit=bus.get_object('org.navit_project.navit', conn.get_navit(iter));
+iface.iter_destroy(iter);
+navit_iface = dbus.Interface(navit, dbus_interface='org.navit_project.navit.navit');
+navit_iface.set_center((1,0x138a4a,0x5d773f));
diff --git a/binding/python/Makefile.am b/binding/python/Makefile.am
new file mode 100644
index 00000000..dd74229a
--- /dev/null
+++ b/binding/python/Makefile.am
@@ -0,0 +1,6 @@
+include $(top_srcdir)/Makefile.inc
+AM_CPPFLAGS = @NAVIT_CFLAGS@ @PYTHON_CFLAGS@ -I$(top_srcdir)/navit -DMODULE=binding_python
+modulebinding_LTLIBRARIES = libbinding_python.la
+libbinding_python_la_SOURCES = binding_python.c main.c navit.c pcoord.c route.c navigation.c attr.c common.h
+libbinding_python_la_LIBADD = @PYTHON_LIBS@
+libbinding_python_la_LDFLAGS = -module -avoid-version
diff --git a/binding/python/attr.c b/binding/python/attr.c
new file mode 100644
index 00000000..2d5ed92b
--- /dev/null
+++ b/binding/python/attr.c
@@ -0,0 +1,99 @@
+/**
+ * Navit, a modular navigation system.
+ * Copyright (C) 2005-2008 Navit Team
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms 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 "common.h"
+#include "item.h"
+#include "attr.h"
+
+typedef struct {
+ PyObject_HEAD
+ int ref;
+ struct attr *attr;
+} attrObject;
+
+static PyObject *
+attr_func(attrObject *self, PyObject *args)
+{
+ const char *file;
+ int ret;
+ if (!PyArg_ParseTuple(args, "s", &file))
+ return NULL;
+ ret=0;
+ return Py_BuildValue("i",ret);
+}
+
+
+
+static PyMethodDef attr_methods[] = {
+ {"func", (PyCFunction) attr_func, METH_VARARGS },
+ {NULL, NULL },
+};
+
+
+static PyObject *
+attr_getattr_py(PyObject *self, char *name)
+{
+ return Py_FindMethod(attr_methods, self, name);
+}
+
+static void
+attr_destroy_py(attrObject *self)
+{
+ if (! self->ref)
+ attr_free(self->attr);
+}
+
+PyTypeObject attr_Type = {
+ Obj_HEAD
+ .tp_name="attr",
+ .tp_basicsize=sizeof(attrObject),
+ .tp_dealloc=(destructor)attr_destroy_py,
+ .tp_getattr=attr_getattr_py,
+};
+
+struct attr *
+attr_py_get(PyObject *self)
+{
+ return ((attrObject *)self)->attr;
+}
+
+PyObject *
+attr_new_py(PyObject *self, PyObject *args)
+{
+ attrObject *ret;
+ const char *name,*value;
+ if (!PyArg_ParseTuple(args, "ss", &name, &value))
+ return NULL;
+ ret=PyObject_NEW(attrObject, &attr_Type);
+ ret->attr=attr_new_from_text(name, value);
+ ret->ref=0;
+ return (PyObject *)ret;
+}
+
+PyObject *
+attr_new_py_ref(struct attr *attr)
+{
+ attrObject *ret;
+
+ ret=PyObject_NEW(attrObject, &attr_Type);
+ ret->ref=1;
+ ret->attr=attr;
+ return (PyObject *)ret;
+}
+
diff --git a/binding/python/binding_python.c b/binding/python/binding_python.c
new file mode 100644
index 00000000..6d4fcc78
--- /dev/null
+++ b/binding/python/binding_python.c
@@ -0,0 +1,370 @@
+/**
+ * Navit, a modular navigation system.
+ * Copyright (C) 2005-2008 Navit Team
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms 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 "config.h"
+#include <glib.h>
+#include "common.h"
+#include <fcntl.h>
+#include "coord.h"
+#include "projection.h"
+#include "debug.h"
+#include "item.h"
+#include "map.h"
+#include "mapset.h"
+#include "plugin.h"
+#include "debug.h"
+#include "item.h"
+#include "attr.h"
+#include "xmlconfig.h"
+
+#if defined(MS_WINDOWS) || defined(__CYGWIN__)
+#define Obj_HEAD PyObject_HEAD_INIT(NULL);
+#else
+#define Obj_HEAD PyObject_HEAD_INIT(&PyType_Type)
+#endif
+
+/* *** coord *** */
+
+typedef struct {
+ PyObject_HEAD
+ struct coord *c;
+} coordObject;
+
+static void coord_destroy_py(coordObject *self);
+
+PyTypeObject coord_Type = {
+ Obj_HEAD
+ .tp_name="coord",
+ .tp_basicsize=sizeof(coordObject),
+ .tp_dealloc=(destructor)coord_destroy_py,
+};
+
+
+/* *** map *** */
+
+typedef struct {
+ PyObject_HEAD
+ int ref;
+ struct map *m;
+} mapObject;
+
+static void map_destroy_py(mapObject *self);
+static PyObject *map_getattr_py(PyObject *self, char *name);
+
+PyTypeObject map_Type = {
+ Obj_HEAD
+ .tp_name="map",
+ .tp_basicsize=sizeof(mapObject),
+ .tp_dealloc=(destructor)map_destroy_py,
+ .tp_getattr=map_getattr_py,
+};
+
+/* *** IMPLEMENTATIONS *** */
+
+/* *** coord *** */
+
+static PyObject *
+coord_new_py(PyObject *self, PyObject *args)
+{
+ coordObject *ret;
+ int x,y;
+ if (!PyArg_ParseTuple(args, "ii:navit.coord",&x,&y))
+ return NULL;
+ ret=PyObject_NEW(coordObject, &coord_Type);
+ ret->c=coord_new(x,y);
+ return (PyObject *)ret;
+}
+
+static void
+coord_destroy_py(coordObject *self)
+{
+ coord_destroy(self->c);
+}
+
+/* *** coord_rect *** */
+
+typedef struct {
+ PyObject_HEAD
+ struct coord_rect *r;
+} coord_rectObject;
+
+
+static void coord_rect_destroy_py(coord_rectObject *self);
+
+PyTypeObject coord_rect_Type = {
+#if defined(MS_WINDOWS) || defined(__CYGWIN__)
+ PyObject_HEAD_INIT(NULL);
+#else
+ PyObject_HEAD_INIT(&PyType_Type)
+#endif
+ .tp_name="coord_rect",
+ .tp_basicsize=sizeof(coord_rectObject),
+ .tp_dealloc=(destructor)coord_rect_destroy_py,
+};
+
+static PyObject *
+coord_rect_new_py(PyObject *self, PyObject *args)
+{
+ coord_rectObject *ret;
+ coordObject *lu,*rd;
+ if (!PyArg_ParseTuple(args, "O!O!:navit.coord_rect_rect",&coord_Type,&lu,&coord_Type,&rd))
+ return NULL;
+ ret=PyObject_NEW(coord_rectObject, &coord_rect_Type);
+ ret->r=coord_rect_new(lu->c,rd->c);
+ return (PyObject *)ret;
+}
+
+static void
+coord_rect_destroy_py(coord_rectObject *self)
+{
+ coord_rect_destroy(self->r);
+}
+
+/* *** map_rect *** */
+
+typedef struct {
+ PyObject_HEAD
+ struct map_rect *mr;
+} map_rectObject;
+
+
+static void map_rect_destroy_py(map_rectObject *self);
+
+PyTypeObject map_rect_Type = {
+#if defined(MS_WINDOWS) || defined(__CYGWIN__)
+ PyObject_HEAD_INIT(NULL);
+#else
+ PyObject_HEAD_INIT(&PyType_Type)
+#endif
+ .tp_name="map_rect",
+ .tp_basicsize=sizeof(map_rectObject),
+ .tp_dealloc=(destructor)map_rect_destroy_py,
+};
+
+static PyObject *
+map_rect_new_py(mapObject *self, PyObject *args)
+{
+ map_rectObject *ret;
+ coord_rectObject *r;
+ if (!PyArg_ParseTuple(args, "O!:navit.map_rect_rect",&coord_rect_Type,&r))
+ return NULL;
+ ret=PyObject_NEW(map_rectObject, &map_rect_Type);
+ ret->mr=map_rect_new(self->m, NULL);
+ return (PyObject *)ret;
+}
+
+static void
+map_rect_destroy_py(map_rectObject *self)
+{
+ map_rect_destroy(self->mr);
+}
+
+
+/* *** map *** */
+
+static PyObject *
+map_dump_file_py(mapObject *self, PyObject *args)
+{
+ const char *s;
+ if (!PyArg_ParseTuple(args, "s",&s))
+ return NULL;
+ map_dump_file(self->m, s);
+ Py_RETURN_NONE;
+}
+
+
+static PyObject *
+map_set_attr_py(mapObject *self, PyObject *args)
+{
+ PyObject *attr;
+ if (!PyArg_ParseTuple(args, "O!", &attr_Type, &attr))
+ return NULL;
+ map_set_attr(self->m, attr_py_get(attr));
+ Py_RETURN_NONE;
+}
+
+
+
+static PyMethodDef map_methods[] = {
+ {"dump_file", (PyCFunction) map_dump_file_py, METH_VARARGS },
+ {"map_rect_new", (PyCFunction) map_rect_new_py, METH_VARARGS },
+ {"set_attr", (PyCFunction) map_set_attr_py, METH_VARARGS },
+ {NULL, NULL },
+};
+
+static PyObject *
+map_getattr_py(PyObject *self, char *name)
+{
+ return Py_FindMethod(map_methods, self, name);
+}
+
+
+static PyObject *
+map_new_py(PyObject *self, PyObject *args)
+{
+ mapObject *ret;
+ char *type, *filename;
+
+ if (!PyArg_ParseTuple(args, "ss:navit.map", &type, &filename))
+ return NULL;
+ ret=PyObject_NEW(mapObject, &map_Type);
+ ret->m=map_new(NULL,NULL);
+ ret->ref=0;
+ return (PyObject *)ret;
+}
+
+PyObject *
+map_py_ref(struct map *map)
+{
+ mapObject *ret;
+ ret=PyObject_NEW(mapObject, &map_Type);
+ ret->m=map;
+ ret->ref=1;
+ return (PyObject *)ret;
+}
+
+static void
+map_destroy_py(mapObject *self)
+{
+ if (!self->ref)
+ map_destroy(self->m);
+}
+
+/* *** mapset *** */
+
+
+typedef struct {
+ PyObject_HEAD
+ struct mapset *ms;
+} mapsetObject;
+
+
+static void mapset_destroy_py(mapsetObject *self);
+static PyObject *mapset_getattr_py(PyObject *self, char *name);
+
+PyTypeObject mapset_Type = {
+#if defined(MS_WINDOWS) || defined(__CYGWIN__)
+ PyObject_HEAD_INIT(NULL);
+#else
+ PyObject_HEAD_INIT(&PyType_Type)
+#endif
+ .tp_name="mapset",
+ .tp_basicsize=sizeof(mapsetObject),
+ .tp_dealloc=(destructor)mapset_destroy_py,
+ .tp_getattr=mapset_getattr_py,
+};
+
+static PyObject *
+mapset_add_py(mapsetObject *self, PyObject *args)
+{
+ mapObject *map;
+ if (!PyArg_ParseTuple(args, "O:navit.mapset", &map))
+ return NULL;
+ Py_INCREF(map);
+ mapset_add_attr(self->ms, &(struct attr){attr_map,.u.map=map->m});
+ return Py_BuildValue("");
+}
+
+static PyMethodDef mapset_methods[] = {
+ {"add", (PyCFunction) mapset_add_py, METH_VARARGS },
+ {NULL, NULL },
+};
+
+static PyObject *
+mapset_getattr_py(PyObject *self, char *name)
+{
+ return Py_FindMethod(mapset_methods, self, name);
+}
+
+static PyObject *
+mapset_new_py(PyObject *self, PyObject *args)
+{
+ mapsetObject *ret;
+ if (!PyArg_ParseTuple(args, ":navit.mapset"))
+ return NULL;
+ ret=PyObject_NEW(mapsetObject, &mapset_Type);
+ ret->ms=mapset_new(NULL,NULL);
+ return (PyObject *)ret;
+}
+
+static void
+mapset_destroy_py(mapsetObject *self)
+{
+ mapset_destroy(self->ms);
+}
+
+static PyObject *
+config_load_py(PyObject *self, PyObject *args)
+{
+ const char *file;
+ int ret;
+ xmlerror *error;
+ if (!PyArg_ParseTuple(args, "s", &file))
+ return NULL;
+ ret=config_load(file, &error);
+ return Py_BuildValue("i",ret);
+}
+
+static PyMethodDef navitMethods[]={
+ {"attr", attr_new_py, METH_VARARGS},
+ {"coord", coord_new_py, METH_VARARGS, "Create a new coordinate point."},
+ {"coord_rect", coord_rect_new_py, METH_VARARGS, "Create a new coordinate rectangle."},
+ {"map", map_new_py, METH_VARARGS, "Create a new map."},
+ {"mapset", mapset_new_py, METH_VARARGS, "Create a new mapset."},
+ {"config_load", config_load_py, METH_VARARGS, "Load a config"},
+ {"main", main_py, METH_VARARGS, "Get Main Object"},
+ {"pcoord", pcoord_py, METH_VARARGS},
+ {NULL, NULL, 0, NULL}
+};
+
+
+PyObject *
+python_object_from_attr(struct attr *attr)
+{
+ switch (attr->type) {
+ case attr_navigation:
+ return navigation_py_ref(attr->u.navigation);
+ case attr_route:
+ return route_py_ref(attr->u.route);
+ default:
+ return NULL;
+ }
+ return NULL;
+}
+
+
+void
+plugin_init(void)
+{
+ int fd,size;
+ char buffer[65536];
+
+ Py_Initialize();
+ Py_InitModule("navit", navitMethods);
+ fd=open("startup.py",O_RDONLY);
+ if (fd >= 0) {
+ size=read(fd, buffer, 65535);
+ if (size > 0) {
+ buffer[size]='\0';
+ PyRun_SimpleString(buffer);
+ }
+ }
+
+ Py_Finalize();
+}
diff --git a/binding/python/common.h b/binding/python/common.h
new file mode 100644
index 00000000..5c1a270c
--- /dev/null
+++ b/binding/python/common.h
@@ -0,0 +1,55 @@
+/**
+ * Navit, a modular navigation system.
+ * Copyright (C) 2005-2008 Navit Team
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms 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 <Python.h>
+#include "debug.h"
+
+#if defined(MS_WINDOWS) || defined(__CYGWIN__)
+#define Obj_HEAD PyObject_HEAD_INIT(NULL);
+#else
+#define Obj_HEAD PyObject_HEAD_INIT(&PyType_Type)
+#endif
+
+struct navit;
+struct map;
+
+PyObject * python_object_from_attr(struct attr *attr);
+
+PyObject * main_py(PyObject *self, PyObject *args);
+
+PyObject * map_py_ref(struct map *map);
+
+struct navigation;
+PyObject * navigation_py(PyObject *self, PyObject *args);
+PyObject * navigation_py_ref(struct navigation *navigation);
+
+PyObject * navit_py(PyObject *self, PyObject *args);
+PyObject * navit_py_ref(struct navit *navit);
+extern PyTypeObject pcoord_Type;
+PyObject * pcoord_py(PyObject *self, PyObject *args);
+struct pcoord *pcoord_py_get(PyObject *self);
+
+struct route;
+PyObject * route_py(PyObject *self, PyObject *args);
+PyObject * route_py_ref(struct route *route);
+
+extern PyTypeObject attr_Type;
+PyObject * attr_new_py(PyObject *self, PyObject *args);
+PyObject * attr_new_py_ref(struct attr *attr);
+struct attr * attr_py_get(PyObject *self);
diff --git a/binding/python/main.c b/binding/python/main.c
new file mode 100644
index 00000000..5a782cc7
--- /dev/null
+++ b/binding/python/main.c
@@ -0,0 +1,71 @@
+/**
+ * Navit, a modular navigation system.
+ * Copyright (C) 2005-2008 Navit Team
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms 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 "common.h"
+#include "main.h"
+
+typedef struct {
+ PyObject_HEAD
+} mainObject;
+
+static PyObject *
+main_navit(PyObject *self, PyObject *args)
+{
+ struct navit *navit;
+ navit=main_get_navit(NULL);
+ return navit_py_ref(navit);
+}
+
+
+
+static PyMethodDef main_methods[] = {
+ {"navit", (PyCFunction) main_navit, METH_VARARGS },
+ {NULL, NULL },
+};
+
+
+static PyObject *
+main_getattr_py(PyObject *self, char *name)
+{
+ return Py_FindMethod(main_methods, self, name);
+}
+
+static void
+main_destroy_py(mainObject *self)
+{
+}
+
+PyTypeObject main_Type = {
+ Obj_HEAD
+ .tp_name="main",
+ .tp_basicsize=sizeof(mainObject),
+ .tp_dealloc=(destructor)main_destroy_py,
+ .tp_getattr=main_getattr_py,
+};
+
+PyObject *
+main_py(PyObject *self, PyObject *args)
+{
+ mainObject *ret;
+
+ dbg(0,"enter\n");
+ ret=PyObject_NEW(mainObject, &main_Type);
+ return (PyObject *)ret;
+}
+
diff --git a/binding/python/navigation.c b/binding/python/navigation.c
new file mode 100644
index 00000000..75a421d5
--- /dev/null
+++ b/binding/python/navigation.c
@@ -0,0 +1,82 @@
+/**
+ * Navit, a modular navigation system.
+ * Copyright (C) 2005-2008 Navit Team
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms 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 "common.h"
+#include "navigation.h"
+
+typedef struct {
+ PyObject_HEAD
+ struct navigation *navigation;
+} navigationObject;
+
+static PyObject *
+navigation_get_map_py(navigationObject *self, PyObject *args)
+{
+ if (!PyArg_ParseTuple(args, ""))
+ return NULL;
+ return map_py_ref(navigation_get_map(self->navigation));
+}
+
+
+
+static PyMethodDef navigation_methods[] = {
+ {"get_map", (PyCFunction) navigation_get_map_py, METH_VARARGS },
+ {NULL, NULL },
+};
+
+
+static PyObject *
+navigation_getattr_py(PyObject *self, char *name)
+{
+ return Py_FindMethod(navigation_methods, self, name);
+}
+
+static void
+navigation_destroy_py(navigationObject *self)
+{
+}
+
+PyTypeObject navigation_Type = {
+ Obj_HEAD
+ .tp_name="navigation",
+ .tp_basicsize=sizeof(navigationObject),
+ .tp_dealloc=(destructor)navigation_destroy_py,
+ .tp_getattr=navigation_getattr_py,
+};
+
+PyObject *
+navigation_py(PyObject *self, PyObject *args)
+{
+ navigationObject *ret;
+
+ ret=PyObject_NEW(navigationObject, &navigation_Type);
+ return (PyObject *)ret;
+}
+
+PyObject *
+navigation_py_ref(struct navigation *navigation)
+{
+ navigationObject *ret;
+
+ ret=PyObject_NEW(navigationObject, &navigation_Type);
+ ret->navigation=navigation;
+ return (PyObject *)ret;
+}
+
+
diff --git a/binding/python/navit.c b/binding/python/navit.c
new file mode 100644
index 00000000..ada8cd7f
--- /dev/null
+++ b/binding/python/navit.c
@@ -0,0 +1,135 @@
+/**
+ * Navit, a modular navigation system.
+ * Copyright (C) 2005-2008 Navit Team
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms 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 "common.h"
+#include "item.h"
+#include "navit.h"
+
+typedef struct {
+ PyObject_HEAD
+ struct navit *navit;
+} navitObject;
+
+static PyObject *
+navit_get_attr_py(navitObject *self, PyObject *args)
+{
+ char *name;
+ struct attr attr;
+ if (!PyArg_ParseTuple(args, "s", &name))
+ return NULL;
+ if (!navit_get_attr(self->navit, attr_from_name(name), &attr, NULL)) {
+ dbg(0,"get_attr not ok\n");
+ Py_RETURN_NONE;
+ }
+ dbg(0,"get_attr ok\n");
+ return python_object_from_attr(&attr);
+}
+
+static PyObject *
+navit_set_center_py(navitObject *self, PyObject *args)
+{
+ PyObject *pcoord;
+ if (!PyArg_ParseTuple(args, "O!", &pcoord_Type, &pcoord))
+ return NULL;
+ navit_set_center(self->navit, pcoord_py_get(pcoord), 0);
+ Py_RETURN_NONE;
+}
+
+static PyObject *
+navit_set_destination_py(navitObject *self, PyObject *args)
+{
+ PyObject *pcoord;
+ const char *description;
+ int async;
+ if (!PyArg_ParseTuple(args, "O!si", &pcoord_Type, &pcoord, &description, &async))
+ return NULL;
+ navit_set_destination(self->navit, pcoord_py_get(pcoord), description, async);
+ Py_RETURN_NONE;
+}
+
+static PyObject *
+navit_set_position_py(navitObject *self, PyObject *args)
+{
+ PyObject *pcoord;
+ if (!PyArg_ParseTuple(args, "O!", &pcoord_Type, &pcoord))
+ return NULL;
+ navit_set_position(self->navit, pcoord_py_get(pcoord));
+ Py_RETURN_NONE;
+}
+
+
+static PyObject *
+navit_zoom_to_route_py(navitObject *self, PyObject *args)
+{
+ if (!PyArg_ParseTuple(args, ""))
+ return NULL;
+ navit_zoom_to_route(self->navit,0);
+ Py_RETURN_NONE;
+}
+
+
+
+
+static PyMethodDef navit_methods[] = {
+ {"get_attr", (PyCFunction) navit_get_attr_py, METH_VARARGS },
+ {"set_center", (PyCFunction) navit_set_center_py, METH_VARARGS },
+ {"set_destination", (PyCFunction) navit_set_destination_py, METH_VARARGS },
+ {"set_position", (PyCFunction) navit_set_position_py, METH_VARARGS },
+ {"zoom_to_route", (PyCFunction) navit_zoom_to_route_py, METH_VARARGS },
+ {NULL, NULL },
+};
+
+
+static PyObject *
+navit_getattr_py(PyObject *self, char *name)
+{
+ return Py_FindMethod(navit_methods, self, name);
+}
+
+static void
+navit_destroy_py(navitObject *self)
+{
+}
+
+PyTypeObject navit_Type = {
+ Obj_HEAD
+ .tp_name="navit",
+ .tp_basicsize=sizeof(navitObject),
+ .tp_dealloc=(destructor)navit_destroy_py,
+ .tp_getattr=navit_getattr_py,
+};
+
+PyObject *
+navit_py(PyObject *self, PyObject *args)
+{
+ navitObject *ret;
+
+ dbg(0,"enter\n");
+ ret=PyObject_NEW(navitObject, &navit_Type);
+ return (PyObject *)ret;
+}
+
+PyObject *
+navit_py_ref(struct navit *navit)
+{
+ dbg(0,"navit=%p\n", navit);
+ navitObject *ret=PyObject_NEW(navitObject, &navit_Type);
+ ret->navit=navit;
+ return (PyObject *)ret;
+}
diff --git a/binding/python/navit.xml.python b/binding/python/navit.xml.python
new file mode 100644
index 00000000..ec3e99de
--- /dev/null
+++ b/binding/python/navit.xml.python
@@ -0,0 +1,7 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!DOCTYPE config SYSTEM "navit.dtd">
+<config xmlns:xi="http://www.w3.org/2001/XInclude">
+ <plugins>
+ <plugin path="$NAVIT_LIBDIR/*/${NAVIT_LIBPREFIX}libbinding_python.so" active="yes"/>
+ </plugins>
+</config>
diff --git a/binding/python/pcoord.c b/binding/python/pcoord.c
new file mode 100644
index 00000000..a4cb2640
--- /dev/null
+++ b/binding/python/pcoord.c
@@ -0,0 +1,88 @@
+/**
+ * Navit, a modular navigation system.
+ * Copyright (C) 2005-2008 Navit Team
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms 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 "common.h"
+#include "coord.h"
+
+typedef struct {
+ PyObject_HEAD
+ struct pcoord pc;
+} pcoordObject;
+
+static PyObject *
+pcoord_func(pcoordObject *self, PyObject *args)
+{
+ const char *file;
+ int ret=0;
+ if (!PyArg_ParseTuple(args, "s", &file))
+ return NULL;
+ return Py_BuildValue("i",ret);
+}
+
+
+
+static PyMethodDef pcoord_methods[] = {
+ {"func", (PyCFunction) pcoord_func, METH_VARARGS },
+ {NULL, NULL },
+};
+
+
+static PyObject *
+pcoord_getattr_py(PyObject *self, char *name)
+{
+ return Py_FindMethod(pcoord_methods, self, name);
+}
+
+static void
+pcoord_destroy_py(pcoordObject *self)
+{
+}
+
+PyTypeObject pcoord_Type = {
+ Obj_HEAD
+ .tp_name="pcoord",
+ .tp_basicsize=sizeof(pcoordObject),
+ .tp_dealloc=(destructor)pcoord_destroy_py,
+ .tp_getattr=pcoord_getattr_py,
+};
+
+PyObject *
+pcoord_py(PyObject *self, PyObject *args)
+{
+ pcoordObject *ret;
+ const char *str;
+ enum projection pro;
+ struct coord c;
+ if (!PyArg_ParseTuple(args, "si", &str, &pro))
+ return NULL;
+ ret=PyObject_NEW(pcoordObject, &pcoord_Type);
+ coord_parse(str, pro, &c);
+ ret->pc.pro=pro;
+ ret->pc.x=c.x;
+ ret->pc.y=c.y;
+ dbg(0,"0x%x,0x%x\n", c.x, c.y);
+ return (PyObject *)ret;
+}
+
+struct pcoord *
+pcoord_py_get(PyObject *self)
+{
+ return &((pcoordObject *)self)->pc;
+}
+
diff --git a/binding/python/route.c b/binding/python/route.c
new file mode 100644
index 00000000..dfbd08cf
--- /dev/null
+++ b/binding/python/route.c
@@ -0,0 +1,84 @@
+/**
+ * Navit, a modular navigation system.
+ * Copyright (C) 2005-2008 Navit Team
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms 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 "common.h"
+#include "item.h"
+#include "coord.h"
+#include "route.h"
+
+typedef struct {
+ PyObject_HEAD
+ struct route *route;
+} routeObject;
+
+static PyObject *
+route_get_map_py(routeObject *self, PyObject *args)
+{
+ if (!PyArg_ParseTuple(args, ""))
+ return NULL;
+ return map_py_ref(route_get_map(self->route));
+}
+
+
+
+static PyMethodDef route_methods[] = {
+ {"get_map", (PyCFunction) route_get_map_py, METH_VARARGS },
+ {NULL, NULL },
+};
+
+
+static PyObject *
+route_getattr_py(PyObject *self, char *name)
+{
+ return Py_FindMethod(route_methods, self, name);
+}
+
+static void
+route_destroy_py(routeObject *self)
+{
+}
+
+PyTypeObject route_Type = {
+ Obj_HEAD
+ .tp_name="route",
+ .tp_basicsize=sizeof(routeObject),
+ .tp_dealloc=(destructor)route_destroy_py,
+ .tp_getattr=route_getattr_py,
+};
+
+PyObject *
+route_py(PyObject *self, PyObject *args)
+{
+ routeObject *ret;
+
+ ret=PyObject_NEW(routeObject, &route_Type);
+ return (PyObject *)ret;
+}
+
+PyObject *
+route_py_ref(struct route *route)
+{
+ routeObject *ret;
+
+ ret=PyObject_NEW(routeObject, &route_Type);
+ ret->route=route;
+ return (PyObject *)ret;
+}
+
+
diff --git a/binding/python/startup.py b/binding/python/startup.py
new file mode 100644
index 00000000..02b20700
--- /dev/null
+++ b/binding/python/startup.py
@@ -0,0 +1,8 @@
+import navit
+navit.config_load("navit.xml.local")
+pos=navit.pcoord("5023.7493 N 00730.2898 E",1);
+dest=navit.pcoord("5023.6604 N 00729.8500 E",1);
+inst=navit.main().navit();
+inst.set_position(pos);
+inst.set_destination(dest,"Test");
+inst.set_center(pos);
diff --git a/binding/python/template.c b/binding/python/template.c
new file mode 100644
index 00000000..088cb5ee
--- /dev/null
+++ b/binding/python/template.c
@@ -0,0 +1,96 @@
+/**
+ * Navit, a modular navigation system.
+ * Copyright (C) 2005-2008 Navit Team
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms 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 "common.h"
+#include "template.h"
+
+typedef struct {
+ PyObject_HEAD
+ int ref;
+ struct template *template;
+} templateObject;
+
+static PyObject *
+template_func(templateObject *self, PyObject *args)
+{
+ const char *file;
+ int ret;
+ if (!PyArg_ParseTuple(args, "s", &file))
+ return NULL;
+ ret=0;
+ return Py_BuildValue("i",ret);
+}
+
+
+
+static PyMethodDef template_methods[] = {
+ {"func", (PyCFunction) template_func, METH_VARARGS },
+ {NULL, NULL },
+};
+
+
+static PyObject *
+template_getattr_py(PyObject *self, char *name)
+{
+ return Py_FindMethod(template_methods, self, name);
+}
+
+static void
+template_destroy_py(templateObject *self)
+{
+ if (! self->ref)
+ template_destroy(self->template);
+}
+
+PyTypeObject template_Type = {
+ Obj_HEAD
+ .tp_name="template",
+ .tp_basicsize=sizeof(templateObject),
+ .tp_dealloc=(destructor)template_destroy_py,
+ .tp_getattr=template_getattr_py,
+};
+
+struct template *
+template_py_get(PyObject *self)
+{
+ return ((templateObject *)self)->template;
+}
+
+PyObject *
+template_new_py(PyObject *self, PyObject *args)
+{
+ templateObject *ret;
+
+ ret=PyObject_NEW(templateObject, &template_Type);
+ ret->template=template_new();
+ ret->ref=0;
+ return (PyObject *)ret;
+}
+
+PyObject *
+template_new_py_ref(struct template *template)
+{
+ templateObject *ret;
+
+ ret=PyObject_NEW(templateObject, &template_Type);
+ ret->ref=1;
+ ret->template=template;
+ return (PyObject *)ret;
+}
+