diff options
author | Marek Vavruša <marek.vavrusa@nic.cz> | 2015-02-23 10:13:29 +0100 |
---|---|---|
committer | Marek Vavruša <marek.vavrusa@nic.cz> | 2015-02-23 10:13:29 +0100 |
commit | e7149d4ff2b3f1f01157fac59fab2100784c4bb2 (patch) | |
tree | 85e678b98c873930ccccf8674f07d0efec44e8cb /lib/module.h | |
parent | build: updated readme (diff) | |
download | knot-resolver-e7149d4ff2b3f1f01157fac59fab2100784c4bb2.tar.xz knot-resolver-e7149d4ff2b3f1f01157fac59fab2100784c4bb2.zip |
lib: loadable versioned modules (api subject to change)
Diffstat (limited to 'lib/module.h')
-rw-r--r-- | lib/module.h | 63 |
1 files changed, 63 insertions, 0 deletions
diff --git a/lib/module.h b/lib/module.h new file mode 100644 index 00000000..6a65d8f7 --- /dev/null +++ b/lib/module.h @@ -0,0 +1,63 @@ +/* Copyright (C) 2015 CZ.NIC, z.s.p.o. <knot-dns@labs.nic.cz> + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see <http://www.gnu.org/licenses/>. + */ + +#pragma once + +#include <libknot/processing/layer.h> + +/* + * Forward decls + */ +struct kr_module; + +/* + * API definition. + */ +#define KR_MODULE_API 0x20150401 /*!< API version */ +typedef uint32_t (module_api_cb)(void); +typedef int (module_init_cb)(struct kr_module *); +typedef int (module_deinit_cb)(struct kr_module *); +typedef int (module_config_cb)(struct kr_module *, void *); +typedef const knot_layer_api_t* (module_layer_cb)(void); + +/*! Loaded module representation. */ +struct kr_module { + module_init_cb *init; /*!< Constructor */ + module_deinit_cb *deinit; /*!< Destructor */ + module_config_cb *config; /*!< Configuration */ + module_layer_cb *layer; /*!< Layer getter */ + void *lib; /*!< Shared library handle or RTLD_DEFAULT */ + void *data; /*!< Custom data context. */ +}; + +/*! Load module instance into memory. + * @param module module structure + * @param name module name + * @param path module search path + * @return 0 or an error + */ +int kr_module_load(struct kr_module *module, const char *name, const char *path); + +/*! Unload module instance. + * @param module module structure + */ +void kr_module_unload(struct kr_module *module); + +/*! Export module API version (place this at the end of your module). + * @param module module name (f.e. hints) + */ +#define KR_MODULE_EXPORT(module) \ + uint32_t module ## _api() { return KR_MODULE_API; }
\ No newline at end of file |