Mercurial > libervia-backend
diff src/bridge/bridge_constructor/bridge_contructor.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 | a00e87d48213 |
children | eb9d33ba4e36 |
line wrap: on
line diff
--- a/src/bridge/bridge_constructor/bridge_contructor.py Wed May 25 17:18:05 2011 +0200 +++ b/src/bridge/bridge_constructor/bridge_contructor.py Thu May 26 16:47:09 2011 +0200 @@ -37,7 +37,7 @@ """ MANAGED_PROTOCOLES=['dbus','mediawiki'] DEFAULT_PROTOCOLE='dbus' -FLAGS=['deprecated'] +FLAGS=['deprecated', 'async'] import sys import os @@ -252,6 +252,7 @@ function = self.getValues(section) print ("Adding %s %s" % (section, function["type"])) default = self.getDefault(section) + async_msg = """<br />'''This method is asynchrone'''""" deprecated_msg = """<br />'''<font color="#FF0000">/!\ WARNING /!\ : This method is deprecated, please don't use it !</font>'''""" signature_signal = \ """\ @@ -274,6 +275,7 @@ 'category':function['category'], 'name':section, 'doc':self.getDoc(section) or "FIXME: No description available", + 'async':async_msg if "async" in self.getFlags(section) else "", 'deprecated':deprecated_msg if "deprecated" in self.getFlags(section) else "", 'parameters':self._wikiParameter(section, function['sig_in']), 'return':self._wikiReturn(section) if function['type'] == 'method' else '' @@ -284,6 +286,7 @@ == %(name)s == ''%(doc)s'' %(deprecated)s +%(async)s {| class="wikitable" style="text-align:left; width:80%%;" ! scope=row | category | %(category)s @@ -335,6 +338,7 @@ print ("Adding %s %s" % (section, function["type"])) default = self.getDefault(section) arg_doc = self.getArgumentsDoc(section) + async = "async" in self.getFlags(section) completion = { 'sig_in':function['sig_in'] or '', 'sig_out':function['sig_out'] or '', @@ -359,11 +363,16 @@ elif function["type"] == "method": completion['debug'] = "" if not self.options.debug else 'debug ("%s")\n%s' % (section,8*' ') completion['args_result'] = self.getArguments(function['sig_in'], name=arg_doc, unicode_protect=self.options.unicode) + completion['async_comma'] = ', ' if async and function['sig_in'] else '' + completion['async_args_def'] = 'callback=None, errback=None' if async else '' + completion['async_args_call'] = 'callback, errback' if async else '' + completion['async_callbacks'] = "('callback', 'errback')" if async else "None" methods_part.append("""\ @dbus.service.method(const_INT_PREFIX+const_%(category)s_SUFFIX, - in_signature='%(sig_in)s', out_signature='%(sig_out)s') - def %(name)s(self, %(args)s): - %(debug)sreturn self.cb["%(name)s"](%(args_result)s) + in_signature='%(sig_in)s', out_signature='%(sig_out)s', + async_callbacks=%(async_callbacks)s) + def %(name)s(self, %(args)s%(async_comma)s%(async_args_def)s): + %(debug)sreturn self.cb["%(name)s"](%(args_result)s%(async_comma)s%(async_args_call)s) """ % completion) #at this point, signals_part, methods_part and direct_calls should be filled, @@ -396,21 +405,25 @@ print ("Adding %s %s" % (section, function["type"])) default = self.getDefault(section) arg_doc = self.getArgumentsDoc(section) + async = "async" in self.getFlags(section) completion = { 'sig_in':function['sig_in'] or '', 'sig_out':function['sig_out'] or '', 'category':'req' if function['category'] == 'request' else 'comm', 'name':section, - 'args':self.getArguments(function['sig_in'], name=arg_doc, default=default ) + 'args':self.getArguments(function['sig_in'], name=arg_doc, default=default) } if function["type"] == "method": completion['debug'] = "" if not self.options.debug else 'debug ("%s")\n%s' % (section,8*' ') completion['args_result'] = self.getArguments(function['sig_in'], name=arg_doc) - result = "self.db_%(category)s_iface.%(name)s(%(args_result)s)" % completion + completion['async_args'] = ', callback=None, errback=None' if async else '' + completion['async_comma'] = ', ' if async and function['sig_in'] else '' + completion['async_args_result'] = 'reply_handler=callback, error_handler=errback' 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): + def %(name)s(self, %(args)s%(async_args)s): %(debug)sreturn %(result)s """ % completion)