WiimoteScannerBackend: Allow StopThreads to request that any Wiimote searching stops

Used by WiimoteScannerDarwin to know when to exit its runloop.
This commit is contained in:
OatmealDome 2021-06-23 23:09:01 -04:00
parent 0de30fa0bb
commit b494d109d4
8 changed files with 15 additions and 1 deletions

View File

@ -48,6 +48,7 @@ public:
bool IsReady() const override { return true; } bool IsReady() const override { return true; }
void FindWiimotes(std::vector<Wiimote*>&, Wiimote*&) override; void FindWiimotes(std::vector<Wiimote*>&, Wiimote*&) override;
void Update() override {} void Update() override {}
void RequestStopSearching() override {}
}; };
} // namespace WiimoteReal } // namespace WiimoteReal

View File

@ -16,5 +16,6 @@ public:
bool IsReady() const override { return false; } bool IsReady() const override { return false; }
void FindWiimotes(std::vector<Wiimote*>&, Wiimote*&) override {} void FindWiimotes(std::vector<Wiimote*>&, Wiimote*&) override {}
void Update() override {} void Update() override {}
void RequestStopSearching() override {}
}; };
} // namespace WiimoteReal } // namespace WiimoteReal

View File

@ -47,6 +47,7 @@ public:
bool IsReady() const override; bool IsReady() const override;
void FindWiimotes(std::vector<Wiimote*>&, Wiimote*&) override; void FindWiimotes(std::vector<Wiimote*>&, Wiimote*&) override;
void Update() override {} // not needed on Linux void Update() override {} // not needed on Linux
void RequestStopSearching() override {} // not needed on Linux
private: private:
int m_device_id; int m_device_id;
int m_device_sock; int m_device_sock;

View File

@ -52,6 +52,7 @@ public:
bool IsReady() const override; bool IsReady() const override;
void FindWiimotes(std::vector<Wiimote*>&, Wiimote*&) override; void FindWiimotes(std::vector<Wiimote*>&, Wiimote*&) override;
void Update() override; void Update() override;
void RequestStopSearching() override {}
}; };
} // namespace WiimoteReal } // namespace WiimoteReal

View File

@ -24,6 +24,7 @@ public:
bool IsReady() const override; bool IsReady() const override;
void FindWiimotes(std::vector<Wiimote*>&, Wiimote*&) override; void FindWiimotes(std::vector<Wiimote*>&, Wiimote*&) override;
void Update() override {} // not needed void Update() override {} // not needed
void RequestStopSearching() override { m_stop_scanning = true; }
private: private:
IOBluetoothHostController* m_host_controller; IOBluetoothHostController* m_host_controller;
bool m_stop_scanning = false; bool m_stop_scanning = false;

View File

@ -39,6 +39,7 @@ public:
bool IsReady() const override; bool IsReady() const override;
void FindWiimotes(std::vector<Wiimote*>&, Wiimote*&) override; void FindWiimotes(std::vector<Wiimote*>&, Wiimote*&) override;
void Update() override {} // not needed for hidapi void Update() override {} // not needed for hidapi
void RequestStopSearching() override {} // not needed for hidapi
}; };
} // namespace WiimoteReal } // namespace WiimoteReal

View File

@ -545,6 +545,12 @@ void WiimoteScanner::StopThread()
if (m_scan_thread_running.TestAndClear()) if (m_scan_thread_running.TestAndClear())
{ {
SetScanMode(WiimoteScanMode::DO_NOT_SCAN); SetScanMode(WiimoteScanMode::DO_NOT_SCAN);
for (const auto& backend : m_backends)
{
backend->RequestStopSearching();
}
m_scan_thread.join(); m_scan_thread.join();
} }
} }

View File

@ -1,4 +1,4 @@
// Copyright 2008 Dolphin Emulator Project // Copyright 2008 Dolphin Emulator Project
// Licensed under GPLv2+ // Licensed under GPLv2+
// Refer to the license.txt file included. // Refer to the license.txt file included.
@ -155,6 +155,8 @@ public:
virtual void FindWiimotes(std::vector<Wiimote*>&, Wiimote*&) = 0; virtual void FindWiimotes(std::vector<Wiimote*>&, Wiimote*&) = 0;
// function called when not looking for more Wiimotes // function called when not looking for more Wiimotes
virtual void Update() = 0; virtual void Update() = 0;
// requests the backend to stop scanning if FindWiimotes is blocking
virtual void RequestStopSearching() = 0;
}; };
enum class WiimoteScanMode enum class WiimoteScanMode