Commit 32e79e10 authored by hjk's avatar hjk

debugger: rename TrkFunctor1 into Callback

parent 5f69a028
......@@ -87,7 +87,6 @@ include(cdb/cdb.pri)
include(gdb/gdb.pri)
include(script/script.pri)
include(tcf/tcf.pri)
include(symbian/symbian.pri)
include(shared/shared.pri)
OTHER_FILES += Debugger.pluginspec
......@@ -27,50 +27,50 @@
**
**************************************************************************/
#ifndef DEBUGGER_TRK_FUNCTOR_H
#define DEBUGGER_TRK_FUNCTOR_H
#ifndef DEBUGGER_CALLBACK_H
#define DEBUGGER_CALLBACK_H
#include <QtGlobal>
// FIXME: rename into something less TRK-specific
namespace trk {
namespace Debugger {
namespace Internal {
/* Helper class for the 1-argument functor:
* Cloneable base class for the implementation which is
* invokeable with the argument. */
template <class Argument>
class TrkFunctor1ImplBase {
Q_DISABLE_COPY(TrkFunctor1ImplBase)
class CallbackImplBase
{
Q_DISABLE_COPY(CallbackImplBase)
public:
TrkFunctor1ImplBase() {}
virtual TrkFunctor1ImplBase *clone() const = 0;
CallbackImplBase() {}
virtual CallbackImplBase *clone() const = 0;
virtual void invoke(Argument a) = 0;
virtual ~TrkFunctor1ImplBase() {}
virtual ~CallbackImplBase() {}
};
/* Helper class for the 1-argument functor: Implementation for
* a class instance with a member function pointer. */
template <class Klass, class Argument>
class TrkFunctor1MemberPtrImpl : public TrkFunctor1ImplBase<Argument> {
template <class Class, class Argument>
class CallbackMemberPtrImpl : public CallbackImplBase<Argument>
{
public:
typedef void (Klass::*MemberFuncPtr)(Argument);
typedef void (Class::*MemberFuncPtr)(Argument);
explicit TrkFunctor1MemberPtrImpl(Klass *instance,
MemberFuncPtr memberFunc) :
m_instance(instance),
m_memberFunc(memberFunc) {}
CallbackMemberPtrImpl(Class *instance,
MemberFuncPtr memberFunc) :
m_instance(instance),
m_memberFunc(memberFunc) {}
virtual TrkFunctor1ImplBase<Argument> *clone() const
virtual CallbackImplBase<Argument> *clone() const
{
return new TrkFunctor1MemberPtrImpl<Klass, Argument>(m_instance, m_memberFunc);
return new CallbackMemberPtrImpl<Class, Argument>(m_instance, m_memberFunc);
}
virtual void invoke(Argument a)
{ (m_instance->*m_memberFunc)(a); }
private:
Klass *m_instance;
Class *m_instance;
MemberFuncPtr m_memberFunc;
};
......@@ -85,33 +85,34 @@ public:
};
...
Foo foo;
TrkFunctor1<const std::string &> f1(&foo, &Foo::print);
Callback<const std::string &> f1(&foo, &Foo::print);
f1("test");
\endcode */
template <class Argument>
class TrkFunctor1 {
class Callback
{
public:
TrkFunctor1() : m_impl(0) {}
Callback() : m_impl(0) {}
template <class Klass>
TrkFunctor1(Klass *instance,
void (Klass::*memberFunc)(Argument)) :
m_impl(new Internal::TrkFunctor1MemberPtrImpl<Klass,Argument>(instance, memberFunc)) {}
template <class Class>
Callback(Class *instance, void (Class::*memberFunc)(Argument)) :
m_impl(new Internal::CallbackMemberPtrImpl<Class,Argument>(instance, memberFunc))
{}
~TrkFunctor1()
~Callback()
{
clean();
}
TrkFunctor1(const TrkFunctor1 &rhs) :
Callback(const Callback &rhs) :
m_impl(0)
{
if (rhs.m_impl)
m_impl = rhs.m_impl->clone();
}
TrkFunctor1 &operator=(const TrkFunctor1 &rhs)
Callback &operator=(const Callback &rhs)
{
if (this != &rhs) {
clean();
......@@ -121,7 +122,7 @@ public:
return *this;
}
inline bool isNull() const { return m_impl == 0; }
bool isNull() const { return m_impl == 0; }
operator bool() const { return !isNull(); }
void operator()(Argument a)
......@@ -139,9 +140,9 @@ private:
}
}
Internal::TrkFunctor1ImplBase<Argument> *m_impl;
Internal::CallbackImplBase<Argument> *m_impl;
};
} // namespace trk
} // namespace Debugger
#endif // _TRK_FUNCTOR_H_
#endif // DEBUGGER_CALLBACK_H
......@@ -3,11 +3,21 @@ HEADERS += \
$$PWD/gdbmi.h \
$$PWD/gdbengine.h \
$$PWD/gdboptionspage.h \
$$PWD/callback.h \
$$PWD/trkutils.h \
$$PWD/trkclient.h \
$$PWD/symbianadapter.h \
#$$PWD/gdboptionspage.h \
SOURCES += \
$$PWD/gdbmi.cpp \
$$PWD/gdbengine.cpp \
$$PWD/gdboptionspage.cpp \
$$PWD/trkutils.cpp \
$$PWD/trkclient.cpp \
$$PWD/symbianadapter.cpp \
$$PWD/symbianengine.cpp \
#$$PWD/gdboptionspage.cpp \
FORMS += $$PWD/gdboptionspage.ui
......
......@@ -29,7 +29,7 @@
#include "symbianadapter.h"
#ifndef STANDALONE_RUNNER
#include "gdb/gdbengine.h"
#include "gdbengine.h"
#endif
#define TrkCB(s) TrkCallback(this, &SymbianAdapter::s)
......@@ -75,7 +75,7 @@ SymbianAdapter::SymbianAdapter()
m_gdbAckMode = true;
m_verbose = 2;
m_serialFrame = false;
m_bufferedMemoryRead = true;
m_bufferedMemoryRead = false;
m_rfcommDevice = "/dev/rfcomm0";
uid_t userId = getuid();
......
......@@ -32,7 +32,7 @@
#include "trkutils.h"
#include "trkclient.h"
#include "../gdb/gdbprocessbase.h"
#include "gdbprocessbase.h"
#include <QtCore/QDebug>
#include <QtCore/QDir>
......@@ -79,8 +79,8 @@ class SymbianAdapter : public GdbProcessBase
public:
typedef trk::TrkResult TrkResult;
typedef trk::TrkFunctor1<const TrkResult &> TrkCallback;
typedef trk::TrkFunctor1<const GdbResult &> GdbCallback;
typedef Callback<const TrkResult &> TrkCallback;
typedef Callback<const GdbResult &> GdbCallback;
SymbianAdapter();
~SymbianAdapter();
......
......@@ -29,7 +29,7 @@
#define QT_NO_CAST_FROM_ASCII
#include "gdb/gdbengine.h"
#include "gdbengine.h"
#include "symbianadapter.h"
#include "debuggermanager.h"
......
......@@ -52,14 +52,17 @@ enum { TimerInterval = 100 };
#ifdef Q_OS_WIN
// Format windows error from GetLastError() value: TODO: Use the one provided by the utisl lib.
// Format windows error from GetLastError() value:
// TODO: Use the one provided by the utils lib.
QString winErrorMessage(unsigned long error)
{
QString rc = QString::fromLatin1("#%1: ").arg(error);
ushort *lpMsgBuf;
const int len = FormatMessage(
FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS,
FORMAT_MESSAGE_ALLOCATE_BUFFER
| FORMAT_MESSAGE_FROM_SYSTEM
| FORMAT_MESSAGE_IGNORE_INSERTS,
NULL, error, 0, (LPTSTR)&lpMsgBuf, 0, NULL);
if (len) {
rc = QString::fromUtf16(lpMsgBuf, len);
......@@ -106,19 +109,17 @@ namespace trk {
* of the answer. */
struct TrkMessage
{
typedef TrkFunctor1<const TrkResult &> Callback;
explicit TrkMessage(byte code = 0u, byte token = 0u,
Callback callback = Callback());
TrkCallback callback = TrkCallback());
byte code;
byte token;
QByteArray data;
QVariant cookie;
Callback callback;
TrkCallback callback;
};
TrkMessage::TrkMessage(byte c, byte t, Callback cb) :
TrkMessage::TrkMessage(byte c, byte t, TrkCallback cb) :
code(c),
token(t),
callback(cb)
......@@ -135,12 +136,10 @@ TrkMessage::TrkMessage(byte c, byte t, Callback cb) :
class TrkWriteQueue
{
public:
typedef TrkDevice::Callback Callback;
TrkWriteQueue();
// Enqueue messages.
void queueTrkMessage(byte code, Callback callback,
void queueTrkMessage(byte code, TrkCallback callback,
const QByteArray &data, const QVariant &cookie);
void queueTrkInitialPing();
......@@ -179,7 +178,7 @@ byte TrkWriteQueue::nextTrkWriteToken()
return trkWriteToken;
}
void TrkWriteQueue::queueTrkMessage(byte code, Callback callback,
void TrkWriteQueue::queueTrkMessage(byte code, TrkCallback callback,
const QByteArray &data, const QVariant &cookie)
{
const byte token = code == TRK_WRITE_QUEUE_NOOP_CODE ?
......@@ -509,7 +508,7 @@ void TrkDevice::emitError(const QString &s)
emit error(s);
}
void TrkDevice::sendTrkMessage(byte code, Callback callback,
void TrkDevice::sendTrkMessage(byte code, TrkCallback callback,
const QByteArray &data, const QVariant &cookie)
{
d->queue.queueTrkMessage(code, callback, data, cookie);
......
......@@ -30,7 +30,7 @@
#ifndef TRKDEVICE_H
#define TRKDEVICE_H
#include "trkfunctor.h"
#include "callback.h"
#include <QtCore/QObject>
#include <QtCore/QVariant>
......@@ -60,6 +60,8 @@ struct TrkDevicePrivate;
enum { TRK_WRITE_QUEUE_NOOP_CODE = 0x7f };
typedef Debugger::Callback<const TrkResult &> TrkCallback;
class TrkDevice : public QObject
{
Q_OBJECT
......@@ -83,9 +85,6 @@ public:
bool write(const QByteArray &data, QString *errorMessage);
// Construct as 'TrkWriteQueueDevice::Callback(instance, &Klass::method);'
typedef TrkFunctor1<const TrkResult &> Callback;
signals:
void messageReceived(const trk::TrkResult &result);
// Emitted with the contents of messages enclosed in 07e, not for log output
......@@ -102,7 +101,7 @@ public:
// Enqueue a message with a notification callback.
void sendTrkMessage(unsigned char code,
Callback callBack = Callback(),
TrkCallback callBack = TrkCallback(),
const QByteArray &data = QByteArray(),
const QVariant &cookie = QVariant());
......
This diff is collapsed.
......@@ -11,7 +11,7 @@ win32:CONFIG+=console
HEADERS += \
$$DEBUGGERHOME/trkutils.h \
$$DEBUGGERHOME/trkfunctor.h \
$$DEBUGGERHOME/callback.h \
$$PWD/trkdevice.h \
SOURCES += \
......
......@@ -40,7 +40,7 @@
namespace trk {
typedef TrkWriteQueueDevice::Callback Callback;
typedef TrkWriteQueueDevice::TrkCallback TrkCallback;
struct LauncherPrivate {
struct CopyState {
......@@ -125,9 +125,9 @@ bool Launcher::startServer(QString *errorMessage)
return false;
d->m_device.sendTrkInitialPing();
d->m_device.sendTrkMessage(TrkConnect); // Connect
d->m_device.sendTrkMessage(TrkSupported, Callback(this, &Launcher::handleSupportMask));
d->m_device.sendTrkMessage(TrkCpuType, Callback(this, &Launcher::handleCpuType));
d->m_device.sendTrkMessage(TrkVersions, Callback(this, &Launcher::handleTrkVersion));
d->m_device.sendTrkMessage(TrkSupported, TrkCallback(this, &Launcher::handleSupportMask));
d->m_device.sendTrkMessage(TrkCpuType, TrkCallback(this, &Launcher::handleCpuType));
d->m_device.sendTrkMessage(TrkVersions, TrkCallback(this, &Launcher::handleTrkVersion));
if (d->m_fileName.isEmpty())
return true;
if (!d->m_copyState.sourceFileName.isEmpty() && !d->m_copyState.destinationFileName.isEmpty())
......@@ -160,7 +160,7 @@ void Launcher::logMessage(const QString &msg)
void Launcher::waitForTrkFinished(const TrkResult &result)
{
Q_UNUSED(result)
d->m_device.sendTrkMessage(TrkPing, Callback(this, &Launcher::handleWaitForFinished));
d->m_device.sendTrkMessage(TrkPing, TrkCallback(this, &Launcher::handleWaitForFinished));
}
void Launcher::terminate()
......@@ -169,7 +169,7 @@ void Launcher::terminate()
QByteArray ba;
appendShort(&ba, 0x0000, TargetByteOrder);
appendInt(&ba, d->m_session.pid, TargetByteOrder);
d->m_device.sendTrkMessage(TrkDeleteItem, Callback(this, &Launcher::waitForTrkFinished), ba);
d->m_device.sendTrkMessage(TrkDeleteItem, TrkCallback(this, &Launcher::waitForTrkFinished), ba);
}
void Launcher::handleResult(const TrkResult &result)
......@@ -240,7 +240,7 @@ void Launcher::handleResult(const TrkResult &result)
QByteArray ba;
appendInt(&ba, d->m_session.pid);
appendInt(&ba, d->m_session.tid);
d->m_device.sendTrkMessage(TrkContinue, Callback(), ba, "CONTINUE");
d->m_device.sendTrkMessage(TrkContinue, TrkCallback(), ba, "CONTINUE");
//d->m_device.sendTrkAck(result.token)
break;
}
......@@ -253,7 +253,7 @@ void Launcher::handleResult(const TrkResult &result)
arg(name));
d->m_device.sendTrkAck(result.token);
if (itemType == 0) { // process
d->m_device.sendTrkMessage(TrkDisconnect, Callback(this, &Launcher::waitForTrkFinished));
d->m_device.sendTrkMessage(TrkDisconnect, TrkCallback(this, &Launcher::waitForTrkFinished));
}
break;
}
......@@ -296,7 +296,7 @@ void Launcher::handleTrkVersion(const TrkResult &result)
<< " float size: " << d->m_session.fpTypeSize
<< " Trk: v" << trkMajor << '.' << trkMinor << " Protocol: " << protocolMajor << '.' << protocolMinor;
qWarning("%s", qPrintable(msg));
d->m_device.sendTrkMessage(TrkPing, Callback(this, &Launcher::waitForTrkFinished));
d->m_device.sendTrkMessage(TrkPing, TrkCallback(this, &Launcher::waitForTrkFinished));
}
}
......@@ -335,12 +335,12 @@ void Launcher::continueCopying()
appendInt(&ba, d->m_copyState.copyFileHandle, TargetByteOrder);
appendString(&ba, d->m_copyState.data->mid(d->m_copyState.position, BLOCKSIZE), TargetByteOrder, false);
d->m_copyState.position += BLOCKSIZE;
d->m_device.sendTrkMessage(TrkWriteFile, Callback(this, &Launcher::handleCopy), ba);
d->m_device.sendTrkMessage(TrkWriteFile, TrkCallback(this, &Launcher::handleCopy), ba);
} else {
QByteArray ba;
appendInt(&ba, d->m_copyState.copyFileHandle, TargetByteOrder);
appendInt(&ba, QDateTime::currentDateTime().toTime_t(), TargetByteOrder);
d->m_device.sendTrkMessage(TrkCloseFile, Callback(this, &Launcher::handleFileCreated), ba);
d->m_device.sendTrkMessage(TrkCloseFile, TrkCallback(this, &Launcher::handleFileCreated), ba);
delete d->m_copyState.data;
d->m_copyState.data = 0;
}
......@@ -388,7 +388,7 @@ void Launcher::handleCreateProcess(const TrkResult &result)
QByteArray ba;
appendInt(&ba, d->m_session.pid);
appendInt(&ba, d->m_session.tid);
d->m_device.sendTrkMessage(TrkContinue, Callback(), ba, "CONTINUE");
d->m_device.sendTrkMessage(TrkContinue, TrkCallback(), ba, "CONTINUE");
}
void Launcher::handleWaitForFinished(const TrkResult &result)
......@@ -423,7 +423,7 @@ void Launcher::cleanUp()
appendByte(&ba, 0x00);
appendByte(&ba, 0x00);
appendInt(&ba, d->m_session.pid);
d->m_device.sendTrkMessage(TrkDeleteItem, Callback(), ba, "Delete process");
d->m_device.sendTrkMessage(TrkDeleteItem, TrkCallback(), ba, "Delete process");
//---TRK------------------------------------------------------
// Command: 0x80 Acknowledge
......@@ -459,7 +459,7 @@ void Launcher::cleanUp()
//---IDE------------------------------------------------------
// Command: 0x02 Disconnect
// [02 27]
// sendTrkMessage(0x02, Callback(this, &Launcher::handleDisconnect));
// sendTrkMessage(0x02, TrkCallback(this, &Launcher::handleDisconnect));
//---TRK------------------------------------------------------
// Command: 0x80 Acknowledge
// Error: 0x00
......@@ -471,7 +471,7 @@ void Launcher::copyFileToRemote()
QByteArray ba;
appendByte(&ba, 0x10);
appendString(&ba, d->m_copyState.destinationFileName.toLocal8Bit(), TargetByteOrder, false);
d->m_device.sendTrkMessage(TrkOpenFile, Callback(this, &Launcher::handleFileCreation), ba);
d->m_device.sendTrkMessage(TrkOpenFile, TrkCallback(this, &Launcher::handleFileCreation), ba);
}
void Launcher::installRemotePackageSilently(const QString &fileName)
......@@ -480,7 +480,7 @@ void Launcher::installRemotePackageSilently(const QString &fileName)
QByteArray ba;
appendByte(&ba, 'C');
appendString(&ba, fileName.toLocal8Bit(), TargetByteOrder, false);
d->m_device.sendTrkMessage(TrkInstallFile, Callback(this, &Launcher::handleInstallPackageFinished), ba);
d->m_device.sendTrkMessage(TrkInstallFile, TrkCallback(this, &Launcher::handleInstallPackageFinished), ba);
}
void Launcher::handleInstallPackageFinished(const TrkResult &)
......@@ -501,7 +501,7 @@ void Launcher::startInferiorIfNeeded()
appendByte(&ba, 0); // ?
appendByte(&ba, 0); // ?
appendString(&ba, d->m_fileName.toLocal8Bit(), TargetByteOrder);
d->m_device.sendTrkMessage(TrkCreateItem, Callback(this, &Launcher::handleCreateProcess), ba); // Create Item
d->m_device.sendTrkMessage(TrkCreateItem, TrkCallback(this, &Launcher::handleCreateProcess), ba); // Create Item
}
}
......@@ -339,24 +339,23 @@ void TrkDevice::emitError(const QString &s)
/* A message to be send to TRK, triggering a callback on receipt
* of the answer. */
typedef Debugger::Callback<const TrkResult &> TrkCallback;
struct TrkMessage {
typedef TrkFunctor1<const TrkResult &> Callback;
explicit TrkMessage(unsigned char code = 0u,
unsigned char token = 0u,
Callback callback = Callback());
TrkCallback callback = TrkCallback());
unsigned char code;
unsigned char token;
QByteArray data;
QVariant cookie;
Callback callback;
TrkCallback callback;
bool invokeOnNAK;
};
TrkMessage::TrkMessage(unsigned char c,
unsigned char t,
Callback cb) :
TrkCallback cb) :
code(c),
token(t),
callback(cb),
......@@ -371,12 +370,10 @@ typedef QSharedPointer<TrkMessage> SharedPointerTrkMessage;
class TrkWriteQueue {
public:
typedef TrkWriteQueueDevice::Callback Callback;
TrkWriteQueue();
// Enqueue messages.
void queueTrkMessage(unsigned char code, Callback callback,
void queueTrkMessage(unsigned char code, TrkCallback callback,
const QByteArray &data, const QVariant &cookie,
bool invokeOnNAK);
void queueTrkInitialPing();
......@@ -419,7 +416,7 @@ unsigned char TrkWriteQueue::nextTrkWriteToken()
return trkWriteToken;
}
void TrkWriteQueue::queueTrkMessage(unsigned char code, Callback callback,
void TrkWriteQueue::queueTrkMessage(unsigned char code, TrkCallback callback,
const QByteArray &data, const QVariant &cookie,
bool invokeOnNAK)
{
......@@ -515,7 +512,7 @@ TrkWriteQueueDevice::~TrkWriteQueueDevice()
delete qd;
}
void TrkWriteQueueDevice::sendTrkMessage(unsigned char code, Callback callback,
void TrkWriteQueueDevice::sendTrkMessage(unsigned char code, TrkCallback callback,
const QByteArray &data, const QVariant &cookie,
bool invokeOnNAK)
{
......@@ -620,7 +617,7 @@ void TrkWriteQueueIODevice::setVerbose(bool b)
d->verbose = b;
}
void TrkWriteQueueIODevice::sendTrkMessage(unsigned char code, Callback callback,
void TrkWriteQueueIODevice::sendTrkMessage(unsigned char code, TrkCallback callback,
const QByteArray &data, const QVariant &cookie,
bool invokeOnNAK)
{
......
......@@ -30,7 +30,7 @@
#ifndef TRKDEVICE_H
#define TRKDEVICE_H
#include "trkfunctor.h"
#include "callback.h"
#include <QtCore/QObject>
#include <QtCore/QVariant>
......@@ -111,12 +111,12 @@ public:
explicit TrkWriteQueueDevice(QObject *parent = 0);
virtual ~TrkWriteQueueDevice();
// Construct as 'TrkWriteQueueDevice::Callback(instance, &Class::method);'
typedef TrkFunctor1<const TrkResult &> Callback;
// Construct as 'TrkWriteQueueDevice::TrkCallback(instance, &Class::method);'
typedef Debugger::Callback<const TrkResult &> TrkCallback;
// Enqueue a message with a notification callback.
void sendTrkMessage(unsigned char code,
Callback callBack = Callback(),
TrkCallback callBack = TrkCallback(),
const QByteArray &data = QByteArray(),
const QVariant &cookie = QVariant(),
// Invoke callback on receiving NAK, too.
......@@ -155,7 +155,7 @@ class TrkWriteQueueIODevice : public QObject
Q_PROPERTY(bool serialFrame READ serialFrame WRITE setSerialFrame)
Q_PROPERTY(bool verbose READ verbose WRITE setVerbose)
public:
typedef TrkFunctor1<const TrkResult &> Callback;
typedef Debugger::Callback<const TrkResult &> TrkCallback;
explicit TrkWriteQueueIODevice(const QSharedPointer<QIODevice> &device,
QObject *parent = 0);
......@@ -168,7 +168,7 @@ public:
void setVerbose(bool b);
void sendTrkMessage(unsigned char code,
Callback callback = Callback(),
TrkCallback callback = TrkCallback(),
const QByteArray &data = QByteArray(),
const QVariant &cookie = QVariant(),
bool invokeOnNAK = false);
......
......@@ -10,6 +10,6 @@ SOURCES += \
HEADERS += \
$$DEBUGGERHOME/trkutils.h \
$$DEBUGGERHOME/trkfunctor.h \
$$DEBUGGERHOME/callback.h \
$$PWD/trkdevice.h \
$$PWD/launcher.h
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment