aboutsummaryrefslogtreecommitdiff
path: root/src/nvim/os/channel.c
diff options
context:
space:
mode:
authorThiago de Arruda <tpadilha84@gmail.com>2014-06-02 11:24:02 -0300
committerThiago de Arruda <tpadilha84@gmail.com>2014-06-02 11:24:02 -0300
commitcab8cf970c09ea465d30e11eb356e2e5d37dc544 (patch)
tree5d274c892e4d53f5e976ae8f6f58aba030785e02 /src/nvim/os/channel.c
parent52a9a5b0b0c53a1481d901f39ed0d1e7e86c3853 (diff)
parent4aecb71b0e819aa84a430dacdab2146229c410a5 (diff)
downloadrneovim-cab8cf970c09ea465d30e11eb356e2e5d37dc544.tar.gz
rneovim-cab8cf970c09ea465d30e11eb356e2e5d37dc544.tar.bz2
rneovim-cab8cf970c09ea465d30e11eb356e2e5d37dc544.zip
Merge pull request #710 'Automatically generate declarations'
Diffstat (limited to 'src/nvim/os/channel.c')
-rw-r--r--src/nvim/os/channel.c38
1 files changed, 28 insertions, 10 deletions
diff --git a/src/nvim/os/channel.c b/src/nvim/os/channel.c
index 6fd7cdbb7e..9a692cf9fe 100644
--- a/src/nvim/os/channel.c
+++ b/src/nvim/os/channel.c
@@ -38,17 +38,11 @@ static PMap(uint64_t) *channels = NULL;
static PMap(cstr_t) *event_strings = NULL;
static msgpack_sbuffer msgpack_event_buffer;
-static void job_out(RStream *rstream, void *data, bool eof);
-static void job_err(RStream *rstream, void *data, bool eof);
-static void parse_msgpack(RStream *rstream, void *data, bool eof);
-static void send_event(Channel *channel, char *type, typval_T *data);
-static void broadcast_event(char *type, typval_T *data);
-static void unsubscribe(Channel *channel, char *event);
-static void close_channel(Channel *channel);
-static void close_cb(uv_handle_t *handle);
-static WBuffer *serialize_event(char *type, typval_T *data);
-static Channel *register_channel(void);
+#ifdef INCLUDE_GENERATED_DECLARATIONS
+# include "os/channel.c.generated.h"
+#endif
+/// Initializes the module
void channel_init()
{
channels = pmap_new(uint64_t)();
@@ -56,6 +50,7 @@ void channel_init()
msgpack_sbuffer_init(&msgpack_event_buffer);
}
+/// Teardown the module
void channel_teardown()
{
if (!channels) {
@@ -69,6 +64,10 @@ void channel_teardown()
});
}
+/// Creates an API channel by starting a job and connecting to its
+/// stdin/stdout. stderr is forwarded to the editor error stream.
+///
+/// @param argv The argument vector for the process
void channel_from_job(char **argv)
{
Channel *channel = register_channel();
@@ -76,6 +75,10 @@ void channel_from_job(char **argv)
channel->data.job_id = job_start(argv, channel, job_out, job_err, NULL);
}
+/// Creates an API channel from a libuv stream representing a tcp or
+/// pipe/socket client connection
+///
+/// @param stream The established connection
void channel_from_stream(uv_stream_t *stream)
{
Channel *channel = register_channel();
@@ -91,6 +94,13 @@ void channel_from_stream(uv_stream_t *stream)
channel->data.streams.uv = stream;
}
+/// Sends event/data 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 type The event type, an arbitrary string
+/// @param obj The event data
+/// @return True if the data was sent successfully, false otherwise.
bool channel_send_event(uint64_t id, char *type, typval_T *data)
{
Channel *channel = NULL;
@@ -107,6 +117,10 @@ bool channel_send_event(uint64_t id, char *type, typval_T *data)
return true;
}
+/// Subscribes to event broadcasts
+///
+/// @param id The channel id
+/// @param event The event type string
void channel_subscribe(uint64_t id, char *event)
{
Channel *channel;
@@ -125,6 +139,10 @@ void channel_subscribe(uint64_t id, char *event)
pmap_put(cstr_t)(channel->subscribed_events, event_string, event_string);
}
+/// Unsubscribes to event broadcasts
+///
+/// @param id The channel id
+/// @param event The event type string
void channel_unsubscribe(uint64_t id, char *event)
{
Channel *channel;