[gnome-builder/wip/chergert/multi-process] gdbus: add basic async support to Builder.py overrides
- From: Christian Hergert <chergert src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-builder/wip/chergert/multi-process] gdbus: add basic async support to Builder.py overrides
- Date: Tue, 20 Oct 2015 20:05:20 +0000 (UTC)
commit 58c3ecd8dc4b52537be44e668f7c82b790a7527f
Author: Christian Hergert <chergert redhat com>
Date: Tue Oct 20 13:04:53 2015 -0700
gdbus: add basic async support to Builder.py overrides
This allows us to do (async=True) in the decorator so that the callee
can delay the response to further async work.
src/Builder.py | 13 ++++++++++---
1 files changed, 10 insertions(+), 3 deletions(-)
---
diff --git a/src/Builder.py b/src/Builder.py
index a6784ef..6485e63 100644
--- a/src/Builder.py
+++ b/src/Builder.py
@@ -41,8 +41,10 @@ class _Gio_DBusMethodInfo:
in_args = None
out_signature = None
-def DBusMethod(dbus_interface, in_signature=None, out_signature=None):
+def DBusMethod(dbus_interface, in_signature=None, out_signature=None, async=False):
def decorator(func):
+ func._is_async = async
+
func._dbus_method = _Gio_DBusMethodInfo()
func._dbus_method.interface = dbus_interface
#func._dbus_method.out_signature = '(' + (out_signature or '') + ')'
@@ -52,6 +54,7 @@ def DBusMethod(dbus_interface, in_signature=None, out_signature=None):
in_signature_list = GLib.Variant.split_signature(in_signature)
arg_names = inspect.getargspec(func).args
arg_names.pop(0) # eat "self" argument
+ if async: arg_names.pop(0) # eat "invocation"
if len(in_signature) != len(arg_names):
raise TypeError('specified signature %s for method %s does not match length of arguments' %
(str(in_signature_list), func.func_name))
for pair in zip(in_signature_list, arg_names):
@@ -135,8 +138,12 @@ class DBusService:
return
try:
- ret = getattr(self, method_name)(*parameters.unpack())
- invocation.return_value(GLib.Variant('(' + info['out_signature'] + ')', (ret,)))
+ func = getattr(self, method_name)
+ if func._is_async:
+ ret = func(invocation, *parameters.unpack())
+ else:
+ ret = func(*parameters.unpack())
+ invocation.return_value(GLib.Variant('(' + info['out_signature'] + ')', (ret,)))
except Exception as e:
invocation.return_error_literal(Gio.dbus_error_quark(),
Gio.DBusError.IO_ERROR,
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]