Source Code (Use browser search to find items of interest.)

Class Index

qt'QIODeviceSource (./qt-2.1.0/src/kernel/qasyncio.h:69)

class Q_EXPORT QIODeviceSource : public QDataSource {
    const int buf_size;
    uchar *buffer;
    QIODevice* iod;
    bool rew;

public:
    QIODeviceSource(QIODevice*, int bufsize=4096);
   ~QIODeviceSource();

    int readyToSend();
    void sendTo(QDataSink* sink, int n);
    bool rewindable() const;
    void enableRewind(bool on);
    void rewind();
};


qt'QIODeviceSource::QIODeviceSource() (./qt-2.1.0/src/kernel/qasyncio.cpp:207)

QIODeviceSource::QIODeviceSource(QIODevice* device, int buffer_size) :
    buf_size(buffer_size),
    buffer(new uchar[buf_size]),
    iod(device),
    rew(FALSE)
{
}

/*!
  Destroys the QIODeviceSource, deleting the QIODevice from which it was
  constructed.
*/

qt'QIODeviceSource::~QIODeviceSource() (./qt-2.1.0/src/kernel/qasyncio.cpp:219)

QIODeviceSource::~QIODeviceSource()
{
    delete iod;
    delete [] buffer;
}

/*!
  Ready until end-of-file.
*/

qt'QIODeviceSource::readyToSend() (./qt-2.1.0/src/kernel/qasyncio.cpp:228)

int QIODeviceSource::readyToSend()
{
    if ( iod->status() != IO_Ok || !(iod->state() & IO_Open) )
	return -1;

    int n = QMIN((uint)buf_size, iod->size()-iod->at());
    return n ? n : -1;
}

/*!
  Reads and sends a block of data.
*/

qt'QIODeviceSource::sendTo() (./qt-2.1.0/src/kernel/qasyncio.cpp:240)

void QIODeviceSource::sendTo(QDataSink* sink, int n)
{
    iod->readBlock((char*)buffer, n);
    sink->receive(buffer, n);
}

/*!
  All QIODeviceSource's are rewindable.
*/

qt'QIODeviceSource::rewindable() (./qt-2.1.0/src/kernel/qasyncio.cpp:249)

bool QIODeviceSource::rewindable() const
{
    return TRUE;
}

/*!
  Enables rewinding.  No special action is taken.
*/

qt'QIODeviceSource::enableRewind() (./qt-2.1.0/src/kernel/qasyncio.cpp:257)

void QIODeviceSource::enableRewind(bool on)
{
    rew = on;
}

/*!
  Calls reset() on the QIODevice.
*/

qt'QIODeviceSource::rewind() (./qt-2.1.0/src/kernel/qasyncio.cpp:265)

void QIODeviceSource::rewind()
{
    if (!rew) {
	QDataSource::rewind();
    } else {
	iod->reset();
	ready();
    }
}


/*!
  \class QDataPump qasyncio.h
  \brief Moves data from a QDataSource to a QDataSink during event processing.

  For a QDataSource to provide data to a QDataSink, a controller must exist
  to examine the QDataSource::readyToSend() and QDataSink::readyToReceive()
  methods and respond to the QASyncIO::activate() signal of the source and
  sink.  One very useful way to do this is interleaved with other event
  processing.  QDataPump provides this - create a pipe between a source
  and a sink, and data will be moved during subsequent event processing.

  Note that each source can only provide data to one sink and each sink
  can only receive data from one source (although it is quite possible
  to write a multiplexing sink that is multiple sources).
*/

/*!
  Constructs a QDataPump to move data from a given \a data_source
  to a given \a data_sink.
*/