WPILibC++  unspecified
ntcore_cpp.h
1 /*----------------------------------------------------------------------------*/
2 /* Copyright (c) FIRST 2015-2018. 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 <utility>
18 #include <vector>
19 
20 #include <llvm/ArrayRef.h>
21 #include <llvm/StringRef.h>
22 #include <llvm/Twine.h>
23 #include <support/deprecated.h>
24 
25 #include "networktables/NetworkTableValue.h"
26 
27 namespace nt {
28 
29 using llvm::ArrayRef;
30 using llvm::StringRef;
31 using llvm::Twine;
32 
34 struct EntryInfo {
36  NT_Entry entry;
37 
39  std::string name;
40 
42  NT_Type type;
43 
45  unsigned int flags;
46 
48  uint64_t last_change;
49 
50  friend void swap(EntryInfo& first, EntryInfo& second) {
51  using std::swap;
52  swap(first.entry, second.entry);
53  swap(first.name, second.name);
54  swap(first.type, second.type);
55  swap(first.flags, second.flags);
56  swap(first.last_change, second.last_change);
57  }
58 };
59 
66  std::string remote_id;
67 
69  std::string remote_ip;
70 
72  unsigned int remote_port;
73 
78  uint64_t last_update;
79 
84  unsigned int protocol_version;
85 
86  friend void swap(ConnectionInfo& first, ConnectionInfo& second) {
87  using std::swap;
88  swap(first.remote_id, second.remote_id);
89  swap(first.remote_ip, second.remote_ip);
90  swap(first.remote_port, second.remote_port);
91  swap(first.last_update, second.last_update);
92  swap(first.protocol_version, second.protocol_version);
93  }
94 };
95 
97 struct RpcParamDef {
98  RpcParamDef() = default;
99  RpcParamDef(StringRef name_, std::shared_ptr<Value> def_value_)
100  : name(name_), def_value(def_value_) {}
101 
102  std::string name;
103  std::shared_ptr<Value> def_value;
104 };
105 
107 struct RpcResultDef {
108  RpcResultDef() = default;
109  RpcResultDef(StringRef name_, NT_Type type_) : name(name_), type(type_) {}
110 
111  std::string name;
112  NT_Type type;
113 };
114 
117  unsigned int version;
118  std::string name;
119  std::vector<RpcParamDef> params;
120  std::vector<RpcResultDef> results;
121 };
122 
124 class RpcAnswer {
125  public:
126  RpcAnswer() : entry(0), call(0) {}
127  RpcAnswer(NT_Entry entry_, NT_RpcCall call_, StringRef name_,
128  StringRef params_, const ConnectionInfo& conn_)
129  : entry(entry_), call(call_), name(name_), params(params_), conn(conn_) {}
130 
132  NT_Entry entry;
133 
135  NT_RpcCall call;
136 
138  std::string name;
139 
141  std::string params;
142 
145 
150  explicit operator bool() const { return call != 0; }
151 
156  void PostResponse(StringRef result) const;
157 
158  friend void swap(RpcAnswer& first, RpcAnswer& second) {
159  using std::swap;
160  swap(first.entry, second.entry);
161  swap(first.call, second.call);
162  swap(first.name, second.name);
163  swap(first.params, second.params);
164  swap(first.conn, second.conn);
165  }
166 };
167 
170  public:
171  EntryNotification() : listener(0), entry(0) {}
172  EntryNotification(NT_EntryListener listener_, NT_Entry entry_,
173  StringRef name_, std::shared_ptr<Value> value_,
174  unsigned int flags_)
175  : listener(listener_),
176  entry(entry_),
177  name(name_),
178  value(value_),
179  flags(flags_) {}
180 
182  NT_EntryListener listener;
183 
185  NT_Entry entry;
186 
188  std::string name;
189 
191  std::shared_ptr<Value> value;
192 
197  unsigned int flags;
198 
199  friend void swap(EntryNotification& first, EntryNotification& second) {
200  using std::swap;
201  swap(first.listener, second.listener);
202  swap(first.entry, second.entry);
203  swap(first.name, second.name);
204  swap(first.value, second.value);
205  swap(first.flags, second.flags);
206  }
207 };
208 
211  public:
212  ConnectionNotification() : listener(0), connected(false) {}
213  ConnectionNotification(NT_ConnectionListener listener_, bool connected_,
214  const ConnectionInfo& conn_)
215  : listener(listener_), connected(connected_), conn(conn_) {}
216 
218  NT_ConnectionListener listener;
219 
221  bool connected = false;
222 
225 
226  friend void swap(ConnectionNotification& first,
227  ConnectionNotification& second) {
228  using std::swap;
229  swap(first.listener, second.listener);
230  swap(first.connected, second.connected);
231  swap(first.conn, second.conn);
232  }
233 };
234 
236 class LogMessage {
237  public:
238  LogMessage() : logger(0), level(0), filename(""), line(0) {}
239  LogMessage(NT_Logger logger_, unsigned int level_, const char* filename_,
240  unsigned int line_, StringRef message_)
241  : logger(logger_),
242  level(level_),
243  filename(filename_),
244  line(line_),
245  message(message_) {}
246 
248  NT_Logger logger;
249 
251  unsigned int level;
252 
254  const char* filename;
255 
257  unsigned int line;
258 
260  std::string message;
261 
262  friend void swap(LogMessage& first, LogMessage& second) {
263  using std::swap;
264  swap(first.logger, second.logger);
265  swap(first.level, second.level);
266  swap(first.filename, second.filename);
267  swap(first.line, second.line);
268  swap(first.message, second.message);
269  }
270 };
271 
282 NT_Inst GetDefaultInstance();
283 
288 NT_Inst CreateInstance();
289 
295 void DestroyInstance(NT_Inst inst);
296 
302 NT_Inst GetInstanceFromHandle(NT_Handle handle);
303 
317 NT_Entry GetEntry(NT_Inst inst, const Twine& name);
318 
332 std::vector<NT_Entry> GetEntries(NT_Inst inst, const Twine& prefix,
333  unsigned int types);
334 
341 std::string GetEntryName(NT_Entry entry);
342 
348 NT_Type GetEntryType(NT_Entry entry);
349 
356 uint64_t GetEntryLastChange(NT_Entry entry);
357 
366 WPI_DEPRECATED("use NT_Entry function instead")
367 std::shared_ptr<Value> GetEntryValue(StringRef name);
368 
377 std::shared_ptr<Value> GetEntryValue(NT_Entry entry);
378 
389 WPI_DEPRECATED("use NT_Entry function instead")
390 bool SetDefaultEntryValue(StringRef name, std::shared_ptr<Value> value);
391 
402 bool SetDefaultEntryValue(NT_Entry entry, std::shared_ptr<Value> value);
403 
413 WPI_DEPRECATED("use NT_Entry function instead")
414 bool SetEntryValue(StringRef name, std::shared_ptr<Value> value);
415 
425 bool SetEntryValue(NT_Entry entry, std::shared_ptr<Value> value);
426 
439 WPI_DEPRECATED("use NT_Entry function instead")
440 void SetEntryTypeValue(StringRef name, std::shared_ptr<Value> value);
441 
454 void SetEntryTypeValue(NT_Entry entry, std::shared_ptr<Value> value);
455 
461 WPI_DEPRECATED("use NT_Entry function instead")
462 void SetEntryFlags(StringRef name, unsigned int flags);
463 
469 void SetEntryFlags(NT_Entry entry, unsigned int flags);
470 
476 WPI_DEPRECATED("use NT_Entry function instead")
477 unsigned int GetEntryFlags(StringRef name);
478 
484 unsigned int GetEntryFlags(NT_Entry entry);
485 
498 WPI_DEPRECATED("use NT_Entry function instead")
499 void DeleteEntry(StringRef name);
500 
513 void DeleteEntry(NT_Entry entry);
514 
525 WPI_DEPRECATED("use NT_Inst function instead")
526 void DeleteAllEntries();
527 
533 void DeleteAllEntries(NT_Inst inst);
534 
548 WPI_DEPRECATED("use NT_Inst function instead")
549 std::vector<EntryInfo> GetEntryInfo(StringRef prefix, unsigned int types);
550 
556 std::vector<EntryInfo> GetEntryInfo(NT_Inst inst, const Twine& prefix,
557  unsigned int types);
558 
567 EntryInfo GetEntryInfo(NT_Entry entry);
568 
587 typedef std::function<void(NT_EntryListener entry_listener, StringRef name,
588  std::shared_ptr<Value> value, unsigned int flags)>
590 
599 WPI_DEPRECATED("use NT_Inst function instead")
600 NT_EntryListener AddEntryListener(StringRef prefix,
601  EntryListenerCallback callback,
602  unsigned int flags);
603 
608 NT_EntryListener AddEntryListener(
609  NT_Inst inst, const Twine& prefix,
610  std::function<void(const EntryNotification& event)> callback,
611  unsigned int flags);
612 
621 NT_EntryListener AddEntryListener(
622  NT_Entry entry,
623  std::function<void(const EntryNotification& event)> callback,
624  unsigned int flags);
625 
635 NT_EntryListenerPoller CreateEntryListenerPoller(NT_Inst inst);
636 
642 void DestroyEntryListenerPoller(NT_EntryListenerPoller poller);
643 
652 NT_EntryListener AddPolledEntryListener(NT_EntryListenerPoller poller,
653  const Twine& prefix,
654  unsigned int flags);
655 
664 NT_EntryListener AddPolledEntryListener(NT_EntryListenerPoller poller,
665  NT_Entry entry, unsigned int flags);
666 
675 std::vector<EntryNotification> PollEntryListener(NT_EntryListenerPoller poller);
676 
689 std::vector<EntryNotification> PollEntryListener(NT_EntryListenerPoller poller,
690  double timeout,
691  bool* timed_out);
692 
699 void CancelPollEntryListener(NT_EntryListenerPoller poller);
700 
705 void RemoveEntryListener(NT_EntryListener entry_listener);
706 
717 bool WaitForEntryListenerQueue(NT_Inst inst, double timeout);
718 
735 typedef std::function<void(NT_ConnectionListener conn_listener, bool connected,
736  const ConnectionInfo& conn)>
738 
746 WPI_DEPRECATED("use NT_Inst function instead")
747 NT_ConnectionListener AddConnectionListener(ConnectionListenerCallback callback,
748  bool immediate_notify);
749 
754 NT_ConnectionListener AddConnectionListener(
755  NT_Inst inst,
756  std::function<void(const ConnectionNotification& event)> callback,
757  bool immediate_notify);
758 
768 NT_ConnectionListenerPoller CreateConnectionListenerPoller(NT_Inst inst);
769 
775 void DestroyConnectionListenerPoller(NT_ConnectionListenerPoller poller);
776 
783 NT_ConnectionListener AddPolledConnectionListener(
784  NT_ConnectionListenerPoller poller, bool immediate_notify);
785 
796  NT_ConnectionListenerPoller poller);
797 
811  NT_ConnectionListenerPoller poller, double timeout, bool* timed_out);
812 
819 void CancelPollConnectionListener(NT_ConnectionListenerPoller poller);
820 
825 void RemoveConnectionListener(NT_ConnectionListener conn_listener);
826 
837 bool WaitForConnectionListenerQueue(NT_Inst inst, double timeout);
838 
854 void CreateRpc(NT_Entry entry, StringRef def,
855  std::function<void(const RpcAnswer& answer)> callback);
856 
866 NT_RpcCallPoller CreateRpcCallPoller(NT_Inst inst);
867 
873 void DestroyRpcCallPoller(NT_RpcCallPoller poller);
874 
883 void CreatePolledRpc(NT_Entry entry, StringRef def, NT_RpcCallPoller poller);
884 
895 std::vector<RpcAnswer> PollRpc(NT_RpcCallPoller poller);
896 
910 std::vector<RpcAnswer> PollRpc(NT_RpcCallPoller poller, double timeout,
911  bool* timed_out);
912 
918 void CancelPollRpc(NT_RpcCallPoller poller);
919 
930 bool WaitForRpcCallQueue(NT_Inst inst, double timeout);
931 
940 void PostRpcResponse(NT_Entry entry, NT_RpcCall call, StringRef result);
941 
952 NT_RpcCall CallRpc(NT_Entry entry, StringRef params);
953 
962 bool GetRpcResult(NT_Entry entry, NT_RpcCall call, std::string* result);
963 
974 bool GetRpcResult(NT_Entry entry, NT_RpcCall call, std::string* result,
975  double timeout, bool* timed_out);
976 
982 void CancelRpcResult(NT_Entry entry, NT_RpcCall call);
983 
989 std::string PackRpcDefinition(const RpcDefinition& def);
990 
998 bool UnpackRpcDefinition(StringRef packed, RpcDefinition* def);
999 
1005 std::string PackRpcValues(ArrayRef<std::shared_ptr<Value>> values);
1006 
1013 std::vector<std::shared_ptr<Value>> UnpackRpcValues(StringRef packed,
1014  ArrayRef<NT_Type> types);
1015 
1029 WPI_DEPRECATED("use NT_Inst function instead")
1030 void SetNetworkIdentity(StringRef name);
1031 
1036 void SetNetworkIdentity(NT_Inst inst, const Twine& name);
1037 
1042 WPI_DEPRECATED("use NT_Inst function instead")
1043 unsigned int GetNetworkMode();
1044 
1050 unsigned int GetNetworkMode(NT_Inst inst);
1051 
1061 WPI_DEPRECATED("use NT_Inst function instead")
1062 void StartServer(StringRef persist_filename, const char* listen_address,
1063  unsigned int port);
1064 
1069 void StartServer(NT_Inst inst, const Twine& persist_filename,
1070  const char* listen_address, unsigned int port);
1071 
1075 WPI_DEPRECATED("use NT_Inst function instead")
1076 void StopServer();
1077 
1082 void StopServer(NT_Inst inst);
1083 
1087 WPI_DEPRECATED("use NT_Inst function instead")
1088 void StartClient();
1089 
1096 WPI_DEPRECATED("use NT_Inst function instead")
1097 void StartClient(const char* server_name, unsigned int port);
1098 
1105 WPI_DEPRECATED("use NT_Inst function instead")
1106 void StartClient(ArrayRef<std::pair<StringRef, unsigned int>> servers);
1107 
1112 void StartClient(NT_Inst inst);
1113 
1118 void StartClient(NT_Inst inst, const char* server_name, unsigned int port);
1119 
1124 void StartClient(NT_Inst inst,
1125  ArrayRef<std::pair<StringRef, unsigned int>> servers);
1126 
1135 void StartClientTeam(NT_Inst inst, unsigned int team, unsigned int port);
1136 
1140 WPI_DEPRECATED("use NT_Inst function instead")
1141 void StopClient();
1142 
1147 void StopClient(NT_Inst inst);
1148 
1155 WPI_DEPRECATED("use NT_Inst function instead")
1156 void SetServer(const char* server_name, unsigned int port);
1157 
1164 WPI_DEPRECATED("use NT_Inst function instead")
1165 void SetServer(ArrayRef<std::pair<StringRef, unsigned int>> servers);
1166 
1171 void SetServer(NT_Inst inst, const char* server_name, unsigned int port);
1172 
1177 void SetServer(NT_Inst inst,
1178  ArrayRef<std::pair<StringRef, unsigned int>> servers);
1179 
1188 void SetServerTeam(NT_Inst inst, unsigned int team, unsigned int port);
1189 
1197 WPI_DEPRECATED("use NT_Inst function instead")
1198 void StartDSClient(unsigned int port);
1199 
1204 void StartDSClient(NT_Inst inst, unsigned int port);
1205 
1207 WPI_DEPRECATED("use NT_Inst function instead")
1208 void StopDSClient();
1209 
1214 void StopDSClient(NT_Inst inst);
1215 
1217 WPI_DEPRECATED("use NT_Inst function instead")
1218 void StopRpcServer();
1219 
1226 WPI_DEPRECATED("use NT_Inst function instead")
1227 void SetUpdateRate(double interval);
1228 
1233 void SetUpdateRate(NT_Inst inst, double interval);
1234 
1245 WPI_DEPRECATED("use NT_Inst function instead")
1246 void Flush();
1247 
1253 void Flush(NT_Inst inst);
1254 
1261 WPI_DEPRECATED("use NT_Inst function instead")
1262 std::vector<ConnectionInfo> GetConnections();
1263 
1268 std::vector<ConnectionInfo> GetConnections(NT_Inst inst);
1269 
1275 bool IsConnected(NT_Inst inst);
1276 
1291 WPI_DEPRECATED("use NT_Inst function instead")
1292 const char* SavePersistent(StringRef filename);
1293 
1298 const char* SavePersistent(NT_Inst inst, const Twine& filename);
1299 
1308 WPI_DEPRECATED("use NT_Inst function instead")
1309 const char* LoadPersistent(
1310  StringRef filename, std::function<void(size_t line, const char* msg)> warn);
1311 
1317 const char* LoadPersistent(
1318  NT_Inst inst, const Twine& filename,
1319  std::function<void(size_t line, const char* msg)> warn);
1320 
1329 const char* SaveEntries(NT_Inst inst, const Twine& filename,
1330  const Twine& prefix);
1331 
1341 const char* LoadEntries(NT_Inst inst, const Twine& filename,
1342  const Twine& prefix,
1343  std::function<void(size_t line, const char* msg)> warn);
1344 
1358 uint64_t Now();
1359 
1374 typedef std::function<void(unsigned int level, const char* file,
1375  unsigned int line, const char* msg)>
1377 
1388 WPI_DEPRECATED("use NT_Inst function instead")
1389 void SetLogger(LogFunc func, unsigned int min_level);
1390 
1404 NT_Logger AddLogger(NT_Inst inst,
1405  std::function<void(const LogMessage& msg)> func,
1406  unsigned int min_level, unsigned int max_level);
1407 
1414 NT_LoggerPoller CreateLoggerPoller(NT_Inst inst);
1415 
1421 void DestroyLoggerPoller(NT_LoggerPoller poller);
1422 
1432 NT_Logger AddPolledLogger(NT_LoggerPoller poller, unsigned int min_level,
1433  unsigned int max_level);
1434 
1441 std::vector<LogMessage> PollLogger(NT_LoggerPoller poller);
1442 
1453 std::vector<LogMessage> PollLogger(NT_LoggerPoller poller, double timeout,
1454  bool* timed_out);
1455 
1461 void CancelPollLogger(NT_LoggerPoller poller);
1462 
1467 void RemoveLogger(NT_Logger logger);
1468 
1479 bool WaitForLoggerQueue(NT_Inst inst, double timeout);
1480 
1483 inline void RpcAnswer::PostResponse(StringRef result) const {
1484  PostRpcResponse(entry, call, result);
1485 }
1486 
1487 } // namespace nt
1488 
1489 #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:61
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:1376
unsigned int remote_port
The port number of the remote node.
Definition: ntcore_cpp.h:72
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:188
std::string remote_id
The remote identifier (as set on the remote node by NetworkTableInstance::SetNetworkIdentity() or nt:...
Definition: ntcore_cpp.h:66
unsigned int GetEntryFlags(StringRef name)
Get Entry Flags.
Definition: ntcore_cpp.cpp:170
NetworkTables log message.
Definition: ntcore_cpp.h:236
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:116
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:589
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:221
NetworkTables Remote Procedure Call (Server Side)
Definition: ntcore_cpp.h:124
void RemoveLogger(NT_Logger logger)
Remove a logger.
Definition: ntcore_cpp.cpp:1045
NT_Type type
Entry type.
Definition: ntcore_cpp.h:42
NT_LoggerPoller CreateLoggerPoller(NT_Inst inst)
Create a log poller.
Definition: ntcore_cpp.cpp:984
NetworkTables Entry Notification.
Definition: ntcore_cpp.h:169
Definition: json.cpp:1170
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
Definition: Twine.h:79
ConnectionInfo conn
Connection that called the RPC.
Definition: ntcore_cpp.h:144
void Flush()
Flush Entries.
Definition: ntcore_cpp.cpp:884
NT_Entry entry
Entry handle.
Definition: ntcore_cpp.h:132
NT_ConnectionListener listener
Listener that was triggered.
Definition: ntcore_cpp.h:218
void RemoveConnectionListener(NT_ConnectionListener conn_listener)
Remove a connection listener.
Definition: ntcore_cpp.cpp:458
NT_RpcCall call
Call handle.
Definition: ntcore_cpp.h:135
NT_Entry entry
Entry handle.
Definition: ntcore_cpp.h:36
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
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory)...
Definition: ArrayRef.h:32
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:185
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 PostRpcResponse(NT_Entry entry, NT_RpcCall call, StringRef result)
Post RPC response (return value) for a polled RPC.
Definition: ntcore_cpp.cpp:563
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:141
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:191
std::vector< ConnectionNotification > PollConnectionListener(NT_ConnectionListenerPoller poller)
Get the next connection event.
Definition: ntcore_cpp.cpp:427
Definition: IEntryNotifier.h:16
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:260
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:97
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:34
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:210
std::string name
Entry name.
Definition: ntcore_cpp.h:39
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:224
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:84
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
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:138
unsigned int flags
Entry flags.
Definition: ntcore_cpp.h:45
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:182
std::string remote_ip
The IP address of the remote node.
Definition: ntcore_cpp.h:69
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:48
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:107
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:257
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:737
void DeleteEntry(StringRef name)
Delete Entry.
Definition: ntcore_cpp.cpp:183
unsigned int level
Log level of the message.
Definition: ntcore_cpp.h:251
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:42
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:248
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:197
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:78
const char * filename
The filename of the source file that generated the message.
Definition: ntcore_cpp.h:254