These all need to be near-idempotent

This commit is contained in:
Rob Emery 2024-10-07 21:26:49 +01:00 committed by Carl Schwan
parent 732bf0636f
commit 9800664360
No known key found for this signature in database
GPG key ID: 02325448204E452A
2 changed files with 31 additions and 10 deletions

View file

@ -75,17 +75,21 @@ void BluetoothLinkProvider::onStop()
void BluetoothLinkProvider::enable() void BluetoothLinkProvider::enable()
{ {
enabled = true; if (enabled == false) {
tryToInitialise(); enabled = true;
tryToInitialise();
}
} }
void BluetoothLinkProvider::disable() void BluetoothLinkProvider::disable()
{ {
enabled = false; if (enabled == true) {
this->onStop(); enabled = false;
this->onStop();
mBluetoothServer = nullptr; mBluetoothServer = nullptr;
mServiceDiscoveryAgent = nullptr; mServiceDiscoveryAgent = nullptr;
}
} }
void BluetoothLinkProvider::onNetworkChange() void BluetoothLinkProvider::onNetworkChange()

View file

@ -86,17 +86,25 @@ LanLinkProvider::~LanLinkProvider()
void LanLinkProvider::enable() void LanLinkProvider::enable()
{ {
disabled = false; if (disabled == true) {
this->onStart(); disabled = false;
this->onStart();
}
} }
void LanLinkProvider::disable() void LanLinkProvider::disable()
{ {
this->onStop(); if (disabled == false) {
disabled = true; this->onStop();
disabled = true;
}
} }
void LanLinkProvider::onStart() void LanLinkProvider::onStart()
{ {
if (disabled) {
return;
}
const QHostAddress bindAddress = m_testMode ? QHostAddress::LocalHost : QHostAddress::Any; const QHostAddress bindAddress = m_testMode ? QHostAddress::LocalHost : QHostAddress::Any;
bool success = m_udpSocket.bind(bindAddress, UDP_PORT, QUdpSocket::ShareAddress); bool success = m_udpSocket.bind(bindAddress, UDP_PORT, QUdpSocket::ShareAddress);
@ -129,6 +137,9 @@ void LanLinkProvider::onStart()
void LanLinkProvider::onStop() void LanLinkProvider::onStop()
{ {
if (disabled) {
return;
}
#ifdef KDECONNECT_MDNS #ifdef KDECONNECT_MDNS
m_mdnsDiscovery.onStop(); m_mdnsDiscovery.onStop();
#endif #endif
@ -139,6 +150,9 @@ void LanLinkProvider::onStop()
void LanLinkProvider::onNetworkChange() void LanLinkProvider::onNetworkChange()
{ {
if (disabled) {
return;
}
if (m_combineNetworkChangeTimer.isActive()) { if (m_combineNetworkChangeTimer.isActive()) {
qCDebug(KDECONNECT_CORE) << "Device discovery triggered too fast, ignoring"; qCDebug(KDECONNECT_CORE) << "Device discovery triggered too fast, ignoring";
return; return;
@ -149,6 +163,9 @@ void LanLinkProvider::onNetworkChange()
// I'm in a new network, let's be polite and introduce myself // I'm in a new network, let's be polite and introduce myself
void LanLinkProvider::combinedOnNetworkChange() void LanLinkProvider::combinedOnNetworkChange()
{ {
if (disabled) {
return;
}
if (!m_server->isListening()) { if (!m_server->isListening()) {
qWarning() << "TCP server not listening, not broadcasting"; qWarning() << "TCP server not listening, not broadcasting";
return; return;