comparison src/bridge/DBus.py @ 337:4402ac630712

bridge: async callback managed in bridge_constructor + misc - the new flag async make the method asynchronous - new method asyncConnect (connect which return when the user is connected) - setMicroblogAccess added to DBus frontend
author Goffi <goffi@goffi.org>
date Thu, 26 May 2011 16:47:09 +0200
parents 953536246d9d
children e6047415868d
comparison
equal deleted inserted replaced
336:953536246d9d 337:4402ac630712
114 114
115 115
116 ### methods ### 116 ### methods ###
117 117
118 @dbus.service.method(const_INT_PREFIX+const_COMM_SUFFIX, 118 @dbus.service.method(const_INT_PREFIX+const_COMM_SUFFIX,
119 in_signature='ss', out_signature='') 119 in_signature='ss', out_signature='',
120 async_callbacks=None)
120 def addContact(self, entity, profile_key="@DEFAULT@"): 121 def addContact(self, entity, profile_key="@DEFAULT@"):
121 return self.cb["addContact"](unicode(entity), unicode(profile_key)) 122 return self.cb["addContact"](unicode(entity), unicode(profile_key))
122 123
123 @dbus.service.method(const_INT_PREFIX+const_REQ_SUFFIX, 124 @dbus.service.method(const_INT_PREFIX+const_COMM_SUFFIX,
124 in_signature='ssss', out_signature='s') 125 in_signature='s', out_signature='',
126 async_callbacks=('callback', 'errback'))
127 def asyncConnect(self, profile_key="@DEFAULT@", callback=None, errback=None):
128 return self.cb["asyncConnect"](unicode(profile_key), callback, errback)
129
130 @dbus.service.method(const_INT_PREFIX+const_REQ_SUFFIX,
131 in_signature='ssss', out_signature='s',
132 async_callbacks=None)
125 def callMenu(self, category, name, menu_type, profile_key): 133 def callMenu(self, category, name, menu_type, profile_key):
126 return self.cb["callMenu"](unicode(category), unicode(name), unicode(menu_type), unicode(profile_key)) 134 return self.cb["callMenu"](unicode(category), unicode(name), unicode(menu_type), unicode(profile_key))
127 135
128 @dbus.service.method(const_INT_PREFIX+const_REQ_SUFFIX, 136 @dbus.service.method(const_INT_PREFIX+const_REQ_SUFFIX,
129 in_signature='sba{ss}', out_signature='') 137 in_signature='sba{ss}', out_signature='',
138 async_callbacks=None)
130 def confirmationAnswer(self, id, accepted, data): 139 def confirmationAnswer(self, id, accepted, data):
131 return self.cb["confirmationAnswer"](unicode(id), accepted, data) 140 return self.cb["confirmationAnswer"](unicode(id), accepted, data)
132 141
133 @dbus.service.method(const_INT_PREFIX+const_COMM_SUFFIX, 142 @dbus.service.method(const_INT_PREFIX+const_COMM_SUFFIX,
134 in_signature='s', out_signature='') 143 in_signature='s', out_signature='',
144 async_callbacks=None)
135 def connect(self, profile_key="@DEFAULT@"): 145 def connect(self, profile_key="@DEFAULT@"):
136 return self.cb["connect"](unicode(profile_key)) 146 return self.cb["connect"](unicode(profile_key))
137 147
138 @dbus.service.method(const_INT_PREFIX+const_REQ_SUFFIX, 148 @dbus.service.method(const_INT_PREFIX+const_REQ_SUFFIX,
139 in_signature='s', out_signature='i') 149 in_signature='s', out_signature='i',
150 async_callbacks=None)
140 def createProfile(self, profile): 151 def createProfile(self, profile):
141 return self.cb["createProfile"](unicode(profile)) 152 return self.cb["createProfile"](unicode(profile))
142 153
143 @dbus.service.method(const_INT_PREFIX+const_COMM_SUFFIX, 154 @dbus.service.method(const_INT_PREFIX+const_COMM_SUFFIX,
144 in_signature='ss', out_signature='') 155 in_signature='ss', out_signature='',
156 async_callbacks=None)
145 def delContact(self, entity, profile_key="@DEFAULT@"): 157 def delContact(self, entity, profile_key="@DEFAULT@"):
146 return self.cb["delContact"](unicode(entity), unicode(profile_key)) 158 return self.cb["delContact"](unicode(entity), unicode(profile_key))
147 159
148 @dbus.service.method(const_INT_PREFIX+const_REQ_SUFFIX, 160 @dbus.service.method(const_INT_PREFIX+const_REQ_SUFFIX,
149 in_signature='s', out_signature='i') 161 in_signature='s', out_signature='i',
162 async_callbacks=None)
150 def deleteProfile(self, profile): 163 def deleteProfile(self, profile):
151 return self.cb["deleteProfile"](unicode(profile)) 164 return self.cb["deleteProfile"](unicode(profile))
152 165
153 @dbus.service.method(const_INT_PREFIX+const_COMM_SUFFIX, 166 @dbus.service.method(const_INT_PREFIX+const_COMM_SUFFIX,
154 in_signature='s', out_signature='') 167 in_signature='s', out_signature='',
168 async_callbacks=None)
155 def disconnect(self, profile_key="@DEFAULT@"): 169 def disconnect(self, profile_key="@DEFAULT@"):
156 return self.cb["disconnect"](unicode(profile_key)) 170 return self.cb["disconnect"](unicode(profile_key))
157 171
158 @dbus.service.method(const_INT_PREFIX+const_COMM_SUFFIX, 172 @dbus.service.method(const_INT_PREFIX+const_COMM_SUFFIX,
159 in_signature='s', out_signature='a(sa{ss}as)') 173 in_signature='s', out_signature='a(sa{ss}as)',
174 async_callbacks=None)
160 def getContacts(self, profile_key="@DEFAULT@"): 175 def getContacts(self, profile_key="@DEFAULT@"):
161 return self.cb["getContacts"](unicode(profile_key)) 176 return self.cb["getContacts"](unicode(profile_key))
162 177
163 @dbus.service.method(const_INT_PREFIX+const_COMM_SUFFIX, 178 @dbus.service.method(const_INT_PREFIX+const_COMM_SUFFIX,
164 in_signature='ssi', out_signature='a{i(ss)}') 179 in_signature='ssi', out_signature='a{i(ss)}',
180 async_callbacks=None)
165 def getHistory(self, from_jid, to_jid, size): 181 def getHistory(self, from_jid, to_jid, size):
166 return self.cb["getHistory"](unicode(from_jid), unicode(to_jid), size) 182 return self.cb["getHistory"](unicode(from_jid), unicode(to_jid), size)
167 183
168 @dbus.service.method(const_INT_PREFIX+const_REQ_SUFFIX, 184 @dbus.service.method(const_INT_PREFIX+const_REQ_SUFFIX,
169 in_signature='sss', out_signature='s') 185 in_signature='sss', out_signature='s',
186 async_callbacks=None)
170 def getMenuHelp(self, category, name, menu_type): 187 def getMenuHelp(self, category, name, menu_type):
171 return self.cb["getMenuHelp"](unicode(category), unicode(name), unicode(menu_type)) 188 return self.cb["getMenuHelp"](unicode(category), unicode(name), unicode(menu_type))
172 189
173 @dbus.service.method(const_INT_PREFIX+const_REQ_SUFFIX, 190 @dbus.service.method(const_INT_PREFIX+const_REQ_SUFFIX,
174 in_signature='', out_signature='a(sss)') 191 in_signature='', out_signature='a(sss)',
192 async_callbacks=None)
175 def getMenus(self, ): 193 def getMenus(self, ):
176 return self.cb["getMenus"]() 194 return self.cb["getMenus"]()
177 195
178 @dbus.service.method(const_INT_PREFIX+const_COMM_SUFFIX, 196 @dbus.service.method(const_INT_PREFIX+const_COMM_SUFFIX,
179 in_signature='ssss', out_signature='s') 197 in_signature='ssss', out_signature='s',
198 async_callbacks=None)
180 def getParamA(self, name, category, attribute="value", profile_key="@DEFAULT@"): 199 def getParamA(self, name, category, attribute="value", profile_key="@DEFAULT@"):
181 return self.cb["getParamA"](unicode(name), unicode(category), unicode(attribute), unicode(profile_key)) 200 return self.cb["getParamA"](unicode(name), unicode(category), unicode(attribute), unicode(profile_key))
182 201
183 @dbus.service.method(const_INT_PREFIX+const_COMM_SUFFIX, 202 @dbus.service.method(const_INT_PREFIX+const_COMM_SUFFIX,
184 in_signature='s', out_signature='s') 203 in_signature='s', out_signature='s',
204 async_callbacks=None)
185 def getParams(self, profile_key="@DEFAULT@"): 205 def getParams(self, profile_key="@DEFAULT@"):
186 return self.cb["getParams"](unicode(profile_key)) 206 return self.cb["getParams"](unicode(profile_key))
187 207
188 @dbus.service.method(const_INT_PREFIX+const_COMM_SUFFIX, 208 @dbus.service.method(const_INT_PREFIX+const_COMM_SUFFIX,
189 in_signature='', out_signature='as') 209 in_signature='', out_signature='as',
210 async_callbacks=None)
190 def getParamsCategories(self, ): 211 def getParamsCategories(self, ):
191 return self.cb["getParamsCategories"]() 212 return self.cb["getParamsCategories"]()
192 213
193 @dbus.service.method(const_INT_PREFIX+const_COMM_SUFFIX, 214 @dbus.service.method(const_INT_PREFIX+const_COMM_SUFFIX,
194 in_signature='ss', out_signature='s') 215 in_signature='ss', out_signature='s',
216 async_callbacks=None)
195 def getParamsForCategory(self, category, profile_key="@DEFAULT@"): 217 def getParamsForCategory(self, category, profile_key="@DEFAULT@"):
196 return self.cb["getParamsForCategory"](unicode(category), unicode(profile_key)) 218 return self.cb["getParamsForCategory"](unicode(category), unicode(profile_key))
197 219
198 @dbus.service.method(const_INT_PREFIX+const_COMM_SUFFIX, 220 @dbus.service.method(const_INT_PREFIX+const_COMM_SUFFIX,
199 in_signature='s', out_signature='s') 221 in_signature='s', out_signature='s',
222 async_callbacks=None)
200 def getParamsUI(self, profile_key="@DEFAULT@"): 223 def getParamsUI(self, profile_key="@DEFAULT@"):
201 return self.cb["getParamsUI"](unicode(profile_key)) 224 return self.cb["getParamsUI"](unicode(profile_key))
202 225
203 @dbus.service.method(const_INT_PREFIX+const_COMM_SUFFIX, 226 @dbus.service.method(const_INT_PREFIX+const_COMM_SUFFIX,
204 in_signature='s', out_signature='a{sa{s(sia{ss})}}') 227 in_signature='s', out_signature='a{sa{s(sia{ss})}}',
228 async_callbacks=None)
205 def getPresenceStatus(self, profile_key="@DEFAULT@"): 229 def getPresenceStatus(self, profile_key="@DEFAULT@"):
206 return self.cb["getPresenceStatus"](unicode(profile_key)) 230 return self.cb["getPresenceStatus"](unicode(profile_key))
207 231
208 @dbus.service.method(const_INT_PREFIX+const_REQ_SUFFIX, 232 @dbus.service.method(const_INT_PREFIX+const_REQ_SUFFIX,
209 in_signature='s', out_signature='s') 233 in_signature='s', out_signature='s',
234 async_callbacks=None)
210 def getProfileName(self, profile_key="@DEFAULT@"): 235 def getProfileName(self, profile_key="@DEFAULT@"):
211 return self.cb["getProfileName"](unicode(profile_key)) 236 return self.cb["getProfileName"](unicode(profile_key))
212 237
213 @dbus.service.method(const_INT_PREFIX+const_REQ_SUFFIX, 238 @dbus.service.method(const_INT_PREFIX+const_REQ_SUFFIX,
214 in_signature='', out_signature='as') 239 in_signature='', out_signature='as',
240 async_callbacks=None)
215 def getProfilesList(self, ): 241 def getProfilesList(self, ):
216 return self.cb["getProfilesList"]() 242 return self.cb["getProfilesList"]()
217 243
218 @dbus.service.method(const_INT_PREFIX+const_REQ_SUFFIX, 244 @dbus.service.method(const_INT_PREFIX+const_REQ_SUFFIX,
219 in_signature='s', out_signature='a{ss}') 245 in_signature='s', out_signature='a{ss}',
246 async_callbacks=None)
220 def getProgress(self, id): 247 def getProgress(self, id):
221 return self.cb["getProgress"](unicode(id)) 248 return self.cb["getProgress"](unicode(id))
222 249
223 @dbus.service.method(const_INT_PREFIX+const_REQ_SUFFIX, 250 @dbus.service.method(const_INT_PREFIX+const_REQ_SUFFIX,
224 in_signature='', out_signature='s') 251 in_signature='', out_signature='s',
252 async_callbacks=None)
225 def getVersion(self, ): 253 def getVersion(self, ):
226 return self.cb["getVersion"]() 254 return self.cb["getVersion"]()
227 255
228 @dbus.service.method(const_INT_PREFIX+const_COMM_SUFFIX, 256 @dbus.service.method(const_INT_PREFIX+const_COMM_SUFFIX,
229 in_signature='s', out_signature='a{ss}') 257 in_signature='s', out_signature='a{ss}',
258 async_callbacks=None)
230 def getWaitingSub(self, profile_key="@DEFAULT@"): 259 def getWaitingSub(self, profile_key="@DEFAULT@"):
231 return self.cb["getWaitingSub"](unicode(profile_key)) 260 return self.cb["getWaitingSub"](unicode(profile_key))
232 261
233 @dbus.service.method(const_INT_PREFIX+const_COMM_SUFFIX, 262 @dbus.service.method(const_INT_PREFIX+const_COMM_SUFFIX,
234 in_signature='s', out_signature='b') 263 in_signature='s', out_signature='b',
264 async_callbacks=None)
235 def isConnected(self, profile_key="@DEFAULT@"): 265 def isConnected(self, profile_key="@DEFAULT@"):
236 return self.cb["isConnected"](unicode(profile_key)) 266 return self.cb["isConnected"](unicode(profile_key))
237 267
238 @dbus.service.method(const_INT_PREFIX+const_REQ_SUFFIX, 268 @dbus.service.method(const_INT_PREFIX+const_REQ_SUFFIX,
239 in_signature='sa{ss}s', out_signature='s') 269 in_signature='sa{ss}s', out_signature='s',
270 async_callbacks=None)
240 def launchAction(self, action_type, data, profile_key="@DEFAULT@"): 271 def launchAction(self, action_type, data, profile_key="@DEFAULT@"):
241 return self.cb["launchAction"](unicode(action_type), data, unicode(profile_key)) 272 return self.cb["launchAction"](unicode(action_type), data, unicode(profile_key))
242 273
243 @dbus.service.method(const_INT_PREFIX+const_COMM_SUFFIX, 274 @dbus.service.method(const_INT_PREFIX+const_COMM_SUFFIX,
244 in_signature='ssssi', out_signature='s') 275 in_signature='ssssi', out_signature='s',
276 async_callbacks=None)
245 def registerNewAccount(self, login, password, email, host, port=5222): 277 def registerNewAccount(self, login, password, email, host, port=5222):
246 return self.cb["registerNewAccount"](unicode(login), unicode(password), unicode(email), unicode(host), port) 278 return self.cb["registerNewAccount"](unicode(login), unicode(password), unicode(email), unicode(host), port)
247 279
248 @dbus.service.method(const_INT_PREFIX+const_COMM_SUFFIX, 280 @dbus.service.method(const_INT_PREFIX+const_COMM_SUFFIX,
249 in_signature='sssss', out_signature='') 281 in_signature='sssss', out_signature='',
282 async_callbacks=None)
250 def sendMessage(self, to_jid, message, subject='', mess_type="chat", profile_key="@DEFAULT@"): 283 def sendMessage(self, to_jid, message, subject='', mess_type="chat", profile_key="@DEFAULT@"):
251 return self.cb["sendMessage"](unicode(to_jid), unicode(message), unicode(subject), unicode(mess_type), unicode(profile_key)) 284 return self.cb["sendMessage"](unicode(to_jid), unicode(message), unicode(subject), unicode(mess_type), unicode(profile_key))
252 285
253 @dbus.service.method(const_INT_PREFIX+const_COMM_SUFFIX, 286 @dbus.service.method(const_INT_PREFIX+const_COMM_SUFFIX,
254 in_signature='ssss', out_signature='') 287 in_signature='ssss', out_signature='',
288 async_callbacks=None)
255 def setParam(self, name, value, category, profile_key="@DEFAULT@"): 289 def setParam(self, name, value, category, profile_key="@DEFAULT@"):
256 return self.cb["setParam"](unicode(name), unicode(value), unicode(category), unicode(profile_key)) 290 return self.cb["setParam"](unicode(name), unicode(value), unicode(category), unicode(profile_key))
257 291
258 @dbus.service.method(const_INT_PREFIX+const_COMM_SUFFIX, 292 @dbus.service.method(const_INT_PREFIX+const_COMM_SUFFIX,
259 in_signature='ssia{ss}s', out_signature='') 293 in_signature='ssia{ss}s', out_signature='',
294 async_callbacks=None)
260 def setPresence(self, to_jid='', show='', priority=0, statuses={}, profile_key="@DEFAULT@"): 295 def setPresence(self, to_jid='', show='', priority=0, statuses={}, profile_key="@DEFAULT@"):
261 return self.cb["setPresence"](unicode(to_jid), unicode(show), priority, statuses, unicode(profile_key)) 296 return self.cb["setPresence"](unicode(to_jid), unicode(show), priority, statuses, unicode(profile_key))
262 297
263 @dbus.service.method(const_INT_PREFIX+const_COMM_SUFFIX, 298 @dbus.service.method(const_INT_PREFIX+const_COMM_SUFFIX,
264 in_signature='sss', out_signature='') 299 in_signature='sss', out_signature='',
300 async_callbacks=None)
265 def subscription(self, sub_type, entity, profile_key="@DEFAULT@"): 301 def subscription(self, sub_type, entity, profile_key="@DEFAULT@"):
266 return self.cb["subscription"](unicode(sub_type), unicode(entity), unicode(profile_key)) 302 return self.cb["subscription"](unicode(sub_type), unicode(entity), unicode(profile_key))
267 303
268 304
269 def __attributes(self, in_sign): 305 def __attributes(self, in_sign):
324 360
325 def addSignal(self, name, int_suffix, signature, doc={}): 361 def addSignal(self, name, int_suffix, signature, doc={}):
326 """Dynamically add a signal to Dbus Bridge""" 362 """Dynamically add a signal to Dbus Bridge"""
327 attributes = ', '.join(self.__attributes(signature)) 363 attributes = ', '.join(self.__attributes(signature))
328 364
329 code = compile ('def '+name+' (self,'+attributes+'): debug ("'+name+' signal")', '<DBus bridge>','exec') 365 #code = compile ('def '+name+' (self,'+attributes+'): debug ("'+name+' signal")', '<DBus bridge>','exec') #XXX: the debug is too annoying with xmllog
366 code = compile ('def '+name+' (self,'+attributes+'): pass', '<DBus bridge>','exec')
330 exec (code) 367 exec (code)
331 signal = locals()[name] 368 signal = locals()[name]
332 setattr(DbusObject, name, dbus.service.signal( 369 setattr(DbusObject, name, dbus.service.signal(
333 const_INT_PREFIX+int_suffix, signature=signature)(signal)) 370 const_INT_PREFIX+int_suffix, signature=signature)(signal))
334 function = getattr(self, name) 371 function = getattr(self, name)