WPILibC++  unspecified
ntcore_cpp.h
1 /*----------------------------------------------------------------------------*/
2 /* Copyright (c) 2015-2018 FIRST. All Rights Reserved. */
3 /* Open Source Software - may be modified and shared by FRC teams. The code */
4 /* must be accompanied by the FIRST BSD license file in the root directory of */
5 /* the project. */
6 /*----------------------------------------------------------------------------*/
7 
8 #ifndef NTCORE_NTCORE_CPP_H_
9 #define NTCORE_NTCORE_CPP_H_
10 
11 #include <stdint.h>
12 
13 #include <cassert>
14 #include <functional>
15 #include <memory>
16 #include <string>
17 #include <thread>
18 #include <utility>
19 #include <vector>
20 
21 #include <wpi/ArrayRef.h>
22 #include <wpi/StringRef.h>
23 #include <wpi/Twine.h>
24 #include <wpi/deprecated.h>
25 
26 #include "networktables/NetworkTableValue.h"
27 
28 namespace nt {
29 
30 using wpi::ArrayRef;
31 using wpi::StringRef;
32 using wpi::Twine;
33 
35 struct EntryInfo {
37  NT_Entry entry;
38 
40  std::string name;
41 
43  NT_Type type;
44 
46  unsigned int flags;
47 
49  uint64_t last_change;
50 
51  friend void swap(EntryInfo& first, EntryInfo& second) {
52  using std::swap;
53  swap(first.entry, second.entry);
54  swap(first.name, second.name);
55  swap(first.type, second.type);
56  swap(first.flags, second.flags);
57  swap(first.last_change, second.last_change);
58  }
59 };
60 
67  std::string remote_id;
68 
70  std::string remote_ip;
71 
73  unsigned int remote_port;
74 
79  uint64_t last_update;
80 
85  unsigned int protocol_version;
86 
87  friend void swap(ConnectionInfo& first, ConnectionInfo& second) {
88  using std::swap;
89  swap(first.remote_id, second.remote_id);
90  swap(first.remote_ip, second.remote_ip);
91  swap(first.remote_port, second.remote_port);
92  swap(first.last_update, second.last_update);
93  swap(first.protocol_version, second.protocol_version);
94  }
95 };
96 
98 struct RpcParamDef {
99  RpcParamDef() = default;
100  RpcParamDef(StringRef name_, std::shared_ptr<Value> def_value_)
101  : name(name_), def_value(def_value_) {}
102 
103  std::string name;
104  std::shared_ptr<Value> def_value;
105 };
106 
108 struct RpcResultDef {
109  RpcResultDef() = default;
110  RpcResultDef(StringRef name_, NT_Type type_) : name(name_), type(type_) {}
111 
112  std::string name;
113  NT_Type type;
114 };
115 
118  unsigned int version;
119  std::string name;
120  std::vector<RpcParamDef> params;
121  std::vector<RpcResultDef> results;
122 };
123 
125 class RpcAnswer {
126  public:
127  RpcAnswer() : entry(0), call(0) {}
128  RpcAnswer(NT_Entry entry_, NT_RpcCall call_, StringRef name_,
129  StringRef params_, const ConnectionInfo& conn_)
130  : entry(entry_), call(call_), name(name_), params(params_), conn(conn_) {}
131 
133  NT_Entry entry;
134 
136  mutable NT_RpcCall call;
137 
139  std::string name;
140 
142  std::string params;
143 
146 
151  explicit operator bool() const { return call != 0; }
152 
158  bool PostResponse(StringRef result) const;
159 
160  friend void swap(RpcAnswer& first, RpcAnswer& second) {
161  using std::swap;
162  swap(first.entry, second.entry);
163  swap(first.call, second.call);
164  swap(first.name, second.name);
165  swap(first.params, second.params);
166  swap(first.conn, second.conn);
167  }
168 };
169 
172  public:
173  EntryNotification() : listener(0), entry(0) {}
174  EntryNotification(NT_EntryListener listener_, NT_Entry entry_,
175  StringRef name_, std::shared_ptr<Value> value_,
176  unsigned int flags_)
177  : listener(listener_),
178  entry(entry_),
179  name(name_),
180  value(value_),
181  flags(flags_) {}
182 
184  NT_EntryListener listener;
185 
187  NT_Entry entry;
188 
190  std::string name;
191 
193  std::shared_ptr<Value> value;
194 
199  unsigned int flags;
200 
201  friend void swap(EntryNotification& first, EntryNotification& second) {
202  using std::swap;
203  swap(first.listener, second.listener);
204  swap(first.entry, second.entry);
205  swap(first.name, second.name);
206  swap(first.value, second.value);
207  swap(first.flags, second.flags);
208  }
209 };
210 
213  public:
214  ConnectionNotification() : listener(0), connected(false) {}
215  ConnectionNotification(NT_ConnectionListener listener_, bool connected_,
216  const ConnectionInfo& conn_)
217  : listener(listener_), connected(connected_), conn(conn_) {}
218 
220  NT_ConnectionListener listener;
221 
223  bool connected = false;
224 
227 
228  friend void swap(ConnectionNotification& first,
229  ConnectionNotification& second) {
230  using std::swap;
231  swap(first.listener, second.listener);
232  swap(first.connected, second.connected);
233  swap(first.conn, second.conn);
234  }
235 };
236 
238 class LogMessage {
239  public:
240  LogMessage() : logger(0), level(0), filename(""), line(0) {}
241  LogMessage(NT_Logger logger_, unsigned int level_, const char* filename_,
242  unsigned int line_, StringRef message_)
243  : logger(logger_),
244  level(level_),
245  filename(filename_),
246  line(line_),
247  message(message_) {}
248 
250  NT_Logger logger;
251 
253  unsigned int level;
254 
256  const char* filename;
257 
259  unsigned int line;
260 
262  std::string message;
263 
264  friend void swap(LogMessage& first, LogMessage& second) {
265  using std::swap;
266  swap(first.logger, second.logger);
267  swap(first.level, second.level);
268  swap(first.filename, second.filename);
269  swap(first.line, second.line);
270  swap(first.message, second.message);
271  }
272 };
273 
284 NT_Inst GetDefaultInstance();
285 
290 NT_Inst CreateInstance();
291 
297 void DestroyInstance(NT_Inst inst);
298 
304 NT_Inst GetInstanceFromHandle(NT_Handle handle);
305 
319 NT_Entry GetEntry(NT_Inst inst, const Twine& name);
320 
334 std::vector<NT_Entry> GetEntries(NT_Inst inst, const Twine& prefix,
335  unsigned int types);
336 
343 std::string GetEntryName(NT_Entry entry);
344 
350 NT_Type GetEntryType(NT_Entry entry);
351 
358 uint64_t GetEntryLastChange(NT_Entry entry);
359 
368 WPI_DEPRECATED("use NT_Entry function instead")
369 std::shared_ptr<Value> GetEntryValue(StringRef name);
370 
379 std::shared_ptr<Value> GetEntryValue(NT_Entry entry);
380 
391 WPI_DEPRECATED("use NT_Entry function instead")
392 bool SetDefaultEntryValue(StringRef name, std::shared_ptr<Value> value);
393 
404 bool SetDefaultEntryValue(NT_Entry entry, std::shared_ptr<Value> value);
405 
415 WPI_DEPRECATED("use NT_Entry function instead")
416 bool SetEntryValue(StringRef name, std::shared_ptr<Value> value);
417 
427 bool SetEntryValue(NT_Entry entry, std::shared_ptr<Value> value);
428 
441 WPI_DEPRECATED("use NT_Entry function instead")
442 void SetEntryTypeValue(StringRef name, std::shared_ptr<Value> value);
443 
456 void SetEntryTypeValue(NT_Entry entry, std::shared_ptr<Value> value);
457 
463 WPI_DEPRECATED("use NT_Entry function instead")
464 void SetEntryFlags(StringRef name, unsigned int flags);
465 
471 void SetEntryFlags(NT_Entry entry, unsigned int flags);
472 
478 WPI_DEPRECATED("use NT_Entry function instead")
479 unsigned int GetEntryFlags(StringRef name);
480 
486 unsigned int GetEntryFlags(NT_Entry entry);
487 
500 WPI_DEPRECATED("use NT_Entry function instead")
501 void DeleteEntry(StringRef name);
502 
515 void DeleteEntry(NT_Entry entry);
516 
527 WPI_DEPRECATED("use NT_Inst function instead")
528 void DeleteAllEntries();
529 
535 void DeleteAllEntries(NT_Inst inst);
536 
550 WPI_DEPRECATED("use NT_Inst function instead")
551 std::vector<EntryInfo> GetEntryInfo(StringRef prefix, unsigned int types);
552 
558 std::vector<EntryInfo> GetEntryInfo(NT_Inst inst, const Twine& prefix,
559  unsigned int types);
560 
569 EntryInfo GetEntryInfo(NT_Entry entry);
570 
589 typedef std::function<void(NT_EntryListener entry_listener, StringRef name,
590  std::shared_ptr<Value> value, unsigned int flags)>
592 
601 WPI_DEPRECATED("use NT_Inst function instead")
602 NT_EntryListener AddEntryListener(StringRef prefix,
603  EntryListenerCallback callback,
604  unsigned int flags);
605 
610 NT_EntryListener AddEntryListener(
611  NT_Inst inst, const Twine& prefix,
612  std::function<void(const EntryNotification& event)> callback,
613  unsigned int flags);
614 
623 NT_EntryListener AddEntryListener(
624  NT_Entry entry,
625  std::function<void(const EntryNotification& event)> callback,
626  unsigned int flags);
627 
637 NT_EntryListenerPoller CreateEntryListenerPoller(NT_Inst inst);
638 
644 void DestroyEntryListenerPoller(NT_EntryListenerPoller poller);
645 
654 NT_EntryListener AddPolledEntryListener(NT_EntryListenerPoller poller,
655  const Twine& prefix,
656  unsigned int flags);
657 
666 NT_EntryListener AddPolledEntryListener(NT_EntryListenerPoller poller,
667  NT_Entry entry, unsigned int flags);
668 
677 std::vector<EntryNotification> PollEntryListener(NT_EntryListenerPoller poller);
678 
691 std::vector<EntryNotification> PollEntryListener(NT_EntryListenerPoller poller,
692  double timeout,
693  bool* timed_out);
694 
701 void CancelPollEntryListener(NT_EntryListenerPoller poller);
702 
707 void RemoveEntryListener(NT_EntryListener entry_listener);
708 
719 bool WaitForEntryListenerQueue(NT_Inst inst, double timeout);
720 
737 typedef std::function<void(NT_ConnectionListener conn_listener, bool connected,
738  const ConnectionInfo& conn)>
740 
748 WPI_DEPRECATED("use NT_Inst function instead")
749 NT_ConnectionListener AddConnectionListener(ConnectionListenerCallback callback,
750  bool immediate_notify);
751 
756 NT_ConnectionListener AddConnectionListener(
757  NT_Inst inst,
758  std::function<void(const ConnectionNotification& event)> callback,
759  bool immediate_notify);
760 
770 NT_ConnectionListenerPoller CreateConnectionListenerPoller(NT_Inst inst);
771 
777 void DestroyConnectionListenerPoller(NT_ConnectionListenerPoller poller);
778 
785 NT_ConnectionListener AddPolledConnectionListener(
786  NT_ConnectionListenerPoller poller, bool immediate_notify);
787 
798  NT_ConnectionListenerPoller poller);
799 
813  NT_ConnectionListenerPoller poller, double timeout, bool* timed_out);
814 
821 void CancelPollConnectionListener(NT_ConnectionListenerPoller poller);
822 
827 void RemoveConnectionListener(NT_ConnectionListener conn_listener);
828 
839 bool WaitForConnectionListenerQueue(NT_Inst inst, double timeout);
840 
856 void CreateRpc(NT_Entry entry, StringRef def,
857  std::function<void(const RpcAnswer& answer)> callback);
858 
868 NT_RpcCallPoller CreateRpcCallPoller(NT_Inst inst);
869 
875 void DestroyRpcCallPoller(NT_RpcCallPoller poller);
876 
885 void CreatePolledRpc(NT_Entry entry, StringRef def, NT_RpcCallPoller poller);
886 
897 std::vector<RpcAnswer> PollRpc(NT_RpcCallPoller poller);
898 
912 std::vector<RpcAnswer> PollRpc(NT_RpcCallPoller poller, double timeout,
913  bool* timed_out);
914 
920 void CancelPollRpc(NT_RpcCallPoller poller);
921 
932 bool WaitForRpcCallQueue(NT_Inst inst, double timeout);
933 
943 bool PostRpcResponse(NT_Entry entry, NT_RpcCall call, StringRef result);
944 
955 NT_RpcCall CallRpc(NT_Entry entry, StringRef params);
956 
965 bool GetRpcResult(NT_Entry entry, NT_RpcCall call, std::string* result);
966 
977 bool GetRpcResult(NT_Entry entry, NT_RpcCall call, std::string* result,
978  double timeout, bool* timed_out);
979 
985 void CancelRpcResult(NT_Entry entry, NT_RpcCall call);
986 
992 std::string PackRpcDefinition(const RpcDefinition& def);
993 
1001 bool UnpackRpcDefinition(StringRef packed, RpcDefinition* def);
1002 
1008 std::string PackRpcValues(ArrayRef<std::shared_ptr<Value>> values);
1009 
1016 std::vector<std::shared_ptr<Value>> UnpackRpcValues(StringRef packed,
1017  ArrayRef<NT_Type> types);
1018 
1032 WPI_DEPRECATED("use NT_Inst function instead")
1033 void SetNetworkIdentity(StringRef name);
1034 
1039 void SetNetworkIdentity(NT_Inst inst, const Twine& name);
1040 
1045 WPI_DEPRECATED("use NT_Inst function instead")
1046 unsigned int GetNetworkMode();
1047 
1053 unsigned int GetNetworkMode(NT_Inst inst);
1054 
1064 WPI_DEPRECATED("use NT_Inst function instead")
1065 void StartServer(StringRef persist_filename, const char* listen_address,
1066  unsigned int port);
1067 
1072 void StartServer(NT_Inst inst, const Twine& persist_filename,
1073  const char* listen_address, unsigned int port);
1074 
1078 WPI_DEPRECATED("use NT_Inst function instead")
1079 void StopServer();
1080 
1085 void StopServer(NT_Inst inst);
1086 
1090 WPI_DEPRECATED("use NT_Inst function instead")
1091 void StartClient();
1092 
1099 WPI_DEPRECATED("use NT_Inst function instead")
1100 void StartClient(const char* server_name, unsigned int port);
1101 
1108 WPI_DEPRECATED("use NT_Inst function instead")
1109 void StartClient(ArrayRef<std::pair<StringRef, unsigned int>> servers);
1110 
1115 void StartClient(NT_Inst inst);
1116 
1121 void StartClient(NT_Inst inst, const char* server_name, unsigned int port);
1122 
1127 void StartClient(NT_Inst inst,
1128  ArrayRef<std::pair<StringRef, unsigned int>> servers);
1129 
1138 void StartClientTeam(NT_Inst inst, unsigned int team, unsigned int port);
1139 
1143 WPI_DEPRECATED("use NT_Inst function instead")
1144 void StopClient();
1145 
1150 void StopClient(NT_Inst inst);
1151 
1158 WPI_DEPRECATED("use NT_Inst function instead")
1159 void SetServer(const char* server_name, unsigned int port);
1160 
1167 WPI_DEPRECATED("use NT_Inst function instead")
1168 void SetServer(ArrayRef<std::pair<StringRef, unsigned int>> servers);
1169 
1174 void SetServer(NT_Inst inst, const char* server_name, unsigned int port);
1175 
1180 void SetServer(NT_Inst inst,
1181  ArrayRef<std::pair<StringRef, unsigned int>> servers);
1182 
1191 void SetServerTeam(NT_Inst inst, unsigned int team, unsigned int port);
1192 
1200 WPI_DEPRECATED("use NT_Inst function instead")
1201 void StartDSClient(unsigned int port);
1202 
1207 void StartDSClient(NT_Inst inst, unsigned int port);
1208 
1210 WPI_DEPRECATED("use NT_Inst function instead")
1211 void StopDSClient();
1212 
1217 void StopDSClient(NT_Inst inst);
1218 
1220 WPI_DEPRECATED("use NT_Inst function instead")
1221 void StopRpcServer();
1222 
1229 WPI_DEPRECATED("use NT_Inst function instead")
1230 void SetUpdateRate(double interval);
1231 
1236 void SetUpdateRate(NT_Inst inst, double interval);
1237 
1248 WPI_DEPRECATED("use NT_Inst function instead")
1249 void Flush();
1250 
1256 void Flush(NT_Inst inst);
1257 
1264 WPI_DEPRECATED("use NT_Inst function instead")
1265 std::vector<ConnectionInfo> GetConnections();
1266 
1271 std::vector<ConnectionInfo> GetConnections(NT_Inst inst);
1272 
1278 bool IsConnected(NT_Inst inst);
1279 
1294 WPI_DEPRECATED("use NT_Inst function instead")
1295 const char* SavePersistent(StringRef filename);
1296 
1301 const char* SavePersistent(NT_Inst inst, const Twine& filename);
1302 
1311 WPI_DEPRECATED("use NT_Inst function instead")
1312 const char* LoadPersistent(
1313  StringRef filename, std::function<void(size_t line, const char* msg)> warn);
1314 
1320 const char* LoadPersistent(
1321  NT_Inst inst, const Twine& filename,
1322  std::function<void(size_t line, const char* msg)> warn);
1323 
1332 const char* SaveEntries(NT_Inst inst, const Twine& filename,
1333  const Twine& prefix);
1334 
1344 const char* LoadEntries(NT_Inst inst, const Twine& filename,
1345  const Twine& prefix,
1346  std::function<void(size_t line, const char* msg)> warn);
1347 
1361 uint64_t Now();
1362 
1377 typedef std::function<void(unsigned int level, const char* file,
1378  unsigned int line, const char* msg)>
1380 
1391 WPI_DEPRECATED("use NT_Inst function instead")
1392 void SetLogger(LogFunc func, unsigned int min_level);
1393 
1407 NT_Logger AddLogger(NT_Inst inst,
1408  std::function<void(const LogMessage& msg)> func,
1409  unsigned int min_level, unsigned int max_level);
1410 
1417 NT_LoggerPoller CreateLoggerPoller(NT_Inst inst);
1418 
1424 void DestroyLoggerPoller(NT_LoggerPoller poller);
1425 
1435 NT_Logger AddPolledLogger(NT_LoggerPoller poller, unsigned int min_level,
1436  unsigned int max_level);
1437 
1444 std::vector<LogMessage> PollLogger(NT_LoggerPoller poller);
1445 
1456 std::vector<LogMessage> PollLogger(NT_LoggerPoller poller, double timeout,
1457  bool* timed_out);
1458 
1464 void CancelPollLogger(NT_LoggerPoller poller);
1465 
1470 void RemoveLogger(NT_Logger logger);
1471 
1482 bool WaitForLoggerQueue(NT_Inst inst, double timeout);
1483 
1486 inline bool RpcAnswer::PostResponse(StringRef result) const {
1487  auto ret = PostRpcResponse(entry, call, result);
1488  call = 0;
1489  return ret;
1490 }
1491 
1492 } // namespace nt
1493 
1494 #endif // NTCORE_NTCORE_CPP_H_
const char * SaveEntries(NT_Inst inst, const Twine &filename, const Twine &prefix)
Save table values to a file.
Definition: ntcore_cpp.cpp:941
NetworkTables Connection Information.
Definition: ntcore_cpp.h:62
void DestroyRpcCallPoller(NT_RpcCallPoller poller)
Destroy a RPC call poller.
Definition: ntcore_cpp.cpp:500
std::vector< ConnectionInfo > GetConnections()
Get information on the currently established network connections.
Definition: ntcore_cpp.cpp:893
void SetEntryFlags(StringRef name, unsigned int flags)
Set Entry Flags.
Definition: ntcore_cpp.cpp:157
bool SetEntryValue(StringRef name, std::shared_ptr< Value > value)
Set Entry Value.
Definition: ntcore_cpp.cpp:131
std::function< void(unsigned int level, const char *file, unsigned int line, const char *msg)> LogFunc
Log function.
Definition: ntcore_cpp.h:1379
unsigned int remote_port
The port number of the remote node.
Definition: ntcore_cpp.h:73
void SetUpdateRate(double interval)
Set the periodic update rate.
Definition: ntcore_cpp.cpp:873
bool WaitForEntryListenerQueue(NT_Inst inst, double timeout)
Wait for the entry listener queue to be empty.
Definition: ntcore_cpp.cpp:368
void SetServer(const char *server_name, unsigned int port)
Sets server address and port for client (without restarting client).
Definition: ntcore_cpp.cpp:823
NT_EntryListenerPoller CreateEntryListenerPoller(NT_Inst inst)
Create a entry listener poller.
Definition: ntcore_cpp.cpp:279
void CreatePolledRpc(NT_Entry entry, StringRef def, NT_RpcCallPoller poller)
Create a polled RPC entry point.
Definition: ntcore_cpp.cpp:509
std::string name
Entry name.
Definition: ntcore_cpp.h:190
std::string remote_id
The remote identifier (as set on the remote node by NetworkTableInstance::SetNetworkIdentity() or nt:...
Definition: ntcore_cpp.h:67
unsigned int GetEntryFlags(StringRef name)
Get Entry Flags.
Definition: ntcore_cpp.cpp:170
NetworkTables log message.
Definition: ntcore_cpp.h:238
std::vector< LogMessage > PollLogger(NT_LoggerPoller poller)
Get the next log event.
Definition: ntcore_cpp.cpp:1015
void DestroyInstance(NT_Inst inst)
Destroy an instance.
Definition: ntcore_cpp.cpp:37
void CancelPollRpc(NT_RpcCallPoller poller)
Cancel a PollRpc call.
Definition: ntcore_cpp.cpp:547
NetworkTables RPC Version 1 Definition.
Definition: ntcore_cpp.h:117
std::function< void(NT_EntryListener entry_listener, StringRef name, std::shared_ptr< Value > value, unsigned int flags)> EntryListenerCallback
Entry listener callback function.
Definition: ntcore_cpp.h:591
bool SetDefaultEntryValue(StringRef name, std::shared_ptr< Value > value)
Set Default Entry Value Returns copy of current entry value if it exists.
Definition: ntcore_cpp.cpp:118
void StopRpcServer()
Stops the RPC server if it is running.
NT_Inst GetInstanceFromHandle(NT_Handle handle)
Get instance handle from another handle.
Definition: ntcore_cpp.cpp:43
bool connected
True if event is due to connection being established.
Definition: ntcore_cpp.h:223
NetworkTables Remote Procedure Call (Server Side)
Definition: ntcore_cpp.h:125
void RemoveLogger(NT_Logger logger)
Remove a logger.
Definition: ntcore_cpp.cpp:1045
NT_Type type
Entry type.
Definition: ntcore_cpp.h:43
NT_LoggerPoller CreateLoggerPoller(NT_Inst inst)
Create a log poller.
Definition: ntcore_cpp.cpp:984
NetworkTables Entry Notification.
Definition: ntcore_cpp.h:171
Definition: SmallVector.h:946
ConnectionInfo conn
Connection that called the RPC.
Definition: ntcore_cpp.h:145
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
NT_Entry entry
Entry handle.
Definition: ntcore_cpp.h:133
NT_ConnectionListener listener
Listener that was triggered.
Definition: ntcore_cpp.h:220
void RemoveConnectionListener(NT_ConnectionListener conn_listener)
Remove a connection listener.
Definition: ntcore_cpp.cpp:458
NT_RpcCall call
Call handle.
Definition: ntcore_cpp.h:136
NT_Entry entry
Entry handle.
Definition: ntcore_cpp.h:37
NT_Inst GetDefaultInstance()
Get default instance.
Definition: ntcore_cpp.cpp:29
NT_EntryListener AddEntryListener(StringRef prefix, EntryListenerCallback callback, unsigned int flags)
Add a listener for all entries starting with a certain prefix.
Definition: ntcore_cpp.cpp:242
void CancelPollLogger(NT_LoggerPoller poller)
Cancel a PollLogger call.
Definition: ntcore_cpp.cpp:1036
void CancelRpcResult(NT_Entry entry, NT_RpcCall call)
Ignore the result of a RPC call.
Definition: ntcore_cpp.cpp:619
std::vector< std::shared_ptr< Value > > UnpackRpcValues(StringRef packed, ArrayRef< NT_Type > types)
Unpack RPC values as required for RPC version 1 definition messages.
Definition: ntcore_cpp.cpp:703
NT_Entry entry
Entry handle.
Definition: ntcore_cpp.h:187
NT_Entry GetEntry(NT_Inst inst, const Twine &name)
Get Entry Handle.
Definition: ntcore_cpp.cpp:56
const char * LoadEntries(NT_Inst inst, const Twine &filename, const Twine &prefix, std::function< void(size_t line, const char *msg)> warn)
Load table values from a file.
Definition: ntcore_cpp.cpp:949
NT_RpcCall CallRpc(NT_Entry entry, StringRef params)
Call a RPC function.
Definition: ntcore_cpp.cpp:577
void SetEntryTypeValue(StringRef name, std::shared_ptr< Value > value)
Set Entry Type and Value.
Definition: ntcore_cpp.cpp:144
const char * LoadPersistent(StringRef filename, std::function< void(size_t line, const char *msg)> warn)
Load persistent values from a file.
Definition: ntcore_cpp.cpp:926
void CreateRpc(NT_Entry entry, StringRef def, std::function< void(const RpcAnswer &answer)> callback)
Create a callback-based RPC entry point.
Definition: ntcore_cpp.cpp:478
void DestroyLoggerPoller(NT_LoggerPoller poller)
Destroy a log poller.
Definition: ntcore_cpp.cpp:992
NT_ConnectionListenerPoller CreateConnectionListenerPoller(NT_Inst inst)
Create a connection listener poller.
Definition: ntcore_cpp.cpp:397
std::vector< NT_Entry > GetEntries(NT_Inst inst, const Twine &prefix, unsigned int types)
Get Entry Handles.
Definition: ntcore_cpp.cpp:66
std::string params
Call raw parameters.
Definition: ntcore_cpp.h:142
void StopServer()
Stops the server if it is running.
Definition: ntcore_cpp.cpp:759
std::vector< RpcAnswer > PollRpc(NT_RpcCallPoller poller)
Get the next incoming RPC call.
Definition: ntcore_cpp.cpp:527
void StartDSClient(unsigned int port)
Starts requesting server address from Driver Station.
Definition: ntcore_cpp.cpp:853
void StopDSClient()
Stops requesting server address from Driver Station.
Definition: ntcore_cpp.cpp:864
bool IsConnected(NT_Inst inst)
Return whether or not the instance is connected to another node.
Definition: ntcore_cpp.cpp:904
std::shared_ptr< Value > value
The new value.
Definition: ntcore_cpp.h:193
std::vector< ConnectionNotification > PollConnectionListener(NT_ConnectionListenerPoller poller)
Get the next connection event.
Definition: ntcore_cpp.cpp:427
Definition: IStorage.h:21
uint64_t Now()
Returns monotonic current time in 1 us increments.
Definition: ntcore_cpp.cpp:717
std::string message
The message.
Definition: ntcore_cpp.h:262
bool PostRpcResponse(NT_Entry entry, NT_RpcCall call, StringRef result)
Post RPC response (return value) for a polled RPC.
Definition: ntcore_cpp.cpp:563
void SetNetworkIdentity(StringRef name)
Set the network identity of this node.
Definition: ntcore_cpp.cpp:723
NetworkTables RPC Version 1 Definition Parameter.
Definition: ntcore_cpp.h:98
NT_RpcCallPoller CreateRpcCallPoller(NT_Inst inst)
Create a RPC call poller.
Definition: ntcore_cpp.cpp:492
void DestroyConnectionListenerPoller(NT_ConnectionListenerPoller poller)
Destroy a connection listener poller.
Definition: ntcore_cpp.cpp:406
void SetLogger(LogFunc func, unsigned int min_level)
Set logger callback function.
Definition: ntcore_cpp.cpp:958
NT_Type GetEntryType(NT_Entry entry)
Gets the type for the specified entry, or unassigned if non existent.
Definition: ntcore_cpp.cpp:87
bool WaitForConnectionListenerQueue(NT_Inst inst, double timeout)
Wait for the connection listener queue to be empty.
Definition: ntcore_cpp.cpp:467
NetworkTables Entry Information.
Definition: ntcore_cpp.h:35
NT_EntryListener AddPolledEntryListener(NT_EntryListenerPoller poller, const Twine &prefix, unsigned int flags)
Create a polled entry listener.
Definition: ntcore_cpp.cpp:297
NetworkTables Connection Notification.
Definition: ntcore_cpp.h:212
std::string name
Entry name.
Definition: ntcore_cpp.h:40
void CancelPollConnectionListener(NT_ConnectionListenerPoller poller)
Cancel a PollConnectionListener call.
Definition: ntcore_cpp.cpp:449
unsigned int GetNetworkMode()
Get the current network mode.
Definition: ntcore_cpp.cpp:734
bool WaitForRpcCallQueue(NT_Inst inst, double timeout)
Wait for the incoming RPC call queue to be empty.
Definition: ntcore_cpp.cpp:556
std::vector< EntryInfo > GetEntryInfo(StringRef prefix, unsigned int types)
Get Entry Information.
Definition: ntcore_cpp.cpp:208
ConnectionInfo conn
Connection info.
Definition: ntcore_cpp.h:226
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
std::vector< EntryNotification > PollEntryListener(NT_EntryListenerPoller poller)
Get the next entry listener event.
Definition: ntcore_cpp.cpp:327
NT_ConnectionListener AddConnectionListener(ConnectionListenerCallback callback, bool immediate_notify)
Add a connection listener.
Definition: ntcore_cpp.cpp:375
const char * SavePersistent(StringRef filename)
Save persistent values to a file.
Definition: ntcore_cpp.cpp:915
unsigned int protocol_version
The protocol version being used for this connection.
Definition: ntcore_cpp.h:85
std::string PackRpcValues(ArrayRef< std::shared_ptr< Value >> values)
Pack RPC values as required for RPC version 1 definition messages.
Definition: ntcore_cpp.cpp:697
void CancelPollEntryListener(NT_EntryListenerPoller poller)
Cancel a PollEntryListener call.
Definition: ntcore_cpp.cpp:350
bool UnpackRpcDefinition(StringRef packed, RpcDefinition *def)
Unpack a RPC version 1 definition.
Definition: ntcore_cpp.cpp:660
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:49
void DeleteAllEntries()
Delete All Entries.
Definition: ntcore_cpp.cpp:196
std::shared_ptr< Value > GetEntryValue(StringRef name)
Get Entry Value.
Definition: ntcore_cpp.cpp:105
std::string name
Entry name.
Definition: ntcore_cpp.h:139
unsigned int flags
Entry flags.
Definition: ntcore_cpp.h:46
NT_Inst CreateInstance()
Create an instance.
Definition: ntcore_cpp.cpp:33
NT_Logger AddLogger(NT_Inst inst, std::function< void(const LogMessage &msg)> func, unsigned int min_level, unsigned int max_level)
Add logger callback function.
Definition: ntcore_cpp.cpp:971
uint64_t GetEntryLastChange(NT_Entry entry)
Gets the last time the entry was changed.
Definition: ntcore_cpp.cpp:96
NT_EntryListener listener
Listener that was triggered.
Definition: ntcore_cpp.h:184
std::string remote_ip
The IP address of the remote node.
Definition: ntcore_cpp.h:70
bool WaitForLoggerQueue(NT_Inst inst, double timeout)
Wait for the incoming log event queue to be empty.
Definition: ntcore_cpp.cpp:1055
uint64_t last_change
Timestamp of last change to entry (type or value).
Definition: ntcore_cpp.h:49
void DestroyEntryListenerPoller(NT_EntryListenerPoller poller)
Destroy a entry listener poller.
Definition: ntcore_cpp.cpp:288
NetworkTables RPC Version 1 Definition Result.
Definition: ntcore_cpp.h:108
bool GetRpcResult(NT_Entry entry, NT_RpcCall call, std::string *result)
Get the result (return value) of a RPC call.
Definition: ntcore_cpp.cpp:589
A network table entry value.
Definition: NetworkTableValue.h:35
unsigned int line
The line number in the source file that generated the message.
Definition: ntcore_cpp.h:259
NT_Logger AddPolledLogger(NT_LoggerPoller poller, unsigned int min_level, unsigned int max_level)
Set the log level for a log poller.
Definition: ntcore_cpp.cpp:1001
std::function< void(NT_ConnectionListener conn_listener, bool connected, const ConnectionInfo &conn)> ConnectionListenerCallback
Connection listener callback function.
Definition: ntcore_cpp.h:739
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
Definition: Twine.h:79
void DeleteEntry(StringRef name)
Delete Entry.
Definition: ntcore_cpp.cpp:183
unsigned int level
Log level of the message.
Definition: ntcore_cpp.h:253
std::string PackRpcDefinition(const RpcDefinition &def)
Pack a RPC version 1 definition.
Definition: ntcore_cpp.cpp:633
NT_Logger logger
The logger that generated the message.
Definition: ntcore_cpp.h:250
NT_ConnectionListener AddPolledConnectionListener(NT_ConnectionListenerPoller poller, bool immediate_notify)
Create a polled connection listener.
Definition: ntcore_cpp.cpp:415
void StopClient()
Stops the client if it is running.
Definition: ntcore_cpp.cpp:814
void StartClient()
Starts a client.
Definition: ntcore_cpp.cpp:768
void StartClientTeam(NT_Inst inst, unsigned int team, unsigned int port)
Starts a client using commonly known robot addresses for the specified team.
Definition: ntcore_cpp.cpp:806
std::string GetEntryName(NT_Entry entry)
Gets the name of the specified entry.
Definition: ntcore_cpp.cpp:78
void RemoveEntryListener(NT_EntryListener entry_listener)
Remove an entry listener.
Definition: ntcore_cpp.cpp:359
unsigned int flags
Update flags.
Definition: ntcore_cpp.h:199
uint64_t last_update
The last time any update was received from the remote node (same scale as returned by nt::Now())...
Definition: ntcore_cpp.h:79
const char * filename
The filename of the source file that generated the message.
Definition: ntcore_cpp.h:256