OSDN Git Service

Update license.
[qt-creator-jp/qt-creator-jp.git] / src / shared / symbianutils / virtualserialdevice.h
1 /**************************************************************************
2 **
3 ** This file is part of Qt Creator
4 **
5 ** Copyright (c) 2011 Nokia Corporation and/or its subsidiary(-ies).
6 **
7 ** Contact: Nokia Corporation (info@qt.nokia.com)
8 **
9 **
10 ** GNU Lesser General Public License Usage
11 **
12 ** This file may be used under the terms of the GNU Lesser General Public
13 ** License version 2.1 as published by the Free Software Foundation and
14 ** appearing in the file LICENSE.LGPL included in the packaging of this file.
15 ** Please review the following information to ensure the GNU Lesser General
16 ** Public License version 2.1 requirements will be met:
17 ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
18 **
19 ** In addition, as a special exception, Nokia gives you certain additional
20 ** rights. These rights are described in the Nokia Qt LGPL Exception
21 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
22 **
23 ** Other Usage
24 **
25 ** Alternatively, this file may be used in accordance with the terms and
26 ** conditions contained in a signed written agreement between you and Nokia.
27 **
28 ** If you have questions regarding the use of this file, please contact
29 ** Nokia at qt-info@nokia.com.
30 **
31 **************************************************************************/
32
33 #ifndef VIRTUALSERIALPORT_H
34 #define VIRTUALSERIALPORT_H
35
36 #include <QtCore/QIODevice>
37 #include <QtCore/QString>
38 #include <QtCore/QMutex>
39
40 QT_BEGIN_NAMESPACE
41 class QWaitCondition;
42 QT_END_NAMESPACE
43
44 #include "symbianutils_global.h"
45
46 namespace SymbianUtils {
47
48 class VirtualSerialDevicePrivate;
49
50 class SYMBIANUTILS_EXPORT VirtualSerialDevice : public QIODevice
51 {
52     Q_OBJECT
53 public:
54     explicit VirtualSerialDevice(const QString &name, QObject *parent = 0);
55     ~VirtualSerialDevice();
56
57     bool open(OpenMode mode);
58     void close();
59     const QString &getPortName() const;
60     void flush();
61
62     qint64 bytesAvailable() const;
63     bool isSequential() const;
64     bool waitForBytesWritten(int msecs);
65     bool waitForReadyRead(int msecs);
66
67 protected:
68     qint64 readData(char *data, qint64 maxSize);
69     qint64 writeData(const char *data, qint64 maxSize);
70
71 private:
72     Q_DISABLE_COPY(VirtualSerialDevice)
73     void platInit();
74     void platClose();
75     void emitBytesWrittenIfNeeded(QMutexLocker &locker, qint64 len);
76
77 private:
78     QString portName;
79     mutable QMutex lock;
80     QList<QByteArray> pendingWrites;
81     bool emittingBytesWritten;
82     QWaitCondition* waiterForBytesWritten;
83     VirtualSerialDevicePrivate *d;
84
85 // Platform-specific stuff
86 #ifdef Q_OS_WIN
87 private:
88     qint64 writeNextBuffer(QMutexLocker &locker);
89     void doWriteCompleted(QMutexLocker &locker);
90 private slots:
91     void writeCompleted();
92     void commEventOccurred();
93 #endif
94
95 #ifdef Q_OS_UNIX
96 private:
97     bool tryWrite(const char *data, qint64 maxSize, qint64 &bytesWritten);
98     enum FlushPendingOption {
99         NothingSpecial = 0,
100         StopAfterWritingOneBuffer = 1,
101         EmitBytesWrittenAsync = 2, // Needed so we don't emit bytesWritten signal directly from writeBytes
102     };
103     Q_DECLARE_FLAGS(FlushPendingOptions, FlushPendingOption)
104     bool tryFlushPendingBuffers(QMutexLocker& locker, FlushPendingOptions flags = NothingSpecial);
105
106 private slots:
107     void writeHasUnblocked(int fileHandle);
108
109 signals:
110     void AsyncCall_emitBytesWrittenIfNeeded(qint64 len);
111
112 #endif
113
114 };
115
116 } // namespace SymbianUtils
117
118 #endif // VIRTUALSERIALPORT_H