diff --git a/src/backend.c b/src/backend.c index c46284d..c86d10f 100644 --- a/src/backend.c +++ b/src/backend.c @@ -7,6 +7,7 @@ #include "common.h" #include "config.h" #include "log.h" +#include "mod-defs.h" #include "backend.h" #include diff --git a/src/backends/backend.h b/src/backends/backend.h index 577d633..399ed26 100644 --- a/src/backends/backend.h +++ b/src/backends/backend.h @@ -7,14 +7,8 @@ #include #include -enum loglevel { - debug = 0, - info = 1, - notice = 2, - warn = 3, - error = 4, - fatal = 5, -}; /* see log.h */ +#include "../mod-defs.h" +#include "../mod-api.h" /** * @file diff --git a/src/filter.c b/src/filter.c index fd454dc..8d2306c 100644 --- a/src/filter.c +++ b/src/filter.c @@ -7,6 +7,7 @@ #include "common.h" #include "config.h" #include "log.h" +#include "mod-defs.h" #include "filter.h" #include diff --git a/src/filters/filter.h b/src/filters/filter.h index 458b462..d0901fb 100644 --- a/src/filters/filter.h +++ b/src/filters/filter.h @@ -15,15 +15,8 @@ #include #include "../strlcpy.h" - -enum loglevel { - debug = 0, - info = 1, - notice = 2, - warn = 3, - error = 4, - fatal = 5, -}; /* see log.h */ +#include "../mod-defs.h" +#include "../mod-api.h" /** * @file diff --git a/src/mod-api.h b/src/mod-api.h new file mode 100644 index 0000000..571c306 --- /dev/null +++ b/src/mod-api.h @@ -0,0 +1,53 @@ +/** @file This file contains common exportable types and routines used by all modules */ + +enum loglevel { + debug = 0, + info = 1, + notice = 2, + warn = 3, + error = 4, + fatal = 5, +}; + +/** + * Opaque module handler, contains module internal structs + */ +typedef struct _config cfg_t; + +/** + * @brief Create instance of module + * @param init Module-specific init string + * @returns Opaque module handler or NULL on failure + */ +extern cfg_t *create(const char *init); + +/** + * @brief Configure module instance + * @param cfg Module handler + * @param key Parameter name + * @param value Parameter value + * @returns true on success, false on error + */ +extern bool config(cfg_t *cfg, const char *key, const char *value); + +/** + * @brief Get internal module state as set of flags (see mod.h) + * @param cfg Module handler + * @returns <0 on error + */ +extern int state(cfg_t *cfg); + +/** + * @brief Sets the log callback + * @param cfg Module handler + * @param cb Logging callback + * @note Optional, if this function is not called, warnings/errors of module will be suppressed + */ +extern void logcb(cfg_t *cfg, void (*cb)(enum loglevel l, const char *msg)); + +/** + * @brief Free module handle + * @param cfg Module handler + * @note Module handler becomes invalid after calling this function on it + */ +extern void destroy(cfg_t *cfg); diff --git a/src/mod-defs.h b/src/mod-defs.h new file mode 100644 index 0000000..dc15453 --- /dev/null +++ b/src/mod-defs.h @@ -0,0 +1,9 @@ +/** used as in return value of state() call */ +#define MOD_IS_READY 1 +#define MOD_WRONG_API 2 +#define MOD_STARTED 4 /* source, backend */ +#define MOD_NEED_FILTER 8 /* only source */ +/* reserved */ +#define MOD_TYPE_SOURCE 1024 +#define MOD_TYPE_FILTER 2048 +#define MOD_TYPE_BACKEND 4096 diff --git a/src/source.c b/src/source.c index 9fe4603..ea52284 100644 --- a/src/source.c +++ b/src/source.c @@ -7,11 +7,11 @@ #include "common.h" #include "config.h" #include "log.h" +#include "mod-defs.h" +#include "source.h" #include -#include "source.h" - #define SOURCE_LIBRARY_PARAM "load" f2b_source_t * diff --git a/src/sources/source.h b/src/sources/source.h index e005dc8..668431c 100644 --- a/src/sources/source.h +++ b/src/sources/source.h @@ -14,15 +14,8 @@ #include #include "../strlcpy.h" - -enum loglevel { - debug = 0, - info = 1, - notice = 2, - warn = 3, - error = 4, - fatal = 5, -}; /* see log.h */ +#include "../mod-defs.h" +#include "../mod-api.h" /** * @file