60 lines
1.3 KiB
C++
60 lines
1.3 KiB
C++
#ifndef CONFIG_MANAGER_H
|
|
#define CONFIG_MANAGER_H
|
|
|
|
#include "common.h"
|
|
#include <string>
|
|
#include <vector>
|
|
#include <atomic>
|
|
#include <thread>
|
|
#include <functional>
|
|
#include <mutex>
|
|
#include <filesystem>
|
|
|
|
class ConfigManager {
|
|
public:
|
|
ConfigManager(const std::string& config_path);
|
|
~ConfigManager();
|
|
|
|
// Load configuration from file
|
|
bool LoadConfig();
|
|
|
|
// Get parsed rules
|
|
std::vector<DomainRule> GetRules() const;
|
|
|
|
// Start monitoring thread for live reload
|
|
void StartMonitoring(std::function<void(const std::vector<DomainRule>&)> callback);
|
|
|
|
// Stop monitoring thread
|
|
void StopMonitoring();
|
|
|
|
// Get configuration values
|
|
std::string GetLogFile() const;
|
|
bool IsLoggingEnabled() const;
|
|
|
|
private:
|
|
std::string config_path_;
|
|
std::vector<DomainRule> rules_;
|
|
std::atomic<bool> monitoring_;
|
|
std::thread monitor_thread_;
|
|
|
|
// Last modification time of config file
|
|
std::filesystem::file_time_type last_modified_;
|
|
|
|
// Callback for rule updates
|
|
std::function<void(const std::vector<DomainRule>&)> update_callback_;
|
|
|
|
// Configuration values
|
|
std::string log_file_;
|
|
bool logging_enabled_;
|
|
|
|
mutable std::mutex config_mutex_;
|
|
|
|
// Monitoring thread function
|
|
void MonitorFileChanges();
|
|
|
|
// Parse JSON configuration
|
|
bool ParseConfig();
|
|
};
|
|
|
|
#endif // CONFIG_MANAGER_H
|