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
# AnalyzerBase files
SOURCES += \
ianalyzerengine.cpp \
ianalyzertool.cpp \
analyzerplugin.cpp \
analyzerruncontrol.cpp \
......@@ -19,7 +18,6 @@ SOURCES += \
startremotedialog.cpp
HEADERS += \
ianalyzerengine.h \
ianalyzertool.h \
analyzerbase_global.h \
analyzerconstants.h \
......
......@@ -31,8 +31,6 @@ QtcPlugin {
"analyzerstartparameters.h",
"analyzerutils.cpp",
"analyzerutils.h",
"ianalyzerengine.cpp",
"ianalyzerengine.h",
"ianalyzertool.cpp",
"ianalyzertool.h",
"startremotedialog.cpp",
......
......@@ -29,14 +29,10 @@
****************************************************************************/
#include "analyzerruncontrol.h"
#include "ianalyzerengine.h"
#include "ianalyzertool.h"
#include "analyzermanager.h"
#include "analyzerstartparameters.h"
#include <projectexplorer/projectexplorer.h>
#include <projectexplorer/taskhub.h>
#include <QDebug>
#include <QAction>
......@@ -44,117 +40,64 @@ using namespace ProjectExplorer;
//////////////////////////////////////////////////////////////////////////
//
// AnalyzerRunControl::Private
// AnalyzerRunControl
//
//////////////////////////////////////////////////////////////////////////
namespace Analyzer {
class AnalyzerRunControl::Private
AnalyzerRunControl::AnalyzerRunControl(const AnalyzerStartParameters &sp,
ProjectExplorer::RunConfiguration *runConfiguration)
: RunControl(runConfiguration, sp.runMode)
{
public:
Private();
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()));
m_runConfig = runConfiguration;
m_sp = sp;
connect(this, SIGNAL(finished()), SLOT(runControlFinished()));
connect(AnalyzerManager::stopAction(), SIGNAL(triggered()), SLOT(stopIt()));
}
AnalyzerRunControl::~AnalyzerRunControl()
void AnalyzerRunControl::stopIt()
{
if (d->m_isRunning)
stop();
if (stop() == RunControl::StoppedSynchronously)
AnalyzerManager::handleToolFinished();
}
delete d->m_engine;
d->m_engine = 0;
delete d;
void AnalyzerRunControl::runControlFinished()
{
m_isRunning = false;
AnalyzerManager::handleToolFinished();
emit finished();
}
void AnalyzerRunControl::start()
{
if (!d->m_engine) {
emit finished();
return;
}
AnalyzerManager::handleToolStarted();
// Clear about-to-be-outdated tasks.
ProjectExplorerPlugin::instance()->taskHub()
->clearTasks(Core::Id(Constants::ANALYZERTASK_ID));
if (d->m_engine->start()) {
d->m_isRunning = true;
if (startEngine()) {
m_isRunning = true;
emit started();
}
}
RunControl::StopResult AnalyzerRunControl::stop()
{
if (!d->m_engine || !d->m_isRunning)
if (!m_isRunning)
return StoppedSynchronously;
d->m_engine->stop();
d->m_isRunning = false;
stopEngine();
m_isRunning = false;
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
{
return d->m_isRunning;
return m_isRunning;
}
QString AnalyzerRunControl::displayName() const
{
if (!d->m_engine)
return QString();
if (d->m_engine->runConfiguration())
return d->m_engine->runConfiguration()->displayName();
else
return d->m_engine->startParameters().displayName;
return m_runConfig ? m_runConfig->displayName() : m_sp.displayName;
}
QIcon AnalyzerRunControl::icon() const
......@@ -162,23 +105,4 @@ QIcon AnalyzerRunControl::icon() const
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
......@@ -36,20 +36,55 @@
#include <projectexplorer/runconfiguration.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;
class IAnalyzerTool;
class IAnalyzerEngine;
#include <QObject>
#include <QString>
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
{
Q_OBJECT
public:
AnalyzerRunControl(IAnalyzerTool *tool, const AnalyzerStartParameters &sp,
AnalyzerRunControl(const AnalyzerStartParameters &sp,
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
void start();
......@@ -58,22 +93,21 @@ public:
QString displayName() const;
QIcon icon() const;
IAnalyzerEngine *engine() const;
public slots:
virtual void logApplicationMessage(const QString &, Utils::OutputFormat) {}
private slots:
void stopIt();
void receiveOutput(const QString &, Utils::OutputFormat format);
void runControlFinished();
void addTask(ProjectExplorer::Task::TaskType type, const QString &description,
const QString &file, int line);
void engineFinished();
signals:
/// Must be emitted when the engine is starting.
void starting(const Analyzer::AnalyzerRunControl *);
private:
class Private;
Private *d;
ProjectExplorer::RunConfiguration *m_runConfig;
AnalyzerStartParameters m_sp;
};
} // namespace Analyzer
#endif // ANALYZERRUNCONTROL_H
......@@ -38,6 +38,7 @@
#include <coreplugin/id.h>
#include <ssh/sshconnection.h>
#include <utils/environment.h>
#include <projectexplorer/projectexplorerconstants.h>
namespace Analyzer {
......@@ -51,6 +52,7 @@ public:
{}
StartMode startMode;
ProjectExplorer::RunMode runMode;
QSsh::SshConnectionParameters connParams;
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;
namespace Analyzer {
class IAnalyzerOutputPaneAdapter;
class IAnalyzerEngine;
class AnalyzerRunControl;
class AbstractAnalyzerSubConfig;
......@@ -116,7 +116,7 @@ public:
/// Returns a new engine for the given start parameters.
/// Called each time the tool is launched.
virtual IAnalyzerEngine *createEngine(const AnalyzerStartParameters &sp,
virtual AnalyzerRunControl *createRunControl(const AnalyzerStartParameters &sp,
ProjectExplorer::RunConfiguration *runConfiguration = 0) = 0;
/// Returns true if the tool can be run
......
......@@ -33,7 +33,6 @@
#include "androidmanager.h"
#include <analyzerbase/ianalyzertool.h>
#include <analyzerbase/ianalyzerengine.h>
#include <analyzerbase/analyzermanager.h>
#include <analyzerbase/analyzerruncontrol.h>
#include <analyzerbase/analyzerstartparameters.h>
......@@ -63,6 +62,7 @@ RunControl *AndroidAnalyzeSupport::createAnalyzeRunControl(AndroidRunConfigurati
AnalyzerStartParameters params;
params.toolId = tool->id();
params.runMode = runMode;
Target *target = runConfig->target();
params.displayName = AndroidManager::packageName(target);
params.sysroot = SysRootKitInformation::sysRoot(target->kit()).toString();
......@@ -76,23 +76,21 @@ RunControl *AndroidAnalyzeSupport::createAnalyzeRunControl(AndroidRunConfigurati
params.startMode = StartQmlRemote;
}
AnalyzerRunControl * const analyzerRunControl = new AnalyzerRunControl(tool, params, runConfig);
new AndroidAnalyzeSupport(runConfig, analyzerRunControl);
AnalyzerRunControl *analyzerRunControl = tool->createRunControl(params, runConfig);
(void) new AndroidAnalyzeSupport(runConfig, analyzerRunControl);
return analyzerRunControl;
}
AndroidAnalyzeSupport::AndroidAnalyzeSupport(AndroidRunConfiguration *runConfig,
AnalyzerRunControl *runControl)
: AndroidRunSupport(runConfig, runControl),
m_engine(0),
m_runControl(0),
m_qmlPort(0)
{
if (runControl) {
m_engine = runControl->engine();
if (m_engine) {
connect(m_engine, SIGNAL(starting(const Analyzer::IAnalyzerEngine*)),
m_runner, SLOT(start()));
}
m_runControl = runControl;
connect(m_runControl, SIGNAL(starting(const Analyzer::AnalyzerRunControl*)),
m_runner, SLOT(start()));
}
connect(&m_outputParser, SIGNAL(waitingForConnectionOnPort(quint16)),
SLOT(remoteIsRunning()));
......@@ -115,8 +113,8 @@ void AndroidAnalyzeSupport::handleRemoteProcessStarted(int qmlPort)
void AndroidAnalyzeSupport::handleRemoteOutput(const QByteArray &output)
{
const QString msg = QString::fromUtf8(output);
if (m_engine)
m_engine->logApplicationMessage(msg, Utils::StdOutFormatSameLine);
if (m_runControl)
m_runControl->logApplicationMessage(msg, Utils::StdOutFormatSameLine);
else
AndroidRunSupport::handleRemoteOutput(output);
m_outputParser.processOutput(msg);
......@@ -124,16 +122,16 @@ void AndroidAnalyzeSupport::handleRemoteOutput(const QByteArray &output)
void AndroidAnalyzeSupport::handleRemoteErrorOutput(const QByteArray &output)
{
if (m_engine)
m_engine->logApplicationMessage(QString::fromUtf8(output), Utils::StdErrFormatSameLine);
if (m_runControl)
m_runControl->logApplicationMessage(QString::fromUtf8(output), Utils::StdErrFormatSameLine);
else
AndroidRunSupport::handleRemoteErrorOutput(output);
}
void AndroidAnalyzeSupport::remoteIsRunning()
{
if (m_engine)
m_engine->notifyRemoteSetupDone(m_qmlPort);
if (m_runControl)
m_runControl->notifyRemoteSetupDone(m_qmlPort);
}
} // namespace Internal
......
......@@ -33,10 +33,7 @@
#include "androidrunsupport.h"
#include <qmldebug/qmloutputparser.h>
namespace Analyzer {
class IAnalyzerEngine;
class AnalyzerRunControl;
}
namespace Analyzer { class AnalyzerRunControl; }
namespace ProjectExplorer { class RunControl; }
namespace Android {
......@@ -66,7 +63,7 @@ private slots:
void remoteIsRunning();
private:
Analyzer::IAnalyzerEngine *m_engine;
Analyzer::AnalyzerRunControl *m_runControl;
QmlDebug::QmlOutputParser m_outputParser;
int m_qmlPort;
};
......
......@@ -45,7 +45,7 @@ LocalQmlProfilerRunner *LocalQmlProfilerRunner::createLocalRunner(
RunConfiguration *runConfiguration,
const Analyzer::AnalyzerStartParameters &sp,
QString *errorMessage,
QmlProfilerEngine *engine)
QmlProfilerRunControl *engine)
{
QmlProjectManager::QmlProjectRunConfiguration *rc1 =
qobject_cast<QmlProjectManager::QmlProjectRunConfiguration *>(runConfiguration);
......@@ -81,7 +81,7 @@ LocalQmlProfilerRunner *LocalQmlProfilerRunner::createLocalRunner(
}
LocalQmlProfilerRunner::LocalQmlProfilerRunner(const Configuration &configuration,
QmlProfilerEngine *engine) :
QmlProfilerRunControl *engine) :
AbstractQmlProfilerRunner(engine),
m_configuration(configuration),
m_engine(engine)
......
......@@ -41,7 +41,7 @@ namespace Analyzer { class AnalyzerStartParameters; }
namespace QmlProfiler {
namespace Internal {
class QmlProfilerEngine;
class QmlProfilerRunControl;
class LocalQmlProfilerRunner : public AbstractQmlProfilerRunner
{
Q_OBJECT
......@@ -58,7 +58,7 @@ public:
static LocalQmlProfilerRunner *createLocalRunner(ProjectExplorer::RunConfiguration *runConfiguration,
const Analyzer::AnalyzerStartParameters &sp,
QString *errorMessage,
QmlProfilerEngine *engine);
QmlProfilerRunControl *engine);
~LocalQmlProfilerRunner();
......@@ -71,12 +71,12 @@ private slots:
void spontaneousStop(int exitCode);
private:
LocalQmlProfilerRunner(const Configuration &configuration, QmlProfilerEngine *engine);
LocalQmlProfilerRunner(const Configuration &configuration, QmlProfilerRunControl *engine);
private:
Configuration m_configuration;
ProjectExplorer::ApplicationLauncher m_launcher;
QmlProfilerEngine *m_engine;
QmlProfilerRunControl *m_engine;
};