38 lines
1.8 KiB
C++
38 lines
1.8 KiB
C++
#ifndef __APPLICATIONSETTINGS_H__
|
|
#define __APPLICATIONSETTINGS_H__
|
|
|
|
#include <boost/asio/steady_timer.hpp>
|
|
#include <boost/property_tree/ptree.hpp>
|
|
|
|
class ApplicationSettings {
|
|
#define BUILD_SETTING_FIELD(Category, Type, Name, DefaultValue) \
|
|
inline void set##Name(const Type &value) { \
|
|
std::lock_guard locker(m_mutex); \
|
|
m_ptree.put(#Category "." #Name, value); \
|
|
m_needSave = true; \
|
|
} \
|
|
inline Type get##Name() const { \
|
|
std::lock_guard locker(m_mutex); \
|
|
return m_ptree.get<Type>(#Category "." #Name, DefaultValue); \
|
|
}
|
|
|
|
#define BUILD_STATUS(Type, Name, DefaultValue) BUILD_SETTING_FIELD(Status, Type, Name, DefaultValue)
|
|
|
|
public:
|
|
ApplicationSettings(const std::string &path);
|
|
void startCheckInterval(boost::asio::io_context &ioContext, uint32_t seconds);
|
|
|
|
protected:
|
|
void run();
|
|
|
|
boost::property_tree::ptree m_ptree;
|
|
bool m_needSave = false;
|
|
mutable std::mutex m_mutex;
|
|
|
|
private:
|
|
std::string m_path;
|
|
std::unique_ptr<boost::asio::steady_timer> m_timer;
|
|
uint32_t m_interval;
|
|
};
|
|
|
|
#endif // __APPLICATIONSETTINGS_H__
|