2 |
andreas |
1 |
/*
|
21 |
andreas |
2 |
* Copyright (C) 2020, 2021 by Andreas Theofilu <andreas@theosys.at>
|
2 |
andreas |
3 |
*
|
|
|
4 |
* This program is free software; you can redistribute it and/or modify
|
|
|
5 |
* it under the terms of the GNU General Public License as published by
|
|
|
6 |
* the Free Software Foundation; either version 3 of the License, or
|
|
|
7 |
* (at your option) any later version.
|
|
|
8 |
*
|
|
|
9 |
* This program is distributed in the hope that it will be useful,
|
|
|
10 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
11 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
12 |
* GNU General Public License for more details.
|
|
|
13 |
*
|
|
|
14 |
* You should have received a copy of the GNU General Public License
|
|
|
15 |
* along with this program; if not, write to the Free Software Foundation,
|
|
|
16 |
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
|
|
17 |
*/
|
|
|
18 |
#ifndef __TCONFIG_H__
|
|
|
19 |
#define __TCONFIG_H__
|
|
|
20 |
|
|
|
21 |
#include <string>
|
|
|
22 |
#include <vector>
|
|
|
23 |
#include <algorithm>
|
|
|
24 |
#include "terror.h"
|
|
|
25 |
|
|
|
26 |
#define V_MAJOR 1
|
|
|
27 |
#define V_MINOR 0
|
|
|
28 |
#define V_PATCH 0
|
|
|
29 |
|
21 |
andreas |
30 |
/**
|
|
|
31 |
* @def TPANEL_VERSION
|
|
|
32 |
* Defines the version of this application.
|
|
|
33 |
*/
|
2 |
andreas |
34 |
#define TPANEL_VERSION ((V_MAJOR * 0x10000) + (V_MINOR * 0x100) + V_PATCH)
|
|
|
35 |
|
24 |
andreas |
36 |
#define VERSION_STRING() _GET_X_VERSION(V_MAJOR, V_MINOR, V_PATCH)
|
|
|
37 |
#define _GET_X_VERSION(a, b, c) _GET_VERSION(a, b, c)
|
|
|
38 |
#define _GET_VERSION(a, b, c) ( #a "." #b "." #c)
|
|
|
39 |
|
21 |
andreas |
40 |
/**
|
|
|
41 |
* @brief The TConfig class manages the configurations.
|
|
|
42 |
*
|
|
|
43 |
* The class contains methods to read a config file, parse it's content and
|
|
|
44 |
* hold the configuration options in the class. All public methods are static.
|
|
|
45 |
*/
|
2 |
andreas |
46 |
class TConfig
|
|
|
47 |
{
|
|
|
48 |
public:
|
|
|
49 |
TConfig(const std::string& path);
|
23 |
andreas |
50 |
bool reReadConfig();
|
2 |
andreas |
51 |
|
|
|
52 |
static void setProgName(const std::string& pname);
|
|
|
53 |
static std::string& getProgName();
|
|
|
54 |
static std::string& getConfigPath();
|
|
|
55 |
static std::string& getConfigFileName();
|
|
|
56 |
static std::string& getProjectPath();
|
|
|
57 |
static std::string& getLogFile();
|
|
|
58 |
static std::string& getLogLevel();
|
|
|
59 |
static bool isLongFormat();
|
|
|
60 |
static bool showBanner();
|
24 |
andreas |
61 |
static bool getScale();
|
2 |
andreas |
62 |
|
|
|
63 |
static std::string& getController();
|
11 |
andreas |
64 |
static int getSystem();
|
2 |
andreas |
65 |
static int getPort();
|
|
|
66 |
static int getChannel();
|
|
|
67 |
static std::string& getPanelType();
|
|
|
68 |
static std::string& getFirmVersion();
|
21 |
andreas |
69 |
static bool certCheck();
|
2 |
andreas |
70 |
|
23 |
andreas |
71 |
static bool saveProjectPath(const std::string& path);
|
|
|
72 |
static bool saveLogFile(const std::string& file);
|
|
|
73 |
static bool saveLogLevel(const std::string& level);
|
|
|
74 |
static bool saveController(const std::string& cnt);
|
|
|
75 |
static bool savePort(int port);
|
|
|
76 |
static bool saveChannel(int channel);
|
|
|
77 |
static bool savePanelType(const std::string& pt);
|
|
|
78 |
static bool saveSettings();
|
|
|
79 |
static void saveFormat(bool format);
|
24 |
andreas |
80 |
static void saveScale(bool scale);
|
23 |
andreas |
81 |
|
2 |
andreas |
82 |
protected:
|
|
|
83 |
static inline std::string <rim(std::string &s) {
|
21 |
andreas |
84 |
s.erase(s.begin(), std::find_if(s.begin(), s.end(), [](int c) {return !std::isspace(c);}));
|
2 |
andreas |
85 |
return s;
|
|
|
86 |
}
|
|
|
87 |
|
23 |
andreas |
88 |
|
2 |
andreas |
89 |
private:
|
|
|
90 |
bool findConfig();
|
|
|
91 |
bool readConfig();
|
|
|
92 |
std::vector<std::string> split(const std::string& str, const std::string& seps, const bool trimEmpty);
|
|
|
93 |
int caseCompare(const std::string& str1, const std::string& str2);
|
|
|
94 |
|
|
|
95 |
std::string mPath;
|
|
|
96 |
std::string mCFile;
|
21 |
andreas |
97 |
#ifdef __ANDROID__
|
|
|
98 |
std::string mRoot;
|
|
|
99 |
#endif
|
2 |
andreas |
100 |
};
|
|
|
101 |
|
|
|
102 |
#endif
|