bridge: generic plugin methods handling for frontend side in D-Bus Bridge \o/
This commit is contained in:
parent
55bbfc6895
commit
d3f91b62e9
4 changed files with 75 additions and 184 deletions
|
|
@ -60,6 +60,41 @@ class DBusBridgeFrontend(BridgeFrontend):
|
|||
else:
|
||||
error(_('Unknown interface'))
|
||||
|
||||
def __getattribute__(self, name):
|
||||
""" usual __getattribute__ if the method exists, else try to find a plugin method """
|
||||
try:
|
||||
return object.__getattribute__(self, name)
|
||||
except AttributeError:
|
||||
# The attribute is not found, we try the plugin proxy to find the requested method
|
||||
|
||||
def getPluginMethod(*args, **kwargs):
|
||||
# We first check if we have an async call. We detect this in two ways:
|
||||
# - if we have the 'callback' and 'errback' keyword arguments
|
||||
# - or if the last two arguments are callable
|
||||
|
||||
async = False
|
||||
|
||||
if kwargs:
|
||||
if 'callback' in kwargs and 'errback' in kwargs:
|
||||
async = True
|
||||
_callback = kwargs.pop('callback')
|
||||
_errback = kwargs.pop('errback')
|
||||
elif len(args)>=2 and callable(args[-1]) and callable(args[-2]):
|
||||
async = True
|
||||
args = list(args)
|
||||
_errback = args.pop()
|
||||
_callback = args.pop()
|
||||
|
||||
method = getattr(self.db_plugin_iface, name)
|
||||
|
||||
if async:
|
||||
kwargs['reply_handler'] = _callback
|
||||
kwargs['error_handler'] = lambda err:_errback(err._dbus_error_name[len(const_ERROR_PREFIX)+1:])
|
||||
|
||||
return method(*args, **kwargs)
|
||||
|
||||
return getPluginMethod
|
||||
|
||||
def addContact(self, entity_jid, profile_key="@DEFAULT@"):
|
||||
return self.db_core_iface.addContact(entity_jid, profile_key)
|
||||
|
||||
|
|
@ -179,102 +214,13 @@ class DBusBridgeFrontend(BridgeFrontend):
|
|||
|
||||
|
||||
#methods from plugins
|
||||
def getRoomsJoined(self, profile_key):
|
||||
return self.db_plugin_iface.getRoomsJoined(profile_key)
|
||||
|
||||
def getRoomsSubjects(self, profile_key):
|
||||
return self.db_plugin_iface.getRoomsSubjects(profile_key)
|
||||
|
||||
|
||||
def joinMUC(self, room_jid, nick, options, profile_key):
|
||||
if options == None:
|
||||
options = [('', '')] #XXX: we have to do this awful hack because python dbus need to guess the signature
|
||||
return self.db_plugin_iface.joinMUC(room_jid, nick, options, profile_key)
|
||||
|
||||
def tarotGameLaunch(self, players, profile_key):
|
||||
return self.db_plugin_iface.tarotGameLaunch(players, profile_key)
|
||||
|
||||
def tarotGameCreate(self, room_jid, players, profile_key):
|
||||
return self.db_plugin_iface.tarotGameCreate(room_jid, players, profile_key)
|
||||
|
||||
def tarotGameReady(self, player, referee, profile_key):
|
||||
return self.db_plugin_iface.tarotGameReady(player, referee, profile_key)
|
||||
|
||||
def tarotGameContratChoosed(self, player, referee, contrat, profile_key):
|
||||
return self.db_plugin_iface.tarotGameContratChoosed(player, referee, contrat, profile_key)
|
||||
|
||||
def tarotGamePlayCards(self, player, referee, cards, profile_key):
|
||||
return self.db_plugin_iface.tarotGamePlayCards(player, referee, cards, profile_key)
|
||||
|
||||
def quizGameLaunch(self, players, profile_key):
|
||||
return self.db_plugin_iface.quizGameLaunch(players, profile_key)
|
||||
|
||||
def quizGameCreate(self, room_jid, players, profile_key):
|
||||
return self.db_plugin_iface.quizGameCreate(room_jid, players, profile_key)
|
||||
|
||||
def quizGameReady(self, player, referee, profile_key):
|
||||
return self.db_plugin_iface.quizGameReady(player, referee, profile_key)
|
||||
|
||||
def quizGameAnswer(self, player, referee, answer, profile_key):
|
||||
return self.db_plugin_iface.quizGameAnswer(player, referee, answer, profile_key)
|
||||
|
||||
def radiocolLaunch(self, players, profile_key):
|
||||
return self.db_plugin_iface.radiocolLaunch(players, profile_key)
|
||||
|
||||
def radiocolCreate(self, room_jid, profile_key):
|
||||
return self.db_plugin_iface.radiocolCreate(room_jid, profile_key)
|
||||
|
||||
def radiocolSongAdded(self, room_jid, song_path, profile):
|
||||
return self.db_plugin_iface.radiocolSongAdded(room_jid, song_path, profile)
|
||||
|
||||
def setAvatar(self, avatar_path, profile):
|
||||
return self.db_plugin_iface.setAvatar(avatar_path, profile)
|
||||
|
||||
def sendFile(self, to, path, data, profile_key):
|
||||
return self.db_plugin_iface.sendFile(to, path, data, profile_key)
|
||||
|
||||
def pipeOut(self, to, path, data, profile_key):
|
||||
return self.db_plugin_iface.pipeOut(to, path, data, profile_key)
|
||||
|
||||
def findGateways(self, target, profile_key):
|
||||
return self.db_plugin_iface.findGateways(target, profile_key)
|
||||
|
||||
def getCard(self, target, profile_key):
|
||||
return self.db_plugin_iface.getCard(target, profile_key)
|
||||
|
||||
def getCardCache(self, target, profile_key):
|
||||
return self.db_plugin_iface.getCardCache(target, profile_key)
|
||||
|
||||
def getAvatarFile(self, hash):
|
||||
return self.db_plugin_iface.getAvatarFile(hash)
|
||||
|
||||
def in_band_register(self, target, profile_key):
|
||||
return self.db_plugin_iface.in_band_register(target, profile_key)
|
||||
|
||||
def gatewayRegister(self, action, target, data, profile_key):
|
||||
if data == None:
|
||||
data = [('', '')] #XXX: we have to do this awful hack because python dbus need to guess the signature
|
||||
return self.db_plugin_iface.gatewayRegister(action, target, data, profile_key)
|
||||
|
||||
def getLastMicroblogs(self, jid, max_items, profile_key, callback=None, errback=None):
|
||||
return self.db_plugin_iface.getLastMicroblogs(jid, max_items, profile_key, reply_handler=callback, error_handler=errback)
|
||||
|
||||
def sendGroupBlog(self, access_type, access_list, message, profile_key='@DEFAULT@'):
|
||||
return self.db_plugin_iface.sendGroupBlog(access_type, access_list, message, profile_key)
|
||||
|
||||
def getLastGroupBlogs(self, jid, max_items, profile_key, callback=None, errback=None):
|
||||
return self.db_plugin_iface.getLastGroupBlogs(jid, max_items, profile_key, reply_handler=callback, error_handler=errback)
|
||||
|
||||
def getMassiveLastGroupBlogs(self, publishers_type, publishers, max_items=10, profile_key='@DEFAULT@', callback=None, errback=None):
|
||||
return self.db_plugin_iface.getMassiveLastGroupBlogs(publishers_type, publishers, max_items, profile_key, reply_handler=callback, error_handler=errback)
|
||||
|
||||
def subscribeGroupBlog(self, jid, profile_key='@DEFAULT@', callback=None, errback=None):
|
||||
return self.db_plugin_iface.subscribeGroupBlog(jid, profile_key, reply_handler=callback, error_handler=errback)
|
||||
|
||||
def massiveSubscribeGroupBlogs(self, publishers_type, publishers, profile_key='@DEFAULT@', callback=None, errback=None):
|
||||
return self.db_plugin_iface.massiveSubscribeGroupBlogs(publishers_type, publishers, profile_key, reply_handler=callback, error_handler=errback)
|
||||
|
||||
def sendPersonalEvent(self, event_type, data, profile_key):
|
||||
return self.db_plugin_iface.sendPersonalEvent(event_type, data, profile_key)
|
||||
|
||||
def setMicroblogAccess(self, access="presence", profile_key='@DEFAULT@', callback=None, errback=None):
|
||||
return self.db_plugin_iface.setMicroblogAccess(access, profile_key, reply_handler=callback, error_handler=errback)
|
||||
return self.db_plugin_iface.gatewayRegister(action, target, data, profile_key)
|
||||
|
|
@ -19,7 +19,7 @@ You should have received a copy of the GNU Affero General Public License
|
|||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
"""
|
||||
|
||||
class BridgeFrontend:
|
||||
class BridgeFrontend(object):
|
||||
def __init__(self):
|
||||
print "Bridge frontend initialization"
|
||||
|
||||
|
|
|
|||
|
|
@ -21,7 +21,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|||
|
||||
from logging import debug, info, error
|
||||
|
||||
class Bridge:
|
||||
class Bridge(object):
|
||||
def __init__(self):
|
||||
info ("Bridge initialization")
|
||||
|
||||
|
|
|
|||
|
|
@ -60,106 +60,51 @@ class DBusBridgeFrontend(BridgeFrontend):
|
|||
else:
|
||||
error(_('Unknown interface'))
|
||||
|
||||
def __getattribute__(self, name):
|
||||
""" usual __getattribute__ if the method exists, else try to find a plugin method """
|
||||
try:
|
||||
return object.__getattribute__(self, name)
|
||||
except AttributeError:
|
||||
# The attribute is not found, we try the plugin proxy to find the requested method
|
||||
|
||||
def getPluginMethod(*args, **kwargs):
|
||||
# We first check if we have an async call. We detect this in two ways:
|
||||
# - if we have the 'callback' and 'errback' keyword arguments
|
||||
# - or if the last two arguments are callable
|
||||
|
||||
async = False
|
||||
|
||||
if kwargs:
|
||||
if 'callback' in kwargs and 'errback' in kwargs:
|
||||
async = True
|
||||
_callback = kwargs.pop('callback')
|
||||
_errback = kwargs.pop('errback')
|
||||
elif len(args)>=2 and callable(args[-1]) and callable(args[-2]):
|
||||
async = True
|
||||
args = list(args)
|
||||
_errback = args.pop()
|
||||
_callback = args.pop()
|
||||
|
||||
method = getattr(self.db_plugin_iface, name)
|
||||
|
||||
if async:
|
||||
kwargs['reply_handler'] = _callback
|
||||
kwargs['error_handler'] = lambda err:_errback(err._dbus_error_name[len(const_ERROR_PREFIX)+1:])
|
||||
|
||||
return method(*args, **kwargs)
|
||||
|
||||
return getPluginMethod
|
||||
|
||||
##METHODS_PART##
|
||||
|
||||
#methods from plugins
|
||||
def getRoomsJoined(self, profile_key):
|
||||
return self.db_plugin_iface.getRoomsJoined(profile_key)
|
||||
|
||||
def getRoomsSubjects(self, profile_key):
|
||||
return self.db_plugin_iface.getRoomsSubjects(profile_key)
|
||||
|
||||
|
||||
def joinMUC(self, room_jid, nick, options, profile_key):
|
||||
if options == None:
|
||||
options = [('', '')] #XXX: we have to do this awful hack because python dbus need to guess the signature
|
||||
return self.db_plugin_iface.joinMUC(room_jid, nick, options, profile_key)
|
||||
|
||||
def tarotGameLaunch(self, players, profile_key):
|
||||
return self.db_plugin_iface.tarotGameLaunch(players, profile_key)
|
||||
|
||||
def tarotGameCreate(self, room_jid, players, profile_key):
|
||||
return self.db_plugin_iface.tarotGameCreate(room_jid, players, profile_key)
|
||||
|
||||
def tarotGameReady(self, player, referee, profile_key):
|
||||
return self.db_plugin_iface.tarotGameReady(player, referee, profile_key)
|
||||
|
||||
def tarotGameContratChoosed(self, player, referee, contrat, profile_key):
|
||||
return self.db_plugin_iface.tarotGameContratChoosed(player, referee, contrat, profile_key)
|
||||
|
||||
def tarotGamePlayCards(self, player, referee, cards, profile_key):
|
||||
return self.db_plugin_iface.tarotGamePlayCards(player, referee, cards, profile_key)
|
||||
|
||||
def quizGameLaunch(self, players, profile_key):
|
||||
return self.db_plugin_iface.quizGameLaunch(players, profile_key)
|
||||
|
||||
def quizGameCreate(self, room_jid, players, profile_key):
|
||||
return self.db_plugin_iface.quizGameCreate(room_jid, players, profile_key)
|
||||
|
||||
def quizGameReady(self, player, referee, profile_key):
|
||||
return self.db_plugin_iface.quizGameReady(player, referee, profile_key)
|
||||
|
||||
def quizGameAnswer(self, player, referee, answer, profile_key):
|
||||
return self.db_plugin_iface.quizGameAnswer(player, referee, answer, profile_key)
|
||||
|
||||
def radiocolLaunch(self, players, profile_key):
|
||||
return self.db_plugin_iface.radiocolLaunch(players, profile_key)
|
||||
|
||||
def radiocolCreate(self, room_jid, profile_key):
|
||||
return self.db_plugin_iface.radiocolCreate(room_jid, profile_key)
|
||||
|
||||
def radiocolSongAdded(self, room_jid, song_path, profile):
|
||||
return self.db_plugin_iface.radiocolSongAdded(room_jid, song_path, profile)
|
||||
|
||||
def setAvatar(self, avatar_path, profile):
|
||||
return self.db_plugin_iface.setAvatar(avatar_path, profile)
|
||||
|
||||
def sendFile(self, to, path, data, profile_key):
|
||||
return self.db_plugin_iface.sendFile(to, path, data, profile_key)
|
||||
|
||||
def pipeOut(self, to, path, data, profile_key):
|
||||
return self.db_plugin_iface.pipeOut(to, path, data, profile_key)
|
||||
|
||||
def findGateways(self, target, profile_key):
|
||||
return self.db_plugin_iface.findGateways(target, profile_key)
|
||||
|
||||
def getCard(self, target, profile_key):
|
||||
return self.db_plugin_iface.getCard(target, profile_key)
|
||||
|
||||
def getCardCache(self, target, profile_key):
|
||||
return self.db_plugin_iface.getCardCache(target, profile_key)
|
||||
|
||||
def getAvatarFile(self, hash):
|
||||
return self.db_plugin_iface.getAvatarFile(hash)
|
||||
|
||||
def in_band_register(self, target, profile_key):
|
||||
return self.db_plugin_iface.in_band_register(target, profile_key)
|
||||
|
||||
def gatewayRegister(self, action, target, data, profile_key):
|
||||
if data == None:
|
||||
data = [('', '')] #XXX: we have to do this awful hack because python dbus need to guess the signature
|
||||
return self.db_plugin_iface.gatewayRegister(action, target, data, profile_key)
|
||||
|
||||
def getLastMicroblogs(self, jid, max_items, profile_key, callback=None, errback=None):
|
||||
return self.db_plugin_iface.getLastMicroblogs(jid, max_items, profile_key, reply_handler=callback, error_handler=errback)
|
||||
|
||||
def sendGroupBlog(self, access_type, access_list, message, profile_key='@DEFAULT@'):
|
||||
return self.db_plugin_iface.sendGroupBlog(access_type, access_list, message, profile_key)
|
||||
|
||||
def getLastGroupBlogs(self, jid, max_items, profile_key, callback=None, errback=None):
|
||||
return self.db_plugin_iface.getLastGroupBlogs(jid, max_items, profile_key, reply_handler=callback, error_handler=errback)
|
||||
|
||||
def getMassiveLastGroupBlogs(self, publishers_type, publishers, max_items=10, profile_key='@DEFAULT@', callback=None, errback=None):
|
||||
return self.db_plugin_iface.getMassiveLastGroupBlogs(publishers_type, publishers, max_items, profile_key, reply_handler=callback, error_handler=errback)
|
||||
|
||||
def subscribeGroupBlog(self, jid, profile_key='@DEFAULT@', callback=None, errback=None):
|
||||
return self.db_plugin_iface.subscribeGroupBlog(jid, profile_key, reply_handler=callback, error_handler=errback)
|
||||
|
||||
def massiveSubscribeGroupBlogs(self, publishers_type, publishers, profile_key='@DEFAULT@', callback=None, errback=None):
|
||||
return self.db_plugin_iface.massiveSubscribeGroupBlogs(publishers_type, publishers, profile_key, reply_handler=callback, error_handler=errback)
|
||||
|
||||
def sendPersonalEvent(self, event_type, data, profile_key):
|
||||
return self.db_plugin_iface.sendPersonalEvent(event_type, data, profile_key)
|
||||
|
||||
def setMicroblogAccess(self, access="presence", profile_key='@DEFAULT@', callback=None, errback=None):
|
||||
return self.db_plugin_iface.setMicroblogAccess(access, profile_key, reply_handler=callback, error_handler=errback)
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue