fixed device clean up on a failed device setup
parent
7123a92a01
commit
be32972ff0
|
|
@ -60,11 +60,6 @@ Device::DeviceError DevicePluginSenic::discoverDevices(const DeviceClassId &devi
|
|||
|
||||
Device::DeviceSetupStatus DevicePluginSenic::setupDevice(Device *device)
|
||||
{
|
||||
if (!m_reconnectTimer) {
|
||||
m_reconnectTimer = hardwareManager()->pluginTimerManager()->registerTimer(10);
|
||||
connect(m_reconnectTimer, &PluginTimer::timeout, this, &DevicePluginSenic::onReconnectTimeout);
|
||||
}
|
||||
|
||||
qCDebug(dcSenic()) << "Setup device" << device->name() << device->params();
|
||||
|
||||
QBluetoothAddress address = QBluetoothAddress(device->paramValue(nuimoDeviceMacParamTypeId).toString());
|
||||
|
|
@ -89,6 +84,16 @@ Device::DeviceSetupStatus DevicePluginSenic::setupDevice(Device *device)
|
|||
return Device::DeviceSetupStatusAsync;
|
||||
}
|
||||
|
||||
void DevicePluginSenic::postSetupDevice(Device *device)
|
||||
{
|
||||
Q_UNUSED(device)
|
||||
|
||||
if (!m_reconnectTimer) {
|
||||
m_reconnectTimer = hardwareManager()->pluginTimerManager()->registerTimer(10);
|
||||
connect(m_reconnectTimer, &PluginTimer::timeout, this, &DevicePluginSenic::onReconnectTimeout);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Device::DeviceError DevicePluginSenic::executeAction(Device *device, const Action &action)
|
||||
{
|
||||
|
|
@ -195,12 +200,21 @@ void DevicePluginSenic::onBluetoothDiscoveryFinished()
|
|||
emit devicesDiscovered(nuimoDeviceClassId, deviceDescriptors);
|
||||
}
|
||||
|
||||
void DevicePluginSenic::onDeviceInitializationFinished()
|
||||
void DevicePluginSenic::onDeviceInitializationFinished(bool success)
|
||||
{
|
||||
Nuimo *nuimo = static_cast<Nuimo *>(sender());
|
||||
Device *device = m_nuimos.value(nuimo);
|
||||
if (!device->setupComplete()) {
|
||||
emit deviceSetupFinished(device, Device::DeviceSetupStatusSuccess);
|
||||
if (success) {
|
||||
emit deviceSetupFinished(device, Device::DeviceSetupStatusSuccess);
|
||||
} else {
|
||||
m_nuimos.take(nuimo);
|
||||
|
||||
hardwareManager()->bluetoothLowEnergyManager()->unregisterDevice(nuimo->bluetoothDevice());
|
||||
nuimo->deleteLater();
|
||||
|
||||
emit deviceSetupFinished(device, Device::DeviceSetupStatusFailure);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -42,6 +42,7 @@ public:
|
|||
void init() override;
|
||||
Device::DeviceError discoverDevices(const DeviceClassId &deviceClassId, const ParamList ¶ms) override;
|
||||
Device::DeviceSetupStatus setupDevice(Device *device) override;
|
||||
void postSetupDevice(Device *device) override;
|
||||
Device::DeviceError executeAction(Device *device, const Action &action) override;
|
||||
|
||||
void deviceRemoved(Device *device) override;
|
||||
|
|
@ -56,7 +57,7 @@ private slots:
|
|||
void onReconnectTimeout();
|
||||
void onBluetoothDiscoveryFinished();
|
||||
|
||||
void onDeviceInitializationFinished();
|
||||
void onDeviceInitializationFinished(bool success);
|
||||
void onConnectedChanged(bool connected);
|
||||
void onBatteryValueChanged(const uint &percentage);
|
||||
void onButtonPressed();
|
||||
|
|
|
|||
|
|
@ -295,7 +295,7 @@ void Nuimo::onLongPressTimer()
|
|||
|
||||
|
||||
|
||||
void Nuimo::onConnectedChanged(const bool &connected)
|
||||
void Nuimo::onConnectedChanged(bool connected)
|
||||
{
|
||||
qCDebug(dcSenic()) << m_bluetoothDevice->name() << m_bluetoothDevice->address().toString() << (connected ? "connected" : "disconnected");
|
||||
|
||||
|
|
@ -323,21 +323,25 @@ void Nuimo::onServiceDiscoveryFinished()
|
|||
|
||||
if (!m_bluetoothDevice->serviceUuids().contains(QBluetoothUuid::DeviceInformation)) {
|
||||
qCWarning(dcSenic()) << "Device Information service not found for device" << bluetoothDevice()->name() << bluetoothDevice()->address().toString();
|
||||
emit deviceInitializationFinished(false);
|
||||
return;
|
||||
}
|
||||
|
||||
if (!m_bluetoothDevice->serviceUuids().contains(QBluetoothUuid::BatteryService)) {
|
||||
qCWarning(dcSenic()) << "Battery service not found for device" << bluetoothDevice()->name() << bluetoothDevice()->address().toString();
|
||||
emit deviceInitializationFinished(false);
|
||||
return;
|
||||
}
|
||||
|
||||
if (!m_bluetoothDevice->serviceUuids().contains(ledMatrinxServiceUuid)) {
|
||||
qCWarning(dcSenic()) << "Led matrix service not found for device" << bluetoothDevice()->name() << bluetoothDevice()->address().toString();
|
||||
emit deviceInitializationFinished(false);
|
||||
return;
|
||||
}
|
||||
|
||||
if (!m_bluetoothDevice->serviceUuids().contains(inputServiceUuid)) {
|
||||
qCWarning(dcSenic()) << "Input service not found for device" << bluetoothDevice()->name() << bluetoothDevice()->address().toString();
|
||||
emit deviceInitializationFinished(false);
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
@ -346,6 +350,7 @@ void Nuimo::onServiceDiscoveryFinished()
|
|||
m_deviceInfoService = m_bluetoothDevice->controller()->createServiceObject(QBluetoothUuid::DeviceInformation, this);
|
||||
if (!m_deviceInfoService) {
|
||||
qCWarning(dcSenic()) << "Could not create device info service.";
|
||||
emit deviceInitializationFinished(false);
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
@ -361,6 +366,7 @@ void Nuimo::onServiceDiscoveryFinished()
|
|||
m_batteryService = m_bluetoothDevice->controller()->createServiceObject(QBluetoothUuid::BatteryService, this);
|
||||
if (!m_batteryService) {
|
||||
qCWarning(dcSenic()) << "Could not create battery service.";
|
||||
emit deviceInitializationFinished(false);
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
@ -377,6 +383,7 @@ void Nuimo::onServiceDiscoveryFinished()
|
|||
m_inputService = m_bluetoothDevice->controller()->createServiceObject(inputServiceUuid, this);
|
||||
if (!m_inputService) {
|
||||
qCWarning(dcSenic()) << "Could not create input service.";
|
||||
emit deviceInitializationFinished(false);
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
@ -393,6 +400,7 @@ void Nuimo::onServiceDiscoveryFinished()
|
|||
m_ledMatrixService = m_bluetoothDevice->controller()->createServiceObject(ledMatrinxServiceUuid, this);
|
||||
if (!m_ledMatrixService) {
|
||||
qCWarning(dcSenic()) << "Could not create led matrix service.";
|
||||
emit deviceInitializationFinished(false);
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
@ -402,7 +410,7 @@ void Nuimo::onServiceDiscoveryFinished()
|
|||
m_ledMatrixService->discoverDetails();
|
||||
}
|
||||
}
|
||||
emit deviceInitializationFinished();
|
||||
emit deviceInitializationFinished(true);
|
||||
}
|
||||
|
||||
void Nuimo::onDeviceInfoServiceStateChanged(const QLowEnergyService::ServiceState &state)
|
||||
|
|
|
|||
|
|
@ -95,10 +95,10 @@ signals:
|
|||
void swipeDetected(const SwipeDirection &direction);
|
||||
void rotationValueChanged(const uint &value);
|
||||
void deviceInformationChanged(const QString &firmwareRevision, const QString &hardwareRevision, const QString &softwareRevision);
|
||||
void deviceInitializationFinished();
|
||||
void deviceInitializationFinished(bool success);
|
||||
|
||||
private slots:
|
||||
void onConnectedChanged(const bool &connected);
|
||||
void onConnectedChanged(bool connected);
|
||||
void onServiceDiscoveryFinished();
|
||||
|
||||
void onDeviceInfoServiceStateChanged(const QLowEnergyService::ServiceState &state);
|
||||
|
|
|
|||
Loading…
Reference in New Issue