mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-04-15 01:05:35 +08:00
refs #485, adjusted setup reader
* log categories as discussed * made some functions thread safe
This commit is contained in:
committed by
Mathew Sutcliffe
parent
b577f9313e
commit
d7e5b5206c
@@ -52,16 +52,16 @@ namespace BlackCore
|
|||||||
{
|
{
|
||||||
// initialized by local file for testing
|
// initialized by local file for testing
|
||||||
emit this->setupSynchronized(true);
|
emit this->setupSynchronized(true);
|
||||||
return CStatusMessage(cats(), CStatusMessage::SeverityInfo, "Using local bootstrap file: " + this->m_localSetupFileValue);
|
return CStatusMessage(this, CStatusMessage::SeverityInfo, "Using local bootstrap file: " + this->m_localSetupFileValue);
|
||||||
}
|
}
|
||||||
else if (this->m_bootstrapMode == CacheOnly)
|
else if (this->m_bootstrapMode == CacheOnly)
|
||||||
{
|
{
|
||||||
m_setup.synchronize();
|
m_setup.synchronize();
|
||||||
CGlobalSetup currentSetup = m_setup.get();
|
CGlobalSetup currentSetup = m_setup.getCopy();
|
||||||
this->m_updateInfoUrls = currentSetup.updateInfoFileUrls();
|
this->m_updateInfoUrls = currentSetup.updateInfoFileUrls();
|
||||||
emit this->setupSynchronized(true);
|
emit this->setupSynchronized(true);
|
||||||
emit this->updateInfoSynchronized(true);
|
emit this->updateInfoSynchronized(true);
|
||||||
return CStatusMessage(cats(), CStatusMessage::SeverityInfo, "Cache only setup, using it as it is");
|
return CStatusMessage(this, CStatusMessage::SeverityInfo, "Cache only setup, using it as it is");
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@@ -74,7 +74,7 @@ namespace BlackCore
|
|||||||
|
|
||||||
// if ever loaded add those URLs
|
// if ever loaded add those URLs
|
||||||
m_setup.synchronize();
|
m_setup.synchronize();
|
||||||
CGlobalSetup currentSetup = m_setup.get();
|
CGlobalSetup currentSetup = m_setup.getCopy();
|
||||||
if (currentSetup.wasLoaded())
|
if (currentSetup.wasLoaded())
|
||||||
{
|
{
|
||||||
if (this->m_bootstrapMode != Explicit || this->m_bootstrapUrls.isEmpty())
|
if (this->m_bootstrapMode != Explicit || this->m_bootstrapUrls.isEmpty())
|
||||||
@@ -86,13 +86,13 @@ namespace BlackCore
|
|||||||
|
|
||||||
if (this->m_bootstrapUrls.isEmpty())
|
if (this->m_bootstrapUrls.isEmpty())
|
||||||
{
|
{
|
||||||
return CStatusMessage(cats(), CStatusMessage::SeverityError, "No bootstrap URLs, cannot load setup");
|
return CStatusMessage(this, CStatusMessage::SeverityError, "No bootstrap URLs, cannot load setup");
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
this->m_bootstrapUrls.removeDuplicates();
|
this->m_bootstrapUrls.removeDuplicates();
|
||||||
this->ps_readSetup(); // start reading
|
this->ps_readSetup(); // start reading
|
||||||
return CStatusMessage(cats(), CStatusMessage::SeverityInfo, "Will start loading setup");
|
return CStatusMessage(this, CStatusMessage::SeverityInfo, "Will start loading setup");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -139,10 +139,12 @@ namespace BlackCore
|
|||||||
|
|
||||||
void CSetupReader::ps_readSetup()
|
void CSetupReader::ps_readSetup()
|
||||||
{
|
{
|
||||||
CUrl url(this->m_bootstrapUrls.obtainNextWorkingUrl());
|
const CUrl url(this->m_bootstrapUrls.obtainNextWorkingUrl());
|
||||||
if (url.isEmpty())
|
if (url.isEmpty())
|
||||||
{
|
{
|
||||||
CLogMessage(this).warning("Cannot read setup, failed URLs: %1") << this->m_bootstrapUrls.getFailedUrls();
|
CLogMessage(this).warning("Cannot read setup, URLs: %1, failed URLs: %2")
|
||||||
|
<< this->m_bootstrapUrls
|
||||||
|
<< this->m_bootstrapUrls.getFailedUrls();
|
||||||
emit setupSynchronized(false);
|
emit setupSynchronized(false);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -152,10 +154,12 @@ namespace BlackCore
|
|||||||
|
|
||||||
void CSetupReader::ps_readUpdateInfo()
|
void CSetupReader::ps_readUpdateInfo()
|
||||||
{
|
{
|
||||||
CUrl url(this->m_updateInfoUrls.obtainNextWorkingUrl());
|
const CUrl url(this->m_updateInfoUrls.obtainNextWorkingUrl());
|
||||||
if (url.isEmpty())
|
if (url.isEmpty())
|
||||||
{
|
{
|
||||||
CLogMessage(this).warning("Cannot read update info, failed URLs: %1") << this->m_updateInfoUrls.getFailedUrls();
|
CLogMessage(this).warning("Cannot read update info, URLs: %1, failed URLs: %2")
|
||||||
|
<< this->m_updateInfoUrls
|
||||||
|
<< this->m_updateInfoUrls.getFailedUrls();
|
||||||
emit updateInfoSynchronized(false);
|
emit updateInfoSynchronized(false);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -252,7 +256,8 @@ namespace BlackCore
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
CGlobalSetup currentSetup = m_setup.get();
|
const CGlobalSetup currentSetup = m_setup.get();
|
||||||
|
this->m_updateInfoUrls = currentSetup.updateInfoFileUrls();
|
||||||
CGlobalSetup loadedSetup;
|
CGlobalSetup loadedSetup;
|
||||||
loadedSetup.convertFromJson(Json::jsonObjectFromString(setupJson));
|
loadedSetup.convertFromJson(Json::jsonObjectFromString(setupJson));
|
||||||
loadedSetup.markAsLoaded(true);
|
loadedSetup.markAsLoaded(true);
|
||||||
@@ -278,7 +283,7 @@ namespace BlackCore
|
|||||||
CStatusMessage m = m_setup.set(loadedSetup, loadedSetup.getMSecsSinceEpoch());
|
CStatusMessage m = m_setup.set(loadedSetup, loadedSetup.getMSecsSinceEpoch());
|
||||||
if (m.isWarningOrAbove())
|
if (m.isWarningOrAbove())
|
||||||
{
|
{
|
||||||
m.setCategories(cats());
|
m.setCategories(getLogCategories());
|
||||||
CLogMessage(this).preformatted(m);
|
CLogMessage(this).preformatted(m);
|
||||||
emit setupSynchronized(false);
|
emit setupSynchronized(false);
|
||||||
return; // issue with cache
|
return; // issue with cache
|
||||||
@@ -361,7 +366,7 @@ namespace BlackCore
|
|||||||
CStatusMessage m = m_updateInfo.set(loadedUpdateInfo, loadedUpdateInfo.getMSecsSinceEpoch());
|
CStatusMessage m = m_updateInfo.set(loadedUpdateInfo, loadedUpdateInfo.getMSecsSinceEpoch());
|
||||||
if (!m.isEmpty())
|
if (!m.isEmpty())
|
||||||
{
|
{
|
||||||
m.setCategories(cats());
|
m.setCategories(getLogCategories());
|
||||||
CLogMessage(this).preformatted(m);
|
CLogMessage(this).preformatted(m);
|
||||||
emit updateInfoSynchronized(false);
|
emit updateInfoSynchronized(false);
|
||||||
return; // issue with cache
|
return; // issue with cache
|
||||||
@@ -394,10 +399,19 @@ namespace BlackCore
|
|||||||
}
|
}
|
||||||
} // function
|
} // function
|
||||||
|
|
||||||
const CLogCategoryList &CSetupReader::cats()
|
const CLogCategoryList &CSetupReader::getLogCategories()
|
||||||
{
|
{
|
||||||
static const CLogCategoryList cats(CLogCategoryList(this).join({ CLogCategory::webservice()}));
|
static const CLogCategoryList cats({ CLogCategory("swift.setupreader"), CLogCategory::webservice()});
|
||||||
return cats;
|
return cats;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
CGlobalSetup CSetupReader::getSetup() const
|
||||||
|
{
|
||||||
|
return m_setup.getCopy();
|
||||||
|
}
|
||||||
|
|
||||||
|
CUpdateInfo CSetupReader::getUpdateInfo() const
|
||||||
|
{
|
||||||
|
return m_updateInfo.getCopy();
|
||||||
|
}
|
||||||
} // namespace
|
} // namespace
|
||||||
|
|||||||
@@ -22,6 +22,7 @@
|
|||||||
#include <QTimer>
|
#include <QTimer>
|
||||||
#include <QNetworkReply>
|
#include <QNetworkReply>
|
||||||
#include <QCommandLineOption>
|
#include <QCommandLineOption>
|
||||||
|
#include <atomic>
|
||||||
|
|
||||||
namespace BlackCore
|
namespace BlackCore
|
||||||
{
|
{
|
||||||
@@ -34,9 +35,27 @@ namespace BlackCore
|
|||||||
class BLACKCORE_EXPORT CSetupReader : public QObject
|
class BLACKCORE_EXPORT CSetupReader : public QObject
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
friend class CApplication; //!< only using class
|
friend class CApplication; //!< only using class
|
||||||
|
|
||||||
|
public:
|
||||||
|
//! Categories
|
||||||
|
static const BlackMisc::CLogCategoryList &getLogCategories();
|
||||||
|
|
||||||
|
//! Current setup
|
||||||
|
//! \threadsafe
|
||||||
|
BlackCore::Data::CGlobalSetup getSetup() const;
|
||||||
|
|
||||||
|
//! Update info
|
||||||
|
//! \threadsafe
|
||||||
|
BlackCore::Data::CUpdateInfo getUpdateInfo() const;
|
||||||
|
|
||||||
|
signals:
|
||||||
|
//! Setup has been read
|
||||||
|
void setupSynchronized(bool success);
|
||||||
|
|
||||||
|
//! Version bas been read
|
||||||
|
void updateInfoSynchronized(bool success);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
//! Constructor
|
//! Constructor
|
||||||
explicit CSetupReader(QObject *parent);
|
explicit CSetupReader(QObject *parent);
|
||||||
@@ -54,18 +73,13 @@ namespace BlackCore
|
|||||||
void gracefulShutdown();
|
void gracefulShutdown();
|
||||||
|
|
||||||
//! Setup loaded?
|
//! Setup loaded?
|
||||||
|
//! \threadsafe
|
||||||
bool isSetupSyncronized() const { return m_setupSyncronized; }
|
bool isSetupSyncronized() const { return m_setupSyncronized; }
|
||||||
|
|
||||||
//! Version info loaded?
|
//! Version info loaded?
|
||||||
|
//! \threadsafe
|
||||||
bool isUpdateSyncronized() const { return m_updateInfoSyncronized; }
|
bool isUpdateSyncronized() const { return m_updateInfoSyncronized; }
|
||||||
|
|
||||||
signals:
|
|
||||||
//! Setup has been read
|
|
||||||
void setupSynchronized(bool success);
|
|
||||||
|
|
||||||
//! Version bas been read
|
|
||||||
void updateInfoSynchronized(bool success);
|
|
||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
//! Setup has been read
|
//! Setup has been read
|
||||||
void ps_parseSetupFile(QNetworkReply *nwReply);
|
void ps_parseSetupFile(QNetworkReply *nwReply);
|
||||||
@@ -98,13 +112,13 @@ namespace BlackCore
|
|||||||
};
|
};
|
||||||
|
|
||||||
bool m_shutdown = false;
|
bool m_shutdown = false;
|
||||||
bool m_setupSyncronized = false;
|
std::atomic<bool> m_setupSyncronized { false };
|
||||||
bool m_updateInfoSyncronized = false;
|
std::atomic<bool> m_updateInfoSyncronized { false };
|
||||||
QString m_localSetupFileValue;
|
QString m_localSetupFileValue;
|
||||||
QString m_bootsrapUrlFileValue;
|
QString m_bootsrapUrlFileValue;
|
||||||
BootsrapMode m_bootstrapMode;
|
BootsrapMode m_bootstrapMode;
|
||||||
BlackMisc::Network::CFailoverUrlList m_bootstrapUrls;
|
BlackMisc::Network::CFailoverUrlList m_bootstrapUrls; //!< location of setup files
|
||||||
BlackMisc::Network::CFailoverUrlList m_updateInfoUrls;
|
BlackMisc::Network::CFailoverUrlList m_updateInfoUrls; //!< location of info files
|
||||||
BlackMisc::CData<BlackCore::Data::GlobalSetup> m_setup {this, &CSetupReader::ps_setupChanged}; //!< data cache setup
|
BlackMisc::CData<BlackCore::Data::GlobalSetup> m_setup {this, &CSetupReader::ps_setupChanged}; //!< data cache setup
|
||||||
BlackMisc::CData<BlackCore::Data::UpdateInfo> m_updateInfo {this}; //!< data cache update info
|
BlackMisc::CData<BlackCore::Data::UpdateInfo> m_updateInfo {this}; //!< data cache update info
|
||||||
|
|
||||||
@@ -129,9 +143,6 @@ namespace BlackCore
|
|||||||
|
|
||||||
//! Read for development environment?
|
//! Read for development environment?
|
||||||
static bool isForDevelopment();
|
static bool isForDevelopment();
|
||||||
|
|
||||||
//! Categories
|
|
||||||
const BlackMisc::CLogCategoryList &cats();
|
|
||||||
};
|
};
|
||||||
} // ns
|
} // ns
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user