Commit f82bb1ec authored by hjk's avatar hjk

ProjectExplorer: Remove Connection as concept

It turns out that one "Connection" per RunControl doesn't map
well to the uses we have. Instead, RunWorkers need to know
individually how to connect to the place where they can work,
but they are already specific enough to be able to use a
standard class (like QUrl) as their way to specify the needed
entry point.

In theory one could see a RunControl's connection as an
aggregation of its workers connection bits, but that does
not really seem to be needed in code.

As consequence, replace UrlConnection by a plain QUrl, and also
the HostName connection by a QUrl with hostName set.

Change-Id: I40c97e37779314ac0a77041e864a18eadb78f987
Reviewed-by: Vikas Pachdha's avatarVikas Pachdha <vikas.pachdha@qt.io>
parent 72775ab8
......@@ -104,9 +104,11 @@ IDevice::Ptr AndroidDevice::clone() const
return IDevice::Ptr(new AndroidDevice(*this));
}
Connection AndroidDevice::toolControlChannel(const ControlChannelHint &) const
QUrl AndroidDevice::toolControlChannel(const ControlChannelHint &) const
{
return HostName("localhost");
QUrl url;
url.setHost("localhost");
return url;
}
} // namespace Internal
......
......@@ -47,7 +47,7 @@ public:
Utils::OsType osType() const override;
ProjectExplorer::IDevice::Ptr clone() const override;
ProjectExplorer::Connection toolControlChannel(const ControlChannelHint &) const override;
QUrl toolControlChannel(const ControlChannelHint &) const override;
protected:
friend class AndroidDeviceFactory;
......
......@@ -2179,9 +2179,8 @@ void DebuggerPluginPrivate::attachToQmlPort()
if (device) {
QSsh::SshConnectionParameters sshParameters = device->sshParameters();
rp.remoteChannel = QString("%1:%2").arg(sshParameters.host).arg(sshParameters.port);
Connection toolControl = device->toolControlChannel(IDevice::QmlControlChannel);
QTC_ASSERT(toolControl.is<HostName>(), return);
rp.qmlServer.host = toolControl.as<HostName>().host();
QUrl toolControl = device->toolControlChannel(IDevice::QmlControlChannel);
rp.qmlServer.host = toolControl.host();
}
rp.qmlServer.port = Utils::Port(dlg.port());
rp.startMode = AttachToRemoteProcess;
......
......@@ -382,7 +382,7 @@ IosQmlProfilerSupport::IosQmlProfilerSupport(RunControl *runControl)
void IosQmlProfilerSupport::start()
{
UrlConnection serverUrl;
QUrl serverUrl;
QTcpServer server;
QTC_ASSERT(server.listen(QHostAddress::LocalHost)
|| server.listen(QHostAddress::LocalHostIPv6), return);
......
......@@ -137,9 +137,11 @@ DeviceEnvironmentFetcher::Ptr DesktopDevice::environmentFetcher() const
return DeviceEnvironmentFetcher::Ptr(new DesktopDeviceEnvironmentFetcher());
}
Connection DesktopDevice::toolControlChannel(const ControlChannelHint &) const
QUrl DesktopDevice::toolControlChannel(const ControlChannelHint &) const
{
return HostName("localhost");
QUrl url;
url.setHost("localhost");
return url;
}
Utils::OsType DesktopDevice::osType() const
......
......@@ -52,7 +52,7 @@ public:
DeviceProcess *createProcess(QObject *parent) const override;
DeviceProcessSignalOperation::Ptr signalOperation() const override;
DeviceEnvironmentFetcher::Ptr environmentFetcher() const override;
Connection toolControlChannel(const ControlChannelHint &) const override;
QUrl toolControlChannel(const ControlChannelHint &) const override;
Utils::OsType osType() const override;
IDevice::Ptr clone() const override;
......
......@@ -411,9 +411,11 @@ void IDevice::setSshParameters(const QSsh::SshConnectionParameters &sshParameter
d->sshParameters.hostKeyDatabase = DeviceManager::instance()->hostKeyDatabase();
}
Connection IDevice::toolControlChannel(const ControlChannelHint &) const
QUrl IDevice::toolControlChannel(const ControlChannelHint &) const
{
return HostName(d->sshParameters.host);
QUrl url;
url.setHost(d->sshParameters.host);
return url;
}
void IDevice::setFreePorts(const Utils::PortList &freePorts)
......@@ -470,8 +472,4 @@ DeviceEnvironmentFetcher::DeviceEnvironmentFetcher()
{
}
void *HostName::staticTypeId = &HostName::staticTypeId;
void *UrlConnection::staticTypeId = &UrlConnection::staticTypeId;
} // namespace ProjectExplorer
......@@ -189,7 +189,7 @@ public:
void setSshParameters(const QSsh::SshConnectionParameters &sshParameters);
enum ControlChannelHint { QmlControlChannel };
virtual Connection toolControlChannel(const ControlChannelHint &) const;
virtual QUrl toolControlChannel(const ControlChannelHint &) const;
Utils::PortList freePorts() const;
void setFreePorts(const Utils::PortList &freePorts);
......
......@@ -688,7 +688,6 @@ public:
QString displayName;
Runnable runnable;
IDevice::ConstPtr device;
Connection connection;
Core::Id runMode;
Utils::Icon icon;
const QPointer<RunConfiguration> runConfiguration; // Not owned.
......@@ -985,16 +984,6 @@ void RunControl::setRunnable(const Runnable &runnable)
d->runnable = runnable;
}
const Connection &RunControl::connection() const
{
return d->connection;
}
void RunControl::setConnection(const Connection &connection)
{
d->connection = connection;
}
QString RunControl::displayName() const
{
return d->displayName;
......@@ -1492,11 +1481,6 @@ const Runnable &RunWorker::runnable() const
return d->runControl->runnable();
}
const Connection &RunWorker::connection() const
{
return d->runControl->connection();
}
Core::Id RunWorker::runMode() const
{
return d->runControl->runMode();
......
......@@ -198,44 +198,6 @@ private:
std::unique_ptr<Concept> d;
};
class PROJECTEXPLORER_EXPORT Connection
{
struct Concept
{
virtual ~Concept() {}
virtual Concept *clone() const = 0;
virtual void *typeId() const = 0;
};
template <class T>
struct Model : public Concept
{
Model(const T &data) : m_data(data) { }
Concept *clone() const override { return new Model(*this); }
void *typeId() const override { return T::staticTypeId; }
T m_data;
};
public:
Connection() = default;
Connection(const Connection &other) : d(other.d ? other.d->clone() : nullptr) { }
Connection(Connection &&other) /* MSVC 2013 doesn't want = default */ : d(std::move(other.d)) {}
template <class T> Connection(const T &data) : d(new Model<T>(data)) {}
void operator=(Connection other) { d = std::move(other.d); }
template <class T> bool is() const {
return d.get() && (d.get()->typeId() == T::staticTypeId);
}
template <class T> const T &as() const {
return static_cast<Model<T> *>(d.get())->m_data;
}
private:
std::unique_ptr<Concept> d;
};
// Documentation inside.
class PROJECTEXPLORER_EXPORT RunConfiguration : public ProjectConfiguration
{
......@@ -387,7 +349,6 @@ public:
void appendMessage(const QString &msg, Utils::OutputFormat format);
IDevice::ConstPtr device() const;
const Runnable &runnable() const;
const Connection &connection() const;
Core::Id runMode() const;
// States
......@@ -466,9 +427,6 @@ public:
const Runnable &runnable() const;
void setRunnable(const Runnable &runnable);
const Connection &connection() const;
void setConnection(const Connection &connection);
virtual void appendMessage(const QString &msg, Utils::OutputFormat format);
virtual void bringApplicationToForeground();
......
......@@ -41,22 +41,8 @@ bool operator==(const StandardRunnable &r1, const StandardRunnable &r2)
void *StandardRunnable::staticTypeId = &StandardRunnable::staticTypeId;
UrlConnection UrlConnection::fromHost(const QString &host)
{
UrlConnection connection;
connection.setHost(host);
return connection;
}
UrlConnection UrlConnection::localHostWithoutPort()
{
QUrl serverUrl;
QTcpServer server;
serverUrl.setHost(server.serverAddress().toString());
return UrlConnection(serverUrl);
}
UrlConnection UrlConnection::localHostAndFreePort()
QUrl urlFromLocalHostAndFreePort()
{
QUrl serverUrl;
QTcpServer server;
......@@ -64,17 +50,22 @@ UrlConnection UrlConnection::localHostAndFreePort()
serverUrl.setHost(server.serverAddress().toString());
serverUrl.setPort(server.serverPort());
}
return UrlConnection(serverUrl);
return serverUrl;
}
UrlConnection UrlConnection::localSocket()
QUrl urlFromLocalSocket()
{
QUrl serverUrl;
serverUrl.setScheme(socketScheme());
serverUrl.setScheme(urlSocketScheme());
Utils::TemporaryFile file("qmlprofiler-freesocket");
if (file.open())
serverUrl.setPath(file.fileName());
return UrlConnection(serverUrl);
return serverUrl;
}
QString urlSocketScheme()
{
return QString("socket");
}
} // namespace ProjectExplorer
......@@ -53,32 +53,8 @@ public:
PROJECTEXPLORER_EXPORT bool operator==(const StandardRunnable &r1, const StandardRunnable &r2);
class PROJECTEXPLORER_EXPORT HostName
{
public:
explicit HostName(const QString &host) : m_host(host) {}
QString host() const { return m_host; }
static void *staticTypeId;
private:
QString m_host;
};
class PROJECTEXPLORER_EXPORT UrlConnection : public QUrl
{
public:
UrlConnection() {}
explicit UrlConnection(const QUrl &url) : QUrl(url) {}
static UrlConnection fromHost(const QString &host);
static UrlConnection localHostAndFreePort();
static UrlConnection localHostWithoutPort();
static UrlConnection localSocket();
static QString socketScheme() { return QLatin1String("socket"); }
static void *staticTypeId;
};
PROJECTEXPLORER_EXPORT QUrl urlFromLocalHostAndFreePort();
PROJECTEXPLORER_EXPORT QUrl urlFromLocalSocket();
PROJECTEXPLORER_EXPORT QString urlSocketScheme();
} // namespace ProjectExplorer
......@@ -271,10 +271,7 @@ void QmlProfilerRunner::setServerUrl(const QUrl &serverUrl)
QUrl QmlProfilerRunner::serverUrl() const
{
QVariant recordedServer = recordedData(QmlServerUrl);
if (recordedServer.isValid())
return recordedServer.toUrl();
QTC_ASSERT(connection().is<UrlConnection>(), return QUrl());
return connection().as<UrlConnection>();
return recordedServer.toUrl();
}
//
......@@ -289,12 +286,12 @@ static QUrl localServerUrl(RunControl *runControl)
const QtSupport::BaseQtVersion *version = QtSupport::QtKitInformation::qtVersion(kit);
if (version) {
if (version->qtVersion() >= QtSupport::QtVersionNumber(5, 6, 0))
serverUrl = UrlConnection::localSocket();
serverUrl = urlFromLocalSocket();
else
serverUrl = UrlConnection::localHostAndFreePort();
serverUrl = urlFromLocalHostAndFreePort();
} else {
qWarning("Running QML profiler on Kit without Qt version?");
serverUrl = UrlConnection::localHostAndFreePort();
serverUrl = urlFromLocalHostAndFreePort();
}
return serverUrl;
}
......
......@@ -580,9 +580,8 @@ void QmlProfilerTool::attachToWaitingApplication()
IDevice::ConstPtr device = DeviceKitInformation::device(kit);
QTC_ASSERT(device, return);
Connection toolControl = device->toolControlChannel(IDevice::QmlControlChannel);
QTC_ASSERT(toolControl.is<HostName>(), return);
serverUrl.setHost(toolControl.as<HostName>().host());
QUrl toolControl = device->toolControlChannel(IDevice::QmlControlChannel);
serverUrl.setHost(toolControl.host());
serverUrl.setPort(port);
Debugger::selectPerspective(Constants::QmlProfilerPerspectiveId);
......
......@@ -80,7 +80,7 @@ void LocalQmlProfilerRunnerTest::testRunner1()
QTRY_COMPARE_WITH_TIMEOUT(runCount, 1, 10000);
QTRY_VERIFY_WITH_TIMEOUT(!running, 10000);
serverUrl = UrlConnection::localSocket();
serverUrl = urlFromLocalSocket();
debuggee.executable = QCoreApplication::applicationFilePath();
// comma is used to specify a test function. In this case, an invalid one.
......@@ -97,7 +97,7 @@ void LocalQmlProfilerRunnerTest::testRunner2()
QTRY_VERIFY_WITH_TIMEOUT(!running, 10000);
debuggee.commandLineArguments.clear();
serverUrl = UrlConnection::localHostAndFreePort();
serverUrl = urlFromLocalHostAndFreePort();
start();
......@@ -119,7 +119,7 @@ void LocalQmlProfilerRunnerTest::testRunner4()
void LocalQmlProfilerRunnerTest::testFindFreePort()
{
QUrl serverUrl = UrlConnection::localHostAndFreePort();
QUrl serverUrl = urlFromLocalHostAndFreePort();
QVERIFY(serverUrl.port() != -1);
QVERIFY(!serverUrl.host().isEmpty());
QTcpServer server;
......@@ -128,7 +128,7 @@ void LocalQmlProfilerRunnerTest::testFindFreePort()
void LocalQmlProfilerRunnerTest::testFindFreeSocket()
{
QUrl serverUrl = UrlConnection::localSocket();
QUrl serverUrl = urlFromLocalSocket();
QString socket = serverUrl.path();
QVERIFY(!socket.isEmpty());
QVERIFY(!QFile::exists(socket));
......
......@@ -55,7 +55,7 @@ private:
int runCount = 0;
ProjectExplorer::RunControl *runControl = nullptr;
ProjectExplorer::StandardRunnable debuggee;
ProjectExplorer::UrlConnection serverUrl;
QUrl serverUrl;
};
} // namespace Internal
......
......@@ -70,12 +70,12 @@ void QmlProfilerClientManagerTest::testConnectionFailure_data()
QTest::addColumn<QmlProfilerStateManager *>("stateManager");
QVarLengthArray<QmlProfilerStateManager *> stateManagers({nullptr, &stateManager});
QUrl localUrl = UrlConnection::localHostAndFreePort();
QUrl localUrl = urlFromLocalHostAndFreePort();
QTest::addColumn<QUrl>("serverUrl");
QVarLengthArray<QString> hosts({"", "/-/|\\-\\|/-", localUrl.host()});
QVarLengthArray<int> ports({-1, 5, localUrl.port()});
QVarLengthArray<QString> sockets({"", "/-/|\\-\\|/-", UrlConnection::localSocket().path()});
QVarLengthArray<QString> sockets({"", "/-/|\\-\\|/-", urlFromLocalSocket().path()});
foreach (QmlProfilerModelManager *modelManager, modelManagers) {
foreach (QmlProfilerStateManager *stateManager, stateManagers) {
......@@ -101,7 +101,7 @@ void QmlProfilerClientManagerTest::testConnectionFailure_data()
.arg(0)
.arg(socket);
QUrl url;
url.setScheme(ProjectExplorer::UrlConnection::socketScheme());
url.setScheme(urlSocketScheme());
url.setPath(socket);
QTest::newRow(tag.toLatin1().constData()) << modelManager << stateManager << url;
}
......@@ -175,7 +175,7 @@ void QmlProfilerClientManagerTest::testUnresponsiveTcp()
clientManager.setProfilerStateManager(&stateManager);
clientManager.setModelManager(&modelManager);
QUrl serverUrl = UrlConnection::localHostAndFreePort();
QUrl serverUrl = urlFromLocalHostAndFreePort();
QTcpServer server;
server.listen(QHostAddress(serverUrl.host()), serverUrl.port());
......@@ -204,7 +204,7 @@ void QmlProfilerClientManagerTest::testUnresponsiveLocal()
clientManager.setProfilerStateManager(&stateManager);
clientManager.setModelManager(&modelManager);
QUrl socketUrl = UrlConnection::localSocket();
QUrl socketUrl = urlFromLocalSocket();
QLocalSocket socket;
QSignalSpy connectionSpy(&socket, SIGNAL(connected()));
......@@ -256,7 +256,7 @@ void QmlProfilerClientManagerTest::testResponsiveTcp()
{
QFETCH(quint32, flushInterval);
QUrl serverUrl = UrlConnection::localHostAndFreePort();
QUrl serverUrl = urlFromLocalHostAndFreePort();
QSignalSpy openedSpy(&clientManager, SIGNAL(connectionOpened()));
QSignalSpy closedSpy(&clientManager, SIGNAL(connectionClosed()));
......@@ -315,7 +315,7 @@ void QmlProfilerClientManagerTest::testResponsiveLocal()
{
QFETCH(quint32, flushInterval);
QUrl socketUrl = UrlConnection::localSocket();
QUrl socketUrl = urlFromLocalSocket();
QSignalSpy openedSpy(&clientManager, SIGNAL(connectionOpened()));
QSignalSpy closedSpy(&clientManager, SIGNAL(connectionClosed()));
......@@ -380,7 +380,7 @@ void QmlProfilerClientManagerTest::testInvalidData()
clientManager.setProfilerStateManager(&stateManager);
clientManager.setModelManager(&modelManager);
QUrl serverUrl = UrlConnection::localHostAndFreePort();
QUrl serverUrl = urlFromLocalHostAndFreePort();
bool dataSent = false;
QTcpServer server;
......@@ -411,7 +411,7 @@ void QmlProfilerClientManagerTest::testInvalidData()
void QmlProfilerClientManagerTest::testStopRecording()
{
QUrl socketUrl = UrlConnection::localSocket();
QUrl socketUrl = urlFromLocalSocket();
{
QmlProfilerClientManager clientManager;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment