diff options
author | Dan Winship <danw@gnome.org> | 2012-09-27 12:38:59 -0400 |
---|---|---|
committer | Dan Winship <danw@gnome.org> | 2012-10-02 15:46:08 -0400 |
commit | 0fdf2e743833647d490a8a536086a0515f49f20c (patch) | |
tree | bf82e359026c187b219fd7081cc1fc61e48dc86c | |
parent | 565c43e91d92195e6143e836a95dd3387afb0d08 (diff) |
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.
-rw-r--r-- | src/nm-device-bond.c | 6 | ||||
-rw-r--r-- | src/nm-device-bt.c | 33 | ||||
-rw-r--r-- | src/nm-device-ethernet.c | 6 | ||||
-rw-r--r-- | src/nm-device-modem.c | 6 | ||||
-rw-r--r-- | src/nm-device-olpc-mesh.c | 32 | ||||
-rw-r--r-- | src/nm-device-wifi.c | 6 | ||||
-rw-r--r-- | src/nm-device.c | 5 | ||||
-rw-r--r-- | src/wimax/nm-device-wimax.c | 6 |
8 files changed, 47 insertions, 53 deletions
diff --git a/src/nm-device-bond.c b/src/nm-device-bond.c index 25b2d9bd..fa22b076 100644 --- a/src/nm-device-bond.c +++ b/src/nm-device-bond.c @@ -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, diff --git a/src/nm-device-bt.c b/src/nm-device-bt.c index a37c43d6..28a2fe1d 100644 --- a/src/nm-device-bt.c +++ b/src/nm-device-bt.c @@ -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, diff --git a/src/nm-device-ethernet.c b/src/nm-device-ethernet.c index 52198f64..4b8f9497 100644 --- a/src/nm-device-ethernet.c +++ b/src/nm-device-ethernet.c @@ -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, diff --git a/src/nm-device-modem.c b/src/nm-device-modem.c index 6f19a7cf..2ceed1fd 100644 --- a/src/nm-device-modem.c +++ b/src/nm-device-modem.c @@ -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, diff --git a/src/nm-device-olpc-mesh.c b/src/nm-device-olpc-mesh.c index 3da0408e..3d5b264e 100644 --- a/src/nm-device-olpc-mesh.c +++ b/src/nm-device-olpc-mesh.c @@ -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); } diff --git a/src/nm-device-wifi.c b/src/nm-device-wifi.c index f008c865..e8b4333d 100644 --- a/src/nm-device-wifi.c +++ b/src/nm-device-wifi.c @@ -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 */ diff --git a/src/nm-device.c b/src/nm-device.c index 09bfd6bf..04adc7e0 100644 --- a/src/nm-device.c +++ b/src/nm-device.c @@ -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); diff --git a/src/wimax/nm-device-wimax.c b/src/wimax/nm-device-wimax.c index 43281c73..d549e67e 100644 --- a/src/wimax/nm-device-wimax.c +++ b/src/wimax/nm-device-wimax.c @@ -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, |