summaryrefslogtreecommitdiff
path: root/navit/binding/win32/binding_win32.c
blob: c6d3295ccba141fdd41f25901f1286f7eb9bd542 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
/**
 * 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 "xmlconfig.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(lvl_error,"this function is a stub\n");
	if (in) {
		while (*in) {
			dbg(lvl_debug,"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(lvl_error,"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(lvl_error,"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(lvl_error,"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(lvl_error,"Got request with wrong MAGIC, expected %s, got %*s.\n",NAVIT_BINDING_W32_MAGIC, msg->magic,sizeof(msg->magic));
        	return;
        }
	dbg(lvl_debug,"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(lvl_debug,"enter\n");
	if (added==1) {
		dbg(lvl_debug,"enter2\n");
		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);
	dbg(lvl_debug,"enter\n");
	callback.type=attr_callback;
	callback.u.callback=callback_new_attr_1(callback_cast(win32_main_navit),attr_navit,this);
	config_add_attr(config, &callback);
}