-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
97 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
#include "ConfigMgr.h" | ||
|
||
ConfigMgr& ConfigMgr::get_instance() | ||
{ | ||
static ConfigMgr instance; | ||
return instance; | ||
} | ||
|
||
bool ConfigMgr::init() | ||
{ | ||
if (!_control.load()) { | ||
std::cerr << "Failed to load control config" << std::endl; | ||
return false; | ||
} | ||
if (!_device.load()) { | ||
std::cerr << "Failed to load device config" << std::endl; | ||
return false; | ||
} | ||
if (!_tasks.load()) { | ||
std::cerr << "Failed to load tasks config" << std::endl; | ||
return false; | ||
} | ||
return true; | ||
} | ||
|
||
bool ConfigMgr::set_config_target(ConfigOption option, std::string target) | ||
{ | ||
switch (option) { | ||
case ConfigOption_Control: | ||
_control.set_target(target); | ||
break; | ||
case ConfigOption_Device: | ||
_device.set_target(target); | ||
break; | ||
case ConfigOption_Tasks: | ||
_tasks.set_target(target); | ||
break; | ||
default: | ||
return false; | ||
} | ||
return true; | ||
} | ||
|
||
ControlConfig& ConfigMgr::get_control_config() | ||
{ | ||
return _control; | ||
} | ||
|
||
DeviceConfig& ConfigMgr::get_device_config() | ||
{ | ||
return _device; | ||
} | ||
|
||
TasksConfig& ConfigMgr::get_tasks_config() | ||
{ | ||
return _tasks; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
#pragma once | ||
|
||
#include <iostream> | ||
|
||
#include "ControlConfig.h" | ||
#include "DeviceConfig.h" | ||
#include "TasksConfig.h" | ||
|
||
enum ConfigOption | ||
{ | ||
ConfigOption_Control = 0, | ||
ConfigOption_Device = 1, | ||
ConfigOption_Tasks = 2 | ||
}; | ||
|
||
class ConfigMgr | ||
{ | ||
public: | ||
static ConfigMgr& get_instance(); | ||
|
||
public: | ||
bool init(); | ||
bool set_config_target(ConfigOption option, std::string target); | ||
|
||
public: | ||
ControlConfig& get_control_config(); | ||
DeviceConfig& get_device_config(); | ||
TasksConfig& get_tasks_config(); | ||
|
||
private: | ||
ConfigMgr() = default; | ||
~ConfigMgr() = default; | ||
|
||
private: | ||
ControlConfig _control; | ||
DeviceConfig _device; | ||
TasksConfig _tasks; | ||
}; |