BareMetal: Split BareMetalRunConfigurationFactory

... into two, each handling one type of RunConfiguration only.

This is temporary to allow easier removal of boiler plate.

Change-Id: I0c8427eaeef07dff06dce7824a87b222f8f05019
Reviewed-by: Christian Kandeler <christian.kandeler@qt.io>
This commit is contained in:
hjk
2017-11-09 19:02:38 +01:00
parent 6caece50cf
commit cb14d74e47
3 changed files with 95 additions and 23 deletions

View File

@@ -68,6 +68,7 @@ bool BareMetalPlugin::initialize(const QStringList &arguments, QString *errorStr
addAutoReleasedObject(new BareMetalDeviceConfigurationFactory); addAutoReleasedObject(new BareMetalDeviceConfigurationFactory);
addAutoReleasedObject(new BareMetalRunConfigurationFactory); addAutoReleasedObject(new BareMetalRunConfigurationFactory);
addAutoReleasedObject(new BareMetalCustomRunConfigurationFactory);
addAutoReleasedObject(new GdbServerProvidersSettingsPage); addAutoReleasedObject(new GdbServerProvidersSettingsPage);
addAutoReleasedObject(new GdbServerProviderManager); addAutoReleasedObject(new GdbServerProviderManager);

View File

@@ -50,6 +50,16 @@ static QString pathFromId(Core::Id id)
return QString::fromUtf8(idStr.mid(int(strlen(BareMetalRunConfiguration::IdPrefix)))); return QString::fromUtf8(idStr.mid(int(strlen(BareMetalRunConfiguration::IdPrefix))));
} }
static bool canHandle(const Target *target)
{
if (!target->project()->supportsKit(target->kit()))
return false;
const Core::Id deviceType = DeviceTypeKitInformation::deviceTypeId(target->kit());
return deviceType == BareMetal::Constants::BareMetalOsType;
}
// BareMetalRunConfigurationFactory
BareMetalRunConfigurationFactory::BareMetalRunConfigurationFactory(QObject *parent) : BareMetalRunConfigurationFactory::BareMetalRunConfigurationFactory(QObject *parent) :
IRunConfigurationFactory(parent) IRunConfigurationFactory(parent)
{ {
@@ -61,23 +71,19 @@ bool BareMetalRunConfigurationFactory::canCreate(Target *parent, Core::Id id) co
if (!canHandle(parent)) if (!canHandle(parent))
return false; return false;
const QString targetName = QFileInfo(pathFromId(id)).fileName(); const QString targetName = QFileInfo(pathFromId(id)).fileName();
return id == BareMetalCustomRunConfiguration::runConfigId() return !parent->applicationTargets().targetFilePath(targetName).isEmpty();
|| !parent->applicationTargets().targetFilePath(targetName).isEmpty();
} }
bool BareMetalRunConfigurationFactory::canRestore(Target *parent, const QVariantMap &map) const bool BareMetalRunConfigurationFactory::canRestore(Target *parent, const QVariantMap &map) const
{ {
if (!canHandle(parent)) if (!canHandle(parent))
return false; return false;
const Core::Id id = idFromMap(map); return idFromMap(map).name().startsWith(BareMetalRunConfiguration::IdPrefix);
return id == BareMetalCustomRunConfiguration::runConfigId()
|| idFromMap(map).name().startsWith(BareMetalRunConfiguration::IdPrefix);
} }
bool BareMetalRunConfigurationFactory::canClone(Target *parent, RunConfiguration *source) const bool BareMetalRunConfigurationFactory::canClone(Target *parent, RunConfiguration *source) const
{ {
const BareMetalRunConfiguration * const bmrc auto bmrc = qobject_cast<BareMetalRunConfiguration *>(source);
= qobject_cast<BareMetalRunConfiguration *>(source);
return bmrc && canCreate(parent, source->id()); return bmrc && canCreate(parent, source->id());
} }
@@ -91,46 +97,91 @@ QList<Core::Id> BareMetalRunConfigurationFactory::availableCreationIds(Target *p
const Core::Id base = Core::Id(BareMetalRunConfiguration::IdPrefix); const Core::Id base = Core::Id(BareMetalRunConfiguration::IdPrefix);
foreach (const BuildTargetInfo &bti, parent->applicationTargets().list) foreach (const BuildTargetInfo &bti, parent->applicationTargets().list)
result << base.withSuffix(bti.projectFilePath.toString() + QLatin1Char('/') + bti.targetName); result << base.withSuffix(bti.projectFilePath.toString() + QLatin1Char('/') + bti.targetName);
result << BareMetalCustomRunConfiguration::runConfigId();
return result; return result;
} }
QString BareMetalRunConfigurationFactory::displayNameForId(Core::Id id) const QString BareMetalRunConfigurationFactory::displayNameForId(Core::Id id) const
{ {
if (id == BareMetalCustomRunConfiguration::runConfigId())
return BareMetalCustomRunConfiguration::runConfigDefaultDisplayName();
return tr("%1 (on GDB server or hardware debugger)") return tr("%1 (on GDB server or hardware debugger)")
.arg(QFileInfo(pathFromId(id)).fileName()); .arg(QFileInfo(pathFromId(id)).fileName());
} }
RunConfiguration *BareMetalRunConfigurationFactory::doCreate(Target *parent, Core::Id id) RunConfiguration *BareMetalRunConfigurationFactory::doCreate(Target *parent, Core::Id id)
{ {
if (id == BareMetalCustomRunConfiguration::runConfigId())
return new BareMetalCustomRunConfiguration(parent);
return createHelper<BareMetalRunConfiguration>(parent, id, pathFromId(id)); return createHelper<BareMetalRunConfiguration>(parent, id, pathFromId(id));
} }
RunConfiguration *BareMetalRunConfigurationFactory::doRestore(Target *parent, const QVariantMap &map) RunConfiguration *BareMetalRunConfigurationFactory::doRestore(Target *parent, const QVariantMap &)
{ {
if (idFromMap(map) == BareMetalCustomRunConfiguration::runConfigId())
return new BareMetalCustomRunConfiguration(parent);
return doCreate(parent,Core::Id(BareMetalRunConfiguration::IdPrefix)); return doCreate(parent,Core::Id(BareMetalRunConfiguration::IdPrefix));
} }
RunConfiguration *BareMetalRunConfigurationFactory::clone(Target *parent, RunConfiguration *source) RunConfiguration *BareMetalRunConfigurationFactory::clone(Target *parent, RunConfiguration *source)
{ {
QTC_ASSERT(canClone(parent, source), return 0); QTC_ASSERT(canClone(parent, source), return 0);
if (qobject_cast<BareMetalCustomRunConfiguration *>(source))
return cloneHelper<BareMetalCustomRunConfiguration>(parent, source);
return cloneHelper<BareMetalRunConfiguration>(parent, source); return cloneHelper<BareMetalRunConfiguration>(parent, source);
} }
bool BareMetalRunConfigurationFactory::canHandle(const Target *target) const
// BareMetalCustomRunConfigurationFactory
BareMetalCustomRunConfigurationFactory::BareMetalCustomRunConfigurationFactory(QObject *parent) :
IRunConfigurationFactory(parent)
{ {
if (!target->project()->supportsKit(target->kit())) setObjectName("BareMetalCustomRunConfigurationFactory");
}
bool BareMetalCustomRunConfigurationFactory::canCreate(Target *parent, Core::Id id) const
{
if (!canHandle(parent))
return false; return false;
const Core::Id deviceType = DeviceTypeKitInformation::deviceTypeId(target->kit()); return id == BareMetalCustomRunConfiguration::runConfigId();
return deviceType == BareMetal::Constants::BareMetalOsType; }
bool BareMetalCustomRunConfigurationFactory::canRestore(Target *parent, const QVariantMap &map) const
{
if (!canHandle(parent))
return false;
const Core::Id id = idFromMap(map);
return id == BareMetalCustomRunConfiguration::runConfigId();
}
bool BareMetalCustomRunConfigurationFactory::canClone(Target *parent, RunConfiguration *source) const
{
auto bmrc = qobject_cast<BareMetalCustomRunConfiguration *>(source);
return bmrc && canCreate(parent, source->id());
}
QList<Core::Id> BareMetalCustomRunConfigurationFactory::availableCreationIds(Target *parent, CreationMode mode) const
{
Q_UNUSED(mode)
QList<Core::Id> result;
if (!canHandle(parent))
return result;
result << BareMetalCustomRunConfiguration::runConfigId();
return result;
}
QString BareMetalCustomRunConfigurationFactory::displayNameForId(Core::Id) const
{
return BareMetalCustomRunConfiguration::runConfigDefaultDisplayName();
}
RunConfiguration *BareMetalCustomRunConfigurationFactory::doCreate(Target *parent, Core::Id)
{
return new BareMetalCustomRunConfiguration(parent);
}
RunConfiguration *BareMetalCustomRunConfigurationFactory::doRestore(Target *parent, const QVariantMap &)
{
return new BareMetalCustomRunConfiguration(parent);
}
RunConfiguration *BareMetalCustomRunConfigurationFactory::clone(Target *parent, RunConfiguration *source)
{
QTC_ASSERT(canClone(parent, source), return 0);
return cloneHelper<BareMetalCustomRunConfiguration>(parent, source);
} }
} // namespace Internal } // namespace Internal

View File

@@ -48,12 +48,32 @@ public:
ProjectExplorer::RunConfiguration *clone(ProjectExplorer::Target *parent, ProjectExplorer::RunConfiguration *clone(ProjectExplorer::Target *parent,
ProjectExplorer::RunConfiguration *source) override; ProjectExplorer::RunConfiguration *source) override;
private: private:
bool canHandle(const ProjectExplorer::Target *target) const;
ProjectExplorer::RunConfiguration *doCreate(ProjectExplorer::Target *parent, Core::Id id) override; ProjectExplorer::RunConfiguration *doCreate(ProjectExplorer::Target *parent, Core::Id id) override;
ProjectExplorer::RunConfiguration *doRestore(ProjectExplorer::Target *parent, ProjectExplorer::RunConfiguration *doRestore(ProjectExplorer::Target *parent,
const QVariantMap &map) override; const QVariantMap &map) override;
}; };
class BareMetalCustomRunConfigurationFactory : public ProjectExplorer::IRunConfigurationFactory
{
Q_OBJECT
public:
explicit BareMetalCustomRunConfigurationFactory(QObject *parent = 0);
QString displayNameForId(Core::Id id) const override;
QList<Core::Id> availableCreationIds(ProjectExplorer::Target *parent, CreationMode mode) const override;
bool canCreate(ProjectExplorer::Target *parent, Core::Id id) const override;
bool canRestore(ProjectExplorer::Target *parent, const QVariantMap &map) const override;
bool canClone(ProjectExplorer::Target *parent, ProjectExplorer::RunConfiguration *source) const override;
ProjectExplorer::RunConfiguration *clone(ProjectExplorer::Target *parent,
ProjectExplorer::RunConfiguration *source) override;
private:
ProjectExplorer::RunConfiguration *doCreate(ProjectExplorer::Target *parent, Core::Id id) override;
ProjectExplorer::RunConfiguration *doRestore(ProjectExplorer::Target *parent,
const QVariantMap &map) override;
};
} // namespace Internal } // namespace Internal
} // namespace RemoteLinux } // namespace RemoteLinux