mirror of
https://gitlab.freedesktop.org/NetworkManager/NetworkManager.git
synced 2025-12-22 18:30:09 +01:00
device/bluez: refactor registering to connections
No (intentional) change in behavior.
This commit is contained in:
parent
920054d8aa
commit
3325cd3d90
1 changed files with 35 additions and 34 deletions
|
|
@ -331,15 +331,26 @@ connection_compatible (NMBluezDevice *self, NMConnection *connection)
|
||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static gboolean
|
||||||
_internal_add_connection (NMBluezDevice *self, NMConnection *connection)
|
_internal_track_connection (NMBluezDevice *self, NMConnection *connection, gboolean tracked)
|
||||||
{
|
{
|
||||||
NMBluezDevicePrivate *priv = NM_BLUEZ_DEVICE_GET_PRIVATE (self);
|
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));
|
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
|
static void
|
||||||
|
|
@ -347,8 +358,10 @@ cp_connection_added (NMConnectionProvider *provider,
|
||||||
NMConnection *connection,
|
NMConnection *connection,
|
||||||
NMBluezDevice *self)
|
NMBluezDevice *self)
|
||||||
{
|
{
|
||||||
if (connection_compatible (self, connection))
|
if (connection_compatible (self, connection)) {
|
||||||
_internal_add_connection (self, connection);
|
if (_internal_track_connection (self, connection, TRUE))
|
||||||
|
check_emit_usable (self);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
|
|
@ -356,26 +369,18 @@ cp_connection_removed (NMConnectionProvider *provider,
|
||||||
NMConnection *connection,
|
NMConnection *connection,
|
||||||
NMBluezDevice *self)
|
NMBluezDevice *self)
|
||||||
{
|
{
|
||||||
NMBluezDevicePrivate *priv = NM_BLUEZ_DEVICE_GET_PRIVATE (self);
|
if (_internal_track_connection (self, connection, FALSE))
|
||||||
|
|
||||||
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);
|
|
||||||
check_emit_usable (self);
|
check_emit_usable (self);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
static void
|
static void
|
||||||
cp_connection_updated (NMConnectionProvider *provider,
|
cp_connection_updated (NMConnectionProvider *provider,
|
||||||
NMConnection *connection,
|
NMConnection *connection,
|
||||||
NMBluezDevice *self)
|
NMBluezDevice *self)
|
||||||
{
|
{
|
||||||
if (connection_compatible (self, connection))
|
if (_internal_track_connection (self, connection,
|
||||||
_internal_add_connection (self, connection);
|
connection_compatible (self, connection)))
|
||||||
else
|
check_emit_usable (self);
|
||||||
cp_connection_removed (provider, connection, self);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
|
|
@ -383,10 +388,17 @@ load_connections (NMBluezDevice *self)
|
||||||
{
|
{
|
||||||
NMBluezDevicePrivate *priv = NM_BLUEZ_DEVICE_GET_PRIVATE (self);
|
NMBluezDevicePrivate *priv = NM_BLUEZ_DEVICE_GET_PRIVATE (self);
|
||||||
const GSList *connections, *iter;
|
const GSList *connections, *iter;
|
||||||
|
gboolean changed = FALSE;
|
||||||
|
|
||||||
connections = nm_connection_provider_get_connections (priv->provider);
|
connections = nm_connection_provider_get_connections (priv->provider);
|
||||||
for (iter = connections; iter; iter = g_slist_next (iter))
|
for (iter = connections; iter; iter = g_slist_next (iter)) {
|
||||||
cp_connection_added (priv->provider, NM_CONNECTION (iter->data), self);
|
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)
|
if (adapter_address)
|
||||||
set_adapter_address (self, adapter_address);
|
set_adapter_address (self, adapter_address);
|
||||||
|
|
||||||
g_signal_connect (priv->provider,
|
g_signal_connect (priv->provider, NM_CP_SIGNAL_CONNECTION_ADDED, G_CALLBACK (cp_connection_added), self);
|
||||||
NM_CP_SIGNAL_CONNECTION_ADDED,
|
g_signal_connect (priv->provider, NM_CP_SIGNAL_CONNECTION_REMOVED, G_CALLBACK (cp_connection_removed), self);
|
||||||
G_CALLBACK (cp_connection_added),
|
g_signal_connect (priv->provider, NM_CP_SIGNAL_CONNECTION_UPDATED, G_CALLBACK (cp_connection_updated), self);
|
||||||
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,
|
g_bus_get (G_BUS_TYPE_SYSTEM,
|
||||||
NULL,
|
NULL,
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue