diff --git a/ntcore/src/main/native/cpp/ConnectionNotifier.h b/ntcore/src/main/native/cpp/ConnectionNotifier.h index 0aec1c724c..66dd5f1bc2 100644 --- a/ntcore/src/main/native/cpp/ConnectionNotifier.h +++ b/ntcore/src/main/native/cpp/ConnectionNotifier.h @@ -5,7 +5,8 @@ #ifndef NTCORE_CONNECTIONNOTIFIER_H_ #define NTCORE_CONNECTIONNOTIFIER_H_ -#include "CallbackManager.h" +#include + #include "Handle.h" #include "IConnectionNotifier.h" #include "ntcore_cpp.h" @@ -15,7 +16,8 @@ namespace nt { namespace impl { class ConnectionNotifierThread - : public CallbackThread { + : public wpi::CallbackThread { public: explicit ConnectionNotifierThread(int inst) : m_inst(inst) {} @@ -42,11 +44,11 @@ class ConnectionNotifierThread class ConnectionNotifier : public IConnectionNotifier, - public CallbackManager { + public wpi::CallbackManager { friend class ConnectionNotifierTest; - friend class CallbackManager; + friend class wpi::CallbackManager; public: explicit ConnectionNotifier(int inst); diff --git a/ntcore/src/main/native/cpp/EntryNotifier.h b/ntcore/src/main/native/cpp/EntryNotifier.h index d27380f4df..c80fc627d0 100644 --- a/ntcore/src/main/native/cpp/EntryNotifier.h +++ b/ntcore/src/main/native/cpp/EntryNotifier.h @@ -9,7 +9,8 @@ #include #include -#include "CallbackManager.h" +#include + #include "Handle.h" #include "IEntryNotifier.h" #include "ntcore_cpp.h" @@ -23,22 +24,23 @@ namespace nt { namespace impl { struct EntryListenerData - : public ListenerData> { + : public wpi::CallbackListenerData< + std::function> { EntryListenerData() = default; EntryListenerData( std::function callback_, StringRef prefix_, unsigned int flags_) - : ListenerData(callback_), prefix(prefix_), flags(flags_) {} + : CallbackListenerData(callback_), prefix(prefix_), flags(flags_) {} EntryListenerData( std::function callback_, NT_Entry entry_, unsigned int flags_) - : ListenerData(callback_), entry(entry_), flags(flags_) {} + : CallbackListenerData(callback_), entry(entry_), flags(flags_) {} EntryListenerData(unsigned int poller_uid_, StringRef prefix_, unsigned int flags_) - : ListenerData(poller_uid_), prefix(prefix_), flags(flags_) {} + : CallbackListenerData(poller_uid_), prefix(prefix_), flags(flags_) {} EntryListenerData(unsigned int poller_uid_, NT_Entry entry_, unsigned int flags_) - : ListenerData(poller_uid_), entry(entry_), flags(flags_) {} + : CallbackListenerData(poller_uid_), entry(entry_), flags(flags_) {} std::string prefix; NT_Entry entry = 0; @@ -46,8 +48,8 @@ struct EntryListenerData }; class EntryNotifierThread - : public CallbackThread { + : public wpi::CallbackThread { public: explicit EntryNotifierThread(int inst) : m_inst(inst) {} @@ -71,9 +73,9 @@ class EntryNotifierThread class EntryNotifier : public IEntryNotifier, - public CallbackManager { + public wpi::CallbackManager { friend class EntryNotifierTest; - friend class CallbackManager; + friend class wpi::CallbackManager; public: explicit EntryNotifier(int inst, wpi::Logger& logger); diff --git a/ntcore/src/main/native/cpp/LoggerImpl.h b/ntcore/src/main/native/cpp/LoggerImpl.h index a055124bac..4f341838dc 100644 --- a/ntcore/src/main/native/cpp/LoggerImpl.h +++ b/ntcore/src/main/native/cpp/LoggerImpl.h @@ -5,7 +5,8 @@ #ifndef NTCORE_LOGGERIMPL_H_ #define NTCORE_LOGGERIMPL_H_ -#include "CallbackManager.h" +#include + #include "Handle.h" #include "ntcore_cpp.h" @@ -13,15 +14,17 @@ namespace nt { namespace impl { -struct LoggerListenerData - : public ListenerData> { +struct LoggerListenerData : public wpi::CallbackListenerData< + std::function> { LoggerListenerData() = default; LoggerListenerData(std::function callback_, unsigned int min_level_, unsigned int max_level_) - : ListenerData(callback_), min_level(min_level_), max_level(max_level_) {} + : CallbackListenerData(callback_), + min_level(min_level_), + max_level(max_level_) {} LoggerListenerData(unsigned int poller_uid_, unsigned int min_level_, unsigned int max_level_) - : ListenerData(poller_uid_), + : CallbackListenerData(poller_uid_), min_level(min_level_), max_level(max_level_) {} @@ -30,7 +33,7 @@ struct LoggerListenerData }; class LoggerThread - : public CallbackThread { + : public wpi::CallbackThread { public: explicit LoggerThread(int inst) : m_inst(inst) {} @@ -52,9 +55,9 @@ class LoggerThread } // namespace impl -class LoggerImpl : public CallbackManager { +class LoggerImpl : public wpi::CallbackManager { friend class LoggerTest; - friend class CallbackManager; + friend class wpi::CallbackManager; public: explicit LoggerImpl(int inst); diff --git a/ntcore/src/main/native/cpp/RpcServer.h b/ntcore/src/main/native/cpp/RpcServer.h index 301bbff106..4d20c50686 100644 --- a/ntcore/src/main/native/cpp/RpcServer.h +++ b/ntcore/src/main/native/cpp/RpcServer.h @@ -7,10 +7,10 @@ #include +#include #include #include -#include "CallbackManager.h" #include "Handle.h" #include "IRpcServer.h" #include "Log.h" @@ -32,11 +32,11 @@ struct RpcNotifierData : public RpcAnswer { }; using RpcListenerData = - ListenerData>; + wpi::CallbackListenerData>; class RpcServerThread - : public CallbackThread { + : public wpi::CallbackThread { public: RpcServerThread(int inst, wpi::Logger& logger) : m_inst(inst), m_logger(logger) {} @@ -78,10 +78,11 @@ class RpcServerThread } // namespace impl -class RpcServer : public IRpcServer, - public CallbackManager { +class RpcServer + : public IRpcServer, + public wpi::CallbackManager { friend class RpcServerTest; - friend class CallbackManager; + friend class wpi::CallbackManager; public: RpcServer(int inst, wpi::Logger& logger); diff --git a/ntcore/src/main/native/cpp/CallbackManager.h b/wpiutil/src/main/native/include/wpi/CallbackManager.h similarity index 94% rename from ntcore/src/main/native/cpp/CallbackManager.h rename to wpiutil/src/main/native/include/wpi/CallbackManager.h index e48ba7dab7..4f1d952afe 100644 --- a/ntcore/src/main/native/cpp/CallbackManager.h +++ b/wpiutil/src/main/native/include/wpi/CallbackManager.h @@ -2,8 +2,8 @@ // Open Source Software; you can modify and/or share it under the terms of // the WPILib BSD license file in the root directory of this project. -#ifndef NTCORE_CALLBACKMANAGER_H_ -#define NTCORE_CALLBACKMANAGER_H_ +#ifndef WPIUTIL_WPI_CALLBACKMANAGER_H_ +#define WPIUTIL_WPI_CALLBACKMANAGER_H_ #include #include @@ -13,22 +13,21 @@ #include #include -#include -#include -#include -#include -#include +#include "wpi/SafeThread.h" +#include "wpi/UidVector.h" +#include "wpi/condition_variable.h" +#include "wpi/mutex.h" +#include "wpi/raw_ostream.h" -namespace nt { - -namespace impl { +namespace wpi { template -class ListenerData { +class CallbackListenerData { public: - ListenerData() = default; - explicit ListenerData(Callback callback_) : callback(callback_) {} - explicit ListenerData(unsigned int poller_uid_) : poller_uid(poller_uid_) {} + CallbackListenerData() = default; + explicit CallbackListenerData(Callback callback_) : callback(callback_) {} + explicit CallbackListenerData(unsigned int poller_uid_) + : poller_uid(poller_uid_) {} explicit operator bool() const { return callback || poller_uid != UINT_MAX; } @@ -46,7 +45,7 @@ class ListenerData { // void DoCallback(Callback callback, const NotifierData& data); template >, + CallbackListenerData>, typename TNotifierData = TUserInfo> class CallbackThread : public wpi::SafeThread { public: @@ -167,8 +166,6 @@ void CallbackThread::Main() { } } -} // namespace impl - // CRTP callback manager // @tparam Derived derived class // @tparam Thread custom thread (must be derived from impl::CallbackThread) @@ -366,6 +363,6 @@ class CallbackManager { wpi::SafeThreadOwner m_owner; }; -} // namespace nt +} // namespace wpi -#endif // NTCORE_CALLBACKMANAGER_H_ +#endif // WPIUTIL_WPI_CALLBACKMANAGER_H_