Subversion Repositories tpanel

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
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
 
21 andreas 36
/**
37
 * @brief The TConfig class manages the configurations.
38
 *
39
 * The class contains methods to read a config file, parse it's content and
40
 * hold the configuration options in the class. All public methods are static.
41
 */
2 andreas 42
class TConfig
43
{
44
	public:
45
		TConfig(const std::string& path);
46
 
47
		static void setProgName(const std::string& pname);
48
		static std::string& getProgName();
49
		static std::string& getConfigPath();
50
		static std::string& getConfigFileName();
51
		static std::string& getProjectPath();
52
		static std::string& getLogFile();
53
		static std::string& getLogLevel();
54
		static bool isLongFormat();
55
		static bool showBanner();
56
 
57
		static std::string& getController();
11 andreas 58
        static int getSystem();
2 andreas 59
		static int getPort();
60
		static int getChannel();
61
		static std::string& getPanelType();
62
		static std::string& getFirmVersion();
21 andreas 63
        static bool certCheck();
2 andreas 64
 
65
	protected:
66
		static inline std::string &ltrim(std::string &s) {
21 andreas 67
            s.erase(s.begin(), std::find_if(s.begin(), s.end(), [](int c) {return !std::isspace(c);}));
2 andreas 68
			return s;
69
		}
70
 
71
	private:
72
		bool findConfig();
73
		bool readConfig();
74
		std::vector<std::string> split(const std::string& str, const std::string& seps, const bool trimEmpty);
75
		int caseCompare(const std::string& str1, const std::string& str2);
76
 
77
		std::string mPath;
78
		std::string mCFile;
21 andreas 79
#ifdef __ANDROID__
80
        std::string mRoot;
81
#endif
2 andreas 82
};
83
 
84
#endif