Try to start PulseAudio if the connection failed (max 3 times).

The logic here is quite complex.
Leaved some print on purpose to see how it works
This commit is contained in:
Davide Andreoli 2014-09-02 20:24:58 +02:00
parent 8b724d1cf2
commit 243f25da04
1 changed files with 12 additions and 5 deletions

View File

@ -379,6 +379,7 @@ class PulseAudio_Client(object):
self.conn = None
self.srv_addr = None
self.channels = []
self.exe_count = 0
self.try_to_connect()
@ -402,20 +403,26 @@ class PulseAudio_Client(object):
return None
def try_to_connect(self):
if self.connect() is False:
print("PULSE: try_to_connect")
if self.conn is None and self.connect() is False:
ecore.Timer(5.0, self.try_to_connect)
return ecore.ECORE_CALLBACK_CANCEL
def connect(self):
print("PULSE: connect %d", self.exe_count)
self.srv_addr = self.address_lookup()
if self.srv_addr is None:
# TODO maybe try to start pulse here
return False
try:
self.conn = dbus.connection.Connection(self.srv_addr,
mainloop=DBusEcoreMainLoop())
except:
if self.exe_count < 3:
print("PULSE: Exe")
self.exe_count += 1
x = ecore.Exe('pulseaudio --start')
x.on_del_event_add(lambda *a: self.connect())
return False
self.exe_count = 0
self.conn.call_on_disconnection(self.disconnect_cb)
# get all available channels
@ -447,7 +454,7 @@ class PulseAudio_Client(object):
self.conn = None
self.srv_addr = None
self.channels = []
ecore.Timer(1.0, self.try_to_connect)
ecore.Timer(3.0, self.try_to_connect)
def channel_signal_cb(self, *args, signal):
obj_path = args[0]