dbus: pass the bus name lost signal up to tuhi
If we're losing the bus name (i.e. we can't get it on startup) there really isn't much we can do other than fail miserably. But in passing signals around we can't do exceptions, so we have to move the mainloop to Tuhi so we can quit() it on error. Fixes #25
This commit is contained in:
parent
cae296e030
commit
2fd781974f
11
tuhi/base.py
11
tuhi/base.py
|
@ -203,6 +203,7 @@ class Tuhi(GObject.Object):
|
|||
GObject.Object.__init__(self)
|
||||
self.server = TuhiDBusServer()
|
||||
self.server.connect('bus-name-acquired', self._on_tuhi_bus_name_acquired)
|
||||
self.server.connect('bus-name-lost', self._on_tuhi_bus_name_lost)
|
||||
self.server.connect('search-start-requested', self._on_start_search_requested)
|
||||
self.server.connect('search-stop-requested', self._on_stop_search_requested)
|
||||
self.bluez = BlueZDeviceManager()
|
||||
|
@ -216,10 +217,14 @@ class Tuhi(GObject.Object):
|
|||
self.devices = {}
|
||||
|
||||
self._search_stop_handler = None
|
||||
self.mainloop = GObject.MainLoop()
|
||||
|
||||
def _on_tuhi_bus_name_acquired(self, dbus_server):
|
||||
self.bluez.connect_to_bluez()
|
||||
|
||||
def _on_tuhi_bus_name_lost(self, dbus_server):
|
||||
self.mainloop.quit()
|
||||
|
||||
def _on_start_search_requested(self, dbus_server, stop_handler):
|
||||
self._search_stop_handler = stop_handler
|
||||
self.bluez.start_discovery()
|
||||
|
@ -306,6 +311,9 @@ class Tuhi(GObject.Object):
|
|||
else:
|
||||
self.bluez.stop_discovery()
|
||||
|
||||
def run(self):
|
||||
self.mainloop.run()
|
||||
|
||||
|
||||
def main(args=sys.argv):
|
||||
desc = "Daemon to extract the pen stroke data from Wacom SmartPad devices"
|
||||
|
@ -319,9 +327,8 @@ def main(args=sys.argv):
|
|||
if ns.verbose:
|
||||
logger.setLevel(logging.DEBUG)
|
||||
|
||||
Tuhi()
|
||||
try:
|
||||
GObject.MainLoop().run()
|
||||
Tuhi().run()
|
||||
except KeyboardInterrupt:
|
||||
pass
|
||||
finally:
|
||||
|
|
|
@ -309,6 +309,8 @@ class TuhiDBusServer(_TuhiDBus):
|
|||
__gsignals__ = {
|
||||
"bus-name-acquired":
|
||||
(GObject.SIGNAL_RUN_FIRST, None, ()),
|
||||
"bus-name-lost":
|
||||
(GObject.SIGNAL_RUN_FIRST, None, ()),
|
||||
|
||||
# Signal arguments:
|
||||
# search_stop_handler(status)
|
||||
|
@ -361,7 +363,8 @@ class TuhiDBusServer(_TuhiDBus):
|
|||
self.emit('bus-name-acquired')
|
||||
|
||||
def _bus_name_lost(self, connection, name):
|
||||
pass
|
||||
logger.error('Bus not available, is there another Tuhi process running?')
|
||||
self.emit('bus-name-lost')
|
||||
|
||||
def _method_cb(self, connection, sender, objpath, interface, methodname, args, invocation):
|
||||
if interface != self.interface:
|
||||
|
|
Loading…
Reference in New Issue