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()
{
if (enabled == false) {
enabled = true;
tryToInitialise();
}
}
void BluetoothLinkProvider::disable()
{
if (enabled == true) {
enabled = false;
this->onStop();
mBluetoothServer = nullptr;
mServiceDiscoveryAgent = nullptr;
}
}
void BluetoothLinkProvider::onNetworkChange()

View file

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