2 * This file is part of mapper
4 * Copyright (C) 2007 Kaj-Michael Lang
5 * Copyright (C) 2006-2007 John Costigan.
7 * POI and GPS-Info code originally written by Cezary Jackiewicz.
9 * Default map data provided by http://www.openstreetmap.org/
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.
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.
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.
29 #include <dbus/dbus.h>
30 #include <dbus/dbus-glib.h>
31 #include <glib-object.h>
34 #include "bluetooth-scan.h"
35 #include "gps-bluetooth-bluez-marshal.h"
38 #include "ui-common.h"
42 * Bluetooth device scanning functions below
45 scan_cb_dev_found(DBusGProxy *object, const char *address, const unsigned int class, const int rssi, ScanInfo *scan_info)
49 gtk_list_store_append(scan_info->store, &iter);
50 gtk_list_store_set(scan_info->store, &iter, 0, g_strdup(address), -1);
54 scan_cb_dev_name_found(DBusGProxy *object, const char *address, const char *name, ScanInfo *scan_info)
59 c=gtk_tree_model_get_iter_first(scan_info->store, &iter);
63 gtk_tree_model_get(GTK_TREE_MODEL(scan_info->store), &iter, 0, &value, -1);
64 if (g_ascii_strcasecmp(address, value) == 0) {
65 gtk_list_store_set(scan_info->store, &iter, 1, g_strdup(name), -1);
68 c=gtk_tree_model_iter_next(GTK_TREE_MODEL(scan_info->store), &iter);
74 scan_cb_search_complete(DBusGProxy *object, ScanInfo *scan_info)
76 gtk_widget_destroy(scan_info->banner);
77 dbus_g_proxy_disconnect_signal(object, "RemoteDeviceFound", G_CALLBACK(scan_cb_dev_found), scan_info);
78 dbus_g_proxy_disconnect_signal(object, "DiscoveryCompleted", G_CALLBACK(scan_cb_search_complete), scan_info);
79 dbus_g_proxy_disconnect_signal(object, "RemoteNameUpdated", G_CALLBACK(scan_cb_dev_name_found), scan_info);
83 scan_start_search(ScanInfo *scan_info)
87 if (NULL == (scan_info->req_proxy = dbus_g_proxy_new_for_name(dbus_conn, "org.bluez", "/org/bluez/hci0", "org.bluez.Adapter"))) {
88 g_printerr("Failed to create D-Bus request proxy for btsearch.");
92 dbus_g_object_register_marshaller(_bt_bluez_VOID__STRING_UINT_INT, G_TYPE_NONE, G_TYPE_STRING, G_TYPE_UINT, G_TYPE_INT, G_TYPE_INVALID);
93 dbus_g_proxy_add_signal(scan_info->req_proxy, "RemoteDeviceFound", G_TYPE_STRING, G_TYPE_UINT, G_TYPE_INT, G_TYPE_INVALID);
94 dbus_g_proxy_connect_signal(scan_info->req_proxy, "RemoteDeviceFound", G_CALLBACK(scan_cb_dev_found), scan_info, NULL);
96 dbus_g_proxy_add_signal(scan_info->req_proxy, "DiscoveryCompleted", G_TYPE_INVALID);
97 dbus_g_proxy_connect_signal(scan_info->req_proxy, "DiscoveryCompleted", G_CALLBACK(scan_cb_search_complete), scan_info, NULL);
99 dbus_g_object_register_marshaller(_bt_bluez_VOID__STRING_STRING, G_TYPE_NONE, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_INVALID);
100 dbus_g_proxy_add_signal(scan_info->req_proxy, "RemoteNameUpdated", G_TYPE_STRING, G_TYPE_STRING, G_TYPE_INVALID);
101 dbus_g_proxy_connect_signal(scan_info->req_proxy, "RemoteNameUpdated", G_CALLBACK(scan_cb_dev_name_found), scan_info, NULL);
104 if (!dbus_g_proxy_call(scan_info->req_proxy, "DiscoverDevices", &error, G_TYPE_INVALID, G_TYPE_INVALID)) {
105 if (error->domain == DBUS_GERROR && error->code == DBUS_GERROR_REMOTE_EXCEPTION) {
106 g_printerr("Caught remote method exception %s: %s", dbus_g_error_get_name(error), error->message);
108 g_printerr("Error: %s\n", error->message);