summaryrefslogtreecommitdiff
path: root/Userland/Libraries/LibConfig
diff options
context:
space:
mode:
authorthankyouverycool <66646555+thankyouverycool@users.noreply.github.com>2022-09-23 09:45:05 -0400
committerAli Mohammad Pur <Ali.mpfard@gmail.com>2022-10-01 13:39:10 +0330
commitc34f2e75e974dcb0933470753795aba50e50e662 (patch)
tree21bdfa581046dc05b8ce16b0695da88242c16b54 /Userland/Libraries/LibConfig
parent6f394d9ee29e8e81107dee91744b63a4d1216cc1 (diff)
downloadserenity-c34f2e75e974dcb0933470753795aba50e50e662.zip
LibCore+LibConfig+ConfigServer: Add Config::{add,remove}_group()
Plumbs synchronous calls for adding and removing group entries to config files. This is useful for services like SystemServer which default to group names for executable paths, and for removing all keys at once.
Diffstat (limited to 'Userland/Libraries/LibConfig')
-rw-r--r--Userland/Libraries/LibConfig/Client.cpp24
-rw-r--r--Userland/Libraries/LibConfig/Client.h14
-rw-r--r--Userland/Libraries/LibConfig/Listener.cpp8
-rw-r--r--Userland/Libraries/LibConfig/Listener.h2
4 files changed, 48 insertions, 0 deletions
diff --git a/Userland/Libraries/LibConfig/Client.cpp b/Userland/Libraries/LibConfig/Client.cpp
index 7046300bc0..9d026630b2 100644
--- a/Userland/Libraries/LibConfig/Client.cpp
+++ b/Userland/Libraries/LibConfig/Client.cpp
@@ -75,6 +75,16 @@ void Client::remove_key(StringView domain, StringView group, StringView key)
remove_key_entry(domain, group, key);
}
+void Client::remove_group(StringView domain, StringView group)
+{
+ remove_group_entry(domain, group);
+}
+
+void Client::add_group(StringView domain, StringView group)
+{
+ add_group_entry(domain, group);
+}
+
void Client::notify_changed_string_value(String const& domain, String const& group, String const& key, String const& value)
{
Listener::for_each([&](auto& listener) {
@@ -103,4 +113,18 @@ void Client::notify_removed_key(String const& domain, String const& group, Strin
});
}
+void Client::notify_removed_group(String const& domain, String const& group)
+{
+ Listener::for_each([&](auto& listener) {
+ listener.config_group_was_removed(domain, group);
+ });
+}
+
+void Client::notify_added_group(String const& domain, String const& group)
+{
+ Listener::for_each([&](auto& listener) {
+ listener.config_group_was_added(domain, group);
+ });
+}
+
}
diff --git a/Userland/Libraries/LibConfig/Client.h b/Userland/Libraries/LibConfig/Client.h
index 406dd3a93b..ff1c2d5207 100644
--- a/Userland/Libraries/LibConfig/Client.h
+++ b/Userland/Libraries/LibConfig/Client.h
@@ -35,6 +35,8 @@ public:
void write_i32(StringView domain, StringView group, StringView key, i32 value);
void write_bool(StringView domain, StringView group, StringView key, bool value);
void remove_key(StringView domain, StringView group, StringView key);
+ void remove_group(StringView domain, StringView group);
+ void add_group(StringView domain, StringView group);
static Client& the();
@@ -48,6 +50,8 @@ private:
void notify_changed_i32_value(String const& domain, String const& group, String const& key, i32 value) override;
void notify_changed_bool_value(String const& domain, String const& group, String const& key, bool value) override;
void notify_removed_key(String const& domain, String const& group, String const& key) override;
+ void notify_removed_group(String const& domain, String const& group) override;
+ void notify_added_group(String const& domain, String const& group) override;
};
inline Vector<String> list_groups(StringView domain)
@@ -95,6 +99,16 @@ inline void remove_key(StringView domain, StringView group, StringView key)
Client::the().remove_key(domain, group, key);
}
+inline void remove_group(StringView domain, StringView group)
+{
+ Client::the().remove_group(domain, group);
+}
+
+inline void add_group(StringView domain, StringView group)
+{
+ Client::the().add_group(domain, group);
+}
+
inline void pledge_domains(Vector<String> const& domains)
{
Client::the().pledge_domains(domains);
diff --git a/Userland/Libraries/LibConfig/Listener.cpp b/Userland/Libraries/LibConfig/Listener.cpp
index 31e5afc93d..08fafeadc1 100644
--- a/Userland/Libraries/LibConfig/Listener.cpp
+++ b/Userland/Libraries/LibConfig/Listener.cpp
@@ -45,4 +45,12 @@ void Listener::config_key_was_removed(String const&, String const&, String const
{
}
+void Listener::config_group_was_removed(String const&, String const&)
+{
+}
+
+void Listener::config_group_was_added(String const&, String const&)
+{
+}
+
}
diff --git a/Userland/Libraries/LibConfig/Listener.h b/Userland/Libraries/LibConfig/Listener.h
index b59c907e41..67820d1be2 100644
--- a/Userland/Libraries/LibConfig/Listener.h
+++ b/Userland/Libraries/LibConfig/Listener.h
@@ -20,6 +20,8 @@ public:
virtual void config_i32_did_change(String const& domain, String const& group, String const& key, i32 value);
virtual void config_bool_did_change(String const& domain, String const& group, String const& key, bool value);
virtual void config_key_was_removed(String const& domain, String const& group, String const& key);
+ virtual void config_group_was_removed(String const& domain, String const& group);
+ virtual void config_group_was_added(String const& domain, String const& group);
protected:
Listener();