annotate libervia/backend/bridge/bridge_constructor/constructors/dbus/dbus_core_template.py @ 4272:89a0999884ac default tip @

cli (list/set): add "--comments" argument.
author Goffi <goffi@goffi.org>
date Thu, 20 Jun 2024 14:46:55 +0200
parents 0d7bb4df2343
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2771
diff changeset
1 #!/usr/bin/env python3
3137
559a625a236b fixed shebangs
Goffi <goffi@goffi.org>
parents: 3136
diff changeset
2
3539
60d3861e5996 bridge (dbus): use Tx DBus for backend part of D-Bus bridge:
Goffi <goffi@goffi.org>
parents: 3480
diff changeset
3 # Libervia communication bridge
3479
be6d91572633 date update
Goffi <goffi@goffi.org>
parents: 3143
diff changeset
4 # Copyright (C) 2009-2021 Jérôme Poisson (goffi@goffi.org)
267
bdcd535e179e Bridge constructor:
Goffi <goffi@goffi.org>
parents:
diff changeset
5
609
84a6e83157c2 fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents: 595
diff changeset
6 # This program is free software: you can redistribute it and/or modify
84a6e83157c2 fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents: 595
diff changeset
7 # it under the terms of the GNU Affero General Public License as published by
84a6e83157c2 fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents: 595
diff changeset
8 # the Free Software Foundation, either version 3 of the License, or
84a6e83157c2 fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents: 595
diff changeset
9 # (at your option) any later version.
267
bdcd535e179e Bridge constructor:
Goffi <goffi@goffi.org>
parents:
diff changeset
10
609
84a6e83157c2 fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents: 595
diff changeset
11 # This program is distributed in the hope that it will be useful,
84a6e83157c2 fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents: 595
diff changeset
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
84a6e83157c2 fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents: 595
diff changeset
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
84a6e83157c2 fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents: 595
diff changeset
14 # GNU Affero General Public License for more details.
267
bdcd535e179e Bridge constructor:
Goffi <goffi@goffi.org>
parents:
diff changeset
15
609
84a6e83157c2 fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents: 595
diff changeset
16 # You should have received a copy of the GNU Affero General Public License
84a6e83157c2 fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents: 595
diff changeset
17 # along with this program. If not, see <http://www.gnu.org/licenses/>.
267
bdcd535e179e Bridge constructor:
Goffi <goffi@goffi.org>
parents:
diff changeset
18
3539
60d3861e5996 bridge (dbus): use Tx DBus for backend part of D-Bus bridge:
Goffi <goffi@goffi.org>
parents: 3480
diff changeset
19 from types import MethodType
60d3861e5996 bridge (dbus): use Tx DBus for backend part of D-Bus bridge:
Goffi <goffi@goffi.org>
parents: 3480
diff changeset
20 from functools import partialmethod
60d3861e5996 bridge (dbus): use Tx DBus for backend part of D-Bus bridge:
Goffi <goffi@goffi.org>
parents: 3480
diff changeset
21 from twisted.internet import defer, reactor
4071
4b842c1fb686 refactoring: renamed `sat` package to `libervia.backend`
Goffi <goffi@goffi.org>
parents: 4037
diff changeset
22 from libervia.backend.core.i18n import _
4b842c1fb686 refactoring: renamed `sat` package to `libervia.backend`
Goffi <goffi@goffi.org>
parents: 4037
diff changeset
23 from libervia.backend.core.log import getLogger
4b842c1fb686 refactoring: renamed `sat` package to `libervia.backend`
Goffi <goffi@goffi.org>
parents: 4037
diff changeset
24 from libervia.backend.core.exceptions import BridgeInitError
4b842c1fb686 refactoring: renamed `sat` package to `libervia.backend`
Goffi <goffi@goffi.org>
parents: 4037
diff changeset
25 from libervia.backend.tools import config
3539
60d3861e5996 bridge (dbus): use Tx DBus for backend part of D-Bus bridge:
Goffi <goffi@goffi.org>
parents: 3480
diff changeset
26 from txdbus import client, objects, error
60d3861e5996 bridge (dbus): use Tx DBus for backend part of D-Bus bridge:
Goffi <goffi@goffi.org>
parents: 3480
diff changeset
27 from txdbus.interface import DBusInterface, Method, Signal
267
bdcd535e179e Bridge constructor:
Goffi <goffi@goffi.org>
parents:
diff changeset
28
3143
830fce0db15d bridge (dbus): new `bridge_dbus_int_prefix` option (in `[DEFAULT]` settings) to change interface prefix
Goffi <goffi@goffi.org>
parents: 3137
diff changeset
29
830fce0db15d bridge (dbus): new `bridge_dbus_int_prefix` option (in `[DEFAULT]` settings) to change interface prefix
Goffi <goffi@goffi.org>
parents: 3137
diff changeset
30 log = getLogger(__name__)
830fce0db15d bridge (dbus): new `bridge_dbus_int_prefix` option (in `[DEFAULT]` settings) to change interface prefix
Goffi <goffi@goffi.org>
parents: 3137
diff changeset
31
830fce0db15d bridge (dbus): new `bridge_dbus_int_prefix` option (in `[DEFAULT]` settings) to change interface prefix
Goffi <goffi@goffi.org>
parents: 3137
diff changeset
32 # Interface prefix
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3539
diff changeset
33 const_INT_PREFIX = config.config_get(
4270
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
34 config.parse_main_conf(), "", "bridge_dbus_int_prefix", "org.libervia.Libervia"
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
35 )
595
1f160467f5de Fix pep8 support in src/bridge.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 587
diff changeset
36 const_ERROR_PREFIX = const_INT_PREFIX + ".error"
3480
7550ae9cfbac Renamed the project from "Salut à Toi" to "Libervia":
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
37 const_OBJ_PATH = "/org/libervia/Libervia/bridge"
371
3ea41a199b36 bridge refactoring: categories are now core and plugin instead of communication and request
Goffi <goffi@goffi.org>
parents: 359
diff changeset
38 const_CORE_SUFFIX = ".core"
3ea41a199b36 bridge refactoring: categories are now core and plugin instead of communication and request
Goffi <goffi@goffi.org>
parents: 359
diff changeset
39 const_PLUGIN_SUFFIX = ".plugin"
267
bdcd535e179e Bridge constructor:
Goffi <goffi@goffi.org>
parents:
diff changeset
40
595
1f160467f5de Fix pep8 support in src/bridge.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 587
diff changeset
41
477
031b0e0aaab8 plugin groupblog: subscriptions/notifications
Goffi <goffi@goffi.org>
parents: 469
diff changeset
42 class ParseError(Exception):
031b0e0aaab8 plugin groupblog: subscriptions/notifications
Goffi <goffi@goffi.org>
parents: 469
diff changeset
43 pass
031b0e0aaab8 plugin groupblog: subscriptions/notifications
Goffi <goffi@goffi.org>
parents: 469
diff changeset
44
595
1f160467f5de Fix pep8 support in src/bridge.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 587
diff changeset
45
3539
60d3861e5996 bridge (dbus): use Tx DBus for backend part of D-Bus bridge:
Goffi <goffi@goffi.org>
parents: 3480
diff changeset
46 class DBusException(Exception):
60d3861e5996 bridge (dbus): use Tx DBus for backend part of D-Bus bridge:
Goffi <goffi@goffi.org>
parents: 3480
diff changeset
47 pass
423
6c20c76abdcc backend: - bridge async D-Bus method now automatically manage callback and errback, we just have to return a deferred
Goffi <goffi@goffi.org>
parents: 419
diff changeset
48
595
1f160467f5de Fix pep8 support in src/bridge.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 587
diff changeset
49
3539
60d3861e5996 bridge (dbus): use Tx DBus for backend part of D-Bus bridge:
Goffi <goffi@goffi.org>
parents: 3480
diff changeset
50 class MethodNotRegistered(DBusException):
60d3861e5996 bridge (dbus): use Tx DBus for backend part of D-Bus bridge:
Goffi <goffi@goffi.org>
parents: 3480
diff changeset
51 dbusErrorName = const_ERROR_PREFIX + ".MethodNotRegistered"
423
6c20c76abdcc backend: - bridge async D-Bus method now automatically manage callback and errback, we just have to return a deferred
Goffi <goffi@goffi.org>
parents: 419
diff changeset
52
595
1f160467f5de Fix pep8 support in src/bridge.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 587
diff changeset
53
3539
60d3861e5996 bridge (dbus): use Tx DBus for backend part of D-Bus bridge:
Goffi <goffi@goffi.org>
parents: 3480
diff changeset
54 class GenericException(DBusException):
423
6c20c76abdcc backend: - bridge async D-Bus method now automatically manage callback and errback, we just have to return a deferred
Goffi <goffi@goffi.org>
parents: 419
diff changeset
55 def __init__(self, twisted_error):
1073
f094583732de bridge: DBusException also transports the twisted failure condition
souliane <souliane@mailoo.org>
parents: 1062
diff changeset
56 """
f094583732de bridge: DBusException also transports the twisted failure condition
souliane <souliane@mailoo.org>
parents: 1062
diff changeset
57
f094583732de bridge: DBusException also transports the twisted failure condition
souliane <souliane@mailoo.org>
parents: 1062
diff changeset
58 @param twisted_error (Failure): instance of twisted Failure
3539
60d3861e5996 bridge (dbus): use Tx DBus for backend part of D-Bus bridge:
Goffi <goffi@goffi.org>
parents: 3480
diff changeset
59 error message is used to store a repr of message and condition in a tuple,
60d3861e5996 bridge (dbus): use Tx DBus for backend part of D-Bus bridge:
Goffi <goffi@goffi.org>
parents: 3480
diff changeset
60 so it can be evaluated by the frontend bridge.
1073
f094583732de bridge: DBusException also transports the twisted failure condition
souliane <souliane@mailoo.org>
parents: 1062
diff changeset
61 """
751
1def5b7edf9f core, bridge: better GenericException handling
Goffi <goffi@goffi.org>
parents: 627
diff changeset
62 try:
1def5b7edf9f core, bridge: better GenericException handling
Goffi <goffi@goffi.org>
parents: 627
diff changeset
63 # twisted_error.value is a class
1062
95758ef3faa8 bridge: async failures are more detailed (full class name + error message)
souliane <souliane@mailoo.org>
parents: 993
diff changeset
64 class_ = twisted_error.value().__class__
751
1def5b7edf9f core, bridge: better GenericException handling
Goffi <goffi@goffi.org>
parents: 627
diff changeset
65 except TypeError:
1def5b7edf9f core, bridge: better GenericException handling
Goffi <goffi@goffi.org>
parents: 627
diff changeset
66 # twisted_error.value is an instance
1062
95758ef3faa8 bridge: async failures are more detailed (full class name + error message)
souliane <souliane@mailoo.org>
parents: 993
diff changeset
67 class_ = twisted_error.value.__class__
3539
60d3861e5996 bridge (dbus): use Tx DBus for backend part of D-Bus bridge:
Goffi <goffi@goffi.org>
parents: 3480
diff changeset
68 data = twisted_error.getErrorMessage()
1073
f094583732de bridge: DBusException also transports the twisted failure condition
souliane <souliane@mailoo.org>
parents: 1062
diff changeset
69 try:
3539
60d3861e5996 bridge (dbus): use Tx DBus for backend part of D-Bus bridge:
Goffi <goffi@goffi.org>
parents: 3480
diff changeset
70 data = (data, twisted_error.value.condition)
1073
f094583732de bridge: DBusException also transports the twisted failure condition
souliane <souliane@mailoo.org>
parents: 1062
diff changeset
71 except AttributeError:
3539
60d3861e5996 bridge (dbus): use Tx DBus for backend part of D-Bus bridge:
Goffi <goffi@goffi.org>
parents: 3480
diff changeset
72 data = (data,)
60d3861e5996 bridge (dbus): use Tx DBus for backend part of D-Bus bridge:
Goffi <goffi@goffi.org>
parents: 3480
diff changeset
73 else:
60d3861e5996 bridge (dbus): use Tx DBus for backend part of D-Bus bridge:
Goffi <goffi@goffi.org>
parents: 3480
diff changeset
74 data = (str(twisted_error),)
60d3861e5996 bridge (dbus): use Tx DBus for backend part of D-Bus bridge:
Goffi <goffi@goffi.org>
parents: 3480
diff changeset
75 self.dbusErrorName = ".".join(
60d3861e5996 bridge (dbus): use Tx DBus for backend part of D-Bus bridge:
Goffi <goffi@goffi.org>
parents: 3480
diff changeset
76 (const_ERROR_PREFIX, class_.__module__, class_.__name__)
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
77 )
3539
60d3861e5996 bridge (dbus): use Tx DBus for backend part of D-Bus bridge:
Goffi <goffi@goffi.org>
parents: 3480
diff changeset
78 super(GenericException, self).__init__(repr(data))
60d3861e5996 bridge (dbus): use Tx DBus for backend part of D-Bus bridge:
Goffi <goffi@goffi.org>
parents: 3480
diff changeset
79
60d3861e5996 bridge (dbus): use Tx DBus for backend part of D-Bus bridge:
Goffi <goffi@goffi.org>
parents: 3480
diff changeset
80 @classmethod
60d3861e5996 bridge (dbus): use Tx DBus for backend part of D-Bus bridge:
Goffi <goffi@goffi.org>
parents: 3480
diff changeset
81 def create_and_raise(cls, exc):
60d3861e5996 bridge (dbus): use Tx DBus for backend part of D-Bus bridge:
Goffi <goffi@goffi.org>
parents: 3480
diff changeset
82 raise cls(exc)
595
1f160467f5de Fix pep8 support in src/bridge.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 587
diff changeset
83
419
6c167a2e04b8 bridge: added generic D-Bus exception management + asyncCreateProfile method
Goffi <goffi@goffi.org>
parents: 371
diff changeset
84
3539
60d3861e5996 bridge (dbus): use Tx DBus for backend part of D-Bus bridge:
Goffi <goffi@goffi.org>
parents: 3480
diff changeset
85 class DBusObject(objects.DBusObject):
60d3861e5996 bridge (dbus): use Tx DBus for backend part of D-Bus bridge:
Goffi <goffi@goffi.org>
parents: 3480
diff changeset
86
60d3861e5996 bridge (dbus): use Tx DBus for backend part of D-Bus bridge:
Goffi <goffi@goffi.org>
parents: 3480
diff changeset
87 core_iface = DBusInterface(
60d3861e5996 bridge (dbus): use Tx DBus for backend part of D-Bus bridge:
Goffi <goffi@goffi.org>
parents: 3480
diff changeset
88 const_INT_PREFIX + const_CORE_SUFFIX,
4270
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
89 ##METHODS_DECLARATIONS_PART##
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
90 ##SIGNALS_DECLARATIONS_PART##
3539
60d3861e5996 bridge (dbus): use Tx DBus for backend part of D-Bus bridge:
Goffi <goffi@goffi.org>
parents: 3480
diff changeset
91 )
4270
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
92 plugin_iface = DBusInterface(const_INT_PREFIX + const_PLUGIN_SUFFIX)
3539
60d3861e5996 bridge (dbus): use Tx DBus for backend part of D-Bus bridge:
Goffi <goffi@goffi.org>
parents: 3480
diff changeset
93
60d3861e5996 bridge (dbus): use Tx DBus for backend part of D-Bus bridge:
Goffi <goffi@goffi.org>
parents: 3480
diff changeset
94 dbusInterfaces = [core_iface, plugin_iface]
60d3861e5996 bridge (dbus): use Tx DBus for backend part of D-Bus bridge:
Goffi <goffi@goffi.org>
parents: 3480
diff changeset
95
60d3861e5996 bridge (dbus): use Tx DBus for backend part of D-Bus bridge:
Goffi <goffi@goffi.org>
parents: 3480
diff changeset
96 def __init__(self, path):
60d3861e5996 bridge (dbus): use Tx DBus for backend part of D-Bus bridge:
Goffi <goffi@goffi.org>
parents: 3480
diff changeset
97 super().__init__(path)
60d3861e5996 bridge (dbus): use Tx DBus for backend part of D-Bus bridge:
Goffi <goffi@goffi.org>
parents: 3480
diff changeset
98 log.debug("Init DBusObject...")
595
1f160467f5de Fix pep8 support in src/bridge.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 587
diff changeset
99 self.cb = {}
267
bdcd535e179e Bridge constructor:
Goffi <goffi@goffi.org>
parents:
diff changeset
100
2086
4633cfcbcccb bridge (D-Bus): bad design fixes:
Goffi <goffi@goffi.org>
parents: 2085
diff changeset
101 def register_method(self, name, cb):
595
1f160467f5de Fix pep8 support in src/bridge.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 587
diff changeset
102 self.cb[name] = cb
267
bdcd535e179e Bridge constructor:
Goffi <goffi@goffi.org>
parents:
diff changeset
103
423
6c20c76abdcc backend: - bridge async D-Bus method now automatically manage callback and errback, we just have to return a deferred
Goffi <goffi@goffi.org>
parents: 419
diff changeset
104 def _callback(self, name, *args, **kwargs):
3539
60d3861e5996 bridge (dbus): use Tx DBus for backend part of D-Bus bridge:
Goffi <goffi@goffi.org>
parents: 3480
diff changeset
105 """Call the callback if it exists, raise an exception else"""
60d3861e5996 bridge (dbus): use Tx DBus for backend part of D-Bus bridge:
Goffi <goffi@goffi.org>
parents: 3480
diff changeset
106 try:
60d3861e5996 bridge (dbus): use Tx DBus for backend part of D-Bus bridge:
Goffi <goffi@goffi.org>
parents: 3480
diff changeset
107 cb = self.cb[name]
60d3861e5996 bridge (dbus): use Tx DBus for backend part of D-Bus bridge:
Goffi <goffi@goffi.org>
parents: 3480
diff changeset
108 except KeyError:
423
6c20c76abdcc backend: - bridge async D-Bus method now automatically manage callback and errback, we just have to return a deferred
Goffi <goffi@goffi.org>
parents: 419
diff changeset
109 raise MethodNotRegistered
6c20c76abdcc backend: - bridge async D-Bus method now automatically manage callback and errback, we just have to return a deferred
Goffi <goffi@goffi.org>
parents: 419
diff changeset
110 else:
3539
60d3861e5996 bridge (dbus): use Tx DBus for backend part of D-Bus bridge:
Goffi <goffi@goffi.org>
parents: 3480
diff changeset
111 d = defer.maybeDeferred(cb, *args, **kwargs)
60d3861e5996 bridge (dbus): use Tx DBus for backend part of D-Bus bridge:
Goffi <goffi@goffi.org>
parents: 3480
diff changeset
112 d.addErrback(GenericException.create_and_raise)
60d3861e5996 bridge (dbus): use Tx DBus for backend part of D-Bus bridge:
Goffi <goffi@goffi.org>
parents: 3480
diff changeset
113 return d
587
952322b1d490 Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 572
diff changeset
114
4270
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
115
2628
779351da2c13 core, frontends: replaced org\.goffi namespaces by org.salutatoi + fixed generation:
Goffi <goffi@goffi.org>
parents: 2624
diff changeset
116 ##METHODS_PART##
267
bdcd535e179e Bridge constructor:
Goffi <goffi@goffi.org>
parents:
diff changeset
117
4270
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
118
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3539
diff changeset
119 class bridge:
587
952322b1d490 Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 572
diff changeset
120
3539
60d3861e5996 bridge (dbus): use Tx DBus for backend part of D-Bus bridge:
Goffi <goffi@goffi.org>
parents: 3480
diff changeset
121 def __init__(self):
60d3861e5996 bridge (dbus): use Tx DBus for backend part of D-Bus bridge:
Goffi <goffi@goffi.org>
parents: 3480
diff changeset
122 log.info("Init DBus...")
60d3861e5996 bridge (dbus): use Tx DBus for backend part of D-Bus bridge:
Goffi <goffi@goffi.org>
parents: 3480
diff changeset
123 self._obj = DBusObject(const_OBJ_PATH)
468
c97640c90a94 D-Bus Bridge: use inspection to name attribute + fix asynchronous calls for dynamically added method, it now use deferred return value instead of callback/errback attributes
Goffi <goffi@goffi.org>
parents: 459
diff changeset
124
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3539
diff changeset
125 async def post_init(self):
627
d207c2186519 core, bridge, jp, quick_frontend: SàT stop more gracefully if bridge can't be initialised:
Goffi <goffi@goffi.org>
parents: 609
diff changeset
126 try:
3539
60d3861e5996 bridge (dbus): use Tx DBus for backend part of D-Bus bridge:
Goffi <goffi@goffi.org>
parents: 3480
diff changeset
127 conn = await client.connect(reactor)
60d3861e5996 bridge (dbus): use Tx DBus for backend part of D-Bus bridge:
Goffi <goffi@goffi.org>
parents: 3480
diff changeset
128 except error.DBusException as e:
60d3861e5996 bridge (dbus): use Tx DBus for backend part of D-Bus bridge:
Goffi <goffi@goffi.org>
parents: 3480
diff changeset
129 if e.errName == "org.freedesktop.DBus.Error.NotSupported":
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
130 log.error(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
131 _(
3539
60d3861e5996 bridge (dbus): use Tx DBus for backend part of D-Bus bridge:
Goffi <goffi@goffi.org>
parents: 3480
diff changeset
132 "D-Bus is not launched, please see README to see instructions on "
60d3861e5996 bridge (dbus): use Tx DBus for backend part of D-Bus bridge:
Goffi <goffi@goffi.org>
parents: 3480
diff changeset
133 "how to launch it"
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
134 )
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
135 )
3539
60d3861e5996 bridge (dbus): use Tx DBus for backend part of D-Bus bridge:
Goffi <goffi@goffi.org>
parents: 3480
diff changeset
136 raise BridgeInitError(str(e))
267
bdcd535e179e Bridge constructor:
Goffi <goffi@goffi.org>
parents:
diff changeset
137
3539
60d3861e5996 bridge (dbus): use Tx DBus for backend part of D-Bus bridge:
Goffi <goffi@goffi.org>
parents: 3480
diff changeset
138 conn.exportObject(self._obj)
60d3861e5996 bridge (dbus): use Tx DBus for backend part of D-Bus bridge:
Goffi <goffi@goffi.org>
parents: 3480
diff changeset
139 await conn.requestBusName(const_INT_PREFIX)
60d3861e5996 bridge (dbus): use Tx DBus for backend part of D-Bus bridge:
Goffi <goffi@goffi.org>
parents: 3480
diff changeset
140
4270
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
141 ##SIGNALS_PART##
2086
4633cfcbcccb bridge (D-Bus): bad design fixes:
Goffi <goffi@goffi.org>
parents: 2085
diff changeset
142 def register_method(self, name, callback):
3539
60d3861e5996 bridge (dbus): use Tx DBus for backend part of D-Bus bridge:
Goffi <goffi@goffi.org>
parents: 3480
diff changeset
143 log.debug(f"registering DBus bridge method [{name}]")
60d3861e5996 bridge (dbus): use Tx DBus for backend part of D-Bus bridge:
Goffi <goffi@goffi.org>
parents: 3480
diff changeset
144 self._obj.register_method(name, callback)
60d3861e5996 bridge (dbus): use Tx DBus for backend part of D-Bus bridge:
Goffi <goffi@goffi.org>
parents: 3480
diff changeset
145
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3539
diff changeset
146 def emit_signal(self, name, *args):
3539
60d3861e5996 bridge (dbus): use Tx DBus for backend part of D-Bus bridge:
Goffi <goffi@goffi.org>
parents: 3480
diff changeset
147 self._obj.emitSignal(name, *args)
267
bdcd535e179e Bridge constructor:
Goffi <goffi@goffi.org>
parents:
diff changeset
148
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3539
diff changeset
149 def add_method(
4270
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
150 self, name, int_suffix, in_sign, out_sign, method, async_=False, doc={}
3539
60d3861e5996 bridge (dbus): use Tx DBus for backend part of D-Bus bridge:
Goffi <goffi@goffi.org>
parents: 3480
diff changeset
151 ):
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3539
diff changeset
152 """Dynamically add a method to D-Bus bridge"""
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
153 # FIXME: doc parameter is kept only temporary, the time to remove it from calls
3539
60d3861e5996 bridge (dbus): use Tx DBus for backend part of D-Bus bridge:
Goffi <goffi@goffi.org>
parents: 3480
diff changeset
154 log.debug(f"Adding method {name!r} to D-Bus bridge")
60d3861e5996 bridge (dbus): use Tx DBus for backend part of D-Bus bridge:
Goffi <goffi@goffi.org>
parents: 3480
diff changeset
155 self._obj.plugin_iface.addMethod(
60d3861e5996 bridge (dbus): use Tx DBus for backend part of D-Bus bridge:
Goffi <goffi@goffi.org>
parents: 3480
diff changeset
156 Method(name, arguments=in_sign, returns=out_sign)
60d3861e5996 bridge (dbus): use Tx DBus for backend part of D-Bus bridge:
Goffi <goffi@goffi.org>
parents: 3480
diff changeset
157 )
4270
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
158
3539
60d3861e5996 bridge (dbus): use Tx DBus for backend part of D-Bus bridge:
Goffi <goffi@goffi.org>
parents: 3480
diff changeset
159 # we have to create a method here instead of using partialmethod, because txdbus
60d3861e5996 bridge (dbus): use Tx DBus for backend part of D-Bus bridge:
Goffi <goffi@goffi.org>
parents: 3480
diff changeset
160 # uses __func__ which doesn't work with partialmethod
60d3861e5996 bridge (dbus): use Tx DBus for backend part of D-Bus bridge:
Goffi <goffi@goffi.org>
parents: 3480
diff changeset
161 def caller(self_, *args, **kwargs):
60d3861e5996 bridge (dbus): use Tx DBus for backend part of D-Bus bridge:
Goffi <goffi@goffi.org>
parents: 3480
diff changeset
162 return self_._callback(name, *args, **kwargs)
4270
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
163
3539
60d3861e5996 bridge (dbus): use Tx DBus for backend part of D-Bus bridge:
Goffi <goffi@goffi.org>
parents: 3480
diff changeset
164 setattr(self._obj, f"dbus_{name}", MethodType(caller, self._obj))
2086
4633cfcbcccb bridge (D-Bus): bad design fixes:
Goffi <goffi@goffi.org>
parents: 2085
diff changeset
165 self.register_method(name, method)
267
bdcd535e179e Bridge constructor:
Goffi <goffi@goffi.org>
parents:
diff changeset
166
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3539
diff changeset
167 def add_signal(self, name, int_suffix, signature, doc={}):
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3539
diff changeset
168 """Dynamically add a signal to D-Bus bridge"""
3539
60d3861e5996 bridge (dbus): use Tx DBus for backend part of D-Bus bridge:
Goffi <goffi@goffi.org>
parents: 3480
diff changeset
169 log.debug(f"Adding signal {name!r} to D-Bus bridge")
60d3861e5996 bridge (dbus): use Tx DBus for backend part of D-Bus bridge:
Goffi <goffi@goffi.org>
parents: 3480
diff changeset
170 self._obj.plugin_iface.addSignal(Signal(name, signature))
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3539
diff changeset
171 setattr(bridge, name, partialmethod(bridge.emit_signal, name))