Commit ac24fd02 authored by Tobias Hunger's avatar Tobias Hunger

IDevice: Add method to check whether a device is compatible with a kit

The default implementation just compares the device's type() with
the device type Id from the Kit.

Change-Id: I7e72737c0b322c3ee11aef6b3a4751bb91e0add0
Reviewed-by: default avatarChristian Kandeler <christian.kandeler@digia.com>
Reviewed-by: default avatarBenjamin Zeller <benjamin.zeller@canonical.com>
parent 592a28ee
......@@ -31,6 +31,9 @@
#include "devicemanager.h"
#include "deviceprocesslist.h"
#include "../kit.h"
#include "../kitinformation.h"
#include <ssh/sshconnection.h>
#include <utils/portlist.h>
#include <utils/qtcassert.h>
......@@ -239,6 +242,16 @@ Core::Id IDevice::id() const
return d->id;
}
/*!
Tests whether a device can be compatible with the given kit. The default
implementation will match the device type specified in the kit against
the device's own type.
*/
bool IDevice::isCompatibleWith(const Kit *k) const
{
return DeviceTypeKitInformation::deviceTypeId(k) == type();
}
PortsGatheringMethod::Ptr IDevice::portsGatheringMethod() const
{
return PortsGatheringMethod::Ptr();
......
......@@ -50,6 +50,8 @@ namespace ProjectExplorer {
class DeviceProcess;
class DeviceProcessList;
class Kit;
namespace Internal { class IDevicePrivate; }
class IDeviceWidget;
......@@ -121,6 +123,8 @@ public:
bool isAutoDetected() const;
Core::Id id() const;
virtual bool isCompatibleWith(const Kit *k) const;
virtual QString displayType() const = 0;
virtual IDeviceWidget *createWidget() = 0;
virtual QList<Core::Id> actionIds() const = 0;
......
......@@ -352,28 +352,40 @@ DeviceKitInformation::DeviceKitInformation()
QVariant DeviceKitInformation::defaultValue(Kit *k) const
{
Core::Id type = DeviceTypeKitInformation::deviceTypeId(k);
// Use default device if that is compatible:
IDevice::ConstPtr dev = DeviceManager::instance()->defaultDevice(type);
return dev.isNull() ? QString() : dev->id().toString();
if (dev && dev->isCompatibleWith(k))
return dev->id().toString();
// Use any other device that is compatible:
for (int i = 0; i < DeviceManager::instance()->deviceCount(); ++i) {
dev = DeviceManager::instance()->deviceAt(i);
if (dev && dev->isCompatibleWith(k))
return dev->id().toString();
}
// Fail: No device set up.
return QString();
}
QList<Task> DeviceKitInformation::validate(const Kit *k) const
{
IDevice::ConstPtr dev = DeviceKitInformation::device(k);
QList<Task> result;
if (!dev.isNull() && dev->type() != DeviceTypeKitInformation::deviceTypeId(k))
result.append(Task(Task::Error, tr("Device does not match device type."),
Utils::FileName(), -1, Core::Id(Constants::TASK_CATEGORY_BUILDSYSTEM)));
if (dev.isNull())
result.append(Task(Task::Warning, tr("No device set."),
Utils::FileName(), -1, Core::Id(Constants::TASK_CATEGORY_BUILDSYSTEM)));
else if (!dev->isCompatibleWith(k))
result.append(Task(Task::Error, tr("Device is incompatible with this kit."),
Utils::FileName(), -1, Core::Id(Constants::TASK_CATEGORY_BUILDSYSTEM)));
return result;
}
void DeviceKitInformation::fix(Kit *k)
{
IDevice::ConstPtr dev = DeviceKitInformation::device(k);
if (!dev.isNull() && dev->type() != DeviceTypeKitInformation::deviceTypeId(k)) {
qWarning("Device is no longer known, removing from kit \"%s\".", qPrintable(k->displayName()));
if (!dev.isNull() && !dev->isCompatibleWith(k)) {
qWarning("Device is no longer compatible with kit \"%s\", removing it.",
qPrintable(k->displayName()));
setDeviceId(k, Core::Id());
}
}
......@@ -382,7 +394,7 @@ void DeviceKitInformation::setup(Kit *k)
{
QTC_ASSERT(DeviceManager::instance()->isLoaded(), return);
IDevice::ConstPtr dev = DeviceKitInformation::device(k);
if (!dev.isNull() && dev->type() == DeviceTypeKitInformation::deviceTypeId(k))
if (!dev.isNull() && dev->isCompatibleWith(k))
return;
setDeviceId(k, Core::Id::fromSetting(defaultValue(k)));
......
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