From b280308ac649da61e2a0f40a222eae21af5352c9 Mon Sep 17 00:00:00 2001 From: Thiago de Arruda Date: Mon, 20 Oct 2014 07:35:10 -0300 Subject: msgpack-rpc: Create subdirectory for msgpack-rpc modules Create the msgpack_rpc subdirectory and move all modules that deal with msgpack-rpc to it. Also merge msgpack_rpc.c into msgpack_rpc/helpers.c --- src/nvim/msgpack_rpc/defs.h | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 src/nvim/msgpack_rpc/defs.h (limited to 'src/nvim/msgpack_rpc/defs.h') diff --git a/src/nvim/msgpack_rpc/defs.h b/src/nvim/msgpack_rpc/defs.h new file mode 100644 index 0000000000..5eec4ced54 --- /dev/null +++ b/src/nvim/msgpack_rpc/defs.h @@ -0,0 +1,34 @@ +#ifndef NVIM_MSGPACK_RPC_DEFS_H +#define NVIM_MSGPACK_RPC_DEFS_H + +#include + + +/// The rpc_method_handlers table, used in msgpack_rpc_dispatch(), stores +/// functions of this type. +typedef Object (*rpc_method_handler_fn)(uint64_t channel_id, + msgpack_object *req, + Error *error); + +/// Initializes the msgpack-rpc method table +void msgpack_rpc_init_method_table(void); + +void msgpack_rpc_init_function_metadata(Dictionary *metadata); + +/// Dispatches to the actual API function after basic payload validation by +/// `msgpack_rpc_call`. It is responsible for validating/converting arguments +/// to C types, and converting the return value back to msgpack types. +/// The implementation is generated at compile time with metadata extracted +/// from the api/*.h headers, +/// +/// @param channel_id The channel id +/// @param method_id The method id +/// @param req The parsed request object +/// @param error Pointer to error structure +/// @return Some object +Object msgpack_rpc_dispatch(uint64_t channel_id, + msgpack_object *req, + Error *error) + FUNC_ATTR_NONNULL_ARG(2) FUNC_ATTR_NONNULL_ARG(3); + +#endif // NVIM_MSGPACK_RPC_DEFS_H -- cgit From 72e3e57bf1aa128b02724e853365f65fd9451f0b Mon Sep 17 00:00:00 2001 From: Thiago de Arruda Date: Mon, 20 Oct 2014 20:07:01 -0300 Subject: msgpack-rpc: Allow selective deferral API calls Since all API functions now run immediately after a msgpack-rpc request is parsed by libuv callbacks, a mechanism was added to override this behavior and allow certain functions to run in Nvim main loop. The mechanism is simple: Any API function tagged with the FUNC_ATTR_DEFERRED (a "dummy" attribute only used by msgpack-gen.lua) will be called when Nvim main loop receives a K_EVENT key. To implement this mechanism it was necessary some restructuration on the msgpack-rpc modules, especially in the msgpack-gen.lua script. --- src/nvim/msgpack_rpc/defs.h | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) (limited to 'src/nvim/msgpack_rpc/defs.h') diff --git a/src/nvim/msgpack_rpc/defs.h b/src/nvim/msgpack_rpc/defs.h index 5eec4ced54..13067fb7b4 100644 --- a/src/nvim/msgpack_rpc/defs.h +++ b/src/nvim/msgpack_rpc/defs.h @@ -6,9 +6,15 @@ /// The rpc_method_handlers table, used in msgpack_rpc_dispatch(), stores /// functions of this type. -typedef Object (*rpc_method_handler_fn)(uint64_t channel_id, - msgpack_object *req, - Error *error); +typedef struct { + Object (*fn)(uint64_t channel_id, + uint64_t request_id, + Array args, + Error *error); + bool defer; // Should the call be deferred to the main loop? This should + // be true if the function mutates editor data structures such + // as buffers, windows, tabs, or if it executes vimscript code. +} MsgpackRpcRequestHandler; /// Initializes the msgpack-rpc method table void msgpack_rpc_init_method_table(void); @@ -31,4 +37,7 @@ Object msgpack_rpc_dispatch(uint64_t channel_id, Error *error) FUNC_ATTR_NONNULL_ARG(2) FUNC_ATTR_NONNULL_ARG(3); +MsgpackRpcRequestHandler msgpack_rpc_get_handler_for(const char *name, + size_t name_len) + FUNC_ATTR_NONNULL_ARG(1); #endif // NVIM_MSGPACK_RPC_DEFS_H -- cgit