Mercurial > libervia-backend
annotate sat/bridge/pb.py @ 3517:8508fab9bcc2
plugin XEP-0353: don't use Jingle Message Initiation for components:
Jingle Message Initiation is currently not useful for components, and the message workflow
is different in Libervia between clients and components (as a result, `messageReceived`
trigger is never called, and the session proposal is never answered).
author | Goffi <goffi@goffi.org> |
---|---|
date | Sat, 01 May 2021 18:30:01 +0200 |
parents | d71a163c0861 |
children | 3c7a64d6f49f |
rev | line source |
---|---|
3028 | 1 #!/usr/bin/env python3 |
3137 | 2 |
2579
787b15d16347
bridge: added generated pb files to repository (needed for Cagou on Android)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
3 |
787b15d16347
bridge: added generated pb files to repository (needed for Cagou on Android)
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) |
2579
787b15d16347
bridge: added generated pb files to repository (needed for Cagou on Android)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
6 |
787b15d16347
bridge: added generated pb files to repository (needed for Cagou on Android)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
7 # This program is free software: you can redistribute it and/or modify |
787b15d16347
bridge: added generated pb files to repository (needed for Cagou on Android)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
8 # it under the terms of the GNU Affero General Public License as published by |
787b15d16347
bridge: added generated pb files to repository (needed for Cagou on Android)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
9 # the Free Software Foundation, either version 3 of the License, or |
787b15d16347
bridge: added generated pb files to repository (needed for Cagou on Android)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
10 # (at your option) any later version. |
787b15d16347
bridge: added generated pb files to repository (needed for Cagou on Android)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
11 |
787b15d16347
bridge: added generated pb files to repository (needed for Cagou on Android)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
12 # This program is distributed in the hope that it will be useful, |
787b15d16347
bridge: added generated pb files to repository (needed for Cagou on Android)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of |
787b15d16347
bridge: added generated pb files to repository (needed for Cagou on Android)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
787b15d16347
bridge: added generated pb files to repository (needed for Cagou on Android)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
15 # GNU Affero General Public License for more details. |
787b15d16347
bridge: added generated pb files to repository (needed for Cagou on Android)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
16 |
787b15d16347
bridge: added generated pb files to repository (needed for Cagou on Android)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
17 # You should have received a copy of the GNU Affero General Public License |
787b15d16347
bridge: added generated pb files to repository (needed for Cagou on Android)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
18 # along with this program. If not, see <http://www.gnu.org/licenses/>. |
787b15d16347
bridge: added generated pb files to repository (needed for Cagou on Android)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
19 |
787b15d16347
bridge: added generated pb files to repository (needed for Cagou on Android)
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 |
3489
d71a163c0861
bridge (pb): connection can be set to used either UNIX socket or TCP socket:
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
22 from pathlib import Path |
2579
787b15d16347
bridge: added generated pb files to repository (needed for Cagou on Android)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
23 from twisted.spread import jelly, pb |
787b15d16347
bridge: added generated pb files to repository (needed for Cagou on Android)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
24 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
|
25 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
|
26 from sat.tools import config |
3039
a1bc34f90fa5
bridge (pb): implemented an asyncio compatible bridge:
Goffi <goffi@goffi.org>
parents:
3028
diff
changeset
|
27 |
2892
82b781c46841
core: added a rosterResync method to bridge:
Goffi <goffi@goffi.org>
parents:
2854
diff
changeset
|
28 log = getLogger(__name__) |
2579
787b15d16347
bridge: added generated pb files to repository (needed for Cagou on Android)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
29 |
787b15d16347
bridge: added generated pb files to repository (needed for Cagou on Android)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
30 |
787b15d16347
bridge: added generated pb files to repository (needed for Cagou on Android)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
31 ## jelly hack |
787b15d16347
bridge: added generated pb files to repository (needed for Cagou on Android)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
32 # we monkey patch jelly to handle namedtuple |
787b15d16347
bridge: added generated pb files to repository (needed for Cagou on Android)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
33 ori_jelly = jelly._Jellier.jelly |
787b15d16347
bridge: added generated pb files to repository (needed for Cagou on Android)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
34 |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2579
diff
changeset
|
35 |
2579
787b15d16347
bridge: added generated pb files to repository (needed for Cagou on Android)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
36 def fixed_jelly(self, obj): |
787b15d16347
bridge: added generated pb files to repository (needed for Cagou on Android)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
37 """this method fix handling of namedtuple""" |
787b15d16347
bridge: added generated pb files to repository (needed for Cagou on Android)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
38 if isinstance(obj, tuple) and not obj is tuple: |
787b15d16347
bridge: added generated pb files to repository (needed for Cagou on Android)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
39 obj = tuple(obj) |
787b15d16347
bridge: added generated pb files to repository (needed for Cagou on Android)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
40 return ori_jelly(self, obj) |
787b15d16347
bridge: added generated pb files to repository (needed for Cagou on Android)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
41 |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2579
diff
changeset
|
42 |
2579
787b15d16347
bridge: added generated pb files to repository (needed for Cagou on Android)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
43 jelly._Jellier.jelly = fixed_jelly |
787b15d16347
bridge: added generated pb files to repository (needed for Cagou on Android)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
44 |
787b15d16347
bridge: added generated pb files to repository (needed for Cagou on Android)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
45 |
3039
a1bc34f90fa5
bridge (pb): implemented an asyncio compatible bridge:
Goffi <goffi@goffi.org>
parents:
3028
diff
changeset
|
46 @dataclasses.dataclass(eq=False) |
a1bc34f90fa5
bridge (pb): implemented an asyncio compatible bridge:
Goffi <goffi@goffi.org>
parents:
3028
diff
changeset
|
47 class HandlerWrapper: |
a1bc34f90fa5
bridge (pb): implemented an asyncio compatible bridge:
Goffi <goffi@goffi.org>
parents:
3028
diff
changeset
|
48 # 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
|
49 # 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
|
50 handler: pb.RemoteReference |
a1bc34f90fa5
bridge (pb): implemented an asyncio compatible bridge:
Goffi <goffi@goffi.org>
parents:
3028
diff
changeset
|
51 |
a1bc34f90fa5
bridge (pb): implemented an asyncio compatible bridge:
Goffi <goffi@goffi.org>
parents:
3028
diff
changeset
|
52 |
2579
787b15d16347
bridge: added generated pb files to repository (needed for Cagou on Android)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
53 class PBRoot(pb.Root): |
787b15d16347
bridge: added generated pb files to repository (needed for Cagou on Android)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
54 def __init__(self): |
787b15d16347
bridge: added generated pb files to repository (needed for Cagou on Android)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
55 self.signals_handlers = [] |
787b15d16347
bridge: added generated pb files to repository (needed for Cagou on Android)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
56 |
787b15d16347
bridge: added generated pb files to repository (needed for Cagou on Android)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
57 def remote_initBridge(self, signals_handler): |
3039
a1bc34f90fa5
bridge (pb): implemented an asyncio compatible bridge:
Goffi <goffi@goffi.org>
parents:
3028
diff
changeset
|
58 self.signals_handlers.append(HandlerWrapper(signals_handler)) |
3028 | 59 log.info("registered signal handler") |
2579
787b15d16347
bridge: added generated pb files to repository (needed for Cagou on Android)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
60 |
3039
a1bc34f90fa5
bridge (pb): implemented an asyncio compatible bridge:
Goffi <goffi@goffi.org>
parents:
3028
diff
changeset
|
61 def sendSignalEb(self, failure_, signal_name): |
a1bc34f90fa5
bridge (pb): implemented an asyncio compatible bridge:
Goffi <goffi@goffi.org>
parents:
3028
diff
changeset
|
62 if not failure_.check(pb.PBConnectionLost): |
a1bc34f90fa5
bridge (pb): implemented an asyncio compatible bridge:
Goffi <goffi@goffi.org>
parents:
3028
diff
changeset
|
63 log.error( |
a1bc34f90fa5
bridge (pb): implemented an asyncio compatible bridge:
Goffi <goffi@goffi.org>
parents:
3028
diff
changeset
|
64 f"Error while sending signal {signal_name}: {failure_}", |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2579
diff
changeset
|
65 ) |
2579
787b15d16347
bridge: added generated pb files to repository (needed for Cagou on Android)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
66 |
787b15d16347
bridge: added generated pb files to repository (needed for Cagou on Android)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
67 def sendSignal(self, name, args, kwargs): |
787b15d16347
bridge: added generated pb files to repository (needed for Cagou on Android)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
68 to_remove = [] |
3039
a1bc34f90fa5
bridge (pb): implemented an asyncio compatible bridge:
Goffi <goffi@goffi.org>
parents:
3028
diff
changeset
|
69 for wrapper in self.signals_handlers: |
a1bc34f90fa5
bridge (pb): implemented an asyncio compatible bridge:
Goffi <goffi@goffi.org>
parents:
3028
diff
changeset
|
70 handler = wrapper.handler |
2579
787b15d16347
bridge: added generated pb files to repository (needed for Cagou on Android)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
71 try: |
787b15d16347
bridge: added generated pb files to repository (needed for Cagou on Android)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
72 d = handler.callRemote(name, *args, **kwargs) |
787b15d16347
bridge: added generated pb files to repository (needed for Cagou on Android)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
73 except pb.DeadReferenceError: |
3039
a1bc34f90fa5
bridge (pb): implemented an asyncio compatible bridge:
Goffi <goffi@goffi.org>
parents:
3028
diff
changeset
|
74 to_remove.append(wrapper) |
2579
787b15d16347
bridge: added generated pb files to repository (needed for Cagou on Android)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
75 else: |
787b15d16347
bridge: added generated pb files to repository (needed for Cagou on Android)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
76 d.addErrback(self.sendSignalEb, name) |
787b15d16347
bridge: added generated pb files to repository (needed for Cagou on Android)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
77 if to_remove: |
3039
a1bc34f90fa5
bridge (pb): implemented an asyncio compatible bridge:
Goffi <goffi@goffi.org>
parents:
3028
diff
changeset
|
78 for wrapper in to_remove: |
3028 | 79 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
|
80 self.signals_handlers.remove(wrapper) |
2579
787b15d16347
bridge: added generated pb files to repository (needed for Cagou on Android)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
81 |
2840
0f277708e2ae
bridge (pb): added bridgeDeactivateSignals and bridgeReactivateSignals methods:
Goffi <goffi@goffi.org>
parents:
2771
diff
changeset
|
82 def _bridgeDeactivateSignals(self): |
0f277708e2ae
bridge (pb): added bridgeDeactivateSignals and bridgeReactivateSignals methods:
Goffi <goffi@goffi.org>
parents:
2771
diff
changeset
|
83 if hasattr(self, "signals_paused"): |
3028 | 84 log.warning("bridge signals already deactivated") |
2840
0f277708e2ae
bridge (pb): added bridgeDeactivateSignals and bridgeReactivateSignals methods:
Goffi <goffi@goffi.org>
parents:
2771
diff
changeset
|
85 if self.signals_handler: |
0f277708e2ae
bridge (pb): added bridgeDeactivateSignals and bridgeReactivateSignals methods:
Goffi <goffi@goffi.org>
parents:
2771
diff
changeset
|
86 self.signals_paused.extend(self.signals_handler) |
0f277708e2ae
bridge (pb): added bridgeDeactivateSignals and bridgeReactivateSignals methods:
Goffi <goffi@goffi.org>
parents:
2771
diff
changeset
|
87 else: |
0f277708e2ae
bridge (pb): added bridgeDeactivateSignals and bridgeReactivateSignals methods:
Goffi <goffi@goffi.org>
parents:
2771
diff
changeset
|
88 self.signals_paused = self.signals_handlers |
0f277708e2ae
bridge (pb): added bridgeDeactivateSignals and bridgeReactivateSignals methods:
Goffi <goffi@goffi.org>
parents:
2771
diff
changeset
|
89 self.signals_handlers = [] |
3028 | 90 log.debug("bridge signals have been deactivated") |
2840
0f277708e2ae
bridge (pb): added bridgeDeactivateSignals and bridgeReactivateSignals methods:
Goffi <goffi@goffi.org>
parents:
2771
diff
changeset
|
91 |
0f277708e2ae
bridge (pb): added bridgeDeactivateSignals and bridgeReactivateSignals methods:
Goffi <goffi@goffi.org>
parents:
2771
diff
changeset
|
92 def _bridgeReactivateSignals(self): |
0f277708e2ae
bridge (pb): added bridgeDeactivateSignals and bridgeReactivateSignals methods:
Goffi <goffi@goffi.org>
parents:
2771
diff
changeset
|
93 try: |
0f277708e2ae
bridge (pb): added bridgeDeactivateSignals and bridgeReactivateSignals methods:
Goffi <goffi@goffi.org>
parents:
2771
diff
changeset
|
94 self.signals_handlers = self.signals_paused |
0f277708e2ae
bridge (pb): added bridgeDeactivateSignals and bridgeReactivateSignals methods:
Goffi <goffi@goffi.org>
parents:
2771
diff
changeset
|
95 except AttributeError: |
3028 | 96 log.debug("signals were already activated") |
2840
0f277708e2ae
bridge (pb): added bridgeDeactivateSignals and bridgeReactivateSignals methods:
Goffi <goffi@goffi.org>
parents:
2771
diff
changeset
|
97 else: |
0f277708e2ae
bridge (pb): added bridgeDeactivateSignals and bridgeReactivateSignals methods:
Goffi <goffi@goffi.org>
parents:
2771
diff
changeset
|
98 del self.signals_paused |
3028 | 99 log.debug("bridge signals have been reactivated") |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2579
diff
changeset
|
100 |
2579
787b15d16347
bridge: added generated pb files to repository (needed for Cagou on Android)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
101 ##METHODS_PART## |
787b15d16347
bridge: added generated pb files to repository (needed for Cagou on Android)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
102 |
787b15d16347
bridge: added generated pb files to repository (needed for Cagou on Android)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
103 |
787b15d16347
bridge: added generated pb files to repository (needed for Cagou on Android)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
104 class Bridge(object): |
787b15d16347
bridge: added generated pb files to repository (needed for Cagou on Android)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
105 def __init__(self): |
787b15d16347
bridge: added generated pb files to repository (needed for Cagou on Android)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
106 log.info("Init Perspective Broker...") |
787b15d16347
bridge: added generated pb files to repository (needed for Cagou on Android)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
107 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
|
108 conf = config.parseMainConf() |
d71a163c0861
bridge (pb): connection can be set to used either UNIX socket or TCP socket:
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
109 conn_type = config.getConfig( |
d71a163c0861
bridge (pb): connection can be set to used either UNIX socket or TCP socket:
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
110 conf, |
d71a163c0861
bridge (pb): connection can be set to used either UNIX socket or TCP socket:
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
111 "", |
d71a163c0861
bridge (pb): connection can be set to used either UNIX socket or TCP socket:
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
112 "bridge_pb_connection_type", |
d71a163c0861
bridge (pb): connection can be set to used either UNIX socket or TCP socket:
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
113 "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
|
114 ) |
d71a163c0861
bridge (pb): connection can be set to used either UNIX socket or TCP socket:
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
115 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
|
116 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
|
117 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
|
118 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
|
119 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
|
120 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
|
121 ) |
d71a163c0861
bridge (pb): connection can be set to used either UNIX socket or TCP socket:
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
122 elif conn_type == "socket": |
d71a163c0861
bridge (pb): connection can be set to used either UNIX socket or TCP socket:
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
123 port = int(config.getConfig( |
d71a163c0861
bridge (pb): connection can be set to used either UNIX socket or TCP socket:
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
124 conf, |
d71a163c0861
bridge (pb): connection can be set to used either UNIX socket or TCP socket:
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
125 "", |
d71a163c0861
bridge (pb): connection can be set to used either UNIX socket or TCP socket:
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
126 "bridge_pb_port", |
d71a163c0861
bridge (pb): connection can be set to used either UNIX socket or TCP socket:
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
127 8789 |
d71a163c0861
bridge (pb): connection can be set to used either UNIX socket or TCP socket:
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
128 )) |
d71a163c0861
bridge (pb): connection can be set to used either UNIX socket or TCP socket:
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
129 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
|
130 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
|
131 else: |
d71a163c0861
bridge (pb): connection can be set to used either UNIX socket or TCP socket:
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
132 raise ValueError(f"Unknown pb connection type: {conn_type!r}") |
2579
787b15d16347
bridge: added generated pb files to repository (needed for Cagou on Android)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
133 |
787b15d16347
bridge: added generated pb files to repository (needed for Cagou on Android)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
134 def sendSignal(self, name, *args, **kwargs): |
787b15d16347
bridge: added generated pb files to repository (needed for Cagou on Android)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
135 self.root.sendSignal(name, args, kwargs) |
787b15d16347
bridge: added generated pb files to repository (needed for Cagou on Android)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
136 |
787b15d16347
bridge: added generated pb files to repository (needed for Cagou on Android)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
137 def remote_initBridge(self, signals_handler): |
787b15d16347
bridge: added generated pb files to repository (needed for Cagou on Android)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
138 self.signals_handlers.append(signals_handler) |
3028 | 139 log.info("registered signal handler") |
2579
787b15d16347
bridge: added generated pb files to repository (needed for Cagou on Android)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
140 |
787b15d16347
bridge: added generated pb files to repository (needed for Cagou on Android)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
141 def register_method(self, name, callback): |
787b15d16347
bridge: added generated pb files to repository (needed for Cagou on Android)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
142 log.debug("registering PB bridge method [%s]" % name) |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2579
diff
changeset
|
143 setattr(self.root, "remote_" + name, callback) |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2579
diff
changeset
|
144 # self.root.register_method(name, callback) |
2579
787b15d16347
bridge: added generated pb files to repository (needed for Cagou on Android)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
145 |
3489
d71a163c0861
bridge (pb): connection can be set to used either UNIX socket or TCP socket:
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
146 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
|
147 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
|
148 ): |
2579
787b15d16347
bridge: added generated pb files to repository (needed for Cagou on Android)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
149 """Dynamically add a method to PB Bridge""" |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2579
diff
changeset
|
150 # FIXME: doc parameter is kept only temporary, the time to remove it from calls |
2579
787b15d16347
bridge: added generated pb files to repository (needed for Cagou on Android)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
151 log.debug("Adding method {name} to PB bridge".format(name=name)) |
787b15d16347
bridge: added generated pb files to repository (needed for Cagou on Android)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
152 self.register_method(name, method) |
787b15d16347
bridge: added generated pb files to repository (needed for Cagou on Android)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
153 |
787b15d16347
bridge: added generated pb files to repository (needed for Cagou on Android)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
154 def addSignal(self, name, int_suffix, signature, doc={}): |
787b15d16347
bridge: added generated pb files to repository (needed for Cagou on Android)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
155 log.debug("Adding signal {name} to PB bridge".format(name=name)) |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2579
diff
changeset
|
156 setattr( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2579
diff
changeset
|
157 self, name, lambda *args, **kwargs: self.sendSignal(name, *args, **kwargs) |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2579
diff
changeset
|
158 ) |
2579
787b15d16347
bridge: added generated pb files to repository (needed for Cagou on Android)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
159 |
2840
0f277708e2ae
bridge (pb): added bridgeDeactivateSignals and bridgeReactivateSignals methods:
Goffi <goffi@goffi.org>
parents:
2771
diff
changeset
|
160 def bridgeDeactivateSignals(self): |
0f277708e2ae
bridge (pb): added bridgeDeactivateSignals and bridgeReactivateSignals methods:
Goffi <goffi@goffi.org>
parents:
2771
diff
changeset
|
161 """Stop sending signals to bridge |
0f277708e2ae
bridge (pb): added bridgeDeactivateSignals and bridgeReactivateSignals methods:
Goffi <goffi@goffi.org>
parents:
2771
diff
changeset
|
162 |
0f277708e2ae
bridge (pb): added bridgeDeactivateSignals and bridgeReactivateSignals methods:
Goffi <goffi@goffi.org>
parents:
2771
diff
changeset
|
163 Mainly used for mobile frontends, when the frontend is paused |
0f277708e2ae
bridge (pb): added bridgeDeactivateSignals and bridgeReactivateSignals methods:
Goffi <goffi@goffi.org>
parents:
2771
diff
changeset
|
164 """ |
0f277708e2ae
bridge (pb): added bridgeDeactivateSignals and bridgeReactivateSignals methods:
Goffi <goffi@goffi.org>
parents:
2771
diff
changeset
|
165 self.root._bridgeDeactivateSignals() |
0f277708e2ae
bridge (pb): added bridgeDeactivateSignals and bridgeReactivateSignals methods:
Goffi <goffi@goffi.org>
parents:
2771
diff
changeset
|
166 |
0f277708e2ae
bridge (pb): added bridgeDeactivateSignals and bridgeReactivateSignals methods:
Goffi <goffi@goffi.org>
parents:
2771
diff
changeset
|
167 def bridgeReactivateSignals(self): |
0f277708e2ae
bridge (pb): added bridgeDeactivateSignals and bridgeReactivateSignals methods:
Goffi <goffi@goffi.org>
parents:
2771
diff
changeset
|
168 """Send again signals to bridge |
0f277708e2ae
bridge (pb): added bridgeDeactivateSignals and bridgeReactivateSignals methods:
Goffi <goffi@goffi.org>
parents:
2771
diff
changeset
|
169 |
0f277708e2ae
bridge (pb): added bridgeDeactivateSignals and bridgeReactivateSignals methods:
Goffi <goffi@goffi.org>
parents:
2771
diff
changeset
|
170 Should only be used after bridgeDeactivateSignals has been called |
0f277708e2ae
bridge (pb): added bridgeDeactivateSignals and bridgeReactivateSignals methods:
Goffi <goffi@goffi.org>
parents:
2771
diff
changeset
|
171 """ |
0f277708e2ae
bridge (pb): added bridgeDeactivateSignals and bridgeReactivateSignals methods:
Goffi <goffi@goffi.org>
parents:
2771
diff
changeset
|
172 self.root._bridgeReactivateSignals() |
2628
779351da2c13
core, frontends: replaced org\.goffi namespaces by org.salutatoi + fixed generation:
Goffi <goffi@goffi.org>
parents:
2624
diff
changeset
|
173 |
2854 | 174 def _debug(self, action, params, profile): |
175 self.sendSignal("_debug", action, params, profile) | |
176 | |
2579
787b15d16347
bridge: added generated pb files to repository (needed for Cagou on Android)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
177 def actionNew(self, action_data, id, security_limit, profile): |
787b15d16347
bridge: added generated pb files to repository (needed for Cagou on Android)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
178 self.sendSignal("actionNew", action_data, id, security_limit, profile) |
787b15d16347
bridge: added generated pb files to repository (needed for Cagou on Android)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
179 |
2894
c7c52c0dc13a
core, quick_frontend(app): fixed connected signal handling
Goffi <goffi@goffi.org>
parents:
2892
diff
changeset
|
180 def connected(self, jid_s, profile): |
c7c52c0dc13a
core, quick_frontend(app): fixed connected signal handling
Goffi <goffi@goffi.org>
parents:
2892
diff
changeset
|
181 self.sendSignal("connected", jid_s, profile) |
2579
787b15d16347
bridge: added generated pb files to repository (needed for Cagou on Android)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
182 |
787b15d16347
bridge: added generated pb files to repository (needed for Cagou on Android)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
183 def contactDeleted(self, entity_jid, profile): |
787b15d16347
bridge: added generated pb files to repository (needed for Cagou on Android)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
184 self.sendSignal("contactDeleted", entity_jid, profile) |
787b15d16347
bridge: added generated pb files to repository (needed for Cagou on Android)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
185 |
787b15d16347
bridge: added generated pb files to repository (needed for Cagou on Android)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
186 def disconnected(self, profile): |
787b15d16347
bridge: added generated pb files to repository (needed for Cagou on Android)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
187 self.sendSignal("disconnected", profile) |
787b15d16347
bridge: added generated pb files to repository (needed for Cagou on Android)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
188 |
787b15d16347
bridge: added generated pb files to repository (needed for Cagou on Android)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
189 def entityDataUpdated(self, jid, name, value, profile): |
787b15d16347
bridge: added generated pb files to repository (needed for Cagou on Android)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
190 self.sendSignal("entityDataUpdated", jid, name, value, profile) |
787b15d16347
bridge: added generated pb files to repository (needed for Cagou on Android)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
191 |
2655
b8600f8130ac
core (bridge): new messageEncryptionStarted and messageEncryptionStopped signals (not used yet)
Goffi <goffi@goffi.org>
parents:
2628
diff
changeset
|
192 def messageEncryptionStarted(self, to_jid, encryption_data, profile_key): |
b8600f8130ac
core (bridge): new messageEncryptionStarted and messageEncryptionStopped signals (not used yet)
Goffi <goffi@goffi.org>
parents:
2628
diff
changeset
|
193 self.sendSignal("messageEncryptionStarted", to_jid, encryption_data, profile_key) |
b8600f8130ac
core (bridge): new messageEncryptionStarted and messageEncryptionStopped signals (not used yet)
Goffi <goffi@goffi.org>
parents:
2628
diff
changeset
|
194 |
b8600f8130ac
core (bridge): new messageEncryptionStarted and messageEncryptionStopped signals (not used yet)
Goffi <goffi@goffi.org>
parents:
2628
diff
changeset
|
195 def messageEncryptionStopped(self, to_jid, encryption_data, profile_key): |
b8600f8130ac
core (bridge): new messageEncryptionStarted and messageEncryptionStopped signals (not used yet)
Goffi <goffi@goffi.org>
parents:
2628
diff
changeset
|
196 self.sendSignal("messageEncryptionStopped", to_jid, encryption_data, profile_key) |
b8600f8130ac
core (bridge): new messageEncryptionStarted and messageEncryptionStopped signals (not used yet)
Goffi <goffi@goffi.org>
parents:
2628
diff
changeset
|
197 |
2628
779351da2c13
core, frontends: replaced org\.goffi namespaces by org.salutatoi + fixed generation:
Goffi <goffi@goffi.org>
parents:
2624
diff
changeset
|
198 def messageNew(self, uid, timestamp, from_jid, to_jid, message, subject, mess_type, extra, profile): |
779351da2c13
core, frontends: replaced org\.goffi namespaces by org.salutatoi + fixed generation:
Goffi <goffi@goffi.org>
parents:
2624
diff
changeset
|
199 self.sendSignal("messageNew", uid, timestamp, from_jid, to_jid, message, subject, mess_type, extra, profile) |
2579
787b15d16347
bridge: added generated pb files to repository (needed for Cagou on Android)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
200 |
787b15d16347
bridge: added generated pb files to repository (needed for Cagou on Android)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
201 def newContact(self, contact_jid, attributes, groups, profile): |
787b15d16347
bridge: added generated pb files to repository (needed for Cagou on Android)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
202 self.sendSignal("newContact", contact_jid, attributes, groups, profile) |
787b15d16347
bridge: added generated pb files to repository (needed for Cagou on Android)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
203 |
787b15d16347
bridge: added generated pb files to repository (needed for Cagou on Android)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
204 def paramUpdate(self, name, value, category, profile): |
787b15d16347
bridge: added generated pb files to repository (needed for Cagou on Android)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
205 self.sendSignal("paramUpdate", name, value, category, profile) |
787b15d16347
bridge: added generated pb files to repository (needed for Cagou on Android)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
206 |
787b15d16347
bridge: added generated pb files to repository (needed for Cagou on Android)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
207 def presenceUpdate(self, entity_jid, show, priority, statuses, profile): |
787b15d16347
bridge: added generated pb files to repository (needed for Cagou on Android)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
208 self.sendSignal("presenceUpdate", entity_jid, show, priority, statuses, profile) |
787b15d16347
bridge: added generated pb files to repository (needed for Cagou on Android)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
209 |
787b15d16347
bridge: added generated pb files to repository (needed for Cagou on Android)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
210 def progressError(self, id, error, profile): |
787b15d16347
bridge: added generated pb files to repository (needed for Cagou on Android)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
211 self.sendSignal("progressError", id, error, profile) |
787b15d16347
bridge: added generated pb files to repository (needed for Cagou on Android)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
212 |
787b15d16347
bridge: added generated pb files to repository (needed for Cagou on Android)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
213 def progressFinished(self, id, metadata, profile): |
787b15d16347
bridge: added generated pb files to repository (needed for Cagou on Android)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
214 self.sendSignal("progressFinished", id, metadata, profile) |
787b15d16347
bridge: added generated pb files to repository (needed for Cagou on Android)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
215 |
787b15d16347
bridge: added generated pb files to repository (needed for Cagou on Android)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
216 def progressStarted(self, id, metadata, profile): |
787b15d16347
bridge: added generated pb files to repository (needed for Cagou on Android)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
217 self.sendSignal("progressStarted", id, metadata, profile) |
787b15d16347
bridge: added generated pb files to repository (needed for Cagou on Android)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
218 |
787b15d16347
bridge: added generated pb files to repository (needed for Cagou on Android)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
219 def subscribe(self, sub_type, entity_jid, profile): |
787b15d16347
bridge: added generated pb files to repository (needed for Cagou on Android)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
220 self.sendSignal("subscribe", sub_type, entity_jid, profile) |