// Copyright © 2010-2012 b0ris //. // 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 2 // 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #ifndef UPDATED_CONFIG_H #define UPDATED_CONFIG_H #include #include "Config.h" #include "SslClient.h" class QTimer; /** * @brief singleton class that can update it's configuration
* -# ServerEntry is read from servers list * -# Trying to connect every Config::ServerEntry::retryTimeout * -# When total time for all retries exceeds Config::ServerEntry::timeout go to the next ServerEntry */ class UpdatedConfig: public QObject, public Config { Q_OBJECT public: /** * @brief Retrieve application-wide instance of Config class * @return Pointer to singleton instance of Config class */ static UpdatedConfig *CurrentConfig(); /** * @brief Get valid server address to communicate with * @return address of server to communicate with ot empty string */ string GetServerAddr(); signals: /** * @brief Signal is emitted when client configuration is updated */ void updated(); private slots: void update(); void connectionError(); void gotServerReply(SslClient::RequestType &type, QByteArray &confdata); private: static const int UPDATED_STATE_FULL = 0x7E; /** * @brief Pointer to the singleton Config instance */ static UpdatedConfig *self; /** * @brief SslClient instance that connects to server and retrieves config */ SslClient *client; /** * @brief timer that is responsible on config updates and reconnection retries */ QTimer *configUpdateTimer; /** * @brief bool value that is true if config is actual and was updated recently
* and false if it isn't actual and has to be updated */ bool configValid; /** * @brief Count time between subsequent request retries */ unsigned time; /** * @brief index of Config::servers that is currently being tried to connect or being worked with */ unsigned activeSrvIndex; /** * @brief value indicating whether last connetion attempt failed or not */ bool retryFailed; /** * @brief value indicating which config parts are already updated
* to check if some part is updated just apply & to this
* value and any of SslClient::RequestType values */ unsigned char updateStatus; /** * @brief creates an instance and tries to connect to servers from config.cfg
* one by one until working server is found or no other ServerEntry records left */ UpdatedConfig(); }; #endif