mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-04-23 05:45:35 +08:00
Use nested namespaces (C++17 feature)
This commit is contained in:
@@ -20,119 +20,116 @@
|
||||
#include <QString>
|
||||
#include <QStringList>
|
||||
|
||||
namespace BlackMisc
|
||||
namespace BlackMisc::Network
|
||||
{
|
||||
namespace Network
|
||||
//! Value object encapsulating a list of URLs.
|
||||
class BLACKMISC_EXPORT CUrlList :
|
||||
public CSequence<CUrl>,
|
||||
public BlackMisc::Mixin::MetaType<CUrlList>
|
||||
{
|
||||
//! Value object encapsulating a list of URLs.
|
||||
class BLACKMISC_EXPORT CUrlList :
|
||||
public CSequence<CUrl>,
|
||||
public BlackMisc::Mixin::MetaType<CUrlList>
|
||||
{
|
||||
public:
|
||||
BLACKMISC_DECLARE_USING_MIXIN_METATYPE(CUrlList)
|
||||
using CSequence::CSequence;
|
||||
public:
|
||||
BLACKMISC_DECLARE_USING_MIXIN_METATYPE(CUrlList)
|
||||
using CSequence::CSequence;
|
||||
|
||||
//! Default constructor.
|
||||
CUrlList();
|
||||
//! Default constructor.
|
||||
CUrlList();
|
||||
|
||||
//! Construct from a base class object.
|
||||
CUrlList(const CSequence<CUrl> &other);
|
||||
//! Construct from a base class object.
|
||||
CUrlList(const CSequence<CUrl> &other);
|
||||
|
||||
//! By list of URLs
|
||||
explicit CUrlList(const QStringList &listOfUrls, bool removeDuplicates = true);
|
||||
//! By list of URLs
|
||||
explicit CUrlList(const QStringList &listOfUrls, bool removeDuplicates = true);
|
||||
|
||||
//! Random location for distributed load
|
||||
CUrl getRandomUrl() const;
|
||||
//! Random location for distributed load
|
||||
CUrl getRandomUrl() const;
|
||||
|
||||
//! Random location for distributed load, tested
|
||||
CUrl getRandomWorkingUrl(int maxTrials = 2, int timeoutMs = -1) const;
|
||||
//! Random location for distributed load, tested
|
||||
CUrl getRandomWorkingUrl(int maxTrials = 2, int timeoutMs = -1) const;
|
||||
|
||||
//! Random location for distributed load
|
||||
CUrl getRandomWithout(const CUrl &exclude) const;
|
||||
//! Random location for distributed load
|
||||
CUrl getRandomWithout(const CUrl &exclude) const;
|
||||
|
||||
//! Random location for distributed load
|
||||
CUrl getRandomWithout(const CUrlList &exclude) const;
|
||||
//! Random location for distributed load
|
||||
CUrl getRandomWithout(const CUrlList &exclude) const;
|
||||
|
||||
//! Append path to all URLs
|
||||
CUrlList withAppendedPath(const QString &path) const;
|
||||
//! Append path to all URLs
|
||||
CUrlList withAppendedPath(const QString &path) const;
|
||||
|
||||
//! Find by host
|
||||
CUrlList findByHost(const QString &host, Qt::CaseSensitivity cs = Qt::CaseInsensitive) const;
|
||||
//! Find by host
|
||||
CUrlList findByHost(const QString &host, Qt::CaseSensitivity cs = Qt::CaseInsensitive) const;
|
||||
|
||||
//! To formatted String
|
||||
QString convertToQString(const QString &separator, bool i18n = false) const;
|
||||
//! To formatted String
|
||||
QString convertToQString(const QString &separator, bool i18n = false) const;
|
||||
|
||||
//! URLs without duplicates
|
||||
CUrlList getWithoutDuplicates() const;
|
||||
//! URLs without duplicates
|
||||
CUrlList getWithoutDuplicates() const;
|
||||
|
||||
//! Remove duplicated URL and return number of removed elements
|
||||
int removeDuplicates();
|
||||
};
|
||||
//! Remove duplicated URL and return number of removed elements
|
||||
int removeDuplicates();
|
||||
};
|
||||
|
||||
//! URL list with fail support
|
||||
class BLACKMISC_EXPORT CFailoverUrlList : public CUrlList
|
||||
{
|
||||
public:
|
||||
//! Default constructor.
|
||||
CFailoverUrlList(int maxTrials = 2);
|
||||
//! URL list with fail support
|
||||
class BLACKMISC_EXPORT CFailoverUrlList : public CUrlList
|
||||
{
|
||||
public:
|
||||
//! Default constructor.
|
||||
CFailoverUrlList(int maxTrials = 2);
|
||||
|
||||
//! By list of URLs
|
||||
explicit CFailoverUrlList(const QStringList &listOfUrls, int maxTrials = 2);
|
||||
//! By list of URLs
|
||||
explicit CFailoverUrlList(const QStringList &listOfUrls, int maxTrials = 2);
|
||||
|
||||
//! From url list
|
||||
CFailoverUrlList(const CUrlList &urlIst, int maxTrials = 2);
|
||||
//! From url list
|
||||
CFailoverUrlList(const CUrlList &urlIst, int maxTrials = 2);
|
||||
|
||||
//! All failed URLs
|
||||
const CUrlList &getFailedUrls() const { return m_failedUrls; }
|
||||
//! All failed URLs
|
||||
const CUrlList &getFailedUrls() const { return m_failedUrls; }
|
||||
|
||||
//! Size of failed URLs
|
||||
int getFailedUrlsSize() const { return m_failedUrls.size(); }
|
||||
//! Size of failed URLs
|
||||
int getFailedUrlsSize() const { return m_failedUrls.size(); }
|
||||
|
||||
//! Get without the failed URLs
|
||||
CUrlList getWithoutFailed() const;
|
||||
//! Get without the failed URLs
|
||||
CUrlList getWithoutFailed() const;
|
||||
|
||||
//! Failed URL
|
||||
bool addFailedUrl(const CUrl &failedUrl);
|
||||
//! Failed URL
|
||||
bool addFailedUrl(const CUrl &failedUrl);
|
||||
|
||||
//! Failed URLs
|
||||
bool addFailedUrls(const CUrlList &failedUrls);
|
||||
//! Failed URLs
|
||||
bool addFailedUrls(const CUrlList &failedUrls);
|
||||
|
||||
//! Failed host
|
||||
bool addFailedHost(const CUrl &failedUrl);
|
||||
//! Failed host
|
||||
bool addFailedHost(const CUrl &failedUrl);
|
||||
|
||||
//! Failed host
|
||||
bool addFailedHost(const QString &host, Qt::CaseSensitivity cs = Qt::CaseInsensitive);
|
||||
//! Failed host
|
||||
bool addFailedHost(const QString &host, Qt::CaseSensitivity cs = Qt::CaseInsensitive);
|
||||
|
||||
//! More URLs to try
|
||||
bool hasMoreUrlsToTry() const;
|
||||
//! More URLs to try
|
||||
bool hasMoreUrlsToTry() const;
|
||||
|
||||
//! Number of URLs which can be used for a retry
|
||||
int numberOfStillValidUrls() const;
|
||||
//! Number of URLs which can be used for a retry
|
||||
int numberOfStillValidUrls() const;
|
||||
|
||||
//! Next utl from this list
|
||||
CUrl obtainNextUrl(bool randomStart = false);
|
||||
//! Next utl from this list
|
||||
CUrl obtainNextUrl(bool randomStart = false);
|
||||
|
||||
//! Round robin with random start point
|
||||
CUrl obtainNextUrlWithout(bool randomStart = false, const CUrlList &exclude = CUrlList()) const;
|
||||
//! Round robin with random start point
|
||||
CUrl obtainNextUrlWithout(bool randomStart = false, const CUrlList &exclude = CUrlList()) const;
|
||||
|
||||
//! Next working URL, test if it can be connected
|
||||
CUrl obtainNextWorkingUrl(bool random = false, int connectTimeoutMs = -1);
|
||||
//! Next working URL, test if it can be connected
|
||||
CUrl obtainNextWorkingUrl(bool random = false, int connectTimeoutMs = -1);
|
||||
|
||||
//! Get the error messages
|
||||
const QStringList &getErrorMessages() const { return m_errorMsgs; }
|
||||
//! Get the error messages
|
||||
const QStringList &getErrorMessages() const { return m_errorMsgs; }
|
||||
|
||||
//! Reset failed URL, allows to set an optional new number of max.trials
|
||||
void reset(int maxTrials = -1);
|
||||
//! Reset failed URL, allows to set an optional new number of max.trials
|
||||
void reset(int maxTrials = -1);
|
||||
|
||||
private:
|
||||
int m_currentIndexDistributedLoad = -1; //!< index for random access
|
||||
int m_maxTrials = 2; //!< number of max trials
|
||||
CUrlList m_failedUrls; //!< failed tested URLs
|
||||
QStringList m_errorMsgs; //!< error messages while testing;
|
||||
};
|
||||
private:
|
||||
int m_currentIndexDistributedLoad = -1; //!< index for random access
|
||||
int m_maxTrials = 2; //!< number of max trials
|
||||
CUrlList m_failedUrls; //!< failed tested URLs
|
||||
QStringList m_errorMsgs; //!< error messages while testing;
|
||||
};
|
||||
|
||||
} //namespace
|
||||
} // namespace
|
||||
|
||||
Q_DECLARE_METATYPE(BlackMisc::Network::CUrlList)
|
||||
|
||||
Reference in New Issue
Block a user