aboutsummaryrefslogtreecommitdiff
path: root/src/volume-control.vala
diff options
context:
space:
mode:
authorLars Uebernickel <lars.uebernickel@canonical.com>2013-09-30 14:13:32 +0200
committerLars Uebernickel <lars.uebernickel@canonical.com>2013-09-30 14:13:32 +0200
commit86719275d89bb2c48d1cc9451f6add1918ee0f75 (patch)
tree04bc6d31a537d58dc2d3b46a0fb035e13f0f0e35 /src/volume-control.vala
parent0fab1e68c5594dda52efda84f8dcaf78a22fade5 (diff)
downloadayatana-indicator-sound-86719275d89bb2c48d1cc9451f6add1918ee0f75.tar.gz
ayatana-indicator-sound-86719275d89bb2c48d1cc9451f6add1918ee0f75.tar.bz2
ayatana-indicator-sound-86719275d89bb2c48d1cc9451f6add1918ee0f75.zip
Reconnect when pulseaudio terminates (or crashes)
Diffstat (limited to 'src/volume-control.vala')
-rw-r--r--src/volume-control.vala65
1 files changed, 40 insertions, 25 deletions
diff --git a/src/volume-control.vala b/src/volume-control.vala
index 9475f53..18c407f 100644
--- a/src/volume-control.vala
+++ b/src/volume-control.vala
@@ -46,21 +46,7 @@ public class VolumeControl : Object
if (loop == null)
loop = new PulseAudio.GLibMainLoop ();
- var props = new Proplist ();
- props.sets (Proplist.PROP_APPLICATION_NAME, "Ubuntu Audio Settings");
- props.sets (Proplist.PROP_APPLICATION_ID, "com.canonical.settings.sound");
- props.sets (Proplist.PROP_APPLICATION_ICON_NAME, "multimedia-volume-control");
- props.sets (Proplist.PROP_APPLICATION_VERSION, "0.1");
-
- context = new PulseAudio.Context (loop.get_api(), null, props);
-
- context.set_state_callback (context_state_callback);
-
- if (context.connect(null, Context.Flags.NOFAIL, null) < 0)
- {
- warning( "pa_context_connect() failed: %s\n", PulseAudio.strerror(context.errno()));
- return;
- }
+ this.reconnect_to_pulse ();
}
/* PulseAudio logic*/
@@ -153,18 +139,47 @@ public class VolumeControl : Object
private void context_state_callback (Context c)
{
- if (c.get_state () == Context.State.READY)
- {
- c.subscribe (PulseAudio.Context.SubscriptionMask.SINK |
- PulseAudio.Context.SubscriptionMask.SOURCE |
- PulseAudio.Context.SubscriptionMask.SOURCE_OUTPUT);
- c.set_subscribe_callback (context_events_cb);
- update_sink ();
- update_source ();
- this.ready = true;
+ switch (c.get_state ()) {
+ case Context.State.READY:
+ c.subscribe (PulseAudio.Context.SubscriptionMask.SINK |
+ PulseAudio.Context.SubscriptionMask.SOURCE |
+ PulseAudio.Context.SubscriptionMask.SOURCE_OUTPUT);
+ c.set_subscribe_callback (context_events_cb);
+ update_sink ();
+ update_source ();
+ this.ready = true;
+ break;
+
+ case Context.State.FAILED:
+ case Context.State.TERMINATED:
+ this.reconnect_to_pulse ();
+ break;
+
+ default:
+ this.ready = false;
+ break;
}
- else
+ }
+
+ void reconnect_to_pulse ()
+ {
+ if (this.ready) {
+ this.context.disconnect ();
+ this.context = null;
this.ready = false;
+ }
+
+ var props = new Proplist ();
+ props.sets (Proplist.PROP_APPLICATION_NAME, "Ubuntu Audio Settings");
+ props.sets (Proplist.PROP_APPLICATION_ID, "com.canonical.settings.sound");
+ props.sets (Proplist.PROP_APPLICATION_ICON_NAME, "multimedia-volume-control");
+ props.sets (Proplist.PROP_APPLICATION_VERSION, "0.1");
+
+ this.context = new PulseAudio.Context (loop.get_api(), null, props);
+ this.context.set_state_callback (context_state_callback);
+
+ if (context.connect(null, Context.Flags.NOFAIL, null) < 0)
+ warning( "pa_context_connect() failed: %s\n", PulseAudio.strerror(context.errno()));
}
/* Mute operations */