Mercurial > libervia-backend
annotate libervia/backend/bridge/pb.py @ 4318:27bb22eace65
tests (unit/email gateway): add test for XEP-0131 handling:
rel 451
author | Goffi <goffi@goffi.org> |
---|---|
date | Sat, 28 Sep 2024 15:59:48 +0200 |
parents | 3a550e9a2b55 |
children |
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 |
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 |
2579
787b15d16347
bridge: added generated pb files to repository (needed for Cagou on Android)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
24 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
|
25 from twisted.internet import reactor |
4071
4b842c1fb686
refactoring: renamed `sat` package to `libervia.backend`
Goffi <goffi@goffi.org>
parents:
4037
diff
changeset
|
26 from libervia.backend.core.log import getLogger |
4b842c1fb686
refactoring: renamed `sat` package to `libervia.backend`
Goffi <goffi@goffi.org>
parents:
4037
diff
changeset
|
27 from libervia.backend.tools import config |
3039
a1bc34f90fa5
bridge (pb): implemented an asyncio compatible bridge:
Goffi <goffi@goffi.org>
parents:
3028
diff
changeset
|
28 |
2892
82b781c46841
core: added a rosterResync method to bridge:
Goffi <goffi@goffi.org>
parents:
2854
diff
changeset
|
29 log = getLogger(__name__) |
2579
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 |
787b15d16347
bridge: added generated pb files to repository (needed for Cagou on Android)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
32 ## jelly hack |
787b15d16347
bridge: added generated pb files to repository (needed for Cagou on Android)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
33 # 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
|
34 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
|
35 |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2579
diff
changeset
|
36 |
2579
787b15d16347
bridge: added generated pb files to repository (needed for Cagou on Android)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
37 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
|
38 """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
|
39 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
|
40 obj = tuple(obj) |
787b15d16347
bridge: added generated pb files to repository (needed for Cagou on Android)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
41 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
|
42 |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2579
diff
changeset
|
43 |
2579
787b15d16347
bridge: added generated pb files to repository (needed for Cagou on Android)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
44 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
|
45 |
787b15d16347
bridge: added generated pb files to repository (needed for Cagou on Android)
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 |
2579
787b15d16347
bridge: added generated pb files to repository (needed for Cagou on Android)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
54 class PBRoot(pb.Root): |
787b15d16347
bridge: added generated pb files to repository (needed for Cagou on Android)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
55 def __init__(self): |
787b15d16347
bridge: added generated pb files to repository (needed for Cagou on Android)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
56 self.signals_handlers = [] |
787b15d16347
bridge: added generated pb files to repository (needed for Cagou on Android)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
57 |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3634
diff
changeset
|
58 def remote_init_bridge(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") |
2579
787b15d16347
bridge: added generated pb files to repository (needed for Cagou on Android)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
61 |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3634
diff
changeset
|
62 def send_signal_eb(self, failure_, signal_name): |
3039
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:
2579
diff
changeset
|
66 ) |
2579
787b15d16347
bridge: added generated pb files to repository (needed for Cagou on Android)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
67 |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3634
diff
changeset
|
68 def send_signal(self, name, args, kwargs): |
2579
787b15d16347
bridge: added generated pb files to repository (needed for Cagou on Android)
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 |
2579
787b15d16347
bridge: added generated pb files to repository (needed for Cagou on Android)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
72 try: |
787b15d16347
bridge: added generated pb files to repository (needed for Cagou on Android)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
73 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
|
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) |
2579
787b15d16347
bridge: added generated pb files to repository (needed for Cagou on Android)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
76 else: |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3634
diff
changeset
|
77 d.addErrback(self.send_signal_eb, name) |
2579
787b15d16347
bridge: added generated pb files to repository (needed for Cagou on Android)
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) |
2579
787b15d16347
bridge: added generated pb files to repository (needed for Cagou on Android)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
82 |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3634
diff
changeset
|
83 def _bridge_deactivate_signals(self): |
2840
0f277708e2ae
bridge (pb): added bridgeDeactivateSignals and bridgeReactivateSignals methods:
Goffi <goffi@goffi.org>
parents:
2771
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:
2771
diff
changeset
|
86 if self.signals_handler: |
0f277708e2ae
bridge (pb): added bridgeDeactivateSignals and bridgeReactivateSignals methods:
Goffi <goffi@goffi.org>
parents:
2771
diff
changeset
|
87 self.signals_paused.extend(self.signals_handler) |
0f277708e2ae
bridge (pb): added bridgeDeactivateSignals and bridgeReactivateSignals methods:
Goffi <goffi@goffi.org>
parents:
2771
diff
changeset
|
88 else: |
0f277708e2ae
bridge (pb): added bridgeDeactivateSignals and bridgeReactivateSignals methods:
Goffi <goffi@goffi.org>
parents:
2771
diff
changeset
|
89 self.signals_paused = self.signals_handlers |
0f277708e2ae
bridge (pb): added bridgeDeactivateSignals and bridgeReactivateSignals methods:
Goffi <goffi@goffi.org>
parents:
2771
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:
2771
diff
changeset
|
92 |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3634
diff
changeset
|
93 def _bridge_reactivate_signals(self): |
2840
0f277708e2ae
bridge (pb): added bridgeDeactivateSignals and bridgeReactivateSignals methods:
Goffi <goffi@goffi.org>
parents:
2771
diff
changeset
|
94 try: |
0f277708e2ae
bridge (pb): added bridgeDeactivateSignals and bridgeReactivateSignals methods:
Goffi <goffi@goffi.org>
parents:
2771
diff
changeset
|
95 self.signals_handlers = self.signals_paused |
0f277708e2ae
bridge (pb): added bridgeDeactivateSignals and bridgeReactivateSignals methods:
Goffi <goffi@goffi.org>
parents:
2771
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:
2771
diff
changeset
|
98 else: |
0f277708e2ae
bridge (pb): added bridgeDeactivateSignals and bridgeReactivateSignals methods:
Goffi <goffi@goffi.org>
parents:
2771
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:
2579
diff
changeset
|
101 |
4270
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4148
diff
changeset
|
102 |
2579
787b15d16347
bridge: added generated pb files to repository (needed for Cagou on Android)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
103 ##METHODS_PART## |
787b15d16347
bridge: added generated pb files to repository (needed for Cagou on Android)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
104 |
787b15d16347
bridge: added generated pb files to repository (needed for Cagou on Android)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
105 |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3634
diff
changeset
|
106 class bridge(object): |
2579
787b15d16347
bridge: added generated pb files to repository (needed for Cagou on Android)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
107 def __init__(self): |
787b15d16347
bridge: added generated pb files to repository (needed for Cagou on Android)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
108 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
|
109 self.root = PBRoot() |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3634
diff
changeset
|
110 conf = config.parse_main_conf() |
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3634
diff
changeset
|
111 get_conf = partial(config.get_conf, conf, "bridge_pb", "") |
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3634
diff
changeset
|
112 conn_type = get_conf("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
|
113 if conn_type == "unix_socket": |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3634
diff
changeset
|
114 local_dir = Path(config.config_get(conf, "", "local_dir")).resolve() |
3489
d71a163c0861
bridge (pb): connection can be set to used either UNIX socket or TCP socket:
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
115 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
|
116 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
|
117 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
|
118 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
|
119 ) |
d71a163c0861
bridge (pb): connection can be set to used either UNIX socket or TCP socket:
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
120 elif conn_type == "socket": |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3634
diff
changeset
|
121 port = int(get_conf("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
|
122 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
|
123 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
|
124 else: |
d71a163c0861
bridge (pb): connection can be set to used either UNIX socket or TCP socket:
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
125 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
|
126 |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3634
diff
changeset
|
127 def send_signal(self, name, *args, **kwargs): |
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3634
diff
changeset
|
128 self.root.send_signal(name, args, kwargs) |
2579
787b15d16347
bridge: added generated pb files to repository (needed for Cagou on Android)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
129 |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3634
diff
changeset
|
130 def remote_init_bridge(self, signals_handler): |
2579
787b15d16347
bridge: added generated pb files to repository (needed for Cagou on Android)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
131 self.signals_handlers.append(signals_handler) |
3028 | 132 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
|
133 |
787b15d16347
bridge: added generated pb files to repository (needed for Cagou on Android)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
134 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
|
135 log.debug("registering PB bridge method [%s]" % name) |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2579
diff
changeset
|
136 setattr(self.root, "remote_" + name, callback) |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2579
diff
changeset
|
137 # 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
|
138 |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3634
diff
changeset
|
139 def add_method( |
4270
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4148
diff
changeset
|
140 self, name, int_suffix, in_sign, out_sign, method, async_=False, doc={} |
3489
d71a163c0861
bridge (pb): connection can be set to used either UNIX socket or TCP socket:
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
141 ): |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3634
diff
changeset
|
142 """Dynamically add a method to PB bridge""" |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2579
diff
changeset
|
143 # 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
|
144 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
|
145 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
|
146 |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3634
diff
changeset
|
147 def add_signal(self, name, int_suffix, signature, doc={}): |
2579
787b15d16347
bridge: added generated pb files to repository (needed for Cagou on Android)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
148 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
|
149 setattr( |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3634
diff
changeset
|
150 self, name, lambda *args, **kwargs: self.send_signal(name, *args, **kwargs) |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2579
diff
changeset
|
151 ) |
2579
787b15d16347
bridge: added generated pb files to repository (needed for Cagou on Android)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
152 |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3634
diff
changeset
|
153 def bridge_deactivate_signals(self): |
2840
0f277708e2ae
bridge (pb): added bridgeDeactivateSignals and bridgeReactivateSignals methods:
Goffi <goffi@goffi.org>
parents:
2771
diff
changeset
|
154 """Stop sending signals to bridge |
0f277708e2ae
bridge (pb): added bridgeDeactivateSignals and bridgeReactivateSignals methods:
Goffi <goffi@goffi.org>
parents:
2771
diff
changeset
|
155 |
0f277708e2ae
bridge (pb): added bridgeDeactivateSignals and bridgeReactivateSignals methods:
Goffi <goffi@goffi.org>
parents:
2771
diff
changeset
|
156 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
|
157 """ |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3634
diff
changeset
|
158 self.root._bridge_deactivate_signals() |
2840
0f277708e2ae
bridge (pb): added bridgeDeactivateSignals and bridgeReactivateSignals methods:
Goffi <goffi@goffi.org>
parents:
2771
diff
changeset
|
159 |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3634
diff
changeset
|
160 def bridge_reactivate_signals(self): |
2840
0f277708e2ae
bridge (pb): added bridgeDeactivateSignals and bridgeReactivateSignals methods:
Goffi <goffi@goffi.org>
parents:
2771
diff
changeset
|
161 """Send again signals to bridge |
0f277708e2ae
bridge (pb): added bridgeDeactivateSignals and bridgeReactivateSignals methods:
Goffi <goffi@goffi.org>
parents:
2771
diff
changeset
|
162 |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3634
diff
changeset
|
163 Should only be used after bridge_deactivate_signals has been called |
2840
0f277708e2ae
bridge (pb): added bridgeDeactivateSignals and bridgeReactivateSignals methods:
Goffi <goffi@goffi.org>
parents:
2771
diff
changeset
|
164 """ |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3634
diff
changeset
|
165 self.root._bridge_reactivate_signals() |
2628
779351da2c13
core, frontends: replaced org\.goffi namespaces by org.salutatoi + fixed generation:
Goffi <goffi@goffi.org>
parents:
2624
diff
changeset
|
166 |
2854 | 167 def _debug(self, action, params, profile): |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3634
diff
changeset
|
168 self.send_signal("_debug", action, params, profile) |
2854 | 169 |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3634
diff
changeset
|
170 def action_new(self, action_data, id, security_limit, profile): |
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3634
diff
changeset
|
171 self.send_signal("action_new", action_data, id, security_limit, profile) |
2579
787b15d16347
bridge: added generated pb files to repository (needed for Cagou on Android)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
172 |
2894
c7c52c0dc13a
core, quick_frontend(app): fixed connected signal handling
Goffi <goffi@goffi.org>
parents:
2892
diff
changeset
|
173 def connected(self, jid_s, profile): |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3634
diff
changeset
|
174 self.send_signal("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
|
175 |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3634
diff
changeset
|
176 def contact_deleted(self, entity_jid, profile): |
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3634
diff
changeset
|
177 self.send_signal("contact_deleted", entity_jid, profile) |
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3634
diff
changeset
|
178 |
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3634
diff
changeset
|
179 def contact_new(self, contact_jid, attributes, groups, profile): |
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3634
diff
changeset
|
180 self.send_signal("contact_new", contact_jid, attributes, groups, profile) |
2579
787b15d16347
bridge: added generated pb files to repository (needed for Cagou on Android)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
181 |
787b15d16347
bridge: added generated pb files to repository (needed for Cagou on Android)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
182 def disconnected(self, profile): |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3634
diff
changeset
|
183 self.send_signal("disconnected", profile) |
2579
787b15d16347
bridge: added generated pb files to repository (needed for Cagou on Android)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
184 |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3634
diff
changeset
|
185 def entity_data_updated(self, jid, name, value, profile): |
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3634
diff
changeset
|
186 self.send_signal("entity_data_updated", jid, name, value, profile) |
2579
787b15d16347
bridge: added generated pb files to repository (needed for Cagou on Android)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
187 |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3634
diff
changeset
|
188 def message_encryption_started(self, to_jid, encryption_data, profile_key): |
4284 | 189 self.send_signal( |
190 "message_encryption_started", to_jid, encryption_data, profile_key | |
191 ) | |
2655
b8600f8130ac
core (bridge): new messageEncryptionStarted and messageEncryptionStopped signals (not used yet)
Goffi <goffi@goffi.org>
parents:
2628
diff
changeset
|
192 |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3634
diff
changeset
|
193 def message_encryption_stopped(self, to_jid, encryption_data, profile_key): |
4284 | 194 self.send_signal( |
195 "message_encryption_stopped", to_jid, encryption_data, profile_key | |
196 ) | |
2655
b8600f8130ac
core (bridge): new messageEncryptionStarted and messageEncryptionStopped signals (not used yet)
Goffi <goffi@goffi.org>
parents:
2628
diff
changeset
|
197 |
4284 | 198 def message_new( |
199 self, | |
200 uid, | |
201 timestamp, | |
202 from_jid, | |
203 to_jid, | |
204 message, | |
205 subject, | |
206 mess_type, | |
207 extra, | |
208 profile, | |
209 ): | |
210 self.send_signal( | |
211 "message_new", | |
212 uid, | |
213 timestamp, | |
214 from_jid, | |
215 to_jid, | |
216 message, | |
217 subject, | |
218 mess_type, | |
219 extra, | |
220 profile, | |
221 ) | |
2579
787b15d16347
bridge: added generated pb files to repository (needed for Cagou on Android)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
222 |
4148
a8a0fa678ce2
bridge: add `message_update` signal
Goffi <goffi@goffi.org>
parents:
4130
diff
changeset
|
223 def message_update(self, uid, message_type, message_data, profile): |
a8a0fa678ce2
bridge: add `message_update` signal
Goffi <goffi@goffi.org>
parents:
4130
diff
changeset
|
224 self.send_signal("message_update", uid, message_type, message_data, profile) |
a8a0fa678ce2
bridge: add `message_update` signal
Goffi <goffi@goffi.org>
parents:
4130
diff
changeset
|
225 |
4130
02f0adc745c6
core: notifications implementation, first draft:
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
226 def notification_deleted(self, id, profile): |
02f0adc745c6
core: notifications implementation, first draft:
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
227 self.send_signal("notification_deleted", id, profile) |
02f0adc745c6
core: notifications implementation, first draft:
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
228 |
4284 | 229 def notification_new( |
230 self, | |
231 id, | |
232 timestamp, | |
233 type, | |
234 body_plain, | |
235 body_rich, | |
236 title, | |
237 requires_action, | |
238 priority, | |
239 expire_at, | |
240 extra, | |
241 profile, | |
242 ): | |
243 self.send_signal( | |
244 "notification_new", | |
245 id, | |
246 timestamp, | |
247 type, | |
248 body_plain, | |
249 body_rich, | |
250 title, | |
251 requires_action, | |
252 priority, | |
253 expire_at, | |
254 extra, | |
255 profile, | |
256 ) | |
4130
02f0adc745c6
core: notifications implementation, first draft:
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
257 |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3634
diff
changeset
|
258 def param_update(self, name, value, category, profile): |
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3634
diff
changeset
|
259 self.send_signal("param_update", name, value, category, profile) |
2579
787b15d16347
bridge: added generated pb files to repository (needed for Cagou on Android)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
260 |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3634
diff
changeset
|
261 def presence_update(self, entity_jid, show, priority, statuses, profile): |
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3634
diff
changeset
|
262 self.send_signal("presence_update", entity_jid, show, priority, statuses, profile) |
2579
787b15d16347
bridge: added generated pb files to repository (needed for Cagou on Android)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
263 |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3634
diff
changeset
|
264 def progress_error(self, id, error, profile): |
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3634
diff
changeset
|
265 self.send_signal("progress_error", id, error, profile) |
2579
787b15d16347
bridge: added generated pb files to repository (needed for Cagou on Android)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
266 |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3634
diff
changeset
|
267 def progress_finished(self, id, metadata, profile): |
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3634
diff
changeset
|
268 self.send_signal("progress_finished", id, metadata, profile) |
2579
787b15d16347
bridge: added generated pb files to repository (needed for Cagou on Android)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
269 |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3634
diff
changeset
|
270 def progress_started(self, id, metadata, profile): |
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3634
diff
changeset
|
271 self.send_signal("progress_started", id, metadata, profile) |
2579
787b15d16347
bridge: added generated pb files to repository (needed for Cagou on Android)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
272 |
787b15d16347
bridge: added generated pb files to repository (needed for Cagou on Android)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
273 def subscribe(self, sub_type, entity_jid, profile): |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3634
diff
changeset
|
274 self.send_signal("subscribe", sub_type, entity_jid, profile) |