Commit 4d382811 authored by hjk's avatar hjk

ProjectExplorer: Introduce a DeviceEnvironmentFetcher

Also, provide implementations for desktop and remote linux.

Change-Id: Ib02202bf1829367334035a361ac73317338cd7a6
Reviewed-by: default avatarChristian Kandeler <christian.kandeler@theqtcompany.com>
parent 2e1494d0
......@@ -32,6 +32,8 @@
#include <projectexplorer/projectexplorerconstants.h>
#include <ssh/sshconnection.h>
#include <utils/environment.h>
#include <utils/portlist.h>
#include <QCoreApplication>
......@@ -116,6 +118,22 @@ DeviceProcessSignalOperation::Ptr DesktopDevice::signalOperation() const
return DeviceProcessSignalOperation::Ptr(new DesktopProcessSignalOperation());
}
class DesktopDeviceEnvironmentFetcher : public DeviceEnvironmentFetcher
{
public:
DesktopDeviceEnvironmentFetcher() {}
void start() override
{
emit finished(Utils::Environment::systemEnvironment(), true);
}
};
DeviceEnvironmentFetcher::Ptr DesktopDevice::environmentFetcher() const
{
return DeviceEnvironmentFetcher::Ptr(new DesktopDeviceEnvironmentFetcher());
}
QString DesktopDevice::qmlProfilerHost() const
{
return QLatin1String("localhost");
......
......@@ -51,6 +51,7 @@ public:
bool canCreateProcess() const override { return true; }
DeviceProcess *createProcess(QObject *parent) const override;
DeviceProcessSignalOperation::Ptr signalOperation() const override;
DeviceEnvironmentFetcher::Ptr environmentFetcher() const override;
QString qmlProfilerHost() const override;
IDevice::Ptr clone() const override;
......
......@@ -277,6 +277,11 @@ DeviceProcess *IDevice::createProcess(QObject * /* parent */) const
return 0;
}
DeviceEnvironmentFetcher::Ptr IDevice::environmentFetcher() const
{
return DeviceEnvironmentFetcher::Ptr();
}
IDevice::DeviceState IDevice::deviceState() const
{
return d->deviceState;
......@@ -457,4 +462,8 @@ DeviceProcessSignalOperation::DeviceProcessSignalOperation()
{
}
DeviceEnvironmentFetcher::DeviceEnvironmentFetcher()
{
}
} // namespace ProjectExplorer
......@@ -40,7 +40,11 @@ class QWidget;
QT_END_NAMESPACE
namespace QSsh { class SshConnectionParameters; }
namespace Utils { class PortList; }
namespace Utils {
class Environment;
class PortList;
} // Utils
namespace ProjectExplorer {
class DeviceProcess;
......@@ -77,6 +81,21 @@ protected:
QString m_errorMessage;
};
class PROJECTEXPLORER_EXPORT DeviceEnvironmentFetcher : public QObject
{
Q_OBJECT
public:
typedef QSharedPointer<DeviceEnvironmentFetcher> Ptr;
virtual void start() = 0;
signals:
void finished(const Utils::Environment &env, bool success);
protected:
explicit DeviceEnvironmentFetcher();
};
class PROJECTEXPLORER_EXPORT PortsGatheringMethod
{
public:
......@@ -138,6 +157,7 @@ public:
virtual bool canCreateProcess() const { return false; }
virtual DeviceProcess *createProcess(QObject *parent) const;
virtual DeviceProcessSignalOperation::Ptr signalOperation() const = 0;
virtual DeviceEnvironmentFetcher::Ptr environmentFetcher() const;
enum DeviceState { DeviceReadyToUse, DeviceConnected, DeviceDisconnected, DeviceStateUnknown };
DeviceState deviceState() const;
......
......@@ -31,6 +31,7 @@
#include "publickeydeploymentdialog.h"
#include "remotelinux_constants.h"
#include "remotelinuxsignaloperation.h"
#include "remotelinuxenvironmentreader.h"
#include <coreplugin/id.h>
#include <projectexplorer/devicesupport/sshdeviceprocesslist.h>
......@@ -254,4 +255,29 @@ DeviceProcessSignalOperation::Ptr LinuxDevice::signalOperation() const
return DeviceProcessSignalOperation::Ptr(new RemoteLinuxSignalOperation(sshParameters()));
}
class LinuxDeviceEnvironmentFetcher : public DeviceEnvironmentFetcher
{
public:
LinuxDeviceEnvironmentFetcher(const IDevice::ConstPtr &device)
: m_reader(device)
{
connect(&m_reader, &Internal::RemoteLinuxEnvironmentReader::finished,
this, &LinuxDeviceEnvironmentFetcher::readerFinished);
connect(&m_reader, &Internal::RemoteLinuxEnvironmentReader::error,
this, &LinuxDeviceEnvironmentFetcher::readerError);
}
private:
void start() override { m_reader.start(); }
void readerFinished() { emit finished(m_reader.remoteEnvironment(), true); }
void readerError() { emit finished(Utils::Environment(), false); }
Internal::RemoteLinuxEnvironmentReader m_reader;
};
DeviceEnvironmentFetcher::Ptr LinuxDevice::environmentFetcher() const
{
return DeviceEnvironmentFetcher::Ptr(new LinuxDeviceEnvironmentFetcher(sharedFromThis()));
}
} // namespace RemoteLinux
......@@ -66,6 +66,7 @@ public:
bool hasDeviceTester() const { return true; }
ProjectExplorer::DeviceTester *createDeviceTester() const;
ProjectExplorer::DeviceProcessSignalOperation::Ptr signalOperation() const;
ProjectExplorer::DeviceEnvironmentFetcher::Ptr environmentFetcher() const;
protected:
LinuxDevice() {}
......
......@@ -28,10 +28,16 @@
#include "remotelinuxrunconfiguration.h"
#include "remotelinuxenvironmentreader.h"
#include <projectexplorer/target.h>
#include <projectexplorer/kitinformation.h>
#include <QCoreApplication>
#include <QMessageBox>
#include <QPushButton>
using namespace ProjectExplorer;
using namespace RemoteLinux::Internal;
namespace {
const QString FetchEnvButtonText
= QCoreApplication::translate("RemoteLinux::RemoteLinuxEnvironmentAspectWidget",
......@@ -41,15 +47,22 @@ const QString FetchEnvButtonText
namespace RemoteLinux {
RemoteLinuxEnvironmentAspectWidget::RemoteLinuxEnvironmentAspectWidget(RemoteLinuxEnvironmentAspect *aspect) :
ProjectExplorer::EnvironmentAspectWidget(aspect, new QPushButton),
deviceEnvReader(new Internal::RemoteLinuxEnvironmentReader(aspect->runConfiguration(), this))
EnvironmentAspectWidget(aspect, new QPushButton)
{
RunConfiguration *runConfiguration = aspect->runConfiguration();
Target *target = runConfiguration->target();
IDevice::ConstPtr device = DeviceKitInformation::device(target->kit());
deviceEnvReader = new RemoteLinuxEnvironmentReader(device, this);
connect(target, &ProjectExplorer::Target::kitChanged,
deviceEnvReader, &RemoteLinuxEnvironmentReader::handleCurrentDeviceConfigChanged);
QPushButton *button = fetchButton();
button->setText(FetchEnvButtonText);
connect(button, &QPushButton::clicked, this, &RemoteLinuxEnvironmentAspectWidget::fetchEnvironment);
connect(deviceEnvReader, &Internal::RemoteLinuxEnvironmentReader::finished,
connect(deviceEnvReader, &RemoteLinuxEnvironmentReader::finished,
this, &RemoteLinuxEnvironmentAspectWidget::fetchEnvironmentFinished);
connect(deviceEnvReader, &Internal::RemoteLinuxEnvironmentReader::error,
connect(deviceEnvReader, &RemoteLinuxEnvironmentReader::error,
this, &RemoteLinuxEnvironmentAspectWidget::fetchEnvironmentError);
}
......
......@@ -27,9 +27,6 @@
#include <projectexplorer/devicesupport/deviceprocess.h>
#include <projectexplorer/devicesupport/idevice.h>
#include <projectexplorer/kitinformation.h>
#include <projectexplorer/runconfiguration.h>
#include <projectexplorer/target.h>
#include <projectexplorer/runnables.h>
using namespace ProjectExplorer;
......@@ -37,24 +34,25 @@ using namespace ProjectExplorer;
namespace RemoteLinux {
namespace Internal {
RemoteLinuxEnvironmentReader::RemoteLinuxEnvironmentReader(RunConfiguration *config, QObject *parent)
RemoteLinuxEnvironmentReader::RemoteLinuxEnvironmentReader(const IDevice::ConstPtr &device,
QObject *parent)
: QObject(parent)
, m_stop(false)
, m_env(Utils::OsTypeLinux)
, m_kit(config->target()->kit())
, m_device(device)
, m_deviceProcess(0)
{
connect(config->target(), SIGNAL(kitChanged()),
this, SLOT(handleCurrentDeviceConfigChanged()));
}
void RemoteLinuxEnvironmentReader::start()
{
IDevice::ConstPtr device = DeviceKitInformation::device(m_kit);
if (!device)
if (!m_device) {
emit error(tr("Error: No device"));
setFinished();
return;
}
m_stop = false;
m_deviceProcess = device->createProcess(this);
m_deviceProcess = m_device->createProcess(this);
connect(m_deviceProcess, &DeviceProcess::error,
this, &RemoteLinuxEnvironmentReader::handleError);
connect(m_deviceProcess, &DeviceProcess::finished,
......
......@@ -26,15 +26,12 @@
#ifndef REMOTELINUXENVIRONMENTREADER_H
#define REMOTELINUXENVIRONMENTREADER_H
#include <projectexplorer/devicesupport/idevice.h>
#include <utils/environment.h>
#include <QObject>
namespace ProjectExplorer {
class DeviceProcess;
class Kit;
class RunConfiguration;
}
namespace ProjectExplorer { class DeviceProcess; }
namespace RemoteLinux {
namespace Internal {
......@@ -44,29 +41,27 @@ class RemoteLinuxEnvironmentReader : public QObject
Q_OBJECT
public:
RemoteLinuxEnvironmentReader(ProjectExplorer::RunConfiguration *config, QObject *parent = 0);
RemoteLinuxEnvironmentReader(const ProjectExplorer::IDevice::ConstPtr &device,
QObject *parent = 0);
void start();
void stop();
Utils::Environment remoteEnvironment() const { return m_env; }
void handleCurrentDeviceConfigChanged();
signals:
void finished();
void error(const QString &error);
private slots:
private:
void handleError();
void handleCurrentDeviceConfigChanged();
void remoteProcessFinished();
private:
void setFinished();
void destroyProcess();
bool m_stop;
Utils::Environment m_env;
ProjectExplorer::Kit *m_kit;
ProjectExplorer::IDevice::ConstPtr m_device;
ProjectExplorer::DeviceProcess *m_deviceProcess;
};
......
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