Torc  0.1
Public Member Functions | Protected Member Functions | Protected Attributes | Friends | List of all members
TorcNetworkRequest Class Reference

A wrapper around QNetworkRequest. More...

#include <torcnetworkrequest.h>

Inheritance diagram for TorcNetworkRequest:
[legend]

Public Member Functions

 TorcNetworkRequest (const QNetworkRequest &Request, QNetworkAccessManager::Operation Type, int BufferSize, int *Abort)
 
 TorcNetworkRequest (const QNetworkRequest &Request, const QByteArray &PostData, int *Abort)
 
bool WaitForStart (int Timeout)
 
int Peek (char *Buffer, qint32 BufferSize, int Timeout)
 
int Read (char *Buffer, qint32 BufferSize, int Timeout, bool Peek=false)
 
qint64 Seek (qint64 Offset)
 
QByteArray & GetBuffer (void)
 
QByteArray ReadAll (int Timeout)
 
int BytesAvailable (void)
 
qint64 GetSize (void) const
 
qint64 GetPosition (void) const
 
void SetReadSize (int Size)
 
void SetRange (int Start, int End=0)
 
void DownloadProgress (qint64 Received, qint64 Total)
 
bool CanByteServe (void) const
 
QUrl GetFinalURL (void) const
 
QString GetContentType (void) const
 
int GetStatus (void) const
 
QByteArray GetHeader (const QByteArray &Header) const
 Return the value of the given header, if present. More...
 
QNetworkReply::NetworkError GetReplyError (void) const
 
void SetReplyError (QNetworkReply::NetworkError Error)
 
- Public Member Functions inherited from TorcReferenceCounter
 TorcReferenceCounter (void)
 
virtual ~TorcReferenceCounter (void)=default
 
void UpRef (void)
 
virtual bool DownRef (void)
 
bool IsShared (void)
 

Protected Member Functions

virtual ~TorcNetworkRequest ()=default
 
void Write (QNetworkReply *Reply)
 

Protected Attributes

QNetworkAccessManager::Operation m_type
 
int * m_abort
 
bool m_started
 
qint64 m_positionInFile
 
qint64 m_rewindPositionInFile
 
int m_readPosition
 
int m_writePosition
 
QAtomicInt m_availableToRead
 
int m_bufferSize
 
int m_reserveBufferSize
 
int m_writeBufferSize
 
QByteArray m_buffer
 
int m_readSize
 
int m_redirectionCount
 
TorcTimer m_readTimer
 
TorcTimer m_writeTimer
 
const QByteArray m_postData
 
bool m_replyFinished
 
int m_replyBytesAvailable
 
qint64 m_bytesReceived
 
qint64 m_bytesTotal
 
QList< QNetworkReply::RawHeaderPair > m_rawHeaders
 
QNetworkReply::NetworkError m_replyError
 
QNetworkRequest m_request
 
int m_rangeStart
 
int m_rangeEnd
 
int m_httpStatus
 
qint64 m_contentLength
 
QString m_contentType
 
bool m_byteServingAvailable
 
- Protected Attributes inherited from TorcReferenceCounter
QAtomicInt m_refCount
 

Friends

class TorcNetwork
 

Additional Inherited Members

- Static Public Member Functions inherited from TorcReferenceCounter
static void EventLoopEnding (bool Ending)
 
- Static Protected Attributes inherited from TorcReferenceCounter
static bool m_eventLoopEnding = false
 

Detailed Description

A wrapper around QNetworkRequest.

TorcNetworkRequest acts as the intermediary between TorcNetwork and any other class accessing the network.

The requestor must create a valid QNetworkRequest, an abort signal and, if a streamed download is required, provide a buffer size.

In the case of streamed downloads, a circular buffer of the given size is created which must be emptied (via Read) on a frequent basis. The readBufferSize for the associated QNetworkReply is set to the same size. Hence there is matched buffering between Qt and Torc. Streamed downloads are optimised for a single producer and a single consumer thread - any other usage is likely to lead to tears before bedtime.

For non-streamed requests, the complete download is copied to the internal buffer and can be retrieved via ReadAll. Take care when downloading files of an unknown size.

Definition at line 10 of file torcnetworkrequest.h.

Constructor & Destructor Documentation

TorcNetworkRequest::TorcNetworkRequest ( const QNetworkRequest &  Request,
QNetworkAccessManager::Operation  Type,
int  BufferSize,
int *  Abort 
)

Definition at line 51 of file torcnetworkrequest.cpp.

TorcNetworkRequest::TorcNetworkRequest ( const QNetworkRequest &  Request,
const QByteArray &  PostData,
int *  Abort 
)

Definition at line 88 of file torcnetworkrequest.cpp.

virtual TorcNetworkRequest::~TorcNetworkRequest ( )
protectedvirtualdefault

Member Function Documentation

int TorcNetworkRequest::BytesAvailable ( void  )

Definition at line 122 of file torcnetworkrequest.cpp.

bool TorcNetworkRequest::CanByteServe ( void  ) const

Definition at line 352 of file torcnetworkrequest.cpp.

void TorcNetworkRequest::DownloadProgress ( qint64  Received,
qint64  Total 
)

Definition at line 346 of file torcnetworkrequest.cpp.

QByteArray & TorcNetworkRequest::GetBuffer ( void  )

Definition at line 394 of file torcnetworkrequest.cpp.

QString TorcNetworkRequest::GetContentType ( void  ) const

Definition at line 362 of file torcnetworkrequest.cpp.

QUrl TorcNetworkRequest::GetFinalURL ( void  ) const

Definition at line 357 of file torcnetworkrequest.cpp.

QByteArray TorcNetworkRequest::GetHeader ( const QByteArray &  Header) const

Return the value of the given header, if present.

Returns
The value of the requested header or a null QByteArray (isNull()) if not found.

Definition at line 376 of file torcnetworkrequest.cpp.

qint64 TorcNetworkRequest::GetPosition ( void  ) const

Definition at line 135 of file torcnetworkrequest.cpp.

QNetworkReply::NetworkError TorcNetworkRequest::GetReplyError ( void  ) const

Definition at line 384 of file torcnetworkrequest.cpp.

qint64 TorcNetworkRequest::GetSize ( void  ) const

Definition at line 130 of file torcnetworkrequest.cpp.

int TorcNetworkRequest::GetStatus ( void  ) const

Definition at line 367 of file torcnetworkrequest.cpp.

int TorcNetworkRequest::Peek ( char *  Buffer,
qint32  BufferSize,
int  Timeout 
)

Definition at line 153 of file torcnetworkrequest.cpp.

int TorcNetworkRequest::Read ( char *  Buffer,
qint32  BufferSize,
int  Timeout,
bool  Peek = false 
)

Definition at line 192 of file torcnetworkrequest.cpp.

QByteArray TorcNetworkRequest::ReadAll ( int  Timeout)

Definition at line 399 of file torcnetworkrequest.cpp.

qint64 TorcNetworkRequest::Seek ( qint64  Offset)

If this is a streamed download, attempt to seek within the range of what is currently buffered.

Definition at line 162 of file torcnetworkrequest.cpp.

void TorcNetworkRequest::SetRange ( int  Start,
int  End = 0 
)

Definition at line 319 of file torcnetworkrequest.cpp.

void TorcNetworkRequest::SetReadSize ( int  Size)

Definition at line 314 of file torcnetworkrequest.cpp.

void TorcNetworkRequest::SetReplyError ( QNetworkReply::NetworkError  Error)

Definition at line 389 of file torcnetworkrequest.cpp.

bool TorcNetworkRequest::WaitForStart ( int  Timeout)

Definition at line 143 of file torcnetworkrequest.cpp.

void TorcNetworkRequest::Write ( QNetworkReply *  Reply)
protected

Definition at line 284 of file torcnetworkrequest.cpp.

Friends And Related Function Documentation

friend class TorcNetwork
friend

Definition at line 12 of file torcnetworkrequest.h.

Member Data Documentation

int* TorcNetworkRequest::m_abort
protected

Definition at line 49 of file torcnetworkrequest.h.

QAtomicInt TorcNetworkRequest::m_availableToRead
protected

Definition at line 55 of file torcnetworkrequest.h.

QByteArray TorcNetworkRequest::m_buffer
protected

Definition at line 59 of file torcnetworkrequest.h.

int TorcNetworkRequest::m_bufferSize
protected

Definition at line 56 of file torcnetworkrequest.h.

bool TorcNetworkRequest::m_byteServingAvailable
protected

Definition at line 83 of file torcnetworkrequest.h.

qint64 TorcNetworkRequest::m_bytesReceived
protected

Definition at line 71 of file torcnetworkrequest.h.

qint64 TorcNetworkRequest::m_bytesTotal
protected

Definition at line 72 of file torcnetworkrequest.h.

qint64 TorcNetworkRequest::m_contentLength
protected

Definition at line 81 of file torcnetworkrequest.h.

QString TorcNetworkRequest::m_contentType
protected

Definition at line 82 of file torcnetworkrequest.h.

int TorcNetworkRequest::m_httpStatus
protected

Definition at line 80 of file torcnetworkrequest.h.

qint64 TorcNetworkRequest::m_positionInFile
protected

Definition at line 51 of file torcnetworkrequest.h.

const QByteArray TorcNetworkRequest::m_postData
protected

Definition at line 66 of file torcnetworkrequest.h.

int TorcNetworkRequest::m_rangeEnd
protected

Definition at line 79 of file torcnetworkrequest.h.

int TorcNetworkRequest::m_rangeStart
protected

Definition at line 78 of file torcnetworkrequest.h.

QList<QNetworkReply::RawHeaderPair> TorcNetworkRequest::m_rawHeaders
protected

Definition at line 73 of file torcnetworkrequest.h.

int TorcNetworkRequest::m_readPosition
protected

Definition at line 53 of file torcnetworkrequest.h.

int TorcNetworkRequest::m_readSize
protected

Definition at line 60 of file torcnetworkrequest.h.

TorcTimer TorcNetworkRequest::m_readTimer
protected

Definition at line 62 of file torcnetworkrequest.h.

int TorcNetworkRequest::m_redirectionCount
protected

Definition at line 61 of file torcnetworkrequest.h.

int TorcNetworkRequest::m_replyBytesAvailable
protected

Definition at line 70 of file torcnetworkrequest.h.

QNetworkReply::NetworkError TorcNetworkRequest::m_replyError
protected

Definition at line 74 of file torcnetworkrequest.h.

bool TorcNetworkRequest::m_replyFinished
protected

Definition at line 69 of file torcnetworkrequest.h.

QNetworkRequest TorcNetworkRequest::m_request
protected

Definition at line 77 of file torcnetworkrequest.h.

int TorcNetworkRequest::m_reserveBufferSize
protected

Definition at line 57 of file torcnetworkrequest.h.

qint64 TorcNetworkRequest::m_rewindPositionInFile
protected

Definition at line 52 of file torcnetworkrequest.h.

bool TorcNetworkRequest::m_started
protected

Definition at line 50 of file torcnetworkrequest.h.

QNetworkAccessManager::Operation TorcNetworkRequest::m_type
protected

Definition at line 48 of file torcnetworkrequest.h.

int TorcNetworkRequest::m_writeBufferSize
protected

Definition at line 58 of file torcnetworkrequest.h.

int TorcNetworkRequest::m_writePosition
protected

Definition at line 54 of file torcnetworkrequest.h.

TorcTimer TorcNetworkRequest::m_writeTimer
protected

Definition at line 63 of file torcnetworkrequest.h.


The documentation for this class was generated from the following files: