8 #ifndef NT_NETWORKCONNECTION_H_ 9 #define NT_NETWORKCONNECTION_H_ 16 #include "support/ConcurrentQueue.h" 17 #include "INetworkConnection.h" 19 #include "ntcore_cpp.h" 28 class IConnectionNotifier;
32 typedef std::function<bool(
34 std::function<std::shared_ptr<Message>()> get_msg,
35 std::function<
void(
llvm::ArrayRef<std::shared_ptr<Message>>)> send_msgs)>
37 typedef std::function<void(std::shared_ptr<Message> msg,
40 typedef std::vector<std::shared_ptr<Message>> Outgoing;
44 std::unique_ptr<wpi::NetworkStream> stream,
46 HandshakeFunc handshake,
47 Message::GetEntryTypeFunc get_entry_type);
51 void set_process_incoming(ProcessIncomingFunc func) {
52 m_process_incoming = func;
60 bool active()
const {
return m_active; }
63 void QueueOutgoing(std::shared_ptr<Message> msg)
override;
64 void PostOutgoing(
bool keep_alive)
override;
66 unsigned int uid()
const {
return m_uid; }
68 unsigned int proto_rev()
const override;
69 void set_proto_rev(
unsigned int proto_rev)
override;
71 State state()
const override;
72 void set_state(State state)
override;
74 std::string remote_id()
const;
77 unsigned long long last_update()
const {
return m_last_update; }
83 void ReadThreadMain();
84 void WriteThreadMain();
87 std::unique_ptr<wpi::NetworkStream> m_stream;
90 OutgoingQueue m_outgoing;
91 HandshakeFunc m_handshake;
92 Message::GetEntryTypeFunc m_get_entry_type;
93 ProcessIncomingFunc m_process_incoming;
94 std::thread m_read_thread;
95 std::thread m_write_thread;
96 std::atomic_bool m_active;
97 std::atomic_uint m_proto_rev;
98 mutable std::mutex m_state_mutex;
100 mutable std::mutex m_remote_id_mutex;
101 std::string m_remote_id;
102 std::atomic_ullong m_last_update;
103 std::chrono::steady_clock::time_point m_last_post;
105 std::mutex m_pending_mutex;
106 Outgoing m_pending_outgoing;
107 std::vector<std::pair<std::size_t, std::size_t>> m_pending_update;
110 std::mutex m_shutdown_mutex;
111 std::condition_variable m_read_shutdown_cv;
112 std::condition_variable m_write_shutdown_cv;
113 bool m_read_shutdown =
false;
114 bool m_write_shutdown =
false;
119 #endif // NT_NETWORKCONNECTION_H_ NetworkTables Connection Information.
Definition: ntcore_cpp.h:57
Definition: NetworkStream.h:17
Definition: IConnectionNotifier.h:17
Definition: SocketError.cpp:18
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory)...
Definition: ArrayRef.h:32
Definition: NetworkConnection.h:30
Definition: IEntryNotifier.h:15
Definition: INetworkConnection.h:18
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:42