libnm-glib: add NMDevice:physical-port-id property

Add the physical-port-id property to NMDevice so that clients can
recognize NPAR/SR-IOV devices.
This commit is contained in:
Dan Winship 2013-10-11 14:59:26 -04:00
parent b7300bbe5a
commit 47cc8b25f2
3 changed files with 58 additions and 0 deletions

View file

@ -130,6 +130,7 @@ global:
nm_device_get_ip6_config;
nm_device_get_ip_iface;
nm_device_get_managed;
nm_device_get_physical_port_id;
nm_device_get_product;
nm_device_get_state;
nm_device_get_state_reason;

View file

@ -96,6 +96,8 @@ typedef struct {
GUdevClient *client;
char *product;
char *vendor;
char *physical_port_id;
} NMDevicePrivate;
enum {
@ -121,6 +123,7 @@ enum {
PROP_DEVICE_TYPE,
PROP_ACTIVE_CONNECTION,
PROP_AVAILABLE_CONNECTIONS,
PROP_PHYSICAL_PORT_ID,
LAST_PROP
};
@ -199,6 +202,7 @@ register_properties (NMDevice *device)
{ NM_DEVICE_STATE_REASON, &priv->state, demarshal_state_reason },
{ NM_DEVICE_ACTIVE_CONNECTION, &priv->active_connection, NULL, NM_TYPE_ACTIVE_CONNECTION },
{ NM_DEVICE_AVAILABLE_CONNECTIONS, &priv->available_connections, NULL, NM_TYPE_REMOTE_CONNECTION },
{ NM_DEVICE_PHYSICAL_PORT_ID, &priv->physical_port_id },
/* Properties that exist in D-Bus but that we don't track */
{ "ip4-address", NULL },
@ -389,6 +393,7 @@ finalize (GObject *object)
g_free (priv->product);
g_free (priv->vendor);
g_free (priv->type_description);
g_free (priv->physical_port_id);
G_OBJECT_CLASS (nm_device_parent_class)->finalize (object);
}
@ -473,6 +478,9 @@ get_property (GObject *object,
case PROP_VENDOR:
g_value_set_string (value, nm_device_get_vendor (device));
break;
case PROP_PHYSICAL_PORT_ID:
g_value_set_string (value, nm_device_get_physical_port_id (device));
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
@ -804,6 +812,22 @@ nm_device_class_init (NMDeviceClass *device_class)
NULL,
G_PARAM_READABLE));
/**
* NMDevice:physical-port-id:
*
* The physical port ID of the device. (See
* nm_device_get_physical_port_id().)
*
* Since: 0.9.10
**/
g_object_class_install_property
(object_class, PROP_PHYSICAL_PORT_ID,
g_param_spec_string (NM_DEVICE_PHYSICAL_PORT_ID,
"Physical Port ID",
"Physical port ID",
NULL,
G_PARAM_READABLE));
/* signals */
/**
@ -1517,6 +1541,37 @@ nm_device_get_vendor (NMDevice *device)
return priv->vendor;
}
/**
* nm_device_get_physical_port_id:
* @device: a #NMDevice
*
* Gets the physical port ID of the #NMDevice. If non-%NULL, this is
* an opaque string that can be used to recognize when
* seemingly-unrelated #NMDevices are actually just different virtual
* ports on a single physical port. (Eg, NPAR / SR-IOV.)
*
* Returns: the physical port ID of the device, or %NULL if the port
* ID is unknown. This is the internal string used by the device and
* must not be modified.
*
* Since: 0.9.10
**/
const char *
nm_device_get_physical_port_id (NMDevice *device)
{
NMDevicePrivate *priv;
g_return_val_if_fail (NM_IS_DEVICE (device), NULL);
priv = NM_DEVICE_GET_PRIVATE (device);
_nm_object_ensure_inited (NM_OBJECT (device));
if (priv->physical_port_id && *priv->physical_port_id)
return priv->physical_port_id;
else
return NULL;
}
typedef struct {
NMDevice *device;
NMDeviceDeactivateFn fn;

View file

@ -80,6 +80,7 @@ GQuark nm_device_error_quark (void);
#define NM_DEVICE_AVAILABLE_CONNECTIONS "available-connections"
#define NM_DEVICE_VENDOR "vendor"
#define NM_DEVICE_PRODUCT "product"
#define NM_DEVICE_PHYSICAL_PORT_ID "physical-port-id"
typedef struct {
NMObject parent;
@ -135,6 +136,7 @@ NMActiveConnection * nm_device_get_active_connection(NMDevice *device);
const GPtrArray * nm_device_get_available_connections(NMDevice *device);
const char * nm_device_get_product (NMDevice *device);
const char * nm_device_get_vendor (NMDevice *device);
const char * nm_device_get_physical_port_id (NMDevice *device);
typedef void (*NMDeviceDeactivateFn) (NMDevice *device, GError *error, gpointer user_data);