From db9437c2e83ec11befa855e4806ac7920d1a5800 Mon Sep 17 00:00:00 2001 From: hjk Date: Fri, 3 Jun 2016 19:11:29 +0200 Subject: [PATCH] Generalize IDevice::qmlProfilerHost The idea is to have a way for tools to specify what kind of control channel they would like to use to communicate with a device without making the choice explicit dependent on the exact kind of tool to further decouple device and tool implementations. The 'hint' values are there to help the device implementation to decide on which channel to use exactly in case there are multiple choices. In any case, the tool is responsible to check that the returned channel is suitable for its operation. Currently the only choice is "QmlControlChannel" yielding a simple wrapper around the former IDevice::qmlProfilerHost() return value. Other enum values may potentially be {Tcp,LocalSocket}ControlChannel (to specify a type of transport) AdbChannel (to specify some generic helper mechanism). It might also turn out that something more complex than an enum will be needed, e.g. to express a set of values with priorities or such, but I'd rather avoid overengineering for now. Change-Id: Id386425eb3dd2bb395065f0bdb6f67217cd40a71 Reviewed-by: Ulf Hermann --- src/plugins/android/androiddevice.cpp | 6 ++++-- src/plugins/android/androiddevice.h | 2 +- src/plugins/debugger/debuggerplugin.cpp | 4 +++- .../devicesupport/desktopdevice.cpp | 6 ++++-- .../devicesupport/desktopdevice.h | 2 +- .../projectexplorer/devicesupport/idevice.cpp | 5 +++-- .../projectexplorer/devicesupport/idevice.h | 16 ++++++++++++++-- src/plugins/qmlprofiler/qmlprofilertool.cpp | 4 +++- 8 files changed, 33 insertions(+), 12 deletions(-) diff --git a/src/plugins/android/androiddevice.cpp b/src/plugins/android/androiddevice.cpp index 6f9b11ba1d3..6bad5d22827 100644 --- a/src/plugins/android/androiddevice.cpp +++ b/src/plugins/android/androiddevice.cpp @@ -27,6 +27,8 @@ #include "androidconstants.h" #include "androidsignaloperation.h" +#include + #include using namespace ProjectExplorer; @@ -96,9 +98,9 @@ IDevice::Ptr AndroidDevice::clone() const return IDevice::Ptr(new AndroidDevice(*this)); } -QString AndroidDevice::qmlProfilerHost() const +Connection AndroidDevice::toolControlChannel(const ControlChannelHint &) const { - return QLatin1String("localhost"); + return HostName("localhost"); } } // namespace Internal diff --git a/src/plugins/android/androiddevice.h b/src/plugins/android/androiddevice.h index b9dfe6ea70a..f050b445373 100644 --- a/src/plugins/android/androiddevice.h +++ b/src/plugins/android/androiddevice.h @@ -46,7 +46,7 @@ public: ProjectExplorer::DeviceProcessSignalOperation::Ptr signalOperation() const override; ProjectExplorer::IDevice::Ptr clone() const override; - QString qmlProfilerHost() const override; + ProjectExplorer::Connection toolControlChannel(const ControlChannelHint &) const override; protected: friend class AndroidDeviceFactory; diff --git a/src/plugins/debugger/debuggerplugin.cpp b/src/plugins/debugger/debuggerplugin.cpp index 03e424b803f..3bfa4f9771c 100644 --- a/src/plugins/debugger/debuggerplugin.cpp +++ b/src/plugins/debugger/debuggerplugin.cpp @@ -2156,7 +2156,9 @@ void DebuggerPluginPrivate::attachToQmlPort() IDevice::ConstPtr device = DeviceKitInformation::device(kit); if (device) { rp.connParams = device->sshParameters(); - rp.qmlServerAddress = device->qmlProfilerHost(); + Connection toolControl = device->toolControlChannel(IDevice::QmlControlChannel); + QTC_ASSERT(toolControl.is(), return); + rp.qmlServerAddress = toolControl.as().host(); } rp.qmlServerPort = Utils::Port(dlg.port()); rp.startMode = AttachToRemoteProcess; diff --git a/src/plugins/projectexplorer/devicesupport/desktopdevice.cpp b/src/plugins/projectexplorer/devicesupport/desktopdevice.cpp index 71ecf037d54..0b305b9818c 100644 --- a/src/plugins/projectexplorer/devicesupport/desktopdevice.cpp +++ b/src/plugins/projectexplorer/devicesupport/desktopdevice.cpp @@ -29,7 +29,9 @@ #include "localprocesslist.h" #include "desktopdeviceconfigurationwidget.h" #include "desktopprocesssignaloperation.h" + #include +#include #include @@ -134,9 +136,9 @@ DeviceEnvironmentFetcher::Ptr DesktopDevice::environmentFetcher() const return DeviceEnvironmentFetcher::Ptr(new DesktopDeviceEnvironmentFetcher()); } -QString DesktopDevice::qmlProfilerHost() const +Connection DesktopDevice::toolControlChannel(const ControlChannelHint &) const { - return QLatin1String("localhost"); + return HostName("localhost"); } IDevice::Ptr DesktopDevice::clone() const diff --git a/src/plugins/projectexplorer/devicesupport/desktopdevice.h b/src/plugins/projectexplorer/devicesupport/desktopdevice.h index b99d83457de..752bd20075f 100644 --- a/src/plugins/projectexplorer/devicesupport/desktopdevice.h +++ b/src/plugins/projectexplorer/devicesupport/desktopdevice.h @@ -52,7 +52,7 @@ public: DeviceProcess *createProcess(QObject *parent) const override; DeviceProcessSignalOperation::Ptr signalOperation() const override; DeviceEnvironmentFetcher::Ptr environmentFetcher() const override; - QString qmlProfilerHost() const override; + Connection toolControlChannel(const ControlChannelHint &) const override; IDevice::Ptr clone() const override; diff --git a/src/plugins/projectexplorer/devicesupport/idevice.cpp b/src/plugins/projectexplorer/devicesupport/idevice.cpp index b48a6b51eca..691bfbfe2d4 100644 --- a/src/plugins/projectexplorer/devicesupport/idevice.cpp +++ b/src/plugins/projectexplorer/devicesupport/idevice.cpp @@ -30,6 +30,7 @@ #include "../kit.h" #include "../kitinformation.h" +#include "../runconfiguration.h" #include #include @@ -407,9 +408,9 @@ void IDevice::setSshParameters(const QSsh::SshConnectionParameters &sshParameter d->sshParameters.hostKeyDatabase = DeviceManager::instance()->hostKeyDatabase(); } -QString IDevice::qmlProfilerHost() const +Connection IDevice::toolControlChannel(const ControlChannelHint &) const { - return d->sshParameters.host; + return HostName(d->sshParameters.host); } void IDevice::setFreePorts(const Utils::PortList &freePorts) diff --git a/src/plugins/projectexplorer/devicesupport/idevice.h b/src/plugins/projectexplorer/devicesupport/idevice.h index ff30c66cf1d..c5043e8a3b3 100644 --- a/src/plugins/projectexplorer/devicesupport/idevice.h +++ b/src/plugins/projectexplorer/devicesupport/idevice.h @@ -48,9 +48,10 @@ class Port; } // Utils namespace ProjectExplorer { + +class Connection; class DeviceProcess; class DeviceProcessList; - class Kit; namespace Internal { class IDevicePrivate; } @@ -107,6 +108,16 @@ public: virtual QList usedPorts(const QByteArray &commandOutput) const = 0; }; +class PROJECTEXPLORER_EXPORT HostName +{ +public: + explicit HostName(const QString &host) : m_host(host) {} + QString host() const { return m_host; } + +private: + QString m_host; +}; + // See cpp file for documentation. class PROJECTEXPLORER_EXPORT IDevice { @@ -178,7 +189,8 @@ public: QSsh::SshConnectionParameters sshParameters() const; void setSshParameters(const QSsh::SshConnectionParameters &sshParameters); - virtual QString qmlProfilerHost() const; + enum ControlChannelHint { QmlControlChannel }; + virtual Connection toolControlChannel(const ControlChannelHint &) const; Utils::PortList freePorts() const; void setFreePorts(const Utils::PortList &freePorts); diff --git a/src/plugins/qmlprofiler/qmlprofilertool.cpp b/src/plugins/qmlprofiler/qmlprofilertool.cpp index 8e793b75996..3427b9a522e 100644 --- a/src/plugins/qmlprofiler/qmlprofilertool.cpp +++ b/src/plugins/qmlprofiler/qmlprofilertool.cpp @@ -562,8 +562,10 @@ void QmlProfilerTool::startRemoteTool(ProjectExplorer::RunConfiguration *rc) IDevice::ConstPtr device = DeviceKitInformation::device(kit); if (device) { + Connection toolControl = device->toolControlChannel(IDevice::QmlControlChannel); + QTC_ASSERT(toolControl.is(), return); + connection.analyzerHost = toolControl.as().host(); connection.connParams = device->sshParameters(); - connection.analyzerHost = device->qmlProfilerHost(); } connection.analyzerPort = Utils::Port(port);