Commit 7a7813b1 authored by Orgad Shaneh's avatar Orgad Shaneh Committed by Orgad Shaneh

BareMetal: Do not add a duplicate entry for GDB server provider

In case the SDK settings contain some host which was imported, and the server
provider was modified to a different host, it is re-imported on next execution
of Creator.

Also fix a potential memory leak when registration fails.

Change-Id: I96d087ab35e0dc54975768c4bc697218080049ae
Reviewed-by: default avatarhjk <hjk@theqtcompany.com>
parent ced554aa
......@@ -79,13 +79,21 @@ void BareMetalDevice::fromMap(const QVariantMap &map)
IDevice::fromMap(map);
QString gdbServerProvider = map.value(QLatin1String(gdbServerProviderIdKeyC)).toString();
if (gdbServerProvider.isEmpty()) {
const QSsh::SshConnectionParameters sshParams = sshParameters();
DefaultGdbServerProvider *newProvider = new DefaultGdbServerProvider;
newProvider->setDisplayName(displayName());
newProvider->m_host = sshParams.host;
newProvider->m_port = sshParams.port;
GdbServerProviderManager::instance()->registerProvider(newProvider);
gdbServerProvider = newProvider->id();
const QString name = displayName();
if (GdbServerProvider *provider =
GdbServerProviderManager::instance()->findByDisplayName(name)) {
gdbServerProvider = provider->id();
} else {
const QSsh::SshConnectionParameters sshParams = sshParameters();
DefaultGdbServerProvider *newProvider = new DefaultGdbServerProvider;
newProvider->setDisplayName(name);
newProvider->m_host = sshParams.host;
newProvider->m_port = sshParams.port;
if (GdbServerProviderManager::instance()->registerProvider(newProvider))
gdbServerProvider = newProvider->id();
else
delete newProvider;
}
}
setGdbServerProviderId(gdbServerProvider);
}
......
......@@ -172,6 +172,14 @@ GdbServerProvider *GdbServerProviderManager::findProvider(const QString &id) con
return Utils::findOrDefault(m_providers, Utils::equal(&GdbServerProvider::id, id));
}
GdbServerProvider *GdbServerProviderManager::findByDisplayName(const QString &displayName) const
{
if (displayName.isEmpty())
return 0;
return Utils::findOrDefault(m_providers, Utils::equal(&GdbServerProvider::displayName, displayName));
}
void GdbServerProviderManager::notifyAboutUpdate(GdbServerProvider *provider)
{
if (!provider || !m_providers.contains(provider))
......
......@@ -56,6 +56,7 @@ public:
QList<GdbServerProvider *> providers() const;
QList<GdbServerProviderFactory *> factories() const;
GdbServerProvider *findProvider(const QString &id) const;
GdbServerProvider *findByDisplayName(const QString &displayName) const;
bool registerProvider(GdbServerProvider *);
void deregisterProvider(GdbServerProvider *);
......
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