6 #include <QJsonDocument>
18 using namespace swift::misc::network;
19 using namespace swift::misc::db;
28 Q_ASSERT_X(mode == CDbFlags::DbReading || mode == CDbFlags::Shared, Q_FUNC_INFO,
"Wrong mode");
33 QReadLocker l(&m_lockInfoObjects);
39 QReadLocker l(&m_lockInfoObjects);
40 return m_infoObjects.
size();
48 SWIFT_VERIFY_X(
false, Q_FUNC_INFO,
"Using this for CInfoDataReader makes no sense");
55 SWIFT_VERIFY_X(
false, Q_FUNC_INFO,
"Using this for CInfoDataReader makes no sense");
62 SWIFT_VERIFY_X(
false, Q_FUNC_INFO,
"Using this for CInfoDataReader makes no sense");
70 Q_ASSERT_X(CEntityFlags::isSingleEntity(entity), Q_FUNC_INFO,
"Need single entity");
71 Q_ASSERT_X(
sApp, Q_FUNC_INFO,
"Need sApp");
73 if (entity == CEntityFlags::DbInfoObjectEntity || entity == CEntityFlags::SharedInfoObjectEntity)
75 SWIFT_VERIFY_X(
false, Q_FUNC_INFO,
"Using this for CInfoDataReader makes no sense");
88 Q_ASSERT_X(CEntityFlags::isSingleEntity(entity), Q_FUNC_INFO,
"Need single entity");
89 Q_ASSERT_X(
sApp, Q_FUNC_INFO,
"Need sApp");
91 if (entity == CEntityFlags::DbInfoObjectEntity || entity == CEntityFlags::SharedInfoObjectEntity)
93 SWIFT_VERIFY_X(
false, Q_FUNC_INFO,
"Using this for CInfoDataReader makes no sense");
104 SWIFT_VERIFY_X(
false, Q_FUNC_INFO,
"Using this for CInfoDataReader makes no sense");
105 return CEntityFlags::NoEntity;
111 SWIFT_VERIFY_X(
false, Q_FUNC_INFO,
"Using this for CInfoDataReader makes no sense");
112 return CEntityFlags::NoEntity;
121 oldUrlInfo = this->
getBaseUrl(CDbFlags::DbReading);
122 newUrlInfo = this->
getBaseUrl(CDbFlags::DbReading);
143 emit this->
dataRead(this->getEntityForMode(), CEntityFlags::ReadStarted, 0, url);
148 void CInfoDataReader::parseInfoObjectsData(QNetworkReply *nwReplyPtr)
152 QScopedPointer<QNetworkReply, QScopedPointerDeleteLater> nwReply(nwReplyPtr);
155 const CDatabaseReader::JsonDatastoreResponse res =
157 if (res.hasErrorMessage())
160 emit this->
dataRead(this->getEntityForMode(), CEntityFlags::ReadFailed, 0, res.getUrl());
165 const CDbInfoList infoObjects = CDbInfoList::fromDatabaseJson(res.getJsonArray());
166 const int n = infoObjects.
size();
170 const QString urlStr = nwReply->url().toString();
175 QWriteLocker wl(&m_lockInfoObjects);
176 m_infoObjects = infoObjects;
182 CUrl CInfoDataReader::getDbInfoObjectsUrl()
const
187 CUrl CInfoDataReader::getSharedInfoObjectsUrl()
const
194 if (m_mode == CDbFlags::DbReading) {
return CEntityFlags::DbInfoObjectEntity; }
195 if (m_mode == CDbFlags::Shared) {
return CEntityFlags::SharedInfoObjectEntity; }
196 qFatal(
"Wrong mode");
197 return CEntityFlags::NoEntity;
201 const QDateTime &newerThan)
206 Q_ASSERT_X(
false, Q_FUNC_INFO,
"Not implemented for CInfoDataReader");
213 case CDbFlags::DbReading:
return getDbInfoObjectsUrl();
214 case CDbFlags::Shared:
return getSharedInfoObjectsUrl();
215 default: qFatal(
"Wrong mode");
225 Q_UNUSED(overrideNewer)
226 Q_ASSERT_X(
false, Q_FUNC_INFO,
"Not supported");
236 Q_UNUSED(overrideNewer)
237 Q_ASSERT_X(
false, Q_FUNC_INFO,
"Not supported");
SWIFT_CORE_EXPORT swift::core::CApplication * sApp
Single instance of application object.
data::CGlobalSetup getGlobalSetup() const
Global setup.
CWebDataServices * getWebDataServices() const
Get the web data services.
swift::misc::network::CUrlLogList getUrlLogList() const
Get the URL log list.
QNetworkReply * getFromNetworkAndLog(const swift::misc::network::CUrl &url, const swift::misc::CSlot< void(QNetworkReply *)> &callback)
Get request from network, and log with m_urlReadLog.
bool doWorkCheck() const
Still enabled etc.?
QDateTime getCacheTimestamp(swift::misc::network::CEntityFlags::Entity entity) const
Corresponding cache timestamp if applicable.
int getCacheCount(swift::misc::network::CEntityFlags::Entity entity) const
Cache count for entity.
swift::misc::network::CUrl getDbInfoReaderUrl() const
Info data reader URL.
Value object encapsulating a list of reader configs.
Specialized version of threaded reader for DB data.
void emitAndLogDataRead(swift::misc::network::CEntityFlags::Entity entity, int number, const JsonDatastoreResponse &res)
Emit signal and log when data have been read.
void logNoWorkingUrl(swift::misc::network::CEntityFlags::Entity entity)
Log if no working URL exists, using m_noWorkingUrlSeverity.
swift::misc::network::CUrl getBaseUrl(swift::misc::db::CDbFlags::DataRetrievalModeFlag mode) const
Base URL for mode (either a shared or DB URL)
void dataRead(swift::misc::network::CEntityFlags::Entity entities, swift::misc::network::CEntityFlags::ReadState state, int number, const QUrl &url)
Combined read signal.
CDatabaseReader::JsonDatastoreResponse setStatusAndTransformReplyIntoDatastoreResponse(QNetworkReply *nwReply)
Check if terminated or error, otherwise split into array of objects.
int getInfoObjectCount() const
Get info list size (either shared or from DB)
virtual void read(swift::misc::network::CEntityFlags::Entity entities, swift::misc::db::CDbFlags::DataRetrievalModeFlag mode, const QDateTime &newerThan)
Read / re-read data file.
swift::misc::db::CDbInfoList getInfoObjects() const
Get info list (either shared or from DB)
virtual void synchronizeCaches(swift::misc::network::CEntityFlags::Entity entities)
Admit caches for given entities.
void readInfoData()
Allow to call directly, special for info objects reader.
virtual int getCacheCount(swift::misc::network::CEntityFlags::Entity entity) const
Cache`s number of entities.
virtual swift::misc::CStatusMessageList readFromJsonFiles(const QString &dir, swift::misc::network::CEntityFlags::Entity whatToRead, bool overrideNewer)
Data read from local data.
swift::misc::network::CUrl getInfoObjectsUrl() const
URL depending on mode, i.e. shared/DB.
virtual void invalidateCaches(swift::misc::network::CEntityFlags::Entity entities)
Invalidate the caches for given entities.
virtual bool hasChangedUrl(swift::misc::network::CEntityFlags::Entity entity, swift::misc::network::CUrl &oldUrlInfo, swift::misc::network::CUrl &newUrlInfo) const
Changed URL, means the cache values have been read from elsewhere.
virtual void admitCaches(swift::misc::network::CEntityFlags::Entity entities)
Admit caches for given entities.
virtual swift::misc::network::CEntityFlags::Entity getEntitiesWithCacheTimestampNewerThan(const QDateTime &threshold) const
Entities already having data in cache (based on timestamp assumption)
virtual swift::misc::network::CEntityFlags::Entity getEntitiesWithCacheCount() const
Entities already having data in cache.
virtual QDateTime getCacheTimestamp(swift::misc::network::CEntityFlags::Entity entity) const
Get cache timestamp.
virtual swift::misc::network::CUrl getDbServiceBaseUrl() const
Get the service URL, individual for each reader.
bool areAllInfoObjectsRead() const
All data read?
virtual bool readFromJsonFilesInBackground(const QString &dir, swift::misc::network::CEntityFlags::Entity whatToRead, bool overrideNewer)
Data read from local data.
virtual swift::misc::network::CEntityFlags::Entity getSupportedEntities() const
Supported entities by this reader.
Class for emitting a log message.
static void preformatted(const CStatusMessage &statusMessage)
Sends a verbatim, preformatted message to the log.
Derived & error(const char16_t(&format)[N])
Set the severity to error, providing a format string.
Derived & info(const char16_t(&format)[N])
Set the severity to info, providing a format string.
size_type size() const
Returns number of elements in the sequence.
Streamable status message, e.g.
Status messages, e.g. from Core -> GUI.
DataRetrievalModeFlag
Which data to read, requires corresponding readers.
Value object encapsulating a list of info objects.
EntityFlag
Which data to read, requires corresponding readers.
Value object encapsulating information of a location, kind of simplified CValueObject compliant versi...
bool isEmpty() const
Empty.
CUrl withAppendedPath(const QString &path) const
Append path.
Value object encapsulating a list of voice rooms.
bool hasPending() const
Any pending calls.
QString getSummary() const
Summary.
Core data traits (aka cached values) and classes.
Classes interacting with the swift database (aka "datastore").
Free functions in swift::misc.
#define SWIFT_VERIFY_X(COND, WHERE, WHAT)
A weaker kind of assert.