tools/runonphone/symbianutils/trkdevice.h
branchRCL_3
changeset 7 3f74d0d4af4c
equal deleted inserted replaced
6:dee5afe5301f 7:3f74d0d4af4c
       
     1 /****************************************************************************
       
     2 **
       
     3 ** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
       
     4 ** All rights reserved.
       
     5 ** Contact: Nokia Corporation (qt-info@nokia.com)
       
     6 **
       
     7 ** This file is part of the tools applications of the Qt Toolkit.
       
     8 **
       
     9 ** $QT_BEGIN_LICENSE:LGPL$
       
    10 ** No Commercial Usage
       
    11 ** This file contains pre-release code and may not be distributed.
       
    12 ** You may use this file in accordance with the terms and conditions
       
    13 ** contained in the Technology Preview License Agreement accompanying
       
    14 ** this package.
       
    15 **
       
    16 ** GNU Lesser General Public License Usage
       
    17 ** Alternatively, this file may be used under the terms of the GNU Lesser
       
    18 ** General Public License version 2.1 as published by the Free Software
       
    19 ** Foundation and appearing in the file LICENSE.LGPL included in the
       
    20 ** packaging of this file.  Please review the following information to
       
    21 ** ensure the GNU Lesser General Public License version 2.1 requirements
       
    22 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
       
    23 **
       
    24 ** In addition, as a special exception, Nokia gives you certain additional
       
    25 ** rights.  These rights are described in the Nokia Qt LGPL Exception
       
    26 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
       
    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 **
       
    34 **
       
    35 **
       
    36 **
       
    37 **
       
    38 ** $QT_END_LICENSE$
       
    39 **
       
    40 ****************************************************************************/
       
    41 
       
    42 #ifndef TRKDEVICE_H
       
    43 #define TRKDEVICE_H
       
    44 
       
    45 #include "symbianutils_global.h"
       
    46 #include "callback.h"
       
    47 
       
    48 #include <QtCore/QObject>
       
    49 #include <QtCore/QVariant>
       
    50 #include <QtCore/QByteArray>
       
    51 #include <QtCore/QSharedPointer>
       
    52 
       
    53 QT_BEGIN_NAMESPACE
       
    54 class QIODevice;
       
    55 QT_END_NAMESPACE
       
    56 
       
    57 namespace trk {
       
    58 
       
    59 struct TrkResult;
       
    60 struct TrkMessage;
       
    61 struct TrkDevicePrivate;
       
    62 
       
    63 /* TrkDevice: Implements a Windows COM or Linux device for
       
    64  * Trk communications. Provides synchronous write and asynchronous
       
    65  * read operation.
       
    66  * The serialFrames property specifies whether packets are encapsulated in
       
    67  * "0x90 <length>" frames, which is currently the case for serial ports. 
       
    68  * Contains a write message queue allowing
       
    69  * for queueing messages with a notification callback. If the message receives
       
    70  * an ACK, the callback is invoked.
       
    71  * The special message TRK_WRITE_QUEUE_NOOP_CODE code can be used for synchronisation.
       
    72  * The respective  message will not be sent, the callback is just invoked. */
       
    73 
       
    74 enum { TRK_WRITE_QUEUE_NOOP_CODE = 0x7f };
       
    75 
       
    76 typedef trk::Callback<const TrkResult &> TrkCallback;
       
    77 
       
    78 class SYMBIANUTILS_EXPORT TrkDevice : public QObject
       
    79 {
       
    80     Q_OBJECT
       
    81     Q_PROPERTY(bool serialFrame READ serialFrame WRITE setSerialFrame)
       
    82     Q_PROPERTY(bool verbose READ verbose WRITE setVerbose)
       
    83     Q_PROPERTY(QString port READ port WRITE setPort)
       
    84 public:
       
    85     explicit TrkDevice(QObject *parent = 0);
       
    86     virtual ~TrkDevice();
       
    87 
       
    88     bool open(QString *errorMessage);
       
    89     bool isOpen() const;
       
    90 
       
    91     QString port() const;
       
    92     void setPort(const QString &p);
       
    93 
       
    94     QString errorString() const;
       
    95 
       
    96     bool serialFrame() const;
       
    97     void setSerialFrame(bool f);
       
    98 
       
    99     int verbose() const;
       
   100     void setVerbose(int b);
       
   101 
       
   102     // Enqueue a message with a notification callback.
       
   103     void sendTrkMessage(unsigned char code,
       
   104                         TrkCallback callBack = TrkCallback(),
       
   105                         const QByteArray &data = QByteArray(),
       
   106                         const QVariant &cookie = QVariant());
       
   107 
       
   108     // Enqeue an initial ping
       
   109     void sendTrkInitialPing();
       
   110 
       
   111     // Send an Ack synchronously, bypassing the queue
       
   112     bool sendTrkAck(unsigned char token);
       
   113 
       
   114 signals:
       
   115     void messageReceived(const trk::TrkResult &result);
       
   116     // Emitted with the contents of messages enclosed in 07e, not for log output
       
   117     void rawDataReceived(const QByteArray &data);
       
   118     void error(const QString &msg);
       
   119     void logMessage(const QString &msg);
       
   120 
       
   121 private slots:
       
   122     void slotMessageReceived(const trk::TrkResult &result, const QByteArray &a);
       
   123 
       
   124 protected slots:
       
   125     void emitError(const QString &msg);
       
   126     void emitLogMessage(const QString &msg);
       
   127 
       
   128 public slots:
       
   129     void close();
       
   130 
       
   131 private:
       
   132     void readMessages();
       
   133     TrkDevicePrivate *d;
       
   134 };
       
   135 
       
   136 } // namespace trk
       
   137 
       
   138 #endif // TRKDEVICE_H