Subversion Repositories tpanel

Rev

Rev 23 | Blame | Last modification | View Log | RSS feed

/*
 * Copyright (C) 2020, 2021 by Andreas Theofilu <andreas@theosys.at>
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software Foundation,
 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301  USA
 */
#ifndef __TCONFIG_H__
#define __TCONFIG_H__

#include <string>
#include <vector>
#include <algorithm>
#include "terror.h"

#define V_MAJOR         1
#define V_MINOR         0
#define V_PATCH         0

/**
 * @def TPANEL_VERSION
 * Defines the version of this application.
 */
#define TPANEL_VERSION          ((V_MAJOR * 0x10000) + (V_MINOR * 0x100) + V_PATCH)

#define VERSION_STRING() _GET_X_VERSION(V_MAJOR, V_MINOR, V_PATCH)
#define _GET_X_VERSION(a, b, c) _GET_VERSION(a, b, c)
#define _GET_VERSION(a, b, c) ( #a "." #b "." #c)

/**
 * @brief The TConfig class manages the configurations.
 *
 * The class contains methods to read a config file, parse it's content and
 * hold the configuration options in the class. All public methods are static.
 */
class TConfig
{
        public:
                TConfig(const std::string& path);
        bool reReadConfig();

                static void setProgName(const std::string& pname);
                static std::string& getProgName();
                static std::string& getConfigPath();
                static std::string& getConfigFileName();
                static std::string& getProjectPath();
                static std::string& getLogFile();
                static std::string& getLogLevel();
                static bool isLongFormat();
                static bool showBanner();
        static bool getScale();

                static std::string& getController();
        static int getSystem();
                static int getPort();
                static int getChannel();
                static std::string& getPanelType();
                static std::string& getFirmVersion();
        static bool certCheck();

        static bool saveProjectPath(const std::string& path);
        static bool saveLogFile(const std::string& file);
        static bool saveLogLevel(const std::string& level);
        static bool saveController(const std::string& cnt);
        static bool savePort(int port);
        static bool saveChannel(int channel);
        static bool savePanelType(const std::string& pt);
        static bool saveSettings();
        static void saveFormat(bool format);
        static void saveScale(bool scale);

        protected:
                static inline std::string &ltrim(std::string &s) {
            s.erase(s.begin(), std::find_if(s.begin(), s.end(), [](int c) {return !std::isspace(c);}));
                        return s;
                }


        private:
                bool findConfig();
                bool readConfig();
                std::vector<std::string> split(const std::string& str, const std::string& seps, const bool trimEmpty);
                int caseCompare(const std::string& str1, const std::string& str2);

                std::string mPath;
                std::string mCFile;
#ifdef __ANDROID__
        std::string mRoot;
#endif
};

#endif