changeset 1237:c1e916594e09

bridge (frontends side): fixed call of async method in blocking context
author Goffi <goffi@goffi.org>
date Thu, 16 Oct 2014 20:18:40 +0200
parents 251ae99a6c0e
children ff58a49a7022
files frontends/src/bridge/DBus.py src/bridge/bridge_constructor/bridge_constructor.py
diffstat 2 files changed, 29 insertions(+), 15 deletions(-) [+]
line wrap: on
line diff
--- a/frontends/src/bridge/DBus.py	Thu Oct 16 20:10:08 2014 +0200
+++ b/frontends/src/bridge/DBus.py	Thu Oct 16 20:18:40 2014 +0200
@@ -126,16 +126,20 @@
         return self.db_core_iface.addContact(entity_jid, profile_key)
 
     def asyncConnect(self, profile_key="@DEFAULT@", password='', callback=None, errback=None):
-        return self.db_core_iface.asyncConnect(profile_key, password, timeout=const_TIMEOUT, reply_handler=callback, error_handler=lambda err:errback(dbus_to_bridge_exception(err)))
+        error_handler = None if callback is None else lambda err:errback(dbus_to_bridge_exception(err))
+        return self.db_core_iface.asyncConnect(profile_key, password, timeout=const_TIMEOUT, reply_handler=callback, error_handler=error_handler)
 
     def asyncCreateProfile(self, profile, password='', callback=None, errback=None):
-        return self.db_core_iface.asyncCreateProfile(profile, password, timeout=const_TIMEOUT, reply_handler=callback, error_handler=lambda err:errback(dbus_to_bridge_exception(err)))
+        error_handler = None if callback is None else lambda err:errback(dbus_to_bridge_exception(err))
+        return self.db_core_iface.asyncCreateProfile(profile, password, timeout=const_TIMEOUT, reply_handler=callback, error_handler=error_handler)
 
     def asyncDeleteProfile(self, profile, callback=None, errback=None):
-        return self.db_core_iface.asyncDeleteProfile(profile, timeout=const_TIMEOUT, reply_handler=callback, error_handler=lambda err:errback(dbus_to_bridge_exception(err)))
+        error_handler = None if callback is None else lambda err:errback(dbus_to_bridge_exception(err))
+        return self.db_core_iface.asyncDeleteProfile(profile, timeout=const_TIMEOUT, reply_handler=callback, error_handler=error_handler)
 
     def asyncGetParamA(self, name, category, attribute="value", security_limit=-1, profile_key="@DEFAULT@", callback=None, errback=None):
-        return unicode(self.db_core_iface.asyncGetParamA(name, category, attribute, security_limit, profile_key, timeout=const_TIMEOUT, reply_handler=callback, error_handler=lambda err:errback(dbus_to_bridge_exception(err))))
+        error_handler = None if callback is None else lambda err:errback(dbus_to_bridge_exception(err))
+        return unicode(self.db_core_iface.asyncGetParamA(name, category, attribute, security_limit, profile_key, timeout=const_TIMEOUT, reply_handler=callback, error_handler=error_handler))
 
     def confirmationAnswer(self, id, accepted, data, profile):
         return self.db_core_iface.confirmationAnswer(id, accepted, data, profile)
@@ -144,10 +148,12 @@
         return self.db_core_iface.delContact(entity_jid, profile_key)
 
     def discoInfos(self, entity_jid, profile_key, callback=None, errback=None):
-        return self.db_core_iface.discoInfos(entity_jid, profile_key, timeout=const_TIMEOUT, reply_handler=callback, error_handler=lambda err:errback(dbus_to_bridge_exception(err)))
+        error_handler = None if callback is None else lambda err:errback(dbus_to_bridge_exception(err))
+        return self.db_core_iface.discoInfos(entity_jid, profile_key, timeout=const_TIMEOUT, reply_handler=callback, error_handler=error_handler)
 
     def discoItems(self, entity_jid, profile_key, callback=None, errback=None):
-        return self.db_core_iface.discoItems(entity_jid, profile_key, timeout=const_TIMEOUT, reply_handler=callback, error_handler=lambda err:errback(dbus_to_bridge_exception(err)))
+        error_handler = None if callback is None else lambda err:errback(dbus_to_bridge_exception(err))
+        return self.db_core_iface.discoItems(entity_jid, profile_key, timeout=const_TIMEOUT, reply_handler=callback, error_handler=error_handler)
 
     def disconnect(self, profile_key="@DEFAULT@"):
         return self.db_core_iface.disconnect(profile_key)
@@ -165,7 +171,8 @@
         return self.db_core_iface.getEntityData(jid, keys, profile)
 
     def getHistory(self, from_jid, to_jid, limit, between=True, search='', profile="@NONE@", callback=None, errback=None):
-        return self.db_core_iface.getHistory(from_jid, to_jid, limit, between, search, profile, timeout=const_TIMEOUT, reply_handler=callback, error_handler=lambda err:errback(dbus_to_bridge_exception(err)))
+        error_handler = None if callback is None else lambda err:errback(dbus_to_bridge_exception(err))
+        return self.db_core_iface.getHistory(from_jid, to_jid, limit, between, search, profile, timeout=const_TIMEOUT, reply_handler=callback, error_handler=error_handler)
 
     def getLastResource(self, contact_jid, profile_key="@DEFAULT@"):
         return unicode(self.db_core_iface.getLastResource(contact_jid, profile_key))
@@ -180,16 +187,19 @@
         return unicode(self.db_core_iface.getParamA(name, category, attribute, profile_key))
 
     def getParams(self, security_limit=-1, app='', profile_key="@DEFAULT@", callback=None, errback=None):
-        return unicode(self.db_core_iface.getParams(security_limit, app, profile_key, timeout=const_TIMEOUT, reply_handler=callback, error_handler=lambda err:errback(dbus_to_bridge_exception(err))))
+        error_handler = None if callback is None else lambda err:errback(dbus_to_bridge_exception(err))
+        return unicode(self.db_core_iface.getParams(security_limit, app, profile_key, timeout=const_TIMEOUT, reply_handler=callback, error_handler=error_handler))
 
     def getParamsCategories(self, ):
         return self.db_core_iface.getParamsCategories()
 
     def getParamsForCategory(self, category, security_limit=-1, app='', profile_key="@DEFAULT@", callback=None, errback=None):
-        return unicode(self.db_core_iface.getParamsForCategory(category, security_limit, app, profile_key, timeout=const_TIMEOUT, reply_handler=callback, error_handler=lambda err:errback(dbus_to_bridge_exception(err))))
+        error_handler = None if callback is None else lambda err:errback(dbus_to_bridge_exception(err))
+        return unicode(self.db_core_iface.getParamsForCategory(category, security_limit, app, profile_key, timeout=const_TIMEOUT, reply_handler=callback, error_handler=error_handler))
 
     def getParamsUI(self, security_limit=-1, app='', profile_key="@DEFAULT@", callback=None, errback=None):
-        return unicode(self.db_core_iface.getParamsUI(security_limit, app, profile_key, timeout=const_TIMEOUT, reply_handler=callback, error_handler=lambda err:errback(dbus_to_bridge_exception(err))))
+        error_handler = None if callback is None else lambda err:errback(dbus_to_bridge_exception(err))
+        return unicode(self.db_core_iface.getParamsUI(security_limit, app, profile_key, timeout=const_TIMEOUT, reply_handler=callback, error_handler=error_handler))
 
     def getPresenceStatuses(self, profile_key="@DEFAULT@"):
         return self.db_core_iface.getPresenceStatuses(profile_key)
@@ -204,7 +214,8 @@
         return self.db_core_iface.getProgress(id, profile)
 
     def getReady(self, callback=None, errback=None):
-        return self.db_core_iface.getReady(timeout=const_TIMEOUT, reply_handler=callback, error_handler=lambda err:errback(dbus_to_bridge_exception(err)))
+        error_handler = None if callback is None else lambda err:errback(dbus_to_bridge_exception(err))
+        return self.db_core_iface.getReady(timeout=const_TIMEOUT, reply_handler=callback, error_handler=error_handler)
 
     def getVersion(self, ):
         return unicode(self.db_core_iface.getVersion())
@@ -219,7 +230,8 @@
         return self.db_core_iface.isConnected(profile_key)
 
     def launchAction(self, callback_id, data, profile_key="@DEFAULT@", callback=None, errback=None):
-        return self.db_core_iface.launchAction(callback_id, data, profile_key, timeout=const_TIMEOUT, reply_handler=callback, error_handler=lambda err:errback(dbus_to_bridge_exception(err)))
+        error_handler = None if callback is None else lambda err:errback(dbus_to_bridge_exception(err))
+        return self.db_core_iface.launchAction(callback_id, data, profile_key, timeout=const_TIMEOUT, reply_handler=callback, error_handler=error_handler)
 
     def loadParamsTemplate(self, filename):
         return self.db_core_iface.loadParamsTemplate(filename)
@@ -231,7 +243,8 @@
         return self.db_core_iface.saveParamsTemplate(filename)
 
     def sendMessage(self, to_jid, message, subject='', mess_type="auto", extra={}, profile_key="@NONE@", callback=None, errback=None):
-        return self.db_core_iface.sendMessage(to_jid, message, subject, mess_type, extra, profile_key, timeout=const_TIMEOUT, reply_handler=callback, error_handler=lambda err:errback(dbus_to_bridge_exception(err)))
+        error_handler = None if callback is None else lambda err:errback(dbus_to_bridge_exception(err))
+        return self.db_core_iface.sendMessage(to_jid, message, subject, mess_type, extra, profile_key, timeout=const_TIMEOUT, reply_handler=callback, error_handler=error_handler)
 
     def setParam(self, name, value, category, security_limit=-1, profile_key="@DEFAULT@"):
         return self.db_core_iface.setParam(name, value, category, security_limit, profile_key)
--- a/src/bridge/bridge_constructor/bridge_constructor.py	Thu Oct 16 20:10:08 2014 +0200
+++ b/src/bridge/bridge_constructor/bridge_constructor.py	Thu Oct 16 20:18:40 2014 +0200
@@ -450,12 +450,13 @@
                 completion['args_result'] = self.getArguments(function['sig_in'], name=arg_doc)
                 completion['async_args'] = 'callback=None, errback=None' if async else ''
                 completion['async_comma'] = ', ' if async and function['sig_in'] else ''
-                completion['async_args_result'] = 'timeout=const_TIMEOUT, reply_handler=callback, error_handler=lambda err:errback(dbus_to_bridge_exception(err))' if async else ''
+                completion['error_handler'] = ("error_handler = None if callback is None else lambda err:errback(dbus_to_bridge_exception(err))\n" + 8*" ") if async else ''
+                completion['async_args_result'] = 'timeout=const_TIMEOUT, reply_handler=callback, error_handler=error_handler' if async else ''
                 result = "self.db_%(category)s_iface.%(name)s(%(args_result)s%(async_comma)s%(async_args_result)s)" % completion
                 completion['result'] = ("unicode(%s)" if self.options.unicode and function['sig_out'] == 's' else "%s") % result
                 methods_part.append("""\
     def %(name)s(self, %(args)s%(async_comma)s%(async_args)s):
-        %(debug)sreturn %(result)s
+        %(error_handler)s%(debug)sreturn %(result)s
 """ % completion)
 
         #at this point, methods_part should be filled,