aboutsummaryrefslogtreecommitdiff
path: root/src/nvim/api/private/handle.c
diff options
context:
space:
mode:
authorThiago de Arruda <tpadilha84@gmail.com>2014-05-23 15:49:28 -0300
committerThiago de Arruda <tpadilha84@gmail.com>2014-05-23 16:06:58 -0300
commit7dfc7bc2e17151dc545c3f2f339515c1b946e586 (patch)
treecac11fd8d24bb5e223754a22cb90dc9e77184575 /src/nvim/api/private/handle.c
parent72e3125f452ae7224162da8e940e20b00680d41a (diff)
downloadrneovim-7dfc7bc2e17151dc545c3f2f339515c1b946e586.tar.gz
rneovim-7dfc7bc2e17151dc545c3f2f339515c1b946e586.tar.bz2
rneovim-7dfc7bc2e17151dc545c3f2f339515c1b946e586.zip
API: Refactor: Implement api/handle module
This module will be used to implement remote management of objects through the API. Object types to be registered must have a `uint64_t` field named 'handle'.
Diffstat (limited to 'src/nvim/api/private/handle.c')
-rw-r--r--src/nvim/api/private/handle.c31
1 files changed, 31 insertions, 0 deletions
diff --git a/src/nvim/api/private/handle.c b/src/nvim/api/private/handle.c
new file mode 100644
index 0000000000..3bf519bc58
--- /dev/null
+++ b/src/nvim/api/private/handle.c
@@ -0,0 +1,31 @@
+#include <stdint.h>
+
+#include "nvim/vim.h"
+#include "nvim/map.h"
+#include "nvim/api/private/handle.h"
+
+#define HANDLE_INIT(name) name##_handles = map_new(uint64_t)()
+
+#define HANDLE_IMPL(type, name) \
+ static Map(uint64_t) *name##_handles = NULL; \
+ \
+ type *handle_get_##name(uint64_t handle) \
+ { \
+ return map_get(uint64_t)(name##_handles, handle); \
+ } \
+ \
+ void handle_register_##name(type *name) \
+ { \
+ assert(!name->handle); \
+ name->handle = next_handle++; \
+ map_put(uint64_t)(name##_handles, name->handle, name); \
+ } \
+ \
+ void handle_unregister_##name(type *name) \
+ { \
+ map_del(uint64_t)(name##_handles, name->handle); \
+ }
+
+void handle_init()
+{
+}