Mercurial > libervia-backend
comparison sat_bridge/DBus.py @ 66:8147b4f40809
SàT: multi-profile: DBus signals and frontend adaptation (first draft)
- Quick App: new single_profile parameter in __init__ (default: yes), used to tell if the application use only one profile at the time or not
- Quick App: new __check_profile method, tell if the profile is used by the current frontend
- Quick App: new methods plug_profile, unplug_profile and clear_profile, must be called by the frontend to tell which profiles to use
- DBus Bridge: new methods getProfileName, getProfilesList and createProfile
author | Goffi <goffi@goffi.org> |
---|---|
date | Wed, 03 Feb 2010 23:35:57 +1100 |
parents | d35c5edab53f |
children | 0e50dd3a234a |
comparison
equal
deleted
inserted
replaced
65:d35c5edab53f | 66:8147b4f40809 |
---|---|
42 self.cb[name]=cb | 42 self.cb[name]=cb |
43 | 43 |
44 ### signals ### | 44 ### signals ### |
45 | 45 |
46 @dbus.service.signal(const_INT_PREFIX+const_COMM_SUFFIX, | 46 @dbus.service.signal(const_INT_PREFIX+const_COMM_SUFFIX, |
47 signature='') | 47 signature='s') |
48 def connected(self): | 48 def connected(self, profile): |
49 debug("Connected signal") | 49 debug("Connected signal") |
50 | 50 |
51 @dbus.service.signal(const_INT_PREFIX+const_COMM_SUFFIX, | 51 @dbus.service.signal(const_INT_PREFIX+const_COMM_SUFFIX, |
52 signature='') | 52 signature='s') |
53 def disconnected(self): | 53 def disconnected(self, profile): |
54 debug("Disconnected signal") | 54 debug("Disconnected signal") |
55 | 55 |
56 @dbus.service.signal(const_INT_PREFIX+const_COMM_SUFFIX, | 56 @dbus.service.signal(const_INT_PREFIX+const_COMM_SUFFIX, |
57 signature='sa{ss}as') | 57 signature='sa{ss}ass') |
58 def newContact(self, contact, attributes, groups): | 58 def newContact(self, contact, attributes, groups, profile): |
59 debug("new contact signal (%s) sended", contact) | 59 debug("new contact signal (%s) sended (profile: %s)", contact, profile) |
60 | 60 |
61 @dbus.service.signal(const_INT_PREFIX+const_COMM_SUFFIX, | 61 @dbus.service.signal(const_INT_PREFIX+const_COMM_SUFFIX, |
62 signature='ssss') | 62 signature='sssss') |
63 def newMessage(self, from_jid, msg, type='chat', to=''): | 63 def newMessage(self, from_jid, msg, type='chat', to='', profile='@NONE@'): |
64 debug("new message signal (from:%s msg:%s type:%s to:%s) sended", from_jid, msg, type, to) | 64 debug("new message signal (from:%s msg:%s type:%s to:%s) sended", from_jid, msg, type, to) |
65 | 65 |
66 @dbus.service.signal(const_INT_PREFIX+const_COMM_SUFFIX, | 66 @dbus.service.signal(const_INT_PREFIX+const_COMM_SUFFIX, |
67 signature='ssia{ss}') | 67 signature='ssia{ss}s') |
68 def presenceUpdate(self, entity, show, priority, statuses): | 68 def presenceUpdate(self, entity, show, priority, statuses, profile): |
69 debug("presence update signal (from:%s show:%s priority:%d statuses:%s) sended" , entity, show, priority, statuses) | 69 debug("presence update signal (from:%s show:%s priority:%d statuses:%s profile:%s) sended" , entity, show, priority, statuses, profile) |
70 | |
71 @dbus.service.signal(const_INT_PREFIX+const_COMM_SUFFIX, | |
72 signature='sss') | |
73 def subscribe(self, type, entity, profile): | |
74 debug("subscribe (type: [%s] from:[%s] profile:[%s])" , type, entity, profile) | |
75 | |
76 @dbus.service.signal(const_INT_PREFIX+const_COMM_SUFFIX, | |
77 signature='ssss') | |
78 def paramUpdate(self, name, value, category, profile): | |
79 debug("param update signal: %s=%s in category %s (profile: %s)", name, value, category, profile) | |
70 | 80 |
71 @dbus.service.signal(const_INT_PREFIX+const_COMM_SUFFIX, | 81 @dbus.service.signal(const_INT_PREFIX+const_COMM_SUFFIX, |
72 signature='ss') | 82 signature='ss') |
73 def subscribe(self, type, entity): | 83 def contactDeleted(self, entity, profile): |
74 debug("subscribe (type: [%s] from:[%s])" , type, entity) | 84 debug("contact deleted signal: %s (profile: %s)", entity, profile) |
75 | |
76 @dbus.service.signal(const_INT_PREFIX+const_COMM_SUFFIX, | |
77 signature='sss') | |
78 def paramUpdate(self, name, value, category): | |
79 debug("param update signal: %s=%s in category %s", name, value, category) | |
80 | |
81 @dbus.service.signal(const_INT_PREFIX+const_COMM_SUFFIX, | |
82 signature='s') | |
83 def contactDeleted(self, entity): | |
84 debug("contact deleted signal: %s", entity) | |
85 | 85 |
86 @dbus.service.signal(const_INT_PREFIX+const_REQ_SUFFIX, | 86 @dbus.service.signal(const_INT_PREFIX+const_REQ_SUFFIX, |
87 signature='ssa{ss}') | 87 signature='ssa{ss}') |
88 def askConfirmation(self, type, id, data): | 88 def askConfirmation(self, type, id, data): |
89 debug("asking for confirmation: id = [%s] type = %s data = %s", id, type, data) | 89 debug("asking for confirmation: id = [%s] type = %s data = %s", id, type, data) |
104 debug("updated value: %s = %s", name, value) | 104 debug("updated value: %s = %s", name, value) |
105 | 105 |
106 ### methods ### | 106 ### methods ### |
107 | 107 |
108 @dbus.service.method(const_INT_PREFIX+const_REQ_SUFFIX, | 108 @dbus.service.method(const_INT_PREFIX+const_REQ_SUFFIX, |
109 in_signature='s', out_signature='s') | |
110 def getProfileName(self, profile_key): | |
111 return self.cb["getProfileName"](profile_key) | |
112 | |
113 @dbus.service.method(const_INT_PREFIX+const_REQ_SUFFIX, | |
109 in_signature='', out_signature='as') | 114 in_signature='', out_signature='as') |
110 def getProfilesList(self): | 115 def getProfilesList(self): |
111 info ('Profile list asked') | 116 info ('Profile list asked') |
112 return self.cb["getProfilesList"]() | 117 return self.cb["getProfilesList"]() |
113 | 118 |
114 @dbus.service.method(const_INT_PREFIX+const_REQ_SUFFIX, | 119 @dbus.service.method(const_INT_PREFIX+const_REQ_SUFFIX, |
115 in_signature='sb', out_signature='') | 120 in_signature='s', out_signature='') |
116 def createProfile(self, name, default=False): | 121 def createProfile(self, name): |
117 info ('Profile creation asked') | 122 info ('Profile creation asked') |
118 return self.cb["createProfile"](name, default) | 123 return self.cb["createProfile"](name, default) |
119 | 124 |
120 @dbus.service.method(const_INT_PREFIX+const_COMM_SUFFIX, | 125 @dbus.service.method(const_INT_PREFIX+const_COMM_SUFFIX, |
121 in_signature='sssi', out_signature='s') | 126 in_signature='sssi', out_signature='s') |
277 info ("Init DBus...") | 282 info ("Init DBus...") |
278 self.session_bus = dbus.SessionBus() | 283 self.session_bus = dbus.SessionBus() |
279 self.dbus_name = dbus.service.BusName(const_INT_PREFIX, self.session_bus) | 284 self.dbus_name = dbus.service.BusName(const_INT_PREFIX, self.session_bus) |
280 self.dbus_bridge = DbusObject(self.session_bus, '/org/goffi/SAT/bridge') | 285 self.dbus_bridge = DbusObject(self.session_bus, '/org/goffi/SAT/bridge') |
281 | 286 |
282 def connected(self): | 287 def connected(self, profile): |
283 self.dbus_bridge.connected() | 288 self.dbus_bridge.connected(profile) |
284 | 289 |
285 def disconnected(self): | 290 def disconnected(self, profile): |
286 self.dbus_bridge.disconnected() | 291 self.dbus_bridge.disconnected(profile) |
287 | 292 |
288 def newContact(self, contact, attributes, groups): | 293 def newContact(self, contact, attributes, groups, profile): |
289 self.dbus_bridge.newContact(contact, attributes, groups) | 294 self.dbus_bridge.newContact(contact, attributes, groups, profile) |
290 | 295 |
291 def newMessage(self,from_jid,msg,type='chat', to=''): | 296 def newMessage(self,from_jid, msg, type, to, profile): |
292 debug("sending message...") | 297 debug("sending message...") |
293 self.dbus_bridge.newMessage(from_jid, msg, type, to) | 298 self.dbus_bridge.newMessage(from_jid, msg, type, to, profile) |
294 | 299 |
295 def presenceUpdate(self, entity, show, priority, statuses): | 300 def presenceUpdate(self, entity, show, priority, statuses, profile): |
296 debug("updating presence for %s",entity) | 301 debug("updating presence for %s",entity) |
297 self.dbus_bridge.presenceUpdate(entity, show, priority, statuses) | 302 self.dbus_bridge.presenceUpdate(entity, show, priority, statuses, profile) |
298 | 303 |
299 def subscribe(self, type, entity): | 304 def subscribe(self, type, entity, profile): |
300 debug("subscribe request for %s",entity) | 305 debug("subscribe request for %s",entity) |
301 self.dbus_bridge.subscribe(type, entity) | 306 self.dbus_bridge.subscribe(type, entity, profile) |
302 | 307 |
303 def paramUpdate(self, name, value, category): | 308 def paramUpdate(self, name, value, category, profile): |
304 debug("updating param [%s] %s ", category, name) | 309 debug("updating param [%s] %s ", category, name) |
305 self.dbus_bridge.paramUpdate(name, value, category) | 310 self.dbus_bridge.paramUpdate(name, value, category, profile) |
306 | 311 |
307 def contactDeleted(self, entity): | 312 def contactDeleted(self, entity, profile): |
308 debug("sending contact deleted signal %s ", entity) | 313 debug("sending contact deleted signal %s ", entity) |
309 self.dbus_bridge.contactDeleted(entity) | 314 self.dbus_bridge.contactDeleted(entity, profile) |
310 | 315 |
311 def askConfirmation(self, type, id, data): | 316 def askConfirmation(self, type, id, data): |
312 self.dbus_bridge.askConfirmation(type, id, data) | 317 self.dbus_bridge.askConfirmation(type, id, data) |
313 | 318 |
314 def actionResult(self, type, id, data): | 319 def actionResult(self, type, id, data): |
319 | 324 |
320 def updatedValue(self, name, value): | 325 def updatedValue(self, name, value): |
321 self.dbus_bridge.updatedValue(name, value) | 326 self.dbus_bridge.updatedValue(name, value) |
322 | 327 |
323 def register(self, name, callback): | 328 def register(self, name, callback): |
324 debug("registering DBus bridge method [%s]",name) | 329 debug("registering DBus bridge method [%s]", name) |
325 self.dbus_bridge.register(name, callback) | 330 self.dbus_bridge.register(name, callback) |
326 | 331 |
327 def addMethod(self, name, int_suffix, in_sign, out_sign, method): | 332 def addMethod(self, name, int_suffix, in_sign, out_sign, method): |
328 """Dynamically add a method to Dbus Bridge""" | 333 """Dynamically add a method to Dbus Bridge""" |
329 print ("Adding method [%s] to DBus bridge" % name) | 334 print ("Adding method [%s] to DBus bridge" % name) |