Mercurial > libervia-backend
comparison sat/bridge/bridge_constructor/constructors/dbus/constructor.py @ 3539:60d3861e5996
bridge (dbus): use Tx DBus for backend part of D-Bus bridge:
Due to recent SQLAlchemy integration, Libervia is now using AsyncIO loop exclusively as
main loop, thus GLib's one can't be used anymore (event if it could be in a separate
thread).
Furthermore Python-DBus is known to have design flaws mentioned even in the official
documentation.
Tx DBus is now used to replace Python-DBus, but only for the backend for now, as it will
need some work on the frontend before we can get completely rid of it.
author | Goffi <goffi@goffi.org> |
---|---|
date | Thu, 03 Jun 2021 15:21:43 +0200 |
parents | 7550ae9cfbac |
children | 524856bd7b19 |
comparison
equal
deleted
inserted
replaced
3538:c605a0d6506f | 3539:60d3861e5996 |
---|---|
23 class DbusConstructor(base_constructor.Constructor): | 23 class DbusConstructor(base_constructor.Constructor): |
24 NAME = "dbus" | 24 NAME = "dbus" |
25 CORE_TEMPLATE = "dbus_core_template.py" | 25 CORE_TEMPLATE = "dbus_core_template.py" |
26 CORE_DEST = "dbus_bridge.py" | 26 CORE_DEST = "dbus_bridge.py" |
27 CORE_FORMATS = { | 27 CORE_FORMATS = { |
28 "methods_declarations": """\ | |
29 Method('{name}', arguments='{sig_in}', returns='{sig_out}'),""", | |
30 | |
31 "methods": """\ | |
32 def dbus_{name}(self, {args}): | |
33 {debug}return self._callback("{name}", {args_no_default})\n""", | |
34 | |
35 "signals_declarations": """\ | |
36 Signal('{name}', '{sig_in}'),""", | |
37 | |
28 "signals": """\ | 38 "signals": """\ |
29 @dbus.service.signal(const_INT_PREFIX+const_{category}_SUFFIX, | |
30 signature='{sig_in}') | |
31 def {name}(self, {args}): | 39 def {name}(self, {args}): |
32 {body}\n""", | 40 self._obj.emitSignal("{name}", {args})\n""", |
33 "methods": """\ | |
34 @dbus.service.method(const_INT_PREFIX+const_{category}_SUFFIX, | |
35 in_signature='{sig_in}', out_signature='{sig_out}', | |
36 async_callbacks={async_callbacks}) | |
37 def {name}(self, {args}{async_comma}{async_args_def}): | |
38 {debug}return self._callback("{name}", {args_result}{async_comma}{async_args_call})\n""", | |
39 "signal_direct_calls": """\ | |
40 def {name}(self, {args}): | |
41 self.dbus_bridge.{name}({args})\n""", | |
42 } | 41 } |
43 | 42 |
44 FRONTEND_TEMPLATE = "dbus_frontend_template.py" | 43 FRONTEND_TEMPLATE = "dbus_frontend_template.py" |
45 FRONTEND_DEST = CORE_DEST | 44 FRONTEND_DEST = CORE_DEST |
46 FRONTEND_FORMATS = { | 45 FRONTEND_FORMATS = { |
66 ) | 65 ) |
67 | 66 |
68 def core_completion_method(self, completion, function, default, arg_doc, async_): | 67 def core_completion_method(self, completion, function, default, arg_doc, async_): |
69 completion.update( | 68 completion.update( |
70 { | 69 { |
71 "debug": "" | 70 "debug": ( |
72 if not self.args.debug | 71 "" if not self.args.debug |
73 else 'log.debug ("%s")\n%s' % (completion["name"], 8 * " "), | 72 else f'log.debug ("{completion["name"]}")\n{8 * " "}' |
74 "args_result": self.getArguments( | 73 ) |
75 function["sig_in"], name=arg_doc, unicode_protect=self.args.unicode | |
76 ), | |
77 "async_comma": ", " if async_ and function["sig_in"] else "", | |
78 "async_args_def": "callback=None, errback=None" if async_ else "", | |
79 "async_args_call": "callback=callback, errback=errback" if async_ else "", | |
80 "async_callbacks": "('callback', 'errback')" if async_ else "None", | |
81 "category": completion["category"].upper(), | |
82 } | 74 } |
83 ) | 75 ) |
84 | 76 |
85 def frontend_completion_method(self, completion, function, default, arg_doc, async_): | 77 def frontend_completion_method(self, completion, function, default, arg_doc, async_): |
86 completion.update( | 78 completion.update( |