1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-26 05:07:35 +00:00

ConfigServer+LibConfig: Add way for clients to listen for config changes

This patch adds a Config::Listener abstract class that anyone can
inherit from and receive notifications when configuration values change.

We don't yet monitor file system changes, so these only work for changes
made by ConfigServer itself.

In order to receive these notifications, clients must monitor the domain
by calling monitor_domain(). Only pledged domains can be monitored.

Note that the client initiating the change does not get notified.
This commit is contained in:
Andreas Kling 2021-08-26 19:05:50 +02:00
parent 9509f2ff87
commit edf7843409
9 changed files with 188 additions and 15 deletions

View file

@ -5,6 +5,7 @@
*/
#include <LibConfig/Client.h>
#include <LibConfig/Listener.h>
namespace Config {
@ -24,6 +25,11 @@ void Client::pledge_domains(Vector<String> const& domains)
async_pledge_domains(domains);
}
void Client::monitor_domain(String const& domain)
{
async_monitor_domain(domain);
}
String Client::read_string(StringView domain, StringView group, StringView key, StringView fallback)
{
return read_string_value(domain, group, key).value_or(fallback);
@ -54,4 +60,25 @@ void Client::write_bool(StringView domain, StringView group, StringView key, boo
async_write_bool_value(domain, group, key, value);
}
void Client::notify_changed_string_value(String const& domain, String const& group, String const& key, String const& value)
{
Listener::for_each([&](auto& listener) {
listener.config_string_did_change(domain, group, key, value);
});
}
void Client::notify_changed_i32_value(String const& domain, String const& group, String const& key, i32 value)
{
Listener::for_each([&](auto& listener) {
listener.config_i32_did_change(domain, group, key, value);
});
}
void Client::notify_changed_bool_value(String const& domain, String const& group, String const& key, bool value)
{
Listener::for_each([&](auto& listener) {
listener.config_bool_did_change(domain, group, key, value);
});
}
}