Torc  0.1
torcnetworkrequest.h
Go to the documentation of this file.
1 #ifndef TORCNETWORKREQUEST_H
2 #define TORCNETWORKREQUEST_H
3 
4 // Qt
5 #include <QMetaType>
6 
7 // Torc
8 #include "torcnetwork.h"
9 
11 {
12  friend class TorcNetwork;
13 
14  public:
15  TorcNetworkRequest(const QNetworkRequest &Request, QNetworkAccessManager::Operation Type, int BufferSize, int *Abort);
16  TorcNetworkRequest(const QNetworkRequest &Request, const QByteArray &PostData, int *Abort);
17 
18  bool WaitForStart (int Timeout);
19  int Peek (char* Buffer, qint32 BufferSize, int Timeout);
20  int Read (char* Buffer, qint32 BufferSize, int Timeout, bool Peek = false);
21  qint64 Seek (qint64 Offset);
22  QByteArray& GetBuffer (void);
23  QByteArray ReadAll (int Timeout);
24  int BytesAvailable (void);
25  qint64 GetSize (void) const;
26  qint64 GetPosition (void) const;
27  void SetReadSize (int Size);
28  void SetRange (int Start, int End = 0);
29  void DownloadProgress (qint64 Received, qint64 Total);
30  bool CanByteServe (void) const;
31  QUrl GetFinalURL (void) const;
32  QString GetContentType (void) const;
33  int GetStatus (void) const;
34  QByteArray GetHeader (const QByteArray &Header) const;
35  QNetworkReply::NetworkError GetReplyError (void) const;
36  void SetReplyError (QNetworkReply::NetworkError Error);
37 
38  protected:
39  virtual ~TorcNetworkRequest() = default;
40  void Write (QNetworkReply *Reply);
41 
42  private:
43  Q_DISABLE_COPY(TorcNetworkRequest)
44  bool WritePriv (QNetworkReply *Reply, const char* Buffer, int Size);
45 
46  protected:
47  // internal state/type
48  QNetworkAccessManager::Operation m_type;
49  int *m_abort;
50  bool m_started;
55  QAtomicInt m_availableToRead;
59  QByteArray m_buffer;
64 
65  // for POST/PUT requests
66  const QByteArray m_postData;
67 
68  // QNetworkReply state
72  qint64 m_bytesTotal;
73  QList<QNetworkReply::RawHeaderPair> m_rawHeaders;
74  QNetworkReply::NetworkError m_replyError;
75 
76  // request/reply details
77  QNetworkRequest m_request;
82  QString m_contentType;
84 };
85 
86 Q_DECLARE_METATYPE(TorcNetworkRequest*)
87 Q_DECLARE_METATYPE(QNetworkReply*)
88 
89 #endif // TORCNETWORKREQUEST_H
TorcNetworkRequest(const QNetworkRequest &Request, QNetworkAccessManager::Operation Type, int BufferSize, int *Abort)
int Read(char *Buffer, qint32 BufferSize, int Timeout, bool Peek=false)
void SetReadSize(int Size)
void SetReplyError(QNetworkReply::NetworkError Error)
qint64 GetPosition(void) const
A reference counting implementation.
A wrapper around QNetworkRequest.
QNetworkReply::NetworkError GetReplyError(void) const
bool WaitForStart(int Timeout)
QNetworkAccessManager::Operation m_type
virtual ~TorcNetworkRequest()=default
const QByteArray m_postData
QByteArray & GetBuffer(void)
int Peek(char *Buffer, qint32 BufferSize, int Timeout)
QString GetContentType(void) const
QUrl GetFinalURL(void) const
bool CanByteServe(void) const
QList< QNetworkReply::RawHeaderPair > m_rawHeaders
QNetworkRequest m_request
qint64 Seek(qint64 Offset)
void DownloadProgress(qint64 Received, qint64 Total)
void Write(QNetworkReply *Reply)
void Error(QNetworkReply::NetworkError Code)
QNetworkReply::NetworkError m_replyError
Subclass of QNetworkAccessManager for sending network requests and monitoring the network state...
Definition: torcnetwork.h:22
QByteArray ReadAll(int Timeout)
QAtomicInt m_availableToRead
int GetStatus(void) const
QByteArray GetHeader(const QByteArray &Header) const
Return the value of the given header, if present.
void SetRange(int Start, int End=0)
qint64 GetSize(void) const