0
0
Fork 0
mirror of https://github.com/matrix-construct/construct synced 2024-06-02 10:08:56 +02:00

ircd::conf: Add reset() suite to rexecute item callbacks.

This commit is contained in:
Jason Volk 2018-09-02 20:59:18 -07:00
parent 6f940ab51e
commit 08a35bdc6a
2 changed files with 55 additions and 0 deletions

View file

@ -51,6 +51,9 @@ namespace ircd::conf
string_view get(const string_view &key, const mutable_buffer &out);
bool set(const string_view &key, const string_view &value);
bool set(std::nothrow_t, const string_view &key, const string_view &value);
bool reset(std::nothrow_t, const string_view &key);
bool reset(const string_view &key);
size_t reset();
}
/// Conf item base class. You don't create this directly; use one of the

View file

@ -12,6 +12,58 @@ decltype(ircd::conf::items)
ircd::conf::items
{};
size_t
ircd::conf::reset()
{
size_t ret{0};
for(const auto &p : items)
ret += reset(p.first);
return ret;
}
bool
ircd::conf::reset(const string_view &key)
try
{
return reset(std::nothrow, key);
}
catch(const std::exception &e)
{
return false;
}
bool
ircd::conf::reset(std::nothrow_t,
const string_view &key)
try
{
auto &item(*items.at(key));
if(!item.set_cb)
return false;
item.set_cb();
return true;
}
catch(const std::out_of_range &e)
{
throw not_found
{
"Conf item '%s' is not available", key
};
}
catch(const std::exception &e)
{
log::error
{
"conf item[%s] set callback :%s",
key,
e.what()
};
throw;
}
bool
ircd::conf::set(std::nothrow_t,
const string_view &key,