57 lines
1.2 KiB
C++
57 lines
1.2 KiB
C++
#include "ConfigManager.h"
|
|
|
|
ConfigManager& ConfigManager::Instance()
|
|
{
|
|
static ConfigManager inst;
|
|
return inst;
|
|
}
|
|
|
|
ConfigManager::ConfigManager()
|
|
{
|
|
IDroneScrewCtrlConfig::CreateInstance(&m_pConfig);
|
|
}
|
|
|
|
ConfigManager::~ConfigManager()
|
|
{
|
|
if (m_pConfig)
|
|
{
|
|
delete m_pConfig;
|
|
m_pConfig = nullptr;
|
|
}
|
|
}
|
|
|
|
bool ConfigManager::Initialize(const std::string& configPath)
|
|
{
|
|
std::lock_guard<std::mutex> lk(m_mutex);
|
|
m_path = configPath;
|
|
if (!m_pConfig) return false;
|
|
int r = m_pConfig->LoadConfig(m_path, m_cache);
|
|
return r == DRONE_CFG_OK;
|
|
}
|
|
|
|
bool ConfigManager::Reload()
|
|
{
|
|
std::lock_guard<std::mutex> lk(m_mutex);
|
|
if (!m_pConfig) return false;
|
|
return m_pConfig->LoadConfig(m_path, m_cache) == DRONE_CFG_OK;
|
|
}
|
|
|
|
bool ConfigManager::Save()
|
|
{
|
|
std::lock_guard<std::mutex> lk(m_mutex);
|
|
if (!m_pConfig) return false;
|
|
return m_pConfig->SaveConfig(m_path, m_cache);
|
|
}
|
|
|
|
DroneScrewCtrlConfigResult ConfigManager::GetConfig() const
|
|
{
|
|
std::lock_guard<std::mutex> lk(m_mutex);
|
|
return m_cache;
|
|
}
|
|
|
|
void ConfigManager::SetConfig(const DroneScrewCtrlConfigResult& cfg)
|
|
{
|
|
std::lock_guard<std::mutex> lk(m_mutex);
|
|
m_cache = cfg;
|
|
}
|