1 /**************************************************************************
3 ** This file is part of Qt Creator
5 ** Copyright (c) 2011 Nokia Corporation and/or its subsidiary(-ies).
7 ** Contact: Nokia Corporation (info@qt.nokia.com)
10 ** GNU Lesser General Public License Usage
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.
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.
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.
28 ** If you have questions regarding the use of this file, please contact
29 ** Nokia at qt-info@nokia.com.
31 **************************************************************************/
36 #include "symbianutils_global.h"
39 #include <QtCore/QObject>
40 #include <QtCore/QVariant>
41 #include <QtCore/QByteArray>
42 #include <QtCore/QSharedPointer>
52 struct TrkDevicePrivate;
54 /* TrkDevice: Implements a Windows COM or Linux device for
55 * Trk communications. Provides synchronous write and asynchronous
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. */
67 enum { TRK_WRITE_QUEUE_NOOP_CODE = 0x7f };
69 typedef trk::Callback<const TrkResult &> TrkCallback;
71 class SYMBIANUTILS_EXPORT TrkDevice : public QObject
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)
78 explicit TrkDevice(QObject *parent = 0);
81 bool open(QString *errorMessage);
85 void setPort(const QString &p);
87 QString errorString() const;
89 bool serialFrame() const;
90 void setSerialFrame(bool f);
93 void setVerbose(int b);
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());
101 // Enqeue an initial ping
102 void sendTrkInitialPing();
104 // Send an Ack synchronously, bypassing the queue
105 bool sendTrkAck(unsigned char token);
108 void clearWriteQueue();
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);
118 void slotMessageReceived(const trk::TrkResult &result, const QByteArray &a);
121 void emitError(const QString &msg);
122 void emitLogMessage(const QString &msg);
134 #endif // TRKDEVICE_H