core: consolidate auto-activation recheck signals

Add a generic signal that devices can use to indicate that something
material in the network situation changed, and that auto-activation
may now be possible.  This reduces specific knowledge of device types
in the policy.
This commit is contained in:
Dan Williams
2014-02-24 18:10:18 -06:00
parent aeb1e103d8
commit 493bbbeb4a
7 changed files with 59 additions and 50 deletions

View File

@@ -95,4 +95,6 @@ void nm_device_master_check_slave_physical_port (NMDevice *dev, NMDevice *slave,
void nm_device_set_carrier (NMDevice *device, gboolean carrier);
void nm_device_emit_recheck_auto_activate (NMDevice *device);
#endif /* NM_DEVICE_PRIVATE_H */

View File

@@ -803,19 +803,32 @@ bring_up (NMDevice *device, gboolean *no_firmware)
return NM_DEVICE_CLASS (nm_device_wifi_parent_class)->bring_up (device, no_firmware);
}
static void
emit_ap_added_removed (NMDeviceWifi *self,
guint signum,
NMAccessPoint *ap,
gboolean recheck_available_connections)
{
g_signal_emit (self, signals[signum], 0, ap);
g_object_notify (G_OBJECT (self), NM_DEVICE_WIFI_ACCESS_POINTS);
nm_device_emit_recheck_auto_activate (NM_DEVICE (self));
if (recheck_available_connections)
nm_device_recheck_available_connections (NM_DEVICE (self));
}
static void
remove_access_point (NMDeviceWifi *device,
NMAccessPoint *ap)
{
NMDeviceWifiPrivate *priv = NM_DEVICE_WIFI_GET_PRIVATE (device);
NMDeviceWifi *self = NM_DEVICE_WIFI (device);
NMDeviceWifiPrivate *priv = NM_DEVICE_WIFI_GET_PRIVATE (self);
g_return_if_fail (ap);
g_return_if_fail (ap != priv->current_ap);
g_return_if_fail (g_slist_find (priv->ap_list, ap));
priv->ap_list = g_slist_remove (priv->ap_list, ap);
g_signal_emit (device, signals[ACCESS_POINT_REMOVED], 0, ap);
g_object_notify (G_OBJECT (device), NM_DEVICE_WIFI_ACCESS_POINTS);
emit_ap_added_removed (self, ACCESS_POINT_REMOVED, ap, FALSE);
g_object_unref (ap);
}
@@ -1788,7 +1801,6 @@ supplicant_iface_scan_done_cb (NMSupplicantInterface *iface,
}
}
/****************************************************************************
* WPA Supplicant control stuff
*
@@ -1887,9 +1899,7 @@ merge_scanned_ap (NMDeviceWifi *self,
g_object_ref (merge_ap);
priv->ap_list = g_slist_prepend (priv->ap_list, merge_ap);
nm_ap_export_to_dbus (merge_ap);
g_signal_emit (self, signals[ACCESS_POINT_ADDED], 0, merge_ap);
g_object_notify (G_OBJECT (self), NM_DEVICE_WIFI_ACCESS_POINTS);
nm_device_recheck_available_connections (NM_DEVICE (self));
emit_ap_added_removed (self, ACCESS_POINT_ADDED, merge_ap, TRUE);
}
}
@@ -2900,10 +2910,8 @@ act_stage1_prepare (NMDevice *dev, NMDeviceStateReason *reason)
nm_ap_export_to_dbus (ap);
g_object_freeze_notify (G_OBJECT (self));
set_current_ap (self, ap, FALSE, FALSE);
g_signal_emit (self, signals[ACCESS_POINT_ADDED], 0, ap);
g_object_notify (G_OBJECT (self), NM_DEVICE_WIFI_ACCESS_POINTS);
emit_ap_added_removed (self, ACCESS_POINT_ADDED, ap, TRUE);
g_object_thaw_notify (G_OBJECT (self));
nm_device_recheck_available_connections (NM_DEVICE (self));
nm_active_connection_set_specific_object (NM_ACTIVE_CONNECTION (req), nm_ap_get_dbus_path (ap));
return NM_ACT_STAGE_RETURN_SUCCESS;

View File

@@ -113,6 +113,7 @@ enum {
IP4_CONFIG_CHANGED,
IP6_CONFIG_CHANGED,
REMOVED,
RECHECK_AUTO_ACTIVATE,
LAST_SIGNAL,
};
static guint signals[LAST_SIGNAL] = { 0 };
@@ -1964,6 +1965,12 @@ nm_device_can_assume_connections (NMDevice *device)
return !!NM_DEVICE_GET_CLASS (device)->update_connection;
}
void
nm_device_emit_recheck_auto_activate (NMDevice *self)
{
g_signal_emit (self, signals[RECHECK_AUTO_ACTIVATE], 0);
}
static void
dnsmasq_state_changed_cb (NMDnsMasqManager *manager, guint32 status, gpointer user_data)
{
@@ -6167,6 +6174,13 @@ nm_device_class_init (NMDeviceClass *klass)
0, NULL, NULL, NULL,
G_TYPE_NONE, 0);
signals[RECHECK_AUTO_ACTIVATE] =
g_signal_new (NM_DEVICE_RECHECK_AUTO_ACTIVATE,
G_OBJECT_CLASS_TYPE (object_class),
G_SIGNAL_RUN_FIRST,
0, NULL, NULL, NULL,
G_TYPE_NONE, 0);
nm_dbus_manager_register_exported_type (nm_dbus_manager_get (),
G_TYPE_FROM_CLASS (klass),
&dbus_glib_nm_device_object_info);

View File

@@ -75,6 +75,7 @@
#define NM_DEVICE_IP4_CONFIG_CHANGED "ip4-config-changed"
#define NM_DEVICE_IP6_CONFIG_CHANGED "ip6-config-changed"
#define NM_DEVICE_REMOVED "removed"
#define NM_DEVICE_RECHECK_AUTO_ACTIVATE "recheck-auto-activate"
G_BEGIN_DECLS

View File

@@ -221,6 +221,19 @@ activation_timed_out (gpointer data)
return FALSE;
}
static void
emit_nsp_added_removed (NMDeviceWimax *self,
guint signum,
NMWimaxNsp *nsp,
gboolean recheck_available_connections)
{
g_signal_emit (self, signals[signum], 0, nsp);
g_object_notify (G_OBJECT (self), NM_DEVICE_WIMAX_NSPS);
nm_device_emit_recheck_auto_activate (NM_DEVICE (self));
if (recheck_available_connections)
nm_device_recheck_available_connections (NM_DEVICE (self));
}
static void
remove_all_nsps (NMDeviceWimax *self)
{
@@ -232,8 +245,7 @@ remove_all_nsps (NMDeviceWimax *self)
NMWimaxNsp *nsp = NM_WIMAX_NSP (priv->nsp_list->data);
priv->nsp_list = g_slist_remove (priv->nsp_list, nsp);
g_signal_emit (self, signals[NSP_REMOVED], 0, nsp);
g_object_notify (G_OBJECT (self), NM_DEVICE_WIMAX_NSPS);
emit_nsp_added_removed (self, NSP_REMOVED, nsp, FALSE);
g_object_unref (nsp);
}
@@ -971,7 +983,7 @@ remove_outdated_nsps (NMDeviceWimax *self,
for (iter = to_remove; iter; iter = iter->next) {
NMWimaxNsp *nsp = NM_WIMAX_NSP (iter->data);
g_signal_emit (self, signals[NSP_REMOVED], 0, nsp);
emit_nsp_added_removed (self, NSP_REMOVED, nsp, FALSE);
priv->nsp_list = g_slist_remove (priv->nsp_list, nsp);
g_object_unref (nsp);
}
@@ -1025,9 +1037,7 @@ wmx_scan_result_cb (struct wmxsdk *wmxsdk,
if (new_nsp) {
priv->nsp_list = g_slist_append (priv->nsp_list, nsp);
nm_wimax_nsp_export_to_dbus (nsp);
g_signal_emit (self, signals[NSP_ADDED], 0, nsp);
g_object_notify (G_OBJECT (self), NM_DEVICE_WIMAX_NSPS);
nm_device_recheck_available_connections (NM_DEVICE (self));
emit_nsp_added_removed (self, NSP_ADDED, nsp, TRUE);
}
}
}

View File

@@ -181,6 +181,7 @@ modem_enabled_cb (NMModem *modem, GParamSpec *pspec, gpointer user_data)
set_enabled (NM_DEVICE (self), nm_modem_get_mm_enabled (priv->modem));
g_signal_emit (G_OBJECT (self), signals[ENABLE_CHANGED], 0);
nm_device_emit_recheck_auto_activate (NM_DEVICE (self));
}
static void

View File

@@ -1602,21 +1602,9 @@ device_autoconnect_changed (NMDevice *device,
}
static void
wireless_networks_changed (NMDevice *device, GObject *ap, gpointer user_data)
device_recheck_auto_activate (NMDevice *device, gpointer user_data)
{
schedule_activate_check ((NMPolicy *) user_data, device);
}
static void
nsps_changed (NMDevice *device, GObject *nsp, gpointer user_data)
{
schedule_activate_check ((NMPolicy *) user_data, device);
}
static void
modem_enabled_changed (NMDevice *device, gpointer user_data)
{
schedule_activate_check ((NMPolicy *) (user_data), device);
schedule_activate_check (NM_POLICY (user_data), device);
}
typedef struct {
@@ -1654,22 +1642,7 @@ device_added (NMManager *manager, NMDevice *device, gpointer user_data)
_connect_device_signal (policy, device, NM_DEVICE_IP4_CONFIG_CHANGED, device_ip4_config_changed, FALSE);
_connect_device_signal (policy, device, NM_DEVICE_IP6_CONFIG_CHANGED, device_ip6_config_changed, FALSE);
_connect_device_signal (policy, device, "notify::" NM_DEVICE_AUTOCONNECT, device_autoconnect_changed, FALSE);
switch (nm_device_get_device_type (device)) {
case NM_DEVICE_TYPE_WIFI:
_connect_device_signal (policy, device, "access-point-added", wireless_networks_changed, FALSE);
_connect_device_signal (policy, device, "access-point-removed", wireless_networks_changed, FALSE);
break;
case NM_DEVICE_TYPE_WIMAX:
_connect_device_signal (policy, device, "nsp-added", nsps_changed, FALSE);
_connect_device_signal (policy, device, "nsp-removed", nsps_changed, FALSE);
break;
case NM_DEVICE_TYPE_MODEM:
_connect_device_signal (policy, device, "enable-changed", modem_enabled_changed, FALSE);
break;
default:
break;
}
_connect_device_signal (policy, device, NM_DEVICE_RECHECK_AUTO_ACTIVATE, device_recheck_auto_activate, FALSE);
}
static void