BareMetal: Update device address when provider is changed

Change-Id: Id020328797c4ec9a739cbf5844f9c4a9acf363ff
Reviewed-by: Denis Shienkov <denis.shienkov@gmail.com>
Reviewed-by: Tobias Hunger <tobias.hunger@qt.io>
This commit is contained in:
Orgad Shaneh
2017-03-17 00:27:57 +02:00
committed by Orgad Shaneh
parent 24a922cb28
commit c82c742d8d
4 changed files with 53 additions and 2 deletions

View File

@@ -59,6 +59,12 @@ BareMetalDevice::Ptr BareMetalDevice::create(const BareMetalDevice &other)
return Ptr(new BareMetalDevice(other)); return Ptr(new BareMetalDevice(other));
} }
BareMetalDevice::~BareMetalDevice()
{
if (GdbServerProvider *provider = GdbServerProviderManager::findProvider(m_gdbServerProviderId))
provider->unregisterDevice(this);
}
QString BareMetalDevice::gdbServerProviderId() const QString BareMetalDevice::gdbServerProviderId() const
{ {
return m_gdbServerProviderId; return m_gdbServerProviderId;
@@ -66,8 +72,26 @@ QString BareMetalDevice::gdbServerProviderId() const
void BareMetalDevice::setGdbServerProviderId(const QString &id) void BareMetalDevice::setGdbServerProviderId(const QString &id)
{ {
if (id == m_gdbServerProviderId)
return;
if (GdbServerProvider *currentProvider = GdbServerProviderManager::findProvider(m_gdbServerProviderId))
currentProvider->unregisterDevice(this);
m_gdbServerProviderId = id; m_gdbServerProviderId = id;
GdbServerProvider *provider = GdbServerProviderManager::findProvider(id); if (GdbServerProvider *provider = GdbServerProviderManager::findProvider(id)) {
setChannelByServerProvider(provider);
provider->registerDevice(this);
}
}
void BareMetalDevice::providerUpdated(GdbServerProvider *provider)
{
GdbServerProvider *myProvider = GdbServerProviderManager::findProvider(m_gdbServerProviderId);
if (provider == myProvider)
setChannelByServerProvider(provider);
}
void BareMetalDevice::setChannelByServerProvider(GdbServerProvider *provider)
{
QTC_ASSERT(provider, return); QTC_ASSERT(provider, return);
const QString channel = provider->channel(); const QString channel = provider->channel();
const int colon = channel.indexOf(QLatin1Char(':')); const int colon = channel.indexOf(QLatin1Char(':'));

View File

@@ -31,6 +31,8 @@
namespace BareMetal { namespace BareMetal {
namespace Internal { namespace Internal {
class GdbServerProvider;
class BareMetalDevice : public ProjectExplorer::IDevice class BareMetalDevice : public ProjectExplorer::IDevice
{ {
public: public:
@@ -42,6 +44,7 @@ public:
Origin origin = ManuallyAdded, Core::Id id = Core::Id()); Origin origin = ManuallyAdded, Core::Id id = Core::Id());
static Ptr create(const BareMetalDevice &other); static Ptr create(const BareMetalDevice &other);
~BareMetalDevice();
QString displayType() const override; QString displayType() const override;
ProjectExplorer::IDeviceWidget *createWidget() override; ProjectExplorer::IDeviceWidget *createWidget() override;
QList<Core::Id> actionIds() const override; QList<Core::Id> actionIds() const override;
@@ -56,6 +59,7 @@ public:
QString gdbServerProviderId() const; QString gdbServerProviderId() const;
void setGdbServerProviderId(const QString &id); void setGdbServerProviderId(const QString &id);
void providerUpdated(GdbServerProvider *provider);
virtual void fromMap(const QVariantMap &map) override; virtual void fromMap(const QVariantMap &map) override;
virtual QVariantMap toMap() const override; virtual QVariantMap toMap() const override;
@@ -67,6 +71,7 @@ protected:
BareMetalDevice(const BareMetalDevice &other); BareMetalDevice(const BareMetalDevice &other);
private: private:
void setChannelByServerProvider(GdbServerProvider *provider);
BareMetalDevice &operator=(const BareMetalDevice &); BareMetalDevice &operator=(const BareMetalDevice &);
QString m_gdbServerProviderId; QString m_gdbServerProviderId;
}; };

View File

@@ -25,7 +25,9 @@
#include "gdbserverprovider.h" #include "gdbserverprovider.h"
#include "gdbserverprovidermanager.h" #include "gdbserverprovidermanager.h"
#include "baremetaldevice.h"
#include <utils/asconst.h>
#include <utils/qtcassert.h> #include <utils/qtcassert.h>
#include <utils/environment.h> #include <utils/environment.h>
@@ -74,6 +76,9 @@ GdbServerProvider::GdbServerProvider(const GdbServerProvider &other)
GdbServerProvider::~GdbServerProvider() GdbServerProvider::~GdbServerProvider()
{ {
const QSet<BareMetalDevice *> devices = m_devices;
for (BareMetalDevice *device : devices)
device->setGdbServerProviderId(QString());
} }
QString GdbServerProvider::displayName() const QString GdbServerProvider::displayName() const
@@ -173,9 +178,21 @@ bool GdbServerProvider::canStartupMode(StartupMode m) const
return m == NoStartup; return m == NoStartup;
} }
void GdbServerProvider::registerDevice(BareMetalDevice *device)
{
m_devices.insert(device);
}
void GdbServerProvider::unregisterDevice(BareMetalDevice *device)
{
m_devices.remove(device);
}
void GdbServerProvider::providerUpdated() void GdbServerProvider::providerUpdated()
{ {
GdbServerProviderManager::notifyAboutUpdate(this); GdbServerProviderManager::notifyAboutUpdate(this);
for (BareMetalDevice *device : Utils::asConst(m_devices))
device->providerUpdated(this);
} }
bool GdbServerProvider::fromMap(const QVariantMap &data) bool GdbServerProvider::fromMap(const QVariantMap &data)

View File

@@ -26,8 +26,8 @@
#pragma once #pragma once
#include <QObject> #include <QObject>
#include <QSet>
#include <QVariantMap> #include <QVariantMap>
#include <QWidget> #include <QWidget>
#include <utils/fileutils.h> #include <utils/fileutils.h>
@@ -44,6 +44,7 @@ QT_END_NAMESPACE
namespace BareMetal { namespace BareMetal {
namespace Internal { namespace Internal {
class BareMetalDevice;
class GdbServerProviderConfigWidget; class GdbServerProviderConfigWidget;
class GdbServerProviderManager; class GdbServerProviderManager;
@@ -85,6 +86,9 @@ public:
virtual bool isValid() const; virtual bool isValid() const;
virtual bool canStartupMode(StartupMode) const; virtual bool canStartupMode(StartupMode) const;
void registerDevice(BareMetalDevice *);
void unregisterDevice(BareMetalDevice *);
protected: protected:
explicit GdbServerProvider(const QString &id); explicit GdbServerProvider(const QString &id);
explicit GdbServerProvider(const GdbServerProvider &); explicit GdbServerProvider(const GdbServerProvider &);
@@ -103,6 +107,7 @@ private:
StartupMode m_startupMode; StartupMode m_startupMode;
QString m_initCommands; QString m_initCommands;
QString m_resetCommands; QString m_resetCommands;
QSet<BareMetalDevice *> m_devices;
friend class GdbServerProviderConfigWidget; friend class GdbServerProviderConfigWidget;
}; };