aboutsummaryrefslogtreecommitdiff
path: root/src/nvim/event
diff options
context:
space:
mode:
authordundargoc <gocdundar@gmail.com>2023-12-12 15:40:21 +0100
committerdundargoc <33953936+dundargoc@users.noreply.github.com>2023-12-17 19:03:18 +0100
commit69bc519b53ebf78fd95c8256468e7d538ebcb948 (patch)
treeeeff39a8b6478da10c8d6b394617cc273e5e0d34 /src/nvim/event
parentc0cb1e8e9437b738c8d3232ec4594113d2221bb2 (diff)
downloadrneovim-69bc519b53ebf78fd95c8256468e7d538ebcb948.tar.gz
rneovim-69bc519b53ebf78fd95c8256468e7d538ebcb948.tar.bz2
rneovim-69bc519b53ebf78fd95c8256468e7d538ebcb948.zip
refactor: move non-symbols to defs.h headers
Diffstat (limited to 'src/nvim/event')
-rw-r--r--src/nvim/event/defs.h166
-rw-r--r--src/nvim/event/libuv_process.c2
-rw-r--r--src/nvim/event/loop.c1
-rw-r--r--src/nvim/event/loop.h39
-rw-r--r--src/nvim/event/multiqueue.h13
-rw-r--r--src/nvim/event/process.c2
-rw-r--r--src/nvim/event/rstream.c1
-rw-r--r--src/nvim/event/signal.c1
-rw-r--r--src/nvim/event/signal.h15
-rw-r--r--src/nvim/event/socket.c1
-rw-r--r--src/nvim/event/socket.h29
-rw-r--r--src/nvim/event/stream.c1
-rw-r--r--src/nvim/event/stream.h50
-rw-r--r--src/nvim/event/time.c3
-rw-r--r--src/nvim/event/time.h14
-rw-r--r--src/nvim/event/wstream.c2
-rw-r--r--src/nvim/event/wstream.h12
17 files changed, 186 insertions, 166 deletions
diff --git a/src/nvim/event/defs.h b/src/nvim/event/defs.h
index 56e00171e2..ffea388b9b 100644
--- a/src/nvim/event/defs.h
+++ b/src/nvim/event/defs.h
@@ -2,6 +2,10 @@
#include <assert.h>
#include <stdarg.h>
+#include <stdbool.h>
+#include <uv.h>
+
+#include "nvim/rbuffer_defs.h"
enum { EVENT_HANDLER_MAX_ARGC = 10, };
@@ -12,3 +16,165 @@ typedef struct {
} Event;
#define event_create(cb, ...) ((Event){ .handler = cb, .argv = { __VA_ARGS__ } })
+
+typedef struct multiqueue MultiQueue;
+typedef void (*PutCallback)(MultiQueue *multiq, void *data);
+
+#define multiqueue_put(q, h, ...) \
+ do { \
+ multiqueue_put_event(q, event_create(h, __VA_ARGS__)); \
+ } while (0)
+
+#define CREATE_EVENT(multiqueue, handler, ...) \
+ do { \
+ if (multiqueue) { \
+ multiqueue_put((multiqueue), (handler), __VA_ARGS__); \
+ } else { \
+ void *argv[] = { __VA_ARGS__ }; \
+ (handler)(argv); \
+ } \
+ } while (0)
+
+// Poll for events until a condition or timeout
+#define LOOP_PROCESS_EVENTS_UNTIL(loop, multiqueue, timeout, condition) \
+ do { \
+ int64_t remaining = timeout; \
+ uint64_t before = (remaining > 0) ? os_hrtime() : 0; \
+ while (!(condition)) { \
+ LOOP_PROCESS_EVENTS(loop, multiqueue, remaining); \
+ if (remaining == 0) { \
+ break; \
+ } else if (remaining > 0) { \
+ uint64_t now = os_hrtime(); \
+ remaining -= (int64_t)((now - before) / 1000000); \
+ before = now; \
+ if (remaining <= 0) { \
+ break; \
+ } \
+ } \
+ } \
+ } while (0)
+
+#define LOOP_PROCESS_EVENTS(loop, multiqueue, timeout) \
+ do { \
+ if (multiqueue && !multiqueue_empty(multiqueue)) { \
+ multiqueue_process_events(multiqueue); \
+ } else { \
+ loop_poll_events(loop, timeout); \
+ } \
+ } while (0)
+
+struct signal_watcher;
+
+typedef struct signal_watcher SignalWatcher;
+typedef void (*signal_cb)(SignalWatcher *watcher, int signum, void *data);
+typedef void (*signal_close_cb)(SignalWatcher *watcher, void *data);
+
+struct signal_watcher {
+ uv_signal_t uv;
+ void *data;
+ signal_cb cb;
+ signal_close_cb close_cb;
+ MultiQueue *events;
+};
+
+struct time_watcher;
+
+typedef struct time_watcher TimeWatcher;
+typedef void (*time_cb)(TimeWatcher *watcher, void *data);
+
+struct time_watcher {
+ uv_timer_t uv;
+ void *data;
+ time_cb cb, close_cb;
+ MultiQueue *events;
+ bool blockable;
+};
+
+struct wbuffer;
+
+typedef struct wbuffer WBuffer;
+typedef void (*wbuffer_data_finalizer)(void *data);
+
+struct wbuffer {
+ size_t size, refcount;
+ char *data;
+ wbuffer_data_finalizer cb;
+};
+
+struct stream;
+
+typedef struct stream Stream;
+/// Type of function called when the Stream buffer is filled with data
+///
+/// @param stream The Stream instance
+/// @param buf The associated RBuffer instance
+/// @param count Number of bytes that was read.
+/// @param data User-defined data
+/// @param eof If the stream reached EOF.
+typedef void (*stream_read_cb)(Stream *stream, RBuffer *buf, size_t count, void *data, bool eof);
+
+/// Type of function called when the Stream has information about a write
+/// request.
+///
+/// @param stream The Stream instance
+/// @param data User-defined data
+/// @param status 0 on success, anything else indicates failure
+typedef void (*stream_write_cb)(Stream *stream, void *data, int status);
+typedef void (*stream_close_cb)(Stream *stream, void *data);
+
+struct stream {
+ bool closed;
+ bool did_eof;
+ union {
+ uv_pipe_t pipe;
+ uv_tcp_t tcp;
+ uv_idle_t idle;
+#ifdef MSWIN
+ uv_tty_t tty;
+#endif
+ } uv;
+ uv_stream_t *uvstream;
+ uv_buf_t uvbuf;
+ RBuffer *buffer;
+ uv_file fd;
+ stream_read_cb read_cb;
+ stream_write_cb write_cb;
+ void *cb_data;
+ stream_close_cb close_cb, internal_close_cb;
+ void *close_cb_data, *internal_data;
+ size_t fpos;
+ size_t curmem;
+ size_t maxmem;
+ size_t pending_reqs;
+ size_t num_bytes;
+ MultiQueue *events;
+};
+
+struct socket_watcher;
+
+#define ADDRESS_MAX_SIZE 256
+
+typedef struct socket_watcher SocketWatcher;
+typedef void (*socket_cb)(SocketWatcher *watcher, int result, void *data);
+typedef void (*socket_close_cb)(SocketWatcher *watcher, void *data);
+
+struct socket_watcher {
+ // Pipe/socket path, or TCP address string
+ char addr[ADDRESS_MAX_SIZE];
+ // TCP server or unix socket (named pipe on Windows)
+ union {
+ struct {
+ uv_tcp_t handle;
+ struct addrinfo *addrinfo;
+ } tcp;
+ struct {
+ uv_pipe_t handle;
+ } pipe;
+ } uv;
+ uv_stream_t *stream;
+ void *data;
+ socket_cb cb;
+ socket_close_cb close_cb;
+ MultiQueue *events;
+};
diff --git a/src/nvim/event/libuv_process.c b/src/nvim/event/libuv_process.c
index 8264adb1fc..07c059423a 100644
--- a/src/nvim/event/libuv_process.c
+++ b/src/nvim/event/libuv_process.c
@@ -4,9 +4,9 @@
#include <uv.h>
#include "nvim/eval/typval.h"
+#include "nvim/event/defs.h"
#include "nvim/event/libuv_process.h"
#include "nvim/event/process.h"
-#include "nvim/event/stream.h"
#include "nvim/log.h"
#include "nvim/os/os.h"
#include "nvim/ui_client.h"
diff --git a/src/nvim/event/loop.c b/src/nvim/event/loop.c
index 697bdb7aa8..a2cb72771c 100644
--- a/src/nvim/event/loop.c
+++ b/src/nvim/event/loop.c
@@ -5,6 +5,7 @@
#include "nvim/event/defs.h"
#include "nvim/event/loop.h"
+#include "nvim/event/multiqueue.h"
#include "nvim/log.h"
#include "nvim/memory.h"
#include "nvim/os/time.h"
diff --git a/src/nvim/event/loop.h b/src/nvim/event/loop.h
index 442a159631..b567df5456 100644
--- a/src/nvim/event/loop.h
+++ b/src/nvim/event/loop.h
@@ -44,45 +44,6 @@ typedef struct loop {
bool closing; ///< Set to true if loop_close() has been called
} Loop;
-#define CREATE_EVENT(multiqueue, handler, ...) \
- do { \
- if (multiqueue) { \
- multiqueue_put((multiqueue), (handler), __VA_ARGS__); \
- } else { \
- void *argv[] = { __VA_ARGS__ }; \
- (handler)(argv); \
- } \
- } while (0)
-
-// Poll for events until a condition or timeout
-#define LOOP_PROCESS_EVENTS_UNTIL(loop, multiqueue, timeout, condition) \
- do { \
- int64_t remaining = timeout; \
- uint64_t before = (remaining > 0) ? os_hrtime() : 0; \
- while (!(condition)) { \
- LOOP_PROCESS_EVENTS(loop, multiqueue, remaining); \
- if (remaining == 0) { \
- break; \
- } else if (remaining > 0) { \
- uint64_t now = os_hrtime(); \
- remaining -= (int64_t)((now - before) / 1000000); \
- before = now; \
- if (remaining <= 0) { \
- break; \
- } \
- } \
- } \
- } while (0)
-
-#define LOOP_PROCESS_EVENTS(loop, multiqueue, timeout) \
- do { \
- if (multiqueue && !multiqueue_empty(multiqueue)) { \
- multiqueue_process_events(multiqueue); \
- } else { \
- loop_poll_events(loop, timeout); \
- } \
- } while (0)
-
#ifdef INCLUDE_GENERATED_DECLARATIONS
# include "event/loop.h.generated.h"
#endif
diff --git a/src/nvim/event/multiqueue.h b/src/nvim/event/multiqueue.h
index 7de307f77e..26e3bc1c30 100644
--- a/src/nvim/event/multiqueue.h
+++ b/src/nvim/event/multiqueue.h
@@ -1,17 +1,8 @@
#pragma once
-#include <uv.h>
+#include <stddef.h> // IWYU pragma: keep
-#include "nvim/event/defs.h"
-#include "nvim/lib/queue.h"
-
-typedef struct multiqueue MultiQueue;
-typedef void (*PutCallback)(MultiQueue *multiq, void *data);
-
-#define multiqueue_put(q, h, ...) \
- do { \
- multiqueue_put_event(q, event_create(h, __VA_ARGS__)); \
- } while (0)
+#include "nvim/event/defs.h" // IWYU pragma: keep
#ifdef INCLUDE_GENERATED_DECLARATIONS
# include "event/multiqueue.h.generated.h"
diff --git a/src/nvim/event/process.c b/src/nvim/event/process.c
index ac9c4973ce..3d9578936c 100644
--- a/src/nvim/event/process.c
+++ b/src/nvim/event/process.c
@@ -6,7 +6,9 @@
#include "klib/klist.h"
#include "nvim/event/libuv_process.h"
#include "nvim/event/loop.h"
+#include "nvim/event/multiqueue.h"
#include "nvim/event/process.h"
+#include "nvim/event/stream.h"
#include "nvim/globals.h"
#include "nvim/log.h"
#include "nvim/main.h"
diff --git a/src/nvim/event/rstream.c b/src/nvim/event/rstream.c
index 130c080db5..df97b592e4 100644
--- a/src/nvim/event/rstream.c
+++ b/src/nvim/event/rstream.c
@@ -5,6 +5,7 @@
#include <sys/types.h>
#include <uv.h>
+#include "nvim/event/defs.h"
#include "nvim/event/loop.h"
#include "nvim/event/rstream.h"
#include "nvim/event/stream.h"
diff --git a/src/nvim/event/signal.c b/src/nvim/event/signal.c
index 2d6cccf53a..3a100812cf 100644
--- a/src/nvim/event/signal.c
+++ b/src/nvim/event/signal.c
@@ -1,6 +1,7 @@
#include <stddef.h>
#include <uv.h>
+#include "nvim/event/defs.h"
#include "nvim/event/loop.h"
#include "nvim/event/signal.h"
diff --git a/src/nvim/event/signal.h b/src/nvim/event/signal.h
index 946de1b4f0..711797ca71 100644
--- a/src/nvim/event/signal.h
+++ b/src/nvim/event/signal.h
@@ -2,23 +2,10 @@
#include <uv.h>
+#include "nvim/event/defs.h"
#include "nvim/event/loop.h"
#include "nvim/event/multiqueue.h"
-struct signal_watcher;
-
-typedef struct signal_watcher SignalWatcher;
-typedef void (*signal_cb)(SignalWatcher *watcher, int signum, void *data);
-typedef void (*signal_close_cb)(SignalWatcher *watcher, void *data);
-
-struct signal_watcher {
- uv_signal_t uv;
- void *data;
- signal_cb cb;
- signal_close_cb close_cb;
- MultiQueue *events;
-};
-
#ifdef INCLUDE_GENERATED_DECLARATIONS
# include "event/signal.h.generated.h"
#endif
diff --git a/src/nvim/event/socket.c b/src/nvim/event/socket.c
index cde53a00e1..3c7b98bfe7 100644
--- a/src/nvim/event/socket.c
+++ b/src/nvim/event/socket.c
@@ -7,6 +7,7 @@
#include "nvim/ascii_defs.h"
#include "nvim/charset.h"
+#include "nvim/event/defs.h"
#include "nvim/event/loop.h"
#include "nvim/event/socket.h"
#include "nvim/event/stream.h"
diff --git a/src/nvim/event/socket.h b/src/nvim/event/socket.h
index 504af3c7a8..24ba361efa 100644
--- a/src/nvim/event/socket.h
+++ b/src/nvim/event/socket.h
@@ -2,39 +2,12 @@
#include <uv.h>
+#include "nvim/event/defs.h"
#include "nvim/event/loop.h"
#include "nvim/event/multiqueue.h"
#include "nvim/event/rstream.h"
#include "nvim/event/wstream.h"
-struct socket_watcher;
-
-#define ADDRESS_MAX_SIZE 256
-
-typedef struct socket_watcher SocketWatcher;
-typedef void (*socket_cb)(SocketWatcher *watcher, int result, void *data);
-typedef void (*socket_close_cb)(SocketWatcher *watcher, void *data);
-
-struct socket_watcher {
- // Pipe/socket path, or TCP address string
- char addr[ADDRESS_MAX_SIZE];
- // TCP server or unix socket (named pipe on Windows)
- union {
- struct {
- uv_tcp_t handle;
- struct addrinfo *addrinfo;
- } tcp;
- struct {
- uv_pipe_t handle;
- } pipe;
- } uv;
- uv_stream_t *stream;
- void *data;
- socket_cb cb;
- socket_close_cb close_cb;
- MultiQueue *events;
-};
-
#ifdef INCLUDE_GENERATED_DECLARATIONS
# include "event/socket.h.generated.h"
#endif
diff --git a/src/nvim/event/stream.c b/src/nvim/event/stream.c
index 8baecbbb31..886e93931b 100644
--- a/src/nvim/event/stream.c
+++ b/src/nvim/event/stream.c
@@ -4,6 +4,7 @@
#include <uv.h>
#include <uv/version.h>
+#include "nvim/event/defs.h"
#include "nvim/event/loop.h"
#include "nvim/event/stream.h"
#include "nvim/log.h"
diff --git a/src/nvim/event/stream.h b/src/nvim/event/stream.h
index ab694e2247..588aab12b0 100644
--- a/src/nvim/event/stream.h
+++ b/src/nvim/event/stream.h
@@ -4,59 +4,11 @@
#include <stddef.h>
#include <uv.h>
+#include "nvim/event/defs.h"
#include "nvim/event/loop.h"
#include "nvim/event/multiqueue.h"
#include "nvim/rbuffer_defs.h"
-struct stream;
-
-typedef struct stream Stream;
-/// Type of function called when the Stream buffer is filled with data
-///
-/// @param stream The Stream instance
-/// @param buf The associated RBuffer instance
-/// @param count Number of bytes that was read.
-/// @param data User-defined data
-/// @param eof If the stream reached EOF.
-typedef void (*stream_read_cb)(Stream *stream, RBuffer *buf, size_t count, void *data, bool eof);
-
-/// Type of function called when the Stream has information about a write
-/// request.
-///
-/// @param stream The Stream instance
-/// @param data User-defined data
-/// @param status 0 on success, anything else indicates failure
-typedef void (*stream_write_cb)(Stream *stream, void *data, int status);
-typedef void (*stream_close_cb)(Stream *stream, void *data);
-
-struct stream {
- bool closed;
- bool did_eof;
- union {
- uv_pipe_t pipe;
- uv_tcp_t tcp;
- uv_idle_t idle;
-#ifdef MSWIN
- uv_tty_t tty;
-#endif
- } uv;
- uv_stream_t *uvstream;
- uv_buf_t uvbuf;
- RBuffer *buffer;
- uv_file fd;
- stream_read_cb read_cb;
- stream_write_cb write_cb;
- void *cb_data;
- stream_close_cb close_cb, internal_close_cb;
- void *close_cb_data, *internal_data;
- size_t fpos;
- size_t curmem;
- size_t maxmem;
- size_t pending_reqs;
- size_t num_bytes;
- MultiQueue *events;
-};
-
#ifdef INCLUDE_GENERATED_DECLARATIONS
# include "event/stream.h.generated.h"
#endif
diff --git a/src/nvim/event/time.c b/src/nvim/event/time.c
index 7206d74176..de837fd278 100644
--- a/src/nvim/event/time.c
+++ b/src/nvim/event/time.c
@@ -1,7 +1,10 @@
+#include <stdbool.h>
#include <stdint.h>
#include <uv.h>
+#include "nvim/event/defs.h"
#include "nvim/event/loop.h"
+#include "nvim/event/multiqueue.h"
#include "nvim/event/time.h"
#ifdef INCLUDE_GENERATED_DECLARATIONS
diff --git a/src/nvim/event/time.h b/src/nvim/event/time.h
index 3514566901..85171f315a 100644
--- a/src/nvim/event/time.h
+++ b/src/nvim/event/time.h
@@ -3,22 +3,10 @@
#include <stdbool.h>
#include <uv.h>
+#include "nvim/event/defs.h"
#include "nvim/event/loop.h"
#include "nvim/event/multiqueue.h"
-struct time_watcher;
-
-typedef struct time_watcher TimeWatcher;
-typedef void (*time_cb)(TimeWatcher *watcher, void *data);
-
-struct time_watcher {
- uv_timer_t uv;
- void *data;
- time_cb cb, close_cb;
- MultiQueue *events;
- bool blockable;
-};
-
#ifdef INCLUDE_GENERATED_DECLARATIONS
# include "event/time.h.generated.h"
#endif
diff --git a/src/nvim/event/wstream.c b/src/nvim/event/wstream.c
index 239f64c013..70cc5b6547 100644
--- a/src/nvim/event/wstream.c
+++ b/src/nvim/event/wstream.c
@@ -1,7 +1,9 @@
#include <assert.h>
#include <stdbool.h>
+#include <stddef.h>
#include <uv.h>
+#include "nvim/event/defs.h"
#include "nvim/event/loop.h"
#include "nvim/event/stream.h"
#include "nvim/event/wstream.h"
diff --git a/src/nvim/event/wstream.h b/src/nvim/event/wstream.h
index 4cba7bde8f..d61ab644f4 100644
--- a/src/nvim/event/wstream.h
+++ b/src/nvim/event/wstream.h
@@ -5,20 +5,10 @@
#include <stdint.h>
#include <uv.h>
+#include "nvim/event/defs.h"
#include "nvim/event/loop.h"
#include "nvim/event/stream.h"
-struct wbuffer;
-
-typedef struct wbuffer WBuffer;
-typedef void (*wbuffer_data_finalizer)(void *data);
-
-struct wbuffer {
- size_t size, refcount;
- char *data;
- wbuffer_data_finalizer cb;
-};
-
#ifdef INCLUDE_GENERATED_DECLARATIONS
# include "event/wstream.h.generated.h"
#endif