]> err.no Git - mapper/blob - src/gps-bluetooth-bluez-dbus.c
Some fixes
[mapper] / src / gps-bluetooth-bluez-dbus.c
1 /*
2  * This file is part of mapper
3  *
4  * Copyright (C) 2007 Kaj-Michael Lang
5  * Copyright (C) 2006-2007 John Costigan.
6  *
7  * POI and GPS-Info code originally written by Cezary Jackiewicz.
8  *
9  * Default map data provided by http://www.openstreetmap.org/
10  *
11  * This program is free software; you can redistribute it and/or modify
12  * it under the terms of the GNU General Public License as published by
13  * the Free Software Foundation; either version 2 of the License, or
14  * (at your option) any later version.
15  *
16  * This program is distributed in the hope that it will be useful,
17  * but WITHOUT ANY WARRANTY; without even the implied warranty of
18  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
19  * GNU General Public License for more details.
20  *
21  * You should have received a copy of the GNU General Public License along
22  * with this program; if not, write to the Free Software Foundation, Inc.,
23  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
24  */
25
26 #include <config.h>
27
28 #include <fcntl.h>
29
30 #include "mapper.h"
31 #include "gps-bluetooth-bluez-marshal.h"
32 #include "gps.h"
33 #include "settings.h"
34 #include "ui-common.h"
35 #include "gps-conn.h"
36
37 /**
38  * Bluetooth device scanning functions below
39  */
40 static void
41 scan_cb_dev_found(DBusGProxy *object, const char *address, const unsigned int class, const int rssi, ScanInfo *scan_info)
42 {
43 GtkTreeIter iter;
44 gtk_list_store_append(scan_info->store, &iter);
45 gtk_list_store_set(scan_info->store, &iter, 0, g_strdup(address), 1, g_strdup(name), -1);
46 }
47
48 static void 
49 scan_cb_search_complete(DBusGProxy * sig_proxy, ScanInfo * scan_info)
50 {
51 gtk_widget_destroy(scan_info->banner);
52 dbus_g_proxy_disconnect_signal(sig_proxy, BTSEARCH_DEV_FOUND_SIG, G_CALLBACK(scan_cb_dev_found), scan_info);
53 dbus_g_proxy_disconnect_signal(sig_proxy, BTSEARCH_SEARCH_COMPLETE_SIG, G_CALLBACK(scan_cb_search_complete), scan_info);
54 }
55
56 gint 
57 scan_start_search(ScanInfo * scan_info)
58 {
59 GError *error = NULL;
60
61 if (NULL == (scan_info->req_proxy = dbus_g_proxy_new_for_name(bus, "org.bluez", "/org/bluez/hci0", "org.bluez.Adapter"))) {
62         g_printerr("Failed to create D-Bus request proxy for btsearch.");
63         return 2;
64 }
65
66 dbus_g_object_register_marshaller(marshal_VOID__STRING_UINT_INT, G_TYPE_NONE, G_TYPE_STRING, G_TYPE_UINT, G_TYPE_INT, G_TYPE_INVALID);
67
68 dbus_g_proxy_add_signal(scan_info->req_proxy, "RemoteDeviceFound", G_TYPE_STRING, G_TYPE_UINT, G_TYPE_INT, G_TYPE_INVALID);
69 dbus_g_proxy_connect_signal(scan_info->req_proxy, "RemoteDeviceFound", G_CALLBACK(scan_cb_dev_found), bus, NULL);
70
71 dbus_g_proxy_add_signal(scan_info->req_proxy, "DiscoveryCompleted", G_TYPE_INVALID);
72 dbus_g_proxy_connect_signal(scan_info->req_proxy, "DiscoveryCompleted", G_CALLBACK(scan_cb_search_complete), bus, NULL);
73
74 #if 0
75 dbus_g_object_register_marshaller(marshal_VOID__STRING_STRING, G_TYPE_NONE, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_INVALID);
76 dbus_g_proxy_add_signal(scan_info->req_proxy, "RemoteNameUpdated", G_TYPE_STRING, G_TYPE_STRING, G_TYPE_INVALID);
77 dbus_g_proxy_connect_signal(scan_info->req_proxy, "RemoteNameUpdated", G_CALLBACK(scan_cb_dev_found), NULL, NULL);
78 #endif
79
80 error = NULL;
81 if (!dbus_g_proxy_call(obj, "DiscoverDevices", &error, G_TYPE_INVALID, G_TYPE_INVALID)) {
82         if (error->domain == DBUS_GERROR && error->code == DBUS_GERROR_REMOTE_EXCEPTION) {
83                 g_printerr("Caught remote method exception %s: %s", dbus_g_error_get_name(error), error->message);
84         } else {
85                 g_printerr("Error: %s\n", error->message);
86         }
87         return 3;
88 }
89
90 return 0;
91 }
92