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 From ed99198ff1a3c2b6aad88b03e838a1337f83c4dc Mon Sep 17 00:00:00 2001 From: Thiago de Arruda Date: Fri, 23 May 2014 15:49:30 -0300 Subject: API: Refactor: Register/unregister created/destroyed buffers - Add the 'handle' field to `buf_T` - Add declare/implement functions for registering/unregistering/retrieving buffers - Register/unregister buffers when they are created/destroyed. --- src/nvim/api/private/handle.c | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'src/nvim/api/private/handle.c') diff --git a/src/nvim/api/private/handle.c b/src/nvim/api/private/handle.c index 3bf519bc58..97f5cd88b5 100644 --- a/src/nvim/api/private/handle.c +++ b/src/nvim/api/private/handle.c @@ -26,6 +26,11 @@ map_del(uint64_t)(name##_handles, name->handle); \ } +static uint64_t next_handle = 1; + +HANDLE_IMPL(buf_T, buffer) + void handle_init() { + HANDLE_INIT(buffer); } -- cgit From 20848c4064fc82c160d68770b2e64f5115f0bf60 Mon Sep 17 00:00:00 2001 From: Thiago de Arruda Date: Fri, 23 May 2014 15:49:33 -0300 Subject: API: Refactor: Register/unregister created/destroyed windows - Add the 'handle' field to `win_T` - Add declare/implement functions for registering/unregistering/retrieving windows - Register/unregister windows when they are created/destroyed. --- src/nvim/api/private/handle.c | 2 ++ 1 file changed, 2 insertions(+) (limited to 'src/nvim/api/private/handle.c') diff --git a/src/nvim/api/private/handle.c b/src/nvim/api/private/handle.c index 97f5cd88b5..3dfe05d59f 100644 --- a/src/nvim/api/private/handle.c +++ b/src/nvim/api/private/handle.c @@ -29,8 +29,10 @@ static uint64_t next_handle = 1; HANDLE_IMPL(buf_T, buffer) +HANDLE_IMPL(win_T, window) void handle_init() { HANDLE_INIT(buffer); + HANDLE_INIT(window); } -- cgit From 5fdf854f78eb1a87acb2d28b3d941d988bd1b74e Mon Sep 17 00:00:00 2001 From: Thiago de Arruda Date: Fri, 23 May 2014 15:49:35 -0300 Subject: API: Refactor: Register/unregister created/destroyed tabpages - Add the 'handle' field to `tabpage_T` - Add declare/implement functions for registering/unregistering/retrieving tabpages - Register/unregister tabpages when they are created/destroyed. --- src/nvim/api/private/handle.c | 2 ++ 1 file changed, 2 insertions(+) (limited to 'src/nvim/api/private/handle.c') diff --git a/src/nvim/api/private/handle.c b/src/nvim/api/private/handle.c index 3dfe05d59f..88d176fccb 100644 --- a/src/nvim/api/private/handle.c +++ b/src/nvim/api/private/handle.c @@ -30,9 +30,11 @@ static uint64_t next_handle = 1; HANDLE_IMPL(buf_T, buffer) HANDLE_IMPL(win_T, window) +HANDLE_IMPL(tabpage_T, tabpage) void handle_init() { HANDLE_INIT(buffer); HANDLE_INIT(window); + HANDLE_INIT(tabpage); } -- cgit