# HG changeset patch # User Goffi # Date 1493248313 -7200 # Node ID c3ae008f7a0f7fe6cae03091e7f22ee094b5e920 # Parent a21fee7e30ee66c8518e09e8a38bdf015e1e1b98 server: move asyncBridgeCall to Libervia.bridgeCall, this way async bridge calls can be used easily everywhere. diff -r a21fee7e30ee -r c3ae008f7a0f src/server/server.py --- 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