libnm-glib, cli: add nm_device_get_type_description
Add a new libnm-glib method to get the type description for a device, and use it in nmcli. For most types, the type description is based on the class name, but for NMDeviceGeneric, it comes from the :type-description property.
This commit is contained in:
@@ -286,49 +286,6 @@ quit (void)
|
||||
g_main_loop_quit (loop); /* quit main loop */
|
||||
}
|
||||
|
||||
/* Convert device type to string. Use setting names strings to match with
|
||||
* connection type names.
|
||||
*/
|
||||
static const char *
|
||||
device_type_to_string (NMDevice *device)
|
||||
{
|
||||
NMDeviceModemCapabilities caps = NM_DEVICE_MODEM_CAPABILITY_NONE;
|
||||
|
||||
switch (nm_device_get_device_type (device)) {
|
||||
case NM_DEVICE_TYPE_ETHERNET:
|
||||
return NM_SETTING_WIRED_SETTING_NAME;
|
||||
case NM_DEVICE_TYPE_ADSL:
|
||||
return NM_SETTING_ADSL_SETTING_NAME;
|
||||
case NM_DEVICE_TYPE_WIFI:
|
||||
return NM_SETTING_WIRELESS_SETTING_NAME;
|
||||
case NM_DEVICE_TYPE_MODEM:
|
||||
caps = nm_device_modem_get_current_capabilities (NM_DEVICE_MODEM (device));
|
||||
if (caps & NM_DEVICE_MODEM_CAPABILITY_GSM_UMTS)
|
||||
return NM_SETTING_GSM_SETTING_NAME;
|
||||
else if (caps & NM_DEVICE_MODEM_CAPABILITY_CDMA_EVDO)
|
||||
return NM_SETTING_CDMA_SETTING_NAME;
|
||||
return _("Unknown");
|
||||
case NM_DEVICE_TYPE_BT:
|
||||
return NM_SETTING_BLUETOOTH_SETTING_NAME;
|
||||
case NM_DEVICE_TYPE_OLPC_MESH:
|
||||
return NM_SETTING_OLPC_MESH_SETTING_NAME;
|
||||
#if WITH_WIMAX
|
||||
case NM_DEVICE_TYPE_WIMAX:
|
||||
return NM_SETTING_WIMAX_SETTING_NAME;
|
||||
#endif
|
||||
case NM_DEVICE_TYPE_INFINIBAND:
|
||||
return NM_SETTING_INFINIBAND_SETTING_NAME;
|
||||
case NM_DEVICE_TYPE_BOND:
|
||||
return NM_SETTING_BOND_SETTING_NAME;
|
||||
case NM_DEVICE_TYPE_VLAN:
|
||||
return NM_SETTING_VLAN_SETTING_NAME;
|
||||
case NM_DEVICE_TYPE_BRIDGE:
|
||||
return NM_SETTING_BRIDGE_SETTING_NAME;
|
||||
default:
|
||||
return _("Unknown");
|
||||
}
|
||||
}
|
||||
|
||||
static char *
|
||||
ap_wpa_rsn_flags_to_string (NM80211ApSecurityFlags flags)
|
||||
{
|
||||
@@ -619,7 +576,7 @@ show_device_info (gpointer data, gpointer user_data)
|
||||
|
||||
nmc->allowed_fields[0].value = (char *) nmc_fields_dev_show_sections[0].name; /* "GENERAL"*/
|
||||
nmc->allowed_fields[1].value = (char *) nm_device_get_iface (device);
|
||||
nmc->allowed_fields[2].value = (char *) device_type_to_string (device);
|
||||
nmc->allowed_fields[2].value = (char *) nm_device_get_type_description (device);
|
||||
nmc->allowed_fields[3].value = (char *) nm_device_get_vendor (device);
|
||||
nmc->allowed_fields[4].value = (char *) nm_device_get_product (device);
|
||||
nmc->allowed_fields[5].value = (char *) (nm_device_get_driver (device) ? nm_device_get_driver (device) : _("(unknown)"));
|
||||
@@ -953,7 +910,7 @@ static void
|
||||
show_device_status (NMDevice *device, NmCli *nmc)
|
||||
{
|
||||
nmc->allowed_fields[0].value = (char *) nm_device_get_iface (device);
|
||||
nmc->allowed_fields[1].value = (char *) device_type_to_string (device);
|
||||
nmc->allowed_fields[1].value = (char *) nm_device_get_type_description (device);
|
||||
nmc->allowed_fields[2].value = (char *) nmc_device_state_to_string (nm_device_get_state (device));
|
||||
nmc->allowed_fields[3].value = (char *) nm_object_get_path (NM_OBJECT (device));
|
||||
|
||||
|
@@ -126,6 +126,7 @@ global:
|
||||
nm_device_get_state;
|
||||
nm_device_get_state_reason;
|
||||
nm_device_get_type;
|
||||
nm_device_get_type_description;
|
||||
nm_device_get_udi;
|
||||
nm_device_get_vendor;
|
||||
nm_device_infiniband_error_get_type;
|
||||
|
@@ -119,6 +119,15 @@ nm_device_generic_get_hw_address (NMDeviceGeneric *device)
|
||||
|
||||
/***********************************************************/
|
||||
|
||||
static const char *
|
||||
get_type_description (NMDevice *device)
|
||||
{
|
||||
NMDeviceGenericPrivate *priv = NM_DEVICE_GENERIC_GET_PRIVATE (device);
|
||||
|
||||
_nm_object_ensure_inited (NM_OBJECT (device));
|
||||
return priv->type_description;
|
||||
}
|
||||
|
||||
static gboolean
|
||||
connection_compatible (NMDevice *device, NMConnection *connection, GError **error)
|
||||
{
|
||||
@@ -235,6 +244,7 @@ nm_device_generic_class_init (NMDeviceGenericClass *klass)
|
||||
object_class->finalize = finalize;
|
||||
object_class->get_property = get_property;
|
||||
|
||||
device_class->get_type_description = get_type_description;
|
||||
device_class->connection_compatible = connection_compatible;
|
||||
|
||||
/**
|
||||
|
@@ -114,6 +114,20 @@ nm_device_modem_get_current_capabilities (NMDeviceModem *self)
|
||||
return NM_DEVICE_MODEM_GET_PRIVATE (self)->current_caps;
|
||||
}
|
||||
|
||||
static const char *
|
||||
get_type_description (NMDevice *device)
|
||||
{
|
||||
NMDeviceModemCapabilities caps;
|
||||
|
||||
caps = nm_device_modem_get_current_capabilities (NM_DEVICE_MODEM (device));
|
||||
if (caps & NM_DEVICE_MODEM_CAPABILITY_GSM_UMTS)
|
||||
return "gsm";
|
||||
else if (caps & NM_DEVICE_MODEM_CAPABILITY_CDMA_EVDO)
|
||||
return "cdma";
|
||||
else
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static gboolean
|
||||
connection_compatible (NMDevice *device, NMConnection *connection, GError **error)
|
||||
{
|
||||
@@ -232,6 +246,8 @@ nm_device_modem_class_init (NMDeviceModemClass *modem_class)
|
||||
object_class->constructed = constructed;
|
||||
object_class->get_property = get_property;
|
||||
object_class->dispose = dispose;
|
||||
|
||||
device_class->get_type_description = get_type_description;
|
||||
device_class->connection_compatible = connection_compatible;
|
||||
|
||||
/**
|
||||
|
@@ -77,6 +77,7 @@ typedef struct {
|
||||
char *driver;
|
||||
char *driver_version;
|
||||
char *firmware_version;
|
||||
char *type_description;
|
||||
NMDeviceCapabilities capabilities;
|
||||
gboolean managed;
|
||||
gboolean firmware_missing;
|
||||
@@ -1083,6 +1084,43 @@ nm_device_get_firmware_version (NMDevice *device)
|
||||
return NM_DEVICE_GET_PRIVATE (device)->firmware_version;
|
||||
}
|
||||
|
||||
/**
|
||||
* nm_device_get_type_description:
|
||||
* @device: a #NMDevice
|
||||
*
|
||||
* Gets a (non-localized) description of the type of device that
|
||||
* @device is.
|
||||
*
|
||||
* Returns: the type description of the device. This is the internal
|
||||
* string used by the device, and must not be modified.
|
||||
*
|
||||
* Since: 0.9.10
|
||||
**/
|
||||
const char *
|
||||
nm_device_get_type_description (NMDevice *device)
|
||||
{
|
||||
NMDevicePrivate *priv = NM_DEVICE_GET_PRIVATE (device);
|
||||
const char *desc, *typename;
|
||||
|
||||
g_return_val_if_fail (NM_IS_DEVICE (device), NULL);
|
||||
|
||||
if (priv->type_description)
|
||||
return priv->type_description;
|
||||
|
||||
if (NM_DEVICE_GET_CLASS (device)->get_type_description) {
|
||||
desc = NM_DEVICE_GET_CLASS (device)->get_type_description (device);
|
||||
if (desc)
|
||||
return desc;
|
||||
}
|
||||
|
||||
typename = G_OBJECT_TYPE_NAME (device);
|
||||
if (g_str_has_prefix (typename, "NMDevice"))
|
||||
typename += 8;
|
||||
priv->type_description = g_ascii_strdown (typename, -1);
|
||||
|
||||
return priv->type_description;
|
||||
}
|
||||
|
||||
/**
|
||||
* nm_device_get_capabilities:
|
||||
* @device: a #NMDevice
|
||||
|
@@ -98,13 +98,14 @@ typedef struct {
|
||||
NMConnection *connection,
|
||||
GError **error);
|
||||
|
||||
const char * (*get_type_description) (NMDevice *device);
|
||||
|
||||
/* Padding for future expansion */
|
||||
void (*_reserved1) (void);
|
||||
void (*_reserved2) (void);
|
||||
void (*_reserved3) (void);
|
||||
void (*_reserved4) (void);
|
||||
void (*_reserved5) (void);
|
||||
void (*_reserved6) (void);
|
||||
} NMDeviceClass;
|
||||
|
||||
GType nm_device_get_type (void);
|
||||
@@ -118,6 +119,7 @@ const char * nm_device_get_udi (NMDevice *device);
|
||||
const char * nm_device_get_driver (NMDevice *device);
|
||||
const char * nm_device_get_driver_version (NMDevice *device);
|
||||
const char * nm_device_get_firmware_version (NMDevice *device);
|
||||
const char * nm_device_get_type_description (NMDevice *device);
|
||||
NMDeviceCapabilities nm_device_get_capabilities (NMDevice *device);
|
||||
gboolean nm_device_get_managed (NMDevice *device);
|
||||
gboolean nm_device_get_autoconnect (NMDevice *device);
|
||||
|
@@ -6,27 +6,6 @@
|
||||
#include "nm-linux-platform.h"
|
||||
#include "nm-fake-platform.h"
|
||||
|
||||
static const char *
|
||||
type_to_string (NMLinkType type)
|
||||
{
|
||||
switch (type) {
|
||||
case NM_LINK_TYPE_LOOPBACK:
|
||||
return "loopback";
|
||||
case NM_LINK_TYPE_ETHERNET:
|
||||
return "ethernet";
|
||||
case NM_LINK_TYPE_DUMMY:
|
||||
return "dummy";
|
||||
case NM_LINK_TYPE_BRIDGE:
|
||||
return "bridge";
|
||||
case NM_LINK_TYPE_BOND:
|
||||
return "bond";
|
||||
case NM_LINK_TYPE_TEAM:
|
||||
return "team";
|
||||
default:
|
||||
return "unknown-type";
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
dump_interface (NMPlatformLink *link)
|
||||
{
|
||||
@@ -45,7 +24,7 @@ dump_interface (NMPlatformLink *link)
|
||||
|
||||
g_assert (link->up || !link->connected);
|
||||
|
||||
printf ("%d: %s: %s", link->ifindex, link->name, type_to_string (link->type));
|
||||
printf ("%d: %s: %s", link->ifindex, link->name, link->type_name);
|
||||
if (link->up)
|
||||
printf (" %s", link->connected ? "CONNECTED" : "DISCONNECTED");
|
||||
else
|
||||
|
Reference in New Issue
Block a user