]> err.no Git - mapper/commitdiff
Start to convert to hildon btconn to the new gps interface.
authorKaj-Michael Lang <milang@tal.org>
Tue, 22 Jan 2008 23:11:39 +0000 (01:11 +0200)
committerKaj-Michael Lang <milang@tal.org>
Tue, 22 Jan 2008 23:11:39 +0000 (01:11 +0200)
Start to add support for using bluez D-Bus API to scan for devices.

src/gps-bluetooth-bluez-dbus.c [new file with mode: 0644]
src/gps-bluetooth-hildon.c
src/gps.c

diff --git a/src/gps-bluetooth-bluez-dbus.c b/src/gps-bluetooth-bluez-dbus.c
new file mode 100644 (file)
index 0000000..5b8f414
--- /dev/null
@@ -0,0 +1,92 @@
+/*
+ * This file is part of mapper
+ *
+ * Copyright (C) 2007 Kaj-Michael Lang
+ * Copyright (C) 2006-2007 John Costigan.
+ *
+ * POI and GPS-Info code originally written by Cezary Jackiewicz.
+ *
+ * Default map data provided by http://www.openstreetmap.org/
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * 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 <config.h>
+
+#include <fcntl.h>
+
+#include "mapper.h"
+#include "gps-bluetooth-bluez-marshal.h"
+#include "gps.h"
+#include "settings.h"
+#include "ui-common.h"
+#include "gps-conn.h"
+
+/**
+ * Bluetooth device scanning functions below
+ */
+static void
+scan_cb_dev_found(DBusGProxy *object, const char *address, const unsigned int class, const int rssi, ScanInfo *scan_info)
+{
+GtkTreeIter iter;
+gtk_list_store_append(scan_info->store, &iter);
+gtk_list_store_set(scan_info->store, &iter, 0, g_strdup(address), 1, g_strdup(name), -1);
+}
+
+static void 
+scan_cb_search_complete(DBusGProxy * sig_proxy, ScanInfo * scan_info)
+{
+gtk_widget_destroy(scan_info->banner);
+dbus_g_proxy_disconnect_signal(sig_proxy, BTSEARCH_DEV_FOUND_SIG, G_CALLBACK(scan_cb_dev_found), scan_info);
+dbus_g_proxy_disconnect_signal(sig_proxy, BTSEARCH_SEARCH_COMPLETE_SIG, G_CALLBACK(scan_cb_search_complete), scan_info);
+}
+
+gint 
+scan_start_search(ScanInfo * scan_info)
+{
+GError *error = NULL;
+
+if (NULL == (scan_info->req_proxy = dbus_g_proxy_new_for_name(bus, "org.bluez", "/org/bluez/hci0", "org.bluez.Adapter"))) {
+       g_printerr("Failed to create D-Bus request proxy for btsearch.");
+       return 2;
+}
+
+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);
+
+dbus_g_proxy_add_signal(scan_info->req_proxy, "RemoteDeviceFound", G_TYPE_STRING, G_TYPE_UINT, G_TYPE_INT, G_TYPE_INVALID);
+dbus_g_proxy_connect_signal(scan_info->req_proxy, "RemoteDeviceFound", G_CALLBACK(scan_cb_dev_found), bus, NULL);
+
+dbus_g_proxy_add_signal(scan_info->req_proxy, "DiscoveryCompleted", G_TYPE_INVALID);
+dbus_g_proxy_connect_signal(scan_info->req_proxy, "DiscoveryCompleted", G_CALLBACK(scan_cb_search_complete), bus, NULL);
+
+#if 0
+dbus_g_object_register_marshaller(marshal_VOID__STRING_STRING, G_TYPE_NONE, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_INVALID);
+dbus_g_proxy_add_signal(scan_info->req_proxy, "RemoteNameUpdated", G_TYPE_STRING, G_TYPE_STRING, G_TYPE_INVALID);
+dbus_g_proxy_connect_signal(scan_info->req_proxy, "RemoteNameUpdated", G_CALLBACK(scan_cb_dev_found), NULL, NULL);
+#endif
+
+error = NULL;
+if (!dbus_g_proxy_call(obj, "DiscoverDevices", &error, G_TYPE_INVALID, G_TYPE_INVALID)) {
+       if (error->domain == DBUS_GERROR && error->code == DBUS_GERROR_REMOTE_EXCEPTION) {
+               g_printerr("Caught remote method exception %s: %s", dbus_g_error_get_name(error), error->message);
+       } else {
+               g_printerr("Error: %s\n", error->message);
+       }
+       return 3;
+}
+
+return 0;
+}
+
index e36d6bbb2fe711364a196e29c82ae327f25134b0..65ae8d5f837a7560b8883218fa462cbb410a95e6 100644 (file)
 #include "gps.h"
 #include "settings.h"
 #include "ui-common.h"
-
 #include "gps-conn.h"
 
-static guint errors;
-static gint fd;
-
-void 
-rcvr_connect_fd(gchar *fdpath)
-{
-/* If file descriptor creation failed, try again later. */
-if (-1 == (fd = open(fdpath, O_RDONLY))) {
-       rcvr_disconnect();
-       rcvr_connect_later();
-} else {
-       /* Reset GPS read buffer */
-       _gps_read_buf_curr = _gps_read_buf;
-       *_gps_read_buf_curr = '\0';
-
-       /* Create channel and add watches. */
-       _channel = g_io_channel_unix_new(fd);
-       g_io_channel_set_flags(_channel, G_IO_FLAG_NONBLOCK, NULL);
-       _error_sid = g_io_add_watch_full(_channel, G_PRIORITY_HIGH_IDLE, G_IO_ERR | G_IO_HUP, channel_cb_error, NULL, NULL);
-       _connect_sid = g_io_add_watch_full(_channel, G_PRIORITY_HIGH_IDLE, G_IO_OUT, channel_cb_connect, NULL, NULL);
-}
-g_free(fdpath);
-}
-
 void 
 rcvr_connect_response(DBusGProxy * proxy, DBusGProxyCall * call_id)
 {
@@ -107,46 +82,6 @@ if (_conn_state == RCVR_DOWN && _rcvr_mac) {
 /* else { Looks like the middle of a disconnect.  Do nothing. } */
 }
 
-/**
- * Connect to the receiver.
- * This method assumes that fd is -1 and _channel is NULL.  If unsure, call
- * rcvr_disconnect() first.
- * Since this is an idle function, this function returns whether or not it
- * should be called again, which is always FALSE.
- */
-gboolean 
-rcvr_connect_now()
-{
-if (_conn_state == RCVR_DOWN && _rcvr_mac) {
-#ifndef DEBUG_GPS
-       if (*_rcvr_mac != '/') {
-               if (_rfcomm_req_proxy) {
-                       gint mybool = TRUE;
-                       dbus_g_proxy_begin_call(_rfcomm_req_proxy,
-                                               BTCOND_RFCOMM_CONNECT_REQ,
-                                               (DBusGProxyCallNotify)
-                                               rcvr_connect_response,
-                                               NULL, NULL,
-                                               G_TYPE_STRING,
-                                               _rcvr_mac,
-                                               G_TYPE_STRING, "SPP",
-                                               G_TYPE_BOOLEAN, &mybool,
-                                               G_TYPE_INVALID);
-               }
-       } else {
-               rcvr_connect_fd(g_strdup(_rcvr_mac));
-       }
-#else
-       /* We're in DEBUG mode, so instead of connecting, skip to FIXED. */
-       printf("FIXED!\n");
-       gps_conn_set_state(RCVR_FIXED);
-#endif
-}
-
-_clater_sid = 0;
-return FALSE;
-}
-
 /**
  * Bluetooth device scanning functions below
  */
index 098b17b8d7866ea14664ed62b5a15c4121239ad8..f8116b39822e18b3fc1b8cae033acb02e9ede6ea 100644 (file)
--- a/src/gps.c
+++ b/src/gps.c
@@ -48,6 +48,7 @@ static gboolean gps_channel_cb_error(GIOChannel *src, GIOCondition condition, gp
 static gboolean gps_channel_cb_input(GIOChannel *src, GIOCondition condition, gpointer data);
 static gboolean gps_channel_cb_connect(GIOChannel * src, GIOCondition condition, gpointer data);
 static gboolean gps_connect_socket(Gps *gps);
+static gboolean gps_connect_file(Gps *gps);
 
 /**
  * Init GPS structure
@@ -96,12 +97,12 @@ gps_connect(Gps *gps)
 {
 switch (gps->io.type) {
        case GPS_IO_FILE:
-               return TRUE;
+               return gps_connect_file(gps);
        break;
        case GPS_IO_RFCOMM:
        case GPS_IO_TCP:
        case GPS_IO_GPSD:
-               gps_connect_socket(gps);
+               return gps_connect_socket(gps);
        break;
        case GPS_IO_GYPSY:
                return FALSE;
@@ -112,6 +113,17 @@ switch (gps->io.type) {
 return FALSE;
 }
 
+static gboolean 
+gps_connect_file(Gps *gps)
+{
+if (-1==(gps->io.fd=open(gps->io.address, O_RDONLY))) {
+       gps_disconnect(gps);
+       gps_connect_later(gps);
+       return FALSE;
+}
+return TRUE;
+}
+
 static gboolean 
 gps_connect_socket(Gps *gps)
 {
@@ -223,8 +235,6 @@ if (gps->io.type==GPS_IO_HILDON_DBUS && gps->io.rfcomm_req_proxy) {
 gboolean 
 gps_connect_now(Gps *gps)
 {
-gint fd;
-
 g_assert(gps);
 
 switch (gps->io.type) {
@@ -237,8 +247,8 @@ switch (gps->io.type) {
        case GPS_IO_TCP:
        case GPS_IO_GPSD:
                if (gps->io.conn==RCVR_DOWN && gps->io.address) {
-                       fd=socket(AF_INET, SOCK_STREAM, 0);
-                       if (fd==-1) {
+                       gps->io.fd=socket(AF_INET, SOCK_STREAM, 0);
+                       if (gps->io.fd==-1) {
                                g_debug("Failed to create socket\n");
                                gps_connect_later(gps);
                                return FALSE;
@@ -246,29 +256,44 @@ switch (gps->io.type) {
                        memcpy(&gps->io.rcvr_addr_in.sin_addr.s_addr, gps->io.address, strlen(gps->io.address));
                        gps->io.rcvr_addr_in.sin_family = AF_INET;
                        gps->io.rcvr_addr_in.sin_port = htons(gps->io.port);
-                       gps->io.fd=fd;
                } else {
                        return FALSE;
                }
        break;
+       case GPS_IO_HILDON_DBUS:
+#ifdef WITH_HILDON_DBUS_BT
+               if (gps->io.rfcomm_req_proxy) {
+                       gint mybool = TRUE;
+                       dbus_g_proxy_begin_call(_rfcomm_req_proxy,
+                               BTCOND_RFCOMM_CONNECT_REQ,
+                               (DBusGProxyCallNotify)
+                               rcvr_connect_response,
+                               NULL, NULL,
+                               G_TYPE_STRING,
+                               _rcvr_mac,
+                               G_TYPE_STRING, "SPP",
+                               G_TYPE_BOOLEAN, &mybool,
+                               G_TYPE_INVALID);
+               }
+#endif
+       break;
        case GPS_IO_RFCOMM:
 #ifdef WITH_BLUEZ
                if (!gps->io.address)
                        return FALSE;
 
                if (gps->io.conn==RCVR_DOWN && gps->io.address) {
-                       fd=socket(AF_BLUETOOTH, SOCK_STREAM, BTPROTO_RFCOMM);
+                       gps->io.fd=socket(AF_BLUETOOTH, SOCK_STREAM, BTPROTO_RFCOMM);
 
                        /* If file descriptor creation failed, try again later.  Note that
                         * there is no need to call rcvr_disconnect() because the file
                         * descriptor creation is the first step, so if it fails, there's
                         * nothing to clean up. */
-                       if (fd==-1) {
+                       if (gps->io.fd==-1) {
                                g_debug("Failed to create socket\n");
                                gps_connect_later(gps);
                                return FALSE;
                        }
-                       gps->io.fd=fd;
                        gps->io.rcvr_addr_rc.rc_family=AF_BLUETOOTH;
                        gps->io.rcvr_addr_rc.rc_channel=1;
                        str2ba(gps->io.address, &gps->io.rcvr_addr_rc.rc_bdaddr);