diff --git a/cscore/src/main/native/cpp/NetworkListener.h b/cscore/src/main/native/cpp/NetworkListener.h index 9457ab0b1e..6d49adccc4 100644 --- a/cscore/src/main/native/cpp/NetworkListener.h +++ b/cscore/src/main/native/cpp/NetworkListener.h @@ -8,8 +8,9 @@ #ifndef CSCORE_NETWORKLISTENER_H_ #define CSCORE_NETWORKLISTENER_H_ +#include + #include -#include namespace cs { @@ -17,19 +18,15 @@ class Notifier; class NetworkListener { public: - NetworkListener(wpi::Logger& logger, Notifier& notifier) - : m_logger(logger), m_notifier(notifier) {} + NetworkListener(wpi::Logger& logger, Notifier& notifier); ~NetworkListener(); void Start(); void Stop(); private: - wpi::Logger& m_logger; - Notifier& m_notifier; - - class Thread; - wpi::SafeThreadOwner m_owner; + class Impl; + std::unique_ptr m_impl; }; } // namespace cs diff --git a/cscore/src/main/native/linux/NetworkListener.cpp b/cscore/src/main/native/linux/NetworkListener.cpp index 048baa69b6..ed3d966589 100644 --- a/cscore/src/main/native/linux/NetworkListener.cpp +++ b/cscore/src/main/native/linux/NetworkListener.cpp @@ -18,36 +18,54 @@ #include +#include + #include "Log.h" #include "Notifier.h" using namespace cs; -class NetworkListener::Thread : public wpi::SafeThread { +class NetworkListener::Impl { public: - Thread(wpi::Logger& logger, Notifier& notifier) + Impl(wpi::Logger& logger, Notifier& notifier) : m_logger(logger), m_notifier(notifier) {} - void Main(); wpi::Logger& m_logger; Notifier& m_notifier; - int m_command_fd = -1; + + class Thread : public wpi::SafeThread { + public: + Thread(wpi::Logger& logger, Notifier& notifier) + : m_logger(logger), m_notifier(notifier) {} + void Main(); + + wpi::Logger& m_logger; + Notifier& m_notifier; + int m_command_fd = -1; + }; + + wpi::SafeThreadOwner m_owner; }; +NetworkListener::NetworkListener(wpi::Logger& logger, Notifier& notifier) + : m_impl(std::make_unique(logger, notifier)) {} + NetworkListener::~NetworkListener() { Stop(); } -void NetworkListener::Start() { m_owner.Start(m_logger, m_notifier); } +void NetworkListener::Start() { + m_impl->m_owner.Start(m_impl->m_logger, m_impl->m_notifier); +} void NetworkListener::Stop() { // Wake up thread - if (auto thr = m_owner.GetThread()) { + if (auto thr = m_impl->m_owner.GetThread()) { thr->m_active = false; if (thr->m_command_fd >= 0) eventfd_write(thr->m_command_fd, 1); } - m_owner.Stop(); + m_impl->m_owner.Stop(); } -void NetworkListener::Thread::Main() { +void NetworkListener::Impl::Thread::Main() { // Create event socket so we can be shut down m_command_fd = ::eventfd(0, 0); if (m_command_fd < 0) { diff --git a/cscore/src/main/native/osx/NetworkListener.cpp b/cscore/src/main/native/osx/NetworkListener.cpp index e52d105813..0716789703 100644 --- a/cscore/src/main/native/osx/NetworkListener.cpp +++ b/cscore/src/main/native/osx/NetworkListener.cpp @@ -7,31 +7,14 @@ #include "NetworkListener.h" -#include "Log.h" -#include "Notifier.h" - using namespace cs; -class NetworkListener::Thread : public wpi::SafeThread { - public: - void Main(); -}; +class NetworkListener::Impl {}; -NetworkListener::~NetworkListener() { Stop(); } +NetworkListener::NetworkListener(wpi::Logger& logger, Notifier& notifier) {} -void NetworkListener::Start() { - auto thr = m_owner.GetThread(); - if (!thr) m_owner.Start(); -} +NetworkListener::~NetworkListener() {} -void NetworkListener::Stop() { - // Wake up thread - if (auto thr = m_owner.GetThread()) { - thr->m_active = false; - } - m_owner.Stop(); -} +void NetworkListener::Start() {} -void NetworkListener::Thread::Main() { - // TODO -} +void NetworkListener::Stop() {} diff --git a/cscore/src/main/native/windows/NetworkListener.cpp b/cscore/src/main/native/windows/NetworkListener.cpp index e52d105813..0716789703 100644 --- a/cscore/src/main/native/windows/NetworkListener.cpp +++ b/cscore/src/main/native/windows/NetworkListener.cpp @@ -7,31 +7,14 @@ #include "NetworkListener.h" -#include "Log.h" -#include "Notifier.h" - using namespace cs; -class NetworkListener::Thread : public wpi::SafeThread { - public: - void Main(); -}; +class NetworkListener::Impl {}; -NetworkListener::~NetworkListener() { Stop(); } +NetworkListener::NetworkListener(wpi::Logger& logger, Notifier& notifier) {} -void NetworkListener::Start() { - auto thr = m_owner.GetThread(); - if (!thr) m_owner.Start(); -} +NetworkListener::~NetworkListener() {} -void NetworkListener::Stop() { - // Wake up thread - if (auto thr = m_owner.GetThread()) { - thr->m_active = false; - } - m_owner.Stop(); -} +void NetworkListener::Start() {} -void NetworkListener::Thread::Main() { - // TODO -} +void NetworkListener::Stop() {}