summaryrefslogtreecommitdiff
path: root/navit/binding
diff options
context:
space:
mode:
authormdankov <mdankov@ffa7fe5e-494d-0410-b361-a75ebd5db220>2012-01-18 21:11:59 +0000
committermdankov <mdankov@ffa7fe5e-494d-0410-b361-a75ebd5db220>2012-01-18 21:11:59 +0000
commit63379267f4acd7ca2597203eba1775bf604ecc94 (patch)
tree759e80ec3a8bf194b72de75919d2aba003818e94 /navit/binding
parent7504bbb0d9cf861e6ae17957ea71fa1f8a66e85c (diff)
downloadnavit-svn-63379267f4acd7ca2597203eba1775bf604ecc94.tar.gz
Add:core:New binding_win32 module for Windows and WinCE. Some details are at ticket #970.
git-svn-id: http://svn.code.sf.net/p/navit/code/trunk/navit@4892 ffa7fe5e-494d-0410-b361-a75ebd5db220
Diffstat (limited to 'navit/binding')
-rw-r--r--navit/binding/Makefile.am7
-rw-r--r--navit/binding/win32/CMakeLists.txt9
-rw-r--r--navit/binding/win32/Makefile.am12
-rw-r--r--navit/binding/win32/binding_win32.c143
-rw-r--r--navit/binding/win32/binding_win32.h37
-rw-r--r--navit/binding/win32/tell_navit.c176
6 files changed, 383 insertions, 1 deletions
diff --git a/navit/binding/Makefile.am b/navit/binding/Makefile.am
index 48e0a8d6..6b782b48 100644
--- a/navit/binding/Makefile.am
+++ b/navit/binding/Makefile.am
@@ -6,5 +6,10 @@ if BINDING_DBUS
SUBDIRS+=dbus
endif
-DIST_SUBDIRS=python dbus
+if BINDING_WIN32
+ SUBDIRS+=win32
+endif
+
+
+DIST_SUBDIRS=python dbus win32
diff --git a/navit/binding/win32/CMakeLists.txt b/navit/binding/win32/CMakeLists.txt
new file mode 100644
index 00000000..792a8ff4
--- /dev/null
+++ b/navit/binding/win32/CMakeLists.txt
@@ -0,0 +1,9 @@
+if (USE_LIBGNUINTL AND NOT HAVE_GLIB)
+ ADD_DEPENDENCIES(support_glib intl_cmake)
+endif()
+
+module_add_library(binding_win32 binding_win32.c)
+
+add_executable(tell_navit tell_navit.c)
+target_link_libraries(tell_navit ${MODULES_NAME} ${NAVIT_SUPPORT_LIBS} fib ${NAVIT_LIBS} )
+install(TARGETS tell_navit DESTINATION ${BIN_DIR} PERMISSIONS OWNER_READ OWNER_WRITE OWNER_EXECUTE GROUP_READ GROUP_EXECUTE WORLD_READ WORLD_EXECUTE)
diff --git a/navit/binding/win32/Makefile.am b/navit/binding/win32/Makefile.am
new file mode 100644
index 00000000..23ec1dea
--- /dev/null
+++ b/navit/binding/win32/Makefile.am
@@ -0,0 +1,12 @@
+include $(top_srcdir)/Makefile.inc
+AM_CPPFLAGS = -I$(top_srcdir)/navit -I$(top_srcdir)/navit/binding/win32 @NAVIT_CFLAGS@ -DMODULE=binding_win32
+if PLUGINS
+modulebinding_LTLIBRARIES = libbinding_win32.la
+else
+noinst_LTLIBRARIES = libbinding_win32.la
+endif
+libbinding_win32_la_SOURCES = binding_win32.c binding_win32.h
+libbinding_win32_la_LIBADD =
+libbinding_win32_la_LDFLAGS = -module -avoid-version
+bin_PROGRAMS=tell_navit
+tell_navit_LDADD = @NAVIT_LIBS@
diff --git a/navit/binding/win32/binding_win32.c b/navit/binding/win32/binding_win32.c
new file mode 100644
index 00000000..ed6c19db
--- /dev/null
+++ b/navit/binding/win32/binding_win32.c
@@ -0,0 +1,143 @@
+/**
+ * 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>
+#include <glib.h>
+#include <windows.h>
+#include "config.h"
+#include "config_.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 "navigation.h"
+#include "command.h"
+#include "callback.h"
+#include "graphics.h"
+#include "track.h"
+#include "vehicle.h"
+#include "vehicleprofile.h"
+#include "map.h"
+#include "mapset.h"
+#include "osd.h"
+#include "route.h"
+#include "search.h"
+#include "callback.h"
+#include "gui.h"
+#include "util.h"
+#include "binding_win32.h"
+
+struct win32_binding_private {
+ struct navit* navit;
+};
+
+
+
+/* TODO: do something meaningful here
+ *
+ */
+static int
+win32_cmd_send_signal(struct navit *navit, char *command, struct attr **in, struct attr ***out)
+{
+ dbg(0,"this function is a stub\n");
+ if (in) {
+ while (*in) {
+ dbg(0,"another attribute to be sent\n");
+ in++;
+ }
+ }
+ return 0;
+}
+
+
+static struct command_table commands[] = {
+ {"win32_send",command_cast(win32_cmd_send_signal)},
+};
+
+
+static void
+win32_wm_copydata(struct win32_binding_private *this, int *hwndSender, COPYDATASTRUCT *cpd)
+{
+ struct attr navit;
+ struct navit_binding_w32_msg *msg;
+ navit.type=attr_navit;
+ navit.u.navit=this->navit;
+ if(cpd->dwData!=NAVIT_BINDING_W32_DWDATA) {
+ dbg(0,"COPYDATA message came with wrong DWDATA value, expected %d, got %d.\n",NAVIT_BINDING_W32_DWDATA,cpd->dwData);
+ return;
+ }
+ if(cpd->cbData<sizeof(*msg)) {
+ dbg(0,"COPYDATA message too short, expected >=%d, got %d.\n",sizeof(*msg),cpd->cbData);
+ return;
+ }
+ msg=cpd->lpData;
+ if(cpd->dwData!=NAVIT_BINDING_W32_VERSION) {
+ dbg(0,"Got request with wrong version number, expected %d, got %d.\n",NAVIT_BINDING_W32_VERSION,msg->version);
+ return;
+ }
+ if(strcmp(NAVIT_BINDING_W32_MAGIC,msg->magic)) {
+ dbg(0,"Got request with wrong MAGIC, expected %s, got %*s.\n",NAVIT_BINDING_W32_MAGIC, msg->magic,sizeof(msg->magic));
+ return;
+ }
+ dbg(0,"Running command %s\n", msg->text);
+ command_evaluate(&navit, msg->text);
+}
+
+static void
+win32_cb_graphics_ready(struct win32_binding_private *this, struct navit *navit)
+{
+ struct graphics *gra;
+ struct callback *gcb;
+
+ gcb=callback_new_attr_1(callback_cast(win32_wm_copydata),attr_wm_copydata, this);
+ gra=navit_get_graphics(navit);
+ dbg_assert(gra);
+ graphics_add_callback(gra, gcb);
+}
+
+static void
+win32_main_navit(struct win32_binding_private *this, struct navit *navit, int added)
+{
+ struct attr attr;
+ dbg(0,"enter");
+ if (added==1) {
+ dbg(0,"enter2");
+ this->navit=navit;
+ command_add_table_attr(commands, sizeof(commands)/sizeof(struct command_table), navit, &attr);
+ navit_add_attr(navit, &attr);
+ navit_add_callback(navit,callback_new_attr_1(callback_cast(win32_cb_graphics_ready),attr_graphics_ready, this));
+ }
+
+}
+
+
+
+void plugin_init(void)
+{
+ struct attr callback;
+ struct win32_binding_private *this=g_new0(struct win32_binding_private,1);
+ callback.type=attr_callback;
+ callback.u.callback=callback_new_attr_1(callback_cast(win32_main_navit),attr_navit,this);
+ config_add_attr(config, &callback);
+}
+
diff --git a/navit/binding/win32/binding_win32.h b/navit/binding/win32/binding_win32.h
new file mode 100644
index 00000000..79fe1eb1
--- /dev/null
+++ b/navit/binding/win32/binding_win32.h
@@ -0,0 +1,37 @@
+/**
+ * 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.
+ */
+
+#ifndef BINDING_WIN32_H
+#define BINDING_WIN32_H
+
+#define NAVIT_BINDING_W32_DWDATA 1
+#define NAVIT_BINDING_W32_MAGIC "NavIt"
+#define NAVIT_BINDING_W32_VERSION 1
+
+struct navit_binding_w32_msg {
+ /* Structure version number, should be equal to NAVIT_BINDING_W32_VERSION */
+ int version;
+ /* Magic code to filter out packets directed to other applications and [mistakely] sent to us or broadcasted.
+ * should be equal to NAVIT_BINDING_W32_MAGIC */
+ char magic[6];
+ /* Command to be executed by Navit */
+ char text[1];
+};
+
+#endif
diff --git a/navit/binding/win32/tell_navit.c b/navit/binding/win32/tell_navit.c
new file mode 100644
index 00000000..86f407e0
--- /dev/null
+++ b/navit/binding/win32/tell_navit.c
@@ -0,0 +1,176 @@
+/**
+ * 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 <windows.h>
+#include <stdio.h>
+#include <stdarg.h>
+#ifdef HAVE_GETOPT_H
+#include <getopt.h>
+#else
+#include <XGetopt.h>
+#endif
+#include <glib.h>
+#include "binding_win32.h"
+
+static LRESULT CALLBACK message_handler( HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam )
+{
+ switch(uMsg) {
+ case WM_CREATE:
+ return 0;
+ }
+ return TRUE;
+}
+
+int errormode=1;
+
+void err(char *fmt, ...)
+{
+ va_list ap;
+ char buf[1024];
+ va_start(ap, fmt);
+ vsnprintf(buf, sizeof(buf), fmt, ap);
+ va_end(ap);
+ switch(errormode) {
+ case 0: /* be silent */
+ break;
+ case 1:
+ MessageBox(NULL, buf, "tell_navit", MB_ICONERROR|MB_OK);
+ break;
+ case 2:
+ fprintf(stderr,"%s",buf);
+ break;
+ }
+}
+
+void print_usage(void)
+{
+ err(
+ "tell_navit usage:\n"
+ "tell_navit [options] navit_command\n"
+ "\t-h this help\n"
+ "\t-e <way>: set way to report error messages:\n"
+ "\t\t0 - suppress messages\n"
+ "\t\t1 - use messagebox (default)\n"
+ "\t\t2 - print to stderr\n"
+ );
+}
+
+int main(int argc, char **argv)
+{
+ HWND navitWindow;
+ COPYDATASTRUCT cd;
+ char opt;
+
+ TCHAR *g_szClassName = TEXT("TellNavitWND");
+ WNDCLASS wc;
+ HWND hwnd;
+ HWND hWndParent=NULL;
+
+
+ if(argc>0) {
+ while((opt = getopt(argc, argv, ":hvc:d:e:s:")) != -1) {
+ switch(opt){
+ case 'h':
+ print_usage();
+ exit(0);
+ break;
+ case 'e':
+ errormode=atoi(optarg);
+ break;
+ default:
+ err("Unknown option %c\n", opt);
+ exit(1);
+ break;
+ }
+ }
+ } else {
+ print_usage();
+ exit(1);
+ }
+ if(optind==argc) {
+ err("Navit command to execute is needed.");
+ exit(1);
+ }
+
+
+ memset(&wc, 0 , sizeof(WNDCLASS));
+ wc.lpfnWndProc = message_handler;
+ wc.hInstance = GetModuleHandle(NULL);
+ wc.lpszClassName = g_szClassName;
+
+ if (!RegisterClass(&wc))
+ {
+ err(TEXT("Window class registration failed\n"));
+ return 1;
+ } else {
+ hwnd = CreateWindow(
+ g_szClassName,
+ TEXT("Tell Navit"),
+ 0,
+ 0,
+ 0,
+ 0,
+ 0,
+ hWndParent,
+ NULL,
+ GetModuleHandle(NULL),
+ NULL);
+ if(!hwnd) {
+ err(TEXT("Can't create hidden window\n"));
+ UnregisterClass(g_szClassName,NULL);
+ return 1;
+ }
+ }
+
+ navitWindow=FindWindow( TEXT("NAVGRA"), NULL );
+ if(!navitWindow) {
+ err(TEXT("Navit window not found\n"));
+ DestroyWindow(hwnd);
+ UnregisterClass(g_szClassName,NULL);
+ return 1;
+ } else {
+ int rv;
+ char *command=g_strjoinv(" ",argv+optind);
+ struct navit_binding_w32_msg *msg;
+ int sz=sizeof(*msg)+strlen(command);
+
+ cd.dwData=NAVIT_BINDING_W32_DWDATA;
+ msg=g_malloc0(sz);
+ msg->version=NAVIT_BINDING_W32_VERSION;
+ g_strlcpy(msg->magic,NAVIT_BINDING_W32_MAGIC,sizeof(msg->magic));
+ g_strlcpy(msg->text,command,sz-sizeof(*msg)+1);
+ cd.cbData=sz;
+ cd.lpData=msg;
+ rv=SendMessage( navitWindow, WM_COPYDATA, (WPARAM)hwnd, (LPARAM) (LPVOID) &cd );
+ g_free(command);
+ g_free(msg);
+ if(rv!=0) {
+ err(TEXT("Error %d sending message, SendMessage return value is %d\n"), GetLastError(), rv);
+ DestroyWindow(hwnd);
+ UnregisterClass(g_szClassName,NULL);
+ return 1;
+ }
+ }
+ DestroyWindow(hwnd);
+ UnregisterClass(g_szClassName,NULL);
+ return 0;
+}
+
+