comparison src/bridge/bridge_constructor/dbus_frontend_template.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 ##METHODS_PART## 98 ##METHODS_PART##
64 99
65 #methods from plugins 100 #methods from plugins
66 def getRoomsJoined(self, profile_key): 101
67 return self.db_plugin_iface.getRoomsJoined(profile_key)
68
69 def getRoomsSubjects(self, profile_key):
70 return self.db_plugin_iface.getRoomsSubjects(profile_key)
71
72 def joinMUC(self, room_jid, nick, options, profile_key): 102 def joinMUC(self, room_jid, nick, options, profile_key):
73 if options == None: 103 if options == None:
74 options = [('', '')] #XXX: we have to do this awful hack because python dbus need to guess the signature 104 options = [('', '')] #XXX: we have to do this awful hack because python dbus need to guess the signature
75 return self.db_plugin_iface.joinMUC(room_jid, nick, options, profile_key) 105 return self.db_plugin_iface.joinMUC(room_jid, nick, options, profile_key)
76
77 def tarotGameLaunch(self, players, profile_key):
78 return self.db_plugin_iface.tarotGameLaunch(players, profile_key)
79 106
80 def tarotGameCreate(self, room_jid, players, profile_key):
81 return self.db_plugin_iface.tarotGameCreate(room_jid, players, profile_key)
82
83 def tarotGameReady(self, player, referee, profile_key):
84 return self.db_plugin_iface.tarotGameReady(player, referee, profile_key)
85
86 def tarotGameContratChoosed(self, player, referee, contrat, profile_key):
87 return self.db_plugin_iface.tarotGameContratChoosed(player, referee, contrat, profile_key)
88
89 def tarotGamePlayCards(self, player, referee, cards, profile_key):
90 return self.db_plugin_iface.tarotGamePlayCards(player, referee, cards, profile_key)
91
92 def quizGameLaunch(self, players, profile_key):
93 return self.db_plugin_iface.quizGameLaunch(players, profile_key)
94
95 def quizGameCreate(self, room_jid, players, profile_key):
96 return self.db_plugin_iface.quizGameCreate(room_jid, players, profile_key)
97
98 def quizGameReady(self, player, referee, profile_key):
99 return self.db_plugin_iface.quizGameReady(player, referee, profile_key)
100
101 def quizGameAnswer(self, player, referee, answer, profile_key):
102 return self.db_plugin_iface.quizGameAnswer(player, referee, answer, profile_key)
103
104 def radiocolLaunch(self, players, profile_key):
105 return self.db_plugin_iface.radiocolLaunch(players, profile_key)
106
107 def radiocolCreate(self, room_jid, profile_key):
108 return self.db_plugin_iface.radiocolCreate(room_jid, profile_key)
109
110 def radiocolSongAdded(self, room_jid, song_path, profile):
111 return self.db_plugin_iface.radiocolSongAdded(room_jid, song_path, profile)
112
113 def setAvatar(self, avatar_path, profile):
114 return self.db_plugin_iface.setAvatar(avatar_path, profile)
115
116 def sendFile(self, to, path, data, profile_key):
117 return self.db_plugin_iface.sendFile(to, path, data, profile_key)
118
119 def pipeOut(self, to, path, data, profile_key):
120 return self.db_plugin_iface.pipeOut(to, path, data, profile_key)
121
122 def findGateways(self, target, profile_key):
123 return self.db_plugin_iface.findGateways(target, profile_key)
124
125 def getCard(self, target, profile_key):
126 return self.db_plugin_iface.getCard(target, profile_key)
127
128 def getCardCache(self, target, profile_key):
129 return self.db_plugin_iface.getCardCache(target, profile_key)
130
131 def getAvatarFile(self, hash):
132 return self.db_plugin_iface.getAvatarFile(hash)
133
134 def in_band_register(self, target, profile_key):
135 return self.db_plugin_iface.in_band_register(target, profile_key)
136
137 def gatewayRegister(self, action, target, data, profile_key): 107 def gatewayRegister(self, action, target, data, profile_key):
138 if data == None: 108 if data == None:
139 data = [('', '')] #XXX: we have to do this awful hack because python dbus need to guess the signature 109 data = [('', '')] #XXX: we have to do this awful hack because python dbus need to guess the signature
140 return self.db_plugin_iface.gatewayRegister(action, target, data, profile_key) 110 return self.db_plugin_iface.gatewayRegister(action, target, data, profile_key)
141
142 def getLastMicroblogs(self, jid, max_items, profile_key, callback=None, errback=None):
143 return self.db_plugin_iface.getLastMicroblogs(jid, max_items, profile_key, reply_handler=callback, error_handler=errback)
144
145 def sendGroupBlog(self, access_type, access_list, message, profile_key='@DEFAULT@'):
146 return self.db_plugin_iface.sendGroupBlog(access_type, access_list, message, profile_key)
147
148 def getLastGroupBlogs(self, jid, max_items, profile_key, callback=None, errback=None):
149 return self.db_plugin_iface.getLastGroupBlogs(jid, max_items, profile_key, reply_handler=callback, error_handler=errback)
150
151 def getMassiveLastGroupBlogs(self, publishers_type, publishers, max_items=10, profile_key='@DEFAULT@', callback=None, errback=None):
152 return self.db_plugin_iface.getMassiveLastGroupBlogs(publishers_type, publishers, max_items, profile_key, reply_handler=callback, error_handler=errback)
153
154 def subscribeGroupBlog(self, jid, profile_key='@DEFAULT@', callback=None, errback=None):
155 return self.db_plugin_iface.subscribeGroupBlog(jid, profile_key, reply_handler=callback, error_handler=errback)
156
157 def massiveSubscribeGroupBlogs(self, publishers_type, publishers, profile_key='@DEFAULT@', callback=None, errback=None):
158 return self.db_plugin_iface.massiveSubscribeGroupBlogs(publishers_type, publishers, profile_key, reply_handler=callback, error_handler=errback)
159
160 def sendPersonalEvent(self, event_type, data, profile_key):
161 return self.db_plugin_iface.sendPersonalEvent(event_type, data, profile_key)
162
163 def setMicroblogAccess(self, access="presence", profile_key='@DEFAULT@', callback=None, errback=None):
164 return self.db_plugin_iface.setMicroblogAccess(access, profile_key, reply_handler=callback, error_handler=errback)
165