From 04f8d563fa906f99f7d2015290fa8c21e36c1462 Mon Sep 17 00:00:00 2001 From: Dan Williams Date: Tue, 25 Sep 2007 17:30:01 +0000 Subject: [PATCH] 2007-09-25 Dan Williams * introspection/nm-device.xml libnm-glib/nm-device.c libnm-glib/nm-device.h - Add 'Carrier' property to exported NMDevice objects * src/nm-device-interface.h src/nm-device-interface.c src/nm-device.c - Add a 'carrier' property to internal NMDevice objects git-svn-id: http://svn-archive.gnome.org/svn/NetworkManager/trunk@2884 4912f4e0-d625-0410-9fb7-b9a5a253dbdc --- ChangeLog | 12 +++++++++++ introspection/nm-device.xml | 1 + libnm-glib/nm-device.c | 43 +++++++++++++++++++++++++++++++++++++ libnm-glib/nm-device.h | 2 ++ src/nm-device-interface.c | 8 +++++++ src/nm-device-interface.h | 4 +++- src/nm-device.c | 7 ++++++ 7 files changed, 76 insertions(+), 1 deletion(-) diff --git a/ChangeLog b/ChangeLog index 85f48f2db7..6fc46a0693 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,15 @@ +2007-09-25 Dan Williams + + * introspection/nm-device.xml + libnm-glib/nm-device.c + libnm-glib/nm-device.h + - Add 'Carrier' property to exported NMDevice objects + + * src/nm-device-interface.h + src/nm-device-interface.c + src/nm-device.c + - Add a 'carrier' property to internal NMDevice objects + 2007-09-25 Dan Williams * src/nm-device-802-11-wireless.c diff --git a/introspection/nm-device.xml b/introspection/nm-device.xml index 38f3c153ea..22d8f583b7 100644 --- a/introspection/nm-device.xml +++ b/introspection/nm-device.xml @@ -20,6 +20,7 @@ + diff --git a/libnm-glib/nm-device.c b/libnm-glib/nm-device.c index 7273e6aa9a..77b1490ed6 100644 --- a/libnm-glib/nm-device.c +++ b/libnm-glib/nm-device.c @@ -11,11 +11,15 @@ typedef struct { DBusGProxy *device_proxy; NMDeviceState state; + gboolean carrier; + gboolean carrier_valid; + gboolean disposed; } NMDevicePrivate; enum { STATE_CHANGED, + CARRIER_CHANGED, LAST_SIGNAL }; @@ -33,6 +37,7 @@ enum { static void device_state_change_proxy (DBusGProxy *proxy, guint state, gpointer user_data); +static void device_carrier_changed_proxy (DBusGProxy *proxy, gboolean carrier, gpointer user_data); static void nm_device_init (NMDevice *device) @@ -40,6 +45,8 @@ nm_device_init (NMDevice *device) NMDevicePrivate *priv = NM_DEVICE_GET_PRIVATE (device); priv->state = NM_DEVICE_STATE_UNKNOWN; + priv->carrier = FALSE; + priv->carrier_valid = FALSE; priv->disposed = FALSE; } @@ -68,6 +75,11 @@ constructor (GType type, dbus_g_proxy_connect_signal (priv->device_proxy, "StateChanged", G_CALLBACK (device_state_change_proxy), object, NULL); + + dbus_g_proxy_add_signal (priv->device_proxy, "CarrierChanged", G_TYPE_BOOLEAN, G_TYPE_INVALID); + dbus_g_proxy_connect_signal (priv->device_proxy, "CarrierChanged", + G_CALLBACK (device_carrier_changed_proxy), + object, NULL); return G_OBJECT (object); } @@ -121,6 +133,19 @@ device_state_change_proxy (DBusGProxy *proxy, guint state, gpointer user_data) } } +static void +device_carrier_changed_proxy (DBusGProxy *proxy, gboolean carrier, gpointer user_data) +{ + NMDevice *device = NM_DEVICE (user_data); + NMDevicePrivate *priv = NM_DEVICE_GET_PRIVATE (device); + + if ((priv->carrier != carrier) || !priv->carrier_valid) { + priv->carrier_valid = TRUE; + priv->carrier = carrier; + g_signal_emit (device, signals[CARRIER_CHANGED], 0, carrier); + } +} + NMDevice * nm_device_new (DBusGConnection *connection, const char *path) { @@ -310,6 +335,24 @@ nm_device_get_description (NMDevice *device) } +gboolean +nm_device_get_carrier (NMDevice *device) +{ + NMDevicePrivate *priv; + + g_return_val_if_fail (NM_IS_DEVICE (device), FALSE); + + priv = NM_DEVICE_GET_PRIVATE (device); + + if (!priv->carrier_valid) { + priv->carrier = nm_object_get_boolean_property (NM_OBJECT (device), + NM_DBUS_INTERFACE_DEVICE, "Carrier"); + priv->carrier_valid = TRUE; + } + + return priv->carrier; +} + NMDeviceType nm_device_type_for_path (DBusGConnection *connection, const char *path) diff --git a/libnm-glib/nm-device.h b/libnm-glib/nm-device.h index 700fbab7cd..758fc76ad7 100644 --- a/libnm-glib/nm-device.h +++ b/libnm-glib/nm-device.h @@ -27,6 +27,7 @@ typedef struct { /* Signals */ void (*state_changed) (NMDevice *device, NMDeviceState state); + void (*carrier_changed) (NMDevice *device, gboolean carrier); } NMDeviceClass; GType nm_device_get_type (void); @@ -49,6 +50,7 @@ guint32 nm_device_get_ip4_address (NMDevice *device); NMIP4Config *nm_device_get_ip4_config (NMDevice *device); NMDeviceState nm_device_get_state (NMDevice *device); char *nm_device_get_description (NMDevice *device); +gboolean nm_device_get_carrier (NMDevice *device); NMDeviceType nm_device_type_for_path (DBusGConnection *connection, const char *path); diff --git a/src/nm-device-interface.c b/src/nm-device-interface.c index 1d64247673..1b0875e55d 100644 --- a/src/nm-device-interface.c +++ b/src/nm-device-interface.c @@ -124,6 +124,14 @@ nm_device_interface_init (gpointer g_iface) 0, G_MAXUINT32, DEVICE_TYPE_UNKNOWN, G_PARAM_READABLE)); + g_object_interface_install_property + (g_iface, + g_param_spec_boolean (NM_DEVICE_INTERFACE_CARRIER, + "Carrier", + "Carrier", + FALSE, + G_PARAM_READABLE)); + /* Signals */ g_signal_new ("state-changed", iface_type, diff --git a/src/nm-device-interface.h b/src/nm-device-interface.h index f7b568fb3c..c1026ddc5e 100644 --- a/src/nm-device-interface.h +++ b/src/nm-device-interface.h @@ -28,6 +28,7 @@ typedef enum #define NM_DEVICE_INTERFACE_IP4_CONFIG "ip4_config" #define NM_DEVICE_INTERFACE_STATE "state" #define NM_DEVICE_INTERFACE_DEVICE_TYPE "device_type" /* ugh */ +#define NM_DEVICE_INTERFACE_CARRIER "carrier" typedef enum { NM_DEVICE_INTERFACE_PROP_FIRST = 0x1000, @@ -40,7 +41,8 @@ typedef enum { NM_DEVICE_INTERFACE_PROP_IP4_ADDRESS, NM_DEVICE_INTERFACE_PROP_IP4_CONFIG, NM_DEVICE_INTERFACE_PROP_STATE, - NM_DEVICE_INTERFACE_PROP_DEVICE_TYPE + NM_DEVICE_INTERFACE_PROP_DEVICE_TYPE, + NM_DEVICE_INTERFACE_PROP_CARRIER } NMDeviceInterfaceProp; diff --git a/src/nm-device.c b/src/nm-device.c index a6dae018fe..c7348dabec 100644 --- a/src/nm-device.c +++ b/src/nm-device.c @@ -1713,6 +1713,9 @@ get_property (GObject *object, guint prop_id, case NM_DEVICE_INTERFACE_PROP_DEVICE_TYPE: g_value_set_uint (value, priv->type); break; + case NM_DEVICE_INTERFACE_PROP_CARRIER: + g_value_set_boolean (value, priv->link_active); + break; default: G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); break; @@ -1781,6 +1784,10 @@ nm_device_class_init (NMDeviceClass *klass) g_object_class_override_property (object_class, NM_DEVICE_INTERFACE_PROP_DEVICE_TYPE, NM_DEVICE_INTERFACE_DEVICE_TYPE); + + g_object_class_override_property (object_class, + NM_DEVICE_INTERFACE_PROP_CARRIER, + NM_DEVICE_INTERFACE_CARRIER); } void