A
download qasyncio.cpp
Language: C++
License: GPL
Copyright: (C) 1992-2000 Trolltech AS. All rights reserved.
LOC: 111
Project Info
FacturaLUX
Server: SourceForge
Type: cvs
...rototipo\src\qt\src\kernel\
   makepsheader.pl
   q1xcompatibility.h
   qabstractlayout.cpp
   qabstractlayout.h
   qaccel.cpp
   qaccel.h
   qaccessible.cpp
   qaccessible.h
   qapplication.cpp
   qapplication.h
   qapplication_p.h
   qapplication_x11.cpp
   qasyncimageio.cpp
   qasyncimageio.h
   qasyncio.cpp
   qasyncio.h
   qbitmap.cpp
   qbitmap.h
   qbrush.h
   qclipboard.cpp
   qclipboard.h
   qclipboard_x11.cpp
   qcolor.cpp
   qcolor.h
   qcolor_p.cpp
   qcolor_p.h
   qcolor_x11.cpp
   qcomplextext.cpp
   qcomplextext_p.h
   qconnection.cpp
   qconnection.h
   qcursor.cpp
   qcursor.h
   qcursor_x11.cpp
   qdesktopwidget.h
   qdesktopwidget_x11.cpp
   qdnd_x11.cpp
   qdragobject.cpp
   qdragobject.h
   qdrawutil.cpp
   qdrawutil.h
   qdropsite.cpp
   qdropsite.h
   qevent.cpp
   qevent.h
   qeventloop.cpp
   qeventloop.h
   qeventloop_p.h
   qeventloop_unix.cpp
   qeventloop_x11.cpp
   qfocusdata.cpp
   qfocusdata.h
   qfont.cpp
   qfont.h
   qfont_x11.cpp
   qfontdata_p.h
   qfontdatabase.cpp
   qfontdatabase.h
   qfontdatabase_x11.cpp
   qfontengine_p.h
   qfontengine_x11.cpp
   qfontinfo.h
   qfontmetrics.h
   qgif.h
   qgplugin.cpp
   qgplugin.h
   qguardedptr.cpp
   qguardedptr.h
   qiconset.cpp
   qiconset.h
   qimage.cpp
   qimage.h
   qimageformatinterface_p.h
   qimageformatplugin.cpp
   qimageformatplugin.h
   qinputcontext_p.h
   qinputcontext_x11.cpp
   qinternal.cpp
   qinternal_p.h
   qjpegio.cpp
   qjpegio.h
   qkeycode.h
   qkeysequence.cpp
   qkeysequence.h
   qlayout.cpp
   qlayout.h
   qlayoutengine.cpp
   qlayoutengine_p.h
   qlocalfs.cpp
   qlocalfs.h
   qlock.cpp
   qlock_p.h
   qmetaobject.cpp
   qmetaobject.h
   qmime.cpp
   qmime.h
   qmngio.cpp
   qmngio.h
   qmotifdnd_x11.cpp
   qmovie.cpp
   qmovie.h
   qnamespace.h
   qnetworkprotocol.cpp
   qnetworkprotocol.h
   qobject.cpp
   qobject.h
   qobjectcleanuphandler.cpp
   qobjectcleanuphandler.h
   qobjectdefs.h
   qobjectdict.h
   qobjectlist.h
   qpaintdevice.h
   qpaintdevice_x11.cpp
   qpaintdevicedefs.h
   qpaintdevicemetrics.cpp
   qpaintdevicemetrics.h
   qpainter.cpp
   qpainter.h
   qpainter_p.h
   qpainter_x11.cpp
   qpalette.cpp
   qpalette.h
   qpen.h
   qpicture.cpp
   qpicture.h
   qpixmap.cpp
   qpixmap.h
   qpixmap_x11.cpp
   qpixmapcache.cpp
   qpixmapcache.h
   qpngio.cpp
   qpngio.h
   qpoint.cpp
   qpoint.h
   qpointarray.cpp
   qpointarray.h
   qpolygonscanner.cpp
   qpolygonscanner.h
   qprinter.cpp
   qprinter.h
   qprinter_p.h
   qprinter_unix.cpp
   qprocess.cpp
   qprocess.h
   qprocess_unix.cpp
   qpsprinter.cpp
   qpsprinter.ps
   qpsprinter_p.h
   qrect.cpp
   qrect.h
   qregion.cpp
   qregion.h
   qregion_x11.cpp
   qrichtext.cpp
   qrichtext_p.cpp
   qrichtext_p.h
   qscriptengine.cpp
   qscriptengine_p.h
   qscriptengine_x11.cpp
   qsession.h
   qsessionmanager.h
   qsharedmemory_p.cpp
   qsharedmemory_p.h
   qsignal.cpp
   qsignal.h
   qsignalmapper.cpp
   qsignalmapper.h
   qsignalslotimp.h
   qsimplerichtext.cpp
   qsimplerichtext.h
   qsize.cpp
   qsize.h
   qsizegrip.cpp
   qsizegrip.h
   qsizepolicy.h
   qsocketnotifier.cpp
   qsocketnotifier.h
   qsound.cpp
   qsound.h
   qsound_x11.cpp
   qstyle.cpp
   qstyle.h
   qstylesheet.cpp
   qstylesheet.h
   qt.h
   qt_compat.pri
   qt_gfx.pri
   qt_kernel.pri
   qt_x11.pri
   qt_x11_p.h
   qtaddons_x11.cpp
   qtextengine.cpp
   qtextengine_p.h
   qtextengine_unix.cpp
   qtextlayout.cpp
   qtextlayout_p.h
   qthread.cpp
   qthread.h
   qthread_unix.cpp
   qtimer.cpp
   qtimer.h
   qtranslator.cpp
   qtranslator.h
   qucomextra.cpp
   qucomextra_p.h
   qurl.cpp
   qurl.h
   qurlinfo.cpp
   qurlinfo.h
   qurloperator.cpp
   qurloperator.h
   qvariant.cpp
   qvariant.h
   qvfbhdr.h
   qwidget.cpp
   qwidget.h
   qwidget_p.h
   qwidget_x11.cpp
   qwidgetcreate_x11.cpp
   qwidgetintdict.h
   qwidgetlist.h
   qwindow.cpp
   qwindow.h
   qwindowdefs.h
   qwmatrix.cpp
   qwmatrix.h

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
/****************************************************************************
** $Id: qasyncio.cpp,v 1.1 2003/12/04 08:17:52 falbujer Exp $
**
** Implementation of asynchronous I/O classes
**
** Created : 970617
**
** Copyright (C) 1992-2000 Trolltech AS.  All rights reserved.
**
** This file is part of the kernel module of the Qt GUI Toolkit.
**
** This file may be distributed under the terms of the Q Public License
** as defined by Trolltech AS of Norway and appearing in the file
** LICENSE.QPL included in the packaging of this file.
**
** This file may be distributed and/or modified under the terms of the
** GNU General Public License version 2 as published by the Free Software
** Foundation and appearing in the file LICENSE.GPL included in the
** packaging of this file.
**
** Licensees holding valid Qt Enterprise Edition or Qt Professional Edition
** licenses may use this file in accordance with the Qt Commercial License
** Agreement provided with the Software.
**
** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
**
** See http://www.trolltech.com/pricing.html or email sales@trolltech.com for
**   information about Qt Commercial License Agreements.
** See http://www.trolltech.com/qpl/ for QPL licensing information.
** See http://www.trolltech.com/gpl/ for GPL licensing information.
**
** Contact info@trolltech.com if any conditions of this licensing are
** not clear to you.
**
**********************************************************************/

#include "qasyncio.h"
#include "qiodevice.h"
#include <stdlib.h>

#ifndef QT_NO_ASYNC_IO

/*!
  \class QAsyncIO qasyncio.h
  \obsolete
  \brief The QAsyncIO class encapsulates I/O asynchronicity.

  The Qt classes for asynchronous input/output provide a simple
  mechanism to allow large files or slow data sources to be processed
  without using large amounts of memory or blocking the user interface.

  This facility is used in Qt to drive animated images.  See QImageConsumer.
*/


/*!
  Destroys the async IO object.
*/
QAsyncIO::~QAsyncIO()
{
}

/*!
  Ensures that only one object, \a obj and function, \a member, can
  respond to changes in readiness.
*/
void QAsyncIO::connect(QObject* obj, const char *member)
{
    signal.disconnect(0, 0);
    signal.connect(obj, member);
}

/*!
  Derived classes should call this when they change from being
  unready to ready.
*/
void QAsyncIO::ready()
{
    signal.activate();
}



/*!
  \class QDataSink qasyncio.h
  \obsolete
  \brief The QDataSink class is an asynchronous consumer of data.

  A data sink is an object which receives data from some source in an
  asynchronous manner.  This means that at some time not determined by
  the data sink, blocks of data are given to it from processing.  The
  data sink is able to limit the maximum size of such blocks which it
  is currently able to process.

  \sa QAsyncIO, QDataSource, QDataPump
*/

/*!
  \fn int QDataSink::readyToReceive()

  The data sink should return a value indicating how much data it is ready
  to consume.  This may be 0.
*/

/*!
  This should be called whenever readyToReceive() might have become non-zero.
  It is merely calls QAsyncIO::ready() if readyToReceive() is non-zero.
*/
void QDataSink::maybeReady()
{
    if (readyToReceive()) ready();
}

/*!
  \fn void QDataSink::receive(const uchar*, int count)

  This function is called to provide data for the data sink.  The \a count
  will be no more than the amount indicated by the most recent call to
  readyToReceive().  The sink must use all the provided data.
*/

/*!
  \fn void QDataSink::eof()

  This function will be called when no more data is available for
  processing.
*/


/*!
  \class QDataSource qasyncio.h
  \obsolete
  \brief The QDataSource class is an asynchronous producer of data.

  A data source is an object which provides data from some source in an
  asynchronous manner.  This means that at some time not determined by
  the data source, blocks of data will be taken from it for processing.
  The data source is able to limit the maximum size of such blocks which
  it is currently able to provide.

  \sa QAsyncIO, QDataSink, QDataPump
*/

/*!
  \fn int QDataSource::readyToSend()

  The data source should return a value indicating how much data it is ready
  to provide.  This may be 0.  If the data source knows it will never be
  able to provide any more data (until after a rewind()), it may return -1.
*/

/*!
  This should be called whenever readyToSend() might have become non-zero.
  It is merely calls QAsyncIO::ready() if readyToSend() is non-zero.
*/
void QDataSource::maybeReady()
{
    if (readyToSend()) ready();
}

/*!
  \fn void QDataSource::sendTo(QDataSink*, int count)

  This function is called to extract data from the source, by sending
  it to the given data sink.  The \a count will be no more than the amount
  indicated by the most recent call to readyToSend().  The source must
  use all the provided data, and the sink will be prepared to accept at
  least this much data.
*/

/*!
  This function should return TRUE if the data source can be rewound.

  The default returns FALSE.
*/
bool QDataSource::rewindable() const
{
    return FALSE;
}

/*!
  If this function is called with \a on set to TRUE, and rewindable()
  is TRUE, then the data source must take measures to allow the rewind()
  function to subsequently operate as described.  If rewindable() is FALSE,
  the function should call QDataSource::enableRewind(), which aborts with
  a qFatal() error.

  For example, a network connection may choose to use a disk cache
  of input only if rewinding is enabled before the first buffer-full of
  data is discarded, returning FALSE in rewindable() if that first buffer
  is discarded.
*/
void QDataSource::enableRewind( bool /* on */ )
{
    qFatal( "Attempted to make unrewindable QDataSource rewindable" );
}

/*!
  This function rewinds the data source.  This may only be called if
  enableRewind(TRUE) has been previously called.
*/
void QDataSource::rewind()
{
    qFatal("Attempted to rewind unrewindable QDataSource");
}

/*!
  \class QIODeviceSource qasyncio.h
  \obsolete
  \brief The QIODeviceSource class is a QDataSource that draws data from a QIODevice.

  This class encapsulates retrieving data from a QIODevice (such as a QFile).
*/

/*!
  Constructs a QIODeviceSource from the QIODevice \a device.  The QIODevice
  \e must be dynamically allocated, becomes owned by the QIODeviceSource,
  and will be deleted when the QIODeviceSource is destroyed. \a buffer_size
  determines the size of buffering to use between asynchronous operations.
  The higher the \a buffer_size, the more efficient, but the less interleaved
  the operation will be with other processing.
*/
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.
*/
QIODeviceSource::~QIODeviceSource()
{
    delete iod;
    delete [] buffer;
}

/*!
  Ready until end-of-file.
*/
int QIODeviceSource::readyToSend()
{
    if ( iod->status() != IO_Ok || !(iod->state() & IO_Open) )
	return -1;

    int n = QMIN((uint)buf_size, iod->size()-iod->at()); // ### not 64-bit safe
                                                         // ### not large file safe
    return n ? n : -1;
}

/*!
  Reads a block of data and sends up to \a n bytes to the \a sink.
*/
void QIODeviceSource::sendTo(QDataSink* sink, int n)
{
    iod->readBlock((char*)buffer, n);
    sink->receive(buffer, n);
}

/*!
  All QIODeviceSource's are rewindable.
*/
bool QIODeviceSource::rewindable() const
{
    return TRUE;
}

/*!
  If \a on is set to TRUE then rewinding is enabled.  
  No special action is taken.  If \a on is set to 
  FALSE then rewinding is disabled.
*/
void QIODeviceSource::enableRewind(bool on)
{
    rew = on;
}

/*!
  Calls reset() on the QIODevice.
*/
void QIODeviceSource::rewind()
{
    if (!rew) {
	QDataSource::rewind();
    } else {
	iod->reset();
	ready();
    }
}


/*!
  \class QDataPump qasyncio.h
  \obsolete
  \brief The QDataPump class 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.
*/
QDataPump::QDataPump(QDataSource* data_source, QDataSink* data_sink) :
    source(data_source), sink(data_sink)
{
    source->connect(this, SLOT(kickStart()));
    sink->connect(this, SLOT(kickStart()));
    connect(&timer, SIGNAL(timeout()), this, SLOT(tryToPump()));
    timer.start(0, TRUE);
}

void QDataPump::kickStart()
{
    if (!timer.isActive()) {
	interval = 0;
	timer.start(0, TRUE);
    }
}

void QDataPump::tryToPump()
{
    int supply, demand;

    supply = source->readyToSend();
    demand = sink->readyToReceive();
    if (demand <= 0) {
	return;
    }
    interval = 0;
    if (supply < 0) {
	// All done (until source signals change in readiness)
	sink->eof();
	return;
    }
    if (!supply)
	return;
    source->sendTo(sink, QMIN(supply, demand));

    timer.start(0, TRUE);
}

#endif // QT_NO_ASYNC_IO

About Koders | Resources | Downloads | Support | Black Duck | Terms of Service | DMCA | Privacy Policy | Contact Us