Base class to pull data from a base class into asynchronous devices such as QProcess or QTcpSocket. More...
Classes | |
class | Context |
Describe the context of one device. More... | |
Public Slots | |
bool | start (QIODevice *device) |
Start to transfer data into the specified device. More... | |
bool | start (const QList< QIODevice *> &devices) |
Start to transfer data into the several devices in parallel. More... | |
void | stop () |
Force a premature stop of the data transfer. More... | |
void | stopCaller () |
This slot stops the transfer on the device which sent the signal. More... | |
void | stopDevice (QIODevice *device) |
Stop the transfer on the specified device. More... | |
Signals | |
void | completed (bool success) |
Emitted when the transfer is completed on all devices. More... | |
void | deviceCompleted (QIODevice *device, bool success) |
Emitted when the transfer is completed on one device. More... | |
void | progress (qint64 current, qint64 maximum) |
Emitted when some progress in the data transfer is available. More... | |
void | started () |
Emitted when the transfer is started. More... | |
Public Member Functions | |
QtlDataPull (int minBufferSize=DEFAULT_MIN_BUFFER_SIZE, QtlLogger *log=0, QObject *parent=0) | |
Constructor. More... | |
virtual | ~QtlDataPull () |
Destructor. More... | |
bool | isStarted () const |
Check if the data transfer is started. More... | |
QtlLogger * | log () const |
Get the message logger. More... | |
bool | progressAvailable () const |
Check if progress report is meaningful. More... | |
qint64 | pulledSize () const |
Get the total size of all pulled data. More... | |
void | setAutoDelete (bool on) |
Set automatic object deletion on transfer completion. More... | |
void | setMaxPulledSize (qint64 size) |
Set the maximum number of bytes to pull. More... | |
void | setProgressIntervalInBytes (qint64 size) |
Set the interval between two emissions of progress(). More... | |
void | setProgressMaxHint (qint64 size) |
Set the probable ("hint") total size of the transfer. More... | |
Static Public Attributes | |
static const int | DEFAULT_MIN_BUFFER_SIZE = 128 * 1024 |
Default minimum buffer size in bytes (128 kB). More... | |
Protected Member Functions | |
virtual void | cleanupTransfer (bool closed) |
Cleanup the transfer. More... | |
void | close () |
Properly terminate the transfer. More... | |
virtual bool | initializeTransfer () |
Initialize the transfer. More... | |
virtual bool | needTransfer (qint64 maxSize)=0 |
Invoked when more data is needed. More... | |
bool | write (const void *data, int dataSize) |
Write data to all devices. More... | |
Private Slots | |
void | bytesWritten (qint64 bytes) |
Invoked when a device has written data. More... | |
void | deviceDestroyed (QObject *object) |
Invoked when a device object is destroyed. More... | |
void | processNewState () |
Invoked from the event loop to process a new state. More... | |
Private Member Functions | |
void | deviceSpecificCleanup (QIODevice *dev, bool closed) |
Perform specific cleanup on a device, depending on its class. More... | |
void | deviceSpecificSetup (QIODevice *dev) |
Perform specific setup on a device, depending on its class. More... | |
bool | needMoreData () const |
Check if more data need to be pulled from the subclass. More... | |
void | processBytesWritten (QIODevice *dev, qint64 bytes) |
Invoked when a device has written data. More... | |
void | processNewStateLater () |
The appropriate processing of the new state will be performed later, after returning in the event loop. More... | |
Private Attributes | |
bool | _autoDelete |
Automatic object deletion on transfer completion. More... | |
bool | _closed |
True when close() is requested by subclass. More... | |
QList< Context > | _devices |
Active output devices. More... | |
QtlLogger * | _log |
Message logger. More... | |
qint64 | _maxIn |
Maximum data size to transfer. More... | |
int | _minBufferSize |
Lower limit of buffer size. More... | |
bool | _newStatePosted |
processNewState() is posted for execution. More... | |
QtlNullLogger | _nullLog |
Default logger. More... | |
int | _processingState |
A counter to protect processNewState(). More... | |
qint64 | _progressInterval |
Emit progress() at this interval (input size in bytes). More... | |
qint64 | _progressMaxHint |
Probable max input size, as reported by progress(). More... | |
qint64 | _progressNext |
Emit next progress() at this input size. More... | |
QTime | _startTime |
Time of start operation. More... | |
qint64 | _totalIn |
Total data transfered by write(). More... | |
Base class to pull data from a base class into asynchronous devices such as QProcess or QTcpSocket.
This class is based on a "pull" model where the data are "pulled" from the subclass when it is appropriate to write to the device's input. QProcess and other asynchronous devices use an internal buffer mechanism. If the application writes data into the device much faster that the process or network can read, then the data accumulate in memory. I have not seen any limiting mechanism in the Qt source code. So, for huge amounts of data (such as video files), the application might saturate its virtual memory.
This class provides a regulation mechanism which avoids that issue. The subclass is "pulled" only when some space is available. On the other hand, this class assumes that input data are always available from the base class.
|
explicit |
Constructor.
[in] | minBufferSize | The minimum buffer size is the lower limit of the buffered data. When the amount of data not yet written to the device is lower than this size, new data is pulled from the subclass. |
[in] | log | Where to log errors. |
[in] | parent | Optional parent object. |
|
virtual |
Destructor.
|
inline |
Set automatic object deletion on transfer completion.
[in] | on | When true, the object deletes itself automatically at the end of the transfer or if the transfer failed to start. Use with care, the object must have been created on the heap. |
|
inline |
Set the maximum number of bytes to pull.
After that number of bytes is read, a proper close is triggered.
[in] | size | Maximum size in bytes. If negative, no maximum is applied. |
|
inline |
Set the interval between two emissions of progress().
The interval is specified in number of input bytes. The signal progress() is emitted at most once in each interval but it not guaranteed that it is emitted on strict multiples of the interval size.
[in] | size | Emit progress() each time that number of input bytes is read. If negative or zero, progress() is never emitted. |
|
inline |
Set the probable ("hint") total size of the transfer.
This size is reported by progress() as maximum. This is useful only if a GUI needs to report the current percentage of the transfer.
[in] | size | Probable total size of the transfer. |
|
inline |
Check if progress report is meaningful.
|
inline |
Check if the data transfer is started.
|
inline |
Get the total size of all pulled data.
|
inline |
Get the message logger.
|
slot |
Start to transfer data into the specified device.
[in] | device | Data destination. Must be open for write. |
|
slot |
Start to transfer data into the several devices in parallel.
The data are pulled only once but duplicated to all devices.
[in] | devices | Data destinations. Must be open for write. |
|
slot |
Force a premature stop of the data transfer.
|
slot |
Stop the transfer on the specified device.
Transfer will continue to the other devices. If the device was the last one, then the transfer is aborted.
[in] | device | The device to remove from the transfer. |
|
slot |
This slot stops the transfer on the device which sent the signal.
This is a convenience slot which can be connected to a signal from a destination device, any form of signal such as "finished", "completed", "aborted" or "disconnected" that the device may support.
Note that the following device's signals are automatically connected to this slot:
|
signal |
Emitted when the transfer is started.
|
signal |
Emitted when some progress in the data transfer is available.
[in] | current | Current number of input bytes. |
[in] | maximum | Total size of the data transfer. It is only a hint. When neither setProgressMaxHint() not setMaxPulledSize() were called, maximum is -1. |
|
signal |
Emitted when the transfer is completed on one device.
This signal can be used to close, flush, disconnect or any other appropriate operation on the device.
Note that the following actions are automatically performed on various subclasses of QIODevice and the application does not need to take care about it.
[in] | device | Device for which the transfer is completed. |
[in] | success | True if all data were successfully transmitted to this device, false on premature error. |
|
signal |
Emitted when the transfer is completed on all devices.
The signal deviceCompleted() is sent once for each device. Then the signal completed() is sent once.
[in] | success | True if all data were successfully transmitted to all device, false on premature error on at least one device. |
|
inlineprotectedvirtual |
Initialize the transfer.
May be reimplemented by subclass.
Reimplemented in QtsDvdDataPull, QtlFileDataPull, and QtsDvdProgramChainDemux.
|
protectedpure virtual |
Invoked when more data is needed.
Must be reimplemented by subclass. An implementation will typically call write() to provide data. If no more data is available, an implementation must call close().
[in] | maxSize | Maximum size in bytes of the requested transfer. If negative, there is not limit. |
Implemented in QtsDvdDataPull, QtlFileDataPull, and QtsDvdProgramChainDemux.
|
inlineprotectedvirtual |
Cleanup the transfer.
May be reimplemented by subclass.
[in] | closed | If true, this is a clean termination, after the subclass called close(). When false, the transfer has been interrupted for an external reason. |
Reimplemented in QtsDvdDataPull, QtlFileDataPull, and QtsDvdProgramChainDemux.
|
protected |
Write data to all devices.
Must be called by subclass to transfer data.
[in] | data | Address of data to transfer. |
[in] | dataSize | Size in bytes of data to transfer. |
|
protected |
Properly terminate the transfer.
Must be called by subclass to signal the end of the transfer. The method cleanupTransfer() will be called later with closed set to true
.
|
privateslot |
Invoked when a device has written data.
[in] | bytes | Number of bytes written. |
|
privateslot |
Invoked when a device object is destroyed.
|
privateslot |
Invoked from the event loop to process a new state.
|
private |
The appropriate processing of the new state will be performed later, after returning in the event loop.
|
private |
Invoked when a device has written data.
[in] | dev | Destination device. |
[in] | bytes | Number of bytes written. |
|
private |
Check if more data need to be pulled from the subclass.
|
private |
Perform specific setup on a device, depending on its class.
[in] | dev | Device to setup. |
|
private |
Perform specific cleanup on a device, depending on its class.
[in] | dev | Device to setup. |
[in] | closed | True on normal termination, false if the transfer was aborted. |
|
static |
Default minimum buffer size in bytes (128 kB).
|
private |
Default logger.
|
private |
Message logger.
|
private |
Automatic object deletion on transfer completion.
|
private |
Lower limit of buffer size.
|
private |
Time of start operation.
|
private |
True when close() is requested by subclass.
|
private |
Maximum data size to transfer.
|
private |
Emit progress() at this interval (input size in bytes).
|
private |
Probable max input size, as reported by progress().
|
private |
Emit next progress() at this input size.
|
private |
Total data transfered by write().
|
private |
Active output devices.
|
private |
processNewState() is posted for execution.
|
private |
A counter to protect processNewState().