core,libnm-glib: expose "slaves" property on NMDeviceBridge

This commit is contained in:
Jiří Klimeš 2012-11-06 13:54:59 +01:00 committed by Dan Williams
parent 789f8c730d
commit 1a7f9e661a
6 changed files with 84 additions and 2 deletions

View file

@ -15,6 +15,13 @@
</tp:docstring>
</property>
<property name="Slaves" type="ao" access="read">
<tp:docstring>
Array of object paths representing devices which are currently
slaved to this device.
</tp:docstring>
</property>
<signal name="PropertiesChanged">
<arg name="properties" type="a{sv}" tp:type="String_Variant_Map">
<tp:docstring>

View file

@ -74,6 +74,7 @@ global:
nm_device_bridge_error_quark;
nm_device_bridge_get_carrier;
nm_device_bridge_get_hw_address;
nm_device_bridge_get_slaves;
nm_device_bridge_get_type;
nm_device_bridge_new;
nm_device_bt_error_get_type;

View file

@ -33,6 +33,7 @@
#include "nm-device-bridge.h"
#include "nm-device-private.h"
#include "nm-object-private.h"
#include "nm-types.h"
G_DEFINE_TYPE (NMDeviceBridge, nm_device_bridge, NM_TYPE_DEVICE)
@ -43,18 +44,21 @@ typedef struct {
char *hw_address;
gboolean carrier;
GPtrArray *slaves;
} NMDeviceBridgePrivate;
enum {
PROP_0,
PROP_HW_ADDRESS,
PROP_CARRIER,
PROP_SLAVES,
LAST_PROP
};
#define DBUS_PROP_HW_ADDRESS "HwAddress"
#define DBUS_PROP_CARRIER "Carrier"
#define DBUS_PROP_SLAVES "Slaves"
/**
* nm_device_bridge_error_quark:
@ -133,6 +137,25 @@ nm_device_bridge_get_carrier (NMDeviceBridge *device)
return NM_DEVICE_BRIDGE_GET_PRIVATE (device)->carrier;
}
/**
* nm_device_bridge_get_slaves:
* @device: a #NMDeviceBridge
*
* Gets the devices currently slaved to @device.
*
* Returns: (element-type NMClient.Device): the #GPtrArray containing
* #NMDevice<!-- -->s that are slaves of @device. This is the internal
* copy used by the device, and must not be modified.
**/
const GPtrArray *
nm_device_bridge_get_slaves (NMDeviceBridge *device)
{
g_return_val_if_fail (NM_IS_DEVICE_BRIDGE (device), FALSE);
_nm_object_ensure_inited (NM_OBJECT (device));
return handle_ptr_array_return (NM_DEVICE_BRIDGE_GET_PRIVATE (device)->slaves);
}
static gboolean
connection_compatible (NMDevice *device, NMConnection *connection, GError **error)
{
@ -187,6 +210,7 @@ register_properties (NMDeviceBridge *device)
const NMPropertiesInfo property_info[] = {
{ NM_DEVICE_BRIDGE_HW_ADDRESS, &priv->hw_address },
{ NM_DEVICE_BRIDGE_CARRIER, &priv->carrier },
{ NM_DEVICE_BRIDGE_SLAVES, &priv->slaves, NULL, NM_TYPE_DEVICE },
{ NULL },
};
@ -219,6 +243,12 @@ dispose (GObject *object)
g_clear_object (&priv->proxy);
if (priv->slaves) {
g_ptr_array_foreach (priv->slaves, (GFunc) g_object_unref, NULL);
g_ptr_array_free (priv->slaves, TRUE);
priv->slaves = NULL;
}
G_OBJECT_CLASS (nm_device_bridge_parent_class)->dispose (object);
}
@ -249,6 +279,9 @@ get_property (GObject *object,
case PROP_CARRIER:
g_value_set_boolean (value, nm_device_bridge_get_carrier (device));
break;
case PROP_SLAVES:
g_value_set_boxed (value, nm_device_bridge_get_slaves (device));
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
@ -298,4 +331,16 @@ nm_device_bridge_class_init (NMDeviceBridgeClass *bridge_class)
FALSE,
G_PARAM_READABLE));
/**
* NMDeviceBridge:slaves:
*
* The devices (#NMDevice) slaved to the bridge device.
**/
g_object_class_install_property
(object_class, PROP_SLAVES,
g_param_spec_boxed (NM_DEVICE_BRIDGE_SLAVES,
"Slaves",
"Slaves",
NM_TYPE_OBJECT_ARRAY,
G_PARAM_READABLE));
}

View file

@ -53,6 +53,7 @@ GQuark nm_device_bridge_error_quark (void);
#define NM_DEVICE_BRIDGE_HW_ADDRESS "hw-address"
#define NM_DEVICE_BRIDGE_CARRIER "carrier"
#define NM_DEVICE_BRIDGE_SLAVES "slaves"
typedef struct {
NMDevice parent;
@ -74,8 +75,9 @@ GType nm_device_bridge_get_type (void);
GObject * nm_device_bridge_new (DBusGConnection *connection, const char *path);
const char * nm_device_bridge_get_hw_address (NMDeviceBridge *device);
gboolean nm_device_bridge_get_carrier (NMDeviceBridge *device);
const char *nm_device_bridge_get_hw_address (NMDeviceBridge *device);
gboolean nm_device_bridge_get_carrier (NMDeviceBridge *device);
const GPtrArray *nm_device_bridge_get_slaves (NMDeviceBridge *device);
G_END_DECLS

View file

@ -32,6 +32,7 @@
#include "NetworkManagerUtils.h"
#include "nm-device-private.h"
#include "nm-netlink-monitor.h"
#include "nm-dbus-glib-types.h"
#include "nm-enum-types.h"
#include "nm-system.h"
@ -60,6 +61,7 @@ enum {
PROP_0,
PROP_HW_ADDRESS,
PROP_CARRIER,
PROP_SLAVES,
LAST_PROP
};
@ -465,6 +467,8 @@ enslave_slave (NMDevice *device, NMDevice *slave, NMConnection *connection)
nm_device_get_ip_iface (device),
nm_device_get_ip_iface (slave));
g_object_notify (G_OBJECT (device), NM_DEVICE_BRIDGE_SLAVES);
/* Set port properties */
s_port = nm_connection_get_setting_bridge_port (connection);
if (s_port) {
@ -499,6 +503,7 @@ release_slave (NMDevice *device, NMDevice *slave)
success);
priv->slaves = g_slist_remove (priv->slaves, sinfo);
free_slave_info (sinfo);
g_object_notify (G_OBJECT (device), NM_DEVICE_BRIDGE_SLAVES);
return success;
}
@ -538,7 +543,12 @@ static void
get_property (GObject *object, guint prop_id,
GValue *value, GParamSpec *pspec)
{
NMDeviceBridge *self = NM_DEVICE_BRIDGE (object);
NMDeviceBridgePrivate *priv = NM_DEVICE_BRIDGE_GET_PRIVATE (self);
const guint8 *current_addr;
GPtrArray *slaves;
GSList *iter;
SlaveInfo *info;
switch (prop_id) {
case PROP_HW_ADDRESS:
@ -548,6 +558,14 @@ get_property (GObject *object, guint prop_id,
case PROP_CARRIER:
g_value_set_boolean (value, nm_device_wired_get_carrier (NM_DEVICE_WIRED (object)));
break;
case PROP_SLAVES:
slaves = g_ptr_array_new ();
for (iter = priv->slaves; iter; iter = iter->next) {
info = iter->data;
g_ptr_array_add (slaves, g_strdup (nm_device_get_path (info->slave)));
}
g_value_take_boxed (value, slaves);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
@ -627,6 +645,14 @@ nm_device_bridge_class_init (NMDeviceBridgeClass *klass)
FALSE,
G_PARAM_READABLE));
g_object_class_install_property
(object_class, PROP_SLAVES,
g_param_spec_boxed (NM_DEVICE_BRIDGE_SLAVES,
"Slaves",
"Slaves",
DBUS_TYPE_G_ARRAY_OF_OBJECT_PATH,
G_PARAM_READABLE));
/* Signals */
signals[PROPERTIES_CHANGED] =
nm_properties_changed_signal_new (object_class,

View file

@ -42,6 +42,7 @@ typedef enum {
#define NM_DEVICE_BRIDGE_HW_ADDRESS "hw-address"
#define NM_DEVICE_BRIDGE_CARRIER "carrier"
#define NM_DEVICE_BRIDGE_SLAVES "slaves"
typedef struct {
NMDeviceWired parent;