comparison src/bridge/DBus.py @ 419:6c167a2e04b8

bridge: added generic D-Bus exception management + asyncCreateProfile method
author Goffi <goffi@goffi.org>
date Wed, 02 Nov 2011 22:47:59 +0100
parents dd4caab17008
children 6c20c76abdcc
comparison
equal deleted inserted replaced
418:199cf4ebcc74 419:6c167a2e04b8
25 import dbus.service 25 import dbus.service
26 import dbus.mainloop.glib 26 import dbus.mainloop.glib
27 from logging import debug, info 27 from logging import debug, info
28 28
29 const_INT_PREFIX = "org.goffi.SAT" #Interface prefix 29 const_INT_PREFIX = "org.goffi.SAT" #Interface prefix
30 const_ERROR_PREFIX = const_INT_PREFIX+".error"
30 const_OBJ_PATH = '/org/goffi/SAT/bridge' 31 const_OBJ_PATH = '/org/goffi/SAT/bridge'
31 const_CORE_SUFFIX = ".core" 32 const_CORE_SUFFIX = ".core"
32 const_PLUGIN_SUFFIX = ".plugin" 33 const_PLUGIN_SUFFIX = ".plugin"
34
35 class GenericException(dbus.DBusException):
36 def __init__(self, name):
37 super(GenericException,self).__init__()
38 self._dbus_error_name = const_ERROR_PREFIX+"."+name
33 39
34 class DbusObject(dbus.service.Object): 40 class DbusObject(dbus.service.Object):
35 41
36 def __init__(self, bus, path): 42 def __init__(self, bus, path):
37 dbus.service.Object.__init__(self, bus, path) 43 dbus.service.Object.__init__(self, bus, path)
132 138
133 @dbus.service.method(const_INT_PREFIX+const_CORE_SUFFIX, 139 @dbus.service.method(const_INT_PREFIX+const_CORE_SUFFIX,
134 in_signature='s', out_signature='', 140 in_signature='s', out_signature='',
135 async_callbacks=('callback', 'errback')) 141 async_callbacks=('callback', 'errback'))
136 def asyncConnect(self, profile_key="@DEFAULT@", callback=None, errback=None): 142 def asyncConnect(self, profile_key="@DEFAULT@", callback=None, errback=None):
137 return self.cb["asyncConnect"](unicode(profile_key), callback, errback) 143 return self.cb["asyncConnect"](unicode(profile_key), callback, lambda arg:errback(GenericException(arg)))
144
145 @dbus.service.method(const_INT_PREFIX+const_CORE_SUFFIX,
146 in_signature='s', out_signature='',
147 async_callbacks=('callback', 'errback'))
148 def asyncCreateProfile(self, profile, callback=None, errback=None):
149 return self.cb["asyncCreateProfile"](unicode(profile), callback, lambda arg:errback(GenericException(arg)))
138 150
139 @dbus.service.method(const_INT_PREFIX+const_CORE_SUFFIX, 151 @dbus.service.method(const_INT_PREFIX+const_CORE_SUFFIX,
140 in_signature='ssss', out_signature='s', 152 in_signature='ssss', out_signature='s',
141 async_callbacks=('callback', 'errback')) 153 async_callbacks=('callback', 'errback'))
142 def asyncGetParamA(self, name, category, attribute="value", profile_key="@DEFAULT@", callback=None, errback=None): 154 def asyncGetParamA(self, name, category, attribute="value", profile_key="@DEFAULT@", callback=None, errback=None):
143 return self.cb["asyncGetParamA"](unicode(name), unicode(category), unicode(attribute), unicode(profile_key), callback, errback) 155 return self.cb["asyncGetParamA"](unicode(name), unicode(category), unicode(attribute), unicode(profile_key), callback, lambda arg:errback(GenericException(arg)))
144 156
145 @dbus.service.method(const_INT_PREFIX+const_CORE_SUFFIX, 157 @dbus.service.method(const_INT_PREFIX+const_CORE_SUFFIX,
146 in_signature='ssss', out_signature='s', 158 in_signature='ssss', out_signature='s',
147 async_callbacks=None) 159 async_callbacks=None)
148 def callMenu(self, category, name, menu_type, profile_key): 160 def callMenu(self, category, name, menu_type, profile_key):