diff 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
line wrap: on
line diff
--- a/src/bridge/DBus.py	Tue Nov 01 23:06:18 2011 +0100
+++ b/src/bridge/DBus.py	Wed Nov 02 22:47:59 2011 +0100
@@ -27,10 +27,16 @@
 from logging import debug, info
 
 const_INT_PREFIX = "org.goffi.SAT"  #Interface prefix
+const_ERROR_PREFIX = const_INT_PREFIX+".error"
 const_OBJ_PATH = '/org/goffi/SAT/bridge'
 const_CORE_SUFFIX = ".core"
 const_PLUGIN_SUFFIX = ".plugin"
 
+class GenericException(dbus.DBusException):
+    def __init__(self, name):
+        super(GenericException,self).__init__()
+        self._dbus_error_name = const_ERROR_PREFIX+"."+name
+
 class DbusObject(dbus.service.Object):
 
     def __init__(self, bus, path):
@@ -134,13 +140,19 @@
                          in_signature='s', out_signature='',
                          async_callbacks=('callback', 'errback'))
     def asyncConnect(self, profile_key="@DEFAULT@", callback=None, errback=None):
-        return self.cb["asyncConnect"](unicode(profile_key), callback, errback)
+        return self.cb["asyncConnect"](unicode(profile_key), callback, lambda arg:errback(GenericException(arg)))
+
+    @dbus.service.method(const_INT_PREFIX+const_CORE_SUFFIX,
+                         in_signature='s', out_signature='',
+                         async_callbacks=('callback', 'errback'))
+    def asyncCreateProfile(self, profile, callback=None, errback=None):
+        return self.cb["asyncCreateProfile"](unicode(profile), callback, lambda arg:errback(GenericException(arg)))
 
     @dbus.service.method(const_INT_PREFIX+const_CORE_SUFFIX,
                          in_signature='ssss', out_signature='s',
                          async_callbacks=('callback', 'errback'))
     def asyncGetParamA(self, name, category, attribute="value", profile_key="@DEFAULT@", callback=None, errback=None):
-        return self.cb["asyncGetParamA"](unicode(name), unicode(category), unicode(attribute), unicode(profile_key), callback, errback)
+        return self.cb["asyncGetParamA"](unicode(name), unicode(category), unicode(attribute), unicode(profile_key), callback, lambda arg:errback(GenericException(arg)))
 
     @dbus.service.method(const_INT_PREFIX+const_CORE_SUFFIX,
                          in_signature='ssss', out_signature='s',