| 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 | ** Commercial Usage
|
|---|
| 11 | ** Licensees holding valid Qt Commercial licenses may use this file in
|
|---|
| 12 | ** accordance with the Qt Commercial License Agreement provided with the
|
|---|
| 13 | ** Software or, alternatively, in accordance with the terms contained in
|
|---|
| 14 | ** a written agreement between you and Nokia.
|
|---|
| 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 | ** GNU General Public License Usage
|
|---|
| 29 | ** Alternatively, this file may be used under the terms of the GNU
|
|---|
| 30 | ** General Public License version 3.0 as published by the Free Software
|
|---|
| 31 | ** Foundation and appearing in the file LICENSE.GPL included in the
|
|---|
| 32 | ** packaging of this file. Please review the following information to
|
|---|
| 33 | ** ensure the GNU General Public License version 3.0 requirements will be
|
|---|
| 34 | ** met: http://www.gnu.org/copyleft/gpl.html.
|
|---|
| 35 | **
|
|---|
| 36 | ** If you have questions regarding the use of this file, please contact
|
|---|
| 37 | ** Nokia at qt-info@nokia.com.
|
|---|
| 38 | ** $QT_END_LICENSE$
|
|---|
| 39 | **
|
|---|
| 40 | ****************************************************************************/
|
|---|
| 41 |
|
|---|
| 42 | #include <QDebug>
|
|---|
| 43 | #include <QCoreApplication>
|
|---|
| 44 | #include <QObject>
|
|---|
| 45 | #include "trksignalhandler.h"
|
|---|
| 46 |
|
|---|
| 47 | class TrkSignalHandlerPrivate
|
|---|
| 48 | {
|
|---|
| 49 | friend class TrkSignalHandler;
|
|---|
| 50 | public:
|
|---|
| 51 | TrkSignalHandlerPrivate();
|
|---|
| 52 | ~TrkSignalHandlerPrivate();
|
|---|
| 53 | private:
|
|---|
| 54 | QTextStream out;
|
|---|
| 55 | QTextStream err;
|
|---|
| 56 | int loglevel;
|
|---|
| 57 | };
|
|---|
| 58 |
|
|---|
| 59 | void TrkSignalHandler::copyingStarted()
|
|---|
| 60 | {
|
|---|
| 61 | if(d->loglevel > 0)
|
|---|
| 62 | d->out << "Copying..." << endl;
|
|---|
| 63 | }
|
|---|
| 64 |
|
|---|
| 65 | void TrkSignalHandler::canNotConnect(const QString &errorMessage)
|
|---|
| 66 | {
|
|---|
| 67 | d->err << "Cannot Connect - " << errorMessage << endl;
|
|---|
| 68 | }
|
|---|
| 69 |
|
|---|
| 70 | void TrkSignalHandler::canNotCreateFile(const QString &filename, const QString &errorMessage)
|
|---|
| 71 | {
|
|---|
| 72 | d->err << "Cannot create file (" << filename << ") - " << errorMessage << endl;
|
|---|
| 73 | }
|
|---|
| 74 |
|
|---|
| 75 | void TrkSignalHandler::canNotWriteFile(const QString &filename, const QString &errorMessage)
|
|---|
| 76 | {
|
|---|
| 77 | d->err << "Cannot write file (" << filename << ") - " << errorMessage << endl;
|
|---|
| 78 | }
|
|---|
| 79 |
|
|---|
| 80 | void TrkSignalHandler::canNotCloseFile(const QString &filename, const QString &errorMessage)
|
|---|
| 81 | {
|
|---|
| 82 | d->err << "Cannot close file (" << filename << ") - " << errorMessage << endl;
|
|---|
| 83 | }
|
|---|
| 84 |
|
|---|
| 85 | void TrkSignalHandler::installingStarted()
|
|---|
| 86 | {
|
|---|
| 87 | if(d->loglevel > 0)
|
|---|
| 88 | d->out << "Installing..." << endl;
|
|---|
| 89 | }
|
|---|
| 90 |
|
|---|
| 91 | void TrkSignalHandler::canNotInstall(const QString &packageFilename, const QString &errorMessage)
|
|---|
| 92 | {
|
|---|
| 93 | d->err << "Cannot install file (" << packageFilename << ") - " << errorMessage << endl;
|
|---|
| 94 | }
|
|---|
| 95 |
|
|---|
| 96 | void TrkSignalHandler::installingFinished()
|
|---|
| 97 | {
|
|---|
| 98 | if(d->loglevel > 0)
|
|---|
| 99 | d->out << "Installing finished" << endl;
|
|---|
| 100 | }
|
|---|
| 101 |
|
|---|
| 102 | void TrkSignalHandler::startingApplication()
|
|---|
| 103 | {
|
|---|
| 104 | if(d->loglevel > 0)
|
|---|
| 105 | d->out << "Starting app..." << endl;
|
|---|
| 106 | }
|
|---|
| 107 |
|
|---|
| 108 | void TrkSignalHandler::applicationRunning(uint pid)
|
|---|
| 109 | {
|
|---|
| 110 | if(d->loglevel > 0)
|
|---|
| 111 | d->out << "Running..." << endl;
|
|---|
| 112 | }
|
|---|
| 113 |
|
|---|
| 114 | void TrkSignalHandler::canNotRun(const QString &errorMessage)
|
|---|
| 115 | {
|
|---|
| 116 | d->err << "Cannot run - " << errorMessage << endl;
|
|---|
| 117 | }
|
|---|
| 118 |
|
|---|
| 119 | void TrkSignalHandler::finished()
|
|---|
| 120 | {
|
|---|
| 121 | if(d->loglevel > 0)
|
|---|
| 122 | d->out << "Done." << endl;
|
|---|
| 123 | QCoreApplication::quit();
|
|---|
| 124 | }
|
|---|
| 125 |
|
|---|
| 126 | void TrkSignalHandler::applicationOutputReceived(const QString &output)
|
|---|
| 127 | {
|
|---|
| 128 | d->out << output;
|
|---|
| 129 | }
|
|---|
| 130 |
|
|---|
| 131 | void TrkSignalHandler::copyProgress(int percent)
|
|---|
| 132 | {
|
|---|
| 133 | if(d->loglevel > 0) {
|
|---|
| 134 | d->out << percent << "% ";
|
|---|
| 135 | d->out.flush();
|
|---|
| 136 | if(percent==100)
|
|---|
| 137 | d->out << endl;
|
|---|
| 138 | }
|
|---|
| 139 | }
|
|---|
| 140 |
|
|---|
| 141 | void TrkSignalHandler::stateChanged(int state)
|
|---|
| 142 | {
|
|---|
| 143 | if(d->loglevel > 1)
|
|---|
| 144 | d->out << "State" << state << endl;
|
|---|
| 145 | }
|
|---|
| 146 |
|
|---|
| 147 | void TrkSignalHandler::setLogLevel(int level)
|
|---|
| 148 | {
|
|---|
| 149 | d->loglevel = level;
|
|---|
| 150 | }
|
|---|
| 151 |
|
|---|
| 152 | void TrkSignalHandler::stopped(uint pc, uint pid, uint tid, const QString& reason)
|
|---|
| 153 | {
|
|---|
| 154 | d->err << "STOPPED: pc=" << hex << pc << " pid=" << pid
|
|---|
| 155 | << " tid=" << tid << dec << " - " << reason << endl;
|
|---|
| 156 | // if it was a breakpoint, then we could continue with "emit resume(pid, tid);"
|
|---|
| 157 | // since we have set no breakpoints, it will be a just in time debug of a panic / exception
|
|---|
| 158 | emit terminate();
|
|---|
| 159 | }
|
|---|
| 160 |
|
|---|
| 161 | void TrkSignalHandler::timeout()
|
|---|
| 162 | {
|
|---|
| 163 | d->err << "FAILED: stopping test due to timeout" << endl;
|
|---|
| 164 | emit terminate();
|
|---|
| 165 | }
|
|---|
| 166 |
|
|---|
| 167 | TrkSignalHandlerPrivate::TrkSignalHandlerPrivate() :
|
|---|
| 168 | out(stdout),
|
|---|
| 169 | err(stderr),
|
|---|
| 170 | loglevel(0)
|
|---|
| 171 | {
|
|---|
| 172 |
|
|---|
| 173 | }
|
|---|
| 174 |
|
|---|
| 175 | TrkSignalHandlerPrivate::~TrkSignalHandlerPrivate()
|
|---|
| 176 | {
|
|---|
| 177 | out.flush();
|
|---|
| 178 | err.flush();
|
|---|
| 179 | }
|
|---|
| 180 |
|
|---|
| 181 | TrkSignalHandler::TrkSignalHandler()
|
|---|
| 182 | {
|
|---|
| 183 | d = new TrkSignalHandlerPrivate();
|
|---|
| 184 | }
|
|---|
| 185 |
|
|---|
| 186 | TrkSignalHandler::~TrkSignalHandler()
|
|---|
| 187 | {
|
|---|
| 188 | delete d;
|
|---|
| 189 | }
|
|---|