Commit 10a3def7 authored by Anael Beutot's avatar Anael Beutot
Browse files

Refactored RPC calls in TagDB.

parent 3b92257c
Loading
Loading
Loading
Loading
+18 −13
Original line number Diff line number Diff line
@@ -201,6 +201,21 @@ class TagDB(object):
        self.async_calls = dict()

    # RPC part
    def rpc_call(self, opaque, callback, remote_name, *args, **kwargs):
        """Local helper for all rpc calls.

        :param opaque: data to associate with the async call
        :param callable callback: callback when call is done, signature is the
            same as for :method:`async_call_cb` of :class:`RpcConnection`
        :param remote_name: remote method name
        :param \*args: arguments for the call
        :param \*\*kwargs: keyword arguments for the call
        """
        # call only if connected and authenticated to the cc-server
        if self.main.rpc_authenticated:
            self.async_calls[self.main.rpc_con.rpc.async_call_cb(
                callback, remote_name, *args, **kwargs)] = opaque

    def rpc_register(self):
        """Register all objects and tags on the cc-server.

@@ -215,21 +230,11 @@ class TagDB(object):

    def rpc_register_sub_object(self, sub_id):
        # register object on the cc-server
        if self.main.rpc_authenticated:
            self.async_calls[self.main.rpc_con.rpc.async_call_cb(
                self.rpc_object_register_cb,
                'register',
                sub_id,
                'vm',  # FIXME generalization
            )] = sub_id
        self.rpc_call(sub_id, self.rpc_object_register_cb, 'register', sub_id,
                      'vm')  # FIXME generalization

    def rpc_unregister_sub_object(self, sub_id):
        if self.main.rpc_authenticated:
            self.async_calls[self.main.rpc_con.rpc.async_call_cb(
                self.rpc_object_unregister_cb,
                'unregister',
                sub_id,
            )] = sub_id
        self.rpc_call(sub_id, self.rpc_object_register_cb, 'unregister', sub_id)

    def rpc_object_register_cb(self, call_id, response, error):
        name = self.async_calls.pop(call_id)