refactor: add onDeviceConnected

dev
Barry 4 years ago
parent 6dbe96d3a8
commit c4fdbffbf4

@ -257,7 +257,7 @@ void Device::initSignals()
emit m_controller->onSetScreenPowerMode(ControlMsg::SPM_OFF);
}
} else {
disconnectDevice();
m_server->stop();
}
});
connect(m_server, &Server::serverStoped, this, [this]() {

@ -40,6 +40,7 @@ bool DeviceManage::connectDevice(Device::DeviceParams params)
}
*/
Device *device = new Device(params);
connect(device, &Device::deviceConnected, this, &DeviceManage::onDeviceConnected);
connect(device, &Device::deviceDisconnected, this, &DeviceManage::onDeviceDisconnected);
connect(device, &Device::controlStateChange, this, &DeviceManage::onControlStateChange);
if (!device->connectDevice()) {
@ -190,17 +191,18 @@ void DeviceManage::setGroupControlHost(Device *host, bool install)
}
}
void DeviceManage::onDeviceDisconnected(QString serial)
void DeviceManage::onDeviceConnected(bool success, const QString &serial, const QString &deviceName, const QSize &size)
{
if (!serial.isEmpty() && m_devices.contains(serial)) {
if (m_devices[serial]->controlState() == Device::GroupControlState::GCS_HOST) {
setGroupControlHost(nullptr, false);
}
m_devices[serial]->deleteLater();
m_devices.remove(serial);
if (!success) {
removeDevice(serial);
}
}
void DeviceManage::onDeviceDisconnected(QString serial)
{
removeDevice(serial);
}
void DeviceManage::onControlStateChange(Device *device, Device::GroupControlState oldState, Device::GroupControlState newState)
{
if (!device) {
@ -300,3 +302,14 @@ quint16 DeviceManage::getFreePort()
}
return 0;
}
void DeviceManage::removeDevice(const QString &serial)
{
if (!serial.isEmpty() && m_devices.contains(serial)) {
if (m_devices[serial]->controlState() == Device::GroupControlState::GCS_HOST) {
setGroupControlHost(nullptr, false);
}
m_devices[serial]->deleteLater();
m_devices.remove(serial);
}
}

@ -26,6 +26,7 @@ protected:
void setGroupControlHost(Device *host, bool install);
protected slots:
void onDeviceConnected(bool success, const QString& serial, const QString& deviceName, const QSize& size);
void onDeviceDisconnected(QString serial);
void onControlStateChange(Device *device, Device::GroupControlState oldState, Device::GroupControlState newState);
@ -36,6 +37,7 @@ protected slots:
private:
quint16 getFreePort();
void removeDevice(const QString& serial);
private:
QMap<QString, QPointer<Device>> m_devices;

Loading…
Cancel
Save