* [Bluez-devel] [PATCH] client.c cleanup
@ 2008-01-25 2:22 Bastien Nocera
2008-01-29 17:01 ` Marcel Holtmann
0 siblings, 1 reply; 12+ messages in thread
From: Bastien Nocera @ 2008-01-25 2:22 UTC (permalink / raw)
To: BlueZ Hackers
[-- Attachment #1: Type: text/plain, Size: 1086 bytes --]
Heya,
Some time ago I had problems with client.c's architecture. It would
allow me to easily report completed discoveries without causing crashes.
The attached patch moves all the static variables into the main
BluetoothClient object, and instead of return a new object when using
_new() we return an existing instance of the client.
This makes no changes to the external API for the BluetoothClient, and
should work just as well as older versions did.
A couple of bugs I found in client.c:
- launch test-client with a dongle inserted, remove and reinsert the
dongle, the bdaddr of the device is not set anymore
- launch test-client without a dongle inserted, insert it, the bdaddr is
not set and there's no children to the adapter (although there are if
inserted when started)
- launch test-client with a dongle inserted, remove it, add another one,
the set of known devices underneath hasn't changed
All those problems exist in the old version of client.c, and I intend on
fixing them, as well as making the search button work as expected in the
device selection widget.
Cheers
[-- Attachment #2: bluez-gnome-client-less-static.patch --]
[-- Type: text/x-patch, Size: 43648 bytes --]
Index: client.c
===================================================================
RCS file: /cvsroot/bluez/gnome/common/client.c,v
retrieving revision 1.36
diff -u -p -r1.36 client.c
--- client.c 17 Dec 2007 01:09:28 -0000 1.36
+++ client.c 25 Jan 2008 02:11:18 -0000
@@ -36,11 +36,7 @@
#include "dbus-glue.h"
-static DBusGConnection *conn = NULL;
-
-static GtkTreeStore *store = NULL;
-
-static gchar *default_adapter = NULL;
+static BluetoothClient *self = NULL;
#define BLUETOOTH_CLIENT_GET_PRIVATE(obj) (G_TYPE_INSTANCE_GET_PRIVATE((obj), \
BLUETOOTH_TYPE_CLIENT, BluetoothClientPrivate))
@@ -49,6 +45,10 @@ typedef struct _BluetoothClientPrivate B
struct _BluetoothClientPrivate {
gboolean registered;
+
+ DBusGConnection *conn;
+ GtkTreeStore *store;
+ gchar *default_adapter;
};
enum {
@@ -60,40 +60,28 @@ static int client_table_signals[LAST_SIG
G_DEFINE_TYPE(BluetoothClient, bluetooth_client, G_TYPE_OBJECT)
-static void bluetooth_client_init(BluetoothClient *self)
+static gboolean find_iter_for_object(DBusGProxy *object,
+ BluetoothClient *client,
+ GtkTreeIter *iter)
{
- BluetoothClientPrivate *priv = BLUETOOTH_CLIENT_GET_PRIVATE(self);
-
- priv->registered = FALSE;
-}
+ BluetoothClientPrivate *priv = BLUETOOTH_CLIENT_GET_PRIVATE(client);
+ gboolean cont;
-static void bluetooth_client_finalize(GObject *object)
-{
- //BluetoothClientPrivate *priv = BLUETOOTH_CLIENT_GET_PRIVATE(object);
-}
+ if (gtk_tree_model_get_iter_first(GTK_TREE_MODEL(priv->store), iter) == FALSE)
+ return FALSE;
-static void bluetooth_client_set_property(GObject *object, guint prop_id,
- const GValue *value, GParamSpec *pspec)
-{
- //BluetoothClientPrivate *priv = BLUETOOTH_CLIENT_GET_PRIVATE(object);
+ cont = TRUE;
+ while (cont == TRUE) {
+ DBusGProxy *o;
- switch (prop_id) {
- default:
- G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec);
- break;
+ gtk_tree_model_get(GTK_TREE_MODEL(priv->store), iter,
+ COLUMN_OBJECT, &o, -1);
+ if (o == object)
+ return TRUE;
+ cont = gtk_tree_model_iter_next(GTK_TREE_MODEL(priv->store), iter);
}
-}
-static void bluetooth_client_get_property(GObject *object, guint prop_id,
- GValue *value, GParamSpec *pspec)
-{
- //BluetoothClientPrivate *priv = BLUETOOTH_CLIENT_GET_PRIVATE(object);
-
- switch (prop_id) {
- default:
- G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec);
- break;
- }
+ return FALSE;
}
static void mode_changed(DBusGProxy *object,
@@ -109,12 +97,15 @@ static void timeout_changed(DBusGProxy *
static void name_changed(DBusGProxy *object,
const char *name, gpointer user_data)
{
- GtkTreePath *path = user_data;
+ BluetoothClient *client = BLUETOOTH_CLIENT(user_data);
+ BluetoothClientPrivate *priv = BLUETOOTH_CLIENT_GET_PRIVATE(client);
+
GtkTreeIter iter;
- gtk_tree_model_get_iter(GTK_TREE_MODEL(store), &iter, path);
+ if (find_iter_for_object(object, BLUETOOTH_CLIENT(client), &iter) == FALSE)
+ return;
- gtk_tree_store_set(store, &iter, COLUMN_NAME, name, -1);
+ gtk_tree_store_set(priv->store, &iter, COLUMN_NAME, name, -1);
}
static void minor_changed(DBusGProxy *object,
@@ -194,8 +185,10 @@ static guint class_to_type(guint32 class
}
static void insert_device(DBusGProxy *object, GtkTreeIter *parent,
+ BluetoothClient *client,
const char *address, const int rssi, gboolean active)
{
+ BluetoothClientPrivate *priv = BLUETOOTH_CLIENT_GET_PRIVATE(client);
GtkTreeIter iter;
GHashTable *hash = NULL;
GValue *value;
@@ -251,7 +244,7 @@ static void insert_device(DBusGProxy *ob
else
connected = g_value_get_boolean(value);
- cont = gtk_tree_model_iter_children(GTK_TREE_MODEL(store),
+ cont = gtk_tree_model_iter_children(GTK_TREE_MODEL(priv->store),
&iter, parent);
type = class_to_type(class);
@@ -259,11 +252,11 @@ static void insert_device(DBusGProxy *ob
while (cont == TRUE) {
gchar *value;
- gtk_tree_model_get(GTK_TREE_MODEL(store), &iter,
+ gtk_tree_model_get(GTK_TREE_MODEL(priv->store), &iter,
COLUMN_ADDRESS, &value, -1);
if (g_ascii_strcasecmp(address, value) == 0) {
- gtk_tree_store_set(store, &iter,
+ gtk_tree_store_set(priv->store, &iter,
COLUMN_ACTIVE, active,
COLUMN_CLASS, class,
COLUMN_RSSI, rssi,
@@ -275,10 +268,10 @@ static void insert_device(DBusGProxy *ob
return;
}
- cont = gtk_tree_model_iter_next(GTK_TREE_MODEL(store), &iter);
+ cont = gtk_tree_model_iter_next(GTK_TREE_MODEL(priv->store), &iter);
}
- gtk_tree_store_insert_with_values(store, &iter, parent, -1,
+ gtk_tree_store_insert_with_values(priv->store, &iter, parent, -1,
COLUMN_ACTIVE, active,
COLUMN_ADDRESS, address,
COLUMN_CLASS, class,
@@ -291,231 +284,243 @@ static void insert_device(DBusGProxy *ob
}
static void invalidate_device(DBusGProxy *object,
- GtkTreeIter *parent, const char *address)
+ GtkTreeIter *parent,
+ BluetoothClient *client,
+ const char *address)
{
+ BluetoothClientPrivate *priv = BLUETOOTH_CLIENT_GET_PRIVATE(client);
GtkTreeIter iter;
gboolean cont;
- cont = gtk_tree_model_iter_children(GTK_TREE_MODEL(store),
+ cont = gtk_tree_model_iter_children(GTK_TREE_MODEL(priv->store),
&iter, parent);
while (cont == TRUE) {
gchar *value;
- gtk_tree_model_get(GTK_TREE_MODEL(store), &iter,
+ gtk_tree_model_get(GTK_TREE_MODEL(priv->store), &iter,
COLUMN_ADDRESS, &value, -1);
if (g_ascii_strcasecmp(address, value) == 0) {
- gtk_tree_store_set(store, &iter,
+ gtk_tree_store_set(priv->store, &iter,
COLUMN_ACTIVE, FALSE, -1);
return;
}
- cont = gtk_tree_model_iter_next(GTK_TREE_MODEL(store), &iter);
+ cont = gtk_tree_model_iter_next(GTK_TREE_MODEL(priv->store), &iter);
}
}
static void change_connected(DBusGProxy *object, GtkTreeIter *parent,
+ BluetoothClient *client,
const char *address, gboolean connected)
{
+ BluetoothClientPrivate *priv = BLUETOOTH_CLIENT_GET_PRIVATE(client);
GtkTreeIter iter;
gboolean cont;
- cont = gtk_tree_model_iter_children(GTK_TREE_MODEL(store),
+ cont = gtk_tree_model_iter_children(GTK_TREE_MODEL(priv->store),
&iter, parent);
while (cont == TRUE) {
gchar *value;
- gtk_tree_model_get(GTK_TREE_MODEL(store), &iter,
+ gtk_tree_model_get(GTK_TREE_MODEL(priv->store), &iter,
COLUMN_ADDRESS, &value, -1);
if (g_ascii_strcasecmp(address, value) == 0) {
- gtk_tree_store_set(store, &iter,
+ gtk_tree_store_set(priv->store, &iter,
COLUMN_CONNECTED, connected, -1);
return;
}
- cont = gtk_tree_model_iter_next(GTK_TREE_MODEL(store), &iter);
+ cont = gtk_tree_model_iter_next(GTK_TREE_MODEL(priv->store), &iter);
}
}
static void rename_device(DBusGProxy *object, GtkTreeIter *parent,
+ BluetoothClient *client,
const char *address, const char *name)
{
+ BluetoothClientPrivate *priv = BLUETOOTH_CLIENT_GET_PRIVATE(client);
GtkTreeIter iter;
gboolean cont;
- cont = gtk_tree_model_iter_children(GTK_TREE_MODEL(store),
+ cont = gtk_tree_model_iter_children(GTK_TREE_MODEL(priv->store),
&iter, parent);
while (cont == TRUE) {
gchar *value;
- gtk_tree_model_get(GTK_TREE_MODEL(store), &iter,
+ gtk_tree_model_get(GTK_TREE_MODEL(priv->store), &iter,
COLUMN_ADDRESS, &value, -1);
if (g_ascii_strcasecmp(address, value) == 0) {
- gtk_tree_store_set(store, &iter,
+ gtk_tree_store_set(priv->store, &iter,
COLUMN_NAME, name, -1);
return;
}
- cont = gtk_tree_model_iter_next(GTK_TREE_MODEL(store), &iter);
+ cont = gtk_tree_model_iter_next(GTK_TREE_MODEL(priv->store), &iter);
}
}
static void change_bonded(DBusGProxy *object, GtkTreeIter *parent,
+ BluetoothClient *client,
const char *address, gboolean bonded)
{
+ BluetoothClientPrivate *priv = BLUETOOTH_CLIENT_GET_PRIVATE(client);
GtkTreeIter iter;
gboolean cont;
- cont = gtk_tree_model_iter_children(GTK_TREE_MODEL(store),
+ cont = gtk_tree_model_iter_children(GTK_TREE_MODEL(priv->store),
&iter, parent);
while (cont == TRUE) {
gchar *value;
- gtk_tree_model_get(GTK_TREE_MODEL(store), &iter,
+ gtk_tree_model_get(GTK_TREE_MODEL(priv->store), &iter,
COLUMN_ADDRESS, &value, -1);
if (g_ascii_strcasecmp(address, value) == 0) {
- gtk_tree_store_set(store, &iter,
+ gtk_tree_store_set(priv->store, &iter,
COLUMN_BONDED, bonded, -1);
return;
}
- cont = gtk_tree_model_iter_next(GTK_TREE_MODEL(store), &iter);
+ cont = gtk_tree_model_iter_next(GTK_TREE_MODEL(priv->store), &iter);
}
}
static void change_trusted(DBusGProxy *object, GtkTreeIter *parent,
+ BluetoothClient *client,
const char *address, gboolean trusted)
{
+ BluetoothClientPrivate *priv = BLUETOOTH_CLIENT_GET_PRIVATE(client);
GtkTreeIter iter;
gboolean cont;
- cont = gtk_tree_model_iter_children(GTK_TREE_MODEL(store),
+ cont = gtk_tree_model_iter_children(GTK_TREE_MODEL(priv->store),
&iter, parent);
while (cont == TRUE) {
gchar *value;
- gtk_tree_model_get(GTK_TREE_MODEL(store), &iter,
+ gtk_tree_model_get(GTK_TREE_MODEL(priv->store), &iter,
COLUMN_ADDRESS, &value, -1);
if (g_ascii_strcasecmp(address, value) == 0) {
- gtk_tree_store_set(store, &iter,
+ gtk_tree_store_set(priv->store, &iter,
COLUMN_TRUSTED, trusted, -1);
return;
}
- cont = gtk_tree_model_iter_next(GTK_TREE_MODEL(store), &iter);
+ cont = gtk_tree_model_iter_next(GTK_TREE_MODEL(priv->store), &iter);
}
}
static void device_found(DBusGProxy *object, const char *address,
const unsigned int class, const int rssi, gpointer user_data)
{
- GtkTreePath *path = user_data;
GtkTreeIter iter;
- gtk_tree_model_get_iter(GTK_TREE_MODEL(store), &iter, path);
+ if (find_iter_for_object(object, BLUETOOTH_CLIENT(user_data), &iter) == FALSE)
+ return;
- insert_device(object, &iter, address, rssi, TRUE);
+ insert_device(object, &iter, BLUETOOTH_CLIENT(user_data), address, rssi, TRUE);
}
static void device_disappeared(DBusGProxy *object,
const char *address, gpointer user_data)
{
- GtkTreePath *path = user_data;
GtkTreeIter iter;
- gtk_tree_model_get_iter(GTK_TREE_MODEL(store), &iter, path);
+ if (find_iter_for_object(object, BLUETOOTH_CLIENT(user_data), &iter) == FALSE)
+ return;
- invalidate_device(object, &iter, address);
+ invalidate_device(object, &iter, BLUETOOTH_CLIENT(user_data), address);
}
static void device_connected(DBusGProxy *object,
const char *address, gpointer user_data)
{
- GtkTreePath *path = user_data;
GtkTreeIter iter;
- gtk_tree_model_get_iter(GTK_TREE_MODEL(store), &iter, path);
+ if (find_iter_for_object(object, BLUETOOTH_CLIENT(user_data), &iter) == FALSE)
+ return;
- change_connected(object, &iter, address, TRUE);
+ change_connected(object, &iter, BLUETOOTH_CLIENT(user_data), address, TRUE);
}
static void device_disconnected(DBusGProxy *object,
const char *address, gpointer user_data)
{
- GtkTreePath *path = user_data;
GtkTreeIter iter;
- gtk_tree_model_get_iter(GTK_TREE_MODEL(store), &iter, path);
+ if (find_iter_for_object(object, BLUETOOTH_CLIENT(user_data), &iter) == FALSE)
+ return;
- change_connected(object, &iter, address, FALSE);
+ change_connected(object, &iter, BLUETOOTH_CLIENT(user_data), address, FALSE);
}
static void name_updated(DBusGProxy *object,
const char *address, const char *name, gpointer user_data)
{
- GtkTreePath *path = user_data;
GtkTreeIter iter;
- gtk_tree_model_get_iter(GTK_TREE_MODEL(store), &iter, path);
+ if (find_iter_for_object(object, BLUETOOTH_CLIENT(user_data), &iter) == FALSE)
+ return;
- rename_device(object, &iter, address, name);
+ rename_device(object, &iter, BLUETOOTH_CLIENT(user_data), address, name);
}
static void bonding_created(DBusGProxy *object,
const char *address, gpointer user_data)
{
- GtkTreePath *path = user_data;
GtkTreeIter iter;
- gtk_tree_model_get_iter(GTK_TREE_MODEL(store), &iter, path);
+ if (find_iter_for_object(object, BLUETOOTH_CLIENT(user_data), &iter) == FALSE)
+ return;
- change_bonded(object, &iter, address, TRUE);
+ change_bonded(object, &iter, BLUETOOTH_CLIENT(user_data), address, TRUE);
}
static void bonding_removed(DBusGProxy *object,
const char *address, gpointer user_data)
{
- GtkTreePath *path = user_data;
GtkTreeIter iter;
- gtk_tree_model_get_iter(GTK_TREE_MODEL(store), &iter, path);
+ if (find_iter_for_object(object, BLUETOOTH_CLIENT(user_data), &iter) == FALSE)
+ return;
- change_bonded(object, &iter, address, FALSE);
+ change_bonded(object, &iter, BLUETOOTH_CLIENT(user_data), address, FALSE);
}
static void trust_added(DBusGProxy *object,
const char *address, gpointer user_data)
{
- GtkTreePath *path = user_data;
GtkTreeIter iter;
- gtk_tree_model_get_iter(GTK_TREE_MODEL(store), &iter, path);
+ if (find_iter_for_object(object, BLUETOOTH_CLIENT(user_data), &iter) == FALSE)
+ return;
- change_trusted(object, &iter, address, TRUE);
+ change_trusted(object, &iter, BLUETOOTH_CLIENT(user_data), address, TRUE);
}
static void trust_removed(DBusGProxy *object,
const char *address, gpointer user_data)
{
- GtkTreePath *path = user_data;
GtkTreeIter iter;
- gtk_tree_model_get_iter(GTK_TREE_MODEL(store), &iter, path);
+ if (find_iter_for_object(object, BLUETOOTH_CLIENT(user_data), &iter) == FALSE)
+ return;
- change_trusted(object, &iter, address, FALSE);
+ change_trusted(object, &iter, BLUETOOTH_CLIENT(user_data), address, FALSE);
}
-static void update_adapter(DBusGProxy *object, GtkTreeIter *iter)
+static void update_adapter(DBusGProxy *object, GtkTreeIter *iter, BluetoothClient *client)
{
+ BluetoothClientPrivate *priv = BLUETOOTH_CLIENT_GET_PRIVATE(client);
GError *error = NULL;
char **array = NULL;
char *address = NULL, *mode = NULL;
@@ -535,14 +540,14 @@ static void update_adapter(DBusGProxy *o
adapter_get_minor_class(object, &minor, NULL);
- gtk_tree_store_set(store, iter, COLUMN_ADDRESS, address,
+ gtk_tree_store_set(priv->store, iter, COLUMN_ADDRESS, address,
COLUMN_NAME, name, -1);
adapter_list_connections(object, &array, &error);
if (error == NULL) {
while (*array) {
- insert_device(object, iter, *array, 0, FALSE);
+ insert_device(object, iter, client, *array, 0, FALSE);
array++;
}
} else {
@@ -555,7 +560,7 @@ static void update_adapter(DBusGProxy *o
if (error == NULL) {
while (*array) {
- insert_device(object, iter, *array, 0, FALSE);
+ insert_device(object, iter, client, *array, 0, FALSE);
array++;
}
} else {
@@ -568,7 +573,7 @@ static void update_adapter(DBusGProxy *o
if (error == NULL) {
while (*array) {
- insert_device(object, iter, *array, 0, FALSE);
+ insert_device(object, iter, client, *array, 0, FALSE);
array++;
}
} else {
@@ -584,228 +589,232 @@ failover:
if (error == NULL) {
while (*array) {
- insert_device(object, iter, *array, 0, FALSE);
+ insert_device(object, iter, client, *array, 0, FALSE);
array++;
}
} else
g_error_free(error);
}
-static void add_adapter(const char *path)
+static void add_adapter(const char *path, BluetoothClient *client)
{
+ BluetoothClientPrivate *priv = BLUETOOTH_CLIENT_GET_PRIVATE(client);
DBusGProxy *object;
GtkTreeIter iter;
- GtkTreePath *tree_path;
gboolean cont;
- cont = gtk_tree_model_get_iter_first(GTK_TREE_MODEL(store), &iter);
+ cont = gtk_tree_model_get_iter_first(GTK_TREE_MODEL(priv->store), &iter);
while (cont == TRUE) {
gchar *value;
- gtk_tree_model_get(GTK_TREE_MODEL(store), &iter,
+ gtk_tree_model_get(GTK_TREE_MODEL(priv->store), &iter,
COLUMN_PATH, &value,
COLUMN_OBJECT, &object, -1);
if (g_ascii_strcasecmp(path, value) == 0) {
- gtk_tree_store_set(store, &iter,
+ gtk_tree_store_set(priv->store, &iter,
COLUMN_ACTIVE, TRUE, -1);
- update_adapter(object, &iter);
+ update_adapter(object, &iter, client);
return;
}
- cont = gtk_tree_model_iter_next(GTK_TREE_MODEL(store), &iter);
+ cont = gtk_tree_model_iter_next(GTK_TREE_MODEL(priv->store), &iter);
}
- object = dbus_g_proxy_new_for_name(conn, "org.bluez",
+ object = dbus_g_proxy_new_for_name(priv->conn, "org.bluez",
path, "org.bluez.Adapter");
- gtk_tree_store_insert_with_values(store, &iter, NULL, -1,
+ gtk_tree_store_insert_with_values(priv->store, &iter, NULL, -1,
COLUMN_PATH, path,
COLUMN_ACTIVE, TRUE,
COLUMN_OBJECT, object, -1);
g_object_unref(object);
- tree_path = gtk_tree_model_get_path(GTK_TREE_MODEL(store), &iter);
-
dbus_g_proxy_add_signal(object, "ModeChanged",
G_TYPE_STRING, G_TYPE_INVALID);
dbus_g_proxy_connect_signal(object, "ModeChanged",
- G_CALLBACK(mode_changed), tree_path, NULL);
+ G_CALLBACK(mode_changed), client, NULL);
dbus_g_proxy_add_signal(object, "DiscoverableTimeoutChanged",
G_TYPE_UINT, G_TYPE_INVALID);
dbus_g_proxy_connect_signal(object, "DiscoverableTimeoutChanged",
- G_CALLBACK(timeout_changed), tree_path, NULL);
+ G_CALLBACK(timeout_changed), client, NULL);
dbus_g_proxy_add_signal(object, "NameChanged",
G_TYPE_STRING, G_TYPE_INVALID);
dbus_g_proxy_connect_signal(object, "NameChanged",
- G_CALLBACK(name_changed), tree_path, NULL);
+ G_CALLBACK(name_changed), client, NULL);
dbus_g_proxy_add_signal(object, "MinorClassChanged",
G_TYPE_STRING, G_TYPE_INVALID);
dbus_g_proxy_connect_signal(object, "MinorClassChanged",
- G_CALLBACK(minor_changed), tree_path, NULL);
+ G_CALLBACK(minor_changed), client, NULL);
dbus_g_proxy_add_signal(object, "RemoteDeviceFound",
G_TYPE_STRING, G_TYPE_UINT,
G_TYPE_INT, G_TYPE_INVALID);
dbus_g_proxy_connect_signal(object, "RemoteDeviceFound",
- G_CALLBACK(device_found), tree_path, NULL);
+ G_CALLBACK(device_found), client, NULL);
dbus_g_proxy_add_signal(object, "RemoteDeviceDisappeared",
G_TYPE_STRING, G_TYPE_INVALID);
dbus_g_proxy_connect_signal(object, "RemoteDeviceDisappeared",
- G_CALLBACK(device_disappeared), tree_path, NULL);
+ G_CALLBACK(device_disappeared), client, NULL);
dbus_g_proxy_add_signal(object, "RemoteDeviceConnected",
G_TYPE_STRING, G_TYPE_INVALID);
dbus_g_proxy_connect_signal(object, "RemoteDeviceConnected",
- G_CALLBACK(device_connected), tree_path, NULL);
+ G_CALLBACK(device_connected), client, NULL);
dbus_g_proxy_add_signal(object, "RemoteDeviceDisconnected",
G_TYPE_STRING, G_TYPE_INVALID);
dbus_g_proxy_connect_signal(object, "RemoteDeviceDisconnected",
- G_CALLBACK(device_disconnected), tree_path, NULL);
+ G_CALLBACK(device_disconnected), client, NULL);
dbus_g_proxy_add_signal(object, "RemoteNameUpdated",
G_TYPE_STRING, G_TYPE_STRING, G_TYPE_INVALID);
dbus_g_proxy_connect_signal(object, "RemoteNameUpdated",
- G_CALLBACK(name_updated), tree_path, NULL);
+ G_CALLBACK(name_updated), client, NULL);
dbus_g_proxy_add_signal(object, "BondingCreated",
G_TYPE_STRING, G_TYPE_INVALID);
dbus_g_proxy_connect_signal(object, "BondingCreated",
- G_CALLBACK(bonding_created), tree_path, NULL);
+ G_CALLBACK(bonding_created), client, NULL);
dbus_g_proxy_add_signal(object, "BondingRemoved",
G_TYPE_STRING, G_TYPE_INVALID);
dbus_g_proxy_connect_signal(object, "BondingRemoved",
- G_CALLBACK(bonding_removed), tree_path, NULL);
+ G_CALLBACK(bonding_removed), client, NULL);
dbus_g_proxy_add_signal(object, "TrustAdded",
G_TYPE_STRING, G_TYPE_INVALID);
dbus_g_proxy_connect_signal(object, "TrustAdded",
- G_CALLBACK(trust_added), tree_path, NULL);
+ G_CALLBACK(trust_added), client, NULL);
dbus_g_proxy_add_signal(object, "TrustRemoved",
G_TYPE_STRING, G_TYPE_INVALID);
dbus_g_proxy_connect_signal(object, "TrustRemoved",
- G_CALLBACK(trust_removed), tree_path, NULL);
+ G_CALLBACK(trust_removed), client, NULL);
dbus_g_proxy_add_signal(object, "DiscoveryCompleted", G_TYPE_INVALID);
- update_adapter(object, &iter);
+ update_adapter(object, &iter, client);
}
-static void remove_adapter(const char *path)
+static void remove_adapter(const char *path, BluetoothClient *client)
{
+ BluetoothClientPrivate *priv = BLUETOOTH_CLIENT_GET_PRIVATE(client);
GtkTreeIter iter;
gboolean cont;
- cont = gtk_tree_model_get_iter_first(GTK_TREE_MODEL(store), &iter);
+ cont = gtk_tree_model_get_iter_first(GTK_TREE_MODEL(priv->store), &iter);
while (cont == TRUE) {
gchar *value;
- gtk_tree_model_get(GTK_TREE_MODEL(store), &iter,
+ gtk_tree_model_get(GTK_TREE_MODEL(priv->store), &iter,
COLUMN_PATH, &value, -1);
if (g_ascii_strcasecmp(path, value) == 0) {
- gtk_tree_store_set(store, &iter,
+ gtk_tree_store_set(priv->store, &iter,
COLUMN_ACTIVE, FALSE,
COLUMN_ADDRESS, NULL,
COLUMN_NAME, NULL, -1);
return;
}
- cont = gtk_tree_model_iter_next(GTK_TREE_MODEL(store), &iter);
+ cont = gtk_tree_model_iter_next(GTK_TREE_MODEL(priv->store), &iter);
}
}
static void adapter_added(DBusGProxy *object,
const char *path, gpointer user_data)
{
- add_adapter(path);
+ add_adapter(path, BLUETOOTH_CLIENT(user_data));
}
static void adapter_removed(DBusGProxy *object,
const char *path, gpointer user_data)
{
- remove_adapter(path);
+ remove_adapter(path, BLUETOOTH_CLIENT(user_data));
}
static void default_adapter_changed(DBusGProxy *object,
const char *path, gpointer user_data)
{
- gchar *temp = default_adapter;
-
- default_adapter = g_ascii_strcasecmp(path, "") ? g_strdup(path) : NULL;
-
+ BluetoothClientPrivate *priv = BLUETOOTH_CLIENT_GET_PRIVATE(user_data);
+ gchar *temp;
+
+ temp = priv->default_adapter;
+ priv->default_adapter = g_ascii_strcasecmp(path, "") ? g_strdup(path) : NULL;
g_free(temp);
+
+ g_message ("new default adapter: %s", priv->default_adapter);
}
static void discovery_completed(DBusGProxy *object,
gpointer user_data)
{
#if 0
- BluetoothClient *self = BLUETOOTH_CLIENT(user_data);
+ BluetoothClient *client = BLUETOOTH_CLIENT(user_data);
- g_signal_emit(G_OBJECT(self), client_table_signals[DISCOVERIES_COMPLETED], 0);
+ g_signal_emit(G_OBJECT(client), client_table_signals[DISCOVERIES_COMPLETED], 0);
#endif
+ g_message ("discovery_completed");
}
-static void setup_manager(void)
+static void setup_manager(BluetoothClient *client)
{
+ BluetoothClientPrivate *priv = BLUETOOTH_CLIENT_GET_PRIVATE(client);
DBusGProxy *object;
GError *error = NULL;
char **array = NULL;
- object = dbus_g_proxy_new_for_name(conn, "org.bluez",
+ object = dbus_g_proxy_new_for_name(priv->conn, "org.bluez",
"/org/bluez", "org.bluez.Manager");
dbus_g_proxy_add_signal(object, "AdapterAdded",
G_TYPE_STRING, G_TYPE_INVALID);
dbus_g_proxy_connect_signal(object, "AdapterAdded",
- G_CALLBACK(adapter_added), conn, NULL);
+ G_CALLBACK(adapter_added), client, NULL);
dbus_g_proxy_add_signal(object, "AdapterRemoved",
G_TYPE_STRING, G_TYPE_INVALID);
dbus_g_proxy_connect_signal(object, "AdapterRemoved",
- G_CALLBACK(adapter_removed), conn, NULL);
+ G_CALLBACK(adapter_removed), client, NULL);
dbus_g_proxy_add_signal(object, "DefaultAdapterChanged",
G_TYPE_STRING, G_TYPE_INVALID);
dbus_g_proxy_connect_signal(object, "DefaultAdapterChanged",
- G_CALLBACK(default_adapter_changed), conn, NULL);
+ G_CALLBACK(default_adapter_changed), client, NULL);
- manager_default_adapter(object, &default_adapter, NULL);
+ manager_default_adapter(object, &priv->default_adapter, NULL);
manager_list_adapters(object, &array, &error);
if (error == NULL) {
while (*array) {
- add_adapter(*array);
+ add_adapter(*array, client);
array++;
}
} else
@@ -815,25 +824,20 @@ static void setup_manager(void)
static void name_owner_changed(DBusGProxy *object, const char *name,
const char *prev, const char *new, gpointer user_data)
{
+ BluetoothClient *client = BLUETOOTH_CLIENT(user_data);
+
if (!g_ascii_strcasecmp(name, "org.bluez") && *new == '\0') {
- /* disable adapters */
+ /* FIXME disable adapters */
}
}
-static void setup_dbus(void)
+static void setup_dbus(BluetoothClient *client)
{
+ BluetoothClientPrivate *priv = BLUETOOTH_CLIENT_GET_PRIVATE(client);
DBusGProxy *object;
GError *error = NULL;
- 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(marshal_VOID__STRING_STRING,
- G_TYPE_NONE, G_TYPE_STRING,
- G_TYPE_STRING, G_TYPE_INVALID);
-
- conn = dbus_g_bus_get(DBUS_BUS_SYSTEM, &error);
+ priv->conn = dbus_g_bus_get(DBUS_BUS_SYSTEM, &error);
if (error != NULL) {
g_printerr("Connecting to system bus failed: %s\n",
error->message);
@@ -841,7 +845,7 @@ static void setup_dbus(void)
return;
}
- object = dbus_g_proxy_new_for_name(conn, DBUS_SERVICE_DBUS,
+ object = dbus_g_proxy_new_for_name(priv->conn, DBUS_SERVICE_DBUS,
DBUS_PATH_DBUS, DBUS_INTERFACE_DBUS);
dbus_g_proxy_add_signal(object, "NameOwnerChanged",
@@ -849,7 +853,56 @@ static void setup_dbus(void)
G_TYPE_STRING, G_TYPE_INVALID);
dbus_g_proxy_connect_signal(object, "NameOwnerChanged",
- G_CALLBACK(name_owner_changed), NULL, NULL);
+ G_CALLBACK(name_owner_changed), client, NULL);
+}
+
+static void bluetooth_client_finalize(GObject *object)
+{
+ BluetoothClientPrivate *priv = BLUETOOTH_CLIENT_GET_PRIVATE(object);
+
+ priv->registered = FALSE;
+ g_free(priv->default_adapter);
+ g_object_unref(G_OBJECT(priv->store));
+}
+
+static void bluetooth_client_init(BluetoothClient *client)
+{
+ BluetoothClientPrivate *priv = BLUETOOTH_CLIENT_GET_PRIVATE(client);
+
+ priv->registered = FALSE;
+
+ priv->store = gtk_tree_store_new(11, G_TYPE_STRING, G_TYPE_BOOLEAN,
+ G_TYPE_OBJECT, G_TYPE_STRING, G_TYPE_UINT,
+ G_TYPE_INT, G_TYPE_STRING, G_TYPE_UINT,
+ G_TYPE_BOOLEAN, G_TYPE_BOOLEAN, G_TYPE_BOOLEAN);
+
+ setup_dbus(client);
+
+ setup_manager(client);
+}
+
+static void bluetooth_client_set_property(GObject *object, guint prop_id,
+ const GValue *value, GParamSpec *pspec)
+{
+ //BluetoothClientPrivate *priv = BLUETOOTH_CLIENT_GET_PRIVATE(object);
+
+ switch (prop_id) {
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec);
+ break;
+ }
+}
+
+static void bluetooth_client_get_property(GObject *object, guint prop_id,
+ GValue *value, GParamSpec *pspec)
+{
+ //BluetoothClientPrivate *priv = BLUETOOTH_CLIENT_GET_PRIVATE(object);
+
+ switch (prop_id) {
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec);
+ break;
+ }
}
static void bluetooth_client_class_init(BluetoothClientClass *klass)
@@ -861,11 +914,6 @@ static void bluetooth_client_class_init(
G_OBJECT_CLASS(klass)->set_property = bluetooth_client_set_property;
G_OBJECT_CLASS(klass)->get_property = bluetooth_client_get_property;
- store = gtk_tree_store_new(11, G_TYPE_STRING, G_TYPE_BOOLEAN,
- G_TYPE_OBJECT, G_TYPE_STRING, G_TYPE_UINT,
- G_TYPE_INT, G_TYPE_STRING, G_TYPE_UINT,
- G_TYPE_BOOLEAN, G_TYPE_BOOLEAN, G_TYPE_BOOLEAN);
-
client_table_signals[DISCOVERIES_COMPLETED] =
g_signal_new ("discoveries-completed",
G_TYPE_FROM_CLASS (klass),
@@ -876,35 +924,44 @@ static void bluetooth_client_class_init(
g_cclosure_marshal_VOID__VOID,
G_TYPE_NONE, 0, G_TYPE_NONE);
- setup_dbus();
+ 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);
- setup_manager();
+ dbus_g_object_register_marshaller(marshal_VOID__STRING_STRING,
+ G_TYPE_NONE, G_TYPE_STRING,
+ G_TYPE_STRING, G_TYPE_INVALID);
}
BluetoothClient *bluetooth_client_new(void)
{
- return BLUETOOTH_CLIENT(g_object_new(BLUETOOTH_TYPE_CLIENT, NULL));
+ if (self == NULL) {
+ self = BLUETOOTH_CLIENT(g_object_new(BLUETOOTH_TYPE_CLIENT, NULL));
+ return self;
+ } else {
+ return g_object_ref(self);
+ }
}
-gboolean bluetooth_client_register_passkey_agent(BluetoothClient *self,
+gboolean bluetooth_client_register_passkey_agent(BluetoothClient *client,
const char *path, const char *address, const void *info)
{
- BluetoothClientPrivate *priv = BLUETOOTH_CLIENT_GET_PRIVATE(self);
+ BluetoothClientPrivate *priv = BLUETOOTH_CLIENT_GET_PRIVATE(client);
DBusGProxy *proxy;
if (priv->registered == FALSE) {
dbus_g_object_type_install_info(BLUETOOTH_TYPE_CLIENT, info);
- dbus_g_connection_register_g_object(conn, path, G_OBJECT(self));
+ dbus_g_connection_register_g_object(priv->conn, path, G_OBJECT(client));
priv->registered = TRUE;
}
- if (default_adapter == NULL)
+ if (priv->default_adapter == NULL)
return FALSE;
- proxy = dbus_g_proxy_new_for_name(conn, "org.bluez",
- default_adapter, "org.bluez.Security");
+ proxy = dbus_g_proxy_new_for_name(priv->conn, "org.bluez",
+ priv->default_adapter, "org.bluez.Security");
security_register_passkey_agent(proxy, path, address, NULL);
@@ -919,25 +976,26 @@ static void create_bonding_reply(DBusGPr
//g_printf("create bonding reply\n");
}
-gboolean bluetooth_client_create_bonding(BluetoothClient *self,
+gboolean bluetooth_client_create_bonding(BluetoothClient *client,
gchar *adapter, const gchar *address)
{
+ BluetoothClientPrivate *priv = BLUETOOTH_CLIENT_GET_PRIVATE(client);
GtkTreeIter iter;
gboolean cont;
if (adapter == NULL)
- adapter = default_adapter;
+ adapter = priv->default_adapter;
if (adapter == NULL)
return FALSE;
- cont = gtk_tree_model_get_iter_first(GTK_TREE_MODEL(store), &iter);
+ cont = gtk_tree_model_get_iter_first(GTK_TREE_MODEL(priv->store), &iter);
while (cont == TRUE) {
DBusGProxy *object;
gchar *path;
- gtk_tree_model_get(GTK_TREE_MODEL(store), &iter,
+ gtk_tree_model_get(GTK_TREE_MODEL(priv->store), &iter,
COLUMN_PATH, &path,
COLUMN_OBJECT, &object, -1);
@@ -947,7 +1005,7 @@ gboolean bluetooth_client_create_bonding
return TRUE;
}
- cont = gtk_tree_model_iter_next(GTK_TREE_MODEL(store), &iter);
+ cont = gtk_tree_model_iter_next(GTK_TREE_MODEL(priv->store), &iter);
}
return FALSE;
@@ -959,25 +1017,26 @@ static void remove_bonding_reply(DBusGPr
//g_printf("remove bonding reply\n");
}
-gboolean bluetooth_client_remove_bonding(BluetoothClient *self,
+gboolean bluetooth_client_remove_bonding(BluetoothClient *client,
gchar *adapter, const gchar *address)
{
+ BluetoothClientPrivate *priv = BLUETOOTH_CLIENT_GET_PRIVATE(client);
GtkTreeIter iter;
gboolean cont;
if (adapter == NULL)
- adapter = default_adapter;
+ adapter = priv->default_adapter;
if (adapter == NULL)
return FALSE;
- cont = gtk_tree_model_get_iter_first(GTK_TREE_MODEL(store), &iter);
+ cont = gtk_tree_model_get_iter_first(GTK_TREE_MODEL(priv->store), &iter);
while (cont == TRUE) {
DBusGProxy *object;
gchar *path;
- gtk_tree_model_get(GTK_TREE_MODEL(store), &iter,
+ gtk_tree_model_get(GTK_TREE_MODEL(priv->store), &iter,
COLUMN_PATH, &path,
COLUMN_OBJECT, &object, -1);
@@ -987,7 +1046,7 @@ gboolean bluetooth_client_remove_bonding
return TRUE;
}
- cont = gtk_tree_model_iter_next(GTK_TREE_MODEL(store), &iter);
+ cont = gtk_tree_model_iter_next(GTK_TREE_MODEL(priv->store), &iter);
}
return FALSE;
@@ -999,25 +1058,26 @@ static void set_trusted_reply(DBusGProxy
//g_printf("set trusted reply\n");
}
-gboolean bluetooth_client_set_trusted(BluetoothClient *self,
+gboolean bluetooth_client_set_trusted(BluetoothClient *client,
gchar *adapter, const gchar *address)
{
+ BluetoothClientPrivate *priv = BLUETOOTH_CLIENT_GET_PRIVATE(client);
GtkTreeIter iter;
gboolean cont;
if (adapter == NULL)
- adapter = default_adapter;
+ adapter = priv->default_adapter;
if (adapter == NULL)
return FALSE;
- cont = gtk_tree_model_get_iter_first(GTK_TREE_MODEL(store), &iter);
+ cont = gtk_tree_model_get_iter_first(GTK_TREE_MODEL(priv->store), &iter);
while (cont == TRUE) {
DBusGProxy *object;
gchar *path;
- gtk_tree_model_get(GTK_TREE_MODEL(store), &iter,
+ gtk_tree_model_get(GTK_TREE_MODEL(priv->store), &iter,
COLUMN_PATH, &path,
COLUMN_OBJECT, &object, -1);
@@ -1027,7 +1087,7 @@ gboolean bluetooth_client_set_trusted(Bl
return TRUE;
}
- cont = gtk_tree_model_iter_next(GTK_TREE_MODEL(store), &iter);
+ cont = gtk_tree_model_iter_next(GTK_TREE_MODEL(priv->store), &iter);
}
return FALSE;
@@ -1039,25 +1099,26 @@ static void remove_trust_reply(DBusGProx
//g_printf("remove trust reply\n");
}
-gboolean bluetooth_client_remove_trust(BluetoothClient *self,
+gboolean bluetooth_client_remove_trust(BluetoothClient *client,
gchar *adapter, const gchar *address)
{
+ BluetoothClientPrivate *priv = BLUETOOTH_CLIENT_GET_PRIVATE(client);
GtkTreeIter iter;
gboolean cont;
if (adapter == NULL)
- adapter = default_adapter;
+ adapter = priv->default_adapter;
if (adapter == NULL)
return FALSE;
- cont = gtk_tree_model_get_iter_first(GTK_TREE_MODEL(store), &iter);
+ cont = gtk_tree_model_get_iter_first(GTK_TREE_MODEL(priv->store), &iter);
while (cont == TRUE) {
DBusGProxy *object;
gchar *path;
- gtk_tree_model_get(GTK_TREE_MODEL(store), &iter,
+ gtk_tree_model_get(GTK_TREE_MODEL(priv->store), &iter,
COLUMN_PATH, &path,
COLUMN_OBJECT, &object, -1);
@@ -1067,7 +1128,7 @@ gboolean bluetooth_client_remove_trust(B
return TRUE;
}
- cont = gtk_tree_model_iter_next(GTK_TREE_MODEL(store), &iter);
+ cont = gtk_tree_model_iter_next(GTK_TREE_MODEL(priv->store), &iter);
}
return FALSE;
@@ -1079,25 +1140,26 @@ static void disconnect_remote_device_rep
//g_printf("disconnect remote device reply\n");
}
-gboolean bluetooth_client_disconnect(BluetoothClient *self,
+gboolean bluetooth_client_disconnect(BluetoothClient *client,
gchar *adapter, const gchar *address)
{
+ BluetoothClientPrivate *priv = BLUETOOTH_CLIENT_GET_PRIVATE(client);
GtkTreeIter iter;
gboolean cont;
if (adapter == NULL)
- adapter = default_adapter;
+ adapter = priv->default_adapter;
if (adapter == NULL)
return FALSE;
- cont = gtk_tree_model_get_iter_first(GTK_TREE_MODEL(store), &iter);
+ cont = gtk_tree_model_get_iter_first(GTK_TREE_MODEL(priv->store), &iter);
while (cont == TRUE) {
DBusGProxy *object;
gchar *path;
- gtk_tree_model_get(GTK_TREE_MODEL(store), &iter,
+ gtk_tree_model_get(GTK_TREE_MODEL(priv->store), &iter,
COLUMN_PATH, &path,
COLUMN_OBJECT, &object, -1);
@@ -1107,71 +1169,74 @@ gboolean bluetooth_client_disconnect(Blu
return TRUE;
}
- cont = gtk_tree_model_iter_next(GTK_TREE_MODEL(store), &iter);
+ cont = gtk_tree_model_iter_next(GTK_TREE_MODEL(priv->store), &iter);
}
return FALSE;
}
-gboolean bluetooth_client_discover_devices(BluetoothClient *self, gchar *adapter)
+gboolean bluetooth_client_discover_devices(BluetoothClient *client, gchar *adapter)
{
+ BluetoothClientPrivate *priv = BLUETOOTH_CLIENT_GET_PRIVATE(client);
GtkTreeIter iter;
gboolean cont;
if (adapter == NULL)
- adapter = default_adapter;
+ adapter = priv->default_adapter;
if (adapter == NULL)
return FALSE;
- cont = gtk_tree_model_get_iter_first(GTK_TREE_MODEL(store), &iter);
+ cont = gtk_tree_model_get_iter_first(GTK_TREE_MODEL(priv->store), &iter);
while (cont == TRUE) {
DBusGProxy *object;
gchar *path;
- gtk_tree_model_get(GTK_TREE_MODEL(store), &iter,
+ gtk_tree_model_get(GTK_TREE_MODEL(priv->store), &iter,
COLUMN_PATH, &path,
COLUMN_OBJECT, &object, -1);
if (g_ascii_strcasecmp(path, adapter) == 0) {
+#if 0
/* Disconnect any lingering signals, to avoid the callback
* being called twice */
dbus_g_proxy_disconnect_signal(object, "DiscoveryCompleted",
- G_CALLBACK(discovery_completed), self);
+ G_CALLBACK(discovery_completed), client);
dbus_g_proxy_connect_signal(object, "DiscoveryCompleted",
- G_CALLBACK(discovery_completed), self, NULL);
+ G_CALLBACK(discovery_completed), client, NULL);
dbus_g_proxy_call(object, "DiscoverDevices",
NULL, G_TYPE_INVALID);
-
+#endif
return TRUE;
}
- cont = gtk_tree_model_iter_next(GTK_TREE_MODEL(store), &iter);
+ cont = gtk_tree_model_iter_next(GTK_TREE_MODEL(priv->store), &iter);
}
return FALSE;
}
-gboolean bluetooth_client_cancel_discovery(BluetoothClient *self, gchar *adapter)
+gboolean bluetooth_client_cancel_discovery(BluetoothClient *client, gchar *adapter)
{
+ BluetoothClientPrivate *priv = BLUETOOTH_CLIENT_GET_PRIVATE(client);
GtkTreeIter iter;
gboolean cont;
if (adapter == NULL)
- adapter = default_adapter;
+ adapter = priv->default_adapter;
if (adapter == NULL)
return FALSE;
- cont = gtk_tree_model_get_iter_first(GTK_TREE_MODEL(store), &iter);
+ cont = gtk_tree_model_get_iter_first(GTK_TREE_MODEL(priv->store), &iter);
while (cont == TRUE) {
DBusGProxy *object;
gchar *path;
- gtk_tree_model_get(GTK_TREE_MODEL(store), &iter,
+ gtk_tree_model_get(GTK_TREE_MODEL(priv->store), &iter,
COLUMN_PATH, &path,
COLUMN_OBJECT, &object, -1);
@@ -1181,26 +1246,29 @@ gboolean bluetooth_client_cancel_discove
return TRUE;
}
- cont = gtk_tree_model_iter_next(GTK_TREE_MODEL(store), &iter);
+ cont = gtk_tree_model_iter_next(GTK_TREE_MODEL(priv->store), &iter);
}
return FALSE;
}
-GtkTreeModel *bluetooth_client_get_model(BluetoothClient *self)
+GtkTreeModel *bluetooth_client_get_model(BluetoothClient *client)
{
- g_object_ref(store);
+ BluetoothClientPrivate *priv = BLUETOOTH_CLIENT_GET_PRIVATE(client);
+
+ g_object_ref(priv->store);
- return GTK_TREE_MODEL(store);
+ return GTK_TREE_MODEL(priv->store);
}
-GtkTreeModel *bluetooth_client_get_model_simple(BluetoothClient *self)
+GtkTreeModel *bluetooth_client_get_model_simple(BluetoothClient *client)
{
+ BluetoothClientPrivate *priv = BLUETOOTH_CLIENT_GET_PRIVATE(client);
GtkTreeModel *model;
GtkTreeIter iter;
gboolean cont;
- model = gtk_tree_model_filter_new(GTK_TREE_MODEL(store), NULL);
+ model = gtk_tree_model_filter_new(GTK_TREE_MODEL(priv->store), NULL);
gtk_tree_model_filter_set_visible_column(GTK_TREE_MODEL_FILTER(model),
COLUMN_ACTIVE);
@@ -1208,29 +1276,29 @@ GtkTreeModel *bluetooth_client_get_model
if (gtk_tree_model_iter_n_children(model, NULL) != 1)
return model;
- cont = gtk_tree_model_get_iter_first(GTK_TREE_MODEL(store), &iter);
+ cont = gtk_tree_model_get_iter_first(GTK_TREE_MODEL(priv->store), &iter);
while (cont == TRUE) {
gboolean active;
- gtk_tree_model_get(GTK_TREE_MODEL(store), &iter,
+ gtk_tree_model_get(GTK_TREE_MODEL(priv->store), &iter,
COLUMN_ACTIVE, &active, -1);
if (active == TRUE) {
GtkTreePath *path;
- path = gtk_tree_model_get_path(GTK_TREE_MODEL(store), &iter);
+ path = gtk_tree_model_get_path(GTK_TREE_MODEL(priv->store), &iter);
g_object_unref(model);
- model = gtk_tree_model_filter_new(GTK_TREE_MODEL(store), path);
+ model = gtk_tree_model_filter_new(GTK_TREE_MODEL(priv->store), path);
gtk_tree_path_free(path);
break;
}
- cont = gtk_tree_model_iter_next(GTK_TREE_MODEL(store), &iter);
+ cont = gtk_tree_model_iter_next(GTK_TREE_MODEL(priv->store), &iter);
}
return model;
@@ -1253,11 +1321,12 @@ static gboolean adapter_list_filter(GtkT
return active;
}
-GtkTreeModel *bluetooth_client_get_model_adapter_list(BluetoothClient *self)
+GtkTreeModel *bluetooth_client_get_model_adapter_list(BluetoothClient *client)
{
+ BluetoothClientPrivate *priv = BLUETOOTH_CLIENT_GET_PRIVATE(client);
GtkTreeModel *model;
- model = gtk_tree_model_filter_new(GTK_TREE_MODEL(store), NULL);
+ model = gtk_tree_model_filter_new(GTK_TREE_MODEL(priv->store), NULL);
gtk_tree_model_filter_set_visible_func(GTK_TREE_MODEL_FILTER(model),
adapter_list_filter, NULL, NULL);
@@ -1275,33 +1344,34 @@ static gboolean device_active_filter(Gtk
return active;
}
-GtkTreeModel *bluetooth_client_get_model_for_adapter(BluetoothClient *self,
+GtkTreeModel *bluetooth_client_get_model_for_adapter(BluetoothClient *client,
gchar *adapter)
{
+ BluetoothClientPrivate *priv = BLUETOOTH_CLIENT_GET_PRIVATE(client);
GtkTreeModel *model;
GtkTreeIter iter;
gboolean cont;
if (adapter == NULL)
- adapter = default_adapter;
+ adapter = priv->default_adapter;
if (adapter == NULL)
return NULL;
- cont = gtk_tree_model_get_iter_first(GTK_TREE_MODEL(store), &iter);
+ cont = gtk_tree_model_get_iter_first(GTK_TREE_MODEL(priv->store), &iter);
while (cont == TRUE) {
gchar *path;
- gtk_tree_model_get(GTK_TREE_MODEL(store), &iter,
+ gtk_tree_model_get(GTK_TREE_MODEL(priv->store), &iter,
COLUMN_PATH, &path, -1);
if (g_ascii_strcasecmp(path, adapter) == 0) {
GtkTreePath *path;
- path = gtk_tree_model_get_path(GTK_TREE_MODEL(store), &iter);
+ path = gtk_tree_model_get_path(GTK_TREE_MODEL(priv->store), &iter);
- model = gtk_tree_model_filter_new(GTK_TREE_MODEL(store), path);
+ model = gtk_tree_model_filter_new(GTK_TREE_MODEL(priv->store), path);
gtk_tree_model_filter_set_visible_func(GTK_TREE_MODEL_FILTER(model),
device_active_filter, NULL, NULL);
@@ -1311,40 +1381,41 @@ GtkTreeModel *bluetooth_client_get_model
return model;
}
- cont = gtk_tree_model_iter_next(GTK_TREE_MODEL(store), &iter);
+ cont = gtk_tree_model_iter_next(GTK_TREE_MODEL(priv->store), &iter);
}
return NULL;
}
-GtkTreeModel *bluetooth_client_get_model_with_filter(BluetoothClient *self,
+GtkTreeModel *bluetooth_client_get_model_with_filter(BluetoothClient *client,
gchar *adapter, GtkTreeModelFilterVisibleFunc func,
gpointer data)
{
+ BluetoothClientPrivate *priv = BLUETOOTH_CLIENT_GET_PRIVATE(client);
GtkTreeModel *model;
GtkTreeIter iter;
gboolean cont;
if (adapter == NULL)
- adapter = default_adapter;
+ adapter = priv->default_adapter;
if (adapter == NULL)
return NULL;
- cont = gtk_tree_model_get_iter_first(GTK_TREE_MODEL(store), &iter);
+ cont = gtk_tree_model_get_iter_first(GTK_TREE_MODEL(priv->store), &iter);
while (cont == TRUE) {
gchar *path;
- gtk_tree_model_get(GTK_TREE_MODEL(store), &iter,
+ gtk_tree_model_get(GTK_TREE_MODEL(priv->store), &iter,
COLUMN_PATH, &path, -1);
if (g_ascii_strcasecmp(path, adapter) == 0) {
GtkTreePath *path;
- path = gtk_tree_model_get_path(GTK_TREE_MODEL(store), &iter);
+ path = gtk_tree_model_get_path(GTK_TREE_MODEL(priv->store), &iter);
- model = gtk_tree_model_filter_new(GTK_TREE_MODEL(store), path);
+ model = gtk_tree_model_filter_new(GTK_TREE_MODEL(priv->store), path);
if (func != NULL)
gtk_tree_model_filter_set_visible_func(GTK_TREE_MODEL_FILTER(model),
@@ -1355,7 +1426,7 @@ GtkTreeModel *bluetooth_client_get_model
return model;
}
- cont = gtk_tree_model_iter_next(GTK_TREE_MODEL(store), &iter);
+ cont = gtk_tree_model_iter_next(GTK_TREE_MODEL(priv->store), &iter);
}
return NULL;
@@ -1374,9 +1445,9 @@ static gboolean device_bonded_filter(Gtk
connected == TRUE) ? TRUE : FALSE;
}
-GtkTreeModel *bluetooth_client_get_model_bonded_list(BluetoothClient *self,
+GtkTreeModel *bluetooth_client_get_model_bonded_list(BluetoothClient *client,
gchar *adapter)
{
- return bluetooth_client_get_model_with_filter(self, adapter,
+ return bluetooth_client_get_model_with_filter(client, adapter,
device_bonded_filter, NULL);
}
[-- Attachment #3: Type: text/plain, Size: 228 bytes --]
-------------------------------------------------------------------------
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2008.
http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
[-- Attachment #4: Type: text/plain, Size: 164 bytes --]
_______________________________________________
Bluez-devel mailing list
Bluez-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/bluez-devel
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [Bluez-devel] [PATCH] client.c cleanup
2008-01-25 2:22 [Bluez-devel] [PATCH] client.c cleanup Bastien Nocera
@ 2008-01-29 17:01 ` Marcel Holtmann
2008-01-29 17:24 ` Bastien Nocera
2008-01-30 17:31 ` Bastien Nocera
0 siblings, 2 replies; 12+ messages in thread
From: Marcel Holtmann @ 2008-01-29 17:01 UTC (permalink / raw)
To: BlueZ development
Hi Bastien,
> Some time ago I had problems with client.c's architecture. It would
> allow me to easily report completed discoveries without causing crashes.
>
> The attached patch moves all the static variables into the main
> BluetoothClient object, and instead of return a new object when using
> _new() we return an existing instance of the client.
>
> This makes no changes to the external API for the BluetoothClient, and
> should work just as well as older versions did.
patch has been applied. Don't really see the difference, but I am okay
with doing it this way.
> A couple of bugs I found in client.c:
> - launch test-client with a dongle inserted, remove and reinsert the
> dongle, the bdaddr of the device is not set anymore
> - launch test-client without a dongle inserted, insert it, the bdaddr is
> not set and there's no children to the adapter (although there are if
> inserted when started)
> - launch test-client with a dongle inserted, remove it, add another one,
> the set of known devices underneath hasn't changed
>
> All those problems exist in the old version of client.c, and I intend on
> fixing them, as well as making the search button work as expected in the
> device selection widget.
Send patches when you figured it out :)
Regards
Marcel
-------------------------------------------------------------------------
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2008.
http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
_______________________________________________
Bluez-devel mailing list
Bluez-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/bluez-devel
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [Bluez-devel] [PATCH] client.c cleanup
2008-01-29 17:01 ` Marcel Holtmann
@ 2008-01-29 17:24 ` Bastien Nocera
2008-01-29 17:35 ` Marcel Holtmann
2008-01-30 17:31 ` Bastien Nocera
1 sibling, 1 reply; 12+ messages in thread
From: Bastien Nocera @ 2008-01-29 17:24 UTC (permalink / raw)
To: BlueZ development
On Tue, 2008-01-29 at 18:01 +0100, Marcel Holtmann wrote:
> Hi Bastien,
>
> > Some time ago I had problems with client.c's architecture. It would
> > allow me to easily report completed discoveries without causing crashes.
> >
> > The attached patch moves all the static variables into the main
> > BluetoothClient object, and instead of return a new object when using
> > _new() we return an existing instance of the client.
> >
> > This makes no changes to the external API for the BluetoothClient, and
> > should work just as well as older versions did.
>
> patch has been applied. Don't really see the difference, but I am okay
> with doing it this way.
There's no differences in terms of the outside API, but it allows the
signals coming back from hcid to have a reference to a BluetoothClient
object and thus sending out signals, etc.
> > A couple of bugs I found in client.c:
> > - launch test-client with a dongle inserted, remove and reinsert the
> > dongle, the bdaddr of the device is not set anymore
> > - launch test-client without a dongle inserted, insert it, the bdaddr is
> > not set and there's no children to the adapter (although there are if
> > inserted when started)
> > - launch test-client with a dongle inserted, remove it, add another one,
> > the set of known devices underneath hasn't changed
> >
> > All those problems exist in the old version of client.c, and I intend on
> > fixing them, as well as making the search button work as expected in the
> > device selection widget.
>
> Send patches when you figured it out :)
I think for most of those it would mean clearing the children of the
adapters (removing them from the tree). Not sure what's wrong about the
bdaddr not appearing for newly inserted devices though, probably just a
missing call.
Cheers
-------------------------------------------------------------------------
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2008.
http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
_______________________________________________
Bluez-devel mailing list
Bluez-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/bluez-devel
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [Bluez-devel] [PATCH] client.c cleanup
2008-01-29 17:24 ` Bastien Nocera
@ 2008-01-29 17:35 ` Marcel Holtmann
2008-01-29 18:08 ` Bastien Nocera
0 siblings, 1 reply; 12+ messages in thread
From: Marcel Holtmann @ 2008-01-29 17:35 UTC (permalink / raw)
To: BlueZ development
Hi Bastien,
> > > A couple of bugs I found in client.c:
> > > - launch test-client with a dongle inserted, remove and reinsert the
> > > dongle, the bdaddr of the device is not set anymore
> > > - launch test-client without a dongle inserted, insert it, the bdaddr is
> > > not set and there's no children to the adapter (although there are if
> > > inserted when started)
> > > - launch test-client with a dongle inserted, remove it, add another one,
> > > the set of known devices underneath hasn't changed
> > >
> > > All those problems exist in the old version of client.c, and I intend on
> > > fixing them, as well as making the search button work as expected in the
> > > device selection widget.
> >
> > Send patches when you figured it out :)
>
> I think for most of those it would mean clearing the children of the
> adapters (removing them from the tree). Not sure what's wrong about the
> bdaddr not appearing for newly inserted devices though, probably just a
> missing call.
that is a bug or missing signal. Keeping the adapter allows us to keep
the D-Bus proxy object and will prevent from duplicate signals. Removing
the adapter would mean to also remove the signal handles etc. Seemed why
to ugly for me.
Regards
Marcel
-------------------------------------------------------------------------
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2008.
http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
_______________________________________________
Bluez-devel mailing list
Bluez-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/bluez-devel
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [Bluez-devel] [PATCH] client.c cleanup
2008-01-29 17:35 ` Marcel Holtmann
@ 2008-01-29 18:08 ` Bastien Nocera
2008-01-29 18:14 ` Marcel Holtmann
0 siblings, 1 reply; 12+ messages in thread
From: Bastien Nocera @ 2008-01-29 18:08 UTC (permalink / raw)
To: BlueZ development
On Tue, 2008-01-29 at 18:35 +0100, Marcel Holtmann wrote:
> Hi Bastien,
>
> > > > A couple of bugs I found in client.c:
> > > > - launch test-client with a dongle inserted, remove and reinsert the
> > > > dongle, the bdaddr of the device is not set anymore
> > > > - launch test-client without a dongle inserted, insert it, the bdaddr is
> > > > not set and there's no children to the adapter (although there are if
> > > > inserted when started)
> > > > - launch test-client with a dongle inserted, remove it, add another one,
> > > > the set of known devices underneath hasn't changed
> > > >
> > > > All those problems exist in the old version of client.c, and I intend on
> > > > fixing them, as well as making the search button work as expected in the
> > > > device selection widget.
> > >
> > > Send patches when you figured it out :)
> >
> > I think for most of those it would mean clearing the children of the
> > adapters (removing them from the tree). Not sure what's wrong about the
> > bdaddr not appearing for newly inserted devices though, probably just a
> > missing call.
>
> that is a bug or missing signal. Keeping the adapter allows us to keep
> the D-Bus proxy object and will prevent from duplicate signals. Removing
> the adapter would mean to also remove the signal handles etc. Seemed why
> to ugly for me.
I'm talking about removing the children (ie. the devices), not the
adapter itself. Which makes sense, as they shouldn't be associated with
a non-existant adapter.
-------------------------------------------------------------------------
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2008.
http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
_______________________________________________
Bluez-devel mailing list
Bluez-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/bluez-devel
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [Bluez-devel] [PATCH] client.c cleanup
2008-01-29 18:08 ` Bastien Nocera
@ 2008-01-29 18:14 ` Marcel Holtmann
0 siblings, 0 replies; 12+ messages in thread
From: Marcel Holtmann @ 2008-01-29 18:14 UTC (permalink / raw)
To: BlueZ development
Hi Bastien,
> > > I think for most of those it would mean clearing the children of the
> > > adapters (removing them from the tree). Not sure what's wrong about the
> > > bdaddr not appearing for newly inserted devices though, probably just a
> > > missing call.
> >
> > that is a bug or missing signal. Keeping the adapter allows us to keep
> > the D-Bus proxy object and will prevent from duplicate signals. Removing
> > the adapter would mean to also remove the signal handles etc. Seemed why
> > to ugly for me.
>
> I'm talking about removing the children (ie. the devices), not the
> adapter itself. Which makes sense, as they shouldn't be associated with
> a non-existant adapter.
we can do that. Makes sense to me. Purge all children on adapter
removal.
Regards
Marcel
-------------------------------------------------------------------------
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2008.
http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
_______________________________________________
Bluez-devel mailing list
Bluez-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/bluez-devel
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [Bluez-devel] [PATCH] client.c cleanup
2008-01-29 17:01 ` Marcel Holtmann
2008-01-29 17:24 ` Bastien Nocera
@ 2008-01-30 17:31 ` Bastien Nocera
2008-01-31 14:57 ` Bastien Nocera
1 sibling, 1 reply; 12+ messages in thread
From: Bastien Nocera @ 2008-01-30 17:31 UTC (permalink / raw)
To: BlueZ development
On Tue, 2008-01-29 at 18:01 +0100, Marcel Holtmann wrote:
> Hi Bastien,
>
> > Some time ago I had problems with client.c's architecture. It would
> > allow me to easily report completed discoveries without causing crashes.
> >
> > The attached patch moves all the static variables into the main
> > BluetoothClient object, and instead of return a new object when using
> > _new() we return an existing instance of the client.
> >
> > This makes no changes to the external API for the BluetoothClient, and
> > should work just as well as older versions did.
>
> patch has been applied. Don't really see the difference, but I am okay
> with doing it this way.
>
> > A couple of bugs I found in client.c:
> > - launch test-client with a dongle inserted, remove and reinsert the
> > dongle, the bdaddr of the device is not set anymore
> > - launch test-client without a dongle inserted, insert it, the bdaddr is
> > not set and there's no children to the adapter (although there are if
> > inserted when started)
Both of those are a race:
When the AdapterAdded signal is launched in hcid, the address isn't
available yet. It is available when "ModeChanged" has been launched
though.
hcid_dbus_register_device() setups the structures, and launched
AdapterAdded, but the address is only set when hcid_dbus_start_device()
is called (and the ModeChanged signal is launched).
How do you think we should be handling that? I would think we should
make GetAddress fail if the data isn't available yet, or hack around it
in client.c and only setup the adapters when the mode changes.
Cheers
-------------------------------------------------------------------------
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2008.
http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
_______________________________________________
Bluez-devel mailing list
Bluez-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/bluez-devel
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [Bluez-devel] [PATCH] client.c cleanup
2008-01-30 17:31 ` Bastien Nocera
@ 2008-01-31 14:57 ` Bastien Nocera
2008-01-31 17:48 ` Bastien Nocera
0 siblings, 1 reply; 12+ messages in thread
From: Bastien Nocera @ 2008-01-31 14:57 UTC (permalink / raw)
To: BlueZ development
[-- Attachment #1: Type: text/plain, Size: 2028 bytes --]
On Wed, 2008-01-30 at 17:31 +0000, Bastien Nocera wrote:
> On Tue, 2008-01-29 at 18:01 +0100, Marcel Holtmann wrote:
> > Hi Bastien,
> >
> > > Some time ago I had problems with client.c's architecture. It would
> > > allow me to easily report completed discoveries without causing crashes.
> > >
> > > The attached patch moves all the static variables into the main
> > > BluetoothClient object, and instead of return a new object when using
> > > _new() we return an existing instance of the client.
> > >
> > > This makes no changes to the external API for the BluetoothClient, and
> > > should work just as well as older versions did.
> >
> > patch has been applied. Don't really see the difference, but I am okay
> > with doing it this way.
> >
> > > A couple of bugs I found in client.c:
> > > - launch test-client with a dongle inserted, remove and reinsert the
> > > dongle, the bdaddr of the device is not set anymore
> > > - launch test-client without a dongle inserted, insert it, the bdaddr is
> > > not set and there's no children to the adapter (although there are if
> > > inserted when started)
>
> Both of those are a race:
> When the AdapterAdded signal is launched in hcid, the address isn't
> available yet. It is available when "ModeChanged" has been launched
> though.
>
> hcid_dbus_register_device() setups the structures, and launched
> AdapterAdded, but the address is only set when hcid_dbus_start_device()
> is called (and the ModeChanged signal is launched).
>
> How do you think we should be handling that? I would think we should
> make GetAddress fail if the data isn't available yet, or hack around it
> in client.c and only setup the adapters when the mode changes.
The easy fix for hcid attached (the default bdaddr should be
00:00:00:00:00:00:00, not an empty string).
And also a patch for client.c to get the device address again when the
device changes mode, so we can change it in the tree from the default
all-zeros address to the real one.
I'll fix the other bugs now.
Cheers
[-- Attachment #2: bluez-utils-hcid-set-default-address.patch --]
[-- Type: text/x-patch, Size: 542 bytes --]
Index: dbus-hci.c
===================================================================
RCS file: /cvsroot/bluez/utils/hcid/dbus-hci.c,v
retrieving revision 1.35
diff -u -p -r1.35 dbus-hci.c
--- dbus-hci.c 28 Jan 2008 10:38:40 -0000 1.35
+++ dbus-hci.c 31 Jan 2008 14:41:40 -0000
@@ -477,6 +477,7 @@ int hcid_dbus_register_device(uint16_t i
adapter->dev_id = id;
adapter->pdiscov_resolve_names = 1;
+ strcpy(adapter->address, "00:00:00:00:00:00:00");
if (!dbus_connection_create_object_path(connection, path, adapter,
NULL)) {
[-- Attachment #3: bluez-gnome-update-bdaddr.patch --]
[-- Type: text/x-patch, Size: 1442 bytes --]
Index: client.c
===================================================================
RCS file: /cvsroot/bluez/gnome/common/client.c,v
retrieving revision 1.37
diff -u -p -r1.37 client.c
--- client.c 29 Jan 2008 17:00:58 -0000 1.37
+++ client.c 31 Jan 2008 14:56:56 -0000
@@ -60,6 +60,8 @@ static int client_table_signals[LAST_SIG
G_DEFINE_TYPE(BluetoothClient, bluetooth_client, G_TYPE_OBJECT)
+static void update_adapter(DBusGProxy *object, GtkTreeIter *iter, BluetoothClient *client);
+
static gboolean find_iter_for_object(DBusGProxy *object,
BluetoothClient *client,
GtkTreeIter *iter)
@@ -87,6 +89,29 @@ static gboolean find_iter_for_object(DBu
static void mode_changed(DBusGProxy *object,
const char *mode, gpointer user_data)
{
+ BluetoothClient *client = (BluetoothClient *) user_data;
+ BluetoothClientPrivate *priv = BLUETOOTH_CLIENT_GET_PRIVATE(client);
+ GtkTreeIter iter;
+ gboolean cont;
+
+ cont = gtk_tree_model_get_iter_first(GTK_TREE_MODEL(priv->store), &iter);
+
+ while (cont == TRUE) {
+ DBusGProxy *o;
+
+ gtk_tree_model_get(GTK_TREE_MODEL(priv->store), &iter,
+ COLUMN_OBJECT, &o, -1);
+
+ if (object == o) {
+ gtk_tree_store_set(priv->store, &iter,
+ COLUMN_ACTIVE, TRUE, -1);
+ update_adapter(object, &iter, client);
+
+ return;
+ }
+
+ cont = gtk_tree_model_iter_next(GTK_TREE_MODEL(priv->store), &iter);
+ }
}
static void timeout_changed(DBusGProxy *object,
[-- Attachment #4: Type: text/plain, Size: 228 bytes --]
-------------------------------------------------------------------------
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2008.
http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
[-- Attachment #5: Type: text/plain, Size: 164 bytes --]
_______________________________________________
Bluez-devel mailing list
Bluez-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/bluez-devel
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [Bluez-devel] [PATCH] client.c cleanup
2008-01-31 14:57 ` Bastien Nocera
@ 2008-01-31 17:48 ` Bastien Nocera
2008-02-01 10:46 ` Bastien Nocera
0 siblings, 1 reply; 12+ messages in thread
From: Bastien Nocera @ 2008-01-31 17:48 UTC (permalink / raw)
To: BlueZ development
[-- Attachment #1: Type: text/plain, Size: 982 bytes --]
On Thu, 2008-01-31 at 14:57 +0000, Bastien Nocera wrote:
<snip>
> And also a patch for client.c to get the device address again when the
> device changes mode, so we can change it in the tree from the default
> all-zeros address to the real one.
>
> I'll fix the other bugs now.
Does the above without the forward declaration, plus:
- add the "default-adapter" property, and property changes notification
- listen to default-adapter changes in the selection widget, and change
the tree model if it changes (so we only show the devices for the
current default)
- remove devices from the list when an adapter is removed, so they don't
appear in the treeview
- show "unknown" in the treeview when a device is of unknown type
It fixes all the UI problems I mentioned in the original e-mail. Next up
would be making the search button work.
About the hcid bug, should GetInfo fail when the bdaddr for the device
isn't available, or should it just give out empty information?
Cheers
[-- Attachment #2: bluez-gnome-fix-multi-adapters.patch --]
[-- Type: text/x-patch, Size: 9708 bytes --]
Index: bluetooth-device-selection.c
===================================================================
RCS file: /cvsroot/bluez/gnome/common/bluetooth-device-selection.c,v
retrieving revision 1.11
diff -u -p -r1.11 bluetooth-device-selection.c
--- bluetooth-device-selection.c 29 Jan 2008 17:03:22 -0000 1.11
+++ bluetooth-device-selection.c 31 Jan 2008 17:29:00 -0000
@@ -54,6 +54,7 @@ struct _BluetoothDeviceSelectionPrivate
/* Widgets/UI bits that can be shown or hidden */
GtkCellRenderer *bonded_cell;
+ GtkWidget *treeview;
GtkWidget *search_button;
GtkWidget *device_type_label, *device_type;
GtkWidget *device_category_label, *device_category;
@@ -171,8 +172,10 @@ type_to_text (GtkTreeViewColumn *column,
guint type;
gtk_tree_model_get (model, iter, COLUMN_TYPE, &type, -1);
-
- g_object_set (cell, "text", bluetooth_type_to_string (type), NULL);
+ if (type == BLUETOOTH_TYPE_ANY)
+ g_object_set (cell, "text", _("Unknown"), NULL);
+ else
+ g_object_set (cell, "text", bluetooth_type_to_string (type), NULL);
}
void
@@ -283,7 +286,8 @@ filter_type_changed_cb (GtkComboBox *wid
BluetoothDeviceSelectionPrivate *priv = BLUETOOTH_DEVICE_SELECTION_GET_PRIVATE(self);
priv->device_type_filter = gtk_combo_box_get_active (GTK_COMBO_BOX(priv->device_type));
- gtk_tree_model_filter_refilter (GTK_TREE_MODEL_FILTER (priv->filter));
+ if (priv->filter)
+ gtk_tree_model_filter_refilter (GTK_TREE_MODEL_FILTER (priv->filter));
g_object_notify (G_OBJECT(self), "device-type-filter");
}
static void
@@ -293,10 +297,40 @@ filter_category_changed_cb (GtkComboBox
BluetoothDeviceSelectionPrivate *priv = BLUETOOTH_DEVICE_SELECTION_GET_PRIVATE(self);
priv->device_category_filter = gtk_combo_box_get_active (GTK_COMBO_BOX(priv->device_category));
- gtk_tree_model_filter_refilter (GTK_TREE_MODEL_FILTER (priv->filter));
+ if (priv->filter)
+ gtk_tree_model_filter_refilter (GTK_TREE_MODEL_FILTER (priv->filter));
g_object_notify (G_OBJECT(self), "device-category-filter");
}
+static void default_adapter_changed (GObject *gobject,
+ GParamSpec *arg1,
+ gpointer data)
+{
+ BluetoothDeviceSelection *self = BLUETOOTH_DEVICE_SELECTION (data);
+ BluetoothDeviceSelectionPrivate *priv = BLUETOOTH_DEVICE_SELECTION_GET_PRIVATE(self);
+ char *adapter;
+
+ g_object_get (gobject, "default-adapter", &adapter, NULL);
+
+ if (adapter == NULL)
+ gtk_tree_view_set_model (GTK_TREE_VIEW(priv->treeview), NULL);
+
+ if (priv->model)
+ g_object_unref (priv->model);
+
+ if (adapter == NULL)
+ return;
+
+ priv->model = bluetooth_client_get_model_with_filter (priv->client, NULL, NULL, NULL);
+ if (priv->model) {
+ priv->filter = gtk_tree_model_filter_new (priv->model, NULL);
+ gtk_tree_model_filter_set_visible_func (GTK_TREE_MODEL_FILTER (priv->filter),
+ filter_func, self, NULL);
+ gtk_tree_view_set_model (GTK_TREE_VIEW(priv->treeview), priv->filter);
+ g_object_unref (priv->filter);
+ }
+}
+
static GtkWidget *
create_treeview (BluetoothDeviceSelection *self)
{
@@ -370,13 +404,12 @@ create_treeview (BluetoothDeviceSelectio
priv->filter = gtk_tree_model_filter_new (priv->model, NULL);
gtk_tree_model_filter_set_visible_func (GTK_TREE_MODEL_FILTER (priv->filter),
filter_func, self, NULL);
- }
- if (priv->model) {
gtk_tree_view_set_model (GTK_TREE_VIEW(tree), priv->filter);
g_object_unref (priv->filter);
}
gtk_container_add (GTK_CONTAINER(scrolled), tree);
+ priv->treeview = tree;
return scrolled;
}
@@ -537,6 +570,9 @@ bluetooth_device_selection_init(Bluetoot
gtk_widget_show (priv->device_type);
}
+ g_signal_connect (priv->client, "notify::default-adapter",
+ G_CALLBACK (default_adapter_changed), self);
+
bluetooth_device_selection_start_discovery (self);
}
Index: client.c
===================================================================
RCS file: /cvsroot/bluez/gnome/common/client.c,v
retrieving revision 1.37
diff -u -p -r1.37 client.c
--- client.c 29 Jan 2008 17:00:58 -0000 1.37
+++ client.c 31 Jan 2008 17:29:00 -0000
@@ -56,10 +56,17 @@ enum {
LAST_SIGNAL
};
+enum {
+ PROP_0,
+ PROP_DEFAULT_ADAPTER
+};
+
static int client_table_signals[LAST_SIGNAL] = { 0 };
G_DEFINE_TYPE(BluetoothClient, bluetooth_client, G_TYPE_OBJECT)
+static void update_adapter(DBusGProxy *object, GtkTreeIter *iter, BluetoothClient *client);
+
static gboolean find_iter_for_object(DBusGProxy *object,
BluetoothClient *client,
GtkTreeIter *iter)
@@ -84,11 +91,6 @@ static gboolean find_iter_for_object(DBu
return FALSE;
}
-static void mode_changed(DBusGProxy *object,
- const char *mode, gpointer user_data)
-{
-}
-
static void timeout_changed(DBusGProxy *object,
const guint32 timeout, gpointer user_data)
{
@@ -596,6 +598,34 @@ failover:
g_error_free(error);
}
+static void mode_changed(DBusGProxy *object,
+ const char *mode, gpointer user_data)
+{
+ BluetoothClient *client = (BluetoothClient *) user_data;
+ BluetoothClientPrivate *priv = BLUETOOTH_CLIENT_GET_PRIVATE(client);
+ GtkTreeIter iter;
+ gboolean cont;
+
+ cont = gtk_tree_model_get_iter_first(GTK_TREE_MODEL(priv->store), &iter);
+
+ while (cont == TRUE) {
+ DBusGProxy *o;
+
+ gtk_tree_model_get(GTK_TREE_MODEL(priv->store), &iter,
+ COLUMN_OBJECT, &o, -1);
+
+ if (object == o) {
+ gtk_tree_store_set(priv->store, &iter,
+ COLUMN_ACTIVE, TRUE, -1);
+ update_adapter(object, &iter, client);
+
+ return;
+ }
+
+ cont = gtk_tree_model_iter_next(GTK_TREE_MODEL(priv->store), &iter);
+ }
+}
+
static void add_adapter(const char *path, BluetoothClient *client)
{
BluetoothClientPrivate *priv = BLUETOOTH_CLIENT_GET_PRIVATE(client);
@@ -715,6 +745,11 @@ static void add_adapter(const char *path
dbus_g_proxy_add_signal(object, "DiscoveryCompleted", G_TYPE_INVALID);
+ if (priv->default_adapter == NULL) {
+ priv->default_adapter = g_ascii_strcasecmp(path, "") ? g_strdup(path) : NULL;
+ g_object_notify (G_OBJECT (client), "default-adapter");
+ }
+
update_adapter(object, &iter, client);
}
@@ -733,10 +768,21 @@ static void remove_adapter(const char *p
COLUMN_PATH, &value, -1);
if (g_ascii_strcasecmp(path, value) == 0) {
+ GtkTreeIter child;
+
gtk_tree_store_set(priv->store, &iter,
COLUMN_ACTIVE, FALSE,
COLUMN_ADDRESS, NULL,
COLUMN_NAME, NULL, -1);
+
+ /* Remove the children */
+ if (gtk_tree_model_iter_children(GTK_TREE_MODEL(priv->store),
+ &child, &iter) == FALSE)
+ return;
+
+ cont = gtk_tree_store_remove (priv->store, &child);
+ while (cont != FALSE)
+ cont = gtk_tree_store_remove (priv->store, &child);
return;
}
@@ -759,14 +805,15 @@ static void adapter_removed(DBusGProxy *
static void default_adapter_changed(DBusGProxy *object,
const char *path, gpointer user_data)
{
- BluetoothClientPrivate *priv = BLUETOOTH_CLIENT_GET_PRIVATE(user_data);
+ BluetoothClient *client = (BluetoothClient *) user_data;
+ BluetoothClientPrivate *priv = BLUETOOTH_CLIENT_GET_PRIVATE(client);
gchar *temp;
temp = priv->default_adapter;
priv->default_adapter = g_ascii_strcasecmp(path, "") ? g_strdup(path) : NULL;
g_free(temp);
- g_message ("new default adapter: %s", priv->default_adapter);
+ g_object_notify (G_OBJECT (client), "default-adapter");
}
static void discovery_completed(DBusGProxy *object,
@@ -896,9 +943,12 @@ static void bluetooth_client_set_propert
static void bluetooth_client_get_property(GObject *object, guint prop_id,
GValue *value, GParamSpec *pspec)
{
- //BluetoothClientPrivate *priv = BLUETOOTH_CLIENT_GET_PRIVATE(object);
+ BluetoothClientPrivate *priv = BLUETOOTH_CLIENT_GET_PRIVATE(object);
switch (prop_id) {
+ case PROP_DEFAULT_ADAPTER:
+ g_value_set_string (value, priv->default_adapter);
+ break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec);
break;
@@ -907,6 +957,8 @@ static void bluetooth_client_get_propert
static void bluetooth_client_class_init(BluetoothClientClass *klass)
{
+ GObjectClass *object_class;
+
g_type_class_add_private(klass, sizeof(BluetoothClientPrivate));
G_OBJECT_CLASS(klass)->finalize = bluetooth_client_finalize;
@@ -924,6 +976,12 @@ static void bluetooth_client_class_init(
g_cclosure_marshal_VOID__VOID,
G_TYPE_NONE, 0, G_TYPE_NONE);
+ object_class = (GObjectClass *) klass;
+
+ g_object_class_install_property (object_class, PROP_DEFAULT_ADAPTER,
+ g_param_spec_string ("default-adapter", NULL, NULL,
+ NULL, G_PARAM_READABLE));
+
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);
Index: test-client.c
===================================================================
RCS file: /cvsroot/bluez/gnome/common/test-client.c,v
retrieving revision 1.11
diff -u -p -r1.11 test-client.c
--- test-client.c 31 Jul 2007 18:22:47 -0000 1.11
+++ test-client.c 31 Jan 2008 17:29:00 -0000
@@ -41,6 +41,17 @@ static void delete_callback(GtkWidget *w
gtk_main_quit();
}
+static void default_adapter_changed (GObject *gobject,
+ GParamSpec *arg1,
+ gpointer user_data)
+{
+ char *adapter;
+
+ g_object_get (gobject, "default-adapter", &adapter, NULL);
+ g_message ("default adapter changed: %s", adapter);
+ g_free (adapter);
+}
+
static void create_window(void)
{
GtkWidget *window;
@@ -135,6 +146,8 @@ static void create_window(void)
g_signal_connect(G_OBJECT(window), "delete-event",
G_CALLBACK(delete_callback), NULL);
+ g_signal_connect(G_OBJECT(client), "notify::default-adapter",
+ G_CALLBACK(default_adapter_changed), client);
gtk_widget_show_all(window);
}
[-- Attachment #3: Type: text/plain, Size: 228 bytes --]
-------------------------------------------------------------------------
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2008.
http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
[-- Attachment #4: Type: text/plain, Size: 164 bytes --]
_______________________________________________
Bluez-devel mailing list
Bluez-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/bluez-devel
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [Bluez-devel] [PATCH] client.c cleanup
2008-01-31 17:48 ` Bastien Nocera
@ 2008-02-01 10:46 ` Bastien Nocera
2008-02-01 12:11 ` Bastien Nocera
0 siblings, 1 reply; 12+ messages in thread
From: Bastien Nocera @ 2008-02-01 10:46 UTC (permalink / raw)
To: BlueZ development
[-- Attachment #1: Type: text/plain, Size: 319 bytes --]
On Thu, 2008-01-31 at 17:48 +0000, Bastien Nocera wrote:
<snip>
> About the hcid bug, should GetInfo fail when the bdaddr for the device
> isn't available, or should it just give out empty information?
Patch to allow GetAddress to fail, and don't add the information that's
not available to the GetInfo dict.
Cheers
[-- Attachment #2: bluez-utils-hcid-allow-getaddr-failure.patch --]
[-- Type: text/x-patch, Size: 2387 bytes --]
Index: adapter.c
===================================================================
RCS file: /cvsroot/bluez/utils/hcid/adapter.c,v
retrieving revision 1.13
diff -u -p -r1.13 adapter.c
--- adapter.c 28 Jan 2008 10:38:40 -0000 1.13
+++ adapter.c 1 Feb 2008 10:44:20 -0000
@@ -302,16 +302,18 @@ static DBusHandlerResult adapter_get_inf
DBUS_TYPE_STRING_AS_STRING DBUS_TYPE_VARIANT_AS_STRING
DBUS_DICT_ENTRY_END_CHAR_AS_STRING, &dict);
- dbus_message_iter_append_dict_entry(&dict, "address",
- DBUS_TYPE_STRING, &property);
-
- memset(str, 0, sizeof(str));
- property = str;
- str2ba(adapter->address, &ba);
-
- if (!read_local_name(&ba, str))
- dbus_message_iter_append_dict_entry(&dict, "name",
- DBUS_TYPE_STRING, &property);
+ if (check_address (property) == 0) {
+ dbus_message_iter_append_dict_entry(&dict, "address",
+ DBUS_TYPE_STRING, &property);
+
+ memset(str, 0, sizeof(str));
+ property = str;
+ str2ba(adapter->address, &ba);
+
+ if (!read_local_name(&ba, str))
+ dbus_message_iter_append_dict_entry(&dict, "name",
+ DBUS_TYPE_STRING, &property);
+ }
get_device_version(adapter->dev_id, str, sizeof(str));
dbus_message_iter_append_dict_entry(&dict, "version",
@@ -337,7 +339,7 @@ static DBusHandlerResult adapter_get_inf
dbus_message_iter_append_dict_entry(&dict, "discoverable_timeout",
DBUS_TYPE_UINT32, &adapter->discov_timeout);
- if (!read_local_class(&ba, cls)) {
+ if (check_address (property) == 0 && !read_local_class(&ba, cls)) {
uint32_t class;
memcpy(&class, cls, 3);
@@ -368,6 +370,9 @@ static DBusHandlerResult adapter_get_add
if (!dbus_message_has_signature(msg, DBUS_TYPE_INVALID_AS_STRING))
return error_invalid_arguments(conn, msg, NULL);
+ if (check_address (paddr) < 0)
+ return error_not_ready(conn, msg);
+
reply = dbus_message_new_method_return(msg);
if (!reply)
return DBUS_HANDLER_RESULT_NEED_MEMORY;
Index: dbus-api.txt
===================================================================
RCS file: /cvsroot/bluez/utils/hcid/dbus-api.txt,v
retrieving revision 1.135
diff -u -p -r1.135 dbus-api.txt
--- dbus-api.txt 28 Jan 2008 10:38:40 -0000 1.135
+++ dbus-api.txt 1 Feb 2008 10:44:20 -0000
@@ -335,7 +335,7 @@ Methods dict GetInfo()
Example: "00:11:22:33:44:55"
- Possible errors: none
+ Possible errors: org.bluez.Error.NotReady
string GetVersion()
[-- Attachment #3: Type: text/plain, Size: 228 bytes --]
-------------------------------------------------------------------------
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2008.
http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
[-- Attachment #4: Type: text/plain, Size: 164 bytes --]
_______________________________________________
Bluez-devel mailing list
Bluez-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/bluez-devel
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [Bluez-devel] [PATCH] client.c cleanup
2008-02-01 10:46 ` Bastien Nocera
@ 2008-02-01 12:11 ` Bastien Nocera
2008-02-01 12:23 ` Marcel Holtmann
0 siblings, 1 reply; 12+ messages in thread
From: Bastien Nocera @ 2008-02-01 12:11 UTC (permalink / raw)
To: BlueZ development
[-- Attachment #1: Type: text/plain, Size: 519 bytes --]
On Fri, 2008-02-01 at 10:46 +0000, Bastien Nocera wrote:
> On Thu, 2008-01-31 at 17:48 +0000, Bastien Nocera wrote:
> <snip>
> > About the hcid bug, should GetInfo fail when the bdaddr for the device
> > isn't available, or should it just give out empty information?
>
> Patch to allow GetAddress to fail, and don't add the information that's
> not available to the GetInfo dict.
Updated patch.
This one allows GetInfo and GetAddress to fail if there's no valid
bdaddr, and fixes the discussed coding style issues.
[-- Attachment #2: bluez-utils-hcid-allow-getaddr-failure-2.patch --]
[-- Type: text/x-patch, Size: 2129 bytes --]
Index: adapter.c
===================================================================
RCS file: /cvsroot/bluez/utils/hcid/adapter.c,v
retrieving revision 1.13
diff -u -p -r1.13 adapter.c
--- adapter.c 28 Jan 2008 10:38:40 -0000 1.13
+++ adapter.c 1 Feb 2008 12:09:25 -0000
@@ -283,7 +283,7 @@ static DBusHandlerResult adapter_get_inf
DBusMessage *msg, void *data)
{
struct adapter *adapter = data;
- const char *property = adapter->address;
+ const char *property;
DBusMessage *reply;
DBusMessageIter iter;
DBusMessageIter dict;
@@ -291,6 +291,9 @@ static DBusHandlerResult adapter_get_inf
char str[249];
uint8_t cls[3];
+ if (check_address(adapter->address) < 0)
+ return error_not_ready(conn, msg);
+
reply = dbus_message_new_method_return(msg);
if (!reply)
return DBUS_HANDLER_RESULT_NEED_MEMORY;
@@ -302,6 +305,7 @@ static DBusHandlerResult adapter_get_inf
DBUS_TYPE_STRING_AS_STRING DBUS_TYPE_VARIANT_AS_STRING
DBUS_DICT_ENTRY_END_CHAR_AS_STRING, &dict);
+ property = adapter->address;
dbus_message_iter_append_dict_entry(&dict, "address",
DBUS_TYPE_STRING, &property);
@@ -368,6 +372,9 @@ static DBusHandlerResult adapter_get_add
if (!dbus_message_has_signature(msg, DBUS_TYPE_INVALID_AS_STRING))
return error_invalid_arguments(conn, msg, NULL);
+ if (check_address(paddr) < 0)
+ return error_not_ready(conn, msg);
+
reply = dbus_message_new_method_return(msg);
if (!reply)
return DBUS_HANDLER_RESULT_NEED_MEMORY;
Index: dbus-api.txt
===================================================================
RCS file: /cvsroot/bluez/utils/hcid/dbus-api.txt,v
retrieving revision 1.135
diff -u -p -r1.135 dbus-api.txt
--- dbus-api.txt 28 Jan 2008 10:38:40 -0000 1.135
+++ dbus-api.txt 1 Feb 2008 12:09:25 -0000
@@ -329,13 +329,15 @@ Methods dict GetInfo()
Returns the properties of the local adapter.
+ Possible errors: org.bluez.Error.NotReady
+
string GetAddress()
Returns the device address for a given path.
Example: "00:11:22:33:44:55"
- Possible errors: none
+ Possible errors: org.bluez.Error.NotReady
string GetVersion()
[-- Attachment #3: Type: text/plain, Size: 228 bytes --]
-------------------------------------------------------------------------
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2008.
http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
[-- Attachment #4: Type: text/plain, Size: 164 bytes --]
_______________________________________________
Bluez-devel mailing list
Bluez-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/bluez-devel
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [Bluez-devel] [PATCH] client.c cleanup
2008-02-01 12:11 ` Bastien Nocera
@ 2008-02-01 12:23 ` Marcel Holtmann
0 siblings, 0 replies; 12+ messages in thread
From: Marcel Holtmann @ 2008-02-01 12:23 UTC (permalink / raw)
To: BlueZ development
Hi Bastien,
> > > About the hcid bug, should GetInfo fail when the bdaddr for the device
> > > isn't available, or should it just give out empty information?
> >
> > Patch to allow GetAddress to fail, and don't add the information that's
> > not available to the GetInfo dict.
>
> Updated patch.
>
> This one allows GetInfo and GetAddress to fail if there's no valid
> bdaddr, and fixes the discussed coding style issues.
patch has been committed. Thanks.
Regards
Marcel
-------------------------------------------------------------------------
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2008.
http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
_______________________________________________
Bluez-devel mailing list
Bluez-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/bluez-devel
^ permalink raw reply [flat|nested] 12+ messages in thread
end of thread, other threads:[~2008-02-01 12:23 UTC | newest]
Thread overview: 12+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2008-01-25 2:22 [Bluez-devel] [PATCH] client.c cleanup Bastien Nocera
2008-01-29 17:01 ` Marcel Holtmann
2008-01-29 17:24 ` Bastien Nocera
2008-01-29 17:35 ` Marcel Holtmann
2008-01-29 18:08 ` Bastien Nocera
2008-01-29 18:14 ` Marcel Holtmann
2008-01-30 17:31 ` Bastien Nocera
2008-01-31 14:57 ` Bastien Nocera
2008-01-31 17:48 ` Bastien Nocera
2008-02-01 10:46 ` Bastien Nocera
2008-02-01 12:11 ` Bastien Nocera
2008-02-01 12:23 ` Marcel Holtmann
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox