Mercurial > libervia-web
annotate libervia.tac @ 36:1d406077b49b
Tarot Game: first draft
author | Goffi <goffi@goffi.org> |
---|---|
date | Tue, 17 May 2011 01:33:12 +0200 |
parents | d43d6e4b9dc8 |
children | b306aa090438 |
rev | line source |
---|---|
0 | 1 #!/usr/bin/python |
2 # -*- coding: utf-8 -*- | |
3 | |
4 """ | |
5 Libervia: a Salut à Toi frontend | |
6 Copyright (C) 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 Affero 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 Affero General Public License for more details. | |
17 | |
18 You should have received a copy of the GNU Affero General Public License | |
19 along with this program. If not, see <http://www.gnu.org/licenses/>. | |
20 """ | |
21 | |
22 from twisted.application import internet, service | |
23 from twisted.internet import glib2reactor | |
24 glib2reactor.install() | |
25 from twisted.internet import reactor, defer | |
26 | |
27 from twisted.web import server | |
28 from twisted.web import error as weberror | |
29 from twisted.web.static import File | |
30 from twisted.web.resource import Resource | |
10 | 31 from twisted.words.protocols.jabber.jid import JID |
0 | 32 from txjsonrpc.web import jsonrpc |
33 from txjsonrpc import jsonrpclib | |
34 from sat_frontends.bridge.DBus import DBusBridgeFrontend,BridgeExceptionNoService | |
14
9bf8ed012adc
- Group microblog management, first draft
Goffi <goffi@goffi.org>
parents:
11
diff
changeset
|
35 import re |
36 | 36 import glob |
37 import os.path | |
10 | 38 from server_side.blog import MicroBlog |
39 | |
0 | 40 TIMEOUT = 120 #Session's time out, after that the user will be disconnected |
36 | 41 LIBERVIA_DIR = "output/" |
42 CARDS_DIR = "cards/" | |
0 | 43 |
44 class MethodHandler(jsonrpc.JSONRPC): | |
45 | |
46 def __init__(self, sat_host): | |
47 jsonrpc.JSONRPC.__init__(self) | |
48 self.sat_host=sat_host | |
49 | |
50 def render(self, request): | |
1 | 51 self.session = request.getSession() |
0 | 52 try: |
1 | 53 profile = self.session.sat_profile |
0 | 54 except AttributeError: |
55 #user is not identified, we return a jsonrpc fault | |
56 parsed = jsonrpclib.loads(request.content.read()) | |
57 fault = jsonrpclib.Fault(0, "Not allowed") #FIXME: define some standard error codes for libervia | |
58 return jsonrpc.JSONRPC._cbRender(self, fault, request, parsed.get('id'), parsed.get('jsonrpc')) | |
59 return jsonrpc.JSONRPC.render(self, request) | |
19 | 60 |
61 def jsonrpc_getProfileJid(self): | |
62 """Return the jid of the profile""" | |
63 profile = self.session.sat_profile | |
64 self.session.sat_jid = self.sat_host.bridge.getParamA("JabberID", "Connection", profile_key=profile) | |
65 return self.session.sat_jid | |
0 | 66 |
67 def jsonrpc_getContacts(self): | |
68 """Return all passed args.""" | |
1 | 69 profile = self.session.sat_profile |
70 return self.sat_host.bridge.getContacts(profile) | |
20 | 71 |
72 def jsonrpc_setStatus(self, status): | |
73 """Change the status""" | |
74 profile = self.session.sat_profile | |
75 print "new status received:", status | |
76 self.sat_host.bridge.setPresence('', '', 0, {'':status}, profile) | |
77 | |
19 | 78 |
79 def jsonrpc_sendMessage(self, to_jid, msg, subject, type): | |
80 """send message""" | |
81 profile = self.session.sat_profile | |
82 return self.sat_host.bridge.sendMessage(to_jid, msg, subject, type, profile) | |
0 | 83 |
11
331c093e4eb3
magicBox is now able to send global microblog
Goffi <goffi@goffi.org>
parents:
10
diff
changeset
|
84 def jsonrpc_sendMblog(self, raw_text): |
331c093e4eb3
magicBox is now able to send global microblog
Goffi <goffi@goffi.org>
parents:
10
diff
changeset
|
85 """Parse raw_text of the microblog box, and send message consequently""" |
331c093e4eb3
magicBox is now able to send global microblog
Goffi <goffi@goffi.org>
parents:
10
diff
changeset
|
86 profile = self.session.sat_profile |
14
9bf8ed012adc
- Group microblog management, first draft
Goffi <goffi@goffi.org>
parents:
11
diff
changeset
|
87 match = re.match(r'@(.+?): *(.*$)', raw_text) |
9bf8ed012adc
- Group microblog management, first draft
Goffi <goffi@goffi.org>
parents:
11
diff
changeset
|
88 if match: |
9bf8ed012adc
- Group microblog management, first draft
Goffi <goffi@goffi.org>
parents:
11
diff
changeset
|
89 recip = match.group(1) |
9bf8ed012adc
- Group microblog management, first draft
Goffi <goffi@goffi.org>
parents:
11
diff
changeset
|
90 text = match.group(2) |
9bf8ed012adc
- Group microblog management, first draft
Goffi <goffi@goffi.org>
parents:
11
diff
changeset
|
91 if recip == '@' and text: |
9bf8ed012adc
- Group microblog management, first draft
Goffi <goffi@goffi.org>
parents:
11
diff
changeset
|
92 #This text if for the public microblog |
9bf8ed012adc
- Group microblog management, first draft
Goffi <goffi@goffi.org>
parents:
11
diff
changeset
|
93 print "Sending message to everybody" |
11
331c093e4eb3
magicBox is now able to send global microblog
Goffi <goffi@goffi.org>
parents:
10
diff
changeset
|
94 return self.sat_host.bridge.sendPersonalEvent("MICROBLOG", {'content':text}, profile) |
14
9bf8ed012adc
- Group microblog management, first draft
Goffi <goffi@goffi.org>
parents:
11
diff
changeset
|
95 else: |
9bf8ed012adc
- Group microblog management, first draft
Goffi <goffi@goffi.org>
parents:
11
diff
changeset
|
96 return self.sat_host.bridge.sendGroupBlog([recip], text, profile) |
9bf8ed012adc
- Group microblog management, first draft
Goffi <goffi@goffi.org>
parents:
11
diff
changeset
|
97 |
20 | 98 def jsonrpc_getPresenceStatus(self): |
99 """Get Presence information for connected contacts""" | |
100 profile = self.session.sat_profile | |
101 return self.sat_host.bridge.getPresenceStatus(profile) | |
102 | |
19 | 103 def jsonrpc_getHistory(self, from_jid, to_jid, size): |
104 """Return history for the from_jid/to_jid couple""" | |
105 #FIXME: this method should definitely be asynchrone, need to fix it !!! | |
106 profile = self.session.sat_profile | |
107 try: | |
108 _jid = JID(self.session.sat_jid) | |
109 except: | |
110 error("No jid saved for this profile") | |
111 return {} | |
112 if JID(from_jid).userhost() != _jid.userhost() and JID(to_jid) != _jid.userhost(): | |
113 error("Trying to get history from a different jid, maybe a hack attempt ?") | |
114 return {} | |
24 | 115 return self.sat_host.bridge.getHistory(from_jid, to_jid, size) |
19 | 116 |
30
7684e3ceb12d
server_side: added getRoomJoined method
Goffi <goffi@goffi.org>
parents:
24
diff
changeset
|
117 def jsonrpc_getRoomJoined(self): |
7684e3ceb12d
server_side: added getRoomJoined method
Goffi <goffi@goffi.org>
parents:
24
diff
changeset
|
118 """Return list of room already joined by user""" |
7684e3ceb12d
server_side: added getRoomJoined method
Goffi <goffi@goffi.org>
parents:
24
diff
changeset
|
119 profile = self.session.sat_profile |
7684e3ceb12d
server_side: added getRoomJoined method
Goffi <goffi@goffi.org>
parents:
24
diff
changeset
|
120 return self.sat_host.bridge.getRoomJoined(profile) |
7684e3ceb12d
server_side: added getRoomJoined method
Goffi <goffi@goffi.org>
parents:
24
diff
changeset
|
121 |
24 | 122 def jsonrpc_launchTarotGame(self, other_players): |
123 """Create a room, invite the other players and start a Tarot game""" | |
124 profile = self.session.sat_profile | |
125 self.sat_host.bridge.tarotGameLaunch(other_players, profile) | |
11
331c093e4eb3
magicBox is now able to send global microblog
Goffi <goffi@goffi.org>
parents:
10
diff
changeset
|
126 |
36 | 127 def jsonrpc_getTarotCardsPaths(self): |
128 """Give the path of all the tarot cards""" | |
129 return map(lambda x: x[len(LIBERVIA_DIR):],glob.glob(os.path.join(LIBERVIA_DIR,CARDS_DIR,'*_*.png'))); | |
130 | |
131 | |
132 | |
0 | 133 class Register(jsonrpc.JSONRPC): |
134 """This class manage the registration procedure with SàT | |
135 It provide an api for the browser, check password and setup the web server""" | |
136 | |
137 def __init__(self, sat_host): | |
138 jsonrpc.JSONRPC.__init__(self) | |
139 self.sat_host=sat_host | |
140 self.profiles_waiting={} | |
141 self.request=None | |
142 | |
143 def getWaitingRequest(self, profile): | |
144 """Tell if a profile is trying to log in""" | |
145 if self.profiles_waiting.has_key(profile): | |
146 return self.profiles_waiting[profile] | |
147 else: | |
148 return None | |
149 | |
14
9bf8ed012adc
- Group microblog management, first draft
Goffi <goffi@goffi.org>
parents:
11
diff
changeset
|
150 def _fillMblogNodes(self, result, session): |
9bf8ed012adc
- Group microblog management, first draft
Goffi <goffi@goffi.org>
parents:
11
diff
changeset
|
151 """Fill the microblog nodes association for this session""" |
9bf8ed012adc
- Group microblog management, first draft
Goffi <goffi@goffi.org>
parents:
11
diff
changeset
|
152 print "Filling session for %s with %s" % (session.sat_profile, result) |
9bf8ed012adc
- Group microblog management, first draft
Goffi <goffi@goffi.org>
parents:
11
diff
changeset
|
153 session.sat_mblog_nodes = dict(result) |
9bf8ed012adc
- Group microblog management, first draft
Goffi <goffi@goffi.org>
parents:
11
diff
changeset
|
154 |
0 | 155 def render(self, request): |
156 """ | |
157 Render method with some hacks: | |
158 - if login is requested, try to login with form data | |
159 - except login, every method is jsonrpc | |
160 - user doesn't need to be authentified for isRegistered, but must be for all other methods | |
161 """ | |
162 if request.postpath==['login']: | |
163 return self.login(request) | |
164 _session = request.getSession() | |
165 parsed = jsonrpclib.loads(request.content.read()) | |
166 if parsed.get("method")!="isRegistered": | |
167 #if we don't call login or isRegistered, we need to be identified | |
168 try: | |
169 profile = _session.sat_profile | |
170 except AttributeError: | |
171 #user is not identified, we return a jsonrpc fault | |
172 fault = jsonrpclib.Fault(0, "Not allowed") #FIXME: define some standard error codes for libervia | |
173 return jsonrpc.JSONRPC._cbRender(self, fault, request, parsed.get('id'), parsed.get('jsonrpc')) | |
174 self.request = request | |
175 return jsonrpc.JSONRPC.render(self, request) | |
176 | |
177 def login(self, request): | |
178 """ | |
179 this method is called with the POST information from the registering form | |
180 it test if the password is ok, and log in if it's the case, | |
181 else it return an error | |
182 @param request: request of the register formulaire, must have "login" and "password" as arguments | |
183 @return: A constant indicating the state: | |
184 - BAD REQUEST: something is wrong in the request (bad arguments, profile_key for login) | |
185 - AUTH ERROR: either the profile or the password is wrong | |
186 - ALREADY WAITING: a request has already be made for this profile | |
187 - server.NOT_DONE_YET: the profile is being processed, the return value will be given by self._logged or self._logginError | |
188 """ | |
189 try: | |
190 _login = request.args['login'][0] | |
191 if _login.startswith('@'): | |
192 raise Exception('No profile_key allowed') | |
193 _pass = request.args['password'][0] | |
194 except KeyError: | |
195 return "BAD REQUEST" | |
196 | |
197 _profile_check = self.sat_host.bridge.getProfileName(_login) | |
198 _profile_pass = self.sat_host.bridge.getParamA("Password", "Connection", profile_key=_login) | |
199 | |
200 if not _profile_check or _profile_check != _login or _profile_pass != _pass: | |
201 return "AUTH ERROR" | |
202 | |
203 if self.profiles_waiting.has_key(_login): | |
204 return "ALREADY WAITING" | |
205 | |
206 if self.sat_host.bridge.isConnected(_login): | |
14
9bf8ed012adc
- Group microblog management, first draft
Goffi <goffi@goffi.org>
parents:
11
diff
changeset
|
207 return self._logged(_login, request, finish=False) |
0 | 208 |
209 self.profiles_waiting[_login] = request | |
210 self.sat_host.bridge.connect(_login) | |
211 return server.NOT_DONE_YET | |
212 | |
213 def __cleanWaiting(self, login): | |
214 """Remove login from waiting queue""" | |
215 try: | |
216 del self.profiles_waiting[login] | |
217 except KeyError: | |
218 pass | |
219 | |
14
9bf8ed012adc
- Group microblog management, first draft
Goffi <goffi@goffi.org>
parents:
11
diff
changeset
|
220 def _logged(self, profile, request, finish=True): |
0 | 221 """Set everything when a user just logged |
222 and return "LOGGED" to the requester""" | |
14
9bf8ed012adc
- Group microblog management, first draft
Goffi <goffi@goffi.org>
parents:
11
diff
changeset
|
223 self.__cleanWaiting(profile) |
0 | 224 _session = request.getSession() |
14
9bf8ed012adc
- Group microblog management, first draft
Goffi <goffi@goffi.org>
parents:
11
diff
changeset
|
225 _session.sat_profile = profile |
24 | 226 self.sat_host.prof_connected.add(profile) |
14
9bf8ed012adc
- Group microblog management, first draft
Goffi <goffi@goffi.org>
parents:
11
diff
changeset
|
227 d = defer.Deferred() |
9bf8ed012adc
- Group microblog management, first draft
Goffi <goffi@goffi.org>
parents:
11
diff
changeset
|
228 self.sat_host.bridge.getMblogNodes(profile, d.callback, d.errback) |
9bf8ed012adc
- Group microblog management, first draft
Goffi <goffi@goffi.org>
parents:
11
diff
changeset
|
229 d.addCallback(self._fillMblogNodes, _session) |
9bf8ed012adc
- Group microblog management, first draft
Goffi <goffi@goffi.org>
parents:
11
diff
changeset
|
230 if finish: |
9bf8ed012adc
- Group microblog management, first draft
Goffi <goffi@goffi.org>
parents:
11
diff
changeset
|
231 request.write('LOGGED') |
9bf8ed012adc
- Group microblog management, first draft
Goffi <goffi@goffi.org>
parents:
11
diff
changeset
|
232 request.finish() |
9bf8ed012adc
- Group microblog management, first draft
Goffi <goffi@goffi.org>
parents:
11
diff
changeset
|
233 else: |
9bf8ed012adc
- Group microblog management, first draft
Goffi <goffi@goffi.org>
parents:
11
diff
changeset
|
234 return "LOGGED" |
0 | 235 |
236 def _logginError(self, login, request, error_type): | |
237 """Something went wrong during loggin, return an error""" | |
238 self.__cleanWaiting(login) | |
239 return error_type | |
240 | |
241 def jsonrpc_isConnected(self): | |
242 _session = self.request.getSession() | |
243 profile = _session.sat_profile | |
244 return self.sat_host.bridge.isConnected(profile) | |
245 | |
246 def jsonrpc_connect(self): | |
247 _session = self.request.getSession() | |
248 profile = _session.sat_profile | |
249 if self.profiles_waiting.has_key(profile): | |
250 raise jsonrpclib.Fault('1','Already waiting') #FIXME: define some standard error codes for libervia | |
251 self.profiles_waiting[profile] = self.request | |
252 self.sat_host.bridge.connect(profile) | |
253 return server.NOT_DONE_YET | |
254 | |
255 def jsonrpc_isRegistered(self): | |
256 """Tell if the user is already registered""" | |
257 _session = self.request.getSession() | |
258 try: | |
259 profile = _session.sat_profile | |
260 except AttributeError: | |
261 return False | |
262 return True | |
263 | |
264 class SignalHandler(jsonrpc.JSONRPC): | |
265 | |
266 def __init__(self, sat_host): | |
267 Resource.__init__(self) | |
268 self.register=None | |
269 self.sat_host=sat_host | |
3
154d4caa57f4
server side: proper profile management in signals generic callback
Goffi <goffi@goffi.org>
parents:
2
diff
changeset
|
270 self.signalDeferred = {} |
24 | 271 self.queue = {} #XXX: gof: don't forgot to purge queue on session end |
2
669c531a857e
signals handling and first draft of microblogging
Goffi <goffi@goffi.org>
parents:
1
diff
changeset
|
272 |
0 | 273 def plugRegister(self, register): |
274 self.register = register | |
2
669c531a857e
signals handling and first draft of microblogging
Goffi <goffi@goffi.org>
parents:
1
diff
changeset
|
275 |
669c531a857e
signals handling and first draft of microblogging
Goffi <goffi@goffi.org>
parents:
1
diff
changeset
|
276 def jsonrpc_getSignals(self): |
669c531a857e
signals handling and first draft of microblogging
Goffi <goffi@goffi.org>
parents:
1
diff
changeset
|
277 """Keep the connection alive until a signal is received, then send it |
669c531a857e
signals handling and first draft of microblogging
Goffi <goffi@goffi.org>
parents:
1
diff
changeset
|
278 @return: (signal, *signal_args)""" |
3
154d4caa57f4
server side: proper profile management in signals generic callback
Goffi <goffi@goffi.org>
parents:
2
diff
changeset
|
279 _session = self.request.getSession() |
154d4caa57f4
server side: proper profile management in signals generic callback
Goffi <goffi@goffi.org>
parents:
2
diff
changeset
|
280 profile = _session.sat_profile |
24 | 281 if profile in self.queue: #if we have signals to send in queue |
282 if self.queue[profile]: | |
283 return self.queue[profile].pop(0) | |
284 else: | |
285 #the queue is empty, we delete the profile from queue | |
286 del self.queue[profile] | |
3
154d4caa57f4
server side: proper profile management in signals generic callback
Goffi <goffi@goffi.org>
parents:
2
diff
changeset
|
287 self.signalDeferred[profile] = defer.Deferred() |
154d4caa57f4
server side: proper profile management in signals generic callback
Goffi <goffi@goffi.org>
parents:
2
diff
changeset
|
288 return self.signalDeferred[profile] |
2
669c531a857e
signals handling and first draft of microblogging
Goffi <goffi@goffi.org>
parents:
1
diff
changeset
|
289 |
669c531a857e
signals handling and first draft of microblogging
Goffi <goffi@goffi.org>
parents:
1
diff
changeset
|
290 def getGenericCb(self, function_name): |
3
154d4caa57f4
server side: proper profile management in signals generic callback
Goffi <goffi@goffi.org>
parents:
2
diff
changeset
|
291 """Return a generic function which send all params to signalDeferred.callback |
154d4caa57f4
server side: proper profile management in signals generic callback
Goffi <goffi@goffi.org>
parents:
2
diff
changeset
|
292 function must have profile as last argument""" |
2
669c531a857e
signals handling and first draft of microblogging
Goffi <goffi@goffi.org>
parents:
1
diff
changeset
|
293 def genericCb(*args): |
3
154d4caa57f4
server side: proper profile management in signals generic callback
Goffi <goffi@goffi.org>
parents:
2
diff
changeset
|
294 profile = args[-1] |
24 | 295 if not profile in self.sat_host.prof_connected: |
296 return | |
3
154d4caa57f4
server side: proper profile management in signals generic callback
Goffi <goffi@goffi.org>
parents:
2
diff
changeset
|
297 if profile in self.signalDeferred: |
154d4caa57f4
server side: proper profile management in signals generic callback
Goffi <goffi@goffi.org>
parents:
2
diff
changeset
|
298 self.signalDeferred[profile].callback((function_name,args[:-1])) |
24 | 299 del self.signalDeferred[profile] |
2
669c531a857e
signals handling and first draft of microblogging
Goffi <goffi@goffi.org>
parents:
1
diff
changeset
|
300 else: |
24 | 301 if not self.queue.has_key(profile): |
302 self.queue[profile] = [] | |
303 self.queue[profile].append((function_name, args[:-1])) | |
2
669c531a857e
signals handling and first draft of microblogging
Goffi <goffi@goffi.org>
parents:
1
diff
changeset
|
304 return genericCb |
669c531a857e
signals handling and first draft of microblogging
Goffi <goffi@goffi.org>
parents:
1
diff
changeset
|
305 |
0 | 306 def connected(self, profile): |
307 assert(self.register) #register must be plugged | |
308 request = self.register.getWaitingRequest(profile) | |
309 if request: | |
310 self.register._logged(profile, request) | |
311 | |
312 def connectionError(self, error_type, profile): | |
313 assert(self.register) #register must be plugged | |
314 request = self.register.getWaitingRequest(profile) | |
315 if request: #The user is trying to log in | |
316 if error_type == "AUTH_ERROR": | |
317 _error_t = "AUTH ERROR" | |
318 else: | |
319 _error_t = "UNKNOWN" | |
320 self.register._logginError(profile, request, _error_t) | |
321 | |
2
669c531a857e
signals handling and first draft of microblogging
Goffi <goffi@goffi.org>
parents:
1
diff
changeset
|
322 def render(self, request): |
669c531a857e
signals handling and first draft of microblogging
Goffi <goffi@goffi.org>
parents:
1
diff
changeset
|
323 """ |
669c531a857e
signals handling and first draft of microblogging
Goffi <goffi@goffi.org>
parents:
1
diff
changeset
|
324 Render method wich reject access if user is not identified |
669c531a857e
signals handling and first draft of microblogging
Goffi <goffi@goffi.org>
parents:
1
diff
changeset
|
325 """ |
669c531a857e
signals handling and first draft of microblogging
Goffi <goffi@goffi.org>
parents:
1
diff
changeset
|
326 _session = request.getSession() |
669c531a857e
signals handling and first draft of microblogging
Goffi <goffi@goffi.org>
parents:
1
diff
changeset
|
327 parsed = jsonrpclib.loads(request.content.read()) |
669c531a857e
signals handling and first draft of microblogging
Goffi <goffi@goffi.org>
parents:
1
diff
changeset
|
328 try: |
669c531a857e
signals handling and first draft of microblogging
Goffi <goffi@goffi.org>
parents:
1
diff
changeset
|
329 profile = _session.sat_profile |
669c531a857e
signals handling and first draft of microblogging
Goffi <goffi@goffi.org>
parents:
1
diff
changeset
|
330 except AttributeError: |
669c531a857e
signals handling and first draft of microblogging
Goffi <goffi@goffi.org>
parents:
1
diff
changeset
|
331 #user is not identified, we return a jsonrpc fault |
669c531a857e
signals handling and first draft of microblogging
Goffi <goffi@goffi.org>
parents:
1
diff
changeset
|
332 fault = jsonrpclib.Fault(0, "Not allowed") #FIXME: define some standard error codes for libervia |
669c531a857e
signals handling and first draft of microblogging
Goffi <goffi@goffi.org>
parents:
1
diff
changeset
|
333 return jsonrpc.JSONRPC._cbRender(self, fault, request, parsed.get('id'), parsed.get('jsonrpc')) |
669c531a857e
signals handling and first draft of microblogging
Goffi <goffi@goffi.org>
parents:
1
diff
changeset
|
334 self.request = request |
669c531a857e
signals handling and first draft of microblogging
Goffi <goffi@goffi.org>
parents:
1
diff
changeset
|
335 return jsonrpc.JSONRPC.render(self, request) |
0 | 336 |
10 | 337 |
0 | 338 class Libervia(service.Service): |
339 | |
340 def __init__(self): | |
36 | 341 root = File(LIBERVIA_DIR) |
0 | 342 self.signal_handler = SignalHandler(self) |
343 _register = Register(self) | |
344 self.signal_handler.plugRegister(_register) | |
345 self.sessions = {} #key = session value = user | |
24 | 346 self.prof_connected = set() #Profiles connected |
0 | 347 ## bridge ## |
348 try: | |
349 self.bridge=DBusBridgeFrontend() | |
350 except BridgeExceptionNoService: | |
351 print(u"Can't connect to SàT backend, are you sure it's launched ?") | |
352 import sys | |
353 sys.exit(1) | |
354 self.bridge.register("connected", self.signal_handler.connected) | |
355 self.bridge.register("connectionError", self.signal_handler.connectionError) | |
36 | 356 for signal_name in ['presenceUpdate', 'personalEvent', 'newMessage', 'roomJoined', 'roomUserJoined', 'roomUserLeft', 'tarotGameStarted']: |
2
669c531a857e
signals handling and first draft of microblogging
Goffi <goffi@goffi.org>
parents:
1
diff
changeset
|
357 self.bridge.register(signal_name, self.signal_handler.getGenericCb(signal_name)) |
10 | 358 root.putChild('json_signal_api', self.signal_handler) |
359 root.putChild('json_api', MethodHandler(self)) | |
360 root.putChild('register_api', _register) | |
361 root.putChild('blog', MicroBlog(self)) | |
362 root.putChild('css', File("server_css/")) | |
363 self.site = server.Site(root) | |
0 | 364 |
365 def startService(self): | |
366 reactor.listenTCP(8080, self.site) | |
1 | 367 |
0 | 368 def run(self): |
369 reactor.run() | |
370 | |
371 def stop(self): | |
372 reactor.stop() | |
373 | |
374 | |
375 | |
376 application = service.Application('Libervia') | |
377 service = Libervia() | |
378 service.setServiceParent(application) |