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:
Peter Johnson
2015-08-02 21:47:01 -07:00
parent 538a19fd47
commit e9073a3cc0
9 changed files with 289 additions and 18 deletions

View File

@@ -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;