bridge: added generic D-Bus exception management + asyncCreateProfile method
This commit is contained in:
parent
ff787e5ca4
commit
407ae30ffb
5 changed files with 38 additions and 4 deletions
|
|
@ -27,10 +27,16 @@ import dbus.mainloop.glib
|
|||
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 @@ class DbusObject(dbus.service.Object):
|
|||
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',
|
||||
|
|
|
|||
|
|
@ -393,7 +393,7 @@ class DbusConstructor(Constructor):
|
|||
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 @@ class DbusConstructor(Constructor):
|
|||
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("""\
|
||||
|
|
|
|||
|
|
@ -172,6 +172,7 @@ sig_out=as
|
|||
doc=Get all profiles
|
||||
|
||||
[createProfile]
|
||||
deprecated=
|
||||
type=method
|
||||
category=core
|
||||
sig_in=s
|
||||
|
|
@ -182,6 +183,20 @@ doc_return=status of the creation:
|
|||
- 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
|
||||
|
|
|
|||
|
|
@ -27,10 +27,16 @@ import dbus.mainloop.glib
|
|||
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):
|
||||
|
|
|
|||
|
|
@ -24,6 +24,7 @@ import dbus, dbus.glib
|
|||
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"
|
||||
|
|
|
|||
Loading…
Reference in a new issue