Commit 99d9f065 authored by hjk's avatar hjk Committed by hjk

analyzer: refactoring of analyzer manager

Change-Id: I60268b8bc86e439beb3fca8f4b6a87ea03925bad
Reviewed-on: http://codereview.qt.nokia.com/1049Reviewed-by: default avatarhjk <qthjk@ovi.com>
parent 343ac579
......@@ -61,6 +61,9 @@ const char * const START = "Analyzer.Start";
const char * const STARTREMOTE = "Analyzer.StartRemote";
const char * const STOP = "Analyzer.Stop";
const char * const G_ANALYZER_TOOLS = "Menu.Group.Analyzer.Tools";
const char * const G_ANALYZER_REMOTE_TOOLS = "Menu.Group.Analyzer.RemoteTools";
// options dialog
const char * const ANALYZER_SETTINGS_CATEGORY = "T.Analyzer";
const char * const ANALYZER_SETTINGS_TR_CATEGORY =
......
......@@ -48,10 +48,6 @@ namespace Utils {
class FancyMainWindow;
}
namespace ProjectExplorer {
class RunConfiguration;
}
namespace Analyzer {
class IAnalyzerTool;
class IAnalyzerEngine;
......@@ -65,37 +61,39 @@ public:
explicit AnalyzerManager(QObject *parent = 0);
~AnalyzerManager();
static AnalyzerManager *instance();
void registerRunControlFactory(ProjectExplorer::IRunControlFactory *factory);
static void registerRunControlFactory(ProjectExplorer::IRunControlFactory *factory);
void extensionsInitialized();
void shutdown();
/**
* Register a tool and initialize it.
*/
void addTool(Analyzer::IAnalyzerTool *tool);
static ProjectExplorer::RunControl *createRunControl
(ProjectExplorer::RunConfiguration *runConfiguration, const QString &mode);
// Register a tool and initialize it.
static void addTool(Analyzer::IAnalyzerTool *tool);
static IAnalyzerTool *toolById(const QByteArray &id);
// Dockwidgets are registered to the main window.
QDockWidget *createDockWidget(IAnalyzerTool *tool, const QString &title,
static QDockWidget *createDockWidget(IAnalyzerTool *tool, const QString &title,
QWidget *widget, Qt::DockWidgetArea area = Qt::TopDockWidgetArea);
Utils::FancyMainWindow *mainWindow() const;
static Utils::FancyMainWindow *mainWindow();
static void showMode();
static void selectTool(IAnalyzerTool *tool);
static void startTool(IAnalyzerTool *tool);
static void stopTool(IAnalyzerTool *tool);
void showMode();
void selectTool(IAnalyzerTool *tool);
void startTool(IAnalyzerTool *tool);
void stopTool();
// Convienience functions.
static void startLocalTool(IAnalyzerTool *tool);
static void startRemoteTool(IAnalyzerTool *tool);
static QString msgToolStarted(const QString &name);
static QString msgToolFinished(const QString &name, int issuesFound);
IAnalyzerEngine *createEngine(const AnalyzerStartParameters &sp,
ProjectExplorer::RunConfiguration *runConfiguration);
static void showStatusMessage(const QString &message, int timeoutMS = 10000);
static void showPermanentStatusMessage(const QString &message);
public slots:
void showStatusMessage(const QString &message, int timeoutMS = 10000);
void showPermanentStatusMessage(const QString &message);
static void handleToolFinished(IAnalyzerTool *tool);
private:
class AnalyzerManagerPrivate;
......
......@@ -47,6 +47,7 @@
#include <coreplugin/ioutputpane.h>
#include <QtCore/QDebug>
#include <QtCore/QTimer>
using namespace Analyzer;
......@@ -67,12 +68,12 @@ AnalyzerRunControl::Private::Private()
// AnalyzerRunControl ////////////////////////////////////////////////////
AnalyzerRunControl::AnalyzerRunControl(const AnalyzerStartParameters &sp,
RunConfiguration *runConfiguration)
AnalyzerRunControl::AnalyzerRunControl(IAnalyzerTool *tool,
const AnalyzerStartParameters &sp, RunConfiguration *runConfiguration)
: RunControl(runConfiguration, Constants::MODE_ANALYZE),
d(new Private)
{
d->m_engine = AnalyzerManager::instance()->createEngine(sp, runConfiguration);
d->m_engine = tool->createEngine(sp, runConfiguration);
if (!d->m_engine)
return;
......@@ -83,6 +84,7 @@ AnalyzerRunControl::AnalyzerRunControl(const AnalyzerStartParameters &sp,
SLOT(addTask(ProjectExplorer::Task::TaskType,QString,QString,int)));
connect(d->m_engine, SIGNAL(finished()),
SLOT(engineFinished()));
connect(this, SIGNAL(finished()), SLOT(runControlFinished()), Qt::QueuedConnection);
}
AnalyzerRunControl::~AnalyzerRunControl()
......@@ -127,6 +129,11 @@ void AnalyzerRunControl::engineFinished()
emit finished();
}
void AnalyzerRunControl::runControlFinished()
{
AnalyzerManager::handleToolFinished(d->m_engine->tool());
}
bool AnalyzerRunControl::isRunning() const
{
return d->m_isRunning;
......
......@@ -45,6 +45,7 @@
namespace Analyzer {
class AnalyzerStartParameters;
class IAnalyzerTool;
class ANALYZER_EXPORT AnalyzerRunControl: public ProjectExplorer::RunControl
{
......@@ -52,8 +53,8 @@ class ANALYZER_EXPORT AnalyzerRunControl: public ProjectExplorer::RunControl
public:
typedef ProjectExplorer::RunConfiguration RunConfiguration;
// the constructor is likely to gain more arguments later
explicit AnalyzerRunControl(const AnalyzerStartParameters &sp, RunConfiguration *runConfiguration);
AnalyzerRunControl(IAnalyzerTool *tool, const AnalyzerStartParameters &sp,
RunConfiguration *runConfiguration);
~AnalyzerRunControl();
// pure virtuals from ProjectExplorer::RunControl
......@@ -70,6 +71,7 @@ private slots:
const QString &file, int line);
void engineFinished();
void runControlFinished();
private:
class Private;
......
......@@ -33,59 +33,25 @@
#include "analyzerruncontrolfactory.h"
#include "analyzerruncontrol.h"
#include "analyzerconstants.h"
#include "analyzermanager.h"
#include "analyzerrunconfigwidget.h"
#include "analyzersettings.h"
#include "analyzerstartparameters.h"
#include <utils/qtcassert.h>
#include <projectexplorer/applicationrunconfiguration.h>
#include <remotelinux/linuxdeviceconfiguration.h>
#include <remotelinux/remotelinuxrunconfiguration.h>
#include <utils/qtcassert.h>
#include <QtCore/QDebug>
using namespace Analyzer;
using namespace Analyzer::Internal;
AnalyzerStartParameters localStartParameters(ProjectExplorer::RunConfiguration *runConfiguration)
{
AnalyzerStartParameters sp;
QTC_ASSERT(runConfiguration, return sp);
ProjectExplorer::LocalApplicationRunConfiguration *rc =
qobject_cast<ProjectExplorer::LocalApplicationRunConfiguration *>(runConfiguration);
QTC_ASSERT(rc, return sp);
sp.startMode = StartLocal;
sp.environment = rc->environment();
sp.workingDirectory = rc->workingDirectory();
sp.debuggee = rc->executable();
sp.debuggeeArgs = rc->commandLineArguments();
sp.displayName = rc->displayName();
sp.connParams.host = QLatin1String("localhost");
sp.connParams.port = rc->qmlDebugServerPort();
return sp;
}
AnalyzerStartParameters remoteLinuxStartParameters(ProjectExplorer::RunConfiguration *runConfiguration)
{
AnalyzerStartParameters sp;
RemoteLinux::RemoteLinuxRunConfiguration * const rc
= qobject_cast<RemoteLinux::RemoteLinuxRunConfiguration *>(runConfiguration);
QTC_ASSERT(rc, return sp);
/////////////////////////////////////////////////////////////////////////////////
//
// AnalyzerRunControlFactory
//
/////////////////////////////////////////////////////////////////////////////////
sp.debuggee = rc->remoteExecutableFilePath();
sp.debuggeeArgs = rc->arguments();
sp.connParams = rc->deviceConfig()->sshParameters();
sp.analyzerCmdPrefix = rc->commandPrefix();
sp.startMode = StartRemote;
sp.displayName = rc->displayName();
return sp;
}
// AnalyzerRunControlFactory ////////////////////////////////////////////////////
AnalyzerRunControlFactory::AnalyzerRunControlFactory(QObject *parent)
: IRunControlFactory(parent)
{
......@@ -100,26 +66,7 @@ ProjectExplorer::RunControl *AnalyzerRunControlFactory::create(RunConfiguration
const QString &mode)
{
QTC_ASSERT(canRun(runConfiguration, mode), return 0);
AnalyzerStartParameters sp;
if (qobject_cast<ProjectExplorer::LocalApplicationRunConfiguration *>(runConfiguration)) {
sp = localStartParameters(runConfiguration);
} else if (qobject_cast<RemoteLinux::RemoteLinuxRunConfiguration *>(runConfiguration)) {
sp = remoteLinuxStartParameters(runConfiguration);
} else {
// might be S60DeviceRunfiguration, or something else ...
sp.startMode = StartRemote;
}
return create(sp, runConfiguration);
}
AnalyzerRunControl *AnalyzerRunControlFactory::create(const AnalyzerStartParameters &sp,
RunConfiguration *runConfiguration)
{
AnalyzerRunControl *rc = new AnalyzerRunControl(sp, runConfiguration);
emit runControlCreated(rc);
return rc;
return AnalyzerManager::createRunControl(runConfiguration, mode);
}
QString AnalyzerRunControlFactory::displayName() const
......
......@@ -39,6 +39,7 @@ namespace Analyzer {
class AnalyzerRunControl;
class AnalyzerStartParameters;
class IAnalyzerTool;
namespace Internal {
......@@ -52,10 +53,9 @@ public:
typedef ProjectExplorer::RunConfiguration RunConfiguration;
typedef ProjectExplorer::RunControl RunControl;
// virtuals from IRunControlFactory
// IRunControlFactory
bool canRun(RunConfiguration *runConfiguration, const QString &mode) const;
RunControl *create(RunConfiguration *runConfiguration, const QString &mode);
AnalyzerRunControl *create(const AnalyzerStartParameters &sp, RunConfiguration *rc = 0);
QString displayName() const;
ProjectExplorer::IRunConfigurationAspect *createRunConfigurationAspect();
......
......@@ -57,6 +57,7 @@ public:
AnalyzerStartMode startMode;
Utils::SshConnectionParameters connParams;
QByteArray toolId;
QString debuggee;
QString debuggeeArgs;
QString analyzerCmdPrefix;
......
......@@ -36,21 +36,12 @@
namespace Analyzer {
IAnalyzerEngine::IAnalyzerEngine(const AnalyzerStartParameters &sp,
ProjectExplorer::RunConfiguration *runConfiguration)
: m_runConfig(runConfiguration)
, m_sp(sp)
IAnalyzerEngine::IAnalyzerEngine(IAnalyzerTool *tool, const AnalyzerStartParameters &sp,
ProjectExplorer::RunConfiguration *runConfiguration)
{
}
ProjectExplorer::RunConfiguration *IAnalyzerEngine::runConfiguration() const
{
return m_runConfig;
}
AnalyzerStartParameters IAnalyzerEngine::startParameters() const
{
return m_sp;
m_runConfig = runConfiguration;
m_sp = sp;
m_tool = tool;
}
} // namespace Analyzer
......@@ -51,6 +51,8 @@ class RunConfiguration;
namespace Analyzer {
class IAnalyzerTool;
/**
* An IAnalyzerEngine instance handles the launch of an analyzation tool.
*
......@@ -61,40 +63,44 @@ class ANALYZER_EXPORT IAnalyzerEngine : public QObject
Q_OBJECT
public:
explicit IAnalyzerEngine(const AnalyzerStartParameters &sp,
IAnalyzerEngine(IAnalyzerTool *tool, const AnalyzerStartParameters &sp,
ProjectExplorer::RunConfiguration *runConfiguration = 0);
/// start analyzation process
/// Start analyzation process.
virtual void start() = 0;
/// trigger async stop of the analyzation process
/// Trigger async stop of the analyzation process.
virtual void stop() = 0;
/// controller actions
/// 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;
/// 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; }
/// the start parameters for this engine
AnalyzerStartParameters startParameters() const;
/// The tool this engine is associated with.
IAnalyzerTool *tool() { return m_tool; }
signals:
/// should be emitted when the debuggee outputted something
/// 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
/// 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
/// Must be emitted when the engine finished.
void finished();
/// must be emitted when the engine is starting
/// Must be emitted when the engine is starting.
void starting(const Analyzer::IAnalyzerEngine *);
private:
ProjectExplorer::RunConfiguration *m_runConfig;
AnalyzerStartParameters m_sp;
IAnalyzerTool *m_tool;
};
} // namespace Analyzer
......
......@@ -67,11 +67,13 @@ public:
explicit IAnalyzerTool(QObject *parent = 0);
/// Returns a unique ID for this tool.
virtual QString id() const = 0;
virtual QByteArray id() const = 0;
/// Returns a short user readable display name for this tool.
virtual QString displayName() const = 0;
/// Returns a user readable description name for this tool.
virtual QString description() const = 0;
/// Returns the name of the menu group of the start action.
virtual QByteArray menuGroup() const = 0;
/**
* The mode in which this tool should preferably be run
......@@ -89,11 +91,6 @@ public:
static QString modeString(ToolMode mode);
/**
* The implementation should setup widgets for the output pane here and
* optionally add dock widgets in the analyzation mode if wanted.
*/
virtual void initialize() = 0;
/// This gets called after all analyzation tools where initialized.
virtual void extensionsInitialized() = 0;
......@@ -112,11 +109,8 @@ public:
virtual IAnalyzerEngine *createEngine(const AnalyzerStartParameters &sp,
ProjectExplorer::RunConfiguration *runConfiguration = 0) = 0;
/// Returns true when this tool can be run on the loca machine.
virtual bool canRunLocally() const = 0;
/// Returns true when this tool can be run on a remote machine.
virtual bool canRunRemotely() const = 0;
/// Starts the tool.
virtual void startTool() = 0;
/// Called when tools gets selected.
virtual void toolSelected() const {}
......
......@@ -50,6 +50,8 @@
#include <QtGui/QMainWindow>
#include <QtGui/QMessageBox>
using namespace Analyzer;
namespace QmlProfiler {
namespace Internal {
......@@ -65,12 +67,12 @@ public:
bool attach(const QString &address, uint port);
static AbstractQmlProfilerRunner *createRunner(ProjectExplorer::RunConfiguration *runConfiguration,
const Analyzer::AnalyzerStartParameters &m_params,
const AnalyzerStartParameters &m_params,
QObject *parent);
QmlProfilerEngine *q;
Analyzer::AnalyzerStartParameters m_params;
AnalyzerStartParameters m_params;
AbstractQmlProfilerRunner *m_runner;
bool m_running;
bool m_fetchingData;
......@@ -79,11 +81,11 @@ public:
AbstractQmlProfilerRunner *
QmlProfilerEngine::QmlProfilerEnginePrivate::createRunner(ProjectExplorer::RunConfiguration *configuration,
const Analyzer::AnalyzerStartParameters &m_params,
const AnalyzerStartParameters &m_params,
QObject *parent)
{
AbstractQmlProfilerRunner *runner = 0;
if (m_params.startMode == Analyzer::StartLocal) {
if (m_params.startMode == StartLocal) {
LocalQmlProfilerRunner::Configuration configuration;
configuration.executable = m_params.debuggee;
configuration.executableArguments = m_params.debuggeeArgs;
......@@ -92,7 +94,7 @@ QmlProfilerEngine::QmlProfilerEnginePrivate::createRunner(ProjectExplorer::RunCo
configuration.port = m_params.connParams.port;
runner = new LocalQmlProfilerRunner(configuration, parent);
} else if (m_params.startMode == Analyzer::StartRemote) {
} else if (m_params.startMode == StartRemote) {
if (Qt4ProjectManager::S60DeviceRunConfiguration *s60Config
= qobject_cast<Qt4ProjectManager::S60DeviceRunConfiguration*>(configuration)) {
runner = new CodaQmlProfilerRunner(s60Config, parent);
......@@ -108,9 +110,9 @@ QmlProfilerEngine::QmlProfilerEnginePrivate::createRunner(ProjectExplorer::RunCo
// QmlProfilerEngine
//
QmlProfilerEngine::QmlProfilerEngine(const Analyzer::AnalyzerStartParameters &sp,
ProjectExplorer::RunConfiguration *runConfiguration)
: IAnalyzerEngine(sp, runConfiguration)
QmlProfilerEngine::QmlProfilerEngine(IAnalyzerTool *tool, const AnalyzerStartParameters &sp,
ProjectExplorer::RunConfiguration *runConfiguration)
: IAnalyzerEngine(tool, sp, runConfiguration)
, d(new QmlProfilerEnginePrivate(this))
{
d->m_params = sp;
......@@ -157,7 +159,7 @@ void QmlProfilerEngine::stop()
void QmlProfilerEngine::stopped()
{
d->m_running = false;
Analyzer::AnalyzerManager::instance()->stopTool();
AnalyzerManager::stopTool(tool());
emit finished();
}
......
......@@ -43,9 +43,10 @@ namespace Internal {
class QmlProfilerEngine : public Analyzer::IAnalyzerEngine
{
Q_OBJECT
public:
explicit QmlProfilerEngine(const Analyzer::AnalyzerStartParameters &sp,
ProjectExplorer::RunConfiguration *runConfiguration);
QmlProfilerEngine(Analyzer::IAnalyzerTool *tool, const Analyzer::AnalyzerStartParameters &sp,
ProjectExplorer::RunConfiguration *runConfiguration);
~QmlProfilerEngine();
signals:
......
......@@ -32,98 +32,59 @@
**************************************************************************/
#include "qmlprofilerplugin.h"
#include "qmlprofilerconstants.h"
#include "qmlprojectanalyzerruncontrolfactory.h"
#include <coreplugin/icore.h>
#include <coreplugin/icontext.h>
#include <coreplugin/actionmanager/actionmanager.h>
#include <coreplugin/actionmanager/command.h>
#include <coreplugin/actionmanager/actioncontainer.h>
#include <coreplugin/coreconstants.h>
#include "qmlprofilertool.h"
#include "qmlprojectanalyzerruncontrolfactory.h"
#include <analyzerbase/analyzermanager.h>
#include <QtGui/QAction>
#include <QtGui/QMessageBox>
#include <QtGui/QMainWindow>
#include <QtGui/QMenu>
#include <QtCore/QtPlugin>
#include "qmlprofilertool.h"
using namespace Analyzer;
using namespace QmlProfiler::Internal;
QmlProfilerPlugin *QmlProfilerPlugin::m_instance = 0;
bool QmlProfilerPlugin::debugOutput = false;
class QmlProfilerPlugin::QmlProfilerPluginPrivate
{
public:
QmlProfilerPluginPrivate(QmlProfilerPlugin *qq):
q(qq)
{}
void initialize(const QStringList &arguments, QString *errorString);
QmlProjectAnalyzerRunControlFactory *m_runControlFactory;
QmlProfilerPlugin *q;
};
void QmlProfilerPlugin::QmlProfilerPluginPrivate::initialize(const QStringList &arguments, QString *errorString)
{
Q_UNUSED(arguments)
Q_UNUSED(errorString)
m_runControlFactory = new QmlProjectAnalyzerRunControlFactory();
Analyzer::AnalyzerManager::instance()->registerRunControlFactory(m_runControlFactory);
}
QmlProfilerPlugin::QmlProfilerPlugin()
: d(new QmlProfilerPluginPrivate(this))
{
m_instance = this;
}
: d(new QmlProfilerPluginPrivate())
{}
QmlProfilerPlugin::~QmlProfilerPlugin()
{
delete d;
m_instance = 0;
}
bool QmlProfilerPlugin::initialize(const QStringList &arguments, QString *errorString)
{
d->initialize(arguments, errorString);
AnalyzerManager::instance()->addTool(new QmlProfilerTool(this));
Q_UNUSED(arguments)
Q_UNUSED(errorString)
d->m_runControlFactory = new QmlProjectAnalyzerRunControlFactory();
AnalyzerManager::registerRunControlFactory(d->m_runControlFactory);
AnalyzerManager::addTool(new QmlProfilerTool(true, this));
AnalyzerManager::addTool(new QmlProfilerTool(false, this));
return true;
}
void QmlProfilerPlugin::extensionsInitialized()
{
// Retrieve objects from the plugin manager's object pool
// Retrieve objects from the plugin manager's object pool.
// "In the extensionsInitialized method, a plugin can be sure that all
// plugins that depend on it are completely initialized."
}
ExtensionSystem::IPlugin::ShutdownFlag QmlProfilerPlugin::aboutToShutdown()
{
// Save settings
// Save settings.
// Disconnect from signals that are not needed during shutdown
// Hide UI (if you add UI that is not in the main window directly)
return SynchronousShutdown;
}
QmlProfilerPlugin *QmlProfilerPlugin::instance()
{
return m_instance;
}
Q_EXPORT_PLUGIN(QmlProfilerPlugin)
......@@ -46,8 +46,6 @@ class QmlProfilerPlugin : public ExtensionSystem::IPlugin
Q_OBJECT
public:
static QmlProfilerPlugin *instance();
QmlProfilerPlugin();
~QmlProfilerPlugin();
......@@ -60,8 +58,6 @@ public:
private:
class QmlProfilerPluginPrivate;
QmlProfilerPluginPrivate *d;
static QmlProfilerPlugin *m_instance;
};
} // namespace Internal
......
......@@ -92,6 +92,7 @@ public:
QmlProfilerTool *q;
bool m_local;
QDeclarativeDebugConnection *m_client;
QTimer m_connectionTimer;
int m_connectionAttempts;
......@@ -118,9 +119,10 @@ public:
QString m_ostDevice;
};
QmlProfilerTool::QmlProfilerTool(QObject *parent)
QmlProfilerTool::QmlProfilerTool(bool local, QObject *parent)
: IAnalyzerTool(parent), d(new QmlProfilerToolPrivate(this))
{
d->m_local = local;
d->m_client = 0;
d->m_connectionAttempts = 0;
d->m_traceWindow = 0;
......@@ -132,6 +134,13 @@ QmlProfilerTool::QmlProfilerTool(QObject *parent)
d->m_connectionTimer.setInterval(200);
connect(&d->m_connectionTimer, SIGNAL(timeout()), SLOT(tryToConnect()));
qmlRegisterType<Canvas>("Monitor", 1, 0, "Canvas");
qmlRegisterType<TiledCanvas>("Monitor", 1, 0, "TiledCanvas");
qmlRegisterType<Context2D>();
qmlRegisterType<CanvasImage>();
qmlRegisterType<CanvasGradient>();
qmlRegisterType<TimelineView>("Monitor", 1, 0,"TimelineView");
}
QmlProfilerTool::~QmlProfilerTool()
......@@ -140,14 +149,26 @@ QmlProfilerTool::~QmlProfilerTool()
delete d;
}
QString QmlProfilerTool::id() const
QByteArray QmlProfilerTool::id() const
{
return "QmlProfiler";
return d->m_local ? "QmlLocalProfiler" : "QmlRemoteProfiler";
}