core: add a 'type-desc' property to NMDeviceInterface and use it

instead of littering the code with NM_IS_*.
This commit is contained in:
Dan Williams
2009-07-07 14:24:12 -04:00
parent d2e88e27b7
commit 3cdb0f6c7a
10 changed files with 50 additions and 22 deletions

View File

@@ -77,6 +77,7 @@ nm_modem_cdma_new (const char *path,
NM_DEVICE_INTERFACE_DRIVER, driver, NM_DEVICE_INTERFACE_DRIVER, driver,
NM_MODEM_PATH, path, NM_MODEM_PATH, path,
NM_MODEM_DEVICE, device, NM_MODEM_DEVICE, device,
NM_DEVICE_INTERFACE_TYPE_DESC, "CDMA",
NULL); NULL);
} }

View File

@@ -97,6 +97,7 @@ nm_modem_gsm_new (const char *path,
NM_MODEM_PATH, path, NM_MODEM_PATH, path,
NM_MODEM_IP_METHOD, ip_method, NM_MODEM_IP_METHOD, ip_method,
NM_MODEM_DEVICE, device, NM_MODEM_DEVICE, device,
NM_DEVICE_INTERFACE_TYPE_DESC, "GSM",
NULL); NULL);
} }

View File

@@ -142,6 +142,7 @@ nm_device_bt_new (const char *udi,
NM_DEVICE_BT_NAME, name, NM_DEVICE_BT_NAME, name,
NM_DEVICE_BT_CAPABILITIES, capabilities, NM_DEVICE_BT_CAPABILITIES, capabilities,
NM_DEVICE_INTERFACE_MANAGED, managed, NM_DEVICE_INTERFACE_MANAGED, managed,
NM_DEVICE_INTERFACE_TYPE_DESC, "Bluetooth",
NULL); NULL);
} }

View File

@@ -399,6 +399,7 @@ nm_device_ethernet_new (const char *udi,
NM_DEVICE_INTERFACE_IFACE, iface, NM_DEVICE_INTERFACE_IFACE, iface,
NM_DEVICE_INTERFACE_DRIVER, driver, NM_DEVICE_INTERFACE_DRIVER, driver,
NM_DEVICE_ETHERNET_IFINDEX, ifindex, NM_DEVICE_ETHERNET_IFINDEX, ifindex,
NM_DEVICE_INTERFACE_TYPE_DESC, "Ethernet",
NULL); NULL);
} }

View File

@@ -146,6 +146,14 @@ nm_device_interface_init (gpointer g_iface)
FALSE, FALSE,
G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY)); 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 */ /* Signals */
g_signal_new ("state-changed", g_signal_new ("state-changed",
iface_type, iface_type,

View File

@@ -51,6 +51,7 @@ typedef enum
#define NM_DEVICE_INTERFACE_STATE "state" #define NM_DEVICE_INTERFACE_STATE "state"
#define NM_DEVICE_INTERFACE_DEVICE_TYPE "device-type" /* ugh */ #define NM_DEVICE_INTERFACE_DEVICE_TYPE "device-type" /* ugh */
#define NM_DEVICE_INTERFACE_MANAGED "managed" #define NM_DEVICE_INTERFACE_MANAGED "managed"
#define NM_DEVICE_INTERFACE_TYPE_DESC "type-desc" /* Internal only */
typedef enum { typedef enum {
NM_DEVICE_INTERFACE_PROP_FIRST = 0x1000, NM_DEVICE_INTERFACE_PROP_FIRST = 0x1000,
@@ -65,6 +66,7 @@ typedef enum {
NM_DEVICE_INTERFACE_PROP_STATE, NM_DEVICE_INTERFACE_PROP_STATE,
NM_DEVICE_INTERFACE_PROP_DEVICE_TYPE, NM_DEVICE_INTERFACE_PROP_DEVICE_TYPE,
NM_DEVICE_INTERFACE_PROP_MANAGED, NM_DEVICE_INTERFACE_PROP_MANAGED,
NM_DEVICE_INTERFACE_PROP_TYPE_DESC
} NMDeviceInterfaceProp; } NMDeviceInterfaceProp;

View File

@@ -3503,6 +3503,7 @@ nm_device_wifi_new (const char *udi,
NM_DEVICE_INTERFACE_IFACE, iface, NM_DEVICE_INTERFACE_IFACE, iface,
NM_DEVICE_INTERFACE_DRIVER, driver, NM_DEVICE_INTERFACE_DRIVER, driver,
NM_DEVICE_WIFI_IFINDEX, ifindex, NM_DEVICE_WIFI_IFINDEX, ifindex,
NM_DEVICE_INTERFACE_TYPE_DESC, "802.11 WiFi",
NULL); NULL);
if (obj == NULL) if (obj == NULL)
return NULL; return NULL;

View File

@@ -75,6 +75,7 @@ struct _NMDevicePrivate
char * iface; /* may change, could be renamed by user */ char * iface; /* may change, could be renamed by user */
char * ip_iface; char * ip_iface;
NMDeviceType type; NMDeviceType type;
char * type_desc;
guint32 capabilities; guint32 capabilities;
char * driver; char * driver;
gboolean managed; /* whether managed by NM or not */ 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 * nm_device_get_act_request
* *
@@ -2211,6 +2220,7 @@ nm_device_finalize (GObject *object)
g_free (self->priv->iface); g_free (self->priv->iface);
g_free (self->priv->ip_iface); g_free (self->priv->ip_iface);
g_free (self->priv->driver); g_free (self->priv->driver);
g_free (self->priv->type_desc);
G_OBJECT_CLASS (nm_device_parent_class)->finalize (object); 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: case NM_DEVICE_INTERFACE_PROP_MANAGED:
priv->managed = g_value_get_boolean (value); priv->managed = g_value_get_boolean (value);
break; break;
case NM_DEVICE_INTERFACE_PROP_TYPE_DESC:
g_free (priv->type_desc);
priv->type_desc = g_value_dup_string (value);
break;
default: default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break; break;
@@ -2300,6 +2314,9 @@ get_property (GObject *object, guint prop_id,
case NM_DEVICE_INTERFACE_PROP_MANAGED: case NM_DEVICE_INTERFACE_PROP_MANAGED:
g_value_set_boolean (value, priv->managed); g_value_set_boolean (value, priv->managed);
break; break;
case NM_DEVICE_INTERFACE_PROP_TYPE_DESC:
g_value_set_string (value, priv->type_desc);
break;
default: default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break; break;
@@ -2370,6 +2387,10 @@ nm_device_class_init (NMDeviceClass *klass)
g_object_class_override_property (object_class, g_object_class_override_property (object_class,
NM_DEVICE_INTERFACE_PROP_MANAGED, NM_DEVICE_INTERFACE_PROP_MANAGED,
NM_DEVICE_INTERFACE_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 static gboolean

View File

@@ -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_iface (NMDevice *dev);
const char * nm_device_get_ip_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_driver (NMDevice *dev);
const char * nm_device_get_type_desc (NMDevice *dev);
NMDeviceType nm_device_get_device_type (NMDevice *dev); NMDeviceType nm_device_get_device_type (NMDevice *dev);
guint32 nm_device_get_capabilities (NMDevice *dev); guint32 nm_device_get_capabilities (NMDevice *dev);

View File

@@ -1134,7 +1134,7 @@ static void
add_device (NMManager *self, NMDevice *device) add_device (NMManager *self, NMDevice *device)
{ {
NMManagerPrivate *priv = NM_MANAGER_GET_PRIVATE (self); NMManagerPrivate *priv = NM_MANAGER_GET_PRIVATE (self);
const char *iface, *driver; const char *iface, *driver, *type_desc;
char *path; char *path;
static guint32 devcount = 0; static guint32 devcount = 0;
const GSList *unmanaged_specs; 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); 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); 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) if (!driver)
driver = "unknown"; driver = "unknown";
nm_info ("(%s): new %s device (driver: '%s')", iface, type_desc, driver);
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 ();
path = g_strdup_printf ("/org/freedesktop/NetworkManager/Devices/%d", devcount++); path = g_strdup_printf ("/org/freedesktop/NetworkManager/Devices/%d", devcount++);
nm_device_set_path (device, path); nm_device_set_path (device, path);