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:
parent
6f940ab51e
commit
08a35bdc6a
|
@ -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
|
||||
|
|
52
ircd/conf.cc
52
ircd/conf.cc
|
@ -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,
|
||||
|
|
Loading…
Reference in a new issue