From: Kaj-Michael Lang Date: Thu, 15 May 2008 15:53:28 +0000 (+0300) Subject: GPS Bluetooth scan: Start to fix bluez D-Bus based scanning X-Git-Url: https://err.no/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=3a91370c0b61b2d2702c5655a87b58824ca86a79;p=mapper GPS Bluetooth scan: Start to fix bluez D-Bus based scanning --- diff --git a/configure.ac b/configure.ac index 7714e9e..07ae533 100644 --- a/configure.ac +++ b/configure.ac @@ -93,6 +93,9 @@ AC_ARG_ENABLE([itbtdbus],AS_HELP_STRING([--enable-itbtdbus],[Use IT D-Bus Blueto AC_ARG_ENABLE([btdbus],AS_HELP_STRING([--enable-btdbus],[Use D-Bus bluez interface]), [enable_btdbus=$enableval], [enable_btdbus=no]) +AC_ARG_ENABLE([bluez],AS_HELP_STRING([--enable-bluez],[Use bluez libbluetooth]), + [enable_bluez=$enableval], [enable_bluez=no]) + AC_ARG_ENABLE([gpsd],AS_HELP_STRING([--enable-gpsd],[Use gpsd]), [enable_gpsd=$enableval], [enable_gpsd=no]) @@ -155,12 +158,16 @@ else AC_DEFINE([WITH_HILDON_DBUS_BT], 1, [IT D-Bus bluetooth]) fi -PKG_CHECK_MODULES(BLUEZ, bluez, HAVE_BLUEZ=yes, HAVE_BLUEZ=no) -if test "x$HAVE_BLUEZ" = "xyes"; then - AC_SUBST(BLUEZ_LIBS) - AC_SUBST(BLUEZ_CFLAGS) - WITH_BLUEZ=yes - AC_DEFINE([WITH_BLUEZ], 1, [Bluez RFCOMM]) +if test "x$enable_bluez" = "xno" ; then + WITH_BLUEZ=no +else + PKG_CHECK_MODULES(BLUEZ, bluez, HAVE_BLUEZ=yes, HAVE_BLUEZ=no) + if test "x$HAVE_BLUEZ" = "xyes"; then + AC_SUBST(BLUEZ_LIBS) + AC_SUBST(BLUEZ_CFLAGS) + WITH_BLUEZ=yes + AC_DEFINE([WITH_BLUEZ], 1, [Bluez RFCOMM]) + fi fi if test "x$enable_btdbus" = "xno" ; then @@ -170,6 +177,7 @@ else AC_DEFINE([WITH_BLUEZ_DBUS_BT], 1, [bluez D-Bus bluetooth]) fi +AM_CONDITIONAL(HAVE_BLUEZ, [test "$enable_bluez" = "yes"]) AM_CONDITIONAL(HAVE_HILDON_DBUS_BT, [test "$enable_itbtdbus" = "yes"]) AM_CONDITIONAL(HAVE_BLUEZ_DBUS_BT, [test "$enable_btdbus" = "yes"]) @@ -460,7 +468,7 @@ if test x$enable_itbtdbus = xyes; then AC_MSG_NOTICE([** Tablet bluetooth D-Bus support enabled]) fi -if test x$HAVE_BLUEZ = xyes; then +if test x$enable_bluez = xyes; then AC_MSG_NOTICE([** Bluez support enabled]) fi diff --git a/src/Makefile.am b/src/Makefile.am index c76dd35..0d0b617 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -133,14 +133,21 @@ libmappergps_la_SOURCES = \ gps-nmea-parse.h \ map.h \ path.h -if HAVE_BLUEZ_DBUS_BT -libmappergps_la_SOURCES+=gps-bluetooth-bluez.c gps-bluetooth-bluez-marshal.c -endif libmappergps_la_CFLAGS = $(GLIBGTK_CFLAGS) $(defines) libmappergps_la_LIBADD = $(GLIBGTK_LIBS) libmappergps_la_LDFLAGS = -lm -no-undefined +# Old C lib +if HAVE_BLUEZ +libmappergps_la_SOURCES+=gps-bluetooth-bluez.c +endif + +# New D-Bus based bluez +if HAVE_BLUEZ_DBUS_BT +libmappergps_la_SOURCES+=gps-bluetooth-bluez-dbus.c gps-bluetooth-bluez-marschal.h gps-bluetooth-bluez-marshal.c +endif + if HAVE_HILDON_DBUS_BT libmappergps_la_SOURCES+=gps-bluetooth-maemo.c gps-bluetooth-maemo-marshal.c libmappergps_la_CFLAGS+= $(HILDON_CFLAGS) $(HILDONFM_CFLAGS) $(HILDON_HELP_CFLAGS) $(LIBGPSBT_CFLAGS) diff --git a/src/gps-bluetooth-bluez-dbus.c b/src/gps-bluetooth-bluez-dbus.c index 5b8f414..0ac413e 100644 --- a/src/gps-bluetooth-bluez-dbus.c +++ b/src/gps-bluetooth-bluez-dbus.c @@ -25,9 +25,13 @@ #include -#include +#include +#include +#include +#include #include "mapper.h" +#include "bluetooth-scan.h" #include "gps-bluetooth-bluez-marshal.h" #include "gps.h" #include "settings.h" @@ -41,44 +45,63 @@ 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); +gtk_list_store_set(scan_info->store, &iter, 0, g_strdup(address), -1); +} + +static void +scan_cb_dev_name_found(DBusGProxy *object, const char *address, const char *name, ScanInfo *scan_info) +{ +GtkTreeIter iter; +gboolean c; + +c=gtk_tree_model_get_iter_first(scan_info->store, &iter); +while (c == TRUE) { + gchar *value; + + gtk_tree_model_get(GTK_TREE_MODEL(scan_info->store), &iter, 0, &value, -1); + if (g_ascii_strcasecmp(address, value) == 0) { + gtk_list_store_set(scan_info->store, &iter, 1, g_strdup(name), -1); + return; + } + c=gtk_tree_model_iter_next(GTK_TREE_MODEL(scan_info->store), &iter); +} + } static void -scan_cb_search_complete(DBusGProxy * sig_proxy, ScanInfo * scan_info) +scan_cb_search_complete(DBusGProxy *object, 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); +dbus_g_proxy_disconnect_signal(object, "RemoteDeviceFound", G_CALLBACK(scan_cb_dev_found), scan_info); +dbus_g_proxy_disconnect_signal(object, "DiscoveryCompleted", G_CALLBACK(scan_cb_search_complete), scan_info); +dbus_g_proxy_disconnect_signal(object, "RemoteNameUpdated", G_CALLBACK(scan_cb_dev_name_found), scan_info); } gint -scan_start_search(ScanInfo * scan_info) +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"))) { +if (NULL == (scan_info->req_proxy = dbus_g_proxy_new_for_name(dbus_conn, "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_object_register_marshaller(_bt_bluez_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_connect_signal(scan_info->req_proxy, "RemoteDeviceFound", G_CALLBACK(scan_cb_dev_found), scan_info, 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); +dbus_g_proxy_connect_signal(scan_info->req_proxy, "DiscoveryCompleted", G_CALLBACK(scan_cb_search_complete), scan_info, 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_object_register_marshaller(_bt_bluez_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 +dbus_g_proxy_connect_signal(scan_info->req_proxy, "RemoteNameUpdated", G_CALLBACK(scan_cb_dev_name_found), scan_info, NULL); error = NULL; -if (!dbus_g_proxy_call(obj, "DiscoverDevices", &error, G_TYPE_INVALID, G_TYPE_INVALID)) { +if (!dbus_g_proxy_call(scan_info->req_proxy, "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 {