Commit f2b3e9f2 authored by Friedemann Kleint's avatar Friedemann Kleint
Browse files

S60/Trk: Change trkutils to be a library of its own.

To be able to share TrkDevices between Debugger and Qt4ProjectManager.
parent 55487216
TEMPLATE = subdirs
CONFIG += ordered
QT += core gui
SUBDIRS = \
qtconcurrent \
......@@ -8,7 +9,8 @@ SUBDIRS = \
utils \
utils/process_stub.pro \
cplusplus \
qmljs
qmljs \
symbianutils
SUPPORT_QT_MAEMO = $$(QTCREATOR_WITH_MAEMO)
!isEmpty(SUPPORT_QT_MAEMO) {
......
INCLUDEPATH *= $$PWD/../../shared/trk
DEPENDPATH += $$PWD/../../shared/trk
LIBS *= -l$$qtLibraryTarget(symbianutils)
TEMPLATE = lib
CONFIG+=dll
TARGET = symbianutils
DEFINES += SYMBIANUTILS_BUILD_LIB
include(../../qtcreatorlibrary.pri)
include(../../shared/trk/trk.pri)
include(../../../shared/trk/trk.pri)
include(../../../libs/symbianutils/symbianutils.pri)
HEADERS += \
$$PWD/gdbmi.h \
$$PWD/gdbengine.h \
......
......@@ -75,6 +75,8 @@ namespace Internal {
enum { KnownRegisters = RegisterPSGdb + 1};
static inline void appendByte(QByteArray *ba, trk::byte b) { ba->append(b); }
static const char *registerNames[KnownRegisters] =
{
"A1", "A2", "A3", "A4",
......@@ -330,7 +332,7 @@ QByteArray TrkGdbAdapter::trkReadRegistersMessage()
return ba;
}
QByteArray TrkGdbAdapter::trkWriteRegisterMessage(byte reg, uint value)
QByteArray TrkGdbAdapter::trkWriteRegisterMessage(trk::byte reg, uint value)
{
QByteArray ba;
appendByte(&ba, 0); // ?
......@@ -372,7 +374,7 @@ QByteArray TrkGdbAdapter::trkWriteMemoryMessage(uint addr, const QByteArray &dat
return ba;
}
QByteArray TrkGdbAdapter::trkStepRangeMessage(byte option)
QByteArray TrkGdbAdapter::trkStepRangeMessage(trk::byte option)
{
QByteArray ba;
ba.reserve(17);
......@@ -510,7 +512,7 @@ void TrkGdbAdapter::readGdbServerCommand()
}
//logMessage(QString("Packet checksum: %1").arg(checkSum));
byte sum = 0;
trk::byte sum = 0;
for (int i = 0; i < pos; ++i)
sum += ba.at(i);
......@@ -557,7 +559,7 @@ void TrkGdbAdapter::sendGdbServerAck()
void TrkGdbAdapter::sendGdbServerMessage(const QByteArray &msg, const QByteArray &logNote)
{
byte sum = 0;
trk::byte sum = 0;
for (int i = 0; i != msg.size(); ++i)
sum += msg.at(i);
......@@ -1071,7 +1073,7 @@ void TrkGdbAdapter::handleGdbServerCommand(const QByteArray &cmd)
}
}
void TrkGdbAdapter::sendTrkMessage(byte code, TrkCallback callback,
void TrkGdbAdapter::sendTrkMessage(trk::byte code, TrkCallback callback,
const QByteArray &data, const QVariant &cookie)
{
if (m_verbose >= 2)
......@@ -1080,7 +1082,7 @@ void TrkGdbAdapter::sendTrkMessage(byte code, TrkCallback callback,
m_trkDevice->sendTrkMessage(code, callback, data, cookie);
}
void TrkGdbAdapter::sendTrkAck(byte token)
void TrkGdbAdapter::sendTrkAck(trk::byte token)
{
//logMessage(QString("SENDING ACKNOWLEDGEMENT FOR TOKEN %1").arg(int(token)));
m_trkDevice->sendTrkAck(token);
......@@ -1184,9 +1186,9 @@ void TrkGdbAdapter::handleTrkResult(const TrkResult &result)
debugMessage(_("RESET SNAPSHOT (NOTIFY CREATED)"));
m_snapshot.reset();
const char *data = result.data.data();
const byte error = result.data.at(0);
const trk::byte error = result.data.at(0);
// type: 1 byte; for dll item, this value is 2.
const byte type = result.data.at(1);
const trk::byte type = result.data.at(1);
const uint pid = extractInt(data + 2);
const uint tid = extractInt(data + 6);
const uint codeseg = extractInt(data + 10);
......
......@@ -186,7 +186,7 @@ private:
//
// TRK
//
void sendTrkMessage(byte code,
void sendTrkMessage(trk::byte code,
TrkCallback callback = TrkCallback(),
const QByteArray &data = QByteArray(),
const QVariant &cookie = QVariant());
......@@ -194,7 +194,7 @@ private:
Q_SLOT void handleTrkError(const QString &msg);
// convenience messages
void sendTrkAck(byte token);
void sendTrkAck(trk::byte token);
void handleCpuType(const TrkResult &result);
void handleCreateProcess(const TrkResult &result);
......@@ -245,12 +245,12 @@ private:
QByteArray trkContinueMessage();
QByteArray trkReadRegistersMessage();
QByteArray trkWriteRegisterMessage(byte reg, uint value);
QByteArray trkWriteRegisterMessage(trk::byte reg, uint value);
QByteArray trkReadMemoryMessage(const MemoryRange &range);
QByteArray trkReadMemoryMessage(uint addr, uint len);
QByteArray trkWriteMemoryMessage(uint addr, const QByteArray &date);
QByteArray trkBreakpointMessage(uint addr, uint len, bool armMode = true);
QByteArray trkStepRangeMessage(byte option);
QByteArray trkStepRangeMessage(trk::byte option);
QByteArray trkDeleteProcessMessage();
QByteArray trkInterruptMessage();
......
......@@ -31,4 +31,4 @@ HEADERS += $$PWD/s60devices.h \
$$PWD/rvctparser.h \
$$PWD/winscwparser.h
FORMS += $$PWD/s60devicespreferencepane.ui
include(../../../shared/trk/trk.pri)||error("could not include trk.pri")
include(../../libs/symbianutils/symbianutils.pri)||error("could not include symbianutils.pri")
......@@ -30,6 +30,8 @@
#ifndef BLUETOOTHLISTENER_H
#define BLUETOOTHLISTENER_H
#include "symbianutils_global.h"
#include <QtCore/QObject>
#include <QtCore/QProcess>
......@@ -41,7 +43,7 @@ struct BluetoothListenerPrivate;
* The rfcomm command is used. It process can be started in the background
* while connection attempts (TrkDevice::open()) are made in the foreground. */
class BluetoothListener : public QObject
class SYMBIANUTILS_EXPORT BluetoothListener : public QObject
{
Q_OBJECT
Q_DISABLE_COPY(BluetoothListener)
......
......@@ -38,7 +38,7 @@
namespace trk {
PromptStartCommunicationResult
SYMBIANUTILS_EXPORT PromptStartCommunicationResult
promptStartCommunication(BaseCommunicationStarter &starter,
const QString &msgBoxTitle,
const QString &msgBoxText,
......@@ -76,7 +76,7 @@ PromptStartCommunicationResult
return PromptStartCommunicationConnected;
}
PromptStartCommunicationResult
SYMBIANUTILS_EXPORT PromptStartCommunicationResult
promptStartSerial(BaseCommunicationStarter &starter,
QWidget *msgBoxParent,
QString *errorMessage)
......@@ -86,7 +86,7 @@ PromptStartCommunicationResult
return promptStartCommunication(starter, title, message, msgBoxParent, errorMessage);
}
PromptStartCommunicationResult
SYMBIANUTILS_EXPORT PromptStartCommunicationResult
promptStartBluetooth(BaseCommunicationStarter &starter,
QWidget *msgBoxParent,
QString *errorMessage)
......
......@@ -30,6 +30,8 @@
#ifndef BLUETOOTHLISTENER_GUI_H
#define BLUETOOTHLISTENER_GUI_H
#include "symbianutils_global.h"
#include <QtCore/QtGlobal>
QT_BEGIN_NAMESPACE
......@@ -50,7 +52,7 @@ enum PromptStartCommunicationResult {
PromptStartCommunicationError
};
PromptStartCommunicationResult
SYMBIANUTILS_EXPORT PromptStartCommunicationResult
promptStartCommunication(BaseCommunicationStarter &starter,
const QString &msgBoxTitle,
const QString &msgBoxText,
......@@ -59,14 +61,14 @@ PromptStartCommunicationResult
// Convenience to start a serial connection (messages prompting
// to launch Trk).
PromptStartCommunicationResult
SYMBIANUTILS_EXPORT PromptStartCommunicationResult
promptStartSerial(BaseCommunicationStarter &starter,
QWidget *msgBoxParent,
QString *errorMessage);
// Convenience to start blue tooth connection (messages
// prompting to connect).
PromptStartCommunicationResult
SYMBIANUTILS_EXPORT PromptStartCommunicationResult
promptStartBluetooth(BaseCommunicationStarter &starter,
QWidget *msgBoxParent,
QString *errorMessage);
......
......@@ -30,7 +30,7 @@
#ifndef DEBUGGER_CALLBACK_H
#define DEBUGGER_CALLBACK_H
#include <QtCore/QtGlobal>
#include "symbianutils_global.h"
namespace trk {
namespace Internal {
......
......@@ -30,6 +30,8 @@
#ifndef COMMUNICATIONSTARTER_H
#define COMMUNICATIONSTARTER_H
#include "symbianutils_global.h"
#include <QtCore/QSharedPointer>
#include <QtCore/QObject>
......@@ -48,7 +50,7 @@ struct BaseCommunicationStarterPrivate;
* The base class can be used as is to prompt the user to launch App TRK for a
* serial communication as this requires no further resource setup. */
class BaseCommunicationStarter : public QObject {
class SYMBIANUTILS_EXPORT BaseCommunicationStarter : public QObject {
Q_OBJECT
Q_DISABLE_COPY(BaseCommunicationStarter)
public:
......@@ -105,7 +107,7 @@ private:
* implement as a factory function that creates and sets up the
* listener (mode, message connection, etc). */
class AbstractBluetoothStarter : public BaseCommunicationStarter {
class SYMBIANUTILS_EXPORT AbstractBluetoothStarter : public BaseCommunicationStarter {
Q_OBJECT
Q_DISABLE_COPY(AbstractBluetoothStarter)
public:
......@@ -122,7 +124,7 @@ protected:
/* ConsoleBluetoothStarter: Convenience class for console processes. Creates a
* listener in "Listen" mode with the messages redirected to standard output. */
class ConsoleBluetoothStarter : public AbstractBluetoothStarter {
class SYMBIANUTILS_EXPORT ConsoleBluetoothStarter : public AbstractBluetoothStarter {
Q_OBJECT
Q_DISABLE_COPY(ConsoleBluetoothStarter)
public:
......
......@@ -29,6 +29,7 @@
#include "launcher.h"
#include "trkutils.h"
#include "trkutils_p.h"
#include "trkdevice.h"
#include "bluetoothlistener.h"
......@@ -604,9 +605,7 @@ void Launcher::cleanUp()
// Sub Cmd: Delete Process
//ProcessID: 0x0000071F (1823)
// [41 24 00 00 00 00 07 1F]
QByteArray ba;
appendByte(&ba, 0x00);
appendByte(&ba, 0x00);
QByteArray ba(2, char(0));
appendInt(&ba, d->m_session.pid);
d->m_device->sendTrkMessage(TrkDeleteItem, TrkCallback(), ba, "Delete process");
......@@ -659,7 +658,7 @@ void Launcher::copyFileToRemote()
{
emit copyingStarted();
QByteArray ba;
appendByte(&ba, 0x10);
ba.append(char(10));
appendString(&ba, d->m_copyState.destinationFileName.toLocal8Bit(), TargetByteOrder, false);
d->m_device->sendTrkMessage(TrkOpenFile, TrkCallback(this, &Launcher::handleFileCreation), ba);
}
......@@ -668,7 +667,7 @@ void Launcher::installRemotePackageSilently()
{
emit installingStarted();
QByteArray ba;
appendByte(&ba, 'C');
ba.append('C');
appendString(&ba, d->m_installFileName.toLocal8Bit(), TargetByteOrder, false);
d->m_device->sendTrkMessage(TrkInstallFile, TrkCallback(this, &Launcher::handleInstallPackageFinished), ba);
}
......@@ -695,7 +694,7 @@ QByteArray Launcher::startProcessMessage(const QString &executable,
// It's not started yet
QByteArray ba;
appendShort(&ba, 0, TargetByteOrder); // create new process
appendByte(&ba, 0); // options - currently unused
ba.append(char(0)); // options - currently unused
if(arguments.isEmpty()) {
appendString(&ba, executable.toLocal8Bit(), TargetByteOrder);
return ba;
......
......@@ -43,7 +43,7 @@ struct LauncherPrivate;
typedef QSharedPointer<TrkDevice> TrkDevicePtr;
class Launcher : public QObject
class SYMBIANUTILS_EXPORT Launcher : public QObject
{
Q_OBJECT
Q_DISABLE_COPY(Launcher)
......
/**************************************************************************
**
** This file is part of Qt Creator
**
** Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
**
** Contact: Nokia Corporation (qt-info@nokia.com)
**
** Commercial Usage
**
** Licensees holding valid Qt Commercial licenses may use this file in
** accordance with the Qt Commercial License Agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and Nokia.
**
** GNU Lesser General Public License Usage
**
** Alternatively, this file may be used under the terms of the GNU Lesser
** General Public License version 2.1 as published by the Free Software
** Foundation and appearing in the file LICENSE.LGPL included in the
** packaging of this file. Please review the following information to
** ensure the GNU Lesser General Public License version 2.1 requirements
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
**
** If you are unsure which license is appropriate for your use, please
** contact the sales department at http://qt.nokia.com/contact.
**
**************************************************************************/
#ifndef SYMBIANUTILS_GLOBAL_H
#define SYMBIANUTILS_GLOBAL_H
#include <QtCore/qglobal.h>
#if defined(SYMBIANUTILS_BUILD_LIB)
# define SYMBIANUTILS_EXPORT Q_DECL_EXPORT
#elif defined(SYMBIANUTILS_BUILD_STATIC_LIB) || defined(SYMBIANUTILS_INCLUDE_PRI)
# define SYMBIANUTILS_EXPORT
#else
# define SYMBIANUTILS_EXPORT Q_DECL_IMPORT
#endif
#endif // SYMBIANUTILS_GLOBAL_H
INCLUDEPATH *= $$PWD
# Input
HEADERS += $$PWD/callback.h \
HEADERS += $$PWD/symbianutils_global.h \
$$PWD/callback.h \
$$PWD/trkutils.h \
$$PWD/trkutils_p.h \
$$PWD/trkdevice.h \
$$PWD/launcher.h \
$$PWD/bluetoothlistener.h \
......
......@@ -29,6 +29,7 @@
#include "trkdevice.h"
#include "trkutils.h"
#include "trkutils_p.h"
#include <QtCore/QString>
#include <QtCore/QDebug>
......@@ -844,8 +845,8 @@ void UnixReaderThread::terminate()
{
// Trigger select() by writing to the pipe
char c = 0;
int written = write(m_terminatePipeFileDescriptors[1], &c, 1);
// FIXME: Use result.
const int written = write(m_terminatePipeFileDescriptors[1], &c, 1);
Q_UNUSED(written)
wait();
}
......
......@@ -30,6 +30,7 @@
#ifndef TRKDEVICE_H
#define TRKDEVICE_H
#include "symbianutils_global.h"
#include "callback.h"
#include <QtCore/QObject>
......@@ -62,7 +63,7 @@ enum { TRK_WRITE_QUEUE_NOOP_CODE = 0x7f };
typedef trk::Callback<const TrkResult &> TrkCallback;
class TrkDevice : public QObject
class SYMBIANUTILS_EXPORT TrkDevice : public QObject
{
Q_OBJECT
Q_PROPERTY(bool serialFrame READ serialFrame WRITE setSerialFrame)
......
......@@ -74,7 +74,7 @@ void Session::reset()
trkAppVersion.reset();
}
QString formatCpu(int major, int minor)
static QString formatCpu(int major, int minor)
{
//: CPU description of an S60 device
//: %1 major verison, %2 minor version
......@@ -131,6 +131,38 @@ QString Session::deviceDescription(unsigned verbose) const
return msg.arg(formatTrkVersion(trkAppVersion));
}
// --------------
QByteArray decode7d(const QByteArray &ba)
{
QByteArray res;
res.reserve(ba.size());
for (int i = 0; i < ba.size(); ++i) {
byte c = byte(ba.at(i));
if (c == 0x7d) {
++i;
c = 0x20 ^ byte(ba.at(i));
}
res.append(c);
}
return res;
}
QByteArray encode7d(const QByteArray &ba)
{
QByteArray res;
res.reserve(ba.size() + 2);
for (int i = 0; i < ba.size(); ++i) {
byte c = byte(ba.at(i));
if (c == 0x7e || c == 0x7d) {
res.append(0x7d);
res.append(0x20 ^ c);
} else {
res.append(c);
}
}
return res;
}
// FIXME: Use the QByteArray based version below?
static inline QString stringFromByte(byte c)
......@@ -138,7 +170,7 @@ static inline QString stringFromByte(byte c)
return QString::fromLatin1("%1").arg(c, 2, 16, QChar('0'));
}
QString stringFromArray(const QByteArray &ba, int maxLen)
SYMBIANUTILS_EXPORT QString stringFromArray(const QByteArray &ba, int maxLen)
{
QString str;
QString ascii;
......@@ -158,7 +190,7 @@ QString stringFromArray(const QByteArray &ba, int maxLen)
return str + " " + ascii;
}
QByteArray hexNumber(uint n, int digits)
SYMBIANUTILS_EXPORT QByteArray hexNumber(uint n, int digits)
{
QByteArray ba = QByteArray::number(n, 16);
if (digits == 0 || ba.size() == digits)
......@@ -166,7 +198,7 @@ QByteArray hexNumber(uint n, int digits)
return QByteArray(digits - ba.size(), '0') + ba;
}
QByteArray hexxNumber(uint n, int digits)
SYMBIANUTILS_EXPORT QByteArray hexxNumber(uint n, int digits)
{
return "0x" + hexNumber(n, digits);
}
......@@ -295,12 +327,12 @@ bool extractResult(QByteArray *buffer, bool serialFrame, TrkResult *result, QByt
return true;
}
ushort extractShort(const char *data)
SYMBIANUTILS_EXPORT ushort extractShort(const char *data)
{
return byte(data[0]) * 256 + byte(data[1]);
}
uint extractInt(const char *data)
SYMBIANUTILS_EXPORT uint extractInt(const char *data)
{
uint res = byte(data[0]);
res *= 256; res += byte(data[1]);
......@@ -309,7 +341,7 @@ uint extractInt(const char *data)
return res;
}
QString quoteUnprintableLatin1(const QByteArray &ba)
SYMBIANUTILS_EXPORT QString quoteUnprintableLatin1(const QByteArray &ba)
{
QString res;
char buf[10];
......@@ -325,49 +357,7 @@ QString quoteUnprintableLatin1(const QByteArray &ba)
return res;
}
QByteArray decode7d(const QByteArray &ba)
{
QByteArray res;
res.reserve(ba.size());
for (int i = 0; i < ba.size(); ++i) {
byte c = byte(ba.at(i));
if (c == 0x7d) {
++i;
c = 0x20 ^ byte(ba.at(i));
}
res.append(c);
}
//if (res != ba)
// logMessage("DECODED: " << stringFromArray(ba)
// << " -> " << stringFromArray(res));
return res;
}
QByteArray encode7d(const QByteArray &ba)
{
QByteArray res;
res.reserve(ba.size() + 2);
for (int i = 0; i < ba.size(); ++i) {
byte c = byte(ba.at(i));
if (c == 0x7e || c == 0x7d) {
res.append(0x7d);
res.append(0x20 ^ c);
} else {
res.append(c);
}
}
//if (res != ba)
// logMessage("ENCODED: " << stringFromArray(ba)
// << " -> " << stringFromArray(res));
return res;
}
void appendByte(QByteArray *ba, byte b)
{
ba->append(b);
}
void appendShort(QByteArray *ba, ushort s, Endianness endian)
SYMBIANUTILS_EXPORT void appendShort(QByteArray *ba, ushort s, Endianness endian)
{
if (endian == BigEndian) {
ba->append(s / 256);
......@@ -378,7 +368,7 @@ void appendShort(QByteArray *ba, ushort s, Endianness endian)
}
}
void appendInt(QByteArray *ba, uint i, Endianness endian)
SYMBIANUTILS_EXPORT void appendInt(QByteArray *ba, uint i, Endianness endian)
{
const uchar b3 = i % 256; i /= 256;
const uchar b2 = i % 256; i /= 256;
......
......@@ -30,19 +30,21 @@
#ifndef DEBUGGER_TRK_UTILS
#define DEBUGGER_TRK_UTILS
#include "symbianutils_global.h"
#include <QtCore/QByteArray>
#include <QtCore/QHash>
#include <QtCore/QStringList>
#include <QtCore/QVariant>
typedef unsigned char byte;
QT_BEGIN_NAMESPACE
class QDateTime;
QT_END_NAMESPACE
namespace trk {
typedef unsigned char byte;
enum Command {
TrkPing = 0x00,
TrkConnect = 0x01,
......@@ -73,17 +75,14 @@ enum Command {
TrkNotifyProcessorReset = 0xa7
};
QByteArray decode7d(const QByteArray &ba);
QByteArray encode7d(const QByteArray &ba);
inline byte extractByte(const char *data) { return *data; }
ushort extractShort(const char *data);
uint extractInt(const char *data);
SYMBIANUTILS_EXPORT ushort extractShort(const char *data);
SYMBIANUTILS_EXPORT uint extractInt(const char *data);
QString quoteUnprintableLatin1(const QByteArray &ba);
SYMBIANUTILS_EXPORT QString quoteUnprintableLatin1(const QByteArray &ba);
// produces "xx xx xx "
QString stringFromArray(const QByteArray &ba, int maxLen = - 1);
SYMBIANUTILS_EXPORT QString stringFromArray(const QByteArray &ba, int maxLen = - 1);