Commit 3de45d8c authored by hjk's avatar hjk

Analyzer: Merge IAnalyzerEngine and AnalyzerRunControl

Change-Id: I74edaef59600a44924d2692c1ebc7f98d8581115
Reviewed-by: default avatarChristiaan Janssen <christiaan.janssen@digia.com>
parent 1fb755bb
...@@ -7,7 +7,6 @@ QT += network ...@@ -7,7 +7,6 @@ QT += network
# AnalyzerBase files # AnalyzerBase files
SOURCES += \ SOURCES += \
ianalyzerengine.cpp \
ianalyzertool.cpp \ ianalyzertool.cpp \
analyzerplugin.cpp \ analyzerplugin.cpp \
analyzerruncontrol.cpp \ analyzerruncontrol.cpp \
...@@ -19,7 +18,6 @@ SOURCES += \ ...@@ -19,7 +18,6 @@ SOURCES += \
startremotedialog.cpp startremotedialog.cpp
HEADERS += \ HEADERS += \
ianalyzerengine.h \
ianalyzertool.h \ ianalyzertool.h \
analyzerbase_global.h \ analyzerbase_global.h \
analyzerconstants.h \ analyzerconstants.h \
......
...@@ -31,8 +31,6 @@ QtcPlugin { ...@@ -31,8 +31,6 @@ QtcPlugin {
"analyzerstartparameters.h", "analyzerstartparameters.h",
"analyzerutils.cpp", "analyzerutils.cpp",
"analyzerutils.h", "analyzerutils.h",
"ianalyzerengine.cpp",
"ianalyzerengine.h",
"ianalyzertool.cpp", "ianalyzertool.cpp",
"ianalyzertool.h", "ianalyzertool.h",
"startremotedialog.cpp", "startremotedialog.cpp",
......
...@@ -29,14 +29,10 @@ ...@@ -29,14 +29,10 @@
****************************************************************************/ ****************************************************************************/
#include "analyzerruncontrol.h" #include "analyzerruncontrol.h"
#include "ianalyzerengine.h"
#include "ianalyzertool.h" #include "ianalyzertool.h"
#include "analyzermanager.h" #include "analyzermanager.h"
#include "analyzerstartparameters.h" #include "analyzerstartparameters.h"
#include <projectexplorer/projectexplorer.h>
#include <projectexplorer/taskhub.h>
#include <QDebug> #include <QDebug>
#include <QAction> #include <QAction>
...@@ -44,117 +40,64 @@ using namespace ProjectExplorer; ...@@ -44,117 +40,64 @@ using namespace ProjectExplorer;
////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////
// //
// AnalyzerRunControl::Private // AnalyzerRunControl
// //
////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////
namespace Analyzer { namespace Analyzer {
class AnalyzerRunControl::Private AnalyzerRunControl::AnalyzerRunControl(const AnalyzerStartParameters &sp,
ProjectExplorer::RunConfiguration *runConfiguration)
: RunControl(runConfiguration, sp.runMode)
{ {
public: m_runConfig = runConfiguration;
Private(); m_sp = sp;
bool m_isRunning;
IAnalyzerEngine *m_engine;
};
AnalyzerRunControl::Private::Private()
: m_isRunning(false), m_engine(0)
{}
//////////////////////////////////////////////////////////////////////////
//
// AnalyzerRunControl
//
//////////////////////////////////////////////////////////////////////////
AnalyzerRunControl::AnalyzerRunControl(IAnalyzerTool *tool,
const AnalyzerStartParameters &sp, RunConfiguration *runConfiguration)
: RunControl(runConfiguration, tool->runMode()),
d(new Private)
{
d->m_engine = tool->createEngine(sp, runConfiguration);
if (!d->m_engine)
return;
connect(d->m_engine, SIGNAL(outputReceived(QString,Utils::OutputFormat)),
SLOT(receiveOutput(QString,Utils::OutputFormat)));
connect(d->m_engine, SIGNAL(taskToBeAdded(ProjectExplorer::Task::TaskType,QString,QString,int)),
SLOT(addTask(ProjectExplorer::Task::TaskType,QString,QString,int)));
connect(d->m_engine, SIGNAL(finished()),
SLOT(engineFinished()));
connect(this, SIGNAL(finished()), SLOT(runControlFinished()));
connect(AnalyzerManager::stopAction(), SIGNAL(triggered()), SLOT(stopIt())); connect(AnalyzerManager::stopAction(), SIGNAL(triggered()), SLOT(stopIt()));
} }
AnalyzerRunControl::~AnalyzerRunControl() void AnalyzerRunControl::stopIt()
{ {
if (d->m_isRunning) if (stop() == RunControl::StoppedSynchronously)
stop(); AnalyzerManager::handleToolFinished();
}
delete d->m_engine; void AnalyzerRunControl::runControlFinished()
d->m_engine = 0; {
delete d; m_isRunning = false;
AnalyzerManager::handleToolFinished();
emit finished();
} }
void AnalyzerRunControl::start() void AnalyzerRunControl::start()
{ {
if (!d->m_engine) {
emit finished();
return;
}
AnalyzerManager::handleToolStarted(); AnalyzerManager::handleToolStarted();
// Clear about-to-be-outdated tasks. if (startEngine()) {
ProjectExplorerPlugin::instance()->taskHub() m_isRunning = true;
->clearTasks(Core::Id(Constants::ANALYZERTASK_ID));
if (d->m_engine->start()) {
d->m_isRunning = true;
emit started(); emit started();
} }
} }
RunControl::StopResult AnalyzerRunControl::stop() RunControl::StopResult AnalyzerRunControl::stop()
{ {
if (!d->m_engine || !d->m_isRunning) if (!m_isRunning)
return StoppedSynchronously; return StoppedSynchronously;
d->m_engine->stop(); stopEngine();
d->m_isRunning = false; m_isRunning = false;
return AsynchronousStop; return AsynchronousStop;
} }
void AnalyzerRunControl::stopIt()
{
if (stop() == RunControl::StoppedSynchronously)
AnalyzerManager::handleToolFinished();
}
void AnalyzerRunControl::engineFinished()
{
d->m_isRunning = false;
AnalyzerManager::handleToolFinished();
emit finished();
}
bool AnalyzerRunControl::isRunning() const bool AnalyzerRunControl::isRunning() const
{ {
return d->m_isRunning; return m_isRunning;
} }
QString AnalyzerRunControl::displayName() const QString AnalyzerRunControl::displayName() const
{ {
if (!d->m_engine) return m_runConfig ? m_runConfig->displayName() : m_sp.displayName;
return QString();
if (d->m_engine->runConfiguration())
return d->m_engine->runConfiguration()->displayName();
else
return d->m_engine->startParameters().displayName;
} }
QIcon AnalyzerRunControl::icon() const QIcon AnalyzerRunControl::icon() const
...@@ -162,23 +105,4 @@ QIcon AnalyzerRunControl::icon() const ...@@ -162,23 +105,4 @@ QIcon AnalyzerRunControl::icon() const
return QIcon(QLatin1String(":/images/analyzer_start_small.png")); return QIcon(QLatin1String(":/images/analyzer_start_small.png"));
} }
IAnalyzerEngine *AnalyzerRunControl::engine() const
{
return d->m_engine;
}
void AnalyzerRunControl::receiveOutput(const QString &text, Utils::OutputFormat format)
{
appendMessage(text, format);
}
void AnalyzerRunControl::addTask(Task::TaskType type, const QString &description,
const QString &file, int line)
{
TaskHub *hub = ProjectExplorerPlugin::instance()->taskHub();
hub->addTask(Task(type, description, Utils::FileName::fromUserInput(file), line,
Core::Id(Constants::ANALYZERTASK_ID)));
hub->requestPopup();
}
} // namespace Analyzer } // namespace Analyzer
...@@ -36,20 +36,55 @@ ...@@ -36,20 +36,55 @@
#include <projectexplorer/runconfiguration.h> #include <projectexplorer/runconfiguration.h>
#include <projectexplorer/task.h> #include <projectexplorer/task.h>
namespace Analyzer { #include "analyzerbase_global.h"
#include "analyzerstartparameters.h"
#include <projectexplorer/task.h>
#include <projectexplorer/runconfiguration.h>
#include <utils/outputformat.h>
class AnalyzerStartParameters; #include <QObject>
class IAnalyzerTool; #include <QString>
class IAnalyzerEngine;
namespace ProjectExplorer { class RunConfiguration; }
namespace Analyzer {
/**
* An AnalyzerRunControl instance handles the launch of an analyzation tool.
*
* It gets created for each launch and deleted when the launch is stopped or ended.
*/
class ANALYZER_EXPORT AnalyzerRunControl : public ProjectExplorer::RunControl class ANALYZER_EXPORT AnalyzerRunControl : public ProjectExplorer::RunControl
{ {
Q_OBJECT Q_OBJECT
public: public:
AnalyzerRunControl(IAnalyzerTool *tool, const AnalyzerStartParameters &sp, AnalyzerRunControl(const AnalyzerStartParameters &sp,
ProjectExplorer::RunConfiguration *runConfiguration); ProjectExplorer::RunConfiguration *runConfiguration);
~AnalyzerRunControl();
/// Start analyzation process.
virtual bool startEngine() = 0;
/// Trigger async stop of the analyzation process.
virtual void stopEngine() = 0;
/// Controller actions.
virtual bool canPause() const { return false; }
virtual void pause() {}
virtual void unpause() {}
/// The active run configuration for this engine, might be zero.
ProjectExplorer::RunConfiguration *runConfiguration() const { return m_runConfig; }
/// The start parameters for this engine.
const AnalyzerStartParameters &startParameters() const { return m_sp; }
StartMode mode() const { return m_sp.startMode; }
virtual void notifyRemoteSetupDone(quint16) {}
virtual void notifyRemoteFinished(bool) {}
bool m_isRunning;
// ProjectExplorer::RunControl // ProjectExplorer::RunControl
void start(); void start();
...@@ -58,22 +93,21 @@ public: ...@@ -58,22 +93,21 @@ public:
QString displayName() const; QString displayName() const;
QIcon icon() const; QIcon icon() const;
IAnalyzerEngine *engine() const; public slots:
virtual void logApplicationMessage(const QString &, Utils::OutputFormat) {}
private slots: private slots:
void stopIt(); void stopIt();
void receiveOutput(const QString &, Utils::OutputFormat format); void runControlFinished();
void addTask(ProjectExplorer::Task::TaskType type, const QString &description, signals:
const QString &file, int line); /// Must be emitted when the engine is starting.
void starting(const Analyzer::AnalyzerRunControl *);
void engineFinished();
private: private:
class Private; ProjectExplorer::RunConfiguration *m_runConfig;
Private *d; AnalyzerStartParameters m_sp;
}; };
} // namespace Analyzer } // namespace Analyzer
#endif // ANALYZERRUNCONTROL_H #endif // ANALYZERRUNCONTROL_H
...@@ -38,6 +38,7 @@ ...@@ -38,6 +38,7 @@
#include <coreplugin/id.h> #include <coreplugin/id.h>
#include <ssh/sshconnection.h> #include <ssh/sshconnection.h>
#include <utils/environment.h> #include <utils/environment.h>
#include <projectexplorer/projectexplorerconstants.h>
namespace Analyzer { namespace Analyzer {
...@@ -51,6 +52,7 @@ public: ...@@ -51,6 +52,7 @@ public:
{} {}
StartMode startMode; StartMode startMode;
ProjectExplorer::RunMode runMode;
QSsh::SshConnectionParameters connParams; QSsh::SshConnectionParameters connParams;
Core::Id toolId; Core::Id toolId;
......
/****************************************************************************
**
** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies).
** Contact: http://www.qt-project.org/legal
** Author: Nicolas Arnaud-Cormos, KDAB (nicolas.arnaud-cormos@kdab.com)
**
** This file is part of Qt Creator.
**
** Commercial License Usage
** Licensees holding valid commercial Qt licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and Digia. For licensing terms and
** conditions see http://qt.digia.com/licensing. For further information
** use the contact form at http://qt.digia.com/contact-us.
**
** 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.
**
** In addition, as a special exception, Digia gives you certain additional
** rights. These rights are described in the Digia Qt LGPL Exception
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
**
****************************************************************************/
#include "ianalyzerengine.h"
namespace Analyzer {
IAnalyzerEngine::IAnalyzerEngine(const AnalyzerStartParameters &sp,
ProjectExplorer::RunConfiguration *runConfiguration)
{
m_runConfig = runConfiguration;
m_sp = sp;
}
} // namespace Analyzer
/****************************************************************************
**
** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies).
** Contact: http://www.qt-project.org/legal
** Author: Nicolas Arnaud-Cormos, KDAB (nicolas.arnaud-cormos@kdab.com)
**
** This file is part of Qt Creator.
**
** Commercial License Usage
** Licensees holding valid commercial Qt licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and Digia. For licensing terms and
** conditions see http://qt.digia.com/licensing. For further information
** use the contact form at http://qt.digia.com/contact-us.
**
** 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.
**
** In addition, as a special exception, Digia gives you certain additional
** rights. These rights are described in the Digia Qt LGPL Exception
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
**
****************************************************************************/
#ifndef IANALYZERENGINE_H
#define IANALYZERENGINE_H
#include "analyzerbase_global.h"
#include "analyzerstartparameters.h"
#include <projectexplorer/task.h>
#include <utils/outputformat.h>
#include <QObject>
#include <QString>
namespace ProjectExplorer {
class RunConfiguration;
}
namespace Analyzer {
/**
* An IAnalyzerEngine instance handles the launch of an analyzation tool.
*
* It gets created for each launch and deleted when the launch is stopped or ended.
*/
class ANALYZER_EXPORT IAnalyzerEngine : public QObject
{
Q_OBJECT
public:
IAnalyzerEngine(const AnalyzerStartParameters &sp,
ProjectExplorer::RunConfiguration *runConfiguration);
/// Start analyzation process.
virtual bool start() = 0;
/// Trigger async stop of the analyzation process.
virtual void stop() = 0;
/// Controller actions.
virtual bool canPause() const { return false; }
virtual void pause() {}
virtual void unpause() {}
/// The active run configuration for this engine, might be zero.
ProjectExplorer::RunConfiguration *runConfiguration() const { return m_runConfig; }
/// The start parameters for this engine.
const AnalyzerStartParameters &startParameters() const { return m_sp; }
StartMode mode() const { return m_sp.startMode; }
virtual void notifyRemoteSetupDone(quint16) {}
virtual void notifyRemoteFinished(bool) {}
public slots:
virtual void logApplicationMessage(const QString &, Utils::OutputFormat) {}
signals:
/// Should be emitted when the debuggee outputted something.
void outputReceived(const QString &, Utils::OutputFormat format);
/// Can be emitted when you want to show a task, e.g. to display an error.
void taskToBeAdded(ProjectExplorer::Task::TaskType type, const QString &description,
const QString &file, int line);
/// Must be emitted when the engine finished.
void finished();
/// Must be emitted when the engine is starting.
void starting(const Analyzer::IAnalyzerEngine *);
private:
ProjectExplorer::RunConfiguration *m_runConfig;
AnalyzerStartParameters m_sp;
};
} // namespace Analyzer
#endif // IANALYZERENGINE_H
...@@ -45,7 +45,7 @@ class RunConfiguration; ...@@ -45,7 +45,7 @@ class RunConfiguration;
namespace Analyzer { namespace Analyzer {
class IAnalyzerOutputPaneAdapter; class IAnalyzerOutputPaneAdapter;
class IAnalyzerEngine; class AnalyzerRunControl;
class AbstractAnalyzerSubConfig; class AbstractAnalyzerSubConfig;
...@@ -116,7 +116,7 @@ public: ...@@ -116,7 +116,7 @@ public:
/// Returns a new engine for the given start parameters. /// Returns a new engine for the given start parameters.
/// Called each time the tool is launched. /// Called each time the tool is launched.
virtual IAnalyzerEngine *createEngine(const AnalyzerStartParameters &sp, virtual AnalyzerRunControl *createRunControl(const AnalyzerStartParameters &sp,
ProjectExplorer::RunConfiguration *runConfiguration = 0) = 0; ProjectExplorer::RunConfiguration *runConfiguration = 0) = 0;
/// Returns true if the tool can be run /// Returns true if the tool can be run
......
...@@ -33,7 +33,6 @@ ...@@ -33,7 +33,6 @@
#include "androidmanager.h" #include "androidmanager.h"
#include <analyzerbase/ianalyzertool.h> #include <analyzerbase/ianalyzertool.h>
#include <analyzerbase/ianalyzerengine.h>
#include <analyzerbase/analyzermanager.h> #include <analyzerbase/analyzermanager.h>
#include <analyzerbase/analyzerruncontrol.h> #include <analyzerbase/analyzerruncontrol.h>
#include <analyzerbase/analyzerstartparameters.h> #include <analyzerbase/analyzerstartparameters.h>
...@@ -63,6 +62,7 @@ RunControl *AndroidAnalyzeSupport::createAnalyzeRunControl(AndroidRunConfigurati ...@@ -63,6 +62,7 @@ RunControl *AndroidAnalyzeSupport::createAnalyzeRunControl(AndroidRunConfigurati
AnalyzerStartParameters params; AnalyzerStartParameters params;
params.toolId = tool->id(); params.toolId = tool->id();
params.runMode = runMode;
Target *target = runConfig->target(); Target *target = runConfig->target();
params.displayName = AndroidManager::packageName(target); params.displayName = AndroidManager::packageName(target);
params.sysroot = SysRootKitInformation::sysRoot(target->kit()).toString(); params.sysroot = SysRootKitInformation::sysRoot(target->kit()).toString();
...@@ -76,23 +76,21 @@ RunControl *AndroidAnalyzeSupport::createAnalyzeRunControl(AndroidRunConfigurati ...@@ -76,23 +76,21 @@ RunControl *AndroidAnalyzeSupport::createAnalyzeRunControl(AndroidRunConfigurati
params.startMode = StartQmlRemote; params.startMode = StartQmlRemote;
} }
AnalyzerRunControl * const analyzerRunControl = new AnalyzerRunControl(tool, params, runConfig); AnalyzerRunControl *analyzerRunControl = tool->createRunControl(params, runConfig);
new AndroidAnalyzeSupport(runConfig, analyzerRunControl); (void) new AndroidAnalyzeSupport(runConfig, analyzerRunControl);
return analyzerRunControl; return analyzerRunControl;
} }
AndroidAnalyzeSupport::AndroidAnalyzeSupport(AndroidRunConfiguration *runConfig, AndroidAnalyzeSupport::AndroidAnalyzeSupport(AndroidRunConfiguration *runConfig,
AnalyzerRunControl *runControl) AnalyzerRunControl *runControl)
: AndroidRunSupport(runConfig, runControl), : AndroidRunSupport(runConfig, runControl),
m_engine(0), m_runControl(0),
m_qmlPort(0) m_qmlPort(0)
{ {
if (runControl) { if (runControl) {