# HG changeset patch # User Goffi # Date 1320270479 -3600 # Node ID 6c167a2e04b8f58169a21efde000af6c91a1ffe6 # Parent 199cf4ebcc74a14971511b181fc46640eee1eb2c bridge: added generic D-Bus exception management + asyncCreateProfile method diff -r 199cf4ebcc74 -r 6c167a2e04b8 src/bridge/DBus.py --- 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', diff -r 199cf4ebcc74 -r 6c167a2e04b8 src/bridge/bridge_constructor/bridge_contructor.py --- a/src/bridge/bridge_constructor/bridge_contructor.py Tue Nov 01 23:06:18 2011 +0100 +++ b/src/bridge/bridge_constructor/bridge_contructor.py Wed Nov 02 22:47:59 2011 +0100 @@ -393,7 +393,7 @@ completion['args_result'] = self.getArguments(function['sig_in'], name=arg_doc, unicode_protect=self.options.unicode) completion['async_comma'] = ', ' if async and function['sig_in'] else '' completion['async_args_def'] = 'callback=None, errback=None' if async else '' - completion['async_args_call'] = 'callback, errback' if async else '' + completion['async_args_call'] = 'callback, lambda arg:errback(GenericException(arg))' if async else '' completion['async_callbacks'] = "('callback', 'errback')" if async else "None" methods_part.append("""\ @dbus.service.method(const_INT_PREFIX+const_%(category)s_SUFFIX, @@ -455,7 +455,7 @@ completion['args_result'] = self.getArguments(function['sig_in'], name=arg_doc) completion['async_args'] = ', callback=None, errback=None' if async else '' completion['async_comma'] = ', ' if async and function['sig_in'] else '' - completion['async_args_result'] = 'reply_handler=callback, error_handler=errback' if async else '' + completion['async_args_result'] = 'reply_handler=callback, error_handler=lambda err:errback(err._dbus_error_name[len(const_ERROR_PREFIX)+1:])' if async else '' result = "self.db_%(category)s_iface.%(name)s(%(args_result)s%(async_comma)s%(async_args_result)s)" % completion completion['result'] = ("unicode(%s)" if self.options.unicode and function['sig_out'] == 's' else "%s") % result methods_part.append("""\ diff -r 199cf4ebcc74 -r 6c167a2e04b8 src/bridge/bridge_constructor/bridge_template.ini --- a/src/bridge/bridge_constructor/bridge_template.ini Tue Nov 01 23:06:18 2011 +0100 +++ b/src/bridge/bridge_constructor/bridge_template.ini Wed Nov 02 22:47:59 2011 +0100 @@ -172,6 +172,7 @@ doc=Get all profiles [createProfile] +deprecated= type=method category=core sig_in=s @@ -182,6 +183,20 @@ - 0: Profile created - 1: The profile name already exists +[asyncCreateProfile] +async= +type=method +category=core +sig_in=s +sig_out= +doc=Create a new profile +doc_param_0=%(doc_profile)s +doc_return=callback is called when profile actually exists in database and memory +errback is called with error constant as parameter: + - "CONFLICT": The profile name already exists + - "CANCELED": profile creation canceled + - "DATABASE": profile creation in database failed + [deleteProfile] type=method category=core diff -r 199cf4ebcc74 -r 6c167a2e04b8 src/bridge/bridge_constructor/dbus_core_template.py --- a/src/bridge/bridge_constructor/dbus_core_template.py Tue Nov 01 23:06:18 2011 +0100 +++ b/src/bridge/bridge_constructor/dbus_core_template.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): diff -r 199cf4ebcc74 -r 6c167a2e04b8 src/bridge/bridge_constructor/dbus_frontend_template.py --- a/src/bridge/bridge_constructor/dbus_frontend_template.py Tue Nov 01 23:06:18 2011 +0100 +++ b/src/bridge/bridge_constructor/dbus_frontend_template.py Wed Nov 02 22:47:59 2011 +0100 @@ -24,6 +24,7 @@ from logging import debug, error 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"