hunting/middleware/IpcConfig/src/IpcConfig.h

99 lines
4.0 KiB
C++

/*
* Copyright (c) 2023 Fancy Code.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef IPCCONFIG_H
#define IPCCONFIG_H
#include "Config.h"
#include "IIpcConfig.h"
#include "StatusCode.h"
#include <map>
#include <memory>
constexpr bool CONFIG_HAS_CHANGED = true;
constexpr bool CONFIG_HAS_NOT_CHANGED = false;
typedef char CHAR_STRING[256];
typedef struct Config_s
{
bool storageLoopSwitch;
bool factoryReset;
bool formattingSDCard;
int workMode;
int continuousShot;
int burstPhotoInterval;
int videoSize;
int infraredIampPower;
int delayed;
int pirSensitivity;
double imageSize;
short testShort;
char testChar;
long testLong;
long long testLLong;
float testFloat;
CHAR_STRING testString;
} Config_s;
class MapInt
{
public:
MapInt() = default;
~MapInt() = default;
};
class IpcConfig : public IIpcConfig
{
public:
IpcConfig();
virtual ~IpcConfig() = default;
const StatusCode Init(void) override;
const StatusCode UnInit(void) override;
const StatusCode ConfigFileSave(void) override;
const int GetInt(const IpcConfigKey &key) override;
void SetInt(const IpcConfigKey &key, const int &value) override;
const short GetShort(const IpcConfigKey &key) override;
void SetShort(const IpcConfigKey &key, const short &value) override;
const long GetLong(const IpcConfigKey &key) override;
void SetLong(const IpcConfigKey &key, const long &value) override;
const long long GetLLong(const IpcConfigKey &key) override;
void SetLLong(const IpcConfigKey &key, const long long &value) override;
const char GetChar(const IpcConfigKey &key) override;
void SetChar(const IpcConfigKey &key, const char &character) override;
const float GetFloat(const IpcConfigKey &key) override;
void SetFloat(const IpcConfigKey &key, const float &value) override;
const double GetDouble(const IpcConfigKey &key) override;
void SetDouble(const IpcConfigKey &key, const double &value) override;
const long double GetLongDouble(const IpcConfigKey &key) override;
void SetLongDouble(const IpcConfigKey &key, const long double &value) override;
const bool GetBool(const IpcConfigKey &key) override;
void SetBool(const IpcConfigKey &key, const bool &value) override;
const std::string GetString(const IpcConfigKey &key) override;
void SetString(const IpcConfigKey &key, const std::string string) override;
private:
void ReadAllConfigParameters(void);
private:
bool mCfgChanged;
VConfig *mCfg;
Config_s mAllData;
std::map<IpcConfigKey, std::map<std::string, std::reference_wrapper<int>>> mCfgMapInt;
std::map<IpcConfigKey, std::map<std::string, std::reference_wrapper<short>>> mCfgMapShort;
std::map<IpcConfigKey, std::map<std::string, std::reference_wrapper<long>>> mCfgMapLong;
std::map<IpcConfigKey, std::map<std::string, std::reference_wrapper<long long>>> mCfgMapLLong;
std::map<IpcConfigKey, std::map<std::string, std::reference_wrapper<char>>> mCfgMapChar;
std::map<IpcConfigKey, std::map<std::string, std::reference_wrapper<float>>> mCfgMapFloat;
std::map<IpcConfigKey, std::map<std::string, std::reference_wrapper<double>>> mCfgMapDouble;
std::map<IpcConfigKey, std::reference_wrapper<long double>> mCfgMapLongDouble;
std::map<IpcConfigKey, std::map<std::string, std::reference_wrapper<bool>>> mCfgMapBool;
std::map<IpcConfigKey, std::map<std::string, std::reference_wrapper<CHAR_STRING>>> mCfgMapString;
};
#endif