Mercurial > libervia-web
diff src/server/server.py @ 935:c3ae008f7a0f
server: move asyncBridgeCall to Libervia.bridgeCall, this way async bridge calls can be used easily everywhere.
author | Goffi <goffi@goffi.org> |
---|---|
date | Thu, 27 Apr 2017 01:11:53 +0200 |
parents | 8a393ae90f8c |
children | 78692d47340d |
line wrap: on
line diff
--- a/src/server/server.py Thu Apr 27 01:09:57 2017 +0200 +++ b/src/server/server.py Thu Apr 27 01:11:53 2017 +0200 @@ -318,29 +318,7 @@ self.sat_host = sat_host def asyncBridgeCall(self, method_name, *args, **kwargs): - """Call an asynchronous bridge method and return a deferred - - @param method_name: name of the method as a unicode - @return: a deferred which trigger the result - - """ - d = defer.Deferred() - - def _callback(*args): - if not args: - d.callback(None) - else: - if len(args) != 1: - Exception("Multiple return arguments not supported") - d.callback(args[0]) - - def _errback(result): - d.errback(failure.Failure(jsonrpclib.Fault(C.ERRNUM_BRIDGE_ERRBACK, result.classname))) - - kwargs["callback"] = _callback - kwargs["errback"] = _errback - getattr(self.sat_host.bridge, method_name)(*args, **kwargs) - return d + return self.sat_host.bridgeCall(method_name, *args, **kwargs) class MethodHandler(JSONRPCMethodManager): @@ -1947,6 +1925,31 @@ else: return version + def bridgeCall(self, method_name, *args, **kwargs): + """Call an asynchronous bridge method and return a deferred + + @param method_name: name of the method as a unicode + @return: a deferred which trigger the result + + """ + d = defer.Deferred() + + def _callback(*args): + if not args: + d.callback(None) + else: + if len(args) != 1: + Exception("Multiple return arguments not supported") + d.callback(args[0]) + + def _errback(result): + d.errback(failure.Failure(jsonrpclib.Fault(C.ERRNUM_BRIDGE_ERRBACK, result.classname))) + + kwargs["callback"] = _callback + kwargs["errback"] = _errback + getattr(self.bridge, method_name)(*args, **kwargs) + return d + def addCleanup(self, callback, *args, **kwargs): """Add cleaning method to call when service is stopped cleaning method will be called in reverse order of they insertion