Move DeviceConnectionManager's global static variable into a local static.

This fixes the same issue that was just fixed in XmlReplayEvent, though
this one hadn't yet caused a crash.
This commit is contained in:
sawinglogz 2020-07-10 12:50:34 -04:00
parent c7db24877c
commit eb5bef5fba
2 changed files with 10 additions and 6 deletions

View File

@ -106,7 +106,7 @@ DeviceConnectionManager::DeviceConnectionManager()
DeviceConnection* DeviceConnectionManager::openConnection(const QString & type, const QString & name)
{
if (!s_factories.contains(type)) {
if (!factories().contains(type)) {
qWarning() << "Unknown device connection type:" << type;
return nullptr;
}
@ -116,7 +116,7 @@ DeviceConnection* DeviceConnectionManager::openConnection(const QString & type,
}
// Recording/replay (if any) is handled by the connection.
DeviceConnection* conn = s_factories[type](name, m_record, m_replay);
DeviceConnection* conn = factories()[type](name, m_record, m_replay);
if (conn) {
if (conn->open()) {
m_connections[name] = conn;
@ -156,15 +156,19 @@ SerialPortConnection* DeviceConnectionManager::openSerialPortConnection(const QS
}
QHash<QString,DeviceConnection::FactoryMethod> DeviceConnectionManager::s_factories;
QHash<QString,DeviceConnection::FactoryMethod> & DeviceConnectionManager::factories()
{
static QHash<QString,DeviceConnection::FactoryMethod> s_factories;
return s_factories;
}
bool DeviceConnectionManager::registerClass(const QString & type, DeviceConnection::FactoryMethod factory)
{
if (s_factories.contains(type)) {
if (factories().contains(type)) {
qWarning() << "Connection class already registered for type" << type;
return false;
}
s_factories[type] = factory;
factories()[type] = factory;
return true;
}

View File

@ -127,7 +127,7 @@ public:
// DeviceConnection subclasses registration, not intended for client use.
protected:
static QHash<QString,DeviceConnection::FactoryMethod> s_factories;
static QHash<QString,DeviceConnection::FactoryMethod> & factories();
public:
static bool registerClass(const QString & type, DeviceConnection::FactoryMethod factory);
static class DeviceConnection* createInstance(const QString & type);