Merge lp:~larsu/indicator-sound/reconnect-to-pulse into lp:indicator-sound/13.10

Proposed by Lars Karlitski on 2013-09-30
Status: Merged
Approved by: Ted Gould on 2013-09-30
Approved revision: 383
Merged at revision: 384
Proposed branch: lp:~larsu/indicator-sound/reconnect-to-pulse
Merge into: lp:indicator-sound/13.10
Diff against target: 84 lines (+40/-25)
1 file modified
src/volume-control.vala (+40/-25)
To merge this branch: bzr merge lp:~larsu/indicator-sound/reconnect-to-pulse
Reviewer Review Type Date Requested Status
Ted Gould (community) 2013-09-30 Approve on 2013-09-30
PS Jenkins bot (community) continuous-integration Approve on 2013-09-30
Review via email: mp+188319@code.launchpad.net

Commit message

Reconnect when pulseaudio terminates (or crashes)

Description of the change

Reconnect when pulseaudio terminates (or crashes)

To post a comment you must log in.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'src/volume-control.vala'
2--- src/volume-control.vala 2013-06-18 19:00:27 +0000
3+++ src/volume-control.vala 2013-09-30 12:15:16 +0000
4@@ -46,21 +46,7 @@
5 if (loop == null)
6 loop = new PulseAudio.GLibMainLoop ();
7
8- var props = new Proplist ();
9- props.sets (Proplist.PROP_APPLICATION_NAME, "Ubuntu Audio Settings");
10- props.sets (Proplist.PROP_APPLICATION_ID, "com.canonical.settings.sound");
11- props.sets (Proplist.PROP_APPLICATION_ICON_NAME, "multimedia-volume-control");
12- props.sets (Proplist.PROP_APPLICATION_VERSION, "0.1");
13-
14- context = new PulseAudio.Context (loop.get_api(), null, props);
15-
16- context.set_state_callback (context_state_callback);
17-
18- if (context.connect(null, Context.Flags.NOFAIL, null) < 0)
19- {
20- warning( "pa_context_connect() failed: %s\n", PulseAudio.strerror(context.errno()));
21- return;
22- }
23+ this.reconnect_to_pulse ();
24 }
25
26 /* PulseAudio logic*/
27@@ -153,18 +139,47 @@
28
29 private void context_state_callback (Context c)
30 {
31- if (c.get_state () == Context.State.READY)
32- {
33- c.subscribe (PulseAudio.Context.SubscriptionMask.SINK |
34- PulseAudio.Context.SubscriptionMask.SOURCE |
35- PulseAudio.Context.SubscriptionMask.SOURCE_OUTPUT);
36- c.set_subscribe_callback (context_events_cb);
37- update_sink ();
38- update_source ();
39- this.ready = true;
40+ switch (c.get_state ()) {
41+ case Context.State.READY:
42+ c.subscribe (PulseAudio.Context.SubscriptionMask.SINK |
43+ PulseAudio.Context.SubscriptionMask.SOURCE |
44+ PulseAudio.Context.SubscriptionMask.SOURCE_OUTPUT);
45+ c.set_subscribe_callback (context_events_cb);
46+ update_sink ();
47+ update_source ();
48+ this.ready = true;
49+ break;
50+
51+ case Context.State.FAILED:
52+ case Context.State.TERMINATED:
53+ this.reconnect_to_pulse ();
54+ break;
55+
56+ default:
57+ this.ready = false;
58+ break;
59 }
60- else
61+ }
62+
63+ void reconnect_to_pulse ()
64+ {
65+ if (this.ready) {
66+ this.context.disconnect ();
67+ this.context = null;
68 this.ready = false;
69+ }
70+
71+ var props = new Proplist ();
72+ props.sets (Proplist.PROP_APPLICATION_NAME, "Ubuntu Audio Settings");
73+ props.sets (Proplist.PROP_APPLICATION_ID, "com.canonical.settings.sound");
74+ props.sets (Proplist.PROP_APPLICATION_ICON_NAME, "multimedia-volume-control");
75+ props.sets (Proplist.PROP_APPLICATION_VERSION, "0.1");
76+
77+ this.context = new PulseAudio.Context (loop.get_api(), null, props);
78+ this.context.set_state_callback (context_state_callback);
79+
80+ if (context.connect(null, Context.Flags.NOFAIL, null) < 0)
81+ warning( "pa_context_connect() failed: %s\n", PulseAudio.strerror(context.errno()));
82 }
83
84 /* Mute operations */

Subscribers

People subscribed via source and target branches