core: add a 'type-desc' property to NMDeviceInterface and use it
instead of littering the code with NM_IS_*.
This commit is contained in:
@@ -77,6 +77,7 @@ nm_modem_cdma_new (const char *path,
|
||||
NM_DEVICE_INTERFACE_DRIVER, driver,
|
||||
NM_MODEM_PATH, path,
|
||||
NM_MODEM_DEVICE, device,
|
||||
NM_DEVICE_INTERFACE_TYPE_DESC, "CDMA",
|
||||
NULL);
|
||||
}
|
||||
|
||||
|
@@ -97,6 +97,7 @@ nm_modem_gsm_new (const char *path,
|
||||
NM_MODEM_PATH, path,
|
||||
NM_MODEM_IP_METHOD, ip_method,
|
||||
NM_MODEM_DEVICE, device,
|
||||
NM_DEVICE_INTERFACE_TYPE_DESC, "GSM",
|
||||
NULL);
|
||||
}
|
||||
|
||||
|
@@ -142,6 +142,7 @@ nm_device_bt_new (const char *udi,
|
||||
NM_DEVICE_BT_NAME, name,
|
||||
NM_DEVICE_BT_CAPABILITIES, capabilities,
|
||||
NM_DEVICE_INTERFACE_MANAGED, managed,
|
||||
NM_DEVICE_INTERFACE_TYPE_DESC, "Bluetooth",
|
||||
NULL);
|
||||
}
|
||||
|
||||
|
@@ -399,6 +399,7 @@ nm_device_ethernet_new (const char *udi,
|
||||
NM_DEVICE_INTERFACE_IFACE, iface,
|
||||
NM_DEVICE_INTERFACE_DRIVER, driver,
|
||||
NM_DEVICE_ETHERNET_IFINDEX, ifindex,
|
||||
NM_DEVICE_INTERFACE_TYPE_DESC, "Ethernet",
|
||||
NULL);
|
||||
}
|
||||
|
||||
|
@@ -146,6 +146,14 @@ nm_device_interface_init (gpointer g_iface)
|
||||
FALSE,
|
||||
G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY));
|
||||
|
||||
g_object_interface_install_property
|
||||
(g_iface,
|
||||
g_param_spec_string (NM_DEVICE_INTERFACE_TYPE_DESC,
|
||||
"Type Description",
|
||||
"Device type description",
|
||||
NULL,
|
||||
G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY));
|
||||
|
||||
/* Signals */
|
||||
g_signal_new ("state-changed",
|
||||
iface_type,
|
||||
|
@@ -51,6 +51,7 @@ typedef enum
|
||||
#define NM_DEVICE_INTERFACE_STATE "state"
|
||||
#define NM_DEVICE_INTERFACE_DEVICE_TYPE "device-type" /* ugh */
|
||||
#define NM_DEVICE_INTERFACE_MANAGED "managed"
|
||||
#define NM_DEVICE_INTERFACE_TYPE_DESC "type-desc" /* Internal only */
|
||||
|
||||
typedef enum {
|
||||
NM_DEVICE_INTERFACE_PROP_FIRST = 0x1000,
|
||||
@@ -65,6 +66,7 @@ typedef enum {
|
||||
NM_DEVICE_INTERFACE_PROP_STATE,
|
||||
NM_DEVICE_INTERFACE_PROP_DEVICE_TYPE,
|
||||
NM_DEVICE_INTERFACE_PROP_MANAGED,
|
||||
NM_DEVICE_INTERFACE_PROP_TYPE_DESC
|
||||
} NMDeviceInterfaceProp;
|
||||
|
||||
|
||||
|
@@ -3503,6 +3503,7 @@ nm_device_wifi_new (const char *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;
|
||||
|
@@ -75,6 +75,7 @@ struct _NMDevicePrivate
|
||||
char * iface; /* may change, could be renamed by user */
|
||||
char * ip_iface;
|
||||
NMDeviceType type;
|
||||
char * type_desc;
|
||||
guint32 capabilities;
|
||||
char * driver;
|
||||
gboolean managed; /* whether managed by NM or not */
|
||||
@@ -338,6 +339,14 @@ real_get_type_capabilities (NMDevice *self)
|
||||
}
|
||||
|
||||
|
||||
const char *
|
||||
nm_device_get_type_desc (NMDevice *self)
|
||||
{
|
||||
g_return_val_if_fail (self != NULL, NULL);
|
||||
|
||||
return self->priv->type_desc;
|
||||
}
|
||||
|
||||
/*
|
||||
* nm_device_get_act_request
|
||||
*
|
||||
@@ -2211,6 +2220,7 @@ nm_device_finalize (GObject *object)
|
||||
g_free (self->priv->iface);
|
||||
g_free (self->priv->ip_iface);
|
||||
g_free (self->priv->driver);
|
||||
g_free (self->priv->type_desc);
|
||||
|
||||
G_OBJECT_CLASS (nm_device_parent_class)->finalize (object);
|
||||
}
|
||||
@@ -2243,6 +2253,10 @@ set_property (GObject *object, guint prop_id,
|
||||
case NM_DEVICE_INTERFACE_PROP_MANAGED:
|
||||
priv->managed = g_value_get_boolean (value);
|
||||
break;
|
||||
case NM_DEVICE_INTERFACE_PROP_TYPE_DESC:
|
||||
g_free (priv->type_desc);
|
||||
priv->type_desc = g_value_dup_string (value);
|
||||
break;
|
||||
default:
|
||||
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
||||
break;
|
||||
@@ -2300,6 +2314,9 @@ get_property (GObject *object, guint prop_id,
|
||||
case NM_DEVICE_INTERFACE_PROP_MANAGED:
|
||||
g_value_set_boolean (value, priv->managed);
|
||||
break;
|
||||
case NM_DEVICE_INTERFACE_PROP_TYPE_DESC:
|
||||
g_value_set_string (value, priv->type_desc);
|
||||
break;
|
||||
default:
|
||||
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
||||
break;
|
||||
@@ -2370,6 +2387,10 @@ nm_device_class_init (NMDeviceClass *klass)
|
||||
g_object_class_override_property (object_class,
|
||||
NM_DEVICE_INTERFACE_PROP_MANAGED,
|
||||
NM_DEVICE_INTERFACE_MANAGED);
|
||||
|
||||
g_object_class_override_property (object_class,
|
||||
NM_DEVICE_INTERFACE_PROP_TYPE_DESC,
|
||||
NM_DEVICE_INTERFACE_TYPE_DESC);
|
||||
}
|
||||
|
||||
static gboolean
|
||||
|
@@ -127,6 +127,7 @@ const char * nm_device_get_udi (NMDevice *dev);
|
||||
const char * nm_device_get_iface (NMDevice *dev);
|
||||
const char * nm_device_get_ip_iface (NMDevice *dev);
|
||||
const char * nm_device_get_driver (NMDevice *dev);
|
||||
const char * nm_device_get_type_desc (NMDevice *dev);
|
||||
|
||||
NMDeviceType nm_device_get_device_type (NMDevice *dev);
|
||||
guint32 nm_device_get_capabilities (NMDevice *dev);
|
||||
|
@@ -1134,7 +1134,7 @@ static void
|
||||
add_device (NMManager *self, NMDevice *device)
|
||||
{
|
||||
NMManagerPrivate *priv = NM_MANAGER_GET_PRIVATE (self);
|
||||
const char *iface, *driver;
|
||||
const char *iface, *driver, *type_desc;
|
||||
char *path;
|
||||
static guint32 devcount = 0;
|
||||
const GSList *unmanaged_specs;
|
||||
@@ -1157,23 +1157,14 @@ add_device (NMManager *self, NMDevice *device)
|
||||
nm_device_wifi_set_enabled (NM_DEVICE_WIFI (device), priv->wireless_enabled);
|
||||
}
|
||||
|
||||
type_desc = nm_device_get_type_desc (device);
|
||||
g_assert (type_desc);
|
||||
iface = nm_device_get_iface (device);
|
||||
driver = nm_device_get_driver (NM_DEVICE (device));
|
||||
g_assert (iface);
|
||||
driver = nm_device_get_driver (device);
|
||||
if (!driver)
|
||||
driver = "unknown";
|
||||
|
||||
if (NM_IS_DEVICE_ETHERNET (device))
|
||||
nm_info ("(%s): new Ethernet device (driver: '%s')", iface, driver);
|
||||
else if (NM_IS_DEVICE_WIFI (device))
|
||||
nm_info ("(%s): new 802.11 WiFi device (driver: '%s')", iface, driver);
|
||||
else if (nm_device_get_device_type (device) == NM_DEVICE_TYPE_GSM)
|
||||
nm_info ("(%s): new GSM device (driver: '%s')", iface, driver);
|
||||
else if (nm_device_get_device_type (device) == NM_DEVICE_TYPE_CDMA)
|
||||
nm_info ("(%s): new CDMA device (driver: '%s')", iface, driver);
|
||||
else if (nm_device_get_device_type (device) == NM_DEVICE_TYPE_BT)
|
||||
nm_info ("(%s): new Bluetooth device", iface);
|
||||
else
|
||||
g_assert_not_reached ();
|
||||
nm_info ("(%s): new %s device (driver: '%s')", iface, type_desc, driver);
|
||||
|
||||
path = g_strdup_printf ("/org/freedesktop/NetworkManager/Devices/%d", devcount++);
|
||||
nm_device_set_path (device, path);
|
||||
|
Reference in New Issue
Block a user