Common System 0.2.0
Common interfaces and patterns for system integration
Loading...
Searching...
No Matches
kcenon::common::config::config_watcher Class Reference

Monitors configuration files for changes and supports hot-reload. More...

#include <config_watcher.h>

Collaboration diagram for kcenon::common::config::config_watcher:
Collaboration graph

Public Types

using change_callback
 Callback type for configuration changes.
 
using error_callback = std::function<void(const std::string& error_message)>
 Callback type for reload errors.
 

Public Member Functions

 config_watcher (const std::string &config_path, size_t max_history=10)
 Construct a config_watcher for the specified file.
 
 ~config_watcher ()
 Destructor. Automatically stops watching if running.
 
 config_watcher (const config_watcher &)=delete
 
config_watcheroperator= (const config_watcher &)=delete
 
 config_watcher (config_watcher &&)=delete
 
config_watcheroperator= (config_watcher &&)=delete
 
VoidResult start ()
 Start watching the configuration file for changes.
 
void stop ()
 Stop watching the configuration file.
 
bool is_running () const
 Check if the watcher is currently running.
 
void on_change (change_callback callback)
 Register a callback for configuration changes.
 
void on_error (error_callback callback)
 Register a callback for reload errors.
 
VoidResult reload ()
 Manually trigger a configuration reload.
 
const unified_configcurrent () const
 Get the current configuration.
 
uint64_t version () const
 Get the current configuration version.
 
std::vector< config_snapshothistory (size_t count=0) const
 Get configuration history snapshots.
 
VoidResult rollback (uint64_t target_version)
 Rollback to a previous configuration version.
 
const std::string & config_path () const
 Get the path to the configuration file being watched.
 
std::vector< config_change_eventrecent_events (size_t count=10) const
 Get recent change events.
 

Private Member Functions

VoidResult init_platform_watcher ()
 Initialize platform-specific file watching.
 
void signal_watcher_shutdown ()
 Signal the watch thread to wake up and exit.
 
void cleanup_platform_watcher ()
 Cleanup platform-specific resources (call after thread join).
 
void watch_loop ()
 Main watch loop - dispatches to platform-specific implementation.
 
VoidResult do_reload ()
 Perform the actual configuration reload.
 
void add_to_history (const unified_config &config)
 Add a configuration to history.
 
void add_event (const config_change_event &event)
 Add a change event to the event log.
 
void notify_change (const unified_config &old_cfg, const unified_config &new_cfg)
 Notify all registered change callbacks.
 
void notify_error (const std::string &message)
 Notify all registered error callbacks.
 

Static Private Member Functions

static std::vector< std::string > get_changed_fields (const unified_config &old_cfg, const unified_config &new_cfg)
 Compare two configurations and return changed field paths.
 

Private Attributes

std::string config_path_
 
unified_config current_config_
 
std::shared_mutex config_mutex_
 
std::atomic< uint64_t > version_
 
size_t max_history_
 
std::mutex history_mutex_
 
std::deque< config_snapshothistory_
 
std::mutex events_mutex_
 
std::deque< config_change_eventevents_
 
std::mutex callbacks_mutex_
 
std::vector< change_callbackchange_callbacks_
 
std::vector< error_callbackerror_callbacks_
 
std::atomic< bool > running_
 
std::thread watch_thread_
 

Detailed Description

Monitors configuration files for changes and supports hot-reload.

The config_watcher provides automatic configuration reloading when the configuration file is modified. It supports:

  • Platform-native file watching
  • Callback notifications for configuration changes
  • Version tracking and history
  • Automatic rollback on validation failures

Usage Example:

config_watcher watcher("config.yaml");
watcher.on_change([](const unified_config& old_cfg,
const unified_config& new_cfg) {
std::cout << "Configuration updated\n";
// Apply changes...
});
watcher.start();
// ... application runs ...
watcher.stop();
Monitors configuration files for changes and supports hot-reload.
Root configuration structure for the unified system.
Examples
config_watcher_example.cpp.

Definition at line 143 of file config_watcher.h.

Member Typedef Documentation

◆ change_callback

Initial value:
std::function<void(const unified_config& old_config,
const unified_config& new_config)>

Callback type for configuration changes.

Definition at line 146 of file config_watcher.h.

◆ error_callback

using kcenon::common::config::config_watcher::error_callback = std::function<void(const std::string& error_message)>

Callback type for reload errors.

Definition at line 150 of file config_watcher.h.

Constructor & Destructor Documentation

◆ config_watcher() [1/3]

kcenon::common::config::config_watcher::config_watcher ( const std::string & config_path,
size_t max_history = 10 )
inlineexplicit

Construct a config_watcher for the specified file.

Parameters
config_pathPath to the YAML configuration file
max_historyMaximum number of configuration snapshots to keep (default: 10)

Definition at line 157 of file config_watcher.h.

159 , version_(0)
160 , max_history_(max_history)
161 , running_(false)
162#if defined(__linux__)
163 , inotify_fd_(-1)
164 , watch_fd_(-1)
165 , shutdown_fd_(-1)
166#elif defined(__APPLE__) || defined(__FreeBSD__)
167 , kqueue_fd_(-1)
168 , file_fd_(-1)
169#elif defined(_WIN32)
170 , dir_handle_(INVALID_HANDLE_VALUE)
171#endif
172 {
173 // Load initial configuration
174 auto result = config_loader::load(config_path_);
175 if (result.is_ok()) {
176 current_config_ = result.value();
178 } else {
179 // Start with defaults if file doesn't exist or can't be loaded
182 }
183 }
static unified_config defaults()
Get default configuration.
static Result< unified_config > load(const std::string &path)
Load configuration from a YAML file.
const std::string & config_path() const
Get the path to the configuration file being watched.
void add_to_history(const unified_config &config)
Add a configuration to history.

References add_to_history(), config_path_, current_config_, kcenon::common::config::config_loader::defaults(), and kcenon::common::config::config_loader::load().

Here is the call graph for this function:

◆ ~config_watcher()

kcenon::common::config::config_watcher::~config_watcher ( )
inline

Destructor. Automatically stops watching if running.

Definition at line 188 of file config_watcher.h.

188 {
189 stop();
190 }
void stop()
Stop watching the configuration file.

References stop().

Here is the call graph for this function:

◆ config_watcher() [2/3]

kcenon::common::config::config_watcher::config_watcher ( const config_watcher & )
delete

◆ config_watcher() [3/3]

kcenon::common::config::config_watcher::config_watcher ( config_watcher && )
delete

Member Function Documentation

◆ add_event()

void kcenon::common::config::config_watcher::add_event ( const config_change_event & event)
inlineprivate

Add a change event to the event log.

Definition at line 974 of file config_watcher.h.

974 {
975 std::lock_guard<std::mutex> lock(events_mutex_);
976 events_.push_back(event);
977
978 // Keep only recent events
979 while (events_.size() > 100) {
980 events_.pop_front();
981 }
982 }
std::deque< config_change_event > events_

◆ add_to_history()

void kcenon::common::config::config_watcher::add_to_history ( const unified_config & config)
inlineprivate

Add a configuration to history.

Definition at line 955 of file config_watcher.h.

955 {
956 std::lock_guard<std::mutex> lock(history_mutex_);
957
958 config_snapshot snapshot;
959 snapshot.version = version_.load();
960 snapshot.timestamp = std::chrono::system_clock::now();
961 snapshot.config = config;
962
963 history_.push_back(snapshot);
964
965 // Trim history if needed
966 while (history_.size() > max_history_) {
967 history_.pop_front();
968 }
969 }
std::deque< config_snapshot > history_

References kcenon::common::config::config_snapshot::config, kcenon::common::config::config_snapshot::timestamp, and kcenon::common::config::config_snapshot::version.

Referenced by config_watcher().

Here is the caller graph for this function:

◆ cleanup_platform_watcher()

void kcenon::common::config::config_watcher::cleanup_platform_watcher ( )
inlineprivate

Cleanup platform-specific resources (call after thread join).

Definition at line 424 of file config_watcher.h.

424 {
425#if defined(__linux__)
426 cleanup_inotify();
427#elif defined(__APPLE__) || defined(__FreeBSD__)
428 cleanup_kqueue();
429#elif defined(_WIN32)
430 cleanup_win32_watcher();
431#endif
432 }

Referenced by stop().

Here is the caller graph for this function:

◆ config_path()

const std::string & kcenon::common::config::config_watcher::config_path ( ) const
inline

Get the path to the configuration file being watched.

Returns
Configuration file path

Definition at line 357 of file config_watcher.h.

357 {
358 return config_path_;
359 }

References config_path_.

◆ current()

const unified_config & kcenon::common::config::config_watcher::current ( ) const
inline

Get the current configuration.

Returns
Reference to the current unified_config

Definition at line 289 of file config_watcher.h.

289 {
290 std::shared_lock<std::shared_mutex> lock(config_mutex_);
291 return current_config_;
292 }

References config_mutex_, and current_config_.

◆ do_reload()

VoidResult kcenon::common::config::config_watcher::do_reload ( )
inlineprivate

Perform the actual configuration reload.

Definition at line 815 of file config_watcher.h.

815 {
816 auto result = config_loader::load(config_path_);
817
818 config_change_event event;
819 event.timestamp = std::chrono::system_clock::now();
820 event.version = version_.load() + 1;
821
822 if (result.is_err()) {
823 event.success = false;
824 event.error_message = result.error().message;
825 add_event(event);
826 notify_error(result.error().message);
827 return make_error<std::monostate>(result.error());
828 }
829
830 unified_config new_config = result.value();
831
832 // Validate the new configuration
833 auto validation_result = config_loader::validate(new_config);
834 if (validation_result.is_err()) {
835 event.success = false;
836 event.error_message = validation_result.error().message;
837 add_event(event);
838 notify_error("Validation failed: " + validation_result.error().message);
841 "Configuration validation failed: " + validation_result.error().message,
842 "config_watcher"
843 );
844 }
845
846 // Get changed fields
847 std::unique_lock<std::shared_mutex> lock(config_mutex_);
848 event.changed_fields = get_changed_fields(current_config_, new_config);
849
850 // Check if any non-hot-reloadable fields changed
851 std::vector<std::string> non_reloadable_changes;
852 for (const auto& field : event.changed_fields) {
853 if (!is_hot_reloadable(field)) {
854 non_reloadable_changes.push_back(field);
855 }
856 }
857
858 // Update configuration
859 unified_config old_config = current_config_;
860 current_config_ = new_config;
861 version_.fetch_add(1);
862 event.version = version_.load();
863 event.success = true;
864
865 // Add to history
866 add_to_history(new_config);
867
868 lock.unlock();
869
870 // Record event
871 add_event(event);
872
873 // Notify callbacks
874 notify_change(old_config, new_config);
875
876 return VoidResult::ok({});
877 }
static Result< T > ok(U &&value)
Create a successful result with value (static factory)
Definition core.h:223
static VoidResult validate(const unified_config &config)
Validate a configuration.
static std::vector< std::string > get_changed_fields(const unified_config &old_cfg, const unified_config &new_cfg)
Compare two configurations and return changed field paths.
void notify_change(const unified_config &old_cfg, const unified_config &new_cfg)
Notify all registered change callbacks.
void add_event(const config_change_event &event)
Add a change event to the event log.
void notify_error(const std::string &message)
Notify all registered error callbacks.
bool is_hot_reloadable(const std::string &field_path)
Check if a configuration field supports hot-reload.
Result< T > make_error(int code, const std::string &message, const std::string &module="")
Create an error result with code and message.
Definition utilities.h:91

References kcenon::common::config::is_hot_reloadable(), kcenon::common::config::config_loader::load(), kcenon::common::make_error(), kcenon::common::Result< T >::ok(), kcenon::common::config::config_loader::validate(), and kcenon::common::config::watcher_error_codes::validation_failed.

Referenced by reload().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ get_changed_fields()

static std::vector< std::string > kcenon::common::config::config_watcher::get_changed_fields ( const unified_config & old_cfg,
const unified_config & new_cfg )
inlinestaticprivate

Compare two configurations and return changed field paths.

Definition at line 882 of file config_watcher.h.

885 {
886 std::vector<std::string> changes;
887
888 // Thread config
889 if (old_cfg.thread.pool_size != new_cfg.thread.pool_size) {
890 changes.push_back("thread.pool_size");
891 }
892 if (old_cfg.thread.queue_type != new_cfg.thread.queue_type) {
893 changes.push_back("thread.queue_type");
894 }
895 if (old_cfg.thread.max_queue_size != new_cfg.thread.max_queue_size) {
896 changes.push_back("thread.max_queue_size");
897 }
898
899 // Logger config
900 if (old_cfg.logger.level != new_cfg.logger.level) {
901 changes.push_back("logger.level");
902 }
903 if (old_cfg.logger.async != new_cfg.logger.async) {
904 changes.push_back("logger.async");
905 }
906 if (old_cfg.logger.buffer_size != new_cfg.logger.buffer_size) {
907 changes.push_back("logger.buffer_size");
908 }
909 if (old_cfg.logger.file_path != new_cfg.logger.file_path) {
910 changes.push_back("logger.file_path");
911 }
912 if (old_cfg.logger.writers != new_cfg.logger.writers) {
913 changes.push_back("logger.writers");
914 }
915
916 // Monitoring config
917 if (old_cfg.monitoring.enabled != new_cfg.monitoring.enabled) {
918 changes.push_back("monitoring.enabled");
919 }
920 if (old_cfg.monitoring.metrics_interval != new_cfg.monitoring.metrics_interval) {
921 changes.push_back("monitoring.metrics_interval");
922 }
923 if (old_cfg.monitoring.tracing.enabled != new_cfg.monitoring.tracing.enabled) {
924 changes.push_back("monitoring.tracing.enabled");
925 }
926 if (old_cfg.monitoring.tracing.sampling_rate != new_cfg.monitoring.tracing.sampling_rate) {
927 changes.push_back("monitoring.tracing.sampling_rate");
928 }
929
930 // Database config
931 if (old_cfg.database.backend != new_cfg.database.backend) {
932 changes.push_back("database.backend");
933 }
934 if (old_cfg.database.connection_string != new_cfg.database.connection_string) {
935 changes.push_back("database.connection_string");
936 }
937
938 // Network config
939 if (old_cfg.network.tls.enabled != new_cfg.network.tls.enabled) {
940 changes.push_back("network.tls.enabled");
941 }
942 if (old_cfg.network.compression != new_cfg.network.compression) {
943 changes.push_back("network.compression");
944 }
945 if (old_cfg.network.buffer_size != new_cfg.network.buffer_size) {
946 changes.push_back("network.buffer_size");
947 }
948
949 return changes;
950 }

References kcenon::common::config::logger_config::async, kcenon::common::config::database_config::backend, kcenon::common::config::logger_config::buffer_size, kcenon::common::config::network_config::buffer_size, kcenon::common::config::network_config::compression, kcenon::common::config::database_config::connection_string, kcenon::common::config::unified_config::database, kcenon::common::config::monitoring_config::enabled, kcenon::common::config::tls_config::enabled, kcenon::common::config::tracing_config::enabled, kcenon::common::config::logger_config::file_path, kcenon::common::config::logger_config::level, kcenon::common::config::unified_config::logger, kcenon::common::config::thread_config::max_queue_size, kcenon::common::config::monitoring_config::metrics_interval, kcenon::common::config::unified_config::monitoring, kcenon::common::config::unified_config::network, kcenon::common::config::thread_config::pool_size, kcenon::common::config::thread_config::queue_type, kcenon::common::config::tracing_config::sampling_rate, kcenon::common::config::unified_config::thread, kcenon::common::config::network_config::tls, kcenon::common::config::monitoring_config::tracing, and kcenon::common::config::logger_config::writers.

◆ history()

std::vector< config_snapshot > kcenon::common::config::config_watcher::history ( size_t count = 0) const
inline

Get configuration history snapshots.

Parameters
countMaximum number of snapshots to return (default: all)
Returns
Vector of configuration snapshots, newest first

Definition at line 307 of file config_watcher.h.

307 {
308 std::lock_guard<std::mutex> lock(history_mutex_);
309
310 if (count == 0 || count > history_.size()) {
311 return {history_.rbegin(), history_.rend()};
312 }
313
314 std::vector<config_snapshot> result;
315 result.reserve(count);
316 auto it = history_.rbegin();
317 for (size_t i = 0; i < count && it != history_.rend(); ++i, ++it) {
318 result.push_back(*it);
319 }
320 return result;
321 }

References history_, and history_mutex_.

◆ init_platform_watcher()

VoidResult kcenon::common::config::config_watcher::init_platform_watcher ( )
inlineprivate

Initialize platform-specific file watching.

Definition at line 386 of file config_watcher.h.

386 {
387#if defined(__linux__)
388 return init_inotify();
389#elif defined(__APPLE__) || defined(__FreeBSD__)
390 return init_kqueue();
391#elif defined(_WIN32)
392 return init_win32_watcher();
393#else
396 "File watching not supported on this platform",
397 "config_watcher"
398 );
399#endif
400 }

References kcenon::common::make_error(), and kcenon::common::config::watcher_error_codes::platform_not_supported.

Referenced by start().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ is_running()

bool kcenon::common::config::config_watcher::is_running ( ) const
inline

Check if the watcher is currently running.

Returns
true if watching, false otherwise
Examples
config_watcher_example.cpp.

Definition at line 248 of file config_watcher.h.

248 {
249 return running_.load();
250 }

References running_.

Referenced by main().

Here is the caller graph for this function:

◆ notify_change()

void kcenon::common::config::config_watcher::notify_change ( const unified_config & old_cfg,
const unified_config & new_cfg )
inlineprivate

Notify all registered change callbacks.

Definition at line 987 of file config_watcher.h.

987 {
988 std::lock_guard<std::mutex> lock(callbacks_mutex_);
989 for (const auto& callback : change_callbacks_) {
990 try {
991 callback(old_cfg, new_cfg);
992 } catch (...) {
993 // Ignore callback exceptions
994 }
995 }
996 }
std::vector< change_callback > change_callbacks_

Referenced by rollback().

Here is the caller graph for this function:

◆ notify_error()

void kcenon::common::config::config_watcher::notify_error ( const std::string & message)
inlineprivate

Notify all registered error callbacks.

Definition at line 1001 of file config_watcher.h.

1001 {
1002 std::lock_guard<std::mutex> lock(callbacks_mutex_);
1003 for (const auto& callback : error_callbacks_) {
1004 try {
1005 callback(message);
1006 } catch (...) {
1007 // Ignore callback exceptions
1008 }
1009 }
1010 }
std::vector< error_callback > error_callbacks_

◆ on_change()

void kcenon::common::config::config_watcher::on_change ( change_callback callback)
inline

Register a callback for configuration changes.

The callback will be invoked whenever the configuration is successfully reloaded. Multiple callbacks can be registered.

Parameters
callbackFunction to call on configuration change
Examples
config_watcher_example.cpp.

Definition at line 260 of file config_watcher.h.

260 {
261 std::lock_guard<std::mutex> lock(callbacks_mutex_);
262 change_callbacks_.push_back(std::move(callback));
263 }

References callbacks_mutex_, and change_callbacks_.

Referenced by main().

Here is the caller graph for this function:

◆ on_error()

void kcenon::common::config::config_watcher::on_error ( error_callback callback)
inline

Register a callback for reload errors.

The callback will be invoked when a reload attempt fails.

Parameters
callbackFunction to call on reload error
Examples
config_watcher_example.cpp.

Definition at line 272 of file config_watcher.h.

272 {
273 std::lock_guard<std::mutex> lock(callbacks_mutex_);
274 error_callbacks_.push_back(std::move(callback));
275 }

References callbacks_mutex_, and error_callbacks_.

Referenced by main().

Here is the caller graph for this function:

◆ operator=() [1/2]

config_watcher & kcenon::common::config::config_watcher::operator= ( config_watcher && )
delete

◆ operator=() [2/2]

config_watcher & kcenon::common::config::config_watcher::operator= ( const config_watcher & )
delete

◆ recent_events()

std::vector< config_change_event > kcenon::common::config::config_watcher::recent_events ( size_t count = 10) const
inline

Get recent change events.

Parameters
countMaximum number of events to return
Returns
Vector of recent change events

Definition at line 366 of file config_watcher.h.

366 {
367 std::lock_guard<std::mutex> lock(events_mutex_);
368
369 if (count == 0 || count > events_.size()) {
370 return {events_.rbegin(), events_.rend()};
371 }
372
373 std::vector<config_change_event> result;
374 result.reserve(count);
375 auto it = events_.rbegin();
376 for (size_t i = 0; i < count && it != events_.rend(); ++i, ++it) {
377 result.push_back(*it);
378 }
379 return result;
380 }

References events_, and events_mutex_.

◆ reload()

VoidResult kcenon::common::config::config_watcher::reload ( )
inline

Manually trigger a configuration reload.

Returns
VoidResult indicating success or failure
Examples
config_watcher_example.cpp.

Definition at line 281 of file config_watcher.h.

281 {
282 return do_reload();
283 }
VoidResult do_reload()
Perform the actual configuration reload.

References do_reload().

Referenced by main().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ rollback()

VoidResult kcenon::common::config::config_watcher::rollback ( uint64_t target_version)
inline

Rollback to a previous configuration version.

Parameters
target_versionVersion number to rollback to
Returns
VoidResult indicating success or failure

Definition at line 328 of file config_watcher.h.

328 {
329 std::lock_guard<std::mutex> lock(history_mutex_);
330
331 for (const auto& snapshot : history_) {
332 if (snapshot.version == target_version) {
333 std::unique_lock<std::shared_mutex> config_lock(config_mutex_);
334 unified_config old_config = current_config_;
335 current_config_ = snapshot.config;
336 version_.fetch_add(1);
337
338 // Notify callbacks
339 config_lock.unlock();
340 notify_change(old_config, current_config_);
341
342 return VoidResult::ok({});
343 }
344 }
345
348 "Target version not found in history: " + std::to_string(target_version),
349 "config_watcher"
350 );
351 }

References config_mutex_, current_config_, history_, history_mutex_, kcenon::common::make_error(), notify_change(), kcenon::common::Result< T >::ok(), kcenon::common::config::watcher_error_codes::rollback_failed, and version_.

Here is the call graph for this function:

◆ signal_watcher_shutdown()

void kcenon::common::config::config_watcher::signal_watcher_shutdown ( )
inlineprivate

Signal the watch thread to wake up and exit.

Definition at line 405 of file config_watcher.h.

405 {
406#if defined(__linux__)
407 signal_eventfd();
408#elif defined(__APPLE__) || defined(__FreeBSD__)
409 // Closing kqueue wakes up kevent() with an error
410 int kq = kqueue_fd_.exchange(-1);
411 if (kq >= 0) {
412 close(kq);
413 }
414#elif defined(_WIN32)
415 if (dir_handle_ != INVALID_HANDLE_VALUE) {
416 CancelIo(dir_handle_);
417 }
418#endif
419 }

Referenced by stop().

Here is the caller graph for this function:

◆ start()

VoidResult kcenon::common::config::config_watcher::start ( )
inline

Start watching the configuration file for changes.

Returns
VoidResult indicating success or failure
Examples
config_watcher_example.cpp.

Definition at line 202 of file config_watcher.h.

202 {
203 if (running_.load()) {
206 "Config watcher is already running",
207 "config_watcher"
208 );
209 }
210
211 auto init_result = init_platform_watcher();
212 if (init_result.is_err()) {
213 return init_result;
214 }
215
216 running_.store(true);
217 watch_thread_ = std::thread([this]() { watch_loop(); });
218
219 return VoidResult::ok({});
220 }
VoidResult init_platform_watcher()
Initialize platform-specific file watching.
void watch_loop()
Main watch loop - dispatches to platform-specific implementation.

References kcenon::common::config::watcher_error_codes::already_running, init_platform_watcher(), kcenon::common::make_error(), kcenon::common::Result< T >::ok(), running_, watch_loop(), and watch_thread_.

Referenced by main().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ stop()

void kcenon::common::config::config_watcher::stop ( )
inline

Stop watching the configuration file.

Examples
config_watcher_example.cpp.

Definition at line 225 of file config_watcher.h.

225 {
226 if (!running_.load()) {
227 return;
228 }
229
230 running_.store(false);
231
232 // Signal the watch thread to wake up
234
235 // Wait for the thread to exit before closing file descriptors
236 if (watch_thread_.joinable()) {
237 watch_thread_.join();
238 }
239
240 // Thread has exited; safe to close platform resources
242 }
void signal_watcher_shutdown()
Signal the watch thread to wake up and exit.
void cleanup_platform_watcher()
Cleanup platform-specific resources (call after thread join).

References cleanup_platform_watcher(), running_, signal_watcher_shutdown(), and watch_thread_.

Referenced by main(), and ~config_watcher().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ version()

uint64_t kcenon::common::config::config_watcher::version ( ) const
inline

Get the current configuration version.

Returns
Current version number

Definition at line 298 of file config_watcher.h.

298 {
299 return version_.load();
300 }

References version_.

◆ watch_loop()

void kcenon::common::config::config_watcher::watch_loop ( )
inlineprivate

Main watch loop - dispatches to platform-specific implementation.

Definition at line 802 of file config_watcher.h.

802 {
803#if defined(__linux__)
804 watch_loop_linux();
805#elif defined(__APPLE__) || defined(__FreeBSD__)
806 watch_loop_kqueue();
807#elif defined(_WIN32)
808 watch_loop_win32();
809#endif
810 }

Referenced by start().

Here is the caller graph for this function:

Member Data Documentation

◆ callbacks_mutex_

std::mutex kcenon::common::config::config_watcher::callbacks_mutex_
private

Definition at line 1030 of file config_watcher.h.

Referenced by on_change(), and on_error().

◆ change_callbacks_

std::vector<change_callback> kcenon::common::config::config_watcher::change_callbacks_
private

Definition at line 1031 of file config_watcher.h.

Referenced by on_change().

◆ config_mutex_

std::shared_mutex kcenon::common::config::config_watcher::config_mutex_
mutableprivate

Definition at line 1015 of file config_watcher.h.

Referenced by current(), and rollback().

◆ config_path_

std::string kcenon::common::config::config_watcher::config_path_
private

Definition at line 1013 of file config_watcher.h.

Referenced by config_path(), and config_watcher().

◆ current_config_

unified_config kcenon::common::config::config_watcher::current_config_
private

Definition at line 1014 of file config_watcher.h.

Referenced by config_watcher(), current(), and rollback().

◆ error_callbacks_

std::vector<error_callback> kcenon::common::config::config_watcher::error_callbacks_
private

Definition at line 1032 of file config_watcher.h.

Referenced by on_error().

◆ events_

std::deque<config_change_event> kcenon::common::config::config_watcher::events_
private

Definition at line 1027 of file config_watcher.h.

Referenced by recent_events().

◆ events_mutex_

std::mutex kcenon::common::config::config_watcher::events_mutex_
mutableprivate

Definition at line 1026 of file config_watcher.h.

Referenced by recent_events().

◆ history_

std::deque<config_snapshot> kcenon::common::config::config_watcher::history_
private

Definition at line 1023 of file config_watcher.h.

Referenced by history(), and rollback().

◆ history_mutex_

std::mutex kcenon::common::config::config_watcher::history_mutex_
mutableprivate

Definition at line 1022 of file config_watcher.h.

Referenced by history(), and rollback().

◆ max_history_

size_t kcenon::common::config::config_watcher::max_history_
private

Definition at line 1021 of file config_watcher.h.

◆ running_

std::atomic<bool> kcenon::common::config::config_watcher::running_
private

Definition at line 1035 of file config_watcher.h.

Referenced by is_running(), start(), and stop().

◆ version_

std::atomic<uint64_t> kcenon::common::config::config_watcher::version_
private

Definition at line 1018 of file config_watcher.h.

Referenced by rollback(), and version().

◆ watch_thread_

std::thread kcenon::common::config::config_watcher::watch_thread_
private

Definition at line 1036 of file config_watcher.h.

Referenced by start(), and stop().


The documentation for this class was generated from the following file: