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

David Henningsson david.henningsson at canonical.com
Mon Jan 28 23:10:31 PST 2013


On 01/28/2013 05:59 PM, 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.

Am I missing an earlier thread here, or why do we need this? Isn't the 
existing checks (that I pushed to 3.0 stable) enough to give a correct 
"busy" result?

> ---
>   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;
> +
>   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);
> +
>   #ifdef __cplusplus
>   }
>   #endif
>



-- 
David Henningsson, Canonical Ltd.
https://launchpad.net/~diwic


More information about the pulseaudio-discuss mailing list