mirror of
https://gitlab.freedesktop.org/NetworkManager/NetworkManager.git
synced 2026-02-04 22:20:27 +01:00
libnm-glib: simplify setting device-type property
Instead of having the superclass check the GObject type and translate that into an NMDeviceType, have each subclass set its own device type.
This commit is contained in:
parent
bc50a2a75b
commit
5a7fdd4b88
11 changed files with 72 additions and 88 deletions
|
|
@ -148,9 +148,7 @@ connection_valid (NMDevice *device, NMConnection *connection)
|
|||
static void
|
||||
nm_device_bond_init (NMDeviceBond *device)
|
||||
{
|
||||
NMDeviceBondPrivate *priv = NM_DEVICE_BOND_GET_PRIVATE (device);
|
||||
|
||||
priv->carrier = FALSE;
|
||||
nm_device_set_device_type (NM_DEVICE (device), NM_DEVICE_TYPE_BOND);
|
||||
}
|
||||
|
||||
static void
|
||||
|
|
|
|||
|
|
@ -198,6 +198,7 @@ connection_valid (NMDevice *device, NMConnection *connection)
|
|||
static void
|
||||
nm_device_bt_init (NMDeviceBt *device)
|
||||
{
|
||||
nm_device_set_device_type (NM_DEVICE (device), NM_DEVICE_TYPE_BT);
|
||||
}
|
||||
|
||||
static void
|
||||
|
|
|
|||
|
|
@ -205,10 +205,7 @@ connection_valid (NMDevice *device, NMConnection *connection)
|
|||
static void
|
||||
nm_device_ethernet_init (NMDeviceEthernet *device)
|
||||
{
|
||||
NMDeviceEthernetPrivate *priv = NM_DEVICE_ETHERNET_GET_PRIVATE (device);
|
||||
|
||||
priv->disposed = FALSE;
|
||||
priv->carrier = FALSE;
|
||||
nm_device_set_device_type (NM_DEVICE (device), NM_DEVICE_TYPE_ETHERNET);
|
||||
}
|
||||
|
||||
static void
|
||||
|
|
|
|||
|
|
@ -152,9 +152,7 @@ connection_valid (NMDevice *device, NMConnection *connection)
|
|||
static void
|
||||
nm_device_infiniband_init (NMDeviceInfiniband *device)
|
||||
{
|
||||
NMDeviceInfinibandPrivate *priv = NM_DEVICE_INFINIBAND_GET_PRIVATE (device);
|
||||
|
||||
priv->carrier = FALSE;
|
||||
nm_device_set_device_type (NM_DEVICE (device), NM_DEVICE_TYPE_INFINIBAND);
|
||||
}
|
||||
|
||||
static void
|
||||
|
|
|
|||
|
|
@ -132,6 +132,12 @@ connection_valid (NMDevice *device, NMConnection *connection)
|
|||
|
||||
/*******************************************************************/
|
||||
|
||||
static void
|
||||
nm_device_modem_init (NMDeviceModem *device)
|
||||
{
|
||||
nm_device_set_device_type (NM_DEVICE (device), NM_DEVICE_TYPE_MODEM);
|
||||
}
|
||||
|
||||
static void
|
||||
register_properties (NMDeviceModem *device)
|
||||
{
|
||||
|
|
@ -164,11 +170,6 @@ constructed (GObject *object)
|
|||
register_properties (NM_DEVICE_MODEM (object));
|
||||
}
|
||||
|
||||
static void
|
||||
nm_device_modem_init (NMDeviceModem *device)
|
||||
{
|
||||
}
|
||||
|
||||
static void
|
||||
get_property (GObject *object,
|
||||
guint prop_id,
|
||||
|
|
|
|||
|
|
@ -161,11 +161,7 @@ connection_valid (NMDevice *device, NMConnection *connection)
|
|||
static void
|
||||
nm_device_olpc_mesh_init (NMDeviceOlpcMesh *device)
|
||||
{
|
||||
NMDeviceOlpcMeshPrivate *priv = NM_DEVICE_OLPC_MESH_GET_PRIVATE (device);
|
||||
|
||||
priv->hw_address = NULL;
|
||||
priv->companion = NULL;
|
||||
priv->active_channel = 0;
|
||||
nm_device_set_device_type (NM_DEVICE (device), NM_DEVICE_TYPE_OLPC_MESH);
|
||||
}
|
||||
|
||||
static void
|
||||
|
|
|
|||
|
|
@ -17,16 +17,12 @@
|
|||
* Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
|
||||
* Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Copyright (C) 2007 - 2008 Red Hat, Inc.
|
||||
* Copyright (C) 2007 - 2012 Red Hat, Inc.
|
||||
*/
|
||||
|
||||
#ifndef NM_DEVICE_PRIVATE_H
|
||||
#define NM_DEVICE_PRIVATE_H
|
||||
|
||||
#include <dbus/dbus-glib.h>
|
||||
|
||||
DBusGConnection *nm_device_get_connection (NMDevice *device);
|
||||
const char *nm_device_get_path (NMDevice *device);
|
||||
DBusGProxy *nm_device_get_properties_proxy (NMDevice *device);
|
||||
void nm_device_set_device_type (NMDevice *device, NMDeviceType dtype);
|
||||
|
||||
#endif /* NM_DEVICE_PRIVATE_H */
|
||||
|
|
|
|||
|
|
@ -167,6 +167,7 @@ connection_valid (NMDevice *device, NMConnection *connection)
|
|||
static void
|
||||
nm_device_vlan_init (NMDeviceVlan *device)
|
||||
{
|
||||
nm_device_set_device_type (NM_DEVICE (device), NM_DEVICE_TYPE_VLAN);
|
||||
}
|
||||
|
||||
static void
|
||||
|
|
|
|||
|
|
@ -451,9 +451,7 @@ connection_valid (NMDevice *device, NMConnection *connection)
|
|||
static void
|
||||
nm_device_wifi_init (NMDeviceWifi *device)
|
||||
{
|
||||
NMDeviceWifiPrivate *priv = NM_DEVICE_WIFI_GET_PRIVATE (device);
|
||||
|
||||
priv->disposed = FALSE;
|
||||
nm_device_set_device_type (NM_DEVICE (device), NM_DEVICE_TYPE_WIFI);
|
||||
}
|
||||
|
||||
static void
|
||||
|
|
|
|||
|
|
@ -33,6 +33,7 @@
|
|||
#include "nm-object-cache.h"
|
||||
#include "nm-dbus-glib-types.h"
|
||||
#include "nm-types-private.h"
|
||||
#include "nm-device-private.h"
|
||||
|
||||
G_DEFINE_TYPE (NMDeviceWimax, nm_device_wimax, NM_TYPE_DEVICE)
|
||||
|
||||
|
|
@ -397,8 +398,9 @@ connection_valid (NMDevice *device, NMConnection *connection)
|
|||
/**************************************************************/
|
||||
|
||||
static void
|
||||
nm_device_wimax_init (NMDeviceWimax *wimax)
|
||||
nm_device_wimax_init (NMDeviceWimax *device)
|
||||
{
|
||||
nm_device_set_device_type (NM_DEVICE (device), NM_DEVICE_TYPE_WIMAX);
|
||||
}
|
||||
|
||||
static void
|
||||
|
|
|
|||
|
|
@ -196,6 +196,34 @@ device_state_changed (DBusGProxy *proxy,
|
|||
}
|
||||
}
|
||||
|
||||
static GType
|
||||
_nm_device_gtype_from_dtype (NMDeviceType dtype)
|
||||
{
|
||||
switch (dtype) {
|
||||
case NM_DEVICE_TYPE_ETHERNET:
|
||||
return NM_TYPE_DEVICE_ETHERNET;
|
||||
case NM_DEVICE_TYPE_WIFI:
|
||||
return NM_TYPE_DEVICE_WIFI;
|
||||
case NM_DEVICE_TYPE_MODEM:
|
||||
return NM_TYPE_DEVICE_MODEM;
|
||||
case NM_DEVICE_TYPE_BT:
|
||||
return NM_TYPE_DEVICE_BT;
|
||||
case NM_DEVICE_TYPE_OLPC_MESH:
|
||||
return NM_TYPE_DEVICE_OLPC_MESH;
|
||||
case NM_DEVICE_TYPE_WIMAX:
|
||||
return NM_TYPE_DEVICE_WIMAX;
|
||||
case NM_DEVICE_TYPE_INFINIBAND:
|
||||
return NM_TYPE_DEVICE_INFINIBAND;
|
||||
case NM_DEVICE_TYPE_BOND:
|
||||
return NM_TYPE_DEVICE_BOND;
|
||||
case NM_DEVICE_TYPE_VLAN:
|
||||
return NM_TYPE_DEVICE_VLAN;
|
||||
default:
|
||||
g_warning ("Unknown device type %d", dtype);
|
||||
return G_TYPE_INVALID;
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
constructed (GObject *object)
|
||||
{
|
||||
|
|
@ -204,6 +232,10 @@ constructed (GObject *object)
|
|||
G_OBJECT_CLASS (nm_device_parent_class)->constructed (object);
|
||||
|
||||
priv = NM_DEVICE_GET_PRIVATE (object);
|
||||
/* Catch failure of subclasses to call nm_device_set_device_type() */
|
||||
g_warn_if_fail (priv->device_type != NM_DEVICE_TYPE_UNKNOWN);
|
||||
/* Catch a subclass setting the wrong type */
|
||||
g_warn_if_fail (G_OBJECT_TYPE (object) == _nm_device_gtype_from_dtype (priv->device_type));
|
||||
|
||||
priv->proxy = dbus_g_proxy_new_for_name (nm_object_get_connection (NM_OBJECT (object)),
|
||||
NM_DBUS_SERVICE,
|
||||
|
|
@ -418,7 +450,7 @@ nm_device_class_init (NMDeviceClass *device_class)
|
|||
"Device Type",
|
||||
"Numeric device type (ie ethernet, wifi, etc)",
|
||||
NM_DEVICE_TYPE_UNKNOWN, G_MAXUINT32, NM_DEVICE_TYPE_UNKNOWN,
|
||||
G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY));
|
||||
G_PARAM_READABLE));
|
||||
/**
|
||||
* NMDevice:udi:
|
||||
*
|
||||
|
|
@ -627,32 +659,27 @@ nm_device_class_init (NMDeviceClass *device_class)
|
|||
G_TYPE_UINT, G_TYPE_UINT, G_TYPE_UINT);
|
||||
}
|
||||
|
||||
static GType
|
||||
_nm_device_gtype_from_dtype (NMDeviceType dtype)
|
||||
/**
|
||||
* nm_device_set_device_type:
|
||||
* @device: the device
|
||||
* @dtype: the NM device type
|
||||
*
|
||||
* Sets the NM device type if it wasn't set during construction. INTERNAL
|
||||
* ONLY METHOD.
|
||||
**/
|
||||
void
|
||||
nm_device_set_device_type (NMDevice *device, NMDeviceType dtype)
|
||||
{
|
||||
switch (dtype) {
|
||||
case NM_DEVICE_TYPE_ETHERNET:
|
||||
return NM_TYPE_DEVICE_ETHERNET;
|
||||
case NM_DEVICE_TYPE_WIFI:
|
||||
return NM_TYPE_DEVICE_WIFI;
|
||||
case NM_DEVICE_TYPE_MODEM:
|
||||
return NM_TYPE_DEVICE_MODEM;
|
||||
case NM_DEVICE_TYPE_BT:
|
||||
return NM_TYPE_DEVICE_BT;
|
||||
case NM_DEVICE_TYPE_OLPC_MESH:
|
||||
return NM_TYPE_DEVICE_OLPC_MESH;
|
||||
case NM_DEVICE_TYPE_WIMAX:
|
||||
return NM_TYPE_DEVICE_WIMAX;
|
||||
case NM_DEVICE_TYPE_INFINIBAND:
|
||||
return NM_TYPE_DEVICE_INFINIBAND;
|
||||
case NM_DEVICE_TYPE_BOND:
|
||||
return NM_TYPE_DEVICE_BOND;
|
||||
case NM_DEVICE_TYPE_VLAN:
|
||||
return NM_TYPE_DEVICE_VLAN;
|
||||
default:
|
||||
g_warning ("Unknown device type %d", dtype);
|
||||
return G_TYPE_INVALID;
|
||||
}
|
||||
NMDevicePrivate *priv;
|
||||
|
||||
g_return_if_fail (device != NULL);
|
||||
g_return_if_fail (dtype != NM_DEVICE_TYPE_UNKNOWN);
|
||||
|
||||
priv = NM_DEVICE_GET_PRIVATE (device);
|
||||
if (priv->device_type == NM_DEVICE_TYPE_UNKNOWN)
|
||||
priv->device_type = dtype;
|
||||
else
|
||||
g_warn_if_fail (dtype == priv->device_type);
|
||||
}
|
||||
|
||||
static GType
|
||||
|
|
@ -823,40 +850,9 @@ nm_device_get_ip_iface (NMDevice *device)
|
|||
NMDeviceType
|
||||
nm_device_get_device_type (NMDevice *self)
|
||||
{
|
||||
NMDevicePrivate *priv;
|
||||
|
||||
g_return_val_if_fail (NM_IS_DEVICE (self), NM_DEVICE_TYPE_UNKNOWN);
|
||||
|
||||
priv = NM_DEVICE_GET_PRIVATE (self);
|
||||
|
||||
/* Fill this in if it wasn't set at construct time.
|
||||
* FIXME: make the device subclasses do this themselves through a private
|
||||
* NMDevice function.
|
||||
*/
|
||||
if (priv->device_type == NM_DEVICE_TYPE_UNKNOWN) {
|
||||
if (NM_IS_DEVICE_ETHERNET (self))
|
||||
priv->device_type = NM_DEVICE_TYPE_ETHERNET;
|
||||
else if (NM_IS_DEVICE_WIFI (self))
|
||||
priv->device_type = NM_DEVICE_TYPE_WIFI;
|
||||
else if (NM_IS_DEVICE_MODEM (self))
|
||||
priv->device_type = NM_DEVICE_TYPE_MODEM;
|
||||
else if (NM_IS_DEVICE_BT (self))
|
||||
priv->device_type = NM_DEVICE_TYPE_BT;
|
||||
else if (NM_IS_DEVICE_OLPC_MESH (self))
|
||||
priv->device_type = NM_DEVICE_TYPE_OLPC_MESH;
|
||||
else if (NM_IS_DEVICE_WIMAX (self))
|
||||
priv->device_type = NM_DEVICE_TYPE_WIMAX;
|
||||
else if (NM_IS_DEVICE_INFINIBAND (self))
|
||||
priv->device_type = NM_DEVICE_TYPE_INFINIBAND;
|
||||
else if (NM_IS_DEVICE_BOND (self))
|
||||
priv->device_type = NM_DEVICE_TYPE_BOND;
|
||||
else if (NM_IS_DEVICE_VLAN (self))
|
||||
priv->device_type = NM_DEVICE_TYPE_VLAN;
|
||||
else
|
||||
g_warn_if_reached ();
|
||||
}
|
||||
|
||||
return priv->device_type;
|
||||
return NM_DEVICE_GET_PRIVATE (self)->device_type;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue