tools/runonphone/main.cpp
changeset 19 fcece45ef507
parent 18 2f34d5167611
child 30 5dc02b23752f
equal deleted inserted replaced
18:2f34d5167611 19:fcece45ef507
    42 #include <QCoreApplication>
    42 #include <QCoreApplication>
    43 #include <QTextStream>
    43 #include <QTextStream>
    44 #include <QStringList>
    44 #include <QStringList>
    45 #include <QScopedPointer>
    45 #include <QScopedPointer>
    46 #include <QTimer>
    46 #include <QTimer>
    47 #include "trkutils.h"
    47 #include "symbianutils/trkutils.h"
    48 #include "trkdevice.h"
    48 #include "symbianutils/trkdevice.h"
    49 #include "launcher.h"
    49 #include "symbianutils/launcher.h"
    50 
    50 
    51 #include "trksignalhandler.h"
    51 #include "trksignalhandler.h"
    52 #include "serenum.h"
    52 #include "serenum.h"
    53 
    53 
    54 void printUsage(QTextStream& outstream)
    54 void printUsage(QTextStream& outstream)
   131     if(exeFile.isEmpty()) {
   131     if(exeFile.isEmpty()) {
   132         printUsage(outstream);
   132         printUsage(outstream);
   133         return 1;
   133         return 1;
   134     }
   134     }
   135 
   135 
   136     if(serialPortName.isEmpty()) {
   136     if (serialPortName.isEmpty()) {
   137         if(loglevel > 0)
   137         if (loglevel > 0)
   138             outstream << "Detecting serial ports" << endl;
   138             outstream << "Detecting serial ports" << endl;
   139         QList <SerialPortId> ports = enumerateSerialPorts();
   139         QList <SerialPortId> ports = enumerateSerialPorts();
   140         foreach(SerialPortId id, ports) {
   140         foreach(SerialPortId id, ports) {
   141             if(loglevel > 0)
   141             if (loglevel > 0)
   142                 outstream << "Port Name: " << id.portName << ", "
   142                 outstream << "Port Name: " << id.portName << ", "
   143                      << "Friendly Name:" << id.friendlyName << endl;
   143                      << "Friendly Name:" << id.friendlyName << endl;
   144             if(serialPortName.isEmpty()) {
   144             if (serialPortName.isEmpty()) {
   145                 if(!id.friendlyName.isEmpty() &&
   145                 if (!id.friendlyName.isEmpty()
   146                    serialPortFriendlyName.isEmpty() &&
   146                         && serialPortFriendlyName.isEmpty()
   147                     (id.friendlyName.contains("symbian", Qt::CaseInsensitive) ||
   147                         && (id.friendlyName.contains("symbian", Qt::CaseInsensitive)
   148                        id.friendlyName.contains("s60", Qt::CaseInsensitive) ||
   148                             || id.friendlyName.contains("s60", Qt::CaseInsensitive)
   149                        id.friendlyName.contains("nokia", Qt::CaseInsensitive)))
   149                             || id.friendlyName.contains("nokia", Qt::CaseInsensitive)))
   150                         serialPortName = id.portName;
   150                         serialPortName = id.portName;
   151                 else if (!id.friendlyName.isEmpty() &&
   151                 else if (!id.friendlyName.isEmpty()
   152                          !serialPortFriendlyName.isEmpty() &&
   152                         && !serialPortFriendlyName.isEmpty()
   153                          id.friendlyName.contains(serialPortFriendlyName))
   153                         && id.friendlyName.contains(serialPortFriendlyName))
   154                         serialPortName = id.portName;
   154                     serialPortName = id.portName;
   155             }
   155             }
   156         }
   156         }
   157         if(serialPortName.isEmpty()) {
   157         if (serialPortName.isEmpty()) {
   158             errstream << "No phone found, ensure USB cable is connected or specify manually with -p" << endl;
   158             errstream << "No phone found, ensure USB cable is connected or specify manually with -p" << endl;
   159             return 1;
   159             return 1;
   160         }
   160         }
   161     }
   161     }
   162 
   162 
   163     QScopedPointer<trk::Launcher> launcher;
   163     QScopedPointer<trk::Launcher> launcher;
   164 
   164 
   165     if(sisFile.isEmpty()) {
   165     if (sisFile.isEmpty()) {
   166         launcher.reset(new trk::Launcher(trk::Launcher::ActionCopyRun));
   166         launcher.reset(new trk::Launcher(trk::Launcher::ActionCopyRun));
   167         launcher->setCopyFileName(exeFile, QString("c:\\sys\\bin\\") + exeFile);
   167         launcher->setCopyFileName(exeFile, QString("c:\\sys\\bin\\") + exeFile);
   168         errstream << "System TRK required to copy EXE, use --sis if using Application TRK" << endl;
   168         errstream << "System TRK required to copy EXE, use --sis if using Application TRK" << endl;
   169     } else {
   169     } else {
   170         launcher.reset(new trk::Launcher(trk::Launcher::ActionCopyInstallRun));
   170         launcher.reset(new trk::Launcher(trk::Launcher::ActionCopyInstallRun));
   171         launcher->addStartupActions(trk::Launcher::ActionInstall);
   171         launcher->addStartupActions(trk::Launcher::ActionInstall);
   172         launcher->setCopyFileName(sisFile, "c:\\data\\testtemp.sis");
   172         launcher->setCopyFileName(sisFile, "c:\\data\\testtemp.sis");
   173         launcher->setInstallFileName("c:\\data\\testtemp.sis");
   173         launcher->setInstallFileName("c:\\data\\testtemp.sis");
   174     }
   174     }
   175     if(loglevel > 0)
   175     if (loglevel > 0)
   176         outstream << "Connecting to target via " << serialPortName << endl;
   176         outstream << "Connecting to target via " << serialPortName << endl;
   177     launcher->setTrkServerName(serialPortName);
   177     launcher->setTrkServerName(serialPortName);
   178 
   178 
   179     launcher->setFileName(QString("c:\\sys\\bin\\") + exeFile);
   179     launcher->setFileName(QString("c:\\sys\\bin\\") + exeFile);
   180     launcher->setCommandLineArgs(cmdLine);
   180     launcher->setCommandLineArgs(cmdLine);
   181 
   181 
   182     if(loglevel > 1)
   182     if (loglevel > 1)
   183         launcher->setVerbose(1);
   183         launcher->setVerbose(1);
   184 
   184 
   185     TrkSignalHandler handler;
   185     TrkSignalHandler handler;
   186     handler.setLogLevel(loglevel);
   186     handler.setLogLevel(loglevel);
   187 
   187 
   210     if (timeout > 0) {
   210     if (timeout > 0) {
   211         timer.start(timeout);
   211         timer.start(timeout);
   212     }
   212     }
   213 
   213 
   214     QString errorMessage;
   214     QString errorMessage;
   215     if(!launcher->startServer(&errorMessage)) {
   215     if (!launcher->startServer(&errorMessage)) {
   216         errstream << errorMessage << endl;
   216         errstream << errorMessage << endl;
   217         return 1;
   217         return 1;
   218     }
   218     }
   219 
   219 
   220     return a.exec();
   220     return a.exec();