Contents of /trunk/src/dbus.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 2 - (show annotations)
Wed Dec 10 00:00:05 2008 UTC (15 years, 5 months ago) by achadwick
File MIME type: text/plain
File size: 3516 byte(s)
Begin trunk. No code changes.
1 /*
2 * Copyright (C) 2008 Till Harbaum <till@harbaum.org>.
3 *
4 * This file is part of OSM2Go.
5 *
6 * OSM2Go is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation, either version 3 of the License, or
9 * (at your option) any later version.
10 *
11 * OSM2Go is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with OSM2Go. If not, see <http://www.gnu.org/licenses/>.
18 */
19
20 #include <libosso.h>
21 #include <dbus/dbus-glib-lowlevel.h>
22
23 #include "appdata.h"
24
25 #define MM_DBUS_SERVICE "com.gnuite.maemo_mapper"
26 #define MM_DBUS_PATH "/com/gnuite/maemo_mapper"
27 #define MM_DBUS_INTERFACE "com.gnuite.maemo_mapper"
28
29 #include <glib.h>
30 #include <dbus/dbus-glib.h>
31
32 static DBusHandlerResult signal_filter
33 (DBusConnection *connection, DBusMessage *message, void *user_data);
34
35 static DBusHandlerResult
36 signal_filter(DBusConnection *connection, DBusMessage *message, void *user_data) {
37 /* User data is the event loop we are running in */
38 appdata_t *appdata = (appdata_t*)user_data;
39
40 if(dbus_message_is_signal(message, MM_DBUS_SERVICE, "view_position_changed")) {
41 DBusError error;
42 double lat, lon;
43 long zoom;
44 dbus_error_init(&error);
45
46 if(dbus_message_get_args(message, &error,
47 DBUS_TYPE_DOUBLE, &lat,
48 DBUS_TYPE_DOUBLE, &lon,
49 DBUS_TYPE_INT32, &zoom,
50 DBUS_TYPE_INVALID)) {
51
52 g_print("MM: position received: %f/%f, zoom = %ld\n",
53 (float)lat, (float)lon, zoom);
54
55 /* store position for further processing */
56 appdata->mmpos.pos.lat = lat;
57 appdata->mmpos.pos.lon = lon;
58 appdata->mmpos.zoom = zoom;
59 appdata->mmpos.valid = TRUE;
60
61 } else {
62 g_print(" Error getting message: %s\n", error.message);
63 dbus_error_free (&error);
64 }
65 return DBUS_HANDLER_RESULT_HANDLED;
66 }
67
68 return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
69 }
70
71 /* if pos==NULL only the screen is refreshed, useful if e.g. */
72 /* the poi database changed */
73 gboolean dbus_mm_set_position(osso_context_t *osso_context, pos_t *pos) {
74 osso_rpc_t retval;
75 osso_return_t ret;
76
77 if(pos)
78 ret = osso_rpc_run(osso_context,
79 MM_DBUS_SERVICE,
80 MM_DBUS_PATH,
81 MM_DBUS_INTERFACE,
82 "set_view_center",
83 &retval,
84 DBUS_TYPE_DOUBLE, (double)pos->lat,
85 DBUS_TYPE_DOUBLE, (double)pos->lon,
86 DBUS_TYPE_INVALID);
87 else
88 ret = osso_rpc_run(osso_context,
89 MM_DBUS_SERVICE,
90 MM_DBUS_PATH,
91 MM_DBUS_INTERFACE,
92 "set_view_center",
93 &retval,
94 DBUS_TYPE_INVALID);
95
96 osso_rpc_free_val(&retval);
97
98 return(ret == OSSO_OK);
99 }
100
101 void dbus_register(appdata_t *appdata) {
102 DBusConnection *bus;
103 DBusError error;
104
105 dbus_error_init (&error);
106 bus = dbus_bus_get(DBUS_BUS_SESSION, &error);
107 if(!bus) {
108 g_warning("Failed to connect to the D-BUS daemon: %s", error.message);
109 dbus_error_free(&error);
110 return;
111 }
112 dbus_connection_setup_with_g_main(bus, NULL);
113
114 /* listening to messages from all objects as no path is specified */
115 dbus_bus_add_match(bus, "type='signal',interface='"MM_DBUS_INTERFACE"'", &error);
116 dbus_connection_add_filter(bus, signal_filter, appdata, NULL);
117 }