mirror of
https://gitlab.com/pholy/OSCAR-code.git
synced 2025-04-08 12:10:43 +00:00
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:
parent
c7db24877c
commit
eb5bef5fba
@ -106,7 +106,7 @@ DeviceConnectionManager::DeviceConnectionManager()
|
|||||||
|
|
||||||
DeviceConnection* DeviceConnectionManager::openConnection(const QString & type, const QString & name)
|
DeviceConnection* DeviceConnectionManager::openConnection(const QString & type, const QString & name)
|
||||||
{
|
{
|
||||||
if (!s_factories.contains(type)) {
|
if (!factories().contains(type)) {
|
||||||
qWarning() << "Unknown device connection type:" << type;
|
qWarning() << "Unknown device connection type:" << type;
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
@ -116,7 +116,7 @@ DeviceConnection* DeviceConnectionManager::openConnection(const QString & type,
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Recording/replay (if any) is handled by the connection.
|
// 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) {
|
||||||
if (conn->open()) {
|
if (conn->open()) {
|
||||||
m_connections[name] = conn;
|
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)
|
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;
|
qWarning() << "Connection class already registered for type" << type;
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
s_factories[type] = factory;
|
factories()[type] = factory;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -127,7 +127,7 @@ public:
|
|||||||
|
|
||||||
// DeviceConnection subclasses registration, not intended for client use.
|
// DeviceConnection subclasses registration, not intended for client use.
|
||||||
protected:
|
protected:
|
||||||
static QHash<QString,DeviceConnection::FactoryMethod> s_factories;
|
static QHash<QString,DeviceConnection::FactoryMethod> & factories();
|
||||||
public:
|
public:
|
||||||
static bool registerClass(const QString & type, DeviceConnection::FactoryMethod factory);
|
static bool registerClass(const QString & type, DeviceConnection::FactoryMethod factory);
|
||||||
static class DeviceConnection* createInstance(const QString & type);
|
static class DeviceConnection* createInstance(const QString & type);
|
||||||
|
Loading…
Reference in New Issue
Block a user