swift
Loading...
Searching...
No Matches
threadedreader.h
Go to the documentation of this file.
1// SPDX-FileCopyrightText: Copyright (C) 2013 swift Project Community / Contributors
2// SPDX-License-Identifier: GPL-3.0-or-later OR LicenseRef-swift-pilot-client-1
3
5
6#ifndef SWIFT_CORE_THREADED_READER_H
7#define SWIFT_CORE_THREADED_READER_H
8
9#include <atomic>
10
11#include <QDateTime>
12#include <QObject>
13#include <QPair>
14#include <QReadWriteLock>
15#include <QString>
16#include <QtGlobal>
17
21#include "misc/worker.h"
22
23class QNetworkReply;
24class QTimer;
25
26namespace swift::core
27{
33 {
35
36 public:
38 static const QStringList &getLogCategories();
39
41 ~CThreadedReader() override = default;
42
45
48
51
54
58
61 void setUpdateTimestamp(const QDateTime &updateTimestamp = QDateTime::currentDateTimeUtc());
62
66 bool isMarkedAsFailed() const;
67
71 void setMarkedAsFailed(bool failed);
72
76
79 void markAsUsedInUnitTest() { m_unitTest = true; }
80
83 swift::misc::network::CUrlLogList getUrlLogList() const;
84
86 QPair<qint64, qint64> getNetworkReplyBytes() const;
87
88 protected:
92 std::atomic_int m_networkReplyProgress;
93 std::atomic_llong m_networkReplyCurrent;
94 std::atomic_llong m_networkReplyMax;
95
97 CThreadedReader(QObject *owner, const QString &name);
98
100 qint64 lastModifiedMsSinceEpoch(QNetworkReply *nwReply) const;
101
103 void threadAssertCheck() const;
104
107 bool didContentChange(const QString &content, int startPosition = -1);
108
111 bool doWorkCheck() const;
112
116 const swift::misc::CSlot<void(QNetworkReply *)> &callback);
117
119 virtual void networkReplyProgress(int logId, qint64 current, qint64 max, const QUrl &url);
120
124
127 static void logInconsistentData(const swift::misc::CStatusMessage &msg, const char *funcInfo = nullptr);
128
129 private:
130 static constexpr int OutdatedPendingCallMs = 30 * 1000;
131
132 QDateTime m_updateTimestamp;
133 size_t m_contentHash = 0;
134 std::atomic_bool m_markedAsFailed { false };
135 bool m_unitTest { false };
137 };
138} // namespace swift::core
139
140#endif // SWIFT_CORE_THREADED_READER_H
std::atomic_llong m_networkReplyCurrent
current bytes
QDateTime getUpdateTimestamp() const
Thread safe, get update timestamp.
void setUpdateTimestamp(const QDateTime &updateTimestamp=QDateTime::currentDateTimeUtc())
Thread safe, set update timestamp.
static const QStringList & getLogCategories()
Log categories.
virtual void networkReplyProgress(int logId, qint64 current, qint64 max, const QUrl &url)
Network request progress.
static void logInconsistentData(const swift::misc::CStatusMessage &msg, const char *funcInfo=nullptr)
Use this to log inconsistent data.
swift::misc::network::CUrlLogList getReadLog() const
Get the read log.
void setMarkedAsFailed(bool failed)
Set marker for read failed.
std::atomic_int m_networkReplyProgress
Progress percentage 0...100.
bool isMarkedAsFailed() const
Is marked as read failed.
void threadAssertCheck() const
Make sure everything runs correctly in own thread.
void logNetworkReplyReceived(QNetworkReply *reply)
Network reply received, mark in m_urlReadLog.
CThreadedReader(CThreadedReader &&)=delete
Move constructor.
QReadWriteLock m_lock
lock which can be used from the derived classes
void markAsUsedInUnitTest()
Used in unit test.
bool didContentChange(const QString &content, int startPosition=-1)
Stores new content hash and returns if content changed (based on hash value.
CThreadedReader & operator=(CThreadedReader &&)=delete
Move assignment.
CThreadedReader(const CThreadedReader &)=delete
Copy constructor.
QNetworkReply * getFromNetworkAndLog(const swift::misc::network::CUrl &url, const swift::misc::CSlot< void(QNetworkReply *)> &callback)
Get request from network, and log with m_urlReadLog.
~CThreadedReader()=default
Destructor.
bool doWorkCheck() const
Still enabled etc.?
CThreadedReader & operator=(const CThreadedReader &)=delete
Copy assignment.
qint64 lastModifiedMsSinceEpoch(QNetworkReply *nwReply) const
When was reply last modified, -1 if N/A.
std::atomic_llong m_networkReplyMax
max bytes
Base class for a long-lived worker object which lives in its own thread.
Definition worker.h:321
const QObject * owner() const
Owner of the worker.
Definition worker.h:352
Callable wrapper for a member function with function signature F.
Definition slot.h:65
Streamable status message, e.g.
Value object encapsulating information of a location, kind of simplified CValueObject compliant versi...
Definition url.h:27
Value object encapsulating a list of voice rooms.
Definition urlloglist.h:26
Backend services of the swift project, like dealing with the network or the simulators.
Definition actionbind.cpp:7
QDateTime currentDateTimeUtc()
QObject(QObject *parent)
Q_OBJECTQ_OBJECT
#define SWIFT_CORE_EXPORT
Export a class or function from the library.