aboutsummaryrefslogtreecommitdiff
path: root/src/nvim/os
diff options
context:
space:
mode:
authorThiago de Arruda <tpadilha84@gmail.com>2014-08-28 17:01:58 -0300
committerThiago de Arruda <tpadilha84@gmail.com>2014-08-29 22:08:58 -0300
commita66d2d15382fb153bfa860c0b3ea7cb9630c8afa (patch)
tree6790fb6db9b1cccf006dacb4df175a28eb1dea6f /src/nvim/os
parentaa23d2f835e32c01b318712459ba7b9f55922469 (diff)
downloadrneovim-a66d2d15382fb153bfa860c0b3ea7cb9630c8afa.tar.gz
rneovim-a66d2d15382fb153bfa860c0b3ea7cb9630c8afa.tar.bz2
rneovim-a66d2d15382fb153bfa860c0b3ea7cb9630c8afa.zip
msgpack-rpc: Always use arrays when sending events or calls
This is required by the msgpack-RPC specification. Also, the send_call/send_event functions were refactored to accept a variable number of arguments
Diffstat (limited to 'src/nvim/os')
-rw-r--r--src/nvim/os/channel.c44
-rw-r--r--src/nvim/os/msgpack_rpc.c6
-rw-r--r--src/nvim/os/provider.c6
3 files changed, 32 insertions, 24 deletions
diff --git a/src/nvim/os/channel.c b/src/nvim/os/channel.c
index 2c1928f3b3..39455df862 100644
--- a/src/nvim/os/channel.c
+++ b/src/nvim/os/channel.c
@@ -143,40 +143,48 @@ bool channel_exists(uint64_t id)
&& channel->enabled;
}
-/// Sends event/data to channel
+/// Sends event/arguments to channel
///
/// @param id The channel id. If 0, the event will be sent to all
/// channels that have subscribed to the event type
/// @param name The event name, an arbitrary string
-/// @param arg The event arg
-/// @return True if the data was sent successfully, false otherwise.
-bool channel_send_event(uint64_t id, char *name, Object arg)
+/// @param args Array with event arguments
+/// @return True if the event was sent successfully, false otherwise.
+bool channel_send_event(uint64_t id, char *name, Array args)
{
Channel *channel = NULL;
if (id > 0) {
if (!(channel = pmap_get(uint64_t)(channels, id)) || !channel->enabled) {
- msgpack_rpc_free_object(arg);
+ msgpack_rpc_free_array(args);
return false;
}
- send_event(channel, name, arg);
+ send_event(channel, name, args);
} else {
- broadcast_event(name, arg);
+ broadcast_event(name, args);
}
return true;
}
+/// Sends a method call to a channel
+///
+/// @param id The channel id
+/// @param name The method name, an arbitrary string
+/// @param args Array with method arguments
+/// @param[out] result Pointer to return value received from the channel
+/// @param[out] error True if the return value is an error
+/// @return True if the call was sent successfully, false otherwise.
bool channel_send_call(uint64_t id,
char *name,
- Object arg,
+ Array args,
Object *result,
bool *errored)
{
Channel *channel = NULL;
if (!(channel = pmap_get(uint64_t)(channels, id)) || !channel->enabled) {
- msgpack_rpc_free_object(arg);
+ msgpack_rpc_free_array(args);
return false;
}
@@ -190,13 +198,13 @@ bool channel_send_call(uint64_t id,
"while processing a RPC call",
channel->id);
*result = STRING_OBJ(cstr_to_string(buf));
- msgpack_rpc_free_object(arg);
+ msgpack_rpc_free_array(args);
return false;
}
uint64_t request_id = channel->next_request_id++;
// Send the msgpack-rpc request
- send_request(channel, request_id, name, arg);
+ send_request(channel, request_id, name, args);
EventSource channel_source = channel->is_job
? job_event_source(channel->data.job)
@@ -415,21 +423,21 @@ static void send_error(Channel *channel, uint64_t id, char *err)
static void send_request(Channel *channel,
uint64_t id,
char *name,
- Object arg)
+ Array args)
{
String method = {.size = strlen(name), .data = name};
- channel_write(channel, serialize_request(id, method, arg, &out_buffer, 1));
+ channel_write(channel, serialize_request(id, method, args, &out_buffer, 1));
}
static void send_event(Channel *channel,
char *name,
- Object arg)
+ Array args)
{
String method = {.size = strlen(name), .data = name};
- channel_write(channel, serialize_request(0, method, arg, &out_buffer, 1));
+ channel_write(channel, serialize_request(0, method, args, &out_buffer, 1));
}
-static void broadcast_event(char *name, Object arg)
+static void broadcast_event(char *name, Array args)
{
kvec_t(Channel *) subscribed;
kv_init(subscribed);
@@ -442,14 +450,14 @@ static void broadcast_event(char *name, Object arg)
});
if (!kv_size(subscribed)) {
- msgpack_rpc_free_object(arg);
+ msgpack_rpc_free_array(args);
goto end;
}
String method = {.size = strlen(name), .data = name};
WBuffer *buffer = serialize_request(0,
method,
- arg,
+ args,
&out_buffer,
kv_size(subscribed));
diff --git a/src/nvim/os/msgpack_rpc.c b/src/nvim/os/msgpack_rpc.c
index 90673fef13..c6e2af2f1c 100644
--- a/src/nvim/os/msgpack_rpc.c
+++ b/src/nvim/os/msgpack_rpc.c
@@ -118,7 +118,7 @@ void msgpack_rpc_error(char *msg, msgpack_packer *res)
/// Serializes a msgpack-rpc request or notification(id == 0)
WBuffer *serialize_request(uint64_t request_id,
String method,
- Object arg,
+ Array args,
msgpack_sbuffer *sbuffer,
size_t refcount)
FUNC_ATTR_NONNULL_ARG(4)
@@ -134,12 +134,12 @@ WBuffer *serialize_request(uint64_t request_id,
msgpack_pack_raw(&pac, method.size);
msgpack_pack_raw_body(&pac, method.data, method.size);
- msgpack_rpc_from_object(arg, &pac);
+ msgpack_rpc_from_array(args, &pac);
WBuffer *rv = wstream_new_buffer(xmemdup(sbuffer->data, sbuffer->size),
sbuffer->size,
refcount,
free);
- msgpack_rpc_free_object(arg);
+ msgpack_rpc_free_array(args);
msgpack_sbuffer_clear(sbuffer);
return rv;
}
diff --git a/src/nvim/os/provider.c b/src/nvim/os/provider.c
index d94203f683..07e757fe0e 100644
--- a/src/nvim/os/provider.c
+++ b/src/nvim/os/provider.c
@@ -98,7 +98,7 @@ bool provider_register(char *method, uint64_t channel_id)
return true;
}
-Object provider_call(char *method, Object arg)
+Object provider_call(char *method, Array args)
{
uint64_t channel_id = get_provider_for(method);
@@ -109,13 +109,13 @@ Object provider_call(char *method, Object arg)
"Provider for \"%s\" is not available",
method);
report_error(buf);
- msgpack_rpc_free_object(arg);
+ msgpack_rpc_free_array(args);
return NIL;
}
bool error = false;
Object result = NIL;
- channel_send_call(channel_id, method, arg, &result, &error);
+ channel_send_call(channel_id, method, args, &result, &error);
if (error) {
report_error(result.data.string.data);