core: add nm_connection_provider_get()

In reality the connection provider (NMSettings) is always the same
object, and some device plugins need access to it.  Instead of
cluttering up the device plugin API by passing the provider into
every plugin regardless of whether the plugin needs it, create
a getter function.
This commit is contained in:
Dan Williams 2014-02-10 06:59:05 -06:00
parent fe6b86a078
commit fd3fe2200c
7 changed files with 41 additions and 74 deletions

View file

@ -80,8 +80,6 @@ void nm_device_set_dhcp_anycast_address (NMDevice *device, guint8 *addr);
gboolean nm_device_dhcp4_renew (NMDevice *device, gboolean release);
NMConnectionProvider *nm_device_get_connection_provider (NMDevice *device);
void nm_device_recheck_available_connections (NMDevice *device);
void nm_device_queued_state_clear (NMDevice *device);

View file

@ -341,11 +341,10 @@ update_connection (NMDevice *device, NMConnection *connection)
new_parent = nm_device_get_iface (parent);
setting_parent = nm_setting_vlan_get_parent (s_vlan);
if (setting_parent && nm_utils_is_uuid (setting_parent)) {
NMConnectionProvider *cp = nm_device_get_connection_provider (device);
NMConnection *parent_connection;
/* Don't change a parent specified by UUID if it's still valid */
parent_connection = nm_connection_provider_get_connection_by_uuid (cp, setting_parent);
parent_connection = nm_connection_provider_get_connection_by_uuid (nm_connection_provider_get (), setting_parent);
if (parent_connection && nm_device_check_connection_compatible (parent, parent_connection, NULL))
new_parent = NULL;
}

View file

@ -1603,7 +1603,6 @@ build_hidden_probe_list (NMDeviceWifi *self)
{
NMDeviceWifiPrivate *priv = NM_DEVICE_WIFI_GET_PRIVATE (self);
guint max_scan_ssids = nm_supplicant_interface_get_max_scan_ssids (priv->supplicant.iface);
NMConnectionProvider *provider = nm_device_get_connection_provider (NM_DEVICE (self));
GSList *connections, *iter;
GPtrArray *ssids = NULL;
static GByteArray *nullssid = NULL;
@ -1616,7 +1615,7 @@ build_hidden_probe_list (NMDeviceWifi *self)
if (G_UNLIKELY (nullssid == NULL))
nullssid = g_byte_array_new ();
connections = nm_connection_provider_get_best_connections (provider,
connections = nm_connection_provider_get_best_connections (nm_connection_provider_get (),
max_scan_ssids - 1,
NM_SETTING_WIRELESS_SETTING_NAME,
NULL,

View file

@ -315,13 +315,6 @@ typedef struct {
GSList * slaves; /* list of SlaveInfo */
NMConnectionProvider *con_provider;
/* connection provider signals for available connections property */
guint cp_added_id;
guint cp_loaded_id;
guint cp_removed_id;
guint cp_updated_id;
} NMDevicePrivate;
static gboolean nm_device_set_ip4_config (NMDevice *dev,
@ -613,6 +606,23 @@ constructed (GObject *object)
if (priv->ifindex > 0)
priv->mtu = nm_platform_link_get_mtu (priv->ifindex);
priv->con_provider = nm_connection_provider_get ();
g_assert (priv->con_provider);
g_signal_connect (priv->con_provider,
NM_CP_SIGNAL_CONNECTION_ADDED,
G_CALLBACK (cp_connection_added),
dev);
g_signal_connect (priv->con_provider,
NM_CP_SIGNAL_CONNECTION_REMOVED,
G_CALLBACK (cp_connection_removed),
dev);
g_signal_connect (priv->con_provider,
NM_CP_SIGNAL_CONNECTION_UPDATED,
G_CALLBACK (cp_connection_updated),
dev);
if (G_OBJECT_CLASS (nm_device_parent_class)->constructed)
G_OBJECT_CLASS (nm_device_parent_class)->constructed (object);
}
@ -884,43 +894,6 @@ nm_device_get_type_desc (NMDevice *self)
return NM_DEVICE_GET_PRIVATE (self)->type_desc;
}
void
nm_device_set_connection_provider (NMDevice *device,
NMConnectionProvider *provider)
{
NMDevicePrivate *priv;
g_return_if_fail (device != NULL);
g_return_if_fail (NM_IS_CONNECTION_PROVIDER (provider));
priv = NM_DEVICE_GET_PRIVATE (device);
g_return_if_fail (priv->con_provider == NULL);
priv->con_provider = provider;
priv->cp_added_id = g_signal_connect (priv->con_provider,
NM_CP_SIGNAL_CONNECTION_ADDED,
G_CALLBACK (cp_connection_added),
device);
priv->cp_removed_id = g_signal_connect (priv->con_provider,
NM_CP_SIGNAL_CONNECTION_REMOVED,
G_CALLBACK (cp_connection_removed),
device);
priv->cp_updated_id = g_signal_connect (priv->con_provider,
NM_CP_SIGNAL_CONNECTION_UPDATED,
G_CALLBACK (cp_connection_updated),
device);
}
NMConnectionProvider *
nm_device_get_connection_provider (NMDevice *device)
{
g_return_val_if_fail (device != NULL, NULL);
return NM_DEVICE_GET_PRIVATE (device)->con_provider;
}
static SlaveInfo *
find_slave_info (NMDevice *self, NMDevice *slave)
{
@ -5508,34 +5481,21 @@ dispose (GObject *object)
priv->carrier_defer_id = 0;
}
if (priv->cp_added_id) {
g_signal_handler_disconnect (priv->con_provider, priv->cp_added_id);
priv->cp_added_id = 0;
if (priv->con_provider) {
g_signal_handlers_disconnect_by_func (priv->con_provider, cp_connection_added, self);
g_signal_handlers_disconnect_by_func (priv->con_provider, cp_connection_removed, self);
g_signal_handlers_disconnect_by_func (priv->con_provider, cp_connection_updated, self);
priv->con_provider = NULL;
}
if (priv->cp_loaded_id) {
g_signal_handler_disconnect (priv->con_provider, priv->cp_loaded_id);
priv->cp_loaded_id = 0;
}
if (priv->cp_removed_id) {
g_signal_handler_disconnect (priv->con_provider, priv->cp_removed_id);
priv->cp_removed_id = 0;
}
if (priv->cp_updated_id) {
g_signal_handler_disconnect (priv->con_provider, priv->cp_updated_id);
priv->cp_updated_id = 0;
}
g_hash_table_unref (priv->available_connections);
priv->available_connections = NULL;
if (priv->carrier_wait_id) {
g_source_remove (priv->carrier_wait_id);
priv->carrier_wait_id = 0;
}
g_hash_table_unref (priv->available_connections);
priv->available_connections = NULL;
g_clear_pointer (&priv->physical_port_id, g_free);
activation_source_clear (self, TRUE, AF_INET);

View file

@ -316,8 +316,6 @@ gboolean nm_device_get_firmware_missing (NMDevice *self);
void nm_device_queue_activation (NMDevice *device, NMActRequest *req);
void nm_device_set_connection_provider (NMDevice *device, NMConnectionProvider *provider);
gboolean nm_device_supports_vlans (NMDevice *device);
void nm_device_add_pending_action (NMDevice *device, const char *action);

View file

@ -76,6 +76,13 @@ struct _NMConnectionProvider {
GType nm_connection_provider_get_type (void);
/**
* nm_connection_provider_get:
*
* Returns: the global #NMConnectionProvider
*/
NMConnectionProvider *nm_connection_provider_get (void);
/**
* nm_connection_provider_get_best_connections:
* @self: the #NMConnectionProvider

View file

@ -1842,8 +1842,6 @@ add_device (NMManager *self, NMDevice *device, gboolean generate_con)
return;
}
nm_device_set_connection_provider (device, NM_CONNECTION_PROVIDER (priv->settings));
priv->devices = g_slist_append (priv->devices, device);
g_signal_connect (device, "state-changed",
@ -4693,6 +4691,14 @@ nm_manager_get (void)
return singleton;
}
NMConnectionProvider *
nm_connection_provider_get (void)
{
g_assert (singleton);
g_assert (NM_MANAGER_GET_PRIVATE (singleton)->settings);
return NM_CONNECTION_PROVIDER (NM_MANAGER_GET_PRIVATE (singleton)->settings);
}
NMManager *
nm_manager_new (NMSettings *settings,
const char *state_file,