diff options
author | Antti Kaijanmäki <antti@kaijanmaki.net> | 2008-08-18 08:30:28 +0000 |
---|---|---|
committer | Antti Kaijanmäki <antti@kaijanmaki.net> | 2008-08-18 08:30:28 +0000 |
commit | 2c21a2fe6b0498585fba0beb003ac8aa6351803c (patch) | |
tree | 9544edfe2ed9a6c96eda933c35fb5110f1d666c6 /libnm-glib/nm-device.c | |
parent | e04934d93efba622123809cc767488af673b2967 (diff) | |
download | NetworkManager-mbca.tar.gz |
keep up with trunkmbca
git-svn-id: http://svn-archive.gnome.org/svn/NetworkManager/branches/mbca@3981 4912f4e0-d625-0410-9fb7-b9a5a253dbdc
Diffstat (limited to 'libnm-glib/nm-device.c')
-rw-r--r-- | libnm-glib/nm-device.c | 237 |
1 files changed, 237 insertions, 0 deletions
diff --git a/libnm-glib/nm-device.c b/libnm-glib/nm-device.c index 24ca876cfd..d142bfe29f 100644 --- a/libnm-glib/nm-device.c +++ b/libnm-glib/nm-device.c @@ -28,6 +28,8 @@ typedef struct { gboolean managed; NMIP4Config *ip4_config; gboolean null_ip4_config; + NMDHCP4Config *dhcp4_config; + gboolean null_dhcp4_config; NMDeviceState state; char *product; char *vendor; @@ -41,6 +43,7 @@ enum { PROP_CAPABILITIES, PROP_MANAGED, PROP_IP4_CONFIG, + PROP_DHCP4_CONFIG, PROP_STATE, PROP_PRODUCT, PROP_VENDOR, @@ -106,6 +109,46 @@ demarshal_ip4_config (NMObject *object, GParamSpec *pspec, GValue *value, gpoint return TRUE; } +static gboolean +demarshal_dhcp4_config (NMObject *object, GParamSpec *pspec, GValue *value, gpointer field) +{ + NMDevicePrivate *priv = NM_DEVICE_GET_PRIVATE (object); + const char *path; + NMDHCP4Config *config = NULL; + DBusGConnection *connection; + + if (!G_VALUE_HOLDS (value, DBUS_TYPE_G_OBJECT_PATH)) + return FALSE; + + priv->null_dhcp4_config = FALSE; + + path = g_value_get_boxed (value); + if (path) { + if (!strcmp (path, "/")) + priv->null_dhcp4_config = TRUE; + else { + config = NM_DHCP4_CONFIG (nm_object_cache_get (path)); + if (config) + config = g_object_ref (config); + else { + connection = nm_object_get_connection (object); + config = NM_DHCP4_CONFIG (nm_dhcp4_config_new (connection, path)); + } + } + } + + if (priv->dhcp4_config) { + g_object_unref (priv->dhcp4_config); + priv->dhcp4_config = NULL; + } + + if (config) + priv->dhcp4_config = config; + + nm_object_queue_notify (object, NM_DEVICE_DHCP4_CONFIG); + return TRUE; +} + static void register_for_property_changed (NMDevice *device) { @@ -117,6 +160,7 @@ register_for_property_changed (NMDevice *device) { NM_DEVICE_CAPABILITIES, nm_object_demarshal_generic, &priv->capabilities }, { NM_DEVICE_MANAGED, nm_object_demarshal_generic, &priv->managed }, { NM_DEVICE_IP4_CONFIG, demarshal_ip4_config, &priv->ip4_config }, + { NM_DEVICE_DHCP4_CONFIG, demarshal_dhcp4_config, &priv->dhcp4_config }, { NULL }, }; @@ -198,6 +242,8 @@ dispose (GObject *object) g_object_unref (priv->proxy); if (priv->ip4_config) g_object_unref (priv->ip4_config); + if (priv->dhcp4_config) + g_object_unref (priv->dhcp4_config); G_OBJECT_CLASS (nm_device_parent_class)->dispose (object); } @@ -243,6 +289,9 @@ get_property (GObject *object, case PROP_IP4_CONFIG: g_value_set_object (value, nm_device_get_ip4_config (device)); break; + case PROP_DHCP4_CONFIG: + g_value_set_object (value, nm_device_get_dhcp4_config (device)); + break; case PROP_STATE: g_value_set_uint (value, nm_device_get_state (device)); break; @@ -272,6 +321,12 @@ nm_device_class_init (NMDeviceClass *device_class) object_class->finalize = finalize; /* properties */ + + /** + * NMDevice:interface: + * + * The interface of the device. + **/ g_object_class_install_property (object_class, PROP_INTERFACE, g_param_spec_string (NM_DEVICE_INTERFACE, @@ -280,6 +335,11 @@ nm_device_class_init (NMDeviceClass *device_class) NULL, G_PARAM_READABLE)); + /** + * NMDevice:udi: + * + * The HAL UDI of the device. + **/ g_object_class_install_property (object_class, PROP_UDI, g_param_spec_string (NM_DEVICE_UDI, @@ -288,6 +348,11 @@ nm_device_class_init (NMDeviceClass *device_class) NULL, G_PARAM_READABLE)); + /** + * NMDevice:driver: + * + * The driver of the device. + **/ g_object_class_install_property (object_class, PROP_DRIVER, g_param_spec_string (NM_DEVICE_DRIVER, @@ -296,6 +361,11 @@ nm_device_class_init (NMDeviceClass *device_class) NULL, G_PARAM_READABLE)); + /** + * NMDevice:capabilities: + * + * The capabilities of the device. + **/ g_object_class_install_property (object_class, PROP_CAPABILITIES, g_param_spec_uint (NM_DEVICE_CAPABILITIES, @@ -304,6 +374,11 @@ nm_device_class_init (NMDeviceClass *device_class) 0, G_MAXUINT32, 0, G_PARAM_READABLE)); + /** + * NMDevice:managed: + * + * Whether the device is managed by NetworkManager. + **/ g_object_class_install_property (object_class, PROP_MANAGED, g_param_spec_boolean (NM_DEVICE_MANAGED, @@ -312,6 +387,11 @@ nm_device_class_init (NMDeviceClass *device_class) FALSE, G_PARAM_READABLE)); + /** + * NMDevice:ip4-config: + * + * The #NMIP4Config of the device. + **/ g_object_class_install_property (object_class, PROP_IP4_CONFIG, g_param_spec_object (NM_DEVICE_IP4_CONFIG, @@ -320,6 +400,24 @@ nm_device_class_init (NMDeviceClass *device_class) NM_TYPE_IP4_CONFIG, G_PARAM_READABLE)); + /** + * NMDevice:dhcp4-config: + * + * The #NMDHCP4Config of the device. + **/ + g_object_class_install_property + (object_class, PROP_DHCP4_CONFIG, + g_param_spec_object (NM_DEVICE_DHCP4_CONFIG, + "DHCP4 Config", + "DHCP4 Config", + NM_TYPE_DHCP4_CONFIG, + G_PARAM_READABLE)); + + /** + * NMDevice:state: + * + * The state of the device. + **/ g_object_class_install_property (object_class, PROP_STATE, g_param_spec_uint (NM_DEVICE_STATE, @@ -328,6 +426,11 @@ nm_device_class_init (NMDeviceClass *device_class) 0, G_MAXUINT32, 0, G_PARAM_READABLE)); + /** + * NMDevice:vendor: + * + * The vendor string of the device. + **/ g_object_class_install_property (object_class, PROP_VENDOR, g_param_spec_string (NM_DEVICE_VENDOR, @@ -336,6 +439,11 @@ nm_device_class_init (NMDeviceClass *device_class) NULL, G_PARAM_READABLE)); + /** + * NMDevice:product: + * + * The product string of the device. + **/ g_object_class_install_property (object_class, PROP_PRODUCT, g_param_spec_string (NM_DEVICE_PRODUCT, @@ -345,6 +453,14 @@ nm_device_class_init (NMDeviceClass *device_class) G_PARAM_READABLE)); /* signals */ + + /** + * NMDevice::state-changed: + * @device: the client that received the signal + * @state: the new state of the device + * + * Notifies the state change of a #NMDevice. + **/ signals[STATE_CHANGED] = g_signal_new ("state-changed", G_OBJECT_CLASS_TYPE (object_class), @@ -356,6 +472,15 @@ nm_device_class_init (NMDeviceClass *device_class) G_TYPE_UINT, G_TYPE_UINT, G_TYPE_UINT); } +/** + * nm_device_new: + * @connection: the #DBusGConnection + * @path: the DBus object path of the device + * + * Creates a new #NMDevice. + * + * Returns: a new device + **/ GObject * nm_device_new (DBusGConnection *connection, const char *path) { @@ -418,6 +543,15 @@ out: return G_OBJECT (device); } +/** + * nm_device_get_iface: + * @device: a #NMDevice + * + * Gets the interface name of the #NMDevice. + * + * Returns: the interface of the device. This is the internal string used by the + * device, and must not be modified. + **/ const char * nm_device_get_iface (NMDevice *device) { @@ -435,6 +569,15 @@ nm_device_get_iface (NMDevice *device) return priv->iface; } +/** + * nm_device_get_udi: + * @device: a #NMDevice + * + * Gets the HAL UDI of the #NMDevice. + * + * Returns: the HAL UDI of the device. This is the internal string used by the + * device, and must not be modified. + **/ const char * nm_device_get_udi (NMDevice *device) { @@ -452,6 +595,15 @@ nm_device_get_udi (NMDevice *device) return priv->udi; } +/** + * nm_device_get_driver: + * @device: a #NMDevice + * + * Gets the driver of the #NMDevice. + * + * Returns: the driver of the device. This is the internal string used by the + * device, and must not be modified. + **/ const char * nm_device_get_driver (NMDevice *device) { @@ -469,6 +621,14 @@ nm_device_get_driver (NMDevice *device) return priv->driver; } +/** + * nm_device_get_capabilities: + * @device: a #NMDevice + * + * Gets the device' capabilities. + * + * Returns: the capabilities + **/ guint32 nm_device_get_capabilities (NMDevice *device) { @@ -486,6 +646,14 @@ nm_device_get_capabilities (NMDevice *device) return priv->capabilities; } +/** + * nm_device_get_managed: + * @device: a #NMDevice + * + * Whether the #NMDevice is managed by NetworkManager. + * + * Returns: %TRUE if the device is managed by NetworkManager + **/ gboolean nm_device_get_managed (NMDevice *device) { @@ -503,6 +671,14 @@ nm_device_get_managed (NMDevice *device) return priv->managed; } +/** + * nm_device_get_ip4_config: + * @device: a #NMDevice + * + * Gets the current #NMIP4Config associated with the #NMDevice. + * + * Returns: the #NMIP4Config or %NULL if the device is not activated. + **/ NMIP4Config * nm_device_get_ip4_config (NMDevice *device) { @@ -529,6 +705,49 @@ nm_device_get_ip4_config (NMDevice *device) return priv->ip4_config; } +/** + * nm_device_get_dhcp4_config: + * @device: a #NMDevice + * + * Gets the current #NMDHCP4Config associated with the #NMDevice. + * + * Returns: the #NMDHCPConfig or %NULL if the device is not activated or not + * using DHCP. + **/ +NMDHCP4Config * +nm_device_get_dhcp4_config (NMDevice *device) +{ + NMDevicePrivate *priv; + char *path; + GValue value = { 0, }; + + g_return_val_if_fail (NM_IS_DEVICE (device), NULL); + + priv = NM_DEVICE_GET_PRIVATE (device); + if (priv->dhcp4_config) + return priv->dhcp4_config; + if (priv->null_dhcp4_config) + return NULL; + + path = nm_object_get_object_path_property (NM_OBJECT (device), NM_DBUS_INTERFACE_DEVICE, "Dhcp4Config"); + if (path) { + g_value_init (&value, DBUS_TYPE_G_OBJECT_PATH); + g_value_take_boxed (&value, path); + demarshal_dhcp4_config (NM_OBJECT (device), NULL, &value, &priv->dhcp4_config); + g_value_unset (&value); + } + + return priv->dhcp4_config; +} + +/** + * nm_device_get_state: + * @device: a #NMDevice + * + * Gets the current #NMDevice state. + * + * Returns: the current device state + **/ NMDeviceState nm_device_get_state (NMDevice *device) { @@ -724,6 +943,15 @@ nm_device_update_description (NMDevice *device) nm_object_queue_notify (NM_OBJECT (device), NM_DEVICE_PRODUCT); } +/** + * nm_device_get_product: + * @device: a #NMDevice + * + * Gets the product string of the #NMDevice. + * + * Returns: the product name of the device. This is the internal string used by the + * device, and must not be modified. + **/ const char * nm_device_get_product (NMDevice *device) { @@ -737,6 +965,15 @@ nm_device_get_product (NMDevice *device) return priv->product; } +/** + * nm_device_get_vendor: + * @device: a #NMDevice + * + * Gets the vendor string of the #NMDevice. + * + * Returns: the vendor name of the device. This is the internal string used by the + * device, and must not be modified. + **/ const char * nm_device_get_vendor (NMDevice *device) { |