Mercurial > libervia-backend
annotate frontends/src/bridge/DBus.py @ 267:bdcd535e179e
Bridge constructor:
- moved constructor files in src/bridge/bridge_constructor
- frontend side can now be generated
author | Goffi <goffi@goffi.org> |
---|---|
date | Mon, 24 Jan 2011 21:19:11 +0100 |
parents | c8406fe5e81e |
children | 1d2e0dfe7114 |
rev | line source |
---|---|
0 | 1 #!/usr/bin/python |
2 #-*- coding: utf-8 -*- | |
3 | |
4 """ | |
5 SAT communication bridge | |
228 | 6 Copyright (C) 2009, 2010, 2011 Jérôme Poisson (goffi@goffi.org) |
0 | 7 |
8 This program is free software: you can redistribute it and/or modify | |
9 it under the terms of the GNU General Public License as published by | |
10 the Free Software Foundation, either version 3 of the License, or | |
11 (at your option) any later version. | |
12 | |
13 This program is distributed in the hope that it will be useful, | |
14 but WITHOUT ANY WARRANTY; without even the implied warranty of | |
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
16 GNU General Public License for more details. | |
17 | |
18 You should have received a copy of the GNU General Public License | |
19 along with this program. If not, see <http://www.gnu.org/licenses/>. | |
20 """ | |
21 | |
22 from bridge_frontend import BridgeFrontend | |
23 import dbus, dbus.glib | |
24 | |
165
8a2053de6f8c
Frontends: management of unlaunched SàT Backend (information message and exit)
Goffi <goffi@goffi.org>
parents:
136
diff
changeset
|
25 class BridgeExceptionNoService(Exception): |
8a2053de6f8c
Frontends: management of unlaunched SàT Backend (information message and exit)
Goffi <goffi@goffi.org>
parents:
136
diff
changeset
|
26 pass |
0 | 27 |
28 class DBusBridgeFrontend(BridgeFrontend): | |
29 def __init__(self): | |
165
8a2053de6f8c
Frontends: management of unlaunched SàT Backend (information message and exit)
Goffi <goffi@goffi.org>
parents:
136
diff
changeset
|
30 try: |
8a2053de6f8c
Frontends: management of unlaunched SàT Backend (information message and exit)
Goffi <goffi@goffi.org>
parents:
136
diff
changeset
|
31 self.sessions_bus = dbus.SessionBus() |
8a2053de6f8c
Frontends: management of unlaunched SàT Backend (information message and exit)
Goffi <goffi@goffi.org>
parents:
136
diff
changeset
|
32 self.db_object = self.sessions_bus.get_object('org.goffi.SAT', |
8a2053de6f8c
Frontends: management of unlaunched SàT Backend (information message and exit)
Goffi <goffi@goffi.org>
parents:
136
diff
changeset
|
33 '/org/goffi/SAT/bridge') |
8a2053de6f8c
Frontends: management of unlaunched SàT Backend (information message and exit)
Goffi <goffi@goffi.org>
parents:
136
diff
changeset
|
34 self.db_comm_iface = dbus.Interface(self.db_object, |
8a2053de6f8c
Frontends: management of unlaunched SàT Backend (information message and exit)
Goffi <goffi@goffi.org>
parents:
136
diff
changeset
|
35 dbus_interface='org.goffi.SAT.communication') |
8a2053de6f8c
Frontends: management of unlaunched SàT Backend (information message and exit)
Goffi <goffi@goffi.org>
parents:
136
diff
changeset
|
36 self.db_req_iface = dbus.Interface(self.db_object, |
8a2053de6f8c
Frontends: management of unlaunched SàT Backend (information message and exit)
Goffi <goffi@goffi.org>
parents:
136
diff
changeset
|
37 dbus_interface='org.goffi.SAT.request') |
8a2053de6f8c
Frontends: management of unlaunched SàT Backend (information message and exit)
Goffi <goffi@goffi.org>
parents:
136
diff
changeset
|
38 except dbus.exceptions.DBusException,e: |
8a2053de6f8c
Frontends: management of unlaunched SàT Backend (information message and exit)
Goffi <goffi@goffi.org>
parents:
136
diff
changeset
|
39 if e._dbus_error_name=='org.freedesktop.DBus.Error.ServiceUnknown': |
8a2053de6f8c
Frontends: management of unlaunched SàT Backend (information message and exit)
Goffi <goffi@goffi.org>
parents:
136
diff
changeset
|
40 raise BridgeExceptionNoService |
8a2053de6f8c
Frontends: management of unlaunched SàT Backend (information message and exit)
Goffi <goffi@goffi.org>
parents:
136
diff
changeset
|
41 else: |
8a2053de6f8c
Frontends: management of unlaunched SàT Backend (information message and exit)
Goffi <goffi@goffi.org>
parents:
136
diff
changeset
|
42 raise e |
0 | 43 #props = self.db_comm_iface.getProperties() |
44 | |
45 def register(self, functionName, handler, iface="communication"): | |
46 if iface == "communication": | |
47 self.db_comm_iface.connect_to_signal(functionName, handler) | |
48 elif iface == "request": | |
49 self.db_req_iface.connect_to_signal(functionName, handler) | |
50 | |
267 | 51 ##METHODS_PART## |
101 | 52 |
65
d35c5edab53f
SàT: multi-profile: memory & dbus bridge's methods profile management
Goffi <goffi@goffi.org>
parents:
64
diff
changeset
|
53 #methods from plugins |
78
ace2af8abc5a
Added method to know which MUC are joined, and which subjects were received.
Goffi <goffi@goffi.org>
parents:
72
diff
changeset
|
54 def getRoomJoined(self, profile_key='@DEFAULT@'): |
ace2af8abc5a
Added method to know which MUC are joined, and which subjects were received.
Goffi <goffi@goffi.org>
parents:
72
diff
changeset
|
55 return self.db_comm_iface.getRoomJoined(profile_key) |
ace2af8abc5a
Added method to know which MUC are joined, and which subjects were received.
Goffi <goffi@goffi.org>
parents:
72
diff
changeset
|
56 |
ace2af8abc5a
Added method to know which MUC are joined, and which subjects were received.
Goffi <goffi@goffi.org>
parents:
72
diff
changeset
|
57 def getRoomSubjects(self, profile_key='@DEFAULT@'): |
ace2af8abc5a
Added method to know which MUC are joined, and which subjects were received.
Goffi <goffi@goffi.org>
parents:
72
diff
changeset
|
58 return self.db_comm_iface.getRoomSubjects(profile_key) |
ace2af8abc5a
Added method to know which MUC are joined, and which subjects were received.
Goffi <goffi@goffi.org>
parents:
72
diff
changeset
|
59 |
72 | 60 def joinMUC(self, service, roomId, nick, profile_key='@DEFAULT@'): |
61 return self.db_comm_iface.joinMUC(service, roomId, nick, profile_key) | |
62 | |
90 | 63 def tarotGameCreate(self, room_jid, players, profile_key='@DEFAULT@'): |
64 return self.db_comm_iface.tarotGameCreate(room_jid, players, profile_key) | |
65 | |
92 | 66 def tarotGameReady(self, player, referee, profile_key='@DEFAULT@'): |
67 return self.db_comm_iface.tarotGameReady(player, referee, profile_key) | |
85 | 68 |
92 | 69 def tarotGameContratChoosed(self, player, referee, contrat, profile_key='@DEFAULT@'): |
70 return self.db_comm_iface.tarotGameContratChoosed(player, referee, contrat, profile_key) | |
71 | |
72 def tarotGamePlayCards(self, player, referee, cards, profile_key='@DEFAULT@'): | |
73 return self.db_comm_iface.tarotGamePlayCards(player, referee, cards, profile_key) | |
91 | 74 |
64 | 75 def sendFile(self, to, path, profile_key='@DEFAULT@'): |
76 return self.db_comm_iface.sendFile(to, path, profile_key) | |
0 | 77 |
65
d35c5edab53f
SàT: multi-profile: memory & dbus bridge's methods profile management
Goffi <goffi@goffi.org>
parents:
64
diff
changeset
|
78 def findGateways(self, target, profile_key='@DEFAULT@'): |
d35c5edab53f
SàT: multi-profile: memory & dbus bridge's methods profile management
Goffi <goffi@goffi.org>
parents:
64
diff
changeset
|
79 return self.db_comm_iface.findGateways(target, profile_key) |
25
53e921c8a357
new plugin: gateways plugin, and first implementation of findGateways
Goffi <goffi@goffi.org>
parents:
22
diff
changeset
|
80 |
64 | 81 def getCard(self, target, profile_key='@DEFAULT@'): |
82 return self.db_comm_iface.getCard(target, profile_key) | |
42
874de3020e1c
Initial VCard (XEP-0054) support + misc fixes
Goffi <goffi@goffi.org>
parents:
37
diff
changeset
|
83 |
64 | 84 def getCardCache(self, target): |
85 return self.db_comm_iface.getCardCache(target) | |
51
8c67ea98ab91
frontend improved to take into account new SàT features
Goffi <goffi@goffi.org>
parents:
43
diff
changeset
|
86 |
43 | 87 def getAvatarFile(self, hash): |
88 return self.db_comm_iface.getAvatarFile(hash) | |
89 | |
64 | 90 def in_band_register(self, target, profile_key='@DEFAULT@'): |
91 return self.db_comm_iface.in_band_register(target, profile_key) | |
0 | 92 |
171
96af1bec2e68
Dbus bridge (frontend): added profile_key argument for gatewayRegister
Goffi <goffi@goffi.org>
parents:
165
diff
changeset
|
93 def gatewayRegister(self, action, target, data, profile_key='@DEFAULT@'): |
37
a61beb21d16d
Gateway registration, unregistration & edition
Goffi <goffi@goffi.org>
parents:
36
diff
changeset
|
94 if data == None: |
101 | 95 data = [('', '')] #XXX: we have to do this awful hack because python dbus need to guess the signature |
171
96af1bec2e68
Dbus bridge (frontend): added profile_key argument for gatewayRegister
Goffi <goffi@goffi.org>
parents:
165
diff
changeset
|
96 return self.db_req_iface.gatewayRegister(action, target, data, profile_key) |
36 | 97 |
101 | 98 |