libnm-glib: add 'autoconnect' property for devices

This commit is contained in:
Jiří Klimeš
2012-05-14 17:09:36 +02:00
parent d1cbeebfc6
commit e0329b44c4
3 changed files with 73 additions and 0 deletions

View File

@@ -89,6 +89,7 @@ global:
nm_device_ethernet_new;
nm_device_filter_connections;
nm_device_get_active_connection;
nm_device_get_autoconnect;
nm_device_get_capabilities;
nm_device_get_device_type;
nm_device_get_dhcp4_config;
@@ -125,6 +126,7 @@ global:
nm_device_olpc_mesh_get_hw_address;
nm_device_olpc_mesh_get_type;
nm_device_olpc_mesh_new;
nm_device_set_autoconnect;
nm_device_vlan_error_get_type;
nm_device_vlan_error_quark;
nm_device_vlan_get_carrier;

View File

@@ -71,6 +71,7 @@ typedef struct {
NMDeviceCapabilities capabilities;
gboolean managed;
gboolean firmware_missing;
gboolean autoconnect;
NMIP4Config *ip4_config;
NMDHCP4Config *dhcp4_config;
NMIP6Config *ip6_config;
@@ -92,6 +93,7 @@ enum {
PROP_DRIVER,
PROP_CAPABILITIES,
PROP_MANAGED,
PROP_AUTOCONNECT,
PROP_FIRMWARE_MISSING,
PROP_IP4_CONFIG,
PROP_DHCP4_CONFIG,
@@ -154,6 +156,7 @@ register_properties (NMDevice *device)
{ NM_DEVICE_DRIVER, &priv->driver },
{ NM_DEVICE_CAPABILITIES, &priv->capabilities },
{ NM_DEVICE_MANAGED, &priv->managed },
{ NM_DEVICE_AUTOCONNECT, &priv->autoconnect },
{ NM_DEVICE_FIRMWARE_MISSING, &priv->firmware_missing },
{ NM_DEVICE_IP4_CONFIG, &priv->ip4_config, NULL, NM_TYPE_IP4_CONFIG },
{ NM_DEVICE_DHCP4_CONFIG, &priv->dhcp4_config, NULL, NM_TYPE_DHCP4_CONFIG },
@@ -326,6 +329,9 @@ get_property (GObject *object,
case PROP_MANAGED:
g_value_set_boolean (value, nm_device_get_managed (device));
break;
case PROP_AUTOCONNECT:
g_value_set_boolean (value, nm_device_get_autoconnect (device));
break;
case PROP_FIRMWARE_MISSING:
g_value_set_boolean (value, nm_device_get_firmware_missing (device));
break;
@@ -375,12 +381,18 @@ set_property (GObject *object,
{
NMDevice *self = NM_DEVICE (object);
NMDevicePrivate *priv = NM_DEVICE_GET_PRIVATE (self);
gboolean b;
switch (prop_id) {
case PROP_DEVICE_TYPE:
/* Construct only */
priv->device_type = g_value_get_uint (value);
break;
case PROP_AUTOCONNECT:
b = g_value_get_boolean (value);
if (priv->autoconnect != b)
nm_device_set_autoconnect (NM_DEVICE (object), b);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
@@ -499,6 +511,19 @@ nm_device_class_init (NMDeviceClass *device_class)
FALSE,
G_PARAM_READABLE));
/**
* NMDevice:autoconnect:
*
* Whether the device can auto-activate a connection.
**/
g_object_class_install_property
(object_class, PROP_AUTOCONNECT,
g_param_spec_boolean (NM_DEVICE_AUTOCONNECT,
"Autoconnect",
"Autoconnect",
TRUE,
G_PARAM_READWRITE));
/**
* NMDevice:firmware-missing:
*
@@ -917,6 +942,49 @@ nm_device_get_managed (NMDevice *device)
return NM_DEVICE_GET_PRIVATE (device)->managed;
}
/**
* nm_device_get_autoconnect:
* @device: a #NMDevice
*
* Whether the #NMDevice can be autoconnected.
*
* Returns: %TRUE if the device is allowed to be autoconnected
**/
gboolean
nm_device_get_autoconnect (NMDevice *device)
{
g_return_val_if_fail (NM_IS_DEVICE (device), FALSE);
_nm_object_ensure_inited (NM_OBJECT (device));
return NM_DEVICE_GET_PRIVATE (device)->autoconnect;
}
/**
* nm_device_set_autoconnect:
* @device: a #NMDevice
* @autoconnect: %TRUE to enable autoconnecting
*
* Enables or disables automatic activation of the #NMDevice.
**/
void
nm_device_set_autoconnect (NMDevice *device, gboolean autoconnect)
{
GValue value = {0,};
g_return_if_fail (NM_IS_DEVICE (device));
g_value_init (&value, G_TYPE_BOOLEAN);
g_value_set_boolean (&value, autoconnect);
NM_DEVICE_GET_PRIVATE (device)->autoconnect = autoconnect;
_nm_object_set_property (NM_OBJECT (device),
NM_DBUS_INTERFACE_DEVICE,
"Autoconnect",
&value);
}
/**
* nm_device_get_firmware_missing:
* @device: a #NMDevice

View File

@@ -52,6 +52,7 @@ G_BEGIN_DECLS
#define NM_DEVICE_DRIVER "driver"
#define NM_DEVICE_CAPABILITIES "capabilities"
#define NM_DEVICE_MANAGED "managed"
#define NM_DEVICE_AUTOCONNECT "autoconnect"
#define NM_DEVICE_FIRMWARE_MISSING "firmware-missing"
#define NM_DEVICE_IP4_CONFIG "ip4-config"
#define NM_DEVICE_DHCP4_CONFIG "dhcp4-config"
@@ -100,6 +101,8 @@ const char * nm_device_get_udi (NMDevice *device);
const char * nm_device_get_driver (NMDevice *device);
NMDeviceCapabilities nm_device_get_capabilities (NMDevice *device);
gboolean nm_device_get_managed (NMDevice *device);
gboolean nm_device_get_autoconnect (NMDevice *device);
void nm_device_set_autoconnect (NMDevice *device, gboolean autoconnect);
gboolean nm_device_get_firmware_missing (NMDevice *device);
NMIP4Config * nm_device_get_ip4_config (NMDevice *device);
NMDHCP4Config * nm_device_get_dhcp4_config (NMDevice *device);