mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-06-24 01:31:46 +00:00
Implement notifiers.
The notifier thread is lazily started when the first notifier is added. This avoids the extra thread/processing overhead when notifiers are not used.
This commit is contained in:
@@ -14,11 +14,14 @@
|
||||
|
||||
#include "support/ConcurrentQueue.h"
|
||||
#include "Message.h"
|
||||
#include "ntcore_cpp.h"
|
||||
|
||||
class NetworkStream;
|
||||
|
||||
namespace nt {
|
||||
|
||||
class Notifier;
|
||||
|
||||
class NetworkConnection {
|
||||
public:
|
||||
enum State { kCreated, kInit, kHandshake, kSynchronized, kActive, kDead };
|
||||
@@ -34,6 +37,7 @@ class NetworkConnection {
|
||||
typedef ConcurrentQueue<Outgoing> OutgoingQueue;
|
||||
|
||||
NetworkConnection(std::unique_ptr<NetworkStream> stream,
|
||||
Notifier& notifier,
|
||||
HandshakeFunc handshake,
|
||||
Message::GetEntryTypeFunc get_entry_type,
|
||||
ProcessIncomingFunc process_incoming);
|
||||
@@ -42,6 +46,8 @@ class NetworkConnection {
|
||||
void Start();
|
||||
void Stop();
|
||||
|
||||
ConnectionInfo info() const;
|
||||
|
||||
bool active() const { return m_active; }
|
||||
NetworkStream& stream() { return *m_stream; }
|
||||
OutgoingQueue& outgoing() { return m_outgoing; }
|
||||
@@ -65,6 +71,7 @@ class NetworkConnection {
|
||||
void WriteThreadMain();
|
||||
|
||||
std::unique_ptr<NetworkStream> m_stream;
|
||||
Notifier& m_notifier;
|
||||
OutgoingQueue m_outgoing;
|
||||
HandshakeFunc m_handshake;
|
||||
Message::GetEntryTypeFunc m_get_entry_type;
|
||||
|
||||
Reference in New Issue
Block a user