[PATCH v0 1/2] reserve: Add support for private D-Bus connections

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

 



On Mon, 2013-01-28 at 17:59 +0100, Mikel Astiz wrote:
> From: Mikel Astiz <mikel.astiz at bmw-carit.de>
> 
> Extend the reserve-monitor API with a registration mechanism to keep
> track of existing private connections. This is necessary because the
> monitor should not consider it busy if a device has been owned by us.
> ---
>  src/modules/reserve-monitor.c | 45 +++++++++++++++++++++++++++++++++++++++++++
>  src/modules/reserve-monitor.h |  6 ++++++
>  2 files changed, 51 insertions(+)
> 
> diff --git a/src/modules/reserve-monitor.c b/src/modules/reserve-monitor.c
> index efd24eb..85720f9 100644
> --- a/src/modules/reserve-monitor.c
> +++ b/src/modules/reserve-monitor.c
> @@ -59,11 +59,17 @@ struct rm_monitor {
>  	"member='NameOwnerChanged',"		\
>  	"arg0='%s'"
>  
> +#define MAX_PRIVATE_CONNECTIONS 256
> +
> +static DBusConnection *private_connections[MAX_PRIVATE_CONNECTIONS];
> +static unsigned private_connection_count;

No global variables please. These can be in the rm_monitor struct just
fine. get_busy() can take a rm_monitor as a parameter instead of a
DBusConnection.

> +
>  static unsigned get_busy(
>  	DBusConnection *c,
>  	const char *name_owner) {
>  
>  	const char *un;
> +	unsigned i;
>  
>  	if (!name_owner || !*name_owner)
>  		return FALSE;
> @@ -73,6 +79,12 @@ static unsigned get_busy(
>  		if (strcmp(name_owner, un) == 0)
>  			return FALSE;
>  
> +	/* Similarly, check if any of the private connections own the device */
> +	for (i = 0; i < private_connection_count; i++)
> +		if ((un = dbus_bus_get_unique_name(private_connections[i])))
> +			if (strcmp(name_owner, un) == 0)
> +				return FALSE;
> +
>  	return TRUE;
>  }
>  
> @@ -320,3 +332,36 @@ void* rm_get_userdata(rm_monitor *m) {
>  
>  	return m->userdata;
>  }
> +
> +int rm_register_private_bus(DBusConnection *c) {
> +
> +	if (!c)
> +		return -EINVAL;
> +
> +	if (private_connection_count == MAX_PRIVATE_CONNECTIONS)
> +		return -ENOMEM;
> +
> +	private_connections[private_connection_count++] = c;
> +
> +	return 0;
> +}
> +
> +int rm_unregister_private_bus(DBusConnection *c) {
> +	unsigned i;
> +
> +	if (!c)
> +		return -EINVAL;
> +
> +	for (i = 0; i < private_connection_count; i++)
> +		if (private_connections[i] == c) {
> +			assert(private_connection_count >= 1);
> +
> +			private_connection_count--;
> +			private_connections[i] = private_connections[private_connection_count];
> +			private_connections[private_connection_count] = NULL;
> +
> +			return 0;
> +		}
> +
> +	return -EINVAL;
> +}
> diff --git a/src/modules/reserve-monitor.h b/src/modules/reserve-monitor.h
> index 85a7ebb..ca3038d 100644
> --- a/src/modules/reserve-monitor.h
> +++ b/src/modules/reserve-monitor.h
> @@ -64,6 +64,12 @@ void rm_set_userdata(rm_monitor *m, void *userdata);
>   * userdata was set. */
>  void* rm_get_userdata(rm_monitor *m);
>  
> +/* Registration of private D-Bus connections, in order to distinguish
> + * self-owned devices from the rest. Returns 0 on success, or a negative
> + * errno style return value on error. */
> +int rm_register_private_bus(DBusConnection *c);
> +int rm_unregister_private_bus(DBusConnection *c);

I think the documentation is a bit unclear. I suggest this version:

"Registration of D-Bus connections used by rd_device objects. If you
create a new DBusConnection for each rd_device (as you should do), use
these functions to let rm_monitor know about those connections, so that
it can track the busy status accurately. Returns 0 on success, or a
negative errno style return value on error."

-- 
Tanu



[Index of Archives]     [Linux Audio Users]     [AMD Graphics]     [Linux USB Devel]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]

  Powered by Linux