You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

49 lines
1.1 KiB
C++

1 year ago
#include "DeviceManager.h"
DeviceManager *DeviceManager::m_pInstance = nullptr;
QMutex DeviceManager::m_mutex;
void DeviceManager::AddDevice(QString deviceName, Device *device)
{
RemoveDevice(deviceName);
m_deviceMap.insert(deviceName, device);
}
void DeviceManager::RemoveDevice(QString deviceName)
{
if(m_deviceMap.contains(deviceName))
{
QMap<QString, Device *>::iterator iter = m_deviceMap.find(deviceName);
delete iter.value();
m_deviceMap.erase(iter);
}
}
void DeviceManager::RemoveAllDevices()
{
while(m_deviceMap.size() > 0)
{
delete m_deviceMap.begin().value();
m_deviceMap.erase(m_deviceMap.begin());
}
}
Device *DeviceManager::GetDevice(QString deviceName)
{
if(m_deviceMap.contains(deviceName))
{
return m_deviceMap.find(deviceName).value();
}
return nullptr;
}
Device *DeviceManager::GetCurrDevice()
{
QString deviceName = QString::fromStdString(m_currDeviceName);
if(m_deviceMap.contains(deviceName))
{
return m_deviceMap.find(deviceName).value();
}
return nullptr;
}