diff options
author | Andrew Christian <andrew.christian@nokia.com> | 2012-02-12 20:12:42 -0500 |
---|---|---|
committer | Chris Craig <ext-chris.craig@nokia.com> | 2012-02-13 18:44:07 +0100 |
commit | d4ffcc57603afd9b426ebe076c2d5335a4cf35dc (patch) | |
tree | ee6ddef38609bb48eb81f2bd9fd729c17280601e | |
parent | 0754b06d35905bc56b0f86bb258008892f39448d (diff) |
Added RewriteDelegate class and sample GdbRewriteDelegate
Change-Id: I58abe4442afec07c4af707db1c0b7823f7c866e9
Reviewed-by: Chris Craig <ext-chris.craig@nokia.com>
-rw-r--r-- | src/core/core-lib.pri | 4 | ||||
-rw-r--r-- | src/core/gdbrewritedelegate.cpp | 77 | ||||
-rw-r--r-- | src/core/gdbrewritedelegate.h | 60 | ||||
-rw-r--r-- | src/core/processbackendfactory.cpp | 48 | ||||
-rw-r--r-- | src/core/processbackendfactory.h | 15 | ||||
-rw-r--r-- | src/core/processbackendmanager.cpp | 7 | ||||
-rw-r--r-- | src/core/rewritedelegate.cpp | 68 | ||||
-rw-r--r-- | src/core/rewritedelegate.h | 63 | ||||
-rw-r--r-- | tests/auto/auto.pro | 2 | ||||
-rw-r--r-- | tests/auto/rewrite/.gitignore | 1 | ||||
-rw-r--r-- | tests/auto/rewrite/rewrite.pro | 6 | ||||
-rw-r--r-- | tests/auto/rewrite/tst_rewrite.cpp | 82 |
12 files changed, 426 insertions, 7 deletions
diff --git a/src/core/core-lib.pri b/src/core/core-lib.pri index d7cbbe1..4b8aa42 100644 --- a/src/core/core-lib.pri +++ b/src/core/core-lib.pri @@ -9,6 +9,8 @@ PUBLIC_HEADERS += \ $$PWD/processbackendfactory.h \ $$PWD/processbackendmanager.h \ $$PWD/matchdelegate.h \ + $$PWD/rewritedelegate.h \ + $$PWD/gdbrewritedelegate.h \ $$PWD/matchinfo.h \ $$PWD/processinfo.h \ $$PWD/processmanager.h \ @@ -40,6 +42,8 @@ SOURCES += \ $$PWD/processbackendfactory.cpp \ $$PWD/processbackendmanager.cpp \ $$PWD/matchdelegate.cpp \ + $$PWD/rewritedelegate.cpp \ + $$PWD/gdbrewritedelegate.cpp \ $$PWD/matchinfo.cpp \ $$PWD/processinfo.cpp \ $$PWD/processmanager.cpp \ diff --git a/src/core/gdbrewritedelegate.cpp b/src/core/gdbrewritedelegate.cpp new file mode 100644 index 0000000..36aa72d --- /dev/null +++ b/src/core/gdbrewritedelegate.cpp @@ -0,0 +1,77 @@ +/**************************************************************************** +** +** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** $QT_BEGIN_LICENSE:LGPL$ +** GNU Lesser General Public License Usage +** 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. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU General +** Public License version 3.0 as published by the Free Software Foundation +** and appearing in the file LICENSE.GPL included in the packaging of this +** file. Please review the following information to ensure the GNU General +** Public License version 3.0 requirements will be met: +** http://www.gnu.org/copyleft/gpl.html. +** +** Other Usage +** Alternatively, this file may be used in accordance with the terms and +** conditions contained in a signed written agreement between you and Nokia. +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include <QStringList> +#include "gdbrewritedelegate.h" +#include "processinfo.h" + +QT_BEGIN_NAMESPACE_PROCESSMANAGER + +/*! + \class GdbRewriteDelegate + \brief The GdbRewriteDelegate class adds gdb to the process arguments. +*/ + +/*! + Construct a GdbRewriteDelegate with an optional \a parent. +*/ + +GdbRewriteDelegate::GdbRewriteDelegate(QObject *parent) + : RewriteDelegate(parent) +{ +} + +/*! + \fn void GdbRewriteDelegate::rewrite(ProcessInfo& info) + + Rewrites "prog arg1 arg2 ..." to be "gdb -- prog arg1 arg2..."x +*/ + +void GdbRewriteDelegate::rewrite(ProcessInfo& info) +{ + QStringList args = info.arguments(); + args.prepend(info.program()); + args.prepend("--"); + info.setProgram("gdb"); + info.setArguments(args); +} + +#include "moc_gdbrewritedelegate.cpp" + +QT_END_NAMESPACE_PROCESSMANAGER diff --git a/src/core/gdbrewritedelegate.h b/src/core/gdbrewritedelegate.h new file mode 100644 index 0000000..3a0867c --- /dev/null +++ b/src/core/gdbrewritedelegate.h @@ -0,0 +1,60 @@ +/**************************************************************************** +** +** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** $QT_BEGIN_LICENSE:LGPL$ +** GNU Lesser General Public License Usage +** 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. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU General +** Public License version 3.0 as published by the Free Software Foundation +** and appearing in the file LICENSE.GPL included in the packaging of this +** file. Please review the following information to ensure the GNU General +** Public License version 3.0 requirements will be met: +** http://www.gnu.org/copyleft/gpl.html. +** +** Other Usage +** Alternatively, this file may be used in accordance with the terms and +** conditions contained in a signed written agreement between you and Nokia. +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef GDB_REWRITE_DELEGATE_H +#define GDB_REWRITE_DELEGATE_H + +#include "rewritedelegate.h" + +QT_BEGIN_NAMESPACE_PROCESSMANAGER + +class Q_ADDON_PROCESSMANAGER_EXPORT GdbRewriteDelegate : public RewriteDelegate +{ + Q_OBJECT +public: + explicit GdbRewriteDelegate(QObject *parent = 0); + virtual void rewrite(ProcessInfo& info); + +private: + Q_DISABLE_COPY(GdbRewriteDelegate); +}; + +QT_END_NAMESPACE_PROCESSMANAGER + +#endif // GDB_REWRITE_DELEGATE_H diff --git a/src/core/processbackendfactory.cpp b/src/core/processbackendfactory.cpp index 78932b8..d0d7a04 100644 --- a/src/core/processbackendfactory.cpp +++ b/src/core/processbackendfactory.cpp @@ -39,6 +39,7 @@ #include "processbackendfactory.h" #include "matchdelegate.h" +#include "rewritedelegate.h" QT_BEGIN_NAMESPACE_PROCESSMANAGER @@ -56,6 +57,7 @@ QT_BEGIN_NAMESPACE_PROCESSMANAGER ProcessBackendFactory::ProcessBackendFactory(QObject *parent) : QObject(parent) , m_matchDelegate(NULL) + , m_rewriteDelegate(NULL) , m_memoryRestricted(false) { } @@ -126,6 +128,31 @@ void ProcessBackendFactory::setMatchDelegate(MatchDelegate *matchDelegate) } /*! + Return the current RewriteDelegate object + */ + +RewriteDelegate *ProcessBackendFactory::rewriteDelegate() const +{ + return m_rewriteDelegate; +} + +/*! + Set a new process RewriteDelegate object \a rewriteDelegate. + The ProcessBackendFactory takes over parentage of the RewriteDelegate. + */ + +void ProcessBackendFactory::setRewriteDelegate(RewriteDelegate *rewriteDelegate) +{ + if (rewriteDelegate != m_rewriteDelegate) { + if (m_rewriteDelegate) + delete m_rewriteDelegate; + m_rewriteDelegate = rewriteDelegate; + m_rewriteDelegate->setParent(this); + emit rewriteDelegateChanged(); + } +} + +/*! \fn bool ProcessBackendFactory::canCreate(const ProcessInfo& info) const Return true if this ProcessBackendFactory matches the ProcessInfo \a info @@ -144,12 +171,33 @@ bool ProcessBackendFactory::canCreate(const ProcessInfo& info) const } /*! + \fn void ProcessBackendFactory::rewrite(ProcessInfo& info) + + Rewrites the ProcessInfo \a info object by passing it to the RewriteDelegate + object. If no RewriteDelegate object is installed, this function does nothing. + + This virtual function may be overridden. +*/ + +void ProcessBackendFactory::rewrite(ProcessInfo& info) +{ + if (m_rewriteDelegate) + m_rewriteDelegate->rewrite(info); +} + +/*! \fn void ProcessBackendFactory::matchDelegateChanged() Signal emitted whenever the MatchDelegate is changed. */ /*! + \fn void ProcessBackendFactory::rewriteDelegateChanged() + + Signal emitted whenever the RewriteDelegate is changed. +*/ + +/*! \fn ProcessBackend * ProcessBackendFactory::create(const ProcessInfo& info, QObject *parent) Create a ProcessBackend object based on the ProcessInfo \a info and \a parent. diff --git a/src/core/processbackendfactory.h b/src/core/processbackendfactory.h index 70a3be5..3600ed7 100644 --- a/src/core/processbackendfactory.h +++ b/src/core/processbackendfactory.h @@ -50,33 +50,40 @@ QT_BEGIN_NAMESPACE_PROCESSMANAGER class ProcessBackend; class ProcessInfo; class MatchDelegate; +class RewriteDelegate; class Q_ADDON_PROCESSMANAGER_EXPORT ProcessBackendFactory : public QObject { Q_OBJECT Q_PROPERTY(MatchDelegate* matchDelegate READ matchDelegate WRITE setMatchDelegate NOTIFY matchDelegateChanged); + Q_PROPERTY(RewriteDelegate* rewriteDelegate READ rewriteDelegate WRITE setRewriteDelegate NOTIFY rewriteDelegateChanged); public: ProcessBackendFactory(QObject *parent = 0); virtual ~ProcessBackendFactory(); virtual bool canCreate(const ProcessInfo& info) const; + virtual void rewrite(ProcessInfo& info); virtual ProcessBackend *create(const ProcessInfo& info, QObject *parent) = 0; void setMemoryRestricted(bool); virtual QList<Q_PID> internalProcesses(); - MatchDelegate * matchDelegate() const; - void setMatchDelegate(MatchDelegate *); + MatchDelegate * matchDelegate() const; + void setMatchDelegate(MatchDelegate *); + RewriteDelegate * rewriteDelegate() const; + void setRewriteDelegate(RewriteDelegate *); signals: void matchDelegateChanged(); + void rewriteDelegateChanged(); protected: virtual void handleMemoryRestrictionChange(); protected: - MatchDelegate *m_matchDelegate; - bool m_memoryRestricted; + MatchDelegate *m_matchDelegate; + RewriteDelegate *m_rewriteDelegate; + bool m_memoryRestricted; }; QT_END_NAMESPACE_PROCESSMANAGER diff --git a/src/core/processbackendmanager.cpp b/src/core/processbackendmanager.cpp index 9df3506..9e00602 100644 --- a/src/core/processbackendmanager.cpp +++ b/src/core/processbackendmanager.cpp @@ -96,8 +96,11 @@ ProcessBackendManager::~ProcessBackendManager() ProcessBackend *ProcessBackendManager::create(const ProcessInfo& info, QObject *parent) { foreach (ProcessBackendFactory *factory, m_factories) { - if (factory->canCreate(info)) - return factory->create(info, parent); + if (factory->canCreate(info)) { + ProcessInfo i = info; + factory->rewrite(i); + return factory->create(i, parent); + } } return NULL; } diff --git a/src/core/rewritedelegate.cpp b/src/core/rewritedelegate.cpp new file mode 100644 index 0000000..c49eb2f --- /dev/null +++ b/src/core/rewritedelegate.cpp @@ -0,0 +1,68 @@ +/**************************************************************************** +** +** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** $QT_BEGIN_LICENSE:LGPL$ +** GNU Lesser General Public License Usage +** 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. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU General +** Public License version 3.0 as published by the Free Software Foundation +** and appearing in the file LICENSE.GPL included in the packaging of this +** file. Please review the following information to ensure the GNU General +** Public License version 3.0 requirements will be met: +** http://www.gnu.org/copyleft/gpl.html. +** +** Other Usage +** Alternatively, this file may be used in accordance with the terms and +** conditions contained in a signed written agreement between you and Nokia. +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "rewritedelegate.h" + +QT_BEGIN_NAMESPACE_PROCESSMANAGER + +/*! + \class RewriteDelegate + \brief The RewriteDelegate class is a virtual class for rewriting ProcessInfo objects. + + You must subclass this class to do anything useful. +*/ + +/*! + Construct a RewriteDelegate with an optional \a parent. +*/ + +RewriteDelegate::RewriteDelegate(QObject *parent) + : QObject(parent) +{ +} + +/*! + \fn void RewriteDelegate::rewrite(ProcessInfo& info) + + You must override this function. +*/ + +#include "moc_rewritedelegate.cpp" + +QT_END_NAMESPACE_PROCESSMANAGER diff --git a/src/core/rewritedelegate.h b/src/core/rewritedelegate.h new file mode 100644 index 0000000..f40c25f --- /dev/null +++ b/src/core/rewritedelegate.h @@ -0,0 +1,63 @@ +/**************************************************************************** +** +** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** $QT_BEGIN_LICENSE:LGPL$ +** GNU Lesser General Public License Usage +** 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. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU General +** Public License version 3.0 as published by the Free Software Foundation +** and appearing in the file LICENSE.GPL included in the packaging of this +** file. Please review the following information to ensure the GNU General +** Public License version 3.0 requirements will be met: +** http://www.gnu.org/copyleft/gpl.html. +** +** Other Usage +** Alternatively, this file may be used in accordance with the terms and +** conditions contained in a signed written agreement between you and Nokia. +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef REWRITE_DELEGATE_H +#define REWRITE_DELEGATE_H + +#include <QObject> +#include "processmanager-global.h" + +QT_BEGIN_NAMESPACE_PROCESSMANAGER + +class ProcessInfo; + +class Q_ADDON_PROCESSMANAGER_EXPORT RewriteDelegate : public QObject +{ + Q_OBJECT +public: + explicit RewriteDelegate(QObject *parent = 0); + virtual void rewrite(ProcessInfo& info) = 0; + +private: + Q_DISABLE_COPY(RewriteDelegate); +}; + +QT_END_NAMESPACE_PROCESSMANAGER + +#endif // REWRITE_DELEGATE_H diff --git a/tests/auto/auto.pro b/tests/auto/auto.pro index 787f22b..ebc3513 100644 --- a/tests/auto/auto.pro +++ b/tests/auto/auto.pro @@ -1,2 +1,2 @@ TEMPLATE = subdirs -SUBDIRS = processmanager declarative matcher +SUBDIRS = processmanager declarative matcher rewrite diff --git a/tests/auto/rewrite/.gitignore b/tests/auto/rewrite/.gitignore new file mode 100644 index 0000000..d9c4f1b --- /dev/null +++ b/tests/auto/rewrite/.gitignore @@ -0,0 +1 @@ +tst_rewrite diff --git a/tests/auto/rewrite/rewrite.pro b/tests/auto/rewrite/rewrite.pro new file mode 100644 index 0000000..fd53bdc --- /dev/null +++ b/tests/auto/rewrite/rewrite.pro @@ -0,0 +1,6 @@ +TARGET = tst_rewrite +QT = processmanager testlib +CONFIG -= app_bundle +CONFIG += testcase + +SOURCES += tst_rewrite.cpp diff --git a/tests/auto/rewrite/tst_rewrite.cpp b/tests/auto/rewrite/tst_rewrite.cpp new file mode 100644 index 0000000..00bbd67 --- /dev/null +++ b/tests/auto/rewrite/tst_rewrite.cpp @@ -0,0 +1,82 @@ +/**************************************************************************** +** +** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** $QT_BEGIN_LICENSE:LGPL$ +** GNU Lesser General Public License Usage +** 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. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU General +** Public License version 3.0 as published by the Free Software Foundation +** and appearing in the file LICENSE.GPL included in the packaging of this +** file. Please review the following information to ensure the GNU General +** Public License version 3.0 requirements will be met: +** http://www.gnu.org/copyleft/gpl.html. +** +** Other Usage +** Alternatively, this file may be used in accordance with the terms and +** conditions contained in a signed written agreement between you and Nokia. +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include <QtTest> + +#include "gdbrewritedelegate.h" +#include "processinfo.h" + +QT_USE_NAMESPACE_PROCESSMANAGER + +/******************************************************************************/ + +class TestRewrite : public QObject +{ + Q_OBJECT +public: + TestRewrite(QObject *parent=0); + +private Q_SLOTS: + void rewriteGdb(); +}; + +TestRewrite::TestRewrite(QObject *parent) + : QObject(parent) +{ +} + +void TestRewrite::rewriteGdb() +{ + ProcessInfo info; + info.setProgram("/usr/bin/abc"); + info.setArguments(QStringList() << "a" << "b"); + + GdbRewriteDelegate delegate; + delegate.rewrite(info); + + QCOMPARE(info.program(), QLatin1String("gdb")); + QCOMPARE(info.arguments().size(), 4); + QCOMPARE(info.arguments().at(0), QLatin1String("--")); + QCOMPARE(info.arguments().at(1), QLatin1String("/usr/bin/abc")); + QCOMPARE(info.arguments().at(2), QLatin1String("a")); + QCOMPARE(info.arguments().at(3), QLatin1String("b")); +} + +QTEST_MAIN(TestRewrite) +#include "tst_rewrite.moc" |