Mercurial > libervia-backend
annotate sat/bridge/bridge_constructor/constructors/pb/pb_core_template.py @ 3728:b15644cae50d
component AP gateway: JID/node ⟺ AP outbox conversion:
- convert a combination of JID and optional pubsub node to AP actor handle (see
`getJIDAndNode` for details) and vice versa
- the gateway now provides a Pubsub service
- retrieve pubsub node and convert it to AP collection, AP pagination is converted to RSM
- do the opposite: convert AP collection to pubsub and handle RSM request. Due to
ActivityStream collection pagination limitations, some RSM request produce inefficient
requests, but caching should be used most of the time in the future and avoid the
problem.
- set specific name to HTTP Server
- new `local_only` setting (`True` by default) to indicate if the gateway can request or
not XMPP Pubsub nodes from other servers
- disco info now specifies important features such as Pubsub RSM, and nodes metadata
ticket 363
author | Goffi <goffi@goffi.org> |
---|---|
date | Tue, 25 Jan 2022 17:54:06 +0100 |
parents | 3c7a64d6f49f |
children | 524856bd7b19 |
rev | line source |
---|---|
3028 | 1 #!/usr/bin/env python3 |
3137 | 2 |
2092
5e79ba00c1e2
bridbe(pb): Perspective Broker bridge, first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
3 |
5e79ba00c1e2
bridbe(pb): Perspective Broker bridge, first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
4 # SAT: a jabber client |
3479 | 5 # Copyright (C) 2009-2021 Jérôme Poisson (goffi@goffi.org) |
2092
5e79ba00c1e2
bridbe(pb): Perspective Broker bridge, first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
6 |
5e79ba00c1e2
bridbe(pb): Perspective Broker bridge, first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
7 # This program is free software: you can redistribute it and/or modify |
5e79ba00c1e2
bridbe(pb): Perspective Broker bridge, first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
8 # it under the terms of the GNU Affero General Public License as published by |
5e79ba00c1e2
bridbe(pb): Perspective Broker bridge, first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
9 # the Free Software Foundation, either version 3 of the License, or |
5e79ba00c1e2
bridbe(pb): Perspective Broker bridge, first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
10 # (at your option) any later version. |
5e79ba00c1e2
bridbe(pb): Perspective Broker bridge, first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
11 |
5e79ba00c1e2
bridbe(pb): Perspective Broker bridge, first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
12 # This program is distributed in the hope that it will be useful, |
5e79ba00c1e2
bridbe(pb): Perspective Broker bridge, first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of |
5e79ba00c1e2
bridbe(pb): Perspective Broker bridge, first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
5e79ba00c1e2
bridbe(pb): Perspective Broker bridge, first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
15 # GNU Affero General Public License for more details. |
5e79ba00c1e2
bridbe(pb): Perspective Broker bridge, first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
16 |
5e79ba00c1e2
bridbe(pb): Perspective Broker bridge, first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
17 # You should have received a copy of the GNU Affero General Public License |
5e79ba00c1e2
bridbe(pb): Perspective Broker bridge, first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
18 # along with this program. If not, see <http://www.gnu.org/licenses/>. |
5e79ba00c1e2
bridbe(pb): Perspective Broker bridge, first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
19 |
5e79ba00c1e2
bridbe(pb): Perspective Broker bridge, first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
20 |
3039
a1bc34f90fa5
bridge (pb): implemented an asyncio compatible bridge:
Goffi <goffi@goffi.org>
parents:
3028
diff
changeset
|
21 import dataclasses |
3634
3c7a64d6f49f
bridge: bridge can now be set using environment variable:
Goffi <goffi@goffi.org>
parents:
3489
diff
changeset
|
22 from functools import partial |
3489
d71a163c0861
bridge (pb): connection can be set to used either UNIX socket or TCP socket:
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
23 from pathlib import Path |
2092
5e79ba00c1e2
bridbe(pb): Perspective Broker bridge, first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
24 from twisted.spread import jelly, pb |
5e79ba00c1e2
bridbe(pb): Perspective Broker bridge, first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
25 from twisted.internet import reactor |
3489
d71a163c0861
bridge (pb): connection can be set to used either UNIX socket or TCP socket:
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
26 from sat.core.log import getLogger |
d71a163c0861
bridge (pb): connection can be set to used either UNIX socket or TCP socket:
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
27 from sat.tools import config |
3039
a1bc34f90fa5
bridge (pb): implemented an asyncio compatible bridge:
Goffi <goffi@goffi.org>
parents:
3028
diff
changeset
|
28 |
2818
9a7cb32836c6
bridge (pb): minor import order change
Goffi <goffi@goffi.org>
parents:
2771
diff
changeset
|
29 log = getLogger(__name__) |
2092
5e79ba00c1e2
bridbe(pb): Perspective Broker bridge, first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
30 |
5e79ba00c1e2
bridbe(pb): Perspective Broker bridge, first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
31 |
5e79ba00c1e2
bridbe(pb): Perspective Broker bridge, first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
32 ## jelly hack |
5e79ba00c1e2
bridbe(pb): Perspective Broker bridge, first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
33 # we monkey patch jelly to handle namedtuple |
5e79ba00c1e2
bridbe(pb): Perspective Broker bridge, first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
34 ori_jelly = jelly._Jellier.jelly |
5e79ba00c1e2
bridbe(pb): Perspective Broker bridge, first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
35 |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
36 |
2092
5e79ba00c1e2
bridbe(pb): Perspective Broker bridge, first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
37 def fixed_jelly(self, obj): |
5e79ba00c1e2
bridbe(pb): Perspective Broker bridge, first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
38 """this method fix handling of namedtuple""" |
5e79ba00c1e2
bridbe(pb): Perspective Broker bridge, first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
39 if isinstance(obj, tuple) and not obj is tuple: |
5e79ba00c1e2
bridbe(pb): Perspective Broker bridge, first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
40 obj = tuple(obj) |
5e79ba00c1e2
bridbe(pb): Perspective Broker bridge, first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
41 return ori_jelly(self, obj) |
5e79ba00c1e2
bridbe(pb): Perspective Broker bridge, first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
42 |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
43 |
2092
5e79ba00c1e2
bridbe(pb): Perspective Broker bridge, first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
44 jelly._Jellier.jelly = fixed_jelly |
5e79ba00c1e2
bridbe(pb): Perspective Broker bridge, first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
45 |
5e79ba00c1e2
bridbe(pb): Perspective Broker bridge, first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
46 |
3039
a1bc34f90fa5
bridge (pb): implemented an asyncio compatible bridge:
Goffi <goffi@goffi.org>
parents:
3028
diff
changeset
|
47 @dataclasses.dataclass(eq=False) |
a1bc34f90fa5
bridge (pb): implemented an asyncio compatible bridge:
Goffi <goffi@goffi.org>
parents:
3028
diff
changeset
|
48 class HandlerWrapper: |
a1bc34f90fa5
bridge (pb): implemented an asyncio compatible bridge:
Goffi <goffi@goffi.org>
parents:
3028
diff
changeset
|
49 # we use a wrapper to keep signals handlers because RemoteReference doesn't support |
a1bc34f90fa5
bridge (pb): implemented an asyncio compatible bridge:
Goffi <goffi@goffi.org>
parents:
3028
diff
changeset
|
50 # comparison (other than equality), making it unusable with a list |
a1bc34f90fa5
bridge (pb): implemented an asyncio compatible bridge:
Goffi <goffi@goffi.org>
parents:
3028
diff
changeset
|
51 handler: pb.RemoteReference |
a1bc34f90fa5
bridge (pb): implemented an asyncio compatible bridge:
Goffi <goffi@goffi.org>
parents:
3028
diff
changeset
|
52 |
a1bc34f90fa5
bridge (pb): implemented an asyncio compatible bridge:
Goffi <goffi@goffi.org>
parents:
3028
diff
changeset
|
53 |
2092
5e79ba00c1e2
bridbe(pb): Perspective Broker bridge, first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
54 class PBRoot(pb.Root): |
5e79ba00c1e2
bridbe(pb): Perspective Broker bridge, first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
55 def __init__(self): |
5e79ba00c1e2
bridbe(pb): Perspective Broker bridge, first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
56 self.signals_handlers = [] |
5e79ba00c1e2
bridbe(pb): Perspective Broker bridge, first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
57 |
5e79ba00c1e2
bridbe(pb): Perspective Broker bridge, first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
58 def remote_initBridge(self, signals_handler): |
3039
a1bc34f90fa5
bridge (pb): implemented an asyncio compatible bridge:
Goffi <goffi@goffi.org>
parents:
3028
diff
changeset
|
59 self.signals_handlers.append(HandlerWrapper(signals_handler)) |
3028 | 60 log.info("registered signal handler") |
2092
5e79ba00c1e2
bridbe(pb): Perspective Broker bridge, first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
61 |
3039
a1bc34f90fa5
bridge (pb): implemented an asyncio compatible bridge:
Goffi <goffi@goffi.org>
parents:
3028
diff
changeset
|
62 def sendSignalEb(self, failure_, signal_name): |
a1bc34f90fa5
bridge (pb): implemented an asyncio compatible bridge:
Goffi <goffi@goffi.org>
parents:
3028
diff
changeset
|
63 if not failure_.check(pb.PBConnectionLost): |
a1bc34f90fa5
bridge (pb): implemented an asyncio compatible bridge:
Goffi <goffi@goffi.org>
parents:
3028
diff
changeset
|
64 log.error( |
a1bc34f90fa5
bridge (pb): implemented an asyncio compatible bridge:
Goffi <goffi@goffi.org>
parents:
3028
diff
changeset
|
65 f"Error while sending signal {signal_name}: {failure_}", |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
66 ) |
2092
5e79ba00c1e2
bridbe(pb): Perspective Broker bridge, first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
67 |
5e79ba00c1e2
bridbe(pb): Perspective Broker bridge, first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
68 def sendSignal(self, name, args, kwargs): |
5e79ba00c1e2
bridbe(pb): Perspective Broker bridge, first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
69 to_remove = [] |
3039
a1bc34f90fa5
bridge (pb): implemented an asyncio compatible bridge:
Goffi <goffi@goffi.org>
parents:
3028
diff
changeset
|
70 for wrapper in self.signals_handlers: |
a1bc34f90fa5
bridge (pb): implemented an asyncio compatible bridge:
Goffi <goffi@goffi.org>
parents:
3028
diff
changeset
|
71 handler = wrapper.handler |
2092
5e79ba00c1e2
bridbe(pb): Perspective Broker bridge, first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
72 try: |
5e79ba00c1e2
bridbe(pb): Perspective Broker bridge, first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
73 d = handler.callRemote(name, *args, **kwargs) |
5e79ba00c1e2
bridbe(pb): Perspective Broker bridge, first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
74 except pb.DeadReferenceError: |
3039
a1bc34f90fa5
bridge (pb): implemented an asyncio compatible bridge:
Goffi <goffi@goffi.org>
parents:
3028
diff
changeset
|
75 to_remove.append(wrapper) |
2092
5e79ba00c1e2
bridbe(pb): Perspective Broker bridge, first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
76 else: |
5e79ba00c1e2
bridbe(pb): Perspective Broker bridge, first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
77 d.addErrback(self.sendSignalEb, name) |
5e79ba00c1e2
bridbe(pb): Perspective Broker bridge, first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
78 if to_remove: |
3039
a1bc34f90fa5
bridge (pb): implemented an asyncio compatible bridge:
Goffi <goffi@goffi.org>
parents:
3028
diff
changeset
|
79 for wrapper in to_remove: |
3028 | 80 log.debug("Removing signal handler for dead frontend") |
3039
a1bc34f90fa5
bridge (pb): implemented an asyncio compatible bridge:
Goffi <goffi@goffi.org>
parents:
3028
diff
changeset
|
81 self.signals_handlers.remove(wrapper) |
2092
5e79ba00c1e2
bridbe(pb): Perspective Broker bridge, first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
82 |
2840
0f277708e2ae
bridge (pb): added bridgeDeactivateSignals and bridgeReactivateSignals methods:
Goffi <goffi@goffi.org>
parents:
2818
diff
changeset
|
83 def _bridgeDeactivateSignals(self): |
0f277708e2ae
bridge (pb): added bridgeDeactivateSignals and bridgeReactivateSignals methods:
Goffi <goffi@goffi.org>
parents:
2818
diff
changeset
|
84 if hasattr(self, "signals_paused"): |
3028 | 85 log.warning("bridge signals already deactivated") |
2840
0f277708e2ae
bridge (pb): added bridgeDeactivateSignals and bridgeReactivateSignals methods:
Goffi <goffi@goffi.org>
parents:
2818
diff
changeset
|
86 if self.signals_handler: |
0f277708e2ae
bridge (pb): added bridgeDeactivateSignals and bridgeReactivateSignals methods:
Goffi <goffi@goffi.org>
parents:
2818
diff
changeset
|
87 self.signals_paused.extend(self.signals_handler) |
0f277708e2ae
bridge (pb): added bridgeDeactivateSignals and bridgeReactivateSignals methods:
Goffi <goffi@goffi.org>
parents:
2818
diff
changeset
|
88 else: |
0f277708e2ae
bridge (pb): added bridgeDeactivateSignals and bridgeReactivateSignals methods:
Goffi <goffi@goffi.org>
parents:
2818
diff
changeset
|
89 self.signals_paused = self.signals_handlers |
0f277708e2ae
bridge (pb): added bridgeDeactivateSignals and bridgeReactivateSignals methods:
Goffi <goffi@goffi.org>
parents:
2818
diff
changeset
|
90 self.signals_handlers = [] |
3028 | 91 log.debug("bridge signals have been deactivated") |
2840
0f277708e2ae
bridge (pb): added bridgeDeactivateSignals and bridgeReactivateSignals methods:
Goffi <goffi@goffi.org>
parents:
2818
diff
changeset
|
92 |
0f277708e2ae
bridge (pb): added bridgeDeactivateSignals and bridgeReactivateSignals methods:
Goffi <goffi@goffi.org>
parents:
2818
diff
changeset
|
93 def _bridgeReactivateSignals(self): |
0f277708e2ae
bridge (pb): added bridgeDeactivateSignals and bridgeReactivateSignals methods:
Goffi <goffi@goffi.org>
parents:
2818
diff
changeset
|
94 try: |
0f277708e2ae
bridge (pb): added bridgeDeactivateSignals and bridgeReactivateSignals methods:
Goffi <goffi@goffi.org>
parents:
2818
diff
changeset
|
95 self.signals_handlers = self.signals_paused |
0f277708e2ae
bridge (pb): added bridgeDeactivateSignals and bridgeReactivateSignals methods:
Goffi <goffi@goffi.org>
parents:
2818
diff
changeset
|
96 except AttributeError: |
3028 | 97 log.debug("signals were already activated") |
2840
0f277708e2ae
bridge (pb): added bridgeDeactivateSignals and bridgeReactivateSignals methods:
Goffi <goffi@goffi.org>
parents:
2818
diff
changeset
|
98 else: |
0f277708e2ae
bridge (pb): added bridgeDeactivateSignals and bridgeReactivateSignals methods:
Goffi <goffi@goffi.org>
parents:
2818
diff
changeset
|
99 del self.signals_paused |
3028 | 100 log.debug("bridge signals have been reactivated") |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
101 |
2092
5e79ba00c1e2
bridbe(pb): Perspective Broker bridge, first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
102 ##METHODS_PART## |
5e79ba00c1e2
bridbe(pb): Perspective Broker bridge, first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
103 |
5e79ba00c1e2
bridbe(pb): Perspective Broker bridge, first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
104 |
5e79ba00c1e2
bridbe(pb): Perspective Broker bridge, first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
105 class Bridge(object): |
5e79ba00c1e2
bridbe(pb): Perspective Broker bridge, first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
106 def __init__(self): |
5e79ba00c1e2
bridbe(pb): Perspective Broker bridge, first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
107 log.info("Init Perspective Broker...") |
5e79ba00c1e2
bridbe(pb): Perspective Broker bridge, first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
108 self.root = PBRoot() |
3489
d71a163c0861
bridge (pb): connection can be set to used either UNIX socket or TCP socket:
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
109 conf = config.parseMainConf() |
3634
3c7a64d6f49f
bridge: bridge can now be set using environment variable:
Goffi <goffi@goffi.org>
parents:
3489
diff
changeset
|
110 getConf = partial(config.getConf, conf, "bridge_pb", "") |
3c7a64d6f49f
bridge: bridge can now be set using environment variable:
Goffi <goffi@goffi.org>
parents:
3489
diff
changeset
|
111 conn_type = getConf("connection_type", "unix_socket") |
3489
d71a163c0861
bridge (pb): connection can be set to used either UNIX socket or TCP socket:
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
112 if conn_type == "unix_socket": |
d71a163c0861
bridge (pb): connection can be set to used either UNIX socket or TCP socket:
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
113 local_dir = Path(config.getConfig(conf, "", "local_dir")).resolve() |
d71a163c0861
bridge (pb): connection can be set to used either UNIX socket or TCP socket:
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
114 socket_path = local_dir / "bridge_pb" |
d71a163c0861
bridge (pb): connection can be set to used either UNIX socket or TCP socket:
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
115 log.info(f"using UNIX Socket at {socket_path}") |
d71a163c0861
bridge (pb): connection can be set to used either UNIX socket or TCP socket:
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
116 reactor.listenUNIX( |
d71a163c0861
bridge (pb): connection can be set to used either UNIX socket or TCP socket:
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
117 str(socket_path), pb.PBServerFactory(self.root), mode=0o600 |
d71a163c0861
bridge (pb): connection can be set to used either UNIX socket or TCP socket:
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
118 ) |
d71a163c0861
bridge (pb): connection can be set to used either UNIX socket or TCP socket:
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
119 elif conn_type == "socket": |
3634
3c7a64d6f49f
bridge: bridge can now be set using environment variable:
Goffi <goffi@goffi.org>
parents:
3489
diff
changeset
|
120 port = int(getConf("port", 8789)) |
3489
d71a163c0861
bridge (pb): connection can be set to used either UNIX socket or TCP socket:
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
121 log.info(f"using TCP Socket at port {port}") |
d71a163c0861
bridge (pb): connection can be set to used either UNIX socket or TCP socket:
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
122 reactor.listenTCP(port, pb.PBServerFactory(self.root)) |
d71a163c0861
bridge (pb): connection can be set to used either UNIX socket or TCP socket:
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
123 else: |
d71a163c0861
bridge (pb): connection can be set to used either UNIX socket or TCP socket:
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
124 raise ValueError(f"Unknown pb connection type: {conn_type!r}") |
2092
5e79ba00c1e2
bridbe(pb): Perspective Broker bridge, first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
125 |
5e79ba00c1e2
bridbe(pb): Perspective Broker bridge, first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
126 def sendSignal(self, name, *args, **kwargs): |
5e79ba00c1e2
bridbe(pb): Perspective Broker bridge, first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
127 self.root.sendSignal(name, args, kwargs) |
5e79ba00c1e2
bridbe(pb): Perspective Broker bridge, first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
128 |
5e79ba00c1e2
bridbe(pb): Perspective Broker bridge, first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
129 def remote_initBridge(self, signals_handler): |
5e79ba00c1e2
bridbe(pb): Perspective Broker bridge, first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
130 self.signals_handlers.append(signals_handler) |
3028 | 131 log.info("registered signal handler") |
2092
5e79ba00c1e2
bridbe(pb): Perspective Broker bridge, first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
132 |
5e79ba00c1e2
bridbe(pb): Perspective Broker bridge, first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
133 def register_method(self, name, callback): |
5e79ba00c1e2
bridbe(pb): Perspective Broker bridge, first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
134 log.debug("registering PB bridge method [%s]" % name) |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
135 setattr(self.root, "remote_" + name, callback) |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
136 # self.root.register_method(name, callback) |
2092
5e79ba00c1e2
bridbe(pb): Perspective Broker bridge, first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
137 |
3489
d71a163c0861
bridge (pb): connection can be set to used either UNIX socket or TCP socket:
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
138 def addMethod( |
d71a163c0861
bridge (pb): connection can be set to used either UNIX socket or TCP socket:
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
139 self, name, int_suffix, in_sign, out_sign, method, async_=False, doc={} |
d71a163c0861
bridge (pb): connection can be set to used either UNIX socket or TCP socket:
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
140 ): |
2092
5e79ba00c1e2
bridbe(pb): Perspective Broker bridge, first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
141 """Dynamically add a method to PB Bridge""" |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
142 # FIXME: doc parameter is kept only temporary, the time to remove it from calls |
2092
5e79ba00c1e2
bridbe(pb): Perspective Broker bridge, first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
143 log.debug("Adding method {name} to PB bridge".format(name=name)) |
5e79ba00c1e2
bridbe(pb): Perspective Broker bridge, first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
144 self.register_method(name, method) |
5e79ba00c1e2
bridbe(pb): Perspective Broker bridge, first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
145 |
5e79ba00c1e2
bridbe(pb): Perspective Broker bridge, first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
146 def addSignal(self, name, int_suffix, signature, doc={}): |
5e79ba00c1e2
bridbe(pb): Perspective Broker bridge, first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
147 log.debug("Adding signal {name} to PB bridge".format(name=name)) |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
148 setattr( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
149 self, name, lambda *args, **kwargs: self.sendSignal(name, *args, **kwargs) |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
150 ) |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
151 |
2840
0f277708e2ae
bridge (pb): added bridgeDeactivateSignals and bridgeReactivateSignals methods:
Goffi <goffi@goffi.org>
parents:
2818
diff
changeset
|
152 def bridgeDeactivateSignals(self): |
0f277708e2ae
bridge (pb): added bridgeDeactivateSignals and bridgeReactivateSignals methods:
Goffi <goffi@goffi.org>
parents:
2818
diff
changeset
|
153 """Stop sending signals to bridge |
0f277708e2ae
bridge (pb): added bridgeDeactivateSignals and bridgeReactivateSignals methods:
Goffi <goffi@goffi.org>
parents:
2818
diff
changeset
|
154 |
0f277708e2ae
bridge (pb): added bridgeDeactivateSignals and bridgeReactivateSignals methods:
Goffi <goffi@goffi.org>
parents:
2818
diff
changeset
|
155 Mainly used for mobile frontends, when the frontend is paused |
0f277708e2ae
bridge (pb): added bridgeDeactivateSignals and bridgeReactivateSignals methods:
Goffi <goffi@goffi.org>
parents:
2818
diff
changeset
|
156 """ |
0f277708e2ae
bridge (pb): added bridgeDeactivateSignals and bridgeReactivateSignals methods:
Goffi <goffi@goffi.org>
parents:
2818
diff
changeset
|
157 self.root._bridgeDeactivateSignals() |
0f277708e2ae
bridge (pb): added bridgeDeactivateSignals and bridgeReactivateSignals methods:
Goffi <goffi@goffi.org>
parents:
2818
diff
changeset
|
158 |
0f277708e2ae
bridge (pb): added bridgeDeactivateSignals and bridgeReactivateSignals methods:
Goffi <goffi@goffi.org>
parents:
2818
diff
changeset
|
159 def bridgeReactivateSignals(self): |
0f277708e2ae
bridge (pb): added bridgeDeactivateSignals and bridgeReactivateSignals methods:
Goffi <goffi@goffi.org>
parents:
2818
diff
changeset
|
160 """Send again signals to bridge |
0f277708e2ae
bridge (pb): added bridgeDeactivateSignals and bridgeReactivateSignals methods:
Goffi <goffi@goffi.org>
parents:
2818
diff
changeset
|
161 |
0f277708e2ae
bridge (pb): added bridgeDeactivateSignals and bridgeReactivateSignals methods:
Goffi <goffi@goffi.org>
parents:
2818
diff
changeset
|
162 Should only be used after bridgeDeactivateSignals has been called |
0f277708e2ae
bridge (pb): added bridgeDeactivateSignals and bridgeReactivateSignals methods:
Goffi <goffi@goffi.org>
parents:
2818
diff
changeset
|
163 """ |
0f277708e2ae
bridge (pb): added bridgeDeactivateSignals and bridgeReactivateSignals methods:
Goffi <goffi@goffi.org>
parents:
2818
diff
changeset
|
164 self.root._bridgeReactivateSignals() |
2092
5e79ba00c1e2
bridbe(pb): Perspective Broker bridge, first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
165 |
5e79ba00c1e2
bridbe(pb): Perspective Broker bridge, first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
166 ##SIGNALS_PART## |