Ignore:
Timestamp:
May 5, 2011, 5:36:53 AM (15 years ago)
Author:
Dmitry A. Kuminov
Message:

trunk: Merged in qt 4.7.2 sources from branches/vendor/nokia/qt.

Location:
trunk
Files:
19 edited
6 copied

Legend:

Unmodified
Added
Removed
  • trunk

  • trunk/tools/runonphone/symbianutils/bluetoothlistener.cpp

    r769 r846  
    11/****************************************************************************
    22**
    3 ** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
     3** Copyright (C) 201 Nokia Corporation and/or its subsidiary(-ies).
    44** All rights reserved.
    55** Contact: Nokia Corporation ([email protected])
  • trunk/tools/runonphone/symbianutils/bluetoothlistener.h

    r769 r846  
    11/****************************************************************************
    22**
    3 ** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
     3** Copyright (C) 201 Nokia Corporation and/or its subsidiary(-ies).
    44** All rights reserved.
    55** Contact: Nokia Corporation ([email protected])
  • trunk/tools/runonphone/symbianutils/bluetoothlistener_gui.cpp

    r769 r846  
    11/****************************************************************************
    22**
    3 ** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
     3** Copyright (C) 201 Nokia Corporation and/or its subsidiary(-ies).
    44** All rights reserved.
    55** Contact: Nokia Corporation ([email protected])
  • trunk/tools/runonphone/symbianutils/bluetoothlistener_gui.h

    r769 r846  
    11/****************************************************************************
    22**
    3 ** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
     3** Copyright (C) 201 Nokia Corporation and/or its subsidiary(-ies).
    44** All rights reserved.
    55** Contact: Nokia Corporation ([email protected])
  • trunk/tools/runonphone/symbianutils/callback.h

    r769 r846  
    11/****************************************************************************
    22**
    3 ** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
     3** Copyright (C) 201 Nokia Corporation and/or its subsidiary(-ies).
    44** All rights reserved.
    55** Contact: Nokia Corporation ([email protected])
  • trunk/tools/runonphone/symbianutils/communicationstarter.cpp

    r769 r846  
    11/****************************************************************************
    22**
    3 ** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
     3** Copyright (C) 201 Nokia Corporation and/or its subsidiary(-ies).
    44** All rights reserved.
    55** Contact: Nokia Corporation ([email protected])
  • trunk/tools/runonphone/symbianutils/communicationstarter.h

    r769 r846  
    11/****************************************************************************
    22**
    3 ** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
     3** Copyright (C) 201 Nokia Corporation and/or its subsidiary(-ies).
    44** All rights reserved.
    55** Contact: Nokia Corporation ([email protected])
  • trunk/tools/runonphone/symbianutils/launcher.cpp

    r769 r846  
    11/****************************************************************************
    22**
    3 ** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
     3** Copyright (C) 201 Nokia Corporation and/or its subsidiary(-ies).
    44** All rights reserved.
    55** Contact: Nokia Corporation ([email protected])
     
    4545#include "trkdevice.h"
    4646#include "bluetoothlistener.h"
     47
    4748
    4849#include <QtCore/QTimer>
     
    5455#include <QtCore/QScopedPointer>
    5556
     57
     58
    5659namespace trk {
     60
     61
     62
     63
     64
     65
     66
     67
     68
     69
     70
     71
     72
     73
     74
     75
     76
     77
     78
     79
     80
     81
     82
     83
     84
     85
     86
    5787
    5888struct LauncherPrivate {
     
    6292        uint copyFileHandle;
    6393        QScopedPointer<QByteArray> data;
    64         int position;
     94        qint64 position;
     95        QScopedPointer<QFile> localFile;
    6596    };
    6697
     
    76107
    77108    CopyState m_copyState;
     109
    78110    QString m_fileName;
    79111    QStringList m_commandLineArgs;
     
    82114    Launcher::Actions m_startupActions;
    83115    bool m_closeDevice;
     116
    84117};
    85118
     
    101134{
    102135    d->m_startupActions = startupActions;
    103     connect(d->m_device.data(), SIGNAL(messageReceived(trk::TrkResult)), this, SLOT(handleResult(trk::TrkResult)));   
    104     connect(this, SIGNAL(finished()), d->m_device.data(), SLOT(close()));
     136    connect(d->m_device.data(), SIGNAL(messageReceived(trk::TrkResult)), this, SLOT(handleResult(trk::TrkResult)));
    105137}
    106138
    107139Launcher::~Launcher()
    108140{
     141
     142
     143
     144
    109145    logMessage("Shutting down.\n");
    110146    delete d;
     
    155191}
    156192
     193
     194
     195
     196
     197
     198
    157199void Launcher::setInstallFileName(const QString &name)
    158200{
     
    189231{
    190232    errorMessage->clear();
     233
    191234    if (d->m_verbose) {
    192         const QString msg = QString::fromLatin1("Port=%1 Executable=%2 Arguments=%3 Package=%4 Remote Package=%5 Install file=%6")
    193                             .arg(trkServerName(), d->m_fileName,
    194                                  d->m_commandLineArgs.join(QString(QLatin1Char(' '))),
    195                                  d->m_copyState.sourceFileName, d->m_copyState.destinationFileName, d->m_installFileName);
     235        QString msg;
     236        QTextStream str(&msg);
     237        str.setIntegerBase(16);
     238        str << "Actions=0x" << d->m_startupActions;
     239        str.setIntegerBase(10);
     240        str << " Port=" << trkServerName();
     241        if (!d->m_fileName.isEmpty())
     242            str << " Executable=" << d->m_fileName;
     243        if (!d->m_commandLineArgs.isEmpty())
     244            str << " Arguments= " << d->m_commandLineArgs.join(QString(QLatin1Char(' ')));
     245        if (!d->m_copyState.sourceFileName.isEmpty())
     246            str << " Package/Source=" << d->m_copyState.sourceFileName;
     247        if (!d->m_copyState.destinationFileName.isEmpty())
     248            str << " Remote Package/Destination=" << d->m_copyState.destinationFileName;
     249        if (!d->m_downloadState.sourceFileName.isEmpty())
     250            str << " Source=" << d->m_downloadState.sourceFileName;
     251        if (!d->m_downloadState.destinationFileName.isEmpty())
     252            str << " Destination=" << d->m_downloadState.destinationFileName;
     253        if (!d->m_installFileName.isEmpty())
     254            str << " Install file=" << d->m_installFileName;
    196255        logMessage(msg);
    197256    }
     
    215274    if (!d->m_device->isOpen() && !d->m_device->open(errorMessage))
    216275        return false;
    217     if (d->m_closeDevice) {
    218         connect(this, SIGNAL(finished()), d->m_device.data(), SLOT(close()));
    219     } else {
    220         disconnect(this, SIGNAL(finished()), d->m_device.data(), 0);
    221     }
    222276    setState(Connecting);
    223277    // Set up the temporary 'waiting' state if we do not get immediate connection
     
    253307    else if (d->m_startupActions & ActionRun)
    254308        startInferiorIfNeeded();
     309
     310
    255311}
    256312
     
    265321    if (d->m_verbose)
    266322        qDebug() << "LAUNCHER: " << qPrintable(msg);
     323
     324
     325
     326
     327
     328
     329
    267330}
    268331
     
    288351    case WaitingForTrk:
    289352        setState(Disconnected);
    290         emit finished();
     353        inished();
    291354        break;
    292355    }
     
    332395    QByteArray str = result.toString().toUtf8();
    333396    if (result.isDebugOutput) { // handle application output
    334         logMessage("APPLICATION OUTPUT: " + result.data);
    335         emit applicationOutputReceived(result.data);
     397        QString msg;
     398        if (result.multiplex == MuxTextTrace) {
     399            if (result.data.length() > 8) {
     400            quint64 timestamp = extractInt64(result.data) & 0x0FFFFFFFFFFFFFFFULL;
     401            quint64 secs = timestamp / 1000000000;
     402            quint64 ns = timestamp % 1000000000;
     403            msg = QString("[%1.%2] %3").arg(secs).arg(ns).arg(QString(result.data.mid(8)));
     404            logMessage("TEXT TRACE: " + msg);
     405            }
     406        } else {
     407            logMessage("APPLICATION OUTPUT: " + stringFromArray(result.data));
     408            msg = result.data;
     409        }
     410        msg.replace("\r\n", "\n");
     411        if(!msg.endsWith('\n')) msg.append('\n');
     412        emit applicationOutputReceived(msg);
    336413        return;
    337414    }
     
    369446        // target->host OS notification
    370447        case TrkNotifyCreated: { // Notify Created
    371             /*
    372             const char *data = result.data.data();
    373             byte error = result.data.at(0);
    374             byte type = result.data.at(1); // type: 1 byte; for dll item, this value is 2.
    375             uint pid = extractInt(data + 2); //  ProcessID: 4 bytes;
    376             uint tid = extractInt(data + 6); //threadID: 4 bytes
    377             uint codeseg = extractInt(data + 10); //code address: 4 bytes; code base address for the library
    378             uint dataseg = extractInt(data + 14); //data address: 4 bytes; data base address for the library
    379             uint len = extractShort(data + 18); //length: 2 bytes; length of the library name string to follow
    380             QByteArray name = result.data.mid(20, len); // name: library name
    381 
    382             logMessage(prefix + "NOTE: LIBRARY LOAD: " + str);
    383             logMessage(prefix + "TOKEN: " + result.token);
    384             logMessage(prefix + "ERROR: " + int(error));
    385             logMessage(prefix + "TYPE:  " + int(type));
    386             logMessage(prefix + "PID:   " + pid);
    387             logMessage(prefix + "TID:   " + tid);
    388             logMessage(prefix + "CODE:  " + codeseg);
    389             logMessage(prefix + "DATA:  " + dataseg);
    390             logMessage(prefix + "LEN:   " + len);
    391             logMessage(prefix + "NAME:  " + name);
    392             */
    393448
    394449            if (result.data.size() < 10)
    395450                break;
     451
     452
     453
     454
     455
     456
     457
     458
     459
     460
     461
    396462            QByteArray ba;
    397463            ba.append(result.data.mid(2, 8));
    398464            d->m_device->sendTrkMessage(TrkContinue, TrkCallback(), ba, "CONTINUE");
    399             //d->m_device->sendTrkAck(result.token)
    400465            break;
    401466        }
    402467        case TrkNotifyDeleted: { // NotifyDeleted
    403468            const ushort itemType = (unsigned char)result.data.at(1);
    404             const ushort len = result.data.size() > 12 ? extractShort(result.data.data() + 10) : ushort(0);
     469            const uint pid = result.data.size() >= 6 ? extractShort(result.data.constData() + 2) : 0;
     470            const uint tid = result.data.size() >= 10 ? extractShort(result.data.constData() + 6) : 0;
     471            Q_UNUSED(tid)
     472            const ushort len = result.data.size() > 12 ? extractShort(result.data.constData() + 10) : ushort(0);
    405473            const QString name = len ? QString::fromAscii(result.data.mid(12, len)) : QString();
    406474            logMessage(QString::fromLatin1("%1 %2 UNLOAD: %3").
     
    408476                       arg(name));
    409477            d->m_device->sendTrkAck(result.token);
    410             if (itemType == 0 // process
     478            if (itemType == // process
    411479                && result.data.size() >= 10
    412480                && d->m_session.pid == extractInt(result.data.data() + 6)) {
    413                 disconnectTrk();
     481                    if (d->m_startupActions & ActionDownload)
     482                        copyFileFromRemote();
     483                    else
     484                        disconnectTrk();
     485            }
     486            else if (itemType == kDSOSDLLItem && len) {
     487                // Remove libraries of process.
     488                for (QList<Library>::iterator it = d->m_session.libraries.begin(); it != d->m_session.libraries.end(); ) {
     489                    if ((*it).pid == pid && (*it).name == name) {
     490                        emit libraryUnloaded(*it);
     491                        it = d->m_session.libraries.erase(it);
     492                    } else {
     493                        ++it;
     494                    }
     495                }
    414496            }
    415497            break;
     
    447529        if (d->m_startupActions == ActionPingOnly) {
    448530            setState(Disconnected);
    449             emit finished();
     531            inished();
    450532        }
    451533        return;
     
    456538    d->m_session.trkAppVersion.protocolMinor = result.data.at(4);
    457539    setState(DeviceDescriptionReceived);
     540
     541
    458542    // Ping mode: Log & Terminate
    459543    if (d->m_startupActions == ActionPingOnly) {
    460         qWarning("%s", qPrintable(deviceDescription()));
     544        qWarning("%s", qPrintable());
    461545        setState(Disconnected);
    462         emit finished();
    463     }
     546        handleFinished();
     547    }
     548}
     549
     550static inline QString msgCannotOpenRemoteFile(const QString &fileName, const QString &message)
     551{
     552    return Launcher::tr("Cannot open remote file '%1': %2").arg(fileName, message);
     553}
     554
     555static inline QString msgCannotOpenLocalFile(const QString &fileName, const QString &message)
     556{
     557    return Launcher::tr("Cannot open '%1': %2").arg(fileName, message);
    464558}
    465559
     
    467561{
    468562    if (result.errorCode() || result.data.size() < 6) {
    469         emit canNotCreateFile(d->m_copyState.destinationFileName, result.errorString());
     563        const QString msg = msgCannotOpenRemoteFile(d->m_copyState.destinationFileName, result.errorString());
     564        logMessage(msg);
     565        emit canNotCreateFile(d->m_copyState.destinationFileName, msg);
    470566        disconnectTrk();
    471567        return;
     
    473569    const char *data = result.data.data();
    474570    d->m_copyState.copyFileHandle = extractInt(data + 2);
    475     QFile file(d->m_copyState.sourceFileName);
    476     file.open(QIODevice::ReadOnly);
     571    const QString localFileName = d->m_copyState.sourceFileName;
     572    QFile file(localFileName);
     573    d->m_copyState.position = 0;
     574    if (!file.open(QIODevice::ReadOnly)) {
     575        const QString msg = msgCannotOpenLocalFile(localFileName, file.errorString());
     576        logMessage(msg);
     577        emit canNotOpenLocalFile(localFileName, msg);
     578        closeRemoteFile(true);
     579        disconnectTrk();
     580        return;
     581    }
    477582    d->m_copyState.data.reset(new QByteArray(file.readAll()));
    478     d->m_copyState.position = 0;
    479583    file.close();
    480584    continueCopying();
     585
     586
     587
     588
     589
     590
     591
     592
     593
     594
     595
     596
     597
     598
     599
     600
     601
     602
     603
     604
     605
     606
     607
     608
     609
     610
     611
     612
     613
     614
     615
     616
     617
     618
     619
     620
     621
     622
     623
     624
     625
     626
     627
     628
     629
     630
     631
     632
     633
     634
     635
     636
     637
     638
     639
     640
    481641}
    482642
     
    494654void Launcher::continueCopying(uint lastCopiedBlockSize)
    495655{
    496     int size = d->m_copyState.data->length();
     656    size = d->m_copyState.data->length();
    497657    d->m_copyState.position += lastCopiedBlockSize;
    498658    if (size == 0)
    499659        emit copyProgress(100);
    500660    else {
    501         int percent = qMin((d->m_copyState.position*100)/size, 100);
    502         emit copyProgress(percent);
     661        const qint64 hundred = 100;
     662        const qint64 percent = qMin( (d->m_copyState.position * hundred) / size, hundred);
     663        emit copyProgress(static_cast<int>(percent));
    503664    }
    504665    if (d->m_copyState.position < size) {
     
    533694    else if (d->m_startupActions & ActionRun)
    534695        startInferiorIfNeeded();
     696
     697
    535698    else
    536699        disconnectTrk();
     
    577740    }
    578741    emit applicationRunning(d->m_session.pid);
     742
     743
     744
     745
     746
     747
     748
     749
     750
    579751    QByteArray ba;
    580752    appendInt(&ba, d->m_session.pid);
     
    587759    logMessage("   FINISHED: " + stringFromArray(result.data));
    588760    setState(Disconnected);
    589     emit finished();
     761    inished();
    590762}
    591763
     
    596768    const char *data = result.data.data() + 1;
    597769
    598     QString str = QLatin1String("SUPPORTED: ");
    599     for (int i = 0; i < 32; ++i) {
    600         //str.append("  [" + formatByte(data[i]) + "]: ");
    601         for (int j = 0; j < 8; ++j) {
    602             if (data[i] & (1 << j)) {
    603                 str.append(QString::number(i * 8 + j, 16));
    604                 str.append(QLatin1Char(' '));
     770    if (d->m_verbose > 1) {
     771        QString str = QLatin1String("SUPPORTED: ");
     772        for (int i = 0; i < 32; ++i) {
     773            for (int j = 0; j < 8; ++j) {
     774                if (data[i] & (1 << j)) {
     775                    str.append(QString::number(i * 8 + j, 16));
     776                    str.append(QLatin1Char(' '));
     777                }
    605778            }
    606779        }
    607     }
    608     logMessage(str);
     780   
     781   
    609782}
    610783
     
    670843    emit copyingStarted();
    671844    QByteArray ba;
    672     ba.append(char(10));
     845    ba.append(char(10));
    673846    appendString(&ba, d->m_copyState.destinationFileName.toLocal8Bit(), TargetByteOrder, false);
    674847    d->m_device->sendTrkMessage(TrkOpenFile, TrkCallback(this, &Launcher::handleFileCreation), ba);
     848
     849
     850
     851
     852
     853
     854
     855
     856
    675857}
    676858
     
    695877    if (d->m_startupActions & ActionRun) {
    696878        startInferiorIfNeeded();
     879
     880
    697881    } else {
    698882        disconnectTrk();
     
    705889    // It's not started yet
    706890    QByteArray ba;
    707     appendShort(&ba, 0, TargetByteOrder); // create new process
     891    appendShort(&ba, 0, TargetByteOrder); // create new process
    708892    ba.append(char(0)); // options - currently unused
    709     if(arguments.isEmpty()) {
    710         appendString(&ba, executable.toLocal8Bit(), TargetByteOrder);
    711         return ba;
    712     }
    713     // Append full command line as one string (leading length information).
    714     QByteArray commandLineBa;
    715     commandLineBa.append(executable.toLocal8Bit());
    716     commandLineBa.append('\0');
    717     commandLineBa.append(arguments.join(QString(QLatin1Char(' '))).toLocal8Bit());
    718     appendString(&ba, commandLineBa, TargetByteOrder);
     893    // One string consisting of binary terminated by '\0' and arguments terminated by '\0'
     894    QByteArray commandLineBa = executable.toLocal8Bit();
     895    commandLineBa.append(char(0));
     896    if (!arguments.isEmpty())
     897        commandLineBa.append(arguments.join(QString(QLatin1Char(' '))).toLocal8Bit());
     898    appendString(&ba, commandLineBa, TargetByteOrder, true);
     899    return ba;
     900}
     901
     902QByteArray Launcher::readMemoryMessage(uint pid, uint tid, uint from, uint len)
     903{
     904    QByteArray ba;
     905    ba.reserve(11);
     906    ba.append(char(0x8)); // Options, FIXME: why?
     907    appendShort(&ba, len);
     908    appendInt(&ba, from);
     909    appendInt(&ba, pid);
     910    appendInt(&ba, tid);
     911    return ba;
     912}
     913
     914QByteArray Launcher::readRegistersMessage(uint pid, uint tid)
     915{
     916    QByteArray ba;
     917    ba.reserve(15);
     918    ba.append(char(0)); // Register set, only 0 supported
     919    appendShort(&ba, 0); //R0
     920    appendShort(&ba, 16); // last register CPSR
     921    appendInt(&ba, pid);
     922    appendInt(&ba, tid);
    719923    return ba;
    720924}
     
    738942    d->m_device->sendTrkMessage(TrkContinue, TrkCallback(), ba, "CONTINUE");
    739943}
     944
     945
     946
     947
     948
     949
     950
     951
     952
     953
     954
     955
     956
     957
     958
     959
     960
     961
     962
     963
     964
     965
     966
     967
     968
     969
     970
     971
     972
     973
     974
     975
     976
     977
     978
     979
     980
     981
     982
     983
     984
     985
     986
     987
     988
     989
     990
     991
     992
     993
     994
     995
     996
     997
     998
     999
     1000
     1001
     1002
     1003
     1004
     1005
     1006
     1007
     1008
     1009
     1010
     1011
     1012
     1013
     1014
     1015
     1016
     1017
     1018
     1019
     1020
     1021
     1022
     1023
     1024
     1025
     1026
     1027
     1028
     1029
     1030
     1031
     1032
     1033
     1034
     1035
    7401036} // namespace trk
  • trunk/tools/runonphone/symbianutils/launcher.h

    r769 r846  
    11/****************************************************************************
    22**
    3 ** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
     3** Copyright (C) 201 Nokia Corporation and/or its subsidiary(-ies).
    44** All rights reserved.
    55** Contact: Nokia Corporation ([email protected])
     
    4444
    4545#include "trkdevice.h"
     46
    4647
    4748#include <QtCore/QObject>
     
    7071        ActionCopyInstall = ActionCopy | ActionInstall,
    7172        ActionRun = 0x4,
     73
    7274        ActionCopyRun = ActionCopy | ActionRun,
    7375        ActionInstallRun = ActionInstall | ActionRun,
     
    9597    void setFileName(const QString &name);
    9698    void setCopyFileName(const QString &srcName, const QString &dstName);
     99
    97100    void setInstallFileName(const QString &name);
    98101    void setCommandLineArgs(const QStringList &args);
    99102    bool startServer(QString *errorMessage);
    100     void setVerbose(int v);   
     103    void setVerbose(int v);
    101104    void setSerialFrame(bool b);
    102105    bool serialFrame() const;
     
    110113    QString deviceDescription(unsigned verbose = 0u) const;
    111114
     115
     116
     117
     118
     119
     120
     121
     122
     123
    112124    static QByteArray startProcessMessage(const QString &executable,
    113125                                          const QStringList &arguments);
     126
     127
     128
    114129    // Parse a TrkNotifyStopped message
    115130    static bool parseNotifyStopped(const QByteArray &a,
     
    120135
    121136signals:
     137
    122138    void copyingStarted();
    123139    void canNotConnect(const QString &errorMessage);
    124140    void canNotCreateFile(const QString &filename, const QString &errorMessage);
     141
     142
    125143    void canNotWriteFile(const QString &filename, const QString &errorMessage);
    126144    void canNotCloseFile(const QString &filename, const QString &errorMessage);
     
    136154    void stateChanged(int);
    137155    void processStopped(uint pc, uint pid, uint tid, const QString& reason);
     156
     157
     158
     159
     160
     161
    138162
    139163public slots:
    140164    void terminate();
    141165    void resumeProcess(uint pid, uint tid);
     166
     167
    142168
    143169private slots:
     
    153179    void handleConnect(const TrkResult &result);
    154180    void handleFileCreation(const TrkResult &result);
     181
    155182    void handleCopy(const TrkResult &result);
     183
    156184    void continueCopying(uint lastCopiedBlockSize = 0);
     185
    157186    void closeRemoteFile(bool failed = false);
    158187    void handleFileCopied(const TrkResult &result);
     
    164193    void handleSupportMask(const TrkResult &result);
    165194    void handleTrkVersion(const TrkResult &result);
     195
     196
    166197
    167198    void copyFileToRemote();
     199
    168200    void installRemotePackageSilently();
    169201    void startInferiorIfNeeded();
     202
    170203
    171204    void logMessage(const QString &msg);
  • trunk/tools/runonphone/symbianutils/symbiandevicemanager.cpp

    r769 r846  
    11/****************************************************************************
    22**
    3 ** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
     3** Copyright (C) 201 Nokia Corporation and/or its subsidiary(-ies).
    44** All rights reserved.
    55** Contact: Nokia Corporation ([email protected])
     
    4141
    4242#include "symbiandevicemanager.h"
     43
    4344
    4445#include <QtCore/QSettings>
     
    4950#include <QtCore/QSharedData>
    5051#include <QtCore/QScopedPointer>
     52
    5153
    5254namespace SymbianUtils {
     
    6264class SymbianDeviceData : public QSharedData {
    6365public:
    64     SymbianDeviceData() : type(SerialPortCommunication) {}
     66    SymbianDeviceData();
     67    ~SymbianDeviceData();
     68
     69    inline bool isOpen() const { return !device.isNull() && device->isOpen(); }
     70    void forcedClose();
    6571
    6672    QString portName;
     
    6874    QString deviceDesc;
    6975    QString manufacturer;
     76
     77
    7078    DeviceCommunicationType type;
     79
     80
    7181};
     82
     83
     84
     85
     86
     87
     88
     89
     90
     91
     92
     93
     94
     95
     96
     97
     98
     99
     100
     101
     102
     103
     104
     105
     106
    72107
    73108SymbianDevice::SymbianDevice(SymbianDeviceData *data) :
    74109    m_data(data)
    75110{
    76 
    77111}
    78112
     
    97131}
    98132
     133
     134
     135
     136
     137
    99138QString SymbianDevice::portName() const
    100139{
     
    107146}
    108147
     148
     149
     150
     151
     152
     153
     154
     155
     156
     157
     158
     159
     160
     161
     162
     163
     164
     165
     166
     167
     168
     169
     170
     171
     172
     173
     174
     175
     176
     177
     178
     179
     180
     181
     182
     183
     184
     185
     186
     187
     188
     189
     190
     191
     192
    109193QString SymbianDevice::deviceDesc() const
    110194{
     
    124208bool SymbianDevice::isNull() const
    125209{
    126     return !m_data->portName.isEmpty();
     210    return m_data->portName.isEmpty();
     211}
     212
     213bool SymbianDevice::isOpen() const
     214{
     215    return m_data->isOpen();
    127216}
    128217
     
    159248}
    160249
    161 QDebug operator<<(QDebug d, const SymbianDevice &cd)
     250QDebug operator<<(QDebug d, const SymbianDevice &cd)
    162251{
    163252    d.nospace() << cd.toString();
     
    167256// ------------- SymbianDeviceManagerPrivate
    168257struct SymbianDeviceManagerPrivate {
    169     SymbianDeviceManagerPrivate() : m_initialized(false) {}
     258    SymbianDeviceManagerPrivate() : m_initialized(false) {}
    170259
    171260    bool m_initialized;
    172261    SymbianDeviceManager::SymbianDeviceList m_devices;
     262
    173263};
    174264
     
    186276SymbianDeviceManager::SymbianDeviceList SymbianDeviceManager::devices() const
    187277{
    188     if (!d->m_initialized)
    189         const_cast<SymbianDeviceManager*>(this)->update(false);
     278    ensureInitialized();
    190279    return d->m_devices;
    191280}
     
    195284    QString rc;
    196285    QTextStream str(&rc);
     286
    197287    const int count = d->m_devices.size();
    198288    for (int i = 0; i < count; i++) {
     
    204294}
    205295
     296
     297
     298
     299
     300
     301
     302
     303
     304
     305
    206306QString SymbianDeviceManager::friendlyNameForPort(const QString &port) const
    207307{
    208     foreach (const SymbianDevice &device, d->m_devices) {
    209         if (device.portName() == port)
    210             return device.friendlyName();
    211     }
    212     return QString();
     308    const int idx = findByPortName(port);
     309    return idx == -1 ? QString() : d->m_devices.at(idx).friendlyName();
     310}
     311
     312SymbianDeviceManager::TrkDevicePtr
     313        SymbianDeviceManager::acquireDevice(const QString &port)
     314{
     315    ensureInitialized();
     316    const int idx = findByPortName(port);
     317    if (idx == -1) {
     318        qWarning("Attempt to acquire device '%s' that does not exist.", qPrintable(port));
     319        if (debug)
     320            qDebug() << *this;
     321        return TrkDevicePtr();
     322      }
     323    const TrkDevicePtr rc = d->m_devices[idx].acquireDevice();
     324    if (debug)
     325        qDebug() << "SymbianDeviceManager::acquireDevice" << port << " returns " << !rc.isNull();
     326    return rc;
    213327}
    214328
     
    218332}
    219333
     334
     335
     336
     337
     338
     339
     340
     341
     342
     343
     344
     345
     346
     347
     348
     349
     350
     351
     352
     353
     354
     355
     356
     357
     358
    220359void SymbianDeviceManager::update(bool emitSignals)
    221360{
     361
    222362    typedef SymbianDeviceList::iterator SymbianDeviceListIterator;
    223363
    224364    if (debug)
    225         qDebug(">SerialDeviceLister::update(%d)\n%s", int(emitSignals),
     365        qDebug(">SerialDeviceLister::update(, int(emitSignals),
    226366               qPrintable(toString()));
    227367
     
    231371    if (newDevices.size() > 1)
    232372        qStableSort(newDevices.begin(), newDevices.end());
    233     if (d->m_devices == newDevices) // Happy, nothing changed.
     373    if (d->m_devices == newDevices) { // Happy, nothing changed.
     374        if (debug)
     375            qDebug("<SerialDeviceLister::update: unchanged\n");
    234376        return;
     377
    235378    // Merge the lists and emit the respective added/removed signals, assuming
    236379    // no one can plug a different device on the same port at the speed of lightning
     
    241384                ++oldIt;
    242385            } else {
    243                 const SymbianDevice toBeDeleted = *oldIt;
     386                SymbianDevice toBeDeleted = *oldIt;
     387                toBeDeleted.forcedClose();
    244388                oldIt = d->m_devices.erase(oldIt);
    245389                if (emitSignals)
     
    302446    // or at least the first one.
    303447    const QString prefix = QLatin1String(linuxBlueToothDeviceRootC);
    304     const QString friendlyFormat = QLatin1String("Bluetooth device (%1)");
     448    const QString friendlyFormat = QLatin1String("Bluetooth device (%1)");
    305449    for (int d = 0; d < 4; d++) {
    306450        QScopedPointer<SymbianDeviceData> device(new SymbianDeviceData);
     
    308452        device->portName = prefix + QString::number(d);
    309453        if (d == 0 || QFileInfo(device->portName).exists()) {
    310             device->friendlyName = friendlyFormat.arg(device->portName);
     454            device->friendlyName = friendlyFormat.arg(device->portName);
    311455            rc.push_back(SymbianDevice(device.take()));
     456
     457
     458
     459
     460
     461
     462
     463
     464
     465
     466
     467
     468
     469
    312470        }
    313471    }
     
    323481}
    324482
    325 QDebug operator<<(QDebug d, const SymbianDeviceManager &sdm)
     483QDebug operator<<(QDebug d, const SymbianDeviceManager &sdm)
    326484{
    327485    d.nospace() << sdm.toString();
  • trunk/tools/runonphone/symbianutils/symbiandevicemanager.h

    r769 r846  
    11/****************************************************************************
    22**
    3 ** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
     3** Copyright (C) 201 Nokia Corporation and/or its subsidiary(-ies).
    44** All rights reserved.
    55** Contact: Nokia Corporation ([email protected])
     
    4747#include <QtCore/QObject>
    4848#include <QtCore/QExplicitlySharedDataPointer>
     49
    4950
    5051QT_BEGIN_NAMESPACE
     
    5253class QTextStream;
    5354QT_END_NAMESPACE
     55
     56
     57
     58
    5459
    5560namespace SymbianUtils {
     
    6368};
    6469
    65 // SymbianDevice, explicitly shared.
     70// SymbianDevice: Explicitly shared device data and a TrkDevice
     71// instance that can be acquired (exclusively) for use.
     72// A device removal from the manager will result in the
     73// device being closed.
    6674class SYMBIANUTILS_EXPORT SymbianDevice {
    6775    explicit SymbianDevice(SymbianDeviceData *data);
    6876    friend class SymbianDeviceManager;
    6977public:
     78
     79
    7080    SymbianDevice();
    7181    SymbianDevice(const SymbianDevice &rhs);
     
    7888    QString portName() const;
    7989    QString friendlyName() const;
     90
     91
     92
     93
     94
     95
     96
     97
     98
     99
     100
    80101
    81102    // Windows only.
     
    87108
    88109private:
     110
     111
    89112    QExplicitlySharedDataPointer<SymbianDeviceData> m_data;
    90113};
    91114
    92 QDebug operator<<(QDebug d, const SymbianDevice &);
     115QDebug operator<<(QDebug d, const SymbianDevice &);
    93116
    94117inline bool operator==(const SymbianDevice &d1, const SymbianDevice &d2)
     
    101124/* SymbianDeviceManager: Singleton that maintains a list of Symbian devices.
    102125 * and emits change signals.
    103  * On Windows, the update slot must be connected to a signal
    104  * emitted from an event handler listening for WM_DEVICECHANGE. */
     126 * On Windows, the update slot must be connected to a [delayed] signal
     127 * emitted from an event handler listening for WM_DEVICECHANGE.
     128 * Device removal will result in the device being closed. */
    105129class SYMBIANUTILS_EXPORT SymbianDeviceManager : public QObject
    106130{
     
    108132public:
    109133    typedef QList<SymbianDevice> SymbianDeviceList;
     134
    110135
    111136    static const char *linuxBlueToothDeviceRootC;
     
    121146    QString toString() const;
    122147
     148
     149
     150
     151
    123152    QString friendlyNameForPort(const QString &port) const;
    124153
    125154public slots:
    126155    void update();
     156
     157
     158
    127159
    128160signals:
    129     void deviceRemoved(const SymbianDevice &d);
    130     void deviceAdded(const SymbianDevice &d);
     161    void deviceRemoved(const SymbianDevice &d);
     162    void deviceAdded(const SymbianDevice &d);
    131163    void updated();
    132164
    133165private:
     166
    134167    void update(bool emitSignals);
    135168    SymbianDeviceList serialPorts() const;
     
    139172};
    140173
    141 QDebug operator<<(QDebug d, const SymbianDeviceManager &);
     174QDebug operator<<(QDebug d, const SymbianDeviceManager &);
    142175
    143176} // namespace SymbianUtils
  • trunk/tools/runonphone/symbianutils/symbianutils.pri

    r769 r846  
    11INCLUDEPATH *= $$PWD
     2
     3
    24
    35# Input
     
    1012    $$PWD/bluetoothlistener.h \
    1113    $$PWD/communicationstarter.h \
    12     $$PWD/symbiandevicemanager.h
     14    $$PWD/symbiandevicemanager.h \
     15    $$PWD/tcftrkdevice.h \
     16    $$PWD/tcftrkmessage.h \
     17    $$PWD/json.h
    1318
    1419SOURCES += $$PWD/trkutils.cpp \
     
    1722    $$PWD/bluetoothlistener.cpp \
    1823    $$PWD/communicationstarter.cpp \
    19     $$PWD/symbiandevicemanager.cpp
     24    $$PWD/symbiandevicemanager.cpp \
     25    $$PWD/tcftrkdevice.cpp \
     26    $$PWD/tcftrkmessage.cpp \
     27    $$PWD/json.cpp
    2028
    2129# Tests/trklauncher is a console application
  • trunk/tools/runonphone/symbianutils/symbianutils_global.h

    r769 r846  
    11/****************************************************************************
    22**
    3 ** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
     3** Copyright (C) 201 Nokia Corporation and/or its subsidiary(-ies).
    44** All rights reserved.
    55** Contact: Nokia Corporation ([email protected])
  • trunk/tools/runonphone/symbianutils/trkdevice.cpp

    r769 r846  
    11/****************************************************************************
    22**
    3 ** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
     3** Copyright (C) 201 Nokia Corporation and/or its subsidiary(-ies).
    44** All rights reserved.
    55** Contact: Nokia Corporation ([email protected])
     
    5353#include <QtCore/QWaitCondition>
    5454#include <QtCore/QSharedPointer>
     55
    5556#include <QtCore/QMetaType>
    5657
     
    103104enum { verboseTrk = 0 };
    104105
     106
     107
     108
     109
     110
    105111namespace trk {
    106112
     
    156162
    157163class TrkWriteQueue
    158 {   
     164{
    159165    Q_DISABLE_COPY(TrkWriteQueue)
    160166public:
    161167    explicit TrkWriteQueue();
     168
    162169
    163170    // Enqueue messages.
     
    209216}
    210217
     218
     219
     220
     221
     222
     223
     224
     225
     226
     227
     228
    211229byte TrkWriteQueue::nextTrkWriteToken()
    212230{
     
    215233        ++m_trkWriteToken;
    216234    if (verboseTrk)
    217         qDebug() << "Write token: " << m_trkWriteToken;
     235        qDebug() << "" << m_trkWriteToken;
    218236    return m_trkWriteToken;
    219237}
     
    350368    Q_OBJECT
    351369    Q_DISABLE_COPY(WriterThread)
    352 public:           
     370public:
    353371    explicit WriterThread(const QSharedPointer<DeviceContext> &context);
    354372
     
    358376    void queueTrkInitialPing();
    359377
     378
     379
    360380    // Call this from the device read notification with the results.
    361381    void slotHandleResult(const TrkResult &result);
     
    375395    void invokeNoopMessage(const trk::TrkMessage &);
    376396
    377 private:   
     397private:
    378398    bool write(const QByteArray &data, QString *errorMessage);
    379399    inline int writePendingMessage();
     
    463483    wait();
    464484    m_terminate = false;
     485
    465486}
    466487
     
    562583}
    563584
     585
     586
     587
     588
     589
     590
     591
    564592void WriterThread::queueTrkInitialPing()
    565593{
     
    593621public:
    594622
     623
     624
    595625signals:
    596626    void messageReceived(const trk::TrkResult &result, const QByteArray &rawData);
     
    607637
    608638    QByteArray m_trkReadBuffer;
     639
    609640};
    610641
    611642ReaderThreadBase::ReaderThreadBase(const QSharedPointer<DeviceContext> &context) :
    612     m_context(context)
     643    m_context(context)
    613644{
    614645    static const int trkResultMetaId = qRegisterMetaType<trk::TrkResult>();
     
    633664    TrkResult r;
    634665    QByteArray rawData;
    635     while (extractResult(&m_trkReadBuffer, m_context->serialFrame, &r, &rawData)) {
     666    while (extractResult(&m_trkReadBuffer, m_context->serialFrame, &r, &rawData)) {
    636667        emit messageReceived(r, rawData);
    637668    }
     
    693724        emit error(QString::fromLatin1("ClearCommError failed: %1").arg(winErrorMessage(GetLastError())));
    694725        return -7;
    695     }   
     726    }
    696727    const DWORD bytesToRead = qMax(DWORD(1), qMin(comStat.cbInQue, DWORD(BufSize)));
    697728    // Trigger read
     
    709740        emit error(QString::fromLatin1("Read error: %1").arg(winErrorMessage(readError)));
    710741        return -1;
    711     }   
     742    }
    712743    // Wait for either termination or data
    713744    const DWORD wr = WaitForMultipleObjects(HandleCount, m_handles, false, INFINITE);
     
    784815};
    785816
    786 UnixReaderThread::UnixReaderThread(const QSharedPointer<DeviceContext> &context) : 
     817UnixReaderThread::UnixReaderThread(const QSharedPointer<DeviceContext> &context) :
    787818    ReaderThreadBase(context)
    788819{
     
    878909
    879910    QSharedPointer<DeviceContext> deviceContext;
    880     QSharedPointer<WriterThread> writerThread;
    881     QSharedPointer<ReaderThread> readerThread;
     911    QSedPointer<WriterThread> writerThread;
     912    QSedPointer<ReaderThread> readerThread;
    882913
    883914    QByteArray trkReadBuffer;
     
    918949bool TrkDevice::open(QString *errorMessage)
    919950{
    920     if (d->verbose)
     951    if (d->verbose)
    921952        qDebug() << "Opening" << port() << "is open: " << isOpen() << " serialFrame=" << serialFrame();
     953
     954
    922955    if (d->port.isEmpty()) {
    923956        *errorMessage = QLatin1String("Internal error: No port set on TrkDevice");
    924957        return false;
    925958    }
    926 
    927     close();
    928959#ifdef Q_OS_WIN
    929960    const QString fullPort = QLatin1String("\\\\.\\") + d->port;
     
    9761007    }
    9771008#endif
    978     d->readerThread = QSharedPointer<ReaderThread>(new ReaderThread(d->deviceContext));
     1009    d->readerThread(new ReaderThread(d->deviceContext));
    9791010    connect(d->readerThread.data(), SIGNAL(error(QString)), this, SLOT(emitError(QString)),
    9801011            Qt::QueuedConnection);
     
    9841015    d->readerThread->start();
    9851016
    986     d->writerThread = QSharedPointer<WriterThread>(new WriterThread(d->deviceContext));
     1017    d->writerThread(new WriterThread(d->deviceContext));
    9871018    connect(d->writerThread.data(), SIGNAL(error(QString)), this, SLOT(emitError(QString)),
    988             Qt::QueuedConnection);   
    989     d->writerThread->start();   
    990 
    991     if (d->verbose)
    992         qDebug() << "Opened" << d->port;
     1019            Qt::QueuedConnection);
     1020    d->writerThread->start();
     1021
     1022    if (d->verbose)
     1023        qDebug() << "Opened" << d->port;
    9931024    return true;
    9941025}
     
    9961027void TrkDevice::close()
    9971028{
     1029
     1030
     1031
     1032
    9981033    if (!isOpen())
    9991034        return;
     
    10111046    d->deviceContext->file.close();
    10121047#endif
     1048
    10131049    if (d->verbose)
    10141050        emitLogMessage("Close");
     
    10311067void TrkDevice::setPort(const QString &p)
    10321068{
     1069
     1070
    10331071    d->port = p;
    10341072}
     
    10461084void TrkDevice::setSerialFrame(bool f)
    10471085{
     1086
     1087
    10481088    d->deviceContext->serialFrame = f;
    10491089}
     
    10611101void TrkDevice::slotMessageReceived(const trk::TrkResult &result, const QByteArray &rawData)
    10621102{
    1063     d->writerThread->slotHandleResult(result);
    1064     if (d->verbose > 1)
    1065         qDebug() << "Received: " << result.toString();
    1066     emit messageReceived(result);   
    1067     if (!rawData.isEmpty())
    1068         emit rawDataReceived(rawData);
     1103    if (isOpen()) { // Might receive bytes after closing due to queued connections.
     1104        d->writerThread->slotHandleResult(result);
     1105        if (d->verbose > 1)
     1106            qDebug() << "Received: " << result.toString();
     1107        emit messageReceived(result);
     1108        if (!rawData.isEmpty())
     1109            emit rawDataReceived(rawData);
     1110    }
    10691111}
    10701112
     
    10761118}
    10771119
     1120
     1121
     1122
     1123
     1124
     1125
    10781126void TrkDevice::sendTrkMessage(byte code, TrkCallback callback,
    10791127     const QByteArray &data, const QVariant &cookie)
    10801128{
     1129
     1130
     1131
     1132
    10811133    if (!d->writerThread.isNull()) {
    10821134        if (d->verbose > 1) {
    1083             QByteArray msg = "Sending:  ";
     1135            QByteArray msg = "Sending:  ";
    10841136            msg += QByteArray::number(code, 16);
    10851137            msg += ": ";
    10861138            msg += stringFromArray(data).toLatin1();
     1139
     1140
    10871141            qDebug("%s", msg.data());
    10881142        }
     
    10931147void TrkDevice::sendTrkInitialPing()
    10941148{
     1149
     1150
     1151
     1152
    10951153    if (!d->writerThread.isNull())
    10961154        d->writerThread->queueTrkInitialPing();
     
    10991157bool TrkDevice::sendTrkAck(byte token)
    11001158{
     1159
     1160
     1161
     1162
    11011163    if (d->writerThread.isNull())
    11021164        return false;
  • trunk/tools/runonphone/symbianutils/trkdevice.h

    r769 r846  
    11/****************************************************************************
    22**
    3 ** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
     3** Copyright (C) 201 Nokia Corporation and/or its subsidiary(-ies).
    44** All rights reserved.
    55** Contact: Nokia Corporation ([email protected])
     
    6565 * read operation.
    6666 * The serialFrames property specifies whether packets are encapsulated in
    67  * "0x90 <length>" frames, which is currently the case for serial ports. 
     67 * "0x90 <length>" frames, which is currently the case for serial ports.
    6868 * Contains a write message queue allowing
    6969 * for queueing messages with a notification callback. If the message receives
    7070 * 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. */
     71 * The special message TRK_WRITE_QUEUE_NOOP_CODE code can be used for synchronization.
     72 * The respective  message will not be sent, the callback is just invoked.
     73 * Note that calling open/close in quick succession can cause crashes
     74 * due to the use of queused signals. */
    7375
    7476enum { TRK_WRITE_QUEUE_NOOP_CODE = 0x7f };
     
    112114    bool sendTrkAck(unsigned char token);
    113115
     116
     117
     118
    114119signals:
    115120    void messageReceived(const trk::TrkResult &result);
  • trunk/tools/runonphone/symbianutils/trkutils.cpp

    r769 r846  
    11/****************************************************************************
    22**
    3 ** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
     3** Copyright (C) 201 Nokia Corporation and/or its subsidiary(-ies).
    44** All rights reserved.
    55** Contact: Nokia Corporation ([email protected])
     
    5252
    5353namespace trk {
     54
     55
     56
     57
     58
     59
     60
     61
     62
     63
     64
     65
     66
     67
     68
     69
     70
     71
     72
    5473
    5574TrkAppVersion::TrkAppVersion()
     
    7897    extended2TypeSize = 0;
    7998    pid = 0;
     99
    80100    tid = 0;
    81101    codeseg = 0;
    82102    dataseg = 0;
    83103
    84     currentThread = 0;
    85104    libraries.clear();
    86105    trkAppVersion.reset();
     
    144163}
    145164
     165
     166
     167
     168
     169
     170
     171
     172
     173
     174
     175
     176
     177
     178
     179
     180
     181
     182
     183
     184
     185
     186
     187
     188
     189
     190
     191
     192
     193
     194
     195
     196
     197
     198
     199
     200
     201
     202
     203
     204
     205
     206
     207
     208
     209
     210
     211
     212
     213
     214
     215
     216
     217
     218
     219
     220
     221
     222
     223
     224
     225
     226
     227
     228
     229
     230
     231
     232
     233
     234
     235
     236
     237
     238
     239
     240
     241
     242
     243
     244
     245
     246
     247
     248
    146249// --------------
    147250
     
    189292    const int size = maxLen == -1 ? ba.size() : qMin(ba.size(), maxLen);
    190293    for (int i = 0; i < size; ++i) {
    191         //if (i == 5 || i == ba.size() - 2)
    192         //    str += "  ";
    193         int c = byte(ba.at(i));
    194         str += QString("%1 ").arg(c, 2, 16, QChar('0'));
    195         if (i >= 8 && i < ba.size() - 2)
    196             ascii += QChar(c).isPrint() ? QChar(c) : QChar('.');
     294        const int c = byte(ba.at(i));
     295        str += QString::fromAscii("%1 ").arg(c, 2, 16, QChar('0'));
     296        ascii += QChar(c).isPrint() ? QChar(c) : QChar('.');
    197297    }
    198298    if (size != ba.size()) {
    199         str += "...";
    200         ascii += "...";
    201     }
    202     return str + "  " + ascii;
     299        str += ;
     300        ascii += ;
     301    }
     302    return str + + ascii;
    203303}
    204304
     
    277377/* returns 0 if array doesn't represent a result,
    278378otherwise returns the length of the result data */
    279 ushort isValidTrkResult(const QByteArray &buffer, bool serialFrame)
     379ushort isValidTrkResult(const QByteArray &buffer, bool serialFrame)
    280380{
    281381    if (serialFrame) {
     
    283383        if (buffer.length() < 4)
    284384            return 0;
    285         if (buffer.at(0) != 0x01 || byte(buffer.at(1)) != 0x90)
    286             return 0;
     385        mux = extractShort(buffer.data());
    287386        const ushort len = extractShort(buffer.data() + 2);
    288387        return (buffer.size() >= len + 4) ? len : ushort(0);
     
    293392    // Regular message delimited by 0x7e..0x7e
    294393    if (firstDelimiterPos == 0) {
     394
    295395        const int endPos = buffer.indexOf(delimiter, firstDelimiterPos + 1);
    296396        return endPos != -1 ? endPos + 1 - firstDelimiterPos : 0;
     
    300400}
    301401
    302 bool extractResult(QByteArray *buffer, bool serialFrame, TrkResult *result, QByteArray *rawData)
     402bool extractResult(QByteArray *buffer, bool serialFrame, TrkResult *result, QByteArray *rawData)
    303403{
    304404    result->clear();
    305405    if(rawData)
    306406        rawData->clear();
    307     const ushort len = isValidTrkResult(*buffer, serialFrame);
     407    ushort len = isValidTrkResult(*buffer, serialFrame, result->multiplex);
     408    // handle receiving application output, which is not a regular command
     409    const int delimiterPos = serialFrame ? 4 : 0;
     410    if (linkEstablishmentMode) {
     411        //when "hot connecting" a device, we can receive partial frames.
     412        //this code resyncs by discarding data until a TRK frame is found
     413        while (buffer->length() > delimiterPos
     414               && result->multiplex != MuxTextTrace
     415               && !(result->multiplex == MuxTrk && buffer->at(delimiterPos) == 0x7e)) {
     416            buffer->remove(0,1);
     417            len = isValidTrkResult(*buffer, serialFrame, result->multiplex);
     418        }
     419    }
    308420    if (!len)
    309421        return false;
    310     // handle receiving application output, which is not a regular command
    311     const int delimiterPos = serialFrame ? 4 : 0;
    312422    if (buffer->at(delimiterPos) != 0x7e) {
    313423        result->isDebugOutput = true;
    314424        result->data = buffer->mid(delimiterPos, len);
    315         result->data.replace("\r\n", "\n");
    316         *buffer->remove(0, delimiterPos + len);
     425        buffer->remove(0, delimiterPos + len);
    317426        return true;
    318427    }
     
    322431    if(rawData)
    323432        *rawData = data;
    324     *buffer->remove(0, delimiterPos + len);
     433    buffer->remove(0, delimiterPos + len);
    325434
    326435    byte sum = 0;
     
    337446    //QByteArray prefix = "READ BUF:                                       ";
    338447    //logMessage((prefix + "HEADER: " + stringFromArray(header).toLatin1()).data());
     448
    339449    return true;
    340450}
     
    351461    res *= 256; res += byte(data[2]);
    352462    res *= 256; res += byte(data[3]);
     463
     464
     465
     466
     467
     468
     469
     470
     471
     472
     473
     474
     475
    353476    return res;
    354477}
  • trunk/tools/runonphone/symbianutils/trkutils.h

    r769 r846  
    11/****************************************************************************
    22**
    3 ** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
     3** Copyright (C) 201 Nokia Corporation and/or its subsidiary(-ies).
    44** All rights reserved.
    55** Contact: Nokia Corporation ([email protected])
     
    4444
    4545#include "symbianutils_global.h"
     46
    4647#include <QtCore/QByteArray>
    4748#include <QtCore/QHash>
     
    5657
    5758typedef unsigned char byte;
     59
    5860
    5961enum Command {
     62
    6063    TrkPing = 0x00,
    6164    TrkConnect = 0x01,
    6265    TrkDisconnect = 0x02,
     66
    6367    TrkVersions = 0x04,
    6468    TrkSupported = 0x05,
    6569    TrkCpuType = 0x06,
     70
     71
    6672    TrkHostVersions = 0x09,
     73
     74
     75
     76
     77
     78
     79
     80
     81
     82
     83
    6784    TrkContinue = 0x18,
     85
     86
     87
     88
     89
     90
     91
     92
     93
     94
     95
     96
    6897    TrkCreateItem = 0x40,
    6998    TrkDeleteItem = 0x41,
     99
     100
    70101
    71102    TrkWriteFile = 0x48,
     103
    72104    TrkOpenFile = 0x4a,
    73105    TrkCloseFile = 0x4b,
     106
    74107    TrkInstallFile = 0x4d,
    75108    TrkInstallFile2 = 0x4e,
    76109
     110
     111
     112
     113
     114
    77115    TrkNotifyAck = 0x80,
    78116    TrkNotifyNak = 0xff,
     117
     118
    79119    TrkNotifyStopped = 0x90,
    80120    TrkNotifyException = 0x91,
    81121    TrkNotifyInternalError = 0x92,
     122
     123
     124
    82125    TrkNotifyCreated = 0xa0,
    83126    TrkNotifyDeleted = 0xa1,
    84127    TrkNotifyProcessorStarted = 0xa2,
    85128    TrkNotifyProcessorStandBy = 0xa6,
    86     TrkNotifyProcessorReset = 0xa7
     129    TrkNotifyProcessorReset = 0xa7,
     130
     131    //target -> host support commands (these are defined but not implemented in TRK)
     132    TrkDSWriteFile = 0xd0,
     133    TrkDSReadFile = 0xd1,
     134    TrkDSOpenFile = 0xd2,
     135    TrkDSCloseFile = 0xd3,
     136    TrkDSPositionFile = 0xd4
     137};
     138
     139enum DSOSItemTypes {
     140    kDSOSProcessItem = 0x0000,
     141    kDSOSThreadItem = 0x0001,
     142    kDSOSDLLItem = 0x0002,
     143    kDSOSAppItem = 0x0003,
     144    kDSOSMemBlockItem = 0x0004,
     145    kDSOSProcAttachItem = 0x0005,
     146    kDSOSThreadAttachItem = 0x0006,
     147    kDSOSProcAttach2Item = 0x0007,
     148    kDSOSProcRunItem = 0x0008,
     149    /* 0x0009 - 0x00ff reserved for general expansion */
     150    /* 0x0100 - 0xffff available for target-specific use */
     151};
     152
     153enum SerialMultiplexor {
     154    MuxRaw = 0,
     155    MuxTextTrace = 0x0102,
     156    MuxTrk = 0x0190
    87157};
    88158
     
    90160SYMBIANUTILS_EXPORT ushort extractShort(const char *data);
    91161SYMBIANUTILS_EXPORT uint extractInt(const char *data);
     162
    92163
    93164SYMBIANUTILS_EXPORT QString quoteUnprintableLatin1(const QByteArray &ba);
     
    109180struct SYMBIANUTILS_EXPORT Library
    110181{
    111     Library() {}
     182    Library();
     183    explicit Library(const TrkResult &r);
    112184
    113185    QByteArray name;
    114186    uint codeseg;
    115187    uint dataseg;
     188
     189
    116190};
    117191
     
    119193{
    120194    TrkAppVersion();
    121     void reset();   
     195    void reset();
    122196
    123197    int trkMajor;
     
    132206    void reset();
    133207    QString deviceDescription(unsigned verbose) const;
     208
     209
     210
     211
     212
    134213
    135214    // Trk feedback
     
    143222    TrkAppVersion trkAppVersion;
    144223    uint pid;
     224
    145225    uint tid;
    146226    uint codeseg;
     
    151231    Libraries libraries;
    152232
    153     typedef uint Thread;
    154     typedef QList<Thread> Threads;
    155     Threads threads;
    156 
    157233    // Gdb request
    158     uint currentThread;
    159234    QStringList modules;
    160235};
     
    169244    QString errorString() const;
    170245
     246
    171247    byte code;
    172248    byte token;
  • trunk/tools/runonphone/symbianutils/trkutils_p.h

    r769 r846  
    11/****************************************************************************
    22**
    3 ** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
     3** Copyright (C) 201 Nokia Corporation and/or its subsidiary(-ies).
    44** All rights reserved.
    55** Contact: Nokia Corporation ([email protected])
     
    5656// the serial frame [0x01 0x90 <len>] and 0x7e encoded7d(ba) 0x7e
    5757QByteArray frameMessage(byte command, byte token, const QByteArray &data, bool serialFrame);
    58 bool extractResult(QByteArray *buffer, bool serialFrame, TrkResult *r, QByteArray *rawData = 0);
     58bool extractResult(QByteArray *buffer, bool serialFrame, TrkResult *r, QByteArray *rawData = 0);
    5959
    6060} // namespace trk
Note: See TracChangeset for help on using the changeset viewer.