Qt 4.8
qwindowspipewriter_p.h
Go to the documentation of this file.
1 /****************************************************************************
2 **
3 ** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
4 ** Contact: http://www.qt-project.org/legal
5 **
6 ** This file is part of the QtCore module of the Qt Toolkit.
7 **
8 ** $QT_BEGIN_LICENSE:LGPL$
9 ** Commercial License Usage
10 ** Licensees holding valid commercial Qt licenses may use this file in
11 ** accordance with the commercial license agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and Digia. For licensing terms and
14 ** conditions see http://qt.digia.com/licensing. For further information
15 ** use the contact form at http://qt.digia.com/contact-us.
16 **
17 ** GNU Lesser General Public License Usage
18 ** Alternatively, this file may be used under the terms of the GNU Lesser
19 ** General Public License version 2.1 as published by the Free Software
20 ** Foundation and appearing in the file LICENSE.LGPL included in the
21 ** packaging of this file. Please review the following information to
22 ** ensure the GNU Lesser General Public License version 2.1 requirements
23 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
24 **
25 ** In addition, as a special exception, Digia gives you certain additional
26 ** rights. These rights are described in the Digia Qt LGPL Exception
27 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
28 **
29 ** GNU General Public License Usage
30 ** Alternatively, this file may be used under the terms of the GNU
31 ** General Public License version 3.0 as published by the Free Software
32 ** Foundation and appearing in the file LICENSE.GPL included in the
33 ** packaging of this file. Please review the following information to
34 ** ensure the GNU General Public License version 3.0 requirements will be
35 ** met: http://www.gnu.org/copyleft/gpl.html.
36 **
37 **
38 ** $QT_END_LICENSE$
39 **
40 ****************************************************************************/
41 
42 #ifndef QWINDOWSPIPEWRITER_P_H
43 #define QWINDOWSPIPEWRITER_P_H
44 
45 //
46 // W A R N I N G
47 // -------------
48 //
49 // This file is not part of the Qt API. It exists purely as an
50 // implementation detail. This header file may change from version to
51 // version without notice, or even be removed.
52 //
53 // We mean it.
54 //
55 
56 #include <qdatetime.h>
57 #include <qthread.h>
58 #include <qmutex.h>
59 #include <qwaitcondition.h>
60 #include <qt_windows.h>
61 
63 
65 
66 QT_MODULE(Core)
67 
68 #ifndef QT_NO_THREAD
69 
70 #define SLEEPMIN 10
71 #define SLEEPMAX 500
72 
74 {
75 
76 public:
78  : totalTimeOut(msecs)
80  {
81  if (totalTimeOut == -1)
83  timer.start();
84  }
85 
87  {
88  int tmp = nextSleep;
90  return tmp;
91  }
92 
93  int timeLeft() const
94  {
95  if (totalTimeOut == -1)
96  return SLEEPMAX;
97  return qMax(totalTimeOut - timer.elapsed(), 0);
98  }
99 
100  bool hasTimedOut() const
101  {
102  if (totalTimeOut == -1)
103  return false;
104  return timer.elapsed() >= totalTimeOut;
105  }
106 
108  {
110  }
111 
112 private:
116 };
117 
119 {
120  Q_OBJECT
121 
122 Q_SIGNALS:
123  void canWrite();
124  void bytesWritten(qint64 bytes);
125 
126 public:
127  QWindowsPipeWriter(HANDLE writePipe, QObject * parent = 0);
129 
130  bool waitForWrite(int msecs);
131  qint64 write(const char *data, qint64 maxlen);
132 
134  {
135  QMutexLocker locker(&lock);
136  return data.size();
137  }
138 
139  bool hadWritten() const
140  {
141  return hasWritten;
142  }
143 
144 protected:
145  void run();
146 
147 private:
150  mutable QMutex lock;
152  volatile bool quitNow;
154 };
155 
156 #endif //QT_NO_THREAD
157 
159 
161 
162 #endif // QT_NO_PROCESS
Q_DECL_CONSTEXPR const T & qMin(const T &a, const T &b)
Definition: qglobal.h:1215
#define QT_END_NAMESPACE
This macro expands to.
Definition: qglobal.h:90
The QMutex class provides access serialization between threads.
Definition: qmutex.h:60
#define QT_MODULE(x)
Definition: qglobal.h:2783
#define QT_BEGIN_HEADER
Definition: qglobal.h:136
void start()
Sets this time to the current time.
Definition: qdatetime.cpp:2070
The QByteArray class provides an array of bytes.
Definition: qbytearray.h:135
The QObject class is the base class of all Qt objects.
Definition: qobject.h:111
#define Q_SIGNALS
Definition: qobjectdefs.h:72
Q_DECL_CONSTEXPR const T & qMax(const T &a, const T &b)
Definition: qglobal.h:1217
qint64 bytesToWrite() const
The QTime class provides clock time functions.
Definition: qdatetime.h:148
#define QT_BEGIN_NAMESPACE
This macro expands to.
Definition: qglobal.h:89
#define SLEEPMAX
#define SLEEPMIN
static const char * data(const QByteArray &arr)
__int64 qint64
Definition: qglobal.h:942
void * HANDLE
Definition: qnamespace.h:1671
#define Q_OBJECT
Definition: qobjectdefs.h:157
QWaitCondition waitCondition
int elapsed() const
Returns the number of milliseconds that have elapsed since the last time start() or restart() was cal...
Definition: qdatetime.cpp:2123
The QMutexLocker class is a convenience class that simplifies locking and unlocking mutexes...
Definition: qmutex.h:101
#define Q_CORE_EXPORT
Definition: qglobal.h:1449
static QReadWriteLock lock
Definition: proxyconf.cpp:399
QFuture< T > run(Function function,...)
#define QT_END_HEADER
Definition: qglobal.h:137
The QThread class provides a platform-independent way to manage threads.
Definition: qthread.h:59