diff sat/bridge/bridge_constructor/constructors/dbus/constructor.py @ 3042:964abd07dc03

bridge (dbus): AsyncIO version of D-Bus bridge: The frontends D-Bus bridge has now an AIOBridge version which can be instantiated to use asyncio (the loop must be managed by frontends).
author Goffi <goffi@goffi.org>
date Tue, 01 Oct 2019 22:49:10 +0200
parents ab2696e34d29
children 9d0df638c8b4
line wrap: on
line diff
--- a/sat/bridge/bridge_constructor/constructors/dbus/constructor.py	Tue Oct 01 22:49:06 2019 +0200
+++ b/sat/bridge/bridge_constructor/constructors/dbus/constructor.py	Tue Oct 01 22:49:10 2019 +0200
@@ -46,7 +46,15 @@
     FRONTEND_FORMATS = {
         "methods": """\
     def {name}(self, {args}{async_comma}{async_args}):
-        {error_handler}{blocking_call}{debug}return {result}\n"""
+        {error_handler}{blocking_call}{debug}return {result}\n""",
+        "async_methods": """\
+    def {name}(self{async_comma}{args}):
+        loop = asyncio.get_running_loop()
+        fut = loop.create_future()
+        reply_handler = lambda ret=None: loop.call_soon_threadsafe(fut.set_result, ret)
+        error_handler = lambda err: loop.call_soon_threadsafe(fut.set_exception, dbus_to_bridge_exception(err))
+        self.db_{category}_iface.{name}({args_result}{async_comma}timeout=const_TIMEOUT, reply_handler=reply_handler, error_handler=error_handler)
+        {debug}return fut\n""",
     }
 
     def core_completion_signal(self, completion, function, default, arg_doc, async_):