8 #ifndef NT_NETWORKCONNECTION_H_
9 #define NT_NETWORKCONNECTION_H_
16 #include "support/ConcurrentQueue.h"
18 #include "ntcore_cpp.h"
28 enum State { kCreated, kInit, kHandshake, kSynchronized, kActive, kDead };
30 typedef std::function<bool(
32 std::function<std::shared_ptr<Message>()> get_msg,
33 std::function<
void(
llvm::ArrayRef<std::shared_ptr<Message>>)> send_msgs)>
35 typedef std::function<void(std::shared_ptr<Message> msg,
37 typedef std::vector<std::shared_ptr<Message>> Outgoing;
42 HandshakeFunc handshake,
43 Message::GetEntryTypeFunc get_entry_type);
47 void set_process_incoming(ProcessIncomingFunc func) {
48 m_process_incoming = func;
56 bool active()
const {
return m_active; }
59 void QueueOutgoing(std::shared_ptr<Message> msg);
60 void PostOutgoing(
bool keep_alive);
62 unsigned int uid()
const {
return m_uid; }
64 unsigned int proto_rev()
const {
return m_proto_rev; }
65 void set_proto_rev(
unsigned int proto_rev) { m_proto_rev = proto_rev; }
67 State state()
const {
return static_cast<State
>(m_state.load()); }
68 void set_state(State state) { m_state =
static_cast<int>(state); }
70 std::string remote_id()
const;
73 unsigned long long last_update()
const {
return m_last_update; }
79 void ReadThreadMain();
80 void WriteThreadMain();
82 static std::atomic_uint s_uid;
85 std::unique_ptr<NetworkStream> m_stream;
88 HandshakeFunc m_handshake;
89 Message::GetEntryTypeFunc m_get_entry_type;
90 ProcessIncomingFunc m_process_incoming;
91 std::thread m_read_thread;
92 std::thread m_write_thread;
93 std::atomic_bool m_active;
94 std::atomic_uint m_proto_rev;
95 std::atomic_int m_state;
96 mutable std::mutex m_remote_id_mutex;
97 std::string m_remote_id;
98 std::atomic_ullong m_last_update;
99 std::chrono::steady_clock::time_point m_last_post;
101 std::mutex m_pending_mutex;
102 Outgoing m_pending_outgoing;
103 std::vector<std::pair<std::size_t, std::size_t>> m_pending_update;
106 std::mutex m_shutdown_mutex;
107 std::condition_variable m_read_shutdown_cv;
108 std::condition_variable m_write_shutdown_cv;
109 bool m_read_shutdown =
false;
110 bool m_write_shutdown =
false;
115 #endif // NT_NETWORKCONNECTION_H_
Definition: NetworkStream.h:15
NetworkTables Connection Information.
Definition: ntcore_cpp.h:43
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory)...
Definition: ArrayRef.h:54
Definition: Notifier.h:17
Definition: NetworkConnection.h:26
Definition: Notifier.h:19
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:39