diff options
Diffstat (limited to 'dnsdist-lua-hooks.cc')
-rw-r--r-- | dnsdist-lua-hooks.cc | 37 |
1 files changed, 37 insertions, 0 deletions
diff --git a/dnsdist-lua-hooks.cc b/dnsdist-lua-hooks.cc new file mode 100644 index 0000000..c5ccb48 --- /dev/null +++ b/dnsdist-lua-hooks.cc @@ -0,0 +1,37 @@ + +#include "dnsdist-lua-hooks.hh" +#include "dnsdist-lua.hh" +#include "lock.hh" + +namespace dnsdist::lua::hooks +{ +static LockGuarded<std::vector<MaintenanceCallback>> s_maintenanceHooks; + +void runMaintenanceHooks(const LuaContext& context) +{ + (void)context; + for (const auto& callback : *(s_maintenanceHooks.lock())) { + callback(); + } +} + +void addMaintenanceCallback(const LuaContext& context, MaintenanceCallback callback) +{ + (void)context; + s_maintenanceHooks.lock()->push_back(std::move(callback)); +} + +void clearMaintenanceHooks() +{ + s_maintenanceHooks.lock()->clear(); +} + +void setupLuaHooks(LuaContext& luaCtx) +{ + luaCtx.writeFunction("addMaintenanceCallback", [&luaCtx](const MaintenanceCallback& callback) { + setLuaSideEffect(); + addMaintenanceCallback(luaCtx, callback); + }); +} + +} |