engine.h 2.37 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
/*  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

19
/* Magic defaults */
20 21 22 23 24
#ifndef LRU_RTT_SIZE
#define LRU_RTT_SIZE 4096 /**< NS RTT cache size */
#endif
#ifndef LRU_REP_SIZE
#define LRU_REP_SIZE (LRU_RTT_SIZE / 2) /**< NS reputation cache size */
25
#endif
26 27 28
#ifndef MP_FREELIST_SIZE
#define MP_FREELIST_SIZE 32 /**< Maximum length of the worker mempool freelist */
#endif
29

30 31 32 33
/*
 * @internal These are forward decls to allow building modules with engine but without Lua.
 */
struct lua_State;
34 35

#include "lib/resolve.h"
36
#include "daemon/network.h"
37

38 39 40 41 42 43 44 45 46 47
/** Cache storage backend. */
struct storage_api {
	const char *prefix; /**< Storage prefix, e.g. 'lmdb://' */
	const namedb_api_t *(*api)(void); /**< Storage API implementation */
	void *(*opts_create)(const char *, size_t); /**< Storage options factory */
};

/** @internal Array of cache backend options. */
typedef array_t(struct storage_api) storage_registry_t;

48 49
struct engine {
    struct kr_context resolver;
50
    struct network net;
51
    module_array_t modules;
52
    storage_registry_t storage_registry;
53
    mm_ctx_t *pool;
54
    struct lua_State *L;
55 56 57 58 59 60 61 62 63
};

int engine_init(struct engine *engine, mm_ctx_t *pool);
void engine_deinit(struct engine *engine);
int engine_cmd(struct engine *engine, const char *str);
int engine_start(struct engine *engine);
void engine_stop(struct engine *engine);
int engine_register(struct engine *engine, const char *module);
int engine_unregister(struct engine *engine, const char *module);
64
void engine_lualib(struct engine *engine, const char *name, int (*lib_cb) (struct lua_State *));
65 66 67 68

/** Execute current chunk in the sandbox */
int engine_pcall(struct lua_State *L, int argc);

69
/** Return engine light userdata. */
70
struct engine *engine_luaget(struct lua_State *L);