comparison src/bridge/bridge_constructor/bridge_constructor.py @ 1367:f71a0fc26886

merged branch frontends_multi_profiles
author Goffi <goffi@goffi.org>
date Wed, 18 Mar 2015 10:52:28 +0100
parents faa1129559b8
children 069ad98b360d
comparison
equal deleted inserted replaced
1295:1e3b1f9ad6e2 1367:f71a0fc26886
444 'category': 'plugin' if function['category'] == 'plugin' else 'core', 444 'category': 'plugin' if function['category'] == 'plugin' else 'core',
445 'name': section, 445 'name': section,
446 'args': self.getArguments(function['sig_in'], name=arg_doc, default=default)} 446 'args': self.getArguments(function['sig_in'], name=arg_doc, default=default)}
447 447
448 if function["type"] == "method": 448 if function["type"] == "method":
449 # XXX: we can manage blocking call in the same way as async one: if callback is None the call will be blocking
449 completion['debug'] = "" if not self.options.debug else 'log.debug ("%s")\n%s' % (section, 8 * ' ') 450 completion['debug'] = "" if not self.options.debug else 'log.debug ("%s")\n%s' % (section, 8 * ' ')
450 completion['args_result'] = self.getArguments(function['sig_in'], name=arg_doc) 451 completion['args_result'] = self.getArguments(function['sig_in'], name=arg_doc)
451 completion['async_args'] = 'callback=None, errback=None' if async else '' 452 completion['async_args'] = 'callback=None, errback=None'
452 completion['async_comma'] = ', ' if async and function['sig_in'] else '' 453 completion['async_comma'] = ', ' if function['sig_in'] else ''
453 completion['error_handler'] = ("error_handler = None if callback is None else lambda err:errback(dbus_to_bridge_exception(err))\n" + 8*" ") if async else '' 454 completion['error_handler'] = """if callback is None:
454 completion['async_args_result'] = 'timeout=const_TIMEOUT, reply_handler=callback, error_handler=error_handler' if async else '' 455 error_handler = None
456 else:
457 if errback is None:
458 errback = log.error
459 error_handler = lambda err:errback(dbus_to_bridge_exception(err))
460 """
461 if async:
462 completion['blocking_call'] = ''
463 completion['async_args_result'] = 'timeout=const_TIMEOUT, reply_handler=callback, error_handler=error_handler'
464 else:
465 # XXX: To have a blocking call, we must have not reply_handler, so we test if callback exists, and add reply_handler only in this case
466 completion['blocking_call'] = """kwargs={}
467 if callback is not None:
468 kwargs['timeout'] = const_TIMEOUT
469 kwargs['reply_handler'] = callback
470 kwargs['error_handler'] = error_handler
471 """
472 completion['async_args_result'] = '**kwargs'
455 result = "self.db_%(category)s_iface.%(name)s(%(args_result)s%(async_comma)s%(async_args_result)s)" % completion 473 result = "self.db_%(category)s_iface.%(name)s(%(args_result)s%(async_comma)s%(async_args_result)s)" % completion
456 completion['result'] = ("unicode(%s)" if self.options.unicode and function['sig_out'] == 's' else "%s") % result 474 completion['result'] = ("unicode(%s)" if self.options.unicode and function['sig_out'] == 's' else "%s") % result
457 methods_part.append("""\ 475 methods_part.append("""\
458 def %(name)s(self, %(args)s%(async_comma)s%(async_args)s): 476 def %(name)s(self, %(args)s%(async_comma)s%(async_args)s):
459 %(error_handler)s%(debug)sreturn %(result)s 477 %(error_handler)s%(blocking_call)s%(debug)sreturn %(result)s
460 """ % completion) 478 """ % completion)
461 479
462 #at this point, methods_part should be filled, 480 #at this point, methods_part should be filled,
463 #we just have to place it in the right part of the template 481 #we just have to place it in the right part of the template
464 frontend_bridge = [] 482 frontend_bridge = []