swift
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 
18 #include "core/swiftcoreexport.h"
21 #include "misc/worker.h"
22 
23 class QNetworkReply;
24 class QTimer;
25 
26 namespace swift::core
27 {
33  {
34  Q_OBJECT
35 
36  public:
38  static const QStringList &getLogCategories();
39 
41  ~CThreadedReader() override = default;
42 
44  CThreadedReader(const CThreadedReader &) = delete;
45 
48 
51 
54 
57  QDateTime getUpdateTimestamp() const;
58 
61  void setUpdateTimestamp(const QDateTime &updateTimestamp = QDateTime::currentDateTimeUtc());
62 
66  bool isMarkedAsFailed() const;
67 
71  void setMarkedAsFailed(bool failed);
72 
75  swift::misc::network::CUrlLogList getReadLog() const;
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:
89  mutable QReadWriteLock m_lock {
90  QReadWriteLock::Recursive
91  };
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 
115  QNetworkReply *getFromNetworkAndLog(const swift::misc::network::CUrl &url,
116  const swift::misc::CSlot<void(QNetworkReply *)> &callback);
117 
119  virtual void networkReplyProgress(int logId, qint64 current, qint64 max, const QUrl &url);
120 
123  void logNetworkReplyReceived(QNetworkReply *reply);
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 };
136  swift::misc::network::CUrlLogList m_urlReadLog;
137  };
138 } // namespace swift::core
139 
140 #endif // SWIFT_CORE_THREADED_READER_H
Support for threaded based reading and parsing tasks such as data files via http, or file system and ...
std::atomic_llong m_networkReplyCurrent
current bytes
std::atomic_int m_networkReplyProgress
Progress percentage 0...100.
CThreadedReader(CThreadedReader &&)=delete
Move constructor.
void markAsUsedInUnitTest()
Used in unit test.
CThreadedReader & operator=(const CThreadedReader &)=delete
Copy assignment.
CThreadedReader & operator=(CThreadedReader &&)=delete
Move assignment.
CThreadedReader(const CThreadedReader &)=delete
Copy constructor.
~CThreadedReader()=default
Destructor.
std::atomic_llong m_networkReplyMax
max bytes
Base class for a long-lived worker object which lives in its own thread.
Definition: worker.h:299
Callable wrapper for a member function with function signature F.
Definition: slot.h:62
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
#define SWIFT_CORE_EXPORT
Export a class or function from the library.