OSDN Git Service

Update license.
[qt-creator-jp/qt-creator-jp.git] / src / shared / symbianutils / trkdevice.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 TRKDEVICE_H
34 #define TRKDEVICE_H
35
36 #include "symbianutils_global.h"
37 #include "callback.h"
38
39 #include <QtCore/QObject>
40 #include <QtCore/QVariant>
41 #include <QtCore/QByteArray>
42 #include <QtCore/QSharedPointer>
43
44 QT_BEGIN_NAMESPACE
45 class QIODevice;
46 QT_END_NAMESPACE
47
48 namespace trk {
49
50 struct TrkResult;
51 struct TrkMessage;
52 struct TrkDevicePrivate;
53
54 /* TrkDevice: Implements a Windows COM or Linux device for
55  * Trk communications. Provides synchronous write and asynchronous
56  * read operation.
57  * The serialFrames property specifies whether packets are encapsulated in
58  * "0x90 <length>" frames, which is currently the case for serial ports.
59  * Contains a write message queue allowing
60  * for queueing messages with a notification callback. If the message receives
61  * an ACK, the callback is invoked.
62  * The special message TRK_WRITE_QUEUE_NOOP_CODE code can be used for synchronization.
63  * The respective  message will not be sent, the callback is just invoked.
64  * Note that calling open/close in quick succession can cause crashes
65  * due to the use of queused signals. */
66
67 enum { TRK_WRITE_QUEUE_NOOP_CODE = 0x7f };
68
69 typedef trk::Callback<const TrkResult &> TrkCallback;
70
71 class SYMBIANUTILS_EXPORT TrkDevice : public QObject
72 {
73     Q_OBJECT
74     Q_PROPERTY(bool serialFrame READ serialFrame WRITE setSerialFrame)
75     Q_PROPERTY(bool verbose READ verbose WRITE setVerbose)
76     Q_PROPERTY(QString port READ port WRITE setPort)
77 public:
78     explicit TrkDevice(QObject *parent = 0);
79     virtual ~TrkDevice();
80
81     bool open(QString *errorMessage);
82     bool isOpen() const;
83
84     QString port() const;
85     void setPort(const QString &p);
86
87     QString errorString() const;
88
89     bool serialFrame() const;
90     void setSerialFrame(bool f);
91
92     int verbose() const;
93     void setVerbose(int b);
94
95     // Enqueue a message with a notification callback.
96     void sendTrkMessage(unsigned char code,
97                         TrkCallback callBack = TrkCallback(),
98                         const QByteArray &data = QByteArray(),
99                         const QVariant &cookie = QVariant());
100
101     // Enqeue an initial ping
102     void sendTrkInitialPing();
103
104     // Send an Ack synchronously, bypassing the queue
105     bool sendTrkAck(unsigned char token);
106
107 public slots:
108     void clearWriteQueue();
109
110 signals:
111     void messageReceived(const trk::TrkResult &result);
112     // Emitted with the contents of messages enclosed in 07e, not for log output
113     void rawDataReceived(const QByteArray &data);
114     void error(const QString &msg);
115     void logMessage(const QString &msg);
116
117 private slots:
118     void slotMessageReceived(const trk::TrkResult &result, const QByteArray &a);
119
120 protected slots:
121     void emitError(const QString &msg);
122     void emitLogMessage(const QString &msg);
123
124 public slots:
125     void close();
126
127 private:
128     void readMessages();
129     TrkDevicePrivate *d;
130 };
131
132 } // namespace trk
133
134 #endif // TRKDEVICE_H