Commit 9f397068 authored by Julian Bouzas's avatar Julian Bouzas
Browse files

reserve-device: acquire device if it has no owner for at least 3 seconds

parent cd3401bc
Pipeline #157962 passed with stages
in 1 minute and 32 seconds
...@@ -25,6 +25,7 @@ struct _WpReserveDevice ...@@ -25,6 +25,7 @@ struct _WpReserveDevice
WpObjectManager *jack_device_om; WpObjectManager *jack_device_om;
guint n_acquired; guint n_acquired;
GSource *timeout_source;
}; };
enum { enum {
...@@ -157,16 +158,30 @@ static void ...@@ -157,16 +158,30 @@ static void
on_reservation_owner_appeared (WpDbusDeviceReservation *reservation, on_reservation_owner_appeared (WpDbusDeviceReservation *reservation,
const gchar *owner, WpReserveDevice *self) const gchar *owner, WpReserveDevice *self)
{ {
/* Clear the current timeout acquire callback */
if (self->timeout_source)
g_source_destroy (self->timeout_source);
g_clear_pointer (&self->timeout_source, g_source_unref);
/* Request the application name to know who is the new owner */ /* Request the application name to know who is the new owner */
wp_dbus_device_reservation_request_property (self->reservation, wp_dbus_device_reservation_request_property (self->reservation,
"ApplicationName", NULL, on_application_name_appeared, self); "ApplicationName", NULL, on_application_name_appeared, self);
} }
static gboolean
timeout_acquire_callback (WpReserveDevice *self)
{
g_return_val_if_fail (self, G_SOURCE_REMOVE);
wp_dbus_device_reservation_acquire (self->reservation);
return G_SOURCE_REMOVE;
}
static void static void
on_reservation_owner_vanished (WpDbusDeviceReservation *reservation, on_reservation_owner_vanished (WpDbusDeviceReservation *reservation,
WpReserveDevice *self) WpReserveDevice *self)
{ {
g_autoptr (WpProxy) device = g_weak_ref_get (&self->device); g_autoptr (WpProxy) device = g_weak_ref_get (&self->device);
g_autoptr (WpCore) core = NULL;
wp_info_object (self, "owner vanished"); wp_info_object (self, "owner vanished");
...@@ -175,6 +190,18 @@ on_reservation_owner_vanished (WpDbusDeviceReservation *reservation, ...@@ -175,6 +190,18 @@ on_reservation_owner_vanished (WpDbusDeviceReservation *reservation,
disable_jack_device (self); disable_jack_device (self);
if (device) if (device)
set_device_profile (device, 0); set_device_profile (device, 0);
/* Clear the current timeout acquire callback */
if (self->timeout_source)
g_source_destroy (self->timeout_source);
g_clear_pointer (&self->timeout_source, g_source_unref);
/* Try to acquire the device if it has no owner for at least 3 seconds */
core = device ? wp_proxy_get_core (device) : NULL;
if (core)
wp_core_timeout_add_closure (core, &self->timeout_source, 3000,
g_cclosure_new_object (G_CALLBACK (timeout_acquire_callback),
G_OBJECT (self)));
} }
static void static void
...@@ -293,6 +320,11 @@ wp_reserve_device_finalize (GObject * object) ...@@ -293,6 +320,11 @@ wp_reserve_device_finalize (GObject * object)
{ {
WpReserveDevice *self = WP_RESERVE_DEVICE (object); WpReserveDevice *self = WP_RESERVE_DEVICE (object);
/* Clear the current timeout acquire callback */
if (self->timeout_source)
g_source_destroy (self->timeout_source);
g_clear_pointer (&self->timeout_source, g_source_unref);
wp_dbus_device_reservation_release (self->reservation); wp_dbus_device_reservation_release (self->reservation);
/* JACK */ /* JACK */
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment