bluez: connections must be pre-configured for BlueZ 5 devices

Modify BlueZ 5 device to have the same behaviour as BlueZ 4, i.e. a
pre-configured connection must exist for the device to show up in
NetworkManager's device list.

Signed-off-by: Thomas Haller <thaller@redhat.com>
This commit is contained in:
Thomas Haller 2013-09-08 16:04:34 +02:00
parent dc85b22e0a
commit 008453e61f
5 changed files with 37 additions and 54 deletions

View file

@ -65,10 +65,8 @@ typedef struct {
char *bt_iface;
#if ! WITH_BLUEZ5
NMConnectionProvider *provider;
GSList *connections;
#endif
} NMBluezDevicePrivate;
@ -167,10 +165,9 @@ check_emit_usable (NMBluezDevice *self)
new_usable = (priv->initialized && priv->capabilities && priv->name &&
priv->address &&
#if WITH_BLUEZ5
priv->adapter && priv->dbus_connection
#else
priv->connections
priv->adapter && priv->dbus_connection &&
#endif
priv->connections
);
if (new_usable != priv->usable) {
priv->usable = new_usable;
@ -180,7 +177,6 @@ check_emit_usable (NMBluezDevice *self)
/********************************************************************/
#if ! WITH_BLUEZ5
static gboolean
connection_compatible (NMBluezDevice *self, NMConnection *connection)
{
@ -270,7 +266,6 @@ cp_connections_loaded (NMConnectionProvider *provider, NMBluezDevice *self)
}
/***********************************************************/
#endif
void
nm_bluez_device_disconnect (NMBluezDevice *self)
@ -670,6 +665,9 @@ query_properties (NMBluezDevice *self)
g_variant_unref (v);
}
/* Check if any connections match this device */
cp_connections_loaded (priv->provider, self);
priv->initialized = TRUE;
g_signal_emit (self, signals[INITIALIZED], 0, TRUE);
@ -791,11 +789,7 @@ on_bus_acquired (GObject *object, GAsyncResult *res, NMBluezDevice *self)
/********************************************************************/
NMBluezDevice *
nm_bluez_device_new (const char *path
#if ! WITH_BLUEZ5
, NMConnectionProvider *provider
#endif
)
nm_bluez_device_new (const char *path, NMConnectionProvider *provider)
{
NMBluezDevice *self;
NMBluezDevicePrivate *priv;
@ -804,9 +798,7 @@ nm_bluez_device_new (const char *path
#endif
g_return_val_if_fail (path != NULL, NULL);
#if ! WITH_BLUEZ5
g_return_val_if_fail (provider != NULL, NULL);
#endif
self = (NMBluezDevice *) g_object_new (NM_TYPE_BLUEZ_DEVICE,
NM_BLUEZ_DEVICE_PATH, path,
@ -816,23 +808,6 @@ nm_bluez_device_new (const char *path
priv = NM_BLUEZ_DEVICE_GET_PRIVATE (self);
#if WITH_BLUEZ5
g_bus_get (G_BUS_TYPE_SYSTEM,
NULL,
(GAsyncReadyCallback) on_bus_acquired,
self);
g_object_ref (self);
g_dbus_proxy_new_for_bus (G_BUS_TYPE_SYSTEM,
G_DBUS_PROXY_FLAGS_NONE,
NULL,
BLUEZ_SERVICE,
priv->path,
BLUEZ_DEVICE_INTERFACE,
NULL,
(GAsyncReadyCallback) on_proxy_acquired,
self);
#else
priv->provider = provider;
g_signal_connect (priv->provider,
@ -855,6 +830,23 @@ nm_bluez_device_new (const char *path
G_CALLBACK (cp_connections_loaded),
self);
#if WITH_BLUEZ5
g_bus_get (G_BUS_TYPE_SYSTEM,
NULL,
(GAsyncReadyCallback) on_bus_acquired,
self);
g_object_ref (self);
g_dbus_proxy_new_for_bus (G_BUS_TYPE_SYSTEM,
G_DBUS_PROXY_FLAGS_NONE,
NULL,
BLUEZ_SERVICE,
priv->path,
BLUEZ_DEVICE_INTERFACE,
NULL,
(GAsyncReadyCallback) on_proxy_acquired,
self);
#else
connection = nm_dbus_manager_get_connection (nm_dbus_manager_get ());
priv->proxy4 = dbus_g_proxy_new_for_name (connection,
@ -887,10 +879,6 @@ dispose (GObject *object)
NMBluezDevice *self = NM_BLUEZ_DEVICE (object);
NMBluezDevicePrivate *priv = NM_BLUEZ_DEVICE_GET_PRIVATE (self);
#if WITH_BLUEZ5
g_clear_object (&priv->adapter);
g_clear_object (&priv->dbus_connection);
#else
g_slist_foreach (priv->connections, (GFunc) g_object_unref, NULL);
g_slist_free (priv->connections);
priv->connections = NULL;
@ -900,6 +888,10 @@ dispose (GObject *object)
g_signal_handlers_disconnect_by_func (priv->provider, cp_connection_updated, self);
g_signal_handlers_disconnect_by_func (priv->provider, cp_connections_loaded, self);
#if WITH_BLUEZ5
g_clear_object (&priv->adapter);
g_clear_object (&priv->dbus_connection);
#else
g_clear_object (&priv->connection_proxy);
#endif

View file

@ -59,11 +59,7 @@ typedef struct {
GType nm_bluez_device_get_type (void);
NMBluezDevice *nm_bluez_device_new (const char *path
#if ! WITH_BLUEZ5
, NMConnectionProvider *provider
#endif
);
NMBluezDevice *nm_bluez_device_new (const char *path, NMConnectionProvider *provider);
const char *nm_bluez_device_get_path (NMBluezDevice *self);

View file

@ -61,13 +61,7 @@ typedef struct {
GType nm_bluez_manager_get_type (void);
NMBluezManager *nm_bluez_manager_get (
#if WITH_BLUEZ5
void
#else
NMConnectionProvider *provider
#endif
);
NMBluezManager *nm_bluez_manager_get (NMConnectionProvider *provider);
void nm_bluez_manager_query_devices (NMBluezManager *manager);

View file

@ -36,6 +36,8 @@ typedef struct {
NMDBusManager *dbus_mgr;
gulong name_owner_changed_id;
NMConnectionProvider *provider;
GDBusProxy *proxy;
GHashTable *devices;
@ -117,7 +119,7 @@ device_added (GDBusProxy *proxy, const gchar *path, NMBluezManager *self)
NMBluezManagerPrivate *priv = NM_BLUEZ_MANAGER_GET_PRIVATE (self);
NMBluezDevice *device;
device = nm_bluez_device_new (path);
device = nm_bluez_device_new (path, priv->provider);
g_signal_connect (device, "initialized", G_CALLBACK (device_initialized), self);
g_signal_connect (device, "notify::usable", G_CALLBACK (device_usable), self);
g_hash_table_insert (priv->devices, (gpointer) nm_bluez_device_get_path (device), device);
@ -329,7 +331,7 @@ dbus_connection_changed_cb (NMDBusManager *dbus_mgr,
/****************************************************************/
NMBluezManager *
nm_bluez_manager_get (void)
nm_bluez_manager_get (NMConnectionProvider *provider)
{
static NMBluezManager *singleton = NULL;
@ -339,6 +341,9 @@ nm_bluez_manager_get (void)
singleton = (NMBluezManager *) g_object_new (NM_TYPE_BLUEZ_MANAGER, NULL);
g_assert (singleton);
/* Cache the connection provider for NMBluezAdapter objects */
NM_BLUEZ_MANAGER_GET_PRIVATE (singleton)->provider = provider;
return singleton;
}

View file

@ -4452,11 +4452,7 @@ nm_manager_new (NMSettings *settings,
G_CALLBACK (rfkill_manager_rfkill_changed_cb),
singleton);
priv->bluez_mgr = nm_bluez_manager_get (
#if ! WITH_BLUEZ5
NM_CONNECTION_PROVIDER (priv->settings)
#endif
);
priv->bluez_mgr = nm_bluez_manager_get (NM_CONNECTION_PROVIDER (priv->settings));
g_signal_connect (priv->bluez_mgr,
NM_BLUEZ_MANAGER_BDADDR_ADDED,