0
0
Fork 0
mirror of https://github.com/matrix-construct/construct synced 2024-11-25 16:22:35 +01:00

ircd::conf: Add item init callback.

This commit is contained in:
Jason Volk 2018-09-03 04:39:44 -07:00
parent 63c3dbaaac
commit be84bf83de
2 changed files with 28 additions and 1 deletions

View file

@ -46,6 +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;
bool exists(const string_view &key);
string_view get(const string_view &key, const mutable_buffer &out);
@ -69,6 +70,7 @@ struct ircd::conf::item<void>
protected:
virtual string_view on_get(const mutable_buffer &) const;
virtual bool on_set(const string_view &);
void call_init();
public:
string_view get(const mutable_buffer &) const;
@ -127,7 +129,9 @@ struct ircd::conf::lex_castable
(
feature.get("default", long(0))
)
{}
{
call_init();
}
};
template<>

View file

@ -12,6 +12,10 @@ decltype(ircd::conf::items)
ircd::conf::items
{};
decltype(ircd::conf::_init_cb)
ircd::conf::_init_cb
{};
size_t
ircd::conf::reset()
{
@ -199,6 +203,23 @@ const
return on_get(buf);
}
void
ircd::conf::item<void>::call_init()
try
{
if(_init_cb)
_init_cb(*this);
}
catch(const std::exception &e)
{
log::error
{
"conf item[%s] init callback :%s",
name,
e.what()
};
}
bool
ircd::conf::item<void>::on_set(const string_view &)
{
@ -231,6 +252,7 @@ ircd::conf::item<std::string>::item(const json::members &members,
unquote(feature.get("default"))
}
{
call_init();
}
bool
@ -262,6 +284,7 @@ ircd::conf::item<bool>::item(const json::members &members,
feature.get<bool>("default", false)
}
{
call_init();
}
bool