Re: [PATCH 7/9] device: Add "master" property to provide a reference to the master link



On Fri, 2011-09-23 at 14:52 +0200, Thomas Graf wrote:
> Provides a function nm_device_set_master() to be used internally to assign a
> master device to a slave device. a gobject reference will be held until
> the assignment is revoked by setting the master NULL.
> 
> Adds a a new device interface property "master" which is readable and contains
> the UDI of the master device or NULL if not set.

So this is internal only?  In that case we want to add
NM_PROPERTY_PARAM_NO_EXPORT to the property registration flags to ensure
this doesn't go out over D-Bus in the PropertyChanged events, and also
maybe mark it as such in nm-device-interface.h like 'type-desc' is.

Second, I'm not sure the UDI is what you want to use here in
get_property().  In fact, I'd just skip that property altogether for now
since it's not really being used as a *property*, but keep the
nm_device_get_master() / nm_device_set_master().  I think we talked at
some point about exposing this through the D-Bus API so that clients
know if a specific NMDevice object has a master, but we can do that in a
later patch.  So the nm-device-interface.[ch] bits can be dropped I
think.

Dan

> Signed-off-by: Thomas Graf <tgraf redhat com>
> ---
>  src/nm-device-interface.c |    8 ++++++++
>  src/nm-device-interface.h |    2 ++
>  src/nm-device.c           |   34 ++++++++++++++++++++++++++++++++++
>  src/nm-device.h           |    3 +++
>  4 files changed, 47 insertions(+), 0 deletions(-)
> 
> diff --git a/src/nm-device-interface.c b/src/nm-device-interface.c
> index fb471f5..fd4e5e7 100644
> --- a/src/nm-device-interface.c
> +++ b/src/nm-device-interface.c
> @@ -219,6 +219,14 @@ nm_device_interface_init (gpointer g_iface)
>  							0, G_MAXINT, 0,
>  							G_PARAM_READABLE | NM_PROPERTY_PARAM_NO_EXPORT));
>  
> +	g_object_interface_install_property
> +		(g_iface,
> +		 g_param_spec_string (NM_DEVICE_INTERFACE_MASTER,
> +							  "Master",
> +							  "ID of master device",
> +							  NULL,
> +							  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 560cdfe..8126b2c 100644
> --- a/src/nm-device-interface.h
> +++ b/src/nm-device-interface.h
> @@ -62,6 +62,7 @@ typedef enum
>  #define NM_DEVICE_INTERFACE_DEVICE_TYPE      "device-type" /* ugh */
>  #define NM_DEVICE_INTERFACE_MANAGED          "managed"
>  #define NM_DEVICE_INTERFACE_FIRMWARE_MISSING "firmware-missing"
> +#define NM_DEVICE_INTERFACE_MASTER           "master"
>  #define NM_DEVICE_INTERFACE_TYPE_DESC        "type-desc"    /* Internal only */
>  #define NM_DEVICE_INTERFACE_RFKILL_TYPE      "rfkill-type"  /* Internal only */
>  #define NM_DEVICE_INTERFACE_IFINDEX          "ifindex"      /* Internal only */
> @@ -87,6 +88,7 @@ typedef enum {
>  	NM_DEVICE_INTERFACE_PROP_TYPE_DESC,
>  	NM_DEVICE_INTERFACE_PROP_RFKILL_TYPE,
>  	NM_DEVICE_INTERFACE_PROP_IFINDEX,
> +	NM_DEVICE_INTERFACE_PROP_MASTER,
>  } NMDeviceInterfaceProp;
>  
> 
> diff --git a/src/nm-device.c b/src/nm-device.c
> index 89c5000..02cd2a0 100644
> --- a/src/nm-device.c
> +++ b/src/nm-device.c
> @@ -150,6 +150,8 @@ typedef struct {
>  
>  	/* inhibit autoconnect feature */
>  	gboolean	autoconnect_inhibit;
> +
> +	NMDevice *	master;
>  } NMDevicePrivate;
>  
>  static gboolean check_connection_compatible (NMDeviceInterface *device,
> @@ -494,6 +496,28 @@ nm_device_get_type_desc (NMDevice *self)
>  	return NM_DEVICE_GET_PRIVATE (self)->type_desc;
>  }
>  
> +NMDevice *
> +nm_device_get_master (NMDevice *self)
> +{
> +	g_return_val_if_fail (self != NULL, NULL);
> +
> +	return NM_DEVICE_GET_PRIVATE (self)->master;
> +}
> +
> +void
> +nm_device_set_master (NMDevice *self, NMDevice *master)
> +{
> +	NMDevicePrivate *priv = NM_DEVICE_GET_PRIVATE(self);
> +
> +	if (priv->master)
> +		g_object_unref (priv->master);
> +	
> +	if (master)
> +		g_object_ref (master);
> +
> +	priv->master = master;
> +}
> +
>  /*
>   * nm_device_get_act_request
>   *
> @@ -3540,6 +3564,12 @@ get_property (GObject *object, guint prop_id,
>  	case NM_DEVICE_INTERFACE_PROP_RFKILL_TYPE:
>  		g_value_set_uint (value, priv->rfkill_type);
>  		break;
> +	case NM_DEVICE_INTERFACE_PROP_MASTER:
> +		if (priv->master)
> +			g_value_set_string (value, nm_device_get_udi(priv->master));
> +		else
> +			g_value_set_string (value, NULL);
> +		break;
>  	default:
>  		G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
>  		break;
> @@ -3646,6 +3676,10 @@ nm_device_class_init (NMDeviceClass *klass)
>  	                                  NM_DEVICE_INTERFACE_PROP_RFKILL_TYPE,
>  	                                  NM_DEVICE_INTERFACE_RFKILL_TYPE);
>  
> +	g_object_class_override_property (object_class,
> +	                                  NM_DEVICE_INTERFACE_PROP_MASTER,
> +	                                  NM_DEVICE_INTERFACE_MASTER);
> +
>  	signals[AUTOCONNECT_ALLOWED] =
>  		g_signal_new ("autoconnect-allowed",
>  		              G_OBJECT_CLASS_TYPE (object_class),
> diff --git a/src/nm-device.h b/src/nm-device.h
> index 62c8fc0..255529f 100644
> --- a/src/nm-device.h
> +++ b/src/nm-device.h
> @@ -154,6 +154,9 @@ NMIP6Config *	nm_device_get_ip6_config	(NMDevice *dev);
>  
>  void *		nm_device_get_system_config_data	(NMDevice *dev);
>  
> +NMDevice *	nm_device_get_master (NMDevice *self);
> +void		nm_device_set_master (NMDevice *self, NMDevice *master);
> +
>  NMActRequest *	nm_device_get_act_request	(NMDevice *dev);
>  
>  gboolean		nm_device_is_available (NMDevice *dev);




[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]