8 #ifndef NTCORE_NETWORKCONNECTION_H_ 9 #define NTCORE_NETWORKCONNECTION_H_ 21 #include <wpi/ConcurrentQueue.h> 22 #include <wpi/condition_variable.h> 23 #include <wpi/mutex.h> 25 #include "INetworkConnection.h" 27 #include "ntcore_cpp.h" 36 class IConnectionNotifier;
40 typedef std::function<bool(
42 std::function<std::shared_ptr<Message>()> get_msg,
43 std::function<
void(
wpi::ArrayRef<std::shared_ptr<Message>>)> send_msgs)>
45 typedef std::function<void(std::shared_ptr<Message> msg,
48 typedef std::vector<std::shared_ptr<Message>> Outgoing;
52 std::unique_ptr<wpi::NetworkStream> stream,
54 HandshakeFunc handshake,
55 Message::GetEntryTypeFunc get_entry_type);
59 void set_process_incoming(ProcessIncomingFunc func) {
60 m_process_incoming = func;
68 bool active()
const {
return m_active; }
71 void QueueOutgoing(std::shared_ptr<Message> msg)
override;
72 void PostOutgoing(
bool keep_alive)
override;
74 unsigned int uid()
const {
return m_uid; }
76 unsigned int proto_rev()
const override;
77 void set_proto_rev(
unsigned int proto_rev)
override;
79 State state()
const override;
80 void set_state(State state)
override;
82 std::string remote_id()
const;
85 uint64_t last_update()
const {
return m_last_update; }
91 void ReadThreadMain();
92 void WriteThreadMain();
95 std::unique_ptr<wpi::NetworkStream> m_stream;
98 OutgoingQueue m_outgoing;
99 HandshakeFunc m_handshake;
100 Message::GetEntryTypeFunc m_get_entry_type;
101 ProcessIncomingFunc m_process_incoming;
102 std::thread m_read_thread;
103 std::thread m_write_thread;
104 std::atomic_bool m_active;
105 std::atomic_uint m_proto_rev;
106 mutable wpi::mutex m_state_mutex;
108 mutable wpi::mutex m_remote_id_mutex;
109 std::string m_remote_id;
110 std::atomic_ullong m_last_update;
111 std::chrono::steady_clock::time_point m_last_post;
113 wpi::mutex m_pending_mutex;
114 Outgoing m_pending_outgoing;
115 std::vector<std::pair<size_t, size_t>> m_pending_update;
118 wpi::mutex m_shutdown_mutex;
119 wpi::condition_variable m_read_shutdown_cv;
120 wpi::condition_variable m_write_shutdown_cv;
121 bool m_read_shutdown =
false;
122 bool m_write_shutdown =
false;
127 #endif // NTCORE_NETWORKCONNECTION_H_ NetworkTables Connection Information.
Definition: ntcore_cpp.h:62
Definition: NetworkStream.h:17
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory)...
Definition: ArrayRef.h:41
Definition: IConnectionNotifier.h:17
namespace to hold default to_json function
Definition: json_binary_writer.cpp:39
Definition: NetworkConnection.h:38
Definition: IStorage.h:21
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:49
Definition: INetworkConnection.h:18