Mercurial > libervia-web
comparison libervia.tac @ 2:669c531a857e
signals handling and first draft of microblogging
- server side: signal handling throught json_signal_api page
- browser side: - signal handling throught a json rpc call loop
- first draft of microblog panel
- ContactPanel put in a separate module
author | Goffi <goffi@goffi.org> |
---|---|
date | Tue, 08 Feb 2011 21:18:31 +0100 |
parents | 0a7c685faa53 |
children | 154d4caa57f4 |
comparison
equal
deleted
inserted
replaced
1:0a7c685faa53 | 2:669c531a857e |
---|---|
180 | 180 |
181 def __init__(self, sat_host): | 181 def __init__(self, sat_host): |
182 Resource.__init__(self) | 182 Resource.__init__(self) |
183 self.register=None | 183 self.register=None |
184 self.sat_host=sat_host | 184 self.sat_host=sat_host |
185 | 185 self.signalDeferred = None |
186 | |
186 def plugRegister(self, register): | 187 def plugRegister(self, register): |
187 self.register = register | 188 self.register = register |
188 | 189 |
189 def presenceUpdate(self, entity, show, priority, statuses, profile): | 190 def jsonrpc_getSignals(self): |
190 print "update de",entity | 191 """Keep the connection alive until a signal is received, then send it |
191 | 192 @return: (signal, *signal_args)""" |
193 self.signalDeferred = defer.Deferred() | |
194 return self.signalDeferred | |
195 | |
196 def getGenericCb(self, function_name): | |
197 """Return a generic function which send all params to signalDeferred.callback""" | |
198 def genericCb(*args): | |
199 if self.signalDeferred: | |
200 self.signalDeferred.callback((function_name,args)) | |
201 else: | |
202 print("Warning: signal [%s] can't be sent" % function_name) | |
203 return genericCb | |
204 | |
205 def genericCallback(self, *args): | |
206 """"This method send all params to signalDeferred""" | |
207 if self.signalDeferred: | |
208 print ("Sending signals %s") | |
209 | |
192 def connected(self, profile): | 210 def connected(self, profile): |
193 assert(self.register) #register must be plugged | 211 assert(self.register) #register must be plugged |
194 request = self.register.getWaitingRequest(profile) | 212 request = self.register.getWaitingRequest(profile) |
195 if request: | 213 if request: |
196 self.register._logged(profile, request) | 214 self.register._logged(profile, request) |
203 _error_t = "AUTH ERROR" | 221 _error_t = "AUTH ERROR" |
204 else: | 222 else: |
205 _error_t = "UNKNOWN" | 223 _error_t = "UNKNOWN" |
206 self.register._logginError(profile, request, _error_t) | 224 self.register._logginError(profile, request, _error_t) |
207 | 225 |
226 def render(self, request): | |
227 """ | |
228 Render method wich reject access if user is not identified | |
229 """ | |
230 _session = request.getSession() | |
231 parsed = jsonrpclib.loads(request.content.read()) | |
232 try: | |
233 profile = _session.sat_profile | |
234 except AttributeError: | |
235 #user is not identified, we return a jsonrpc fault | |
236 fault = jsonrpclib.Fault(0, "Not allowed") #FIXME: define some standard error codes for libervia | |
237 return jsonrpc.JSONRPC._cbRender(self, fault, request, parsed.get('id'), parsed.get('jsonrpc')) | |
238 self.request = request | |
239 return jsonrpc.JSONRPC.render(self, request) | |
208 | 240 |
209 class Libervia(service.Service): | 241 class Libervia(service.Service): |
210 | 242 |
211 def __init__(self): | 243 def __init__(self): |
212 root = File("output/") | 244 root = File("output/") |
213 self.signal_handler = SignalHandler(self) | 245 self.signal_handler = SignalHandler(self) |
214 root.putChild('test', self.signal_handler) | 246 root.putChild('json_signal_api', self.signal_handler) |
215 _register = Register(self) | 247 _register = Register(self) |
216 self.signal_handler.plugRegister(_register) | 248 self.signal_handler.plugRegister(_register) |
217 root.putChild('json_api', MethodHandler(self)) | 249 root.putChild('json_api', MethodHandler(self)) |
218 root.putChild('register_api', _register) | 250 root.putChild('register_api', _register) |
219 self.site = server.Site(root) | 251 self.site = server.Site(root) |
223 self.bridge=DBusBridgeFrontend() | 255 self.bridge=DBusBridgeFrontend() |
224 except BridgeExceptionNoService: | 256 except BridgeExceptionNoService: |
225 print(u"Can't connect to SàT backend, are you sure it's launched ?") | 257 print(u"Can't connect to SàT backend, are you sure it's launched ?") |
226 import sys | 258 import sys |
227 sys.exit(1) | 259 sys.exit(1) |
228 self.bridge.register("presenceUpdate", self.signal_handler.presenceUpdate) | |
229 self.bridge.register("connected", self.signal_handler.connected) | 260 self.bridge.register("connected", self.signal_handler.connected) |
230 self.bridge.register("connectionError", self.signal_handler.connectionError) | 261 self.bridge.register("connectionError", self.signal_handler.connectionError) |
262 for signal_name in ['presenceUpdate']: | |
263 self.bridge.register(signal_name, self.signal_handler.getGenericCb(signal_name)) | |
231 | 264 |
232 def startService(self): | 265 def startService(self): |
233 reactor.listenTCP(8080, self.site) | 266 reactor.listenTCP(8080, self.site) |
234 | 267 |
235 def run(self): | 268 def run(self): |