8 #ifndef NTCORE_DISPATCHER_H_ 9 #define NTCORE_DISPATCHER_H_ 20 #include <wpi/StringRef.h> 21 #include <wpi/Twine.h> 22 #include <wpi/condition_variable.h> 23 #include <wpi/mutex.h> 25 #include "IDispatcher.h" 26 #include "INetworkConnection.h" 30 class NetworkAcceptor;
36 class IConnectionNotifier;
38 class NetworkConnection;
41 friend class DispatcherTest;
44 typedef std::function<std::unique_ptr<wpi::NetworkStream>()> Connector;
48 virtual ~DispatcherBase();
52 std::unique_ptr<wpi::NetworkAcceptor> acceptor);
56 void SetIdentity(
const Twine& name);
61 unsigned int AddListener(
63 bool immediate_notify)
const;
64 unsigned int AddPolledListener(
unsigned int poller_uid,
65 bool immediate_notify)
const;
67 void SetConnector(Connector connector);
68 void SetConnectorOverride(Connector connector);
69 void ClearConnectorOverride();
71 bool active()
const {
return m_active; }
73 DispatcherBase(
const DispatcherBase&) =
delete;
74 DispatcherBase& operator=(
const DispatcherBase&) =
delete;
77 void DispatchThreadMain();
78 void ServerThreadMain();
79 void ClientThreadMain();
83 std::function<std::shared_ptr<Message>()> get_msg,
84 std::function<
void(
wpi::ArrayRef<std::shared_ptr<Message>>)> send_msgs);
87 std::function<std::shared_ptr<Message>()> get_msg,
88 std::function<
void(
wpi::ArrayRef<std::shared_ptr<Message>>)> send_msgs);
90 void ClientReconnect(
unsigned int proto_rev = 0x0300);
97 unsigned int m_networkMode = NT_NET_MODE_NONE;
98 std::string m_persist_filename;
99 std::thread m_dispatch_thread;
100 std::thread m_clientserver_thread;
102 std::unique_ptr<wpi::NetworkAcceptor> m_server_acceptor;
103 Connector m_client_connector_override;
104 Connector m_client_connector;
105 uint8_t m_connections_uid = 0;
108 mutable wpi::mutex m_user_mutex;
109 std::vector<std::shared_ptr<INetworkConnection>> m_connections;
110 std::string m_identity;
112 std::atomic_bool m_active;
113 std::atomic_uint m_update_rate;
116 wpi::mutex m_flush_mutex;
117 wpi::condition_variable m_flush_cv;
118 std::chrono::steady_clock::time_point m_last_flush;
119 bool m_do_flush =
false;
122 wpi::condition_variable m_reconnect_cv;
123 unsigned int m_reconnect_proto_rev = 0x0300;
124 bool m_do_reconnect =
true;
131 friend class DispatcherTest;
141 void SetServer(
const char* server_name,
unsigned int port);
145 void SetServerOverride(
const char* server_name,
unsigned int port);
146 void ClearServerOverride();
151 #endif // NTCORE_DISPATCHER_H_ Definition: Dispatcher.h:40
std::vector< ConnectionInfo > GetConnections()
Get information on the currently established network connections.
Definition: ntcore_cpp.cpp:893
void SetUpdateRate(double interval)
Set the periodic update rate.
Definition: ntcore_cpp.cpp:873
void SetServer(const char *server_name, unsigned int port)
Sets server address and port for client (without restarting client).
Definition: ntcore_cpp.cpp:823
Definition: Dispatcher.h:130
void Flush()
Flush Entries.
Definition: ntcore_cpp.cpp:884
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: IStorage.h:26
Definition: NetworkConnection.h:38
bool IsConnected(NT_Inst inst)
Return whether or not the instance is connected to another node.
Definition: ntcore_cpp.cpp:904
Definition: IStorage.h:21
NetworkTables Connection Notification.
Definition: ntcore_cpp.h:212
unsigned int GetNetworkMode()
Get the current network mode.
Definition: ntcore_cpp.cpp:734
void SetServerTeam(NT_Inst inst, unsigned int team, unsigned int port)
Sets server addresses and port for client (without restarting client).
Definition: ntcore_cpp.cpp:846
void StartServer(StringRef persist_filename, const char *listen_address, unsigned int port)
Starts a server using the specified filename, listening address, and port.
Definition: ntcore_cpp.cpp:745
Definition: IDispatcher.h:21
Definition: INetworkConnection.h:18
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
Definition: Twine.h:79
void StartClient()
Starts a client.
Definition: ntcore_cpp.cpp:768