#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::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; }