core: implement NMDevice::state-changed more idiomatically

Rather than having NMDevice subclasses connect to their own
::state-changed signal, fix up the signal definition so they can just
override the class handler.
This commit is contained in:
Dan Winship 2012-09-27 12:38:59 -04:00
parent 565c43e91d
commit 0fdf2e7438
8 changed files with 47 additions and 53 deletions

View file

@ -81,8 +81,7 @@ static void
device_state_changed (NMDevice *device,
NMDeviceState new_state,
NMDeviceState old_state,
NMDeviceStateReason reason,
gpointer user_data)
NMDeviceStateReason reason)
{
if (new_state == NM_DEVICE_STATE_UNAVAILABLE) {
/* Use NM_DEVICE_STATE_REASON_CARRIER to make sure num retries is reset */
@ -464,7 +463,6 @@ constructed (GObject *object)
static void
nm_device_bond_init (NMDeviceBond * self)
{
g_signal_connect (self, "state-changed", G_CALLBACK (device_state_changed), NULL);
}
static void
@ -540,6 +538,8 @@ nm_device_bond_class_init (NMDeviceBondClass *klass)
parent_class->enslave_slave = enslave_slave;
parent_class->release_slave = release_slave;
parent_class->state_changed = device_state_changed;
/* properties */
g_object_class_install_property
(object_class, PROP_HW_ADDRESS,

View file

@ -543,8 +543,7 @@ static void
device_state_changed (NMDevice *device,
NMDeviceState new_state,
NMDeviceState old_state,
NMDeviceStateReason reason,
gpointer user_data)
NMDeviceStateReason reason)
{
NMDeviceBtPrivate *priv = NM_DEVICE_BT_GET_PRIVATE (device);
@ -1164,28 +1163,22 @@ nm_device_bt_new (const char *udi,
guint32 capabilities,
gboolean managed)
{
NMDevice *device;
g_return_val_if_fail (udi != NULL, NULL);
g_return_val_if_fail (bdaddr != NULL, NULL);
g_return_val_if_fail (name != NULL, NULL);
g_return_val_if_fail (capabilities != NM_BT_CAPABILITY_NONE, NULL);
device = (NMDevice *) g_object_new (NM_TYPE_DEVICE_BT,
NM_DEVICE_UDI, udi,
NM_DEVICE_IFACE, bdaddr,
NM_DEVICE_DRIVER, "bluez",
NM_DEVICE_BT_HW_ADDRESS, bdaddr,
NM_DEVICE_BT_NAME, name,
NM_DEVICE_BT_CAPABILITIES, capabilities,
NM_DEVICE_MANAGED, managed,
NM_DEVICE_TYPE_DESC, "Bluetooth",
NM_DEVICE_DEVICE_TYPE, NM_DEVICE_TYPE_BT,
NULL);
if (device)
g_signal_connect (device, "state-changed", G_CALLBACK (device_state_changed), device);
return device;
return (NMDevice *) g_object_new (NM_TYPE_DEVICE_BT,
NM_DEVICE_UDI, udi,
NM_DEVICE_IFACE, bdaddr,
NM_DEVICE_DRIVER, "bluez",
NM_DEVICE_BT_HW_ADDRESS, bdaddr,
NM_DEVICE_BT_NAME, name,
NM_DEVICE_BT_CAPABILITIES, capabilities,
NM_DEVICE_MANAGED, managed,
NM_DEVICE_TYPE_DESC, "Bluetooth",
NM_DEVICE_DEVICE_TYPE, NM_DEVICE_TYPE_BT,
NULL);
}
static void
@ -1310,6 +1303,8 @@ nm_device_bt_class_init (NMDeviceBtClass *klass)
device_class->hwaddr_matches = hwaddr_matches;
device_class->is_available = is_available;
device_class->state_changed = device_state_changed;
/* Properties */
g_object_class_install_property
(object_class, PROP_HW_ADDRESS,

View file

@ -283,8 +283,7 @@ static void
device_state_changed (NMDevice *device,
NMDeviceState new_state,
NMDeviceState old_state,
NMDeviceStateReason reason,
gpointer user_data)
NMDeviceStateReason reason)
{
switch (new_state) {
case NM_DEVICE_STATE_ACTIVATED:
@ -300,7 +299,6 @@ device_state_changed (NMDevice *device,
static void
nm_device_ethernet_init (NMDeviceEthernet * self)
{
g_signal_connect (self, "state-changed", G_CALLBACK (device_state_changed), NULL);
}
static gboolean
@ -1534,6 +1532,8 @@ nm_device_ethernet_class_init (NMDeviceEthernetClass *klass)
parent_class->connection_match_config = connection_match_config;
parent_class->hwaddr_matches = hwaddr_matches;
parent_class->state_changed = device_state_changed;
/* properties */
g_object_class_install_property
(object_class, PROP_HW_ADDRESS,

View file

@ -196,8 +196,7 @@ static void
device_state_changed (NMDevice *device,
NMDeviceState new_state,
NMDeviceState old_state,
NMDeviceStateReason reason,
gpointer user_data)
NMDeviceStateReason reason)
{
nm_modem_device_state_changed (NM_DEVICE_MODEM_GET_PRIVATE (device)->modem,
new_state,
@ -374,7 +373,6 @@ nm_device_modem_new (NMModem *modem, const char *driver)
static void
nm_device_modem_init (NMDeviceModem *self)
{
g_signal_connect (self, "state-changed", G_CALLBACK (device_state_changed), self);
}
static void
@ -478,6 +476,8 @@ nm_device_modem_class_init (NMDeviceModemClass *mclass)
device_class->get_enabled = get_enabled;
device_class->set_enabled = set_enabled;
device_class->state_changed = device_state_changed;
/* Properties */
g_object_class_install_property
(object_class, PROP_MODEM,

View file

@ -107,6 +107,9 @@ struct _NMDeviceOlpcMeshPrivate
guint device_added_id;
};
static void state_changed (NMDevice *device, NMDeviceState new_state,
NMDeviceState old_state, NMDeviceStateReason reason);
static GQuark
nm_olpc_mesh_error_quark (void)
{
@ -524,6 +527,8 @@ nm_device_olpc_mesh_class_init (NMDeviceOlpcMeshClass *klass)
parent_class->act_stage1_prepare = act_stage1_prepare;
parent_class->act_stage2_config = act_stage2_config;
parent_class->state_changed = state_changed;
/* Properties */
g_object_class_install_property
(object_class, PROP_HW_ADDRESS,
@ -716,11 +721,12 @@ check_companion_cb (gpointer user_data)
}
static void
state_changed_cb (NMDevice *device, NMDeviceState state, gpointer user_data)
state_changed (NMDevice *device, NMDeviceState new_state,
NMDeviceState old_state, NMDeviceStateReason reason)
{
NMDeviceOlpcMesh *self = NM_DEVICE_OLPC_MESH (device);
switch (state) {
switch (new_state) {
case NM_DEVICE_STATE_UNMANAGED:
break;
case NM_DEVICE_STATE_UNAVAILABLE:
@ -746,23 +752,15 @@ nm_device_olpc_mesh_new (const char *udi,
const char *iface,
const char *driver)
{
GObject *obj;
g_return_val_if_fail (udi != NULL, NULL);
g_return_val_if_fail (iface != NULL, NULL);
g_return_val_if_fail (driver != NULL, NULL);
obj = g_object_new (NM_TYPE_DEVICE_OLPC_MESH,
NM_DEVICE_UDI, udi,
NM_DEVICE_IFACE, iface,
NM_DEVICE_DRIVER, driver,
NM_DEVICE_TYPE_DESC, "802.11 OLPC Mesh",
NM_DEVICE_DEVICE_TYPE, NM_DEVICE_TYPE_OLPC_MESH,
NULL);
if (obj == NULL)
return NULL;
g_signal_connect (obj, "state-changed", G_CALLBACK (state_changed_cb), NULL);
return NM_DEVICE (obj);
return (NMDevice *) g_object_new (NM_TYPE_DEVICE_OLPC_MESH,
NM_DEVICE_UDI, udi,
NM_DEVICE_IFACE, iface,
NM_DEVICE_DRIVER, driver,
NM_DEVICE_TYPE_DESC, "802.11 OLPC Mesh",
NM_DEVICE_DEVICE_TYPE, NM_DEVICE_TYPE_OLPC_MESH,
NULL);
}

View file

@ -3410,8 +3410,7 @@ static void
device_state_changed (NMDevice *device,
NMDeviceState new_state,
NMDeviceState old_state,
NMDeviceStateReason reason,
gpointer user_data)
NMDeviceStateReason reason)
{
NMDeviceWifi *self = NM_DEVICE_WIFI (device);
NMDeviceWifiPrivate *priv = NM_DEVICE_WIFI_GET_PRIVATE (self);
@ -3576,7 +3575,6 @@ nm_device_wifi_new (const char *udi,
static void
nm_device_wifi_init (NMDeviceWifi * self)
{
g_signal_connect (self, "state-changed", G_CALLBACK (device_state_changed), NULL);
}
static void
@ -3720,6 +3718,8 @@ nm_device_wifi_class_init (NMDeviceWifiClass *klass)
parent_class->spec_match_list = spec_match_list;
parent_class->hwaddr_matches = hwaddr_matches;
parent_class->state_changed = device_state_changed;
klass->scanning_allowed = scanning_allowed;
/* Properties */

View file

@ -4330,8 +4330,9 @@ nm_device_class_init (NMDeviceClass *klass)
signals[STATE_CHANGED] =
g_signal_new ("state-changed",
G_OBJECT_CLASS_TYPE (object_class),
G_SIGNAL_RUN_FIRST,
0, NULL, NULL,
G_SIGNAL_RUN_LAST,
G_STRUCT_OFFSET (NMDeviceClass, state_changed),
NULL, NULL,
_nm_marshal_VOID__UINT_UINT_UINT,
G_TYPE_NONE, 3,
G_TYPE_UINT, G_TYPE_UINT, G_TYPE_UINT);

View file

@ -1293,8 +1293,7 @@ static void
device_state_changed (NMDevice *device,
NMDeviceState new_state,
NMDeviceState old_state,
NMDeviceStateReason reason,
gpointer user_data)
NMDeviceStateReason reason)
{
NMDeviceWimax *self = NM_DEVICE_WIMAX (device);
NMDeviceWimaxPrivate *priv = NM_DEVICE_WIMAX_GET_PRIVATE (self);
@ -1396,7 +1395,6 @@ nm_device_wimax_new (const char *udi,
struct wmxsdk *sdk;
nm_wimax_util_sdk_ref ();
g_signal_connect (device, "state-changed", G_CALLBACK (device_state_changed), NULL);
/* See if the SDK already knows about this interface */
sdk = iwmx_sdk_get_wmxsdk_for_iface (iface);
@ -1536,6 +1534,8 @@ nm_device_wimax_class_init (NMDeviceWimaxClass *klass)
device_class->set_enabled = set_enabled;
device_class->hwaddr_matches = hwaddr_matches;
device_class->state_changed = device_state_changed;
/* Properties */
g_object_class_install_property
(object_class, PROP_HW_ADDRESS,