Client.cpp 4.2 KB

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