annotate sat/bridge/pb.py @ 3686:fc209014524a

install (setup): set minimum version of `python-dateutil` to `2.8.1`: `dateutil.parser.ParserError` is only available from `2.8.1`, thus this become the minimum required version.
author Goffi <goffi@goffi.org>
date Thu, 30 Sep 2021 10:32:04 +0200
parents 3c7a64d6f49f
children 524856bd7b19
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2894
diff changeset
1 #!/usr/bin/env python3
3137
559a625a236b fixed shebangs
Goffi <goffi@goffi.org>
parents: 3136
diff changeset
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
be6d91572633 date update
Goffi <goffi@goffi.org>
parents: 3137
diff changeset
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
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
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
787b15d16347 bridge: added generated pb files to repository (needed for Cagou on Android)
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
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2894
diff changeset
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
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: 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
787b15d16347 bridge: added generated pb files to repository (needed for Cagou on Android)
Goffi <goffi@goffi.org>
parents:
diff changeset
68 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
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:
787b15d16347 bridge: added generated pb files to repository (needed for Cagou on Android)
Goffi <goffi@goffi.org>
parents:
diff changeset
77 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
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
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2894
diff changeset
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
2840
0f277708e2ae bridge (pb): added bridgeDeactivateSignals and bridgeReactivateSignals methods:
Goffi <goffi@goffi.org>
parents: 2771
diff changeset
83 def _bridgeDeactivateSignals(self):
0f277708e2ae bridge (pb): added bridgeDeactivateSignals and bridgeReactivateSignals methods:
Goffi <goffi@goffi.org>
parents: 2771
diff changeset
84 if hasattr(self, "signals_paused"):
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2894
diff changeset
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
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2894
diff changeset
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
0f277708e2ae bridge (pb): added bridgeDeactivateSignals and bridgeReactivateSignals methods:
Goffi <goffi@goffi.org>
parents: 2771
diff changeset
93 def _bridgeReactivateSignals(self):
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
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2894
diff changeset
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
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2894
diff changeset
100 log.debug("bridge signals have been reactivated")
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2579
diff changeset
101
2579
787b15d16347 bridge: added generated pb files to repository (needed for Cagou on Android)
Goffi <goffi@goffi.org>
parents:
diff changeset
102 ##METHODS_PART##
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
787b15d16347 bridge: added generated pb files to repository (needed for Cagou on Android)
Goffi <goffi@goffi.org>
parents:
diff changeset
105 class Bridge(object):
787b15d16347 bridge: added generated pb files to repository (needed for Cagou on Android)
Goffi <goffi@goffi.org>
parents:
diff changeset
106 def __init__(self):
787b15d16347 bridge: added generated pb files to repository (needed for Cagou on Android)
Goffi <goffi@goffi.org>
parents:
diff changeset
107 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
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}")
2579
787b15d16347 bridge: added generated pb files to repository (needed for Cagou on Android)
Goffi <goffi@goffi.org>
parents:
diff changeset
125
787b15d16347 bridge: added generated pb files to repository (needed for Cagou on Android)
Goffi <goffi@goffi.org>
parents:
diff changeset
126 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
127 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
128
787b15d16347 bridge: added generated pb files to repository (needed for Cagou on Android)
Goffi <goffi@goffi.org>
parents:
diff changeset
129 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
130 self.signals_handlers.append(signals_handler)
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2894
diff changeset
131 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
132
787b15d16347 bridge: added generated pb files to repository (needed for Cagou on Android)
Goffi <goffi@goffi.org>
parents:
diff changeset
133 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
134 log.debug("registering PB bridge method [%s]" % name)
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2579
diff changeset
135 setattr(self.root, "remote_" + name, callback)
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2579
diff changeset
136 #  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
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 ):
2579
787b15d16347 bridge: added generated pb files to repository (needed for Cagou on Android)
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: 2579
diff changeset
142 # 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
143 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
144 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
145
787b15d16347 bridge: added generated pb files to repository (needed for Cagou on Android)
Goffi <goffi@goffi.org>
parents:
diff changeset
146 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
147 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
148 setattr(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2579
diff changeset
149 self, name, lambda *args, **kwargs: self.sendSignal(name, *args, **kwargs)
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2579
diff changeset
150 )
2579
787b15d16347 bridge: added generated pb files to repository (needed for Cagou on Android)
Goffi <goffi@goffi.org>
parents:
diff changeset
151
2840
0f277708e2ae bridge (pb): added bridgeDeactivateSignals and bridgeReactivateSignals methods:
Goffi <goffi@goffi.org>
parents: 2771
diff changeset
152 def bridgeDeactivateSignals(self):
0f277708e2ae bridge (pb): added bridgeDeactivateSignals and bridgeReactivateSignals methods:
Goffi <goffi@goffi.org>
parents: 2771
diff changeset
153 """Stop sending signals to bridge
0f277708e2ae bridge (pb): added bridgeDeactivateSignals and bridgeReactivateSignals methods:
Goffi <goffi@goffi.org>
parents: 2771
diff changeset
154
0f277708e2ae bridge (pb): added bridgeDeactivateSignals and bridgeReactivateSignals methods:
Goffi <goffi@goffi.org>
parents: 2771
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: 2771
diff changeset
156 """
0f277708e2ae bridge (pb): added bridgeDeactivateSignals and bridgeReactivateSignals methods:
Goffi <goffi@goffi.org>
parents: 2771
diff changeset
157 self.root._bridgeDeactivateSignals()
0f277708e2ae bridge (pb): added bridgeDeactivateSignals and bridgeReactivateSignals methods:
Goffi <goffi@goffi.org>
parents: 2771
diff changeset
158
0f277708e2ae bridge (pb): added bridgeDeactivateSignals and bridgeReactivateSignals methods:
Goffi <goffi@goffi.org>
parents: 2771
diff changeset
159 def bridgeReactivateSignals(self):
0f277708e2ae bridge (pb): added bridgeDeactivateSignals and bridgeReactivateSignals methods:
Goffi <goffi@goffi.org>
parents: 2771
diff changeset
160 """Send again signals to bridge
0f277708e2ae bridge (pb): added bridgeDeactivateSignals and bridgeReactivateSignals methods:
Goffi <goffi@goffi.org>
parents: 2771
diff changeset
161
0f277708e2ae bridge (pb): added bridgeDeactivateSignals and bridgeReactivateSignals methods:
Goffi <goffi@goffi.org>
parents: 2771
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: 2771
diff changeset
163 """
0f277708e2ae bridge (pb): added bridgeDeactivateSignals and bridgeReactivateSignals methods:
Goffi <goffi@goffi.org>
parents: 2771
diff changeset
164 self.root._bridgeReactivateSignals()
2628
779351da2c13 core, frontends: replaced org\.goffi namespaces by org.salutatoi + fixed generation:
Goffi <goffi@goffi.org>
parents: 2624
diff changeset
165
2854
eb9fa72eb62b core: added a "_debug" signal:
Goffi <goffi@goffi.org>
parents: 2840
diff changeset
166 def _debug(self, action, params, profile):
eb9fa72eb62b core: added a "_debug" signal:
Goffi <goffi@goffi.org>
parents: 2840
diff changeset
167 self.sendSignal("_debug", action, params, profile)
eb9fa72eb62b core: added a "_debug" signal:
Goffi <goffi@goffi.org>
parents: 2840
diff changeset
168
2579
787b15d16347 bridge: added generated pb files to repository (needed for Cagou on Android)
Goffi <goffi@goffi.org>
parents:
diff changeset
169 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
170 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
171
2894
c7c52c0dc13a core, quick_frontend(app): fixed connected signal handling
Goffi <goffi@goffi.org>
parents: 2892
diff changeset
172 def connected(self, jid_s, profile):
c7c52c0dc13a core, quick_frontend(app): fixed connected signal handling
Goffi <goffi@goffi.org>
parents: 2892
diff changeset
173 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
174
787b15d16347 bridge: added generated pb files to repository (needed for Cagou on Android)
Goffi <goffi@goffi.org>
parents:
diff changeset
175 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
176 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
177
787b15d16347 bridge: added generated pb files to repository (needed for Cagou on Android)
Goffi <goffi@goffi.org>
parents:
diff changeset
178 def disconnected(self, profile):
787b15d16347 bridge: added generated pb files to repository (needed for Cagou on Android)
Goffi <goffi@goffi.org>
parents:
diff changeset
179 self.sendSignal("disconnected", profile)
787b15d16347 bridge: added generated pb files to repository (needed for Cagou on Android)
Goffi <goffi@goffi.org>
parents:
diff changeset
180
787b15d16347 bridge: added generated pb files to repository (needed for Cagou on Android)
Goffi <goffi@goffi.org>
parents:
diff changeset
181 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
182 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
183
2655
b8600f8130ac core (bridge): new messageEncryptionStarted and messageEncryptionStopped signals (not used yet)
Goffi <goffi@goffi.org>
parents: 2628
diff changeset
184 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
185 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
186
b8600f8130ac core (bridge): new messageEncryptionStarted and messageEncryptionStopped signals (not used yet)
Goffi <goffi@goffi.org>
parents: 2628
diff changeset
187 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
188 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
189
2628
779351da2c13 core, frontends: replaced org\.goffi namespaces by org.salutatoi + fixed generation:
Goffi <goffi@goffi.org>
parents: 2624
diff changeset
190 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
191 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
192
787b15d16347 bridge: added generated pb files to repository (needed for Cagou on Android)
Goffi <goffi@goffi.org>
parents:
diff changeset
193 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
194 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
195
787b15d16347 bridge: added generated pb files to repository (needed for Cagou on Android)
Goffi <goffi@goffi.org>
parents:
diff changeset
196 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
197 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
198
787b15d16347 bridge: added generated pb files to repository (needed for Cagou on Android)
Goffi <goffi@goffi.org>
parents:
diff changeset
199 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
200 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
201
787b15d16347 bridge: added generated pb files to repository (needed for Cagou on Android)
Goffi <goffi@goffi.org>
parents:
diff changeset
202 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
203 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
204
787b15d16347 bridge: added generated pb files to repository (needed for Cagou on Android)
Goffi <goffi@goffi.org>
parents:
diff changeset
205 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
206 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
207
787b15d16347 bridge: added generated pb files to repository (needed for Cagou on Android)
Goffi <goffi@goffi.org>
parents:
diff changeset
208 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
209 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
210
787b15d16347 bridge: added generated pb files to repository (needed for Cagou on Android)
Goffi <goffi@goffi.org>
parents:
diff changeset
211 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
212 self.sendSignal("subscribe", sub_type, entity_jid, profile)