mirror of
https://github.com/matrix-construct/construct
synced 2024-10-31 19:08:59 +01:00
ircd::conf: Use util::callbacks here.
This commit is contained in:
parent
16bbecf649
commit
1711df33a9
3 changed files with 16 additions and 7 deletions
|
@ -46,7 +46,7 @@ namespace ircd::conf
|
|||
using set_cb = std::function<void ()>;
|
||||
|
||||
extern std::map<string_view, item<> *> items;
|
||||
extern std::function<void (item<> &)> _init_cb;
|
||||
extern callbacks<void (item<> &)> on_init;
|
||||
|
||||
bool exists(const string_view &key);
|
||||
string_view get(const string_view &key, const mutable_buffer &out);
|
||||
|
|
|
@ -12,8 +12,8 @@ decltype(ircd::conf::items)
|
|||
ircd::conf::items
|
||||
{};
|
||||
|
||||
decltype(ircd::conf::_init_cb)
|
||||
ircd::conf::_init_cb
|
||||
decltype(ircd::conf::on_init)
|
||||
ircd::conf::on_init
|
||||
{};
|
||||
|
||||
size_t
|
||||
|
@ -207,8 +207,7 @@ void
|
|||
ircd::conf::item<void>::call_init()
|
||||
try
|
||||
{
|
||||
if(_init_cb)
|
||||
_init_cb(*this);
|
||||
on_init(*this);
|
||||
}
|
||||
catch(const std::exception &e)
|
||||
{
|
||||
|
|
|
@ -15,16 +15,26 @@ extern "C" void reload_conf();
|
|||
extern "C" void refresh_conf();
|
||||
static void init_conf_item(conf::item<> &);
|
||||
|
||||
// This module registers with conf::on_init to be called back
|
||||
// when a conf item is initialized; when this module is unloaded
|
||||
// we have to unregister that listener using this state.
|
||||
decltype(conf::on_init)::const_iterator
|
||||
conf_on_init_iter
|
||||
{
|
||||
end(conf::on_init)
|
||||
};
|
||||
|
||||
mapi::header
|
||||
IRCD_MODULE
|
||||
{
|
||||
"Server Configuration", []
|
||||
{
|
||||
ircd::conf::_init_cb = init_conf_item;
|
||||
conf_on_init_iter = conf::on_init.emplace(end(conf::on_init), init_conf_item);
|
||||
reload_conf();
|
||||
}, []
|
||||
{
|
||||
ircd::conf::_init_cb = nullptr;
|
||||
assert(conf_on_init_iter != end(conf::on_init));
|
||||
conf::on_init.erase(conf_on_init_iter);
|
||||
}
|
||||
};
|
||||
|
||||
|
|
Loading…
Reference in a new issue