2005-10-29 19:13:17 +00:00
|
|
|
import _util
|
2005-05-01 19:34:58 +00:00
|
|
|
import inspect
|
2005-05-24 00:21:07 +00:00
|
|
|
import dbus_bindings
|
2005-05-01 19:34:58 +00:00
|
|
|
|
2005-11-04 12:18:00 +00:00
|
|
|
def method(dbus_interface, in_signature=None, out_signature=None, async_callbacks=None):
|
2005-05-01 19:34:58 +00:00
|
|
|
_util._validate_interface_or_name(dbus_interface)
|
|
|
|
|
|
|
|
|
|
def decorator(func):
|
2005-11-04 12:18:00 +00:00
|
|
|
args = inspect.getargspec(func)[0]
|
|
|
|
|
args.pop(0)
|
|
|
|
|
|
|
|
|
|
if async_callbacks:
|
|
|
|
|
if type(async_callbacks) != tuple:
|
|
|
|
|
raise TypeError('async_callbacks must be a tuple of (keyword for return callback, keyword for error callback)')
|
|
|
|
|
if len(async_callbacks) != 2:
|
|
|
|
|
raise ValueError('async_callbacks must be a tuple of (keyword for return callback, keyword for error callback)')
|
|
|
|
|
args.remove(async_callbacks[0])
|
|
|
|
|
args.remove(async_callbacks[1])
|
|
|
|
|
|
|
|
|
|
if in_signature:
|
|
|
|
|
in_sig = tuple(dbus_bindings.Signature(in_signature))
|
|
|
|
|
|
|
|
|
|
if len(in_sig) > len(args):
|
|
|
|
|
raise ValueError, 'input signature is longer than the number of arguments taken'
|
|
|
|
|
elif len(in_sig) < len(args):
|
|
|
|
|
raise ValueError, 'input signature is shorter than the number of arguments taken'
|
|
|
|
|
|
2005-05-01 19:34:58 +00:00
|
|
|
func._dbus_is_method = True
|
2005-11-04 12:18:00 +00:00
|
|
|
func._dbus_async_callbacks = async_callbacks
|
2005-05-01 19:34:58 +00:00
|
|
|
func._dbus_interface = dbus_interface
|
2005-10-29 19:13:17 +00:00
|
|
|
func._dbus_in_signature = in_signature
|
|
|
|
|
func._dbus_out_signature = out_signature
|
2005-11-04 12:18:00 +00:00
|
|
|
func._dbus_args = args
|
2005-05-01 19:34:58 +00:00
|
|
|
return func
|
|
|
|
|
|
|
|
|
|
return decorator
|
|
|
|
|
|
2005-10-29 19:13:17 +00:00
|
|
|
def signal(dbus_interface, signature=None):
|
2005-05-01 19:34:58 +00:00
|
|
|
_util._validate_interface_or_name(dbus_interface)
|
|
|
|
|
def decorator(func):
|
|
|
|
|
def emit_signal(self, *args, **keywords):
|
2005-11-07 15:31:30 +00:00
|
|
|
func(self, *args, **keywords)
|
2005-05-24 00:21:07 +00:00
|
|
|
message = dbus_bindings.Signal(self._object_path, dbus_interface, func.__name__)
|
2005-05-01 19:34:58 +00:00
|
|
|
iter = message.get_iter(True)
|
2005-11-07 15:31:30 +00:00
|
|
|
|
|
|
|
|
if emit_signal._dbus_signature:
|
|
|
|
|
signature = tuple(dbus_bindings.Signature(emit_signal._dbus_signature))
|
|
|
|
|
for (arg, sig) in zip(args, signature):
|
|
|
|
|
iter.append_strict(arg, sig)
|
|
|
|
|
else:
|
|
|
|
|
for arg in args:
|
|
|
|
|
iter.append(arg)
|
|
|
|
|
|
2005-05-01 19:34:58 +00:00
|
|
|
self._connection.send(message)
|
2005-05-24 00:21:07 +00:00
|
|
|
|
2005-11-04 12:18:00 +00:00
|
|
|
args = inspect.getargspec(func)[0]
|
|
|
|
|
args.pop(0)
|
|
|
|
|
|
|
|
|
|
if signature:
|
2005-11-07 15:31:30 +00:00
|
|
|
sig = tuple(dbus_bindings.Signature(signature))
|
2005-11-04 12:18:00 +00:00
|
|
|
|
|
|
|
|
if len(sig) > len(args):
|
|
|
|
|
raise ValueError, 'signal signature is longer than the number of arguments provided'
|
|
|
|
|
elif len(sig) < len(args):
|
|
|
|
|
raise ValueError, 'signal signature is shorter than the number of arguments provided'
|
|
|
|
|
|
2005-10-29 19:13:17 +00:00
|
|
|
emit_signal.__name__ = func.__name__
|
|
|
|
|
emit_signal.__doc__ = func.__doc__
|
2005-05-01 19:34:58 +00:00
|
|
|
emit_signal._dbus_is_signal = True
|
|
|
|
|
emit_signal._dbus_interface = dbus_interface
|
2005-10-29 19:13:17 +00:00
|
|
|
emit_signal._dbus_signature = signature
|
2005-11-04 12:18:00 +00:00
|
|
|
emit_signal._dbus_args = args
|
2005-05-01 19:34:58 +00:00
|
|
|
return emit_signal
|
|
|
|
|
|
|
|
|
|
return decorator
|
|
|
|
|
|
2005-05-24 16:30:51 +00:00
|
|
|
def explicitly_pass_message(func):
|
|
|
|
|
func._dbus_pass_message = True
|
|
|
|
|
return func
|