Mercurial > libervia-backend
annotate src/bridge/bridge_constructor/dbus_frontend_template.py @ 359:eb9d33ba4e36
bridge: templates' constants can now be overrided
author | Goffi <goffi@goffi.org> |
---|---|
date | Mon, 06 Jun 2011 18:35:30 +0200 |
parents | 4402ac630712 |
children | 141eeb7cd9e6 |
rev | line source |
---|---|
267 | 1 #!/usr/bin/python |
2 #-*- coding: utf-8 -*- | |
3 | |
4 """ | |
5 SAT communication bridge | |
6 Copyright (C) 2009, 2010, 2011 Jérôme Poisson (goffi@goffi.org) | |
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 | |
272
1d2e0dfe7114
bridge: core & frontend sides of bridge are now generated
Goffi <goffi@goffi.org>
parents:
267
diff
changeset
|
24 from logging import debug |
267 | 25 |
359
eb9d33ba4e36
bridge: templates' constants can now be overrided
Goffi <goffi@goffi.org>
parents:
337
diff
changeset
|
26 const_INT_PREFIX = "org.goffi.SAT" #Interface prefix |
eb9d33ba4e36
bridge: templates' constants can now be overrided
Goffi <goffi@goffi.org>
parents:
337
diff
changeset
|
27 const_OBJ_PATH = '/org/goffi/SAT/bridge' |
eb9d33ba4e36
bridge: templates' constants can now be overrided
Goffi <goffi@goffi.org>
parents:
337
diff
changeset
|
28 const_COMM_SUFFIX = ".communication" |
eb9d33ba4e36
bridge: templates' constants can now be overrided
Goffi <goffi@goffi.org>
parents:
337
diff
changeset
|
29 const_REQ_SUFFIX = ".request" |
eb9d33ba4e36
bridge: templates' constants can now be overrided
Goffi <goffi@goffi.org>
parents:
337
diff
changeset
|
30 |
267 | 31 class BridgeExceptionNoService(Exception): |
32 pass | |
33 | |
34 class DBusBridgeFrontend(BridgeFrontend): | |
35 def __init__(self): | |
36 try: | |
37 self.sessions_bus = dbus.SessionBus() | |
359
eb9d33ba4e36
bridge: templates' constants can now be overrided
Goffi <goffi@goffi.org>
parents:
337
diff
changeset
|
38 self.db_object = self.sessions_bus.get_object(const_INT_PREFIX, |
eb9d33ba4e36
bridge: templates' constants can now be overrided
Goffi <goffi@goffi.org>
parents:
337
diff
changeset
|
39 const_OBJ_PATH) |
267 | 40 self.db_comm_iface = dbus.Interface(self.db_object, |
359
eb9d33ba4e36
bridge: templates' constants can now be overrided
Goffi <goffi@goffi.org>
parents:
337
diff
changeset
|
41 dbus_interface=const_INT_PREFIX + const_COMM_SUFFIX) |
267 | 42 self.db_req_iface = dbus.Interface(self.db_object, |
359
eb9d33ba4e36
bridge: templates' constants can now be overrided
Goffi <goffi@goffi.org>
parents:
337
diff
changeset
|
43 dbus_interface=const_INT_PREFIX + const_REQ_SUFFIX) |
267 | 44 except dbus.exceptions.DBusException,e: |
45 if e._dbus_error_name=='org.freedesktop.DBus.Error.ServiceUnknown': | |
46 raise BridgeExceptionNoService | |
47 else: | |
48 raise e | |
49 #props = self.db_comm_iface.getProperties() | |
50 | |
51 def register(self, functionName, handler, iface="communication"): | |
52 if iface == "communication": | |
53 self.db_comm_iface.connect_to_signal(functionName, handler) | |
54 elif iface == "request": | |
55 self.db_req_iface.connect_to_signal(functionName, handler) | |
56 | |
57 ##METHODS_PART## | |
58 | |
59 #methods from plugins | |
60 def getRoomJoined(self, profile_key='@DEFAULT@'): | |
61 return self.db_comm_iface.getRoomJoined(profile_key) | |
62 | |
63 def getRoomSubjects(self, profile_key='@DEFAULT@'): | |
64 return self.db_comm_iface.getRoomSubjects(profile_key) | |
65 | |
66 def joinMUC(self, service, roomId, nick, profile_key='@DEFAULT@'): | |
67 return self.db_comm_iface.joinMUC(service, roomId, nick, profile_key) | |
68 | |
320
5fc5e6a7e5c3
plugin Tarot: added a launch method to automatically create a new room, invite players and create the game
Goffi <goffi@goffi.org>
parents:
307
diff
changeset
|
69 def tarotGameLaunch(self, players, profile_key='@DEFAULT@'): |
5fc5e6a7e5c3
plugin Tarot: added a launch method to automatically create a new room, invite players and create the game
Goffi <goffi@goffi.org>
parents:
307
diff
changeset
|
70 return self.db_comm_iface.tarotGameLaunch(players, profile_key) |
5fc5e6a7e5c3
plugin Tarot: added a launch method to automatically create a new room, invite players and create the game
Goffi <goffi@goffi.org>
parents:
307
diff
changeset
|
71 |
267 | 72 def tarotGameCreate(self, room_jid, players, profile_key='@DEFAULT@'): |
73 return self.db_comm_iface.tarotGameCreate(room_jid, players, profile_key) | |
74 | |
75 def tarotGameReady(self, player, referee, profile_key='@DEFAULT@'): | |
76 return self.db_comm_iface.tarotGameReady(player, referee, profile_key) | |
77 | |
78 def tarotGameContratChoosed(self, player, referee, contrat, profile_key='@DEFAULT@'): | |
79 return self.db_comm_iface.tarotGameContratChoosed(player, referee, contrat, profile_key) | |
80 | |
81 def tarotGamePlayCards(self, player, referee, cards, profile_key='@DEFAULT@'): | |
82 return self.db_comm_iface.tarotGamePlayCards(player, referee, cards, profile_key) | |
83 | |
84 def sendFile(self, to, path, profile_key='@DEFAULT@'): | |
85 return self.db_comm_iface.sendFile(to, path, profile_key) | |
86 | |
87 def findGateways(self, target, profile_key='@DEFAULT@'): | |
88 return self.db_comm_iface.findGateways(target, profile_key) | |
89 | |
90 def getCard(self, target, profile_key='@DEFAULT@'): | |
91 return self.db_comm_iface.getCard(target, profile_key) | |
92 | |
93 def getCardCache(self, target): | |
94 return self.db_comm_iface.getCardCache(target) | |
95 | |
96 def getAvatarFile(self, hash): | |
97 return self.db_comm_iface.getAvatarFile(hash) | |
98 | |
99 def in_band_register(self, target, profile_key='@DEFAULT@'): | |
100 return self.db_comm_iface.in_band_register(target, profile_key) | |
101 | |
102 def gatewayRegister(self, action, target, data, profile_key='@DEFAULT@'): | |
103 if data == None: | |
104 data = [('', '')] #XXX: we have to do this awful hack because python dbus need to guess the signature | |
105 return self.db_req_iface.gatewayRegister(action, target, data, profile_key) | |
106 | |
303
2b52a5da0978
plugin XEP_0277: microblog access model can now be changed
Goffi <goffi@goffi.org>
parents:
272
diff
changeset
|
107 def getLastMicroblogs(self, jid, max_items, profile_key='@DEFAULT@', callback=None, errback=None): |
2b52a5da0978
plugin XEP_0277: microblog access model can now be changed
Goffi <goffi@goffi.org>
parents:
272
diff
changeset
|
108 return self.db_comm_iface.getLastMicroblogs(jid, max_items, profile_key, reply_handler=callback, error_handler=errback) |
267 | 109 |
307 | 110 def getMblogNodes(self, profile_key='@DEFAULT@', callback=None, errback=None): |
111 return self.db_comm_iface.getMblogNodes(profile_key, reply_handler=callback, error_handler=errback) | |
112 | |
113 def sendGroupBlog(self, groups, message, profile_key='@DEFAULT@'): | |
114 return self.db_comm_iface.sendGroupBlog(groups, message, profile_key) | |
115 | |
304 | 116 def sendPersonalEvent(self, event_type, data, profile_key='@DEFAULT@'): |
117 return self.db_comm_iface.sendPersonalEvent(event_type, data, profile_key) | |
337
4402ac630712
bridge: async callback managed in bridge_constructor + misc
Goffi <goffi@goffi.org>
parents:
320
diff
changeset
|
118 |
4402ac630712
bridge: async callback managed in bridge_constructor + misc
Goffi <goffi@goffi.org>
parents:
320
diff
changeset
|
119 def setMicroblogAccess(self, access="presence", profile_key='@DEFAULT@', callback=None, errback=None): |
4402ac630712
bridge: async callback managed in bridge_constructor + misc
Goffi <goffi@goffi.org>
parents:
320
diff
changeset
|
120 return self.db_comm_iface.setMicroblogAccess(access, profile_key, reply_handler=callback, error_handler=errback) |
304 | 121 |