annotate src/bridge/bridge_constructor/dbus_frontend_template.py @ 363:54c77a56b22f

bridge: bridge_constuctor's frontend template update with quiz answer method
author Goffi <goffi@goffi.org>
date Sun, 12 Jun 2011 23:43:36 +0200
parents 141eeb7cd9e6
children 3ea41a199b36
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
267
bdcd535e179e Bridge constructor:
Goffi <goffi@goffi.org>
parents:
diff changeset
1 #!/usr/bin/python
bdcd535e179e Bridge constructor:
Goffi <goffi@goffi.org>
parents:
diff changeset
2 #-*- coding: utf-8 -*-
bdcd535e179e Bridge constructor:
Goffi <goffi@goffi.org>
parents:
diff changeset
3
bdcd535e179e Bridge constructor:
Goffi <goffi@goffi.org>
parents:
diff changeset
4 """
bdcd535e179e Bridge constructor:
Goffi <goffi@goffi.org>
parents:
diff changeset
5 SAT communication bridge
bdcd535e179e Bridge constructor:
Goffi <goffi@goffi.org>
parents:
diff changeset
6 Copyright (C) 2009, 2010, 2011 Jérôme Poisson (goffi@goffi.org)
bdcd535e179e Bridge constructor:
Goffi <goffi@goffi.org>
parents:
diff changeset
7
bdcd535e179e Bridge constructor:
Goffi <goffi@goffi.org>
parents:
diff changeset
8 This program is free software: you can redistribute it and/or modify
bdcd535e179e Bridge constructor:
Goffi <goffi@goffi.org>
parents:
diff changeset
9 it under the terms of the GNU General Public License as published by
bdcd535e179e Bridge constructor:
Goffi <goffi@goffi.org>
parents:
diff changeset
10 the Free Software Foundation, either version 3 of the License, or
bdcd535e179e Bridge constructor:
Goffi <goffi@goffi.org>
parents:
diff changeset
11 (at your option) any later version.
bdcd535e179e Bridge constructor:
Goffi <goffi@goffi.org>
parents:
diff changeset
12
bdcd535e179e Bridge constructor:
Goffi <goffi@goffi.org>
parents:
diff changeset
13 This program is distributed in the hope that it will be useful,
bdcd535e179e Bridge constructor:
Goffi <goffi@goffi.org>
parents:
diff changeset
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
bdcd535e179e Bridge constructor:
Goffi <goffi@goffi.org>
parents:
diff changeset
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
bdcd535e179e Bridge constructor:
Goffi <goffi@goffi.org>
parents:
diff changeset
16 GNU General Public License for more details.
bdcd535e179e Bridge constructor:
Goffi <goffi@goffi.org>
parents:
diff changeset
17
bdcd535e179e Bridge constructor:
Goffi <goffi@goffi.org>
parents:
diff changeset
18 You should have received a copy of the GNU General Public License
bdcd535e179e Bridge constructor:
Goffi <goffi@goffi.org>
parents:
diff changeset
19 along with this program. If not, see <http://www.gnu.org/licenses/>.
bdcd535e179e Bridge constructor:
Goffi <goffi@goffi.org>
parents:
diff changeset
20 """
bdcd535e179e Bridge constructor:
Goffi <goffi@goffi.org>
parents:
diff changeset
21
bdcd535e179e Bridge constructor:
Goffi <goffi@goffi.org>
parents:
diff changeset
22 from bridge_frontend import BridgeFrontend
bdcd535e179e Bridge constructor:
Goffi <goffi@goffi.org>
parents:
diff changeset
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
bdcd535e179e Bridge constructor:
Goffi <goffi@goffi.org>
parents:
diff changeset
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
bdcd535e179e Bridge constructor:
Goffi <goffi@goffi.org>
parents:
diff changeset
31 class BridgeExceptionNoService(Exception):
bdcd535e179e Bridge constructor:
Goffi <goffi@goffi.org>
parents:
diff changeset
32 pass
bdcd535e179e Bridge constructor:
Goffi <goffi@goffi.org>
parents:
diff changeset
33
bdcd535e179e Bridge constructor:
Goffi <goffi@goffi.org>
parents:
diff changeset
34 class DBusBridgeFrontend(BridgeFrontend):
bdcd535e179e Bridge constructor:
Goffi <goffi@goffi.org>
parents:
diff changeset
35 def __init__(self):
bdcd535e179e Bridge constructor:
Goffi <goffi@goffi.org>
parents:
diff changeset
36 try:
bdcd535e179e Bridge constructor:
Goffi <goffi@goffi.org>
parents:
diff changeset
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
bdcd535e179e Bridge constructor:
Goffi <goffi@goffi.org>
parents:
diff changeset
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
bdcd535e179e Bridge constructor:
Goffi <goffi@goffi.org>
parents:
diff changeset
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
bdcd535e179e Bridge constructor:
Goffi <goffi@goffi.org>
parents:
diff changeset
44 except dbus.exceptions.DBusException,e:
bdcd535e179e Bridge constructor:
Goffi <goffi@goffi.org>
parents:
diff changeset
45 if e._dbus_error_name=='org.freedesktop.DBus.Error.ServiceUnknown':
bdcd535e179e Bridge constructor:
Goffi <goffi@goffi.org>
parents:
diff changeset
46 raise BridgeExceptionNoService
bdcd535e179e Bridge constructor:
Goffi <goffi@goffi.org>
parents:
diff changeset
47 else:
bdcd535e179e Bridge constructor:
Goffi <goffi@goffi.org>
parents:
diff changeset
48 raise e
bdcd535e179e Bridge constructor:
Goffi <goffi@goffi.org>
parents:
diff changeset
49 #props = self.db_comm_iface.getProperties()
bdcd535e179e Bridge constructor:
Goffi <goffi@goffi.org>
parents:
diff changeset
50
bdcd535e179e Bridge constructor:
Goffi <goffi@goffi.org>
parents:
diff changeset
51 def register(self, functionName, handler, iface="communication"):
bdcd535e179e Bridge constructor:
Goffi <goffi@goffi.org>
parents:
diff changeset
52 if iface == "communication":
bdcd535e179e Bridge constructor:
Goffi <goffi@goffi.org>
parents:
diff changeset
53 self.db_comm_iface.connect_to_signal(functionName, handler)
bdcd535e179e Bridge constructor:
Goffi <goffi@goffi.org>
parents:
diff changeset
54 elif iface == "request":
bdcd535e179e Bridge constructor:
Goffi <goffi@goffi.org>
parents:
diff changeset
55 self.db_req_iface.connect_to_signal(functionName, handler)
bdcd535e179e Bridge constructor:
Goffi <goffi@goffi.org>
parents:
diff changeset
56
bdcd535e179e Bridge constructor:
Goffi <goffi@goffi.org>
parents:
diff changeset
57 ##METHODS_PART##
bdcd535e179e Bridge constructor:
Goffi <goffi@goffi.org>
parents:
diff changeset
58
bdcd535e179e Bridge constructor:
Goffi <goffi@goffi.org>
parents:
diff changeset
59 #methods from plugins
bdcd535e179e Bridge constructor:
Goffi <goffi@goffi.org>
parents:
diff changeset
60 def getRoomJoined(self, profile_key='@DEFAULT@'):
bdcd535e179e Bridge constructor:
Goffi <goffi@goffi.org>
parents:
diff changeset
61 return self.db_comm_iface.getRoomJoined(profile_key)
bdcd535e179e Bridge constructor:
Goffi <goffi@goffi.org>
parents:
diff changeset
62
bdcd535e179e Bridge constructor:
Goffi <goffi@goffi.org>
parents:
diff changeset
63 def getRoomSubjects(self, profile_key='@DEFAULT@'):
bdcd535e179e Bridge constructor:
Goffi <goffi@goffi.org>
parents:
diff changeset
64 return self.db_comm_iface.getRoomSubjects(profile_key)
bdcd535e179e Bridge constructor:
Goffi <goffi@goffi.org>
parents:
diff changeset
65
bdcd535e179e Bridge constructor:
Goffi <goffi@goffi.org>
parents:
diff changeset
66 def joinMUC(self, service, roomId, nick, profile_key='@DEFAULT@'):
bdcd535e179e Bridge constructor:
Goffi <goffi@goffi.org>
parents:
diff changeset
67 return self.db_comm_iface.joinMUC(service, roomId, nick, profile_key)
bdcd535e179e Bridge constructor:
Goffi <goffi@goffi.org>
parents:
diff changeset
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
bdcd535e179e Bridge constructor:
Goffi <goffi@goffi.org>
parents:
diff changeset
72 def tarotGameCreate(self, room_jid, players, profile_key='@DEFAULT@'):
bdcd535e179e Bridge constructor:
Goffi <goffi@goffi.org>
parents:
diff changeset
73 return self.db_comm_iface.tarotGameCreate(room_jid, players, profile_key)
bdcd535e179e Bridge constructor:
Goffi <goffi@goffi.org>
parents:
diff changeset
74
bdcd535e179e Bridge constructor:
Goffi <goffi@goffi.org>
parents:
diff changeset
75 def tarotGameReady(self, player, referee, profile_key='@DEFAULT@'):
bdcd535e179e Bridge constructor:
Goffi <goffi@goffi.org>
parents:
diff changeset
76 return self.db_comm_iface.tarotGameReady(player, referee, profile_key)
bdcd535e179e Bridge constructor:
Goffi <goffi@goffi.org>
parents:
diff changeset
77
bdcd535e179e Bridge constructor:
Goffi <goffi@goffi.org>
parents:
diff changeset
78 def tarotGameContratChoosed(self, player, referee, contrat, profile_key='@DEFAULT@'):
bdcd535e179e Bridge constructor:
Goffi <goffi@goffi.org>
parents:
diff changeset
79 return self.db_comm_iface.tarotGameContratChoosed(player, referee, contrat, profile_key)
bdcd535e179e Bridge constructor:
Goffi <goffi@goffi.org>
parents:
diff changeset
80
bdcd535e179e Bridge constructor:
Goffi <goffi@goffi.org>
parents:
diff changeset
81 def tarotGamePlayCards(self, player, referee, cards, profile_key='@DEFAULT@'):
bdcd535e179e Bridge constructor:
Goffi <goffi@goffi.org>
parents:
diff changeset
82 return self.db_comm_iface.tarotGamePlayCards(player, referee, cards, profile_key)
bdcd535e179e Bridge constructor:
Goffi <goffi@goffi.org>
parents:
diff changeset
83
361
141eeb7cd9e6 Quizz game: first draft
Goffi <goffi@goffi.org>
parents: 359
diff changeset
84 def quizGameLaunch(self, players, profile_key='@DEFAULT@'):
141eeb7cd9e6 Quizz game: first draft
Goffi <goffi@goffi.org>
parents: 359
diff changeset
85 return self.db_comm_iface.quizGameLaunch(players, profile_key)
141eeb7cd9e6 Quizz game: first draft
Goffi <goffi@goffi.org>
parents: 359
diff changeset
86
141eeb7cd9e6 Quizz game: first draft
Goffi <goffi@goffi.org>
parents: 359
diff changeset
87 def quizGameCreate(self, room_jid, players, profile_key='@DEFAULT@'):
141eeb7cd9e6 Quizz game: first draft
Goffi <goffi@goffi.org>
parents: 359
diff changeset
88 return self.db_comm_iface.quizGameCreate(room_jid, players, profile_key)
141eeb7cd9e6 Quizz game: first draft
Goffi <goffi@goffi.org>
parents: 359
diff changeset
89
141eeb7cd9e6 Quizz game: first draft
Goffi <goffi@goffi.org>
parents: 359
diff changeset
90 def quizGameReady(self, player, referee, profile_key='@DEFAULT@'):
141eeb7cd9e6 Quizz game: first draft
Goffi <goffi@goffi.org>
parents: 359
diff changeset
91 return self.db_comm_iface.quizGameReady(player, referee, profile_key)
141eeb7cd9e6 Quizz game: first draft
Goffi <goffi@goffi.org>
parents: 359
diff changeset
92
363
54c77a56b22f bridge: bridge_constuctor's frontend template update with quiz answer method
Goffi <goffi@goffi.org>
parents: 361
diff changeset
93 def quizGameAnswer(self, player, referee, answer, profile_key='@DEFAULT@'):
54c77a56b22f bridge: bridge_constuctor's frontend template update with quiz answer method
Goffi <goffi@goffi.org>
parents: 361
diff changeset
94 return self.db_comm_iface.quizGameAnswer(player, referee, answer, profile_key)
54c77a56b22f bridge: bridge_constuctor's frontend template update with quiz answer method
Goffi <goffi@goffi.org>
parents: 361
diff changeset
95
267
bdcd535e179e Bridge constructor:
Goffi <goffi@goffi.org>
parents:
diff changeset
96 def sendFile(self, to, path, profile_key='@DEFAULT@'):
bdcd535e179e Bridge constructor:
Goffi <goffi@goffi.org>
parents:
diff changeset
97 return self.db_comm_iface.sendFile(to, path, profile_key)
bdcd535e179e Bridge constructor:
Goffi <goffi@goffi.org>
parents:
diff changeset
98
bdcd535e179e Bridge constructor:
Goffi <goffi@goffi.org>
parents:
diff changeset
99 def findGateways(self, target, profile_key='@DEFAULT@'):
bdcd535e179e Bridge constructor:
Goffi <goffi@goffi.org>
parents:
diff changeset
100 return self.db_comm_iface.findGateways(target, profile_key)
bdcd535e179e Bridge constructor:
Goffi <goffi@goffi.org>
parents:
diff changeset
101
bdcd535e179e Bridge constructor:
Goffi <goffi@goffi.org>
parents:
diff changeset
102 def getCard(self, target, profile_key='@DEFAULT@'):
bdcd535e179e Bridge constructor:
Goffi <goffi@goffi.org>
parents:
diff changeset
103 return self.db_comm_iface.getCard(target, profile_key)
bdcd535e179e Bridge constructor:
Goffi <goffi@goffi.org>
parents:
diff changeset
104
bdcd535e179e Bridge constructor:
Goffi <goffi@goffi.org>
parents:
diff changeset
105 def getCardCache(self, target):
bdcd535e179e Bridge constructor:
Goffi <goffi@goffi.org>
parents:
diff changeset
106 return self.db_comm_iface.getCardCache(target)
bdcd535e179e Bridge constructor:
Goffi <goffi@goffi.org>
parents:
diff changeset
107
bdcd535e179e Bridge constructor:
Goffi <goffi@goffi.org>
parents:
diff changeset
108 def getAvatarFile(self, hash):
bdcd535e179e Bridge constructor:
Goffi <goffi@goffi.org>
parents:
diff changeset
109 return self.db_comm_iface.getAvatarFile(hash)
bdcd535e179e Bridge constructor:
Goffi <goffi@goffi.org>
parents:
diff changeset
110
bdcd535e179e Bridge constructor:
Goffi <goffi@goffi.org>
parents:
diff changeset
111 def in_band_register(self, target, profile_key='@DEFAULT@'):
bdcd535e179e Bridge constructor:
Goffi <goffi@goffi.org>
parents:
diff changeset
112 return self.db_comm_iface.in_band_register(target, profile_key)
bdcd535e179e Bridge constructor:
Goffi <goffi@goffi.org>
parents:
diff changeset
113
bdcd535e179e Bridge constructor:
Goffi <goffi@goffi.org>
parents:
diff changeset
114 def gatewayRegister(self, action, target, data, profile_key='@DEFAULT@'):
bdcd535e179e Bridge constructor:
Goffi <goffi@goffi.org>
parents:
diff changeset
115 if data == None:
bdcd535e179e Bridge constructor:
Goffi <goffi@goffi.org>
parents:
diff changeset
116 data = [('', '')] #XXX: we have to do this awful hack because python dbus need to guess the signature
bdcd535e179e Bridge constructor:
Goffi <goffi@goffi.org>
parents:
diff changeset
117 return self.db_req_iface.gatewayRegister(action, target, data, profile_key)
bdcd535e179e Bridge constructor:
Goffi <goffi@goffi.org>
parents:
diff changeset
118
303
2b52a5da0978 plugin XEP_0277: microblog access model can now be changed
Goffi <goffi@goffi.org>
parents: 272
diff changeset
119 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
120 return self.db_comm_iface.getLastMicroblogs(jid, max_items, profile_key, reply_handler=callback, error_handler=errback)
267
bdcd535e179e Bridge constructor:
Goffi <goffi@goffi.org>
parents:
diff changeset
121
307
1e4575e12581 Group blog first draft
Goffi <goffi@goffi.org>
parents: 304
diff changeset
122 def getMblogNodes(self, profile_key='@DEFAULT@', callback=None, errback=None):
1e4575e12581 Group blog first draft
Goffi <goffi@goffi.org>
parents: 304
diff changeset
123 return self.db_comm_iface.getMblogNodes(profile_key, reply_handler=callback, error_handler=errback)
1e4575e12581 Group blog first draft
Goffi <goffi@goffi.org>
parents: 304
diff changeset
124
1e4575e12581 Group blog first draft
Goffi <goffi@goffi.org>
parents: 304
diff changeset
125 def sendGroupBlog(self, groups, message, profile_key='@DEFAULT@'):
1e4575e12581 Group blog first draft
Goffi <goffi@goffi.org>
parents: 304
diff changeset
126 return self.db_comm_iface.sendGroupBlog(groups, message, profile_key)
1e4575e12581 Group blog first draft
Goffi <goffi@goffi.org>
parents: 304
diff changeset
127
304
e04ccf122bb6 microblog sending
Goffi <goffi@goffi.org>
parents: 303
diff changeset
128 def sendPersonalEvent(self, event_type, data, profile_key='@DEFAULT@'):
e04ccf122bb6 microblog sending
Goffi <goffi@goffi.org>
parents: 303
diff changeset
129 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
130
4402ac630712 bridge: async callback managed in bridge_constructor + misc
Goffi <goffi@goffi.org>
parents: 320
diff changeset
131 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
132 return self.db_comm_iface.setMicroblogAccess(access, profile_key, reply_handler=callback, error_handler=errback)
304
e04ccf122bb6 microblog sending
Goffi <goffi@goffi.org>
parents: 303
diff changeset
133