Commit daa89fe8 authored by Marek Vavruša's avatar Marek Vavruša

lib/modules: layer() api now accept module name

module api can now store userdata, e.g. owner
parent 067f4d02
......@@ -442,7 +442,7 @@ static int resolve(knot_layer_t *ctx, knot_pkt_t *pkt)
}
/** Module implementation. */
const knot_layer_api_t *iterate_layer(void)
const knot_layer_api_t *iterate_layer(struct kr_module *module)
{
static const knot_layer_api_t _layer = {
.begin = &begin,
......
......@@ -19,9 +19,6 @@
#include "lib/layer.h"
#include "lib/rplan.h"
/* Processing module implementation. */
extern const knot_layer_api_t *iterate_layer(void);
/* Packet classification. */
enum {
PKT_NOERROR = 1 << 0, /* Positive response */
......@@ -34,4 +31,4 @@ enum {
int kr_response_classify(knot_pkt_t *pkt);
/* Processing module implementation. */
const knot_layer_api_t *iterate_layer(void);
\ No newline at end of file
const knot_layer_api_t *iterate_layer(struct kr_module *module);
\ No newline at end of file
......@@ -148,7 +148,7 @@ static int stash(knot_layer_t *ctx)
}
/** Module implementation. */
const knot_layer_api_t *pktcache_layer(void)
const knot_layer_api_t *pktcache_layer(struct kr_module *module)
{
static const knot_layer_api_t _layer = {
.begin = &begin,
......
......@@ -247,7 +247,7 @@ static int stash(knot_layer_t *ctx, knot_pkt_t *pkt)
}
/** Module implementation. */
const knot_layer_api_t *rrcache_layer(void)
const knot_layer_api_t *rrcache_layer(struct kr_module *module)
{
static const knot_layer_api_t _layer = {
.begin = &begin,
......
......@@ -19,4 +19,4 @@
#include "lib/layer.h"
/* Processing module implementation. */
extern const knot_layer_api_t *rrcache_layer(void);
const knot_layer_api_t *rrcache_layer(struct kr_module *module);
......@@ -34,10 +34,10 @@ 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 *, const char *);
typedef const knot_layer_api_t* (module_layer_cb)(void);
typedef const knot_layer_api_t* (module_layer_cb)(struct kr_module *);
typedef struct kr_prop *(module_prop_cb)(void);
typedef char *(kr_prop_cb)(void *, struct kr_module *, const char *);
#define KR_MODULE_API ((uint32_t) 0x20150401)
#define KR_MODULE_API ((uint32_t) 0x20150402)
/* @endcond */
/**
......
......@@ -61,7 +61,7 @@ static void prepare_layers(struct kr_request *param)
for (size_t i = 0; i < ctx->modules->len; ++i) {
struct kr_module *mod = &ctx->modules->at[i];
if (mod->layer) {
knot_overlay_add(&param->overlay, mod->layer(), param);
knot_overlay_add(&param->overlay, mod->layer(mod), param);
}
}
}
......
......@@ -30,11 +30,11 @@ A module is a shared library defining specific functions, here's an overview of
.. csv-table::
:header: "C", "Go", "Params", "Comment"
"``X_api()`` [#]_", "``Api()``", "", "Implemented API (``uint32_t``)"
"``X_api()`` [#]_", "``Api()``", "", "Implemented API (``uint32_t``)"
"``X_init()``", "``Init()``", "``module``", "Constructor"
"``X_deinit()``", "``Deinit()``", "``module, key``", "Destructor"
"``X_config()``", "``Config()``", "``module``", "Configuration"
"``X_layer()``", "``Layer()``", "", ":ref:`Module layer <lib-layers>`"
"``X_layer()``", "``Layer()``", "``module``", ":ref:`Module layer <lib-layers>`"
"``X_props()``", "``Props()``", "", "NULL-terminated list of properties"
.. [#] Mandatory symbol.
......@@ -170,7 +170,7 @@ Now we can add the implementations for the ``Begin`` and ``Finish`` functions, a
return 0
}
func Layer() *C.knot_layer_api_t {
func Layer(module *C.struct_kr_module) *C.knot_layer_api_t {
// Wrapping the inline trampoline function
return C._layer()
}
......
......@@ -41,6 +41,6 @@ func Finish(ctx *C.knot_layer_t) C.int {
return 0
}
func Layer() *C.knot_layer_api_t {
func Layer(module *C.struct_kr_module) *C.knot_layer_api_t {
return C._layer()
}
......@@ -36,9 +36,6 @@
#define DEFAULT_FILE "/etc/hosts"
#define DEBUG_MSG(qry, fmt...) QRDEBUG(qry, "hint", fmt)
/** @todo Hack until layers can store userdata. */
static struct kr_zonecut *g_map = NULL;
static int begin(knot_layer_t *ctx, void *module_param)
{
ctx->data = module_param;
......@@ -78,7 +75,6 @@ static int answer_query(knot_pkt_t *pkt, pack_t *addr_set, struct kr_request *pa
static int query(knot_layer_t *ctx, knot_pkt_t *pkt)
{
assert(pkt && ctx);
struct kr_request *param = ctx->data;
struct kr_query *qry = kr_rplan_current(&param->rplan);
if (!qry || ctx->state & (KNOT_STATE_DONE|KNOT_STATE_FAIL)) {
......@@ -89,7 +85,9 @@ static int query(knot_layer_t *ctx, knot_pkt_t *pkt)
}
/* Find a matching name */
pack_t *pack = kr_zonecut_find(g_map, qry->sname);
struct kr_module *module = ctx->api->data;
struct kr_zonecut *hint_map = module->data;
pack_t *pack = kr_zonecut_find(hint_map, qry->sname);
if (!pack || pack->len == 0) {
return ctx->state;
}
......@@ -182,7 +180,6 @@ static int load(struct kr_module *module, const char *path)
struct kr_zonecut *hints = mm_alloc(pool, sizeof(*hints));
kr_zonecut_init(hints, (const uint8_t *)(""), pool);
module->data = hints;
g_map = hints;
return load_map(hints, fp);
}
......@@ -268,12 +265,14 @@ static char* hint_get(void *env, struct kr_module *module, const char *args)
* Module implementation.
*/
const knot_layer_api_t *hints_layer(void)
const knot_layer_api_t *hints_layer(struct kr_module *module)
{
static const knot_layer_api_t _layer = {
static knot_layer_api_t _layer = {
.begin = &begin,
.produce = &query
.produce = &query,
};
/* Store module reference */
_layer.data = module;
return &_layer;
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment