core: clean up more usage of NM_IS_DEVICE_xxx()

One more step on the way to modular WiMAX and other device types.
This commit is contained in:
Dan Williams
2011-11-18 12:34:27 -06:00
parent edefc552fd
commit c71b032d7a
2 changed files with 30 additions and 29 deletions

View File

@@ -436,7 +436,7 @@ modem_added (NMModemManager *modem_manager,
/* Give Bluetooth DUN devices first chance to claim the modem */
for (iter = priv->devices; iter; iter = g_slist_next (iter)) {
if (NM_IS_DEVICE_BT (iter->data)) {
if (nm_device_get_device_type (iter->data) == NM_DEVICE_TYPE_BT) {
if (nm_device_bt_modem_added (NM_DEVICE_BT (iter->data), modem, driver))
return;
}
@@ -576,7 +576,7 @@ modem_removed (NMModemManager *modem_manager,
/* Give Bluetooth DUN devices first chance to handle the modem removal */
for (iter = priv->devices; iter; iter = g_slist_next (iter)) {
if (NM_IS_DEVICE_BT (iter->data)) {
if (nm_device_get_device_type (iter->data) == NM_DEVICE_TYPE_BT) {
if (nm_device_bt_modem_removed (NM_DEVICE_BT (iter->data), modem))
return;
}
@@ -1209,7 +1209,7 @@ nm_manager_get_ipw_rfkill_state (NMManager *self)
NMDevice *candidate = NM_DEVICE (iter->data);
RfKillState candidate_state;
if (NM_IS_DEVICE_WIFI (candidate)) {
if (nm_device_get_device_type (candidate) == NM_DEVICE_TYPE_WIFI) {
candidate_state = nm_device_wifi_get_ipw_rfkill_state (NM_DEVICE_WIFI (candidate));
if (candidate_state > ipw_state)
@@ -1483,10 +1483,13 @@ add_device (NMManager *self, NMDevice *device)
NMConnection *existing = NULL;
gboolean managed = FALSE, enabled = FALSE;
RfKillType rtype;
NMDeviceType devtype;
iface = nm_device_get_ip_iface (device);
g_assert (iface);
devtype = nm_device_get_device_type (device);
/* Ignore the device if we already know about it. But some modems will
* provide pseudo-ethernet devices that NM has already claimed while
* ModemManager is still detecting the modem's serial ports, so when the
@@ -1495,7 +1498,7 @@ add_device (NMManager *self, NMDevice *device)
* check for an existing device with the same IP interface name and kill
* the ethernet device later in favor of the modem device.
*/
if (!NM_IS_DEVICE_MODEM (device) && find_device_by_ip_iface (self, iface)) {
if ((devtype != NM_DEVICE_TYPE_MODEM) && find_device_by_ip_iface (self, iface)) {
g_object_unref (device);
return;
}
@@ -1510,7 +1513,7 @@ add_device (NMManager *self, NMDevice *device)
G_CALLBACK (manager_device_disconnect_request),
self);
if (NM_IS_DEVICE_WIFI (device)) {
if (devtype == NM_DEVICE_TYPE_WIFI) {
/* Attach to the access-point-added signal so that the manager can fill
* non-SSID-broadcasting APs with an SSID.
*/
@@ -1524,7 +1527,7 @@ add_device (NMManager *self, NMDevice *device)
g_signal_connect (device, "notify::" NM_DEVICE_WIFI_IPW_RFKILL_STATE,
G_CALLBACK (manager_ipw_rfkill_state_changed),
self);
} else if (NM_IS_DEVICE_MODEM (device)) {
} else if (devtype == NM_DEVICE_TYPE_MODEM) {
g_signal_connect (device, NM_DEVICE_MODEM_ENABLE_CHANGED,
G_CALLBACK (manager_modem_enabled_changed),
self);
@@ -1694,7 +1697,7 @@ bluez_manager_resync_devices (NMManager *self)
guint32 uuids;
const char *bdaddr;
if (NM_IS_DEVICE_BT (candidate)) {
if (nm_device_get_device_type (candidate) == NM_DEVICE_TYPE_BT) {
uuids = nm_device_bt_get_capabilities (NM_DEVICE_BT (candidate));
bdaddr = nm_device_bt_get_hw_address (NM_DEVICE_BT (candidate));

View File

@@ -32,12 +32,6 @@
#include "nm-activation-request.h"
#include "nm-logging.h"
#include "nm-device.h"
#include "nm-device-wifi.h"
#include "nm-device-ethernet.h"
#include "nm-device-modem.h"
#if WITH_WIMAX
#include "nm-device-wimax.h"
#endif
#include "nm-dbus-manager.h"
#include "nm-setting-ip4-config.h"
#include "nm-setting-connection.h"
@@ -97,6 +91,7 @@ get_best_ip4_device (NMManager *manager, NMActRequest **out_req)
devices = nm_manager_get_devices (manager);
for (iter = devices; iter; iter = g_slist_next (iter)) {
NMDevice *dev = NM_DEVICE (iter->data);
NMDeviceType devtype = nm_device_get_device_type (dev);
NMActRequest *req;
NMConnection *connection;
NMIP4Config *ip4_config;
@@ -137,7 +132,7 @@ get_best_ip4_device (NMManager *manager, NMActRequest **out_req)
}
}
if (!can_default && !NM_IS_DEVICE_MODEM (dev))
if (!can_default && (devtype != NM_DEVICE_TYPE_MODEM))
continue;
/* 'never-default' devices can't ever be the default */
@@ -171,6 +166,7 @@ get_best_ip6_device (NMManager *manager, NMActRequest **out_req)
devices = nm_manager_get_devices (manager);
for (iter = devices; iter; iter = g_slist_next (iter)) {
NMDevice *dev = NM_DEVICE (iter->data);
NMDeviceType devtype = nm_device_get_device_type (dev);
NMActRequest *req;
NMConnection *connection;
NMIP6Config *ip6_config;
@@ -211,7 +207,7 @@ get_best_ip6_device (NMManager *manager, NMActRequest **out_req)
}
}
if (!can_default && !NM_IS_DEVICE_MODEM (dev))
if (!can_default && (devtype != NM_DEVICE_TYPE_MODEM))
continue;
/* 'never-default' devices can't ever be the default */
@@ -1119,23 +1115,21 @@ device_ip_config_changed (NMDevice *device,
}
static void
wireless_networks_changed (NMDeviceWifi *device, NMAccessPoint *ap, gpointer user_data)
wireless_networks_changed (NMDevice *device, GObject *ap, gpointer user_data)
{
schedule_activate_check ((NMPolicy *) user_data, NM_DEVICE (device), 0);
schedule_activate_check ((NMPolicy *) user_data, device, 0);
}
#if WITH_WIMAX
static void
nsps_changed (NMDeviceWimax *device, NMWimaxNsp *nsp, gpointer user_data)
nsps_changed (NMDevice *device, GObject *nsp, gpointer user_data)
{
schedule_activate_check ((NMPolicy *) user_data, NM_DEVICE (device), 0);
schedule_activate_check ((NMPolicy *) user_data, device, 0);
}
#endif
static void
modem_enabled_changed (NMDeviceModem *device, gpointer user_data)
modem_enabled_changed (NMDevice *device, gpointer user_data)
{
schedule_activate_check ((NMPolicy *) (user_data), NM_DEVICE (device), 0);
schedule_activate_check ((NMPolicy *) (user_data), device, 0);
}
typedef struct {
@@ -1164,16 +1158,20 @@ device_added (NMManager *manager, NMDevice *device, gpointer user_data)
_connect_device_signal (policy, device, "notify::" NM_DEVICE_IP4_CONFIG, device_ip_config_changed);
_connect_device_signal (policy, device, "notify::" NM_DEVICE_IP6_CONFIG, device_ip_config_changed);
if (NM_IS_DEVICE_WIFI (device)) {
switch (nm_device_get_device_type (device)) {
case NM_DEVICE_TYPE_WIFI:
_connect_device_signal (policy, device, "access-point-added", wireless_networks_changed);
_connect_device_signal (policy, device, "access-point-removed", wireless_networks_changed);
#if WITH_WIMAX
} else if (NM_IS_DEVICE_WIMAX (device)) {
break;
case NM_DEVICE_TYPE_WIMAX:
_connect_device_signal (policy, device, "nsp-added", nsps_changed);
_connect_device_signal (policy, device, "nsp-removed", nsps_changed);
#endif
} else if (NM_IS_DEVICE_MODEM (device)) {
_connect_device_signal (policy, device, NM_DEVICE_MODEM_ENABLE_CHANGED, modem_enabled_changed);
break;
case NM_DEVICE_TYPE_MODEM:
_connect_device_signal (policy, device, "enable-changed", modem_enabled_changed);
break;
default:
break;
}
}