device/bluez: refactor registering to connections

No (intentional) change in behavior.
This commit is contained in:
Thomas Haller
2016-04-13 14:52:09 +02:00
parent 920054d8aa
commit 3325cd3d90

View File

@@ -331,15 +331,26 @@ connection_compatible (NMBluezDevice *self, NMConnection *connection)
return TRUE;
}
static void
_internal_add_connection (NMBluezDevice *self, NMConnection *connection)
static gboolean
_internal_track_connection (NMBluezDevice *self, NMConnection *connection, gboolean tracked)
{
NMBluezDevicePrivate *priv = NM_BLUEZ_DEVICE_GET_PRIVATE (self);
gboolean was_tracked;
if (!g_slist_find (priv->connections, connection)) {
was_tracked = !!g_slist_find (priv->connections, connection);
if (was_tracked == !!tracked)
return FALSE;
if (tracked)
priv->connections = g_slist_prepend (priv->connections, g_object_ref (connection));
check_emit_usable (self);
else {
priv->connections = g_slist_remove (priv->connections, connection);
if (priv->pan_connection == connection)
priv->pan_connection = NULL;
g_object_unref (connection);
}
return TRUE;
}
static void
@@ -347,8 +358,10 @@ cp_connection_added (NMConnectionProvider *provider,
NMConnection *connection,
NMBluezDevice *self)
{
if (connection_compatible (self, connection))
_internal_add_connection (self, connection);
if (connection_compatible (self, connection)) {
if (_internal_track_connection (self, connection, TRUE))
check_emit_usable (self);
}
}
static void
@@ -356,15 +369,8 @@ cp_connection_removed (NMConnectionProvider *provider,
NMConnection *connection,
NMBluezDevice *self)
{
NMBluezDevicePrivate *priv = NM_BLUEZ_DEVICE_GET_PRIVATE (self);
if (g_slist_find (priv->connections, connection)) {
priv->connections = g_slist_remove (priv->connections, connection);
if (priv->pan_connection == connection)
priv->pan_connection = NULL;
g_object_unref (connection);
if (_internal_track_connection (self, connection, FALSE))
check_emit_usable (self);
}
}
static void
@@ -372,10 +378,9 @@ cp_connection_updated (NMConnectionProvider *provider,
NMConnection *connection,
NMBluezDevice *self)
{
if (connection_compatible (self, connection))
_internal_add_connection (self, connection);
else
cp_connection_removed (provider, connection, self);
if (_internal_track_connection (self, connection,
connection_compatible (self, connection)))
check_emit_usable (self);
}
static void
@@ -383,10 +388,17 @@ load_connections (NMBluezDevice *self)
{
NMBluezDevicePrivate *priv = NM_BLUEZ_DEVICE_GET_PRIVATE (self);
const GSList *connections, *iter;
gboolean changed = FALSE;
connections = nm_connection_provider_get_connections (priv->provider);
for (iter = connections; iter; iter = g_slist_next (iter))
cp_connection_added (priv->provider, NM_CONNECTION (iter->data), self);
for (iter = connections; iter; iter = g_slist_next (iter)) {
NMConnection *connection = iter->data;
if (connection_compatible (self, connection))
changed |= _internal_track_connection (self, connection, TRUE);
}
if (changed)
check_emit_usable (self);
}
/***********************************************************/
@@ -1031,20 +1043,9 @@ nm_bluez_device_new (const char *path,
if (adapter_address)
set_adapter_address (self, adapter_address);
g_signal_connect (priv->provider,
NM_CP_SIGNAL_CONNECTION_ADDED,
G_CALLBACK (cp_connection_added),
self);
g_signal_connect (priv->provider,
NM_CP_SIGNAL_CONNECTION_REMOVED,
G_CALLBACK (cp_connection_removed),
self);
g_signal_connect (priv->provider,
NM_CP_SIGNAL_CONNECTION_UPDATED,
G_CALLBACK (cp_connection_updated),
self);
g_signal_connect (priv->provider, NM_CP_SIGNAL_CONNECTION_ADDED, G_CALLBACK (cp_connection_added), self);
g_signal_connect (priv->provider, NM_CP_SIGNAL_CONNECTION_REMOVED, G_CALLBACK (cp_connection_removed), self);
g_signal_connect (priv->provider, NM_CP_SIGNAL_CONNECTION_UPDATED, G_CALLBACK (cp_connection_updated), self);
g_bus_get (G_BUS_TYPE_SYSTEM,
NULL,