comparison src/bridge/bridge_constructor/dbus_frontend_template.py @ 627:d207c2186519

core, bridge, jp, quick_frontend: SàT stop more gracefully if bridge can't be initialised: - new BridgeInitError and BridgeExceptionNoService are in core.exceptions - D-Bus NotSupported is catched in bridge, and launch a BridgeInitError - BridgeInitError stop SàT core, jp, and quick_frontends with an explanation message. fix bug 27
author Goffi <goffi@goffi.org>
date Fri, 21 Jun 2013 02:00:37 +0200
parents 84a6e83157c2
children 648511e42a69
comparison
equal deleted inserted replaced
626:190ccc6dc36c 627:d207c2186519
18 # along with this program. If not, see <http://www.gnu.org/licenses/>. 18 # along with this program. If not, see <http://www.gnu.org/licenses/>.
19 19
20 from bridge_frontend import BridgeFrontend 20 from bridge_frontend import BridgeFrontend
21 import dbus 21 import dbus
22 from logging import debug, error 22 from logging import debug, error
23 from sat.core.exceptions import BridgeExceptionNoService, BridgeInitError
23 24
24 from dbus.mainloop.glib import DBusGMainLoop 25 from dbus.mainloop.glib import DBusGMainLoop
25 DBusGMainLoop(set_as_default=True) 26 DBusGMainLoop(set_as_default=True)
26 27
27 const_INT_PREFIX = "org.goffi.SAT" # Interface prefix 28 const_INT_PREFIX = "org.goffi.SAT" # Interface prefix
28 const_ERROR_PREFIX = const_INT_PREFIX + ".error" 29 const_ERROR_PREFIX = const_INT_PREFIX + ".error"
29 const_OBJ_PATH = '/org/goffi/SAT/bridge' 30 const_OBJ_PATH = '/org/goffi/SAT/bridge'
30 const_CORE_SUFFIX = ".core" 31 const_CORE_SUFFIX = ".core"
31 const_PLUGIN_SUFFIX = ".plugin" 32 const_PLUGIN_SUFFIX = ".plugin"
32
33
34 class BridgeExceptionNoService(Exception):
35 pass
36 33
37 34
38 class DBusBridgeFrontend(BridgeFrontend): 35 class DBusBridgeFrontend(BridgeFrontend):
39 def __init__(self): 36 def __init__(self):
40 try: 37 try:
46 self.db_plugin_iface = dbus.Interface(self.db_object, 43 self.db_plugin_iface = dbus.Interface(self.db_object,
47 dbus_interface=const_INT_PREFIX + const_PLUGIN_SUFFIX) 44 dbus_interface=const_INT_PREFIX + const_PLUGIN_SUFFIX)
48 except dbus.exceptions.DBusException, e: 45 except dbus.exceptions.DBusException, e:
49 if e._dbus_error_name == 'org.freedesktop.DBus.Error.ServiceUnknown': 46 if e._dbus_error_name == 'org.freedesktop.DBus.Error.ServiceUnknown':
50 raise BridgeExceptionNoService 47 raise BridgeExceptionNoService
48 elif e._dbus_error_name == 'org.freedesktop.DBus.Error.NotSupported':
49 print u"D-Bus is not launched, please see README to see instructions on how to launch it"
50 raise BridgeInitError
51 else: 51 else:
52 raise e 52 raise e
53 #props = self.db_core_iface.getProperties() 53 #props = self.db_core_iface.getProperties()
54 54
55 def register(self, functionName, handler, iface="core"): 55 def register(self, functionName, handler, iface="core"):