comparison frontends/src/bridge/DBus.py @ 568:239abc5484c9

bridge: generic plugin methods handling for frontend side in D-Bus Bridge \o/
author Goffi <goffi@goffi.org>
date Mon, 07 Jan 2013 01:01:10 +0100
parents 0bb2e0d1c878
children ca13633d3b6b
comparison
equal deleted inserted replaced
567:01569aa4d7aa 568:239abc5484c9
58 elif iface == "plugin": 58 elif iface == "plugin":
59 self.db_plugin_iface.connect_to_signal(functionName, handler) 59 self.db_plugin_iface.connect_to_signal(functionName, handler)
60 else: 60 else:
61 error(_('Unknown interface')) 61 error(_('Unknown interface'))
62 62
63 def __getattribute__(self, name):
64 """ usual __getattribute__ if the method exists, else try to find a plugin method """
65 try:
66 return object.__getattribute__(self, name)
67 except AttributeError:
68 # The attribute is not found, we try the plugin proxy to find the requested method
69
70 def getPluginMethod(*args, **kwargs):
71 # We first check if we have an async call. We detect this in two ways:
72 # - if we have the 'callback' and 'errback' keyword arguments
73 # - or if the last two arguments are callable
74
75 async = False
76
77 if kwargs:
78 if 'callback' in kwargs and 'errback' in kwargs:
79 async = True
80 _callback = kwargs.pop('callback')
81 _errback = kwargs.pop('errback')
82 elif len(args)>=2 and callable(args[-1]) and callable(args[-2]):
83 async = True
84 args = list(args)
85 _errback = args.pop()
86 _callback = args.pop()
87
88 method = getattr(self.db_plugin_iface, name)
89
90 if async:
91 kwargs['reply_handler'] = _callback
92 kwargs['error_handler'] = lambda err:_errback(err._dbus_error_name[len(const_ERROR_PREFIX)+1:])
93
94 return method(*args, **kwargs)
95
96 return getPluginMethod
97
63 def addContact(self, entity_jid, profile_key="@DEFAULT@"): 98 def addContact(self, entity_jid, profile_key="@DEFAULT@"):
64 return self.db_core_iface.addContact(entity_jid, profile_key) 99 return self.db_core_iface.addContact(entity_jid, profile_key)
65 100
66 def asyncConnect(self, profile_key="@DEFAULT@", callback=None, errback=None): 101 def asyncConnect(self, profile_key="@DEFAULT@", callback=None, errback=None):
67 return self.db_core_iface.asyncConnect(profile_key, reply_handler=callback, error_handler=lambda err:errback(err._dbus_error_name[len(const_ERROR_PREFIX)+1:])) 102 return self.db_core_iface.asyncConnect(profile_key, reply_handler=callback, error_handler=lambda err:errback(err._dbus_error_name[len(const_ERROR_PREFIX)+1:]))
177 def updateContact(self, entity_jid, name, groups, profile_key="@DEFAULT@"): 212 def updateContact(self, entity_jid, name, groups, profile_key="@DEFAULT@"):
178 return self.db_core_iface.updateContact(entity_jid, name, groups, profile_key) 213 return self.db_core_iface.updateContact(entity_jid, name, groups, profile_key)
179 214
180 215
181 #methods from plugins 216 #methods from plugins
182 def getRoomsJoined(self, profile_key): 217
183 return self.db_plugin_iface.getRoomsJoined(profile_key)
184
185 def getRoomsSubjects(self, profile_key):
186 return self.db_plugin_iface.getRoomsSubjects(profile_key)
187
188 def joinMUC(self, room_jid, nick, options, profile_key): 218 def joinMUC(self, room_jid, nick, options, profile_key):
189 if options == None: 219 if options == None:
190 options = [('', '')] #XXX: we have to do this awful hack because python dbus need to guess the signature 220 options = [('', '')] #XXX: we have to do this awful hack because python dbus need to guess the signature
191 return self.db_plugin_iface.joinMUC(room_jid, nick, options, profile_key) 221 return self.db_plugin_iface.joinMUC(room_jid, nick, options, profile_key)
192
193 def tarotGameLaunch(self, players, profile_key):
194 return self.db_plugin_iface.tarotGameLaunch(players, profile_key)
195 222
196 def tarotGameCreate(self, room_jid, players, profile_key):
197 return self.db_plugin_iface.tarotGameCreate(room_jid, players, profile_key)
198
199 def tarotGameReady(self, player, referee, profile_key):
200 return self.db_plugin_iface.tarotGameReady(player, referee, profile_key)
201
202 def tarotGameContratChoosed(self, player, referee, contrat, profile_key):
203 return self.db_plugin_iface.tarotGameContratChoosed(player, referee, contrat, profile_key)
204
205 def tarotGamePlayCards(self, player, referee, cards, profile_key):
206 return self.db_plugin_iface.tarotGamePlayCards(player, referee, cards, profile_key)
207
208 def quizGameLaunch(self, players, profile_key):
209 return self.db_plugin_iface.quizGameLaunch(players, profile_key)
210
211 def quizGameCreate(self, room_jid, players, profile_key):
212 return self.db_plugin_iface.quizGameCreate(room_jid, players, profile_key)
213
214 def quizGameReady(self, player, referee, profile_key):
215 return self.db_plugin_iface.quizGameReady(player, referee, profile_key)
216
217 def quizGameAnswer(self, player, referee, answer, profile_key):
218 return self.db_plugin_iface.quizGameAnswer(player, referee, answer, profile_key)
219
220 def radiocolLaunch(self, players, profile_key):
221 return self.db_plugin_iface.radiocolLaunch(players, profile_key)
222
223 def radiocolCreate(self, room_jid, profile_key):
224 return self.db_plugin_iface.radiocolCreate(room_jid, profile_key)
225
226 def radiocolSongAdded(self, room_jid, song_path, profile):
227 return self.db_plugin_iface.radiocolSongAdded(room_jid, song_path, profile)
228
229 def setAvatar(self, avatar_path, profile):
230 return self.db_plugin_iface.setAvatar(avatar_path, profile)
231
232 def sendFile(self, to, path, data, profile_key):
233 return self.db_plugin_iface.sendFile(to, path, data, profile_key)
234
235 def pipeOut(self, to, path, data, profile_key):
236 return self.db_plugin_iface.pipeOut(to, path, data, profile_key)
237
238 def findGateways(self, target, profile_key):
239 return self.db_plugin_iface.findGateways(target, profile_key)
240
241 def getCard(self, target, profile_key):
242 return self.db_plugin_iface.getCard(target, profile_key)
243
244 def getCardCache(self, target, profile_key):
245 return self.db_plugin_iface.getCardCache(target, profile_key)
246
247 def getAvatarFile(self, hash):
248 return self.db_plugin_iface.getAvatarFile(hash)
249
250 def in_band_register(self, target, profile_key):
251 return self.db_plugin_iface.in_band_register(target, profile_key)
252
253 def gatewayRegister(self, action, target, data, profile_key): 223 def gatewayRegister(self, action, target, data, profile_key):
254 if data == None: 224 if data == None:
255 data = [('', '')] #XXX: we have to do this awful hack because python dbus need to guess the signature 225 data = [('', '')] #XXX: we have to do this awful hack because python dbus need to guess the signature
256 return self.db_plugin_iface.gatewayRegister(action, target, data, profile_key) 226 return self.db_plugin_iface.gatewayRegister(action, target, data, profile_key)
257
258 def getLastMicroblogs(self, jid, max_items, profile_key, callback=None, errback=None):
259 return self.db_plugin_iface.getLastMicroblogs(jid, max_items, profile_key, reply_handler=callback, error_handler=errback)
260
261 def sendGroupBlog(self, access_type, access_list, message, profile_key='@DEFAULT@'):
262 return self.db_plugin_iface.sendGroupBlog(access_type, access_list, message, profile_key)
263
264 def getLastGroupBlogs(self, jid, max_items, profile_key, callback=None, errback=None):
265 return self.db_plugin_iface.getLastGroupBlogs(jid, max_items, profile_key, reply_handler=callback, error_handler=errback)
266
267 def getMassiveLastGroupBlogs(self, publishers_type, publishers, max_items=10, profile_key='@DEFAULT@', callback=None, errback=None):
268 return self.db_plugin_iface.getMassiveLastGroupBlogs(publishers_type, publishers, max_items, profile_key, reply_handler=callback, error_handler=errback)
269
270 def subscribeGroupBlog(self, jid, profile_key='@DEFAULT@', callback=None, errback=None):
271 return self.db_plugin_iface.subscribeGroupBlog(jid, profile_key, reply_handler=callback, error_handler=errback)
272
273 def massiveSubscribeGroupBlogs(self, publishers_type, publishers, profile_key='@DEFAULT@', callback=None, errback=None):
274 return self.db_plugin_iface.massiveSubscribeGroupBlogs(publishers_type, publishers, profile_key, reply_handler=callback, error_handler=errback)
275
276 def sendPersonalEvent(self, event_type, data, profile_key):
277 return self.db_plugin_iface.sendPersonalEvent(event_type, data, profile_key)
278
279 def setMicroblogAccess(self, access="presence", profile_key='@DEFAULT@', callback=None, errback=None):
280 return self.db_plugin_iface.setMicroblogAccess(access, profile_key, reply_handler=callback, error_handler=errback)