diff options
author | Thiago de Arruda <tpadilha84@gmail.com> | 2014-06-20 10:53:05 -0300 |
---|---|---|
committer | Thiago de Arruda <tpadilha84@gmail.com> | 2014-06-24 13:02:24 -0300 |
commit | ea7a389ec77c0031160ce860129101c603d8e0ec (patch) | |
tree | 64b415d9d820a170e82fb22d2315d3817e07b175 /src/nvim/eval.c | |
parent | 09605cec03ea23e87ee285fd950a23ce8d23678d (diff) | |
download | rneovim-ea7a389ec77c0031160ce860129101c603d8e0ec.tar.gz rneovim-ea7a389ec77c0031160ce860129101c603d8e0ec.tar.bz2 rneovim-ea7a389ec77c0031160ce860129101c603d8e0ec.zip |
channel: Implement the 'channel_send_call' function
This function is used to send RPC calls to clients. In contrast to
`channel_send_event`, this function will block until the client sends a
response(But it will continue processing requests from that client).
The RPC call stack has a maximum depth of 20.
Diffstat (limited to 'src/nvim/eval.c')
-rw-r--r-- | src/nvim/eval.c | 43 |
1 files changed, 43 insertions, 0 deletions
diff --git a/src/nvim/eval.c b/src/nvim/eval.c index 7300e60b1a..4c39950344 100644 --- a/src/nvim/eval.c +++ b/src/nvim/eval.c @@ -71,6 +71,7 @@ #include "nvim/os/time.h" #include "nvim/os/channel.h" #include "nvim/api/private/helpers.h" +#include "nvim/os/msgpack_rpc.h" #define DICT_MAXNEST 100 /* maximum nesting of lists and dicts */ @@ -6453,6 +6454,7 @@ static struct fst { {"searchpair", 3, 7, f_searchpair}, {"searchpairpos", 3, 7, f_searchpairpos}, {"searchpos", 1, 4, f_searchpos}, + {"send_call", 3, 3, f_send_call}, {"send_event", 3, 3, f_send_event}, {"setbufvar", 3, 3, f_setbufvar}, {"setcmdpos", 1, 1, f_setcmdpos}, @@ -12525,6 +12527,47 @@ do_searchpair ( return retval; } +// "send_call()" function +static void f_send_call(typval_T *argvars, typval_T *rettv) +{ + rettv->v_type = VAR_NUMBER; + rettv->vval.v_number = 0; + + if (check_restricted() || check_secure()) { + return; + } + + if (argvars[0].v_type != VAR_NUMBER || argvars[0].vval.v_number <= 0) { + EMSG2(_(e_invarg2), "Channel id must be a positive integer"); + return; + } + + if (argvars[1].v_type != VAR_STRING) { + EMSG2(_(e_invarg2), "Method name must be a string"); + return; + } + + bool errored; + Object result; + if (!channel_send_call((uint64_t)argvars[0].vval.v_number, + (char *)argvars[1].vval.v_string, + vim_to_object(&argvars[2]), + &result, + &errored)) { + EMSG2(_(e_invarg2), "Channel doesn't exist"); + return; + } + + Error conversion_error = {.set = false}; + if (errored || !object_to_vim(result, rettv, &conversion_error)) { + EMSG(errored ? + result.data.string.data : + _("Error converting the call result")); + } + + msgpack_rpc_free_object(result); +} + // "send_event()" function static void f_send_event(typval_T *argvars, typval_T *rettv) { |