Commit b62ff36e authored by Dan Williams's avatar Dan Williams

core: get rid of nm_device_set_device_type()

parent 9b8d8fe8
......@@ -72,13 +72,14 @@ nm_modem_cdma_new (const char *path,
g_return_val_if_fail (driver != NULL, NULL);
return (NMDevice *) g_object_new (NM_TYPE_MODEM_CDMA,
NM_DEVICE_INTERFACE_UDI, path,
NM_DEVICE_INTERFACE_IFACE, data_device,
NM_DEVICE_INTERFACE_DRIVER, driver,
NM_MODEM_PATH, path,
NM_MODEM_DEVICE, device,
NM_DEVICE_INTERFACE_UDI, path,
NM_DEVICE_INTERFACE_IFACE, data_device,
NM_DEVICE_INTERFACE_DRIVER, driver,
NM_MODEM_PATH, path,
NM_MODEM_DEVICE, device,
NM_DEVICE_INTERFACE_TYPE_DESC, "CDMA",
NULL);
NM_DEVICE_INTERFACE_DEVICE_TYPE, NM_DEVICE_TYPE_CDMA,
NULL);
}
static void
......@@ -264,7 +265,6 @@ real_get_ppp_name (NMModem *device, NMConnection *connection)
static void
nm_modem_cdma_init (NMModemCdma *self)
{
nm_device_set_device_type (NM_DEVICE (self), NM_DEVICE_TYPE_CDMA);
}
static void
......
......@@ -91,14 +91,15 @@ nm_modem_gsm_new (const char *path,
g_return_val_if_fail (driver != NULL, NULL);
return (NMDevice *) g_object_new (NM_TYPE_MODEM_GSM,
NM_DEVICE_INTERFACE_UDI, path,
NM_DEVICE_INTERFACE_IFACE, data_device,
NM_DEVICE_INTERFACE_DRIVER, driver,
NM_MODEM_PATH, path,
NM_MODEM_IP_METHOD, ip_method,
NM_MODEM_DEVICE, device,
NM_DEVICE_INTERFACE_UDI, path,
NM_DEVICE_INTERFACE_IFACE, data_device,
NM_DEVICE_INTERFACE_DRIVER, driver,
NM_MODEM_PATH, path,
NM_MODEM_IP_METHOD, ip_method,
NM_MODEM_DEVICE, device,
NM_DEVICE_INTERFACE_TYPE_DESC, "GSM",
NULL);
NM_DEVICE_INTERFACE_DEVICE_TYPE, NM_DEVICE_TYPE_GSM,
NULL);
}
static NMDeviceStateReason
......@@ -432,7 +433,6 @@ real_get_ppp_name (NMModem *device, NMConnection *connection)
static void
nm_modem_gsm_init (NMModemGsm *self)
{
nm_device_set_device_type (NM_DEVICE (self), NM_DEVICE_TYPE_GSM);
}
static void
......
......@@ -122,7 +122,7 @@ nm_bt_error_get_type (void)
}
NMDeviceBt *
NMDevice *
nm_device_bt_new (const char *udi,
const char *bdaddr,
const char *name,
......@@ -134,16 +134,17 @@ nm_device_bt_new (const char *udi,
g_return_val_if_fail (name != NULL, NULL);
g_return_val_if_fail (capabilities != NM_BT_CAPABILITY_NONE, NULL);
return (NMDeviceBt *) g_object_new (NM_TYPE_DEVICE_BT,
NM_DEVICE_INTERFACE_UDI, udi,
NM_DEVICE_INTERFACE_IFACE, bdaddr,
NM_DEVICE_INTERFACE_DRIVER, "bluez",
NM_DEVICE_BT_HW_ADDRESS, bdaddr,
NM_DEVICE_BT_NAME, name,
NM_DEVICE_BT_CAPABILITIES, capabilities,
NM_DEVICE_INTERFACE_MANAGED, managed,
NM_DEVICE_INTERFACE_TYPE_DESC, "Bluetooth",
NULL);
return (NMDevice *) g_object_new (NM_TYPE_DEVICE_BT,
NM_DEVICE_INTERFACE_UDI, udi,
NM_DEVICE_INTERFACE_IFACE, bdaddr,
NM_DEVICE_INTERFACE_DRIVER, "bluez",
NM_DEVICE_BT_HW_ADDRESS, bdaddr,
NM_DEVICE_BT_NAME, name,
NM_DEVICE_BT_CAPABILITIES, capabilities,
NM_DEVICE_INTERFACE_MANAGED, managed,
NM_DEVICE_INTERFACE_TYPE_DESC, "Bluetooth",
NM_DEVICE_INTERFACE_DEVICE_TYPE, NM_DEVICE_TYPE_BT,
NULL);
}
guint32 nm_device_bt_get_capabilities (NMDeviceBt *self)
......@@ -705,7 +706,6 @@ real_deactivate_quickly (NMDevice *device)
static void
nm_device_bt_init (NMDeviceBt *self)
{
nm_device_set_device_type (NM_DEVICE (self), NM_DEVICE_TYPE_BT);
}
static gboolean
......
......@@ -50,11 +50,11 @@ typedef struct {
GType nm_device_bt_get_type (void);
NMDeviceBt *nm_device_bt_new (const char *udi,
const char *bdaddr,
const char *name,
guint32 capabilities,
gboolean managed);
NMDevice *nm_device_bt_new (const char *udi,
const char *bdaddr,
const char *name,
guint32 capabilities,
gboolean managed);
guint32 nm_device_bt_get_capabilities (NMDeviceBt *device);
......
......@@ -326,14 +326,6 @@ constructor (GType type,
static void
nm_device_ethernet_init (NMDeviceEthernet * self)
{
NMDeviceEthernetPrivate *priv = NM_DEVICE_ETHERNET_GET_PRIVATE (self);
priv->disposed = FALSE;
memset (&(priv->hw_addr), 0, sizeof (struct ether_addr));
priv->carrier = FALSE;
nm_device_set_device_type (NM_DEVICE (self), NM_DEVICE_TYPE_ETHERNET);
}
static gboolean
......@@ -384,7 +376,7 @@ real_hw_take_down (NMDevice *dev)
nm_system_device_set_up_down (dev, FALSE, NULL);
}
NMDeviceEthernet *
NMDevice *
nm_device_ethernet_new (const char *udi,
const char *iface,
const char *driver,
......@@ -394,13 +386,14 @@ nm_device_ethernet_new (const char *udi,
g_return_val_if_fail (iface != NULL, NULL);
g_return_val_if_fail (driver != NULL, NULL);
return (NMDeviceEthernet *) g_object_new (NM_TYPE_DEVICE_ETHERNET,
NM_DEVICE_INTERFACE_UDI, udi,
NM_DEVICE_INTERFACE_IFACE, iface,
NM_DEVICE_INTERFACE_DRIVER, driver,
NM_DEVICE_ETHERNET_IFINDEX, ifindex,
NM_DEVICE_INTERFACE_TYPE_DESC, "Ethernet",
NULL);
return (NMDevice *) g_object_new (NM_TYPE_DEVICE_ETHERNET,
NM_DEVICE_INTERFACE_UDI, udi,
NM_DEVICE_INTERFACE_IFACE, iface,
NM_DEVICE_INTERFACE_DRIVER, driver,
NM_DEVICE_ETHERNET_IFINDEX, ifindex,
NM_DEVICE_INTERFACE_TYPE_DESC, "Ethernet",
NM_DEVICE_INTERFACE_DEVICE_TYPE, NM_DEVICE_TYPE_ETHERNET,
NULL);
}
......
......@@ -56,13 +56,13 @@ typedef struct {
GType nm_device_ethernet_get_type (void);
NMDeviceEthernet *nm_device_ethernet_new (const char *udi,
const char *iface,
const char *driver,
guint32 ifindex);
NMDevice *nm_device_ethernet_new (const char *udi,
const char *iface,
const char *driver,
guint32 ifindex);
void nm_device_ethernet_get_address (NMDeviceEthernet *dev,
struct ether_addr *addr);
struct ether_addr *addr);
gboolean nm_device_ethernet_get_carrier (NMDeviceEthernet *dev);
......
......@@ -26,8 +26,6 @@
void nm_device_set_ip_iface (NMDevice *self, const char *iface);
void nm_device_set_device_type (NMDevice *dev, NMDeviceType type);
void nm_device_activate_schedule_stage3_ip_config_start (NMDevice *device);
void nm_device_state_changed (NMDevice *device,
......
......@@ -136,7 +136,7 @@ typedef struct Supplicant {
} Supplicant;
struct _NMDeviceWifiPrivate {
gboolean dispose_has_run;
gboolean disposed;
struct ether_addr hw_addr;
guint32 ifindex;
......@@ -452,20 +452,6 @@ get_wireless_capabilities (NMDeviceWifi *self,
}
static void
nm_device_wifi_init (NMDeviceWifi * self)
{
NMDeviceWifiPrivate *priv = NM_DEVICE_WIFI_GET_PRIVATE (self);
priv->dispose_has_run = FALSE;
priv->ap_list = NULL;
priv->we_version = 0;
memset (&(priv->hw_addr), 0, sizeof (struct ether_addr));
nm_device_set_device_type (NM_DEVICE (self), NM_DEVICE_TYPE_WIFI);
}
static guint32 iw_freq_to_uint32 (struct iw_freq *freq)
{
if (freq->e == 0) {
......@@ -3166,18 +3152,223 @@ real_get_type_capabilities (NMDevice *dev)
}
static gboolean
spec_match_list (NMDevice *device, const GSList *specs)
{
struct ether_addr ether;
char *hwaddr;
gboolean matched;
nm_device_wifi_get_address (NM_DEVICE_WIFI (device), &ether);
hwaddr = nm_ether_ntop (&ether);
matched = nm_match_spec_hwaddr (specs, hwaddr);
g_free (hwaddr);
return matched;
}
static gboolean
unavailable_to_disconnected (gpointer user_data)
{
nm_device_state_changed (NM_DEVICE (user_data),
NM_DEVICE_STATE_DISCONNECTED,
NM_DEVICE_STATE_REASON_NONE);
return FALSE;
}
static void
device_state_changed (NMDevice *device,
NMDeviceState new_state,
NMDeviceState old_state,
NMDeviceStateReason reason,
gpointer user_data)
{
NMDeviceWifi *self = NM_DEVICE_WIFI (device);
NMDeviceWifiPrivate *priv = NM_DEVICE_WIFI_GET_PRIVATE (self);
gboolean clear_aps = FALSE;
/* Remove any previous delayed transition to disconnected */
if (priv->state_to_disconnected_id) {
g_source_remove (priv->state_to_disconnected_id);
priv->state_to_disconnected_id = 0;
}
if (new_state <= NM_DEVICE_STATE_UNAVAILABLE) {
/* Clean up the supplicant interface because in these states the
* device cannot be used.
*/
if (priv->supplicant.iface)
supplicant_interface_release (self);
}
switch (new_state) {
case NM_DEVICE_STATE_UNMANAGED:
clear_aps = TRUE;
break;
case NM_DEVICE_STATE_UNAVAILABLE:
/* If the device is enabled and the supplicant manager is ready,
* acquire a supplicant interface and transition to DISCONNECTED because
* the device is now ready to use.
*/
if (priv->enabled) {
gboolean success;
struct iw_range range;
/* Wait for some drivers like ipw3945 to come back to life */
success = wireless_get_range (self, &range, NULL);
if (!priv->supplicant.iface)
supplicant_interface_acquire (self);
if (priv->supplicant.iface)
priv->state_to_disconnected_id = g_idle_add (unavailable_to_disconnected, self);
}
clear_aps = TRUE;
break;
case NM_DEVICE_STATE_ACTIVATED:
activation_success_handler (device);
break;
case NM_DEVICE_STATE_FAILED:
activation_failure_handler (device);
break;
case NM_DEVICE_STATE_DISCONNECTED:
// FIXME: ensure that the activation request is destroyed
break;
default:
break;
}
if (clear_aps)
remove_all_aps (self);
}
guint32
nm_device_wifi_get_ifindex (NMDeviceWifi *self)
{
g_return_val_if_fail (self != NULL, FALSE);
return NM_DEVICE_WIFI_GET_PRIVATE (self)->ifindex;
}
NMAccessPoint *
nm_device_wifi_get_activation_ap (NMDeviceWifi *self)
{
NMDeviceWifiPrivate *priv;
NMActRequest *req;
const char *ap_path;
GSList * elt;
g_return_val_if_fail (NM_IS_DEVICE_WIFI (self), NULL);
req = nm_device_get_act_request (NM_DEVICE (self));
if (!req)
return NULL;
ap_path = nm_act_request_get_specific_object (req);
if (!ap_path)
return NULL;
/* Find the AP by it's object path */
priv = NM_DEVICE_WIFI_GET_PRIVATE (self);
for (elt = priv->ap_list; elt; elt = g_slist_next (elt)) {
NMAccessPoint *ap = NM_AP (elt->data);
if (!strcmp (ap_path, nm_ap_get_dbus_path (ap)))
return ap;
}
return NULL;
}
void
nm_device_wifi_set_enabled (NMDeviceWifi *self, gboolean enabled)
{
NMDeviceWifiPrivate *priv;
NMDeviceState state;
g_return_if_fail (NM_IS_DEVICE_WIFI (self));
priv = NM_DEVICE_WIFI_GET_PRIVATE (self);
if (priv->enabled == enabled)
return;
priv->enabled = enabled;
state = nm_device_interface_get_state (NM_DEVICE_INTERFACE (self));
if (state < NM_DEVICE_STATE_UNAVAILABLE)
return;
if (enabled) {
gboolean no_firmware = FALSE, success;
struct iw_range range;
if (state != NM_DEVICE_STATE_UNAVAILABLE)
nm_warning ("not in expected unavailable state!");
if (!nm_device_hw_bring_up (NM_DEVICE (self), TRUE, &no_firmware)) {
/* The device sucks, or HAL was lying to us about the killswitch state */
priv->enabled = FALSE;
return;
}
/* Wait for some drivers like ipw3945 to come back to life */
success = wireless_get_range (self, &range, NULL);
if (!priv->supplicant.iface)
supplicant_interface_acquire (self);
if (priv->supplicant.iface) {
nm_device_state_changed (NM_DEVICE (self),
NM_DEVICE_STATE_DISCONNECTED,
NM_DEVICE_STATE_REASON_NONE);
}
} else {
nm_device_state_changed (NM_DEVICE (self),
NM_DEVICE_STATE_UNAVAILABLE,
NM_DEVICE_STATE_REASON_NONE);
nm_device_hw_take_down (NM_DEVICE (self), TRUE);
}
}
/********************************************************************/
NMDevice *
nm_device_wifi_new (const char *udi,
const char *iface,
const char *driver,
guint32 ifindex)
{
g_return_val_if_fail (udi != NULL, NULL);
g_return_val_if_fail (iface != NULL, NULL);
g_return_val_if_fail (driver != NULL, NULL);
return (NMDevice *) g_object_new (NM_TYPE_DEVICE_WIFI,
NM_DEVICE_INTERFACE_UDI, udi,
NM_DEVICE_INTERFACE_IFACE, iface,
NM_DEVICE_INTERFACE_DRIVER, driver,
NM_DEVICE_WIFI_IFINDEX, ifindex,
NM_DEVICE_INTERFACE_TYPE_DESC, "802.11 WiFi",
NM_DEVICE_INTERFACE_DEVICE_TYPE, NM_DEVICE_TYPE_WIFI,
NULL);
}
static void
nm_device_wifi_init (NMDeviceWifi * self)
{
g_signal_connect (self, "state-changed", G_CALLBACK (device_state_changed), NULL);
}
static void
nm_device_wifi_dispose (GObject *object)
dispose (GObject *object)
{
NMDeviceWifi *self = NM_DEVICE_WIFI (object);
NMDeviceWifiPrivate *priv = NM_DEVICE_WIFI_GET_PRIVATE (self);
if (priv->dispose_has_run) {
if (priv->disposed) {
G_OBJECT_CLASS (nm_device_wifi_parent_class)->dispose (object);
return;
}
priv->dispose_has_run = TRUE;
priv->disposed = TRUE;
if (priv->periodic_source_id) {
g_source_remove (priv->periodic_source_id);
......@@ -3219,21 +3410,6 @@ nm_device_wifi_dispose (GObject *object)
G_OBJECT_CLASS (nm_device_wifi_parent_class)->dispose (object);
}
static gboolean
spec_match_list (NMDevice *device, const GSList *specs)
{
struct ether_addr ether;
char *hwaddr;
gboolean matched;
nm_device_wifi_get_address (NM_DEVICE_WIFI (device), &ether);
hwaddr = nm_ether_ntop (&ether);
matched = nm_match_spec_hwaddr (specs, hwaddr);
g_free (hwaddr);
return matched;
}
static void
get_property (GObject *object, guint prop_id,
GValue *value, GParamSpec *pspec)
......@@ -3300,7 +3476,7 @@ nm_device_wifi_class_init (NMDeviceWifiClass *klass)
object_class->constructor = constructor;
object_class->get_property = get_property;
object_class->set_property = set_property;
object_class->dispose = nm_device_wifi_dispose;
object_class->dispose = dispose;
parent_class->get_type_capabilities = real_get_type_capabilities;
parent_class->get_generic_capabilities = real_get_generic_capabilities;
......@@ -3410,193 +3586,4 @@ nm_device_wifi_class_init (NMDeviceWifiClass *klass)
dbus_g_error_domain_register (NM_WIFI_ERROR, NULL, NM_TYPE_WIFI_ERROR);
}
static gboolean
unavailable_to_disconnected (gpointer user_data)
{
nm_device_state_changed (NM_DEVICE (user_data),
NM_DEVICE_STATE_DISCONNECTED,
NM_DEVICE_STATE_REASON_NONE);
return FALSE;
}
static void
device_state_changed (NMDevice *device,
NMDeviceState new_state,
NMDeviceState old_state,
NMDeviceStateReason reason,
gpointer user_data)
{
NMDeviceWifi *self = NM_DEVICE_WIFI (device);
NMDeviceWifiPrivate *priv = NM_DEVICE_WIFI_GET_PRIVATE (self);
gboolean clear_aps = FALSE;
/* Remove any previous delayed transition to disconnected */
if (priv->state_to_disconnected_id) {
g_source_remove (priv->state_to_disconnected_id);
priv->state_to_disconnected_id = 0;
}
if (new_state <= NM_DEVICE_STATE_UNAVAILABLE) {
/* Clean up the supplicant interface because in these states the
* device cannot be used.
*/
if (priv->supplicant.iface)
supplicant_interface_release (self);
}
switch (new_state) {
case NM_DEVICE_STATE_UNMANAGED:
clear_aps = TRUE;
break;
case NM_DEVICE_STATE_UNAVAILABLE:
/* If the device is enabled and the supplicant manager is ready,
* acquire a supplicant interface and transition to DISCONNECTED because
* the device is now ready to use.
*/
if (priv->enabled) {
gboolean success;
struct iw_range range;
/* Wait for some drivers like ipw3945 to come back to life */
success = wireless_get_range (self, &range, NULL);
if (!priv->supplicant.iface)
supplicant_interface_acquire (self);
if (priv->supplicant.iface)
priv->state_to_disconnected_id = g_idle_add (unavailable_to_disconnected, self);
}
clear_aps = TRUE;
break;
case NM_DEVICE_STATE_ACTIVATED:
activation_success_handler (device);
break;
case NM_DEVICE_STATE_FAILED:
activation_failure_handler (device);
break;
case NM_DEVICE_STATE_DISCONNECTED:
// FIXME: ensure that the activation request is destroyed
break;
default:
break;
}
if (clear_aps)
remove_all_aps (self);
}
NMDeviceWifi *
nm_device_wifi_new (const char *udi,
const char *iface,
const char *driver,
guint32 ifindex)
{
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_WIFI,
NM_DEVICE_INTERFACE_UDI, udi,
NM_DEVICE_INTERFACE_IFACE, iface,
NM_DEVICE_INTERFACE_DRIVER, driver,
NM_DEVICE_WIFI_IFINDEX, ifindex,
NM_DEVICE_INTERFACE_TYPE_DESC, "802.11 WiFi",
NULL);
if (obj == NULL)
return NULL;
g_signal_connect (obj, "state-changed", G_CALLBACK (device_state_changed), NULL);
return NM_DEVICE_WIFI (obj);
}
guint32
nm_device_wifi_get_ifindex (NMDeviceWifi *self)
{
g_return_val_if_fail (self != NULL, FALSE);
return NM_DEVICE_WIFI_GET_PRIVATE (self)->ifindex;
}
NMAccessPoint *
nm_device_wifi_get_activation_ap (NMDeviceWifi *self)
{
NMDeviceWifiPrivate *priv;
NMActRequest *req;
const char *ap_path;
GSList * elt;
g_return_val_if_fail (NM_IS_DEVICE_WIFI (self), NULL);
req = nm_device_get_act_request (NM_DEVICE (self));
if (!req)
return NULL;
ap_path = nm_act_request_get_specific_object (req);
if (!ap_path)
return NULL;
/* Find the AP by it's object path */
priv = NM_DEVICE_WIFI_GET_PRIVATE (self);
for (elt = priv->ap_list; elt; elt = g_slist_next (elt)) {
NMAccessPoint *ap = NM_AP (elt->data);