MCPcopy Create free account
hub / github.com/Serial-Studio/Serial-Studio / close

Method close

app/src/IO/Drivers/BluetoothLE.cpp:479–535  ·  view source on GitHub ↗

* @brief Closes the Bluetooth LE connection. The resolved service + notify UUIDs are * re-staged as pendings so the GATT configuration survives a disconnect. Controller * and service go through deleteLater(): close() can run inside the controller's own * disconnected emission, and deleting the sender mid-emission crashes the backend. */

Source from the content-addressed store, hash-verified

477 * disconnected emission, and deleting the sender mid-emission crashes the backend.
478 */
479void IO::Drivers::BluetoothLE::close()
480{
481 const bool wasConnected = m_deviceConnected;
482 m_deviceConnected = false;
483 m_gattReady = false;
484 m_probeServiceIndex = -1;
485
486 const QString liveServiceUuid = m_service ? m_service->serviceUuid().toString() : QString();
487 QString liveNotifyUuid;
488 if (m_selectedCharacteristic >= 0 && m_selectedCharacteristic < m_characteristics.count())
489 liveNotifyUuid = m_characteristics.at(m_selectedCharacteristic).uuid().toString();
490
491 if (!liveServiceUuid.isEmpty())
492 m_pendingServiceUuid = liveServiceUuid;
493
494 if (!liveNotifyUuid.isEmpty())
495 m_pendingNotifyUuid = liveNotifyUuid;
496
497 m_serviceNames.clear();
498 m_serviceUuids.clear();
499 m_characteristics.clear();
500 m_characteristicNames.clear();
501 m_selectedCharacteristic = -1;
502
503 if (m_service) {
504 m_service->disconnect(this);
505 m_service->deleteLater();
506 m_service = nullptr;
507 }
508
509 if (m_controller) {
510 m_controller->disconnect(this);
511 m_controller->disconnectFromDevice();
512 m_controller->deleteLater();
513 m_controller = nullptr;
514 }
515
516 if (wasConnected) {
517 for (auto* inst : std::as_const(s_instances)) {
518 if (inst == this || inst->m_deviceIndex != m_deviceIndex)
519 continue;
520
521 inst->m_serviceNames.clear();
522 inst->m_serviceUuids.clear();
523 inst->m_characteristicNames.clear();
524 inst->m_selectedCharacteristic = -1;
525 Q_EMIT inst->servicesChanged();
526 Q_EMIT inst->characteristicsChanged();
527 Q_EMIT inst->characteristicIndexChanged();
528 }
529 }
530
531 Q_EMIT servicesChanged();
532 Q_EMIT characteristicsChanged();
533 Q_EMIT characteristicIndexChanged();
534 Q_EMIT deviceConnectedChanged();
535}
536

Callers 1

Calls 4

isEmptyMethod · 0.80
countMethod · 0.45
clearMethod · 0.45
disconnectMethod · 0.45

Tested by

no test coverage detected