]> err.no Git - mapper/blob - src/gps-bluetooth-maemo.c
GpsBluez: cleanups
[mapper] / src / gps-bluetooth-maemo.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 /* Let this header handle all ifdefs */
31 #include "hildon-mapper.h"
32
33 #include "mapper.h"
34 #include "gps-bluetooth-maemo-marshal.h"
35 #include "gps.h"
36 #include "settings.h"
37 #include "ui-common.h"
38 #include "gps-conn.h"
39 #include "bluetooth-scan.h"
40
41 /**
42  * Bluetooth device scanning functions below
43  */
44 static void
45 scan_cb_dev_found(DBusGProxy *sig_proxy, const gchar *bda, const gchar *name, gpointer *class, guchar rssi, gint coff, ScanInfo *scan_info)
46 {
47 GtkTreeIter iter;
48 gtk_list_store_append(scan_info->store, &iter);
49 gtk_list_store_set(scan_info->store, &iter, 0, g_strdup(bda), 1, g_strdup(name), -1);
50 }
51
52 static void 
53 scan_cb_search_complete(DBusGProxy * sig_proxy, ScanInfo * scan_info)
54 {
55 gtk_widget_destroy(scan_info->banner);
56 dbus_g_proxy_disconnect_signal(sig_proxy, BTSEARCH_DEV_FOUND_SIG, G_CALLBACK(scan_cb_dev_found), scan_info);
57 dbus_g_proxy_disconnect_signal(sig_proxy, BTSEARCH_SEARCH_COMPLETE_SIG, G_CALLBACK(scan_cb_search_complete), scan_info);
58 }
59
60 /**
61  * Request bluetooth device scan
62  */
63 gint 
64 scan_start_search(ScanInfo * scan_info)
65 {
66 GError *error = NULL;
67
68 if (NULL == (scan_info->req_proxy = dbus_g_proxy_new_for_name(dbus_conn, BTSEARCH_SERVICE, BTSEARCH_REQ_PATH, BTSEARCH_REQ_INTERFACE))) {
69         g_printerr("Failed to create D-Bus request proxy for btsearch.");
70         return 2;
71 }
72
73 if (NULL == (scan_info->sig_proxy = dbus_g_proxy_new_for_name(dbus_conn, BTSEARCH_SERVICE, BTSEARCH_SIG_PATH, BTSEARCH_SIG_INTERFACE))) {
74         g_printerr("Failed to create D-Bus signal proxy for btsearch.");
75         return 2;
76 }
77
78 dbus_g_object_register_marshaller(_bt_maemo_VOID__STRING_STRING_POINTER_UCHAR_UINT, G_TYPE_NONE, G_TYPE_STRING, G_TYPE_STRING, DBUS_TYPE_G_UCHAR_ARRAY, G_TYPE_UCHAR, G_TYPE_UINT, G_TYPE_INVALID);
79
80 dbus_g_proxy_add_signal(scan_info->sig_proxy, BTSEARCH_DEV_FOUND_SIG, G_TYPE_STRING, G_TYPE_STRING, DBUS_TYPE_G_UCHAR_ARRAY, G_TYPE_UCHAR, G_TYPE_UINT, G_TYPE_INVALID);
81 dbus_g_proxy_connect_signal(scan_info->sig_proxy, BTSEARCH_DEV_FOUND_SIG, G_CALLBACK(scan_cb_dev_found), scan_info, NULL);
82
83 dbus_g_proxy_add_signal(scan_info->sig_proxy, BTSEARCH_SEARCH_COMPLETE_SIG, G_TYPE_INVALID);
84 dbus_g_proxy_connect_signal(scan_info->sig_proxy, BTSEARCH_SEARCH_COMPLETE_SIG, G_CALLBACK(scan_cb_search_complete), scan_info, NULL);
85
86 error = NULL;
87 if (!dbus_g_proxy_call(scan_info->req_proxy, BTSEARCH_START_SEARCH_REQ, &error, G_TYPE_INVALID, G_TYPE_INVALID)) {
88         if (error->domain == DBUS_GERROR && error->code == DBUS_GERROR_REMOTE_EXCEPTION) {
89                 g_printerr("Caught remote method exception %s: %s", dbus_g_error_get_name(error), error->message);
90         } else {
91                 g_printerr("Error: %s\n", error->message);
92         }
93         return 3;
94 }
95
96 return 0;
97 }
98