From 7dfc7bc2e17151dc545c3f2f339515c1b946e586 Mon Sep 17 00:00:00 2001 From: Thiago de Arruda Date: Fri, 23 May 2014 15:49:28 -0300 Subject: 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'. --- src/nvim/api/private/handle.c | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 src/nvim/api/private/handle.c (limited to 'src/nvim/api/private/handle.c') 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 + +#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() +{ +} -- cgit