Serenity Operating System
at master 147 lines 4.3 kB view raw
1/* 2 * Copyright (c) 2021, Andreas Kling <kling@serenityos.org> 3 * 4 * SPDX-License-Identifier: BSD-2-Clause 5 */ 6 7#include <LibConfig/Client.h> 8#include <LibConfig/Listener.h> 9 10namespace Config { 11 12static RefPtr<Client> s_the = nullptr; 13 14Client& Client::the() 15{ 16 if (!s_the || !s_the->is_open()) { 17 VERIFY(Core::EventLoop::has_been_instantiated()); 18 s_the = Client::try_create().release_value_but_fixme_should_propagate_errors(); 19 } 20 return *s_the; 21} 22 23void Client::pledge_domains(Vector<DeprecatedString> const& domains) 24{ 25 async_pledge_domains(domains); 26} 27 28void Client::monitor_domain(DeprecatedString const& domain) 29{ 30 async_monitor_domain(domain); 31} 32 33Vector<DeprecatedString> Client::list_keys(StringView domain, StringView group) 34{ 35 return list_config_keys(domain, group); 36} 37 38Vector<DeprecatedString> Client::list_groups(StringView domain) 39{ 40 return list_config_groups(domain); 41} 42 43DeprecatedString Client::read_string(StringView domain, StringView group, StringView key, StringView fallback) 44{ 45 return read_string_value(domain, group, key).value_or(fallback); 46} 47 48i32 Client::read_i32(StringView domain, StringView group, StringView key, i32 fallback) 49{ 50 return read_i32_value(domain, group, key).value_or(fallback); 51} 52 53u32 Client::read_u32(StringView domain, StringView group, StringView key, u32 fallback) 54{ 55 return read_u32_value(domain, group, key).value_or(fallback); 56} 57 58bool Client::read_bool(StringView domain, StringView group, StringView key, bool fallback) 59{ 60 return read_bool_value(domain, group, key).value_or(fallback); 61} 62 63void Client::write_string(StringView domain, StringView group, StringView key, StringView value) 64{ 65 write_string_value(domain, group, key, value); 66} 67 68void Client::write_i32(StringView domain, StringView group, StringView key, i32 value) 69{ 70 write_i32_value(domain, group, key, value); 71} 72 73void Client::write_u32(StringView domain, StringView group, StringView key, u32 value) 74{ 75 write_u32_value(domain, group, key, value); 76} 77 78void Client::write_bool(StringView domain, StringView group, StringView key, bool value) 79{ 80 write_bool_value(domain, group, key, value); 81} 82 83void Client::remove_key(StringView domain, StringView group, StringView key) 84{ 85 remove_key_entry(domain, group, key); 86} 87 88void Client::remove_group(StringView domain, StringView group) 89{ 90 remove_group_entry(domain, group); 91} 92 93void Client::add_group(StringView domain, StringView group) 94{ 95 add_group_entry(domain, group); 96} 97 98void Client::notify_changed_string_value(DeprecatedString const& domain, DeprecatedString const& group, DeprecatedString const& key, DeprecatedString const& value) 99{ 100 Listener::for_each([&](auto& listener) { 101 listener.config_string_did_change(domain, group, key, value); 102 }); 103} 104 105void Client::notify_changed_i32_value(DeprecatedString const& domain, DeprecatedString const& group, DeprecatedString const& key, i32 value) 106{ 107 Listener::for_each([&](auto& listener) { 108 listener.config_i32_did_change(domain, group, key, value); 109 }); 110} 111 112void Client::notify_changed_u32_value(DeprecatedString const& domain, DeprecatedString const& group, DeprecatedString const& key, u32 value) 113{ 114 Listener::for_each([&](auto& listener) { 115 listener.config_u32_did_change(domain, group, key, value); 116 }); 117} 118 119void Client::notify_changed_bool_value(DeprecatedString const& domain, DeprecatedString const& group, DeprecatedString const& key, bool value) 120{ 121 Listener::for_each([&](auto& listener) { 122 listener.config_bool_did_change(domain, group, key, value); 123 }); 124} 125 126void Client::notify_removed_key(DeprecatedString const& domain, DeprecatedString const& group, DeprecatedString const& key) 127{ 128 Listener::for_each([&](auto& listener) { 129 listener.config_key_was_removed(domain, group, key); 130 }); 131} 132 133void Client::notify_removed_group(DeprecatedString const& domain, DeprecatedString const& group) 134{ 135 Listener::for_each([&](auto& listener) { 136 listener.config_group_was_removed(domain, group); 137 }); 138} 139 140void Client::notify_added_group(DeprecatedString const& domain, DeprecatedString const& group) 141{ 142 Listener::for_each([&](auto& listener) { 143 listener.config_group_was_added(domain, group); 144 }); 145} 146 147}