WPILibC++  2018.4.1-20180729040223-1137-g011f0ff
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Modules Pages
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 
38 using wpi::ArrayRef;
39 using wpi::StringRef;
40 using wpi::Twine;
41 
43 struct EntryInfo {
45  NT_Entry entry;
46 
48  std::string name;
49 
52 
54  unsigned int flags;
55 
57  uint64_t last_change;
58 
59  friend void swap(EntryInfo& first, EntryInfo& second) {
60  using std::swap;
61  swap(first.entry, second.entry);
62  swap(first.name, second.name);
63  swap(first.type, second.type);
64  swap(first.flags, second.flags);
65  swap(first.last_change, second.last_change);
66  }
67 };
68 
75  std::string remote_id;
76 
78  std::string remote_ip;
79 
81  unsigned int remote_port;
82 
87  uint64_t last_update;
88 
93  unsigned int protocol_version;
94 
95  friend void swap(ConnectionInfo& first, ConnectionInfo& second) {
96  using std::swap;
97  swap(first.remote_id, second.remote_id);
98  swap(first.remote_ip, second.remote_ip);
99  swap(first.remote_port, second.remote_port);
100  swap(first.last_update, second.last_update);
101  swap(first.protocol_version, second.protocol_version);
102  }
103 };
104 
106 struct RpcParamDef {
107  RpcParamDef() = default;
108  RpcParamDef(StringRef name_, std::shared_ptr<Value> def_value_)
109  : name(name_), def_value(def_value_) {}
110 
111  std::string name;
112  std::shared_ptr<Value> def_value;
113 };
114 
116 struct RpcResultDef {
117  RpcResultDef() = default;
118  RpcResultDef(StringRef name_, NT_Type type_) : name(name_), type(type_) {}
119 
120  std::string name;
121  NT_Type type;
122 };
123 
126  unsigned int version;
127  std::string name;
128  std::vector<RpcParamDef> params;
129  std::vector<RpcResultDef> results;
130 };
131 
133 class RpcAnswer {
134  public:
135  RpcAnswer() : entry(0), call(0) {}
136  RpcAnswer(NT_Entry entry_, NT_RpcCall call_, StringRef name_,
137  StringRef params_, const ConnectionInfo& conn_)
138  : entry(entry_), call(call_), name(name_), params(params_), conn(conn_) {}
139 
141  NT_Entry entry;
142 
144  mutable NT_RpcCall call;
145 
147  std::string name;
148 
150  std::string params;
151 
154 
159  explicit operator bool() const { return call != 0; }
160 
166  bool PostResponse(StringRef result) const;
167 
168  friend void swap(RpcAnswer& first, RpcAnswer& second) {
169  using std::swap;
170  swap(first.entry, second.entry);
171  swap(first.call, second.call);
172  swap(first.name, second.name);
173  swap(first.params, second.params);
174  swap(first.conn, second.conn);
175  }
176 };
177 
180  public:
181  EntryNotification() : listener(0), entry(0) {}
182  EntryNotification(NT_EntryListener listener_, NT_Entry entry_,
183  StringRef name_, std::shared_ptr<Value> value_,
184  unsigned int flags_)
185  : listener(listener_),
186  entry(entry_),
187  name(name_),
188  value(value_),
189  flags(flags_) {}
190 
192  NT_EntryListener listener;
193 
195  NT_Entry entry;
196 
198  std::string name;
199 
201  std::shared_ptr<Value> value;
202 
207  unsigned int flags;
208 
209  friend void swap(EntryNotification& first, EntryNotification& second) {
210  using std::swap;
211  swap(first.listener, second.listener);
212  swap(first.entry, second.entry);
213  swap(first.name, second.name);
214  swap(first.value, second.value);
215  swap(first.flags, second.flags);
216  }
217 };
218 
221  public:
222  ConnectionNotification() : listener(0), connected(false) {}
223  ConnectionNotification(NT_ConnectionListener listener_, bool connected_,
224  const ConnectionInfo& conn_)
225  : listener(listener_), connected(connected_), conn(conn_) {}
226 
228  NT_ConnectionListener listener;
229 
231  bool connected = false;
232 
235 
236  friend void swap(ConnectionNotification& first,
237  ConnectionNotification& second) {
238  using std::swap;
239  swap(first.listener, second.listener);
240  swap(first.connected, second.connected);
241  swap(first.conn, second.conn);
242  }
243 };
244 
246 class LogMessage {
247  public:
248  LogMessage() : logger(0), level(0), filename(""), line(0) {}
249  LogMessage(NT_Logger logger_, unsigned int level_, const char* filename_,
250  unsigned int line_, StringRef message_)
251  : logger(logger_),
252  level(level_),
253  filename(filename_),
254  line(line_),
255  message(message_) {}
256 
258  NT_Logger logger;
259 
261  unsigned int level;
262 
264  const char* filename;
265 
267  unsigned int line;
268 
270  std::string message;
271 
272  friend void swap(LogMessage& first, LogMessage& second) {
273  using std::swap;
274  swap(first.logger, second.logger);
275  swap(first.level, second.level);
276  swap(first.filename, second.filename);
277  swap(first.line, second.line);
278  swap(first.message, second.message);
279  }
280 };
281 
293 NT_Inst GetDefaultInstance();
294 
300 NT_Inst CreateInstance();
301 
308 void DestroyInstance(NT_Inst inst);
309 
316 NT_Inst GetInstanceFromHandle(NT_Handle handle);
317 
332 NT_Entry GetEntry(NT_Inst inst, const Twine& name);
333 
348 std::vector<NT_Entry> GetEntries(NT_Inst inst, const Twine& prefix,
349  unsigned int types);
350 
358 std::string GetEntryName(NT_Entry entry);
359 
366 NT_Type GetEntryType(NT_Entry entry);
367 
375 uint64_t GetEntryLastChange(NT_Entry entry);
376 
386 WPI_DEPRECATED("use NT_Entry function instead")
387 std::shared_ptr<Value> GetEntryValue(StringRef name);
388 
398 std::shared_ptr<Value> GetEntryValue(NT_Entry entry);
399 
411 WPI_DEPRECATED("use NT_Entry function instead")
412 bool SetDefaultEntryValue(StringRef name, std::shared_ptr<Value> value);
413 
425 bool SetDefaultEntryValue(NT_Entry entry, std::shared_ptr<Value> value);
426 
437 WPI_DEPRECATED("use NT_Entry function instead")
438 bool SetEntryValue(StringRef name, std::shared_ptr<Value> value);
439 
450 bool SetEntryValue(NT_Entry entry, std::shared_ptr<Value> value);
451 
465 WPI_DEPRECATED("use NT_Entry function instead")
466 void SetEntryTypeValue(StringRef name, std::shared_ptr<Value> value);
467 
481 void SetEntryTypeValue(NT_Entry entry, std::shared_ptr<Value> value);
482 
489 WPI_DEPRECATED("use NT_Entry function instead")
490 void SetEntryFlags(StringRef name, unsigned int flags);
491 
498 void SetEntryFlags(NT_Entry entry, unsigned int flags);
499 
506 WPI_DEPRECATED("use NT_Entry function instead")
507 unsigned int GetEntryFlags(StringRef name);
508 
515 unsigned int GetEntryFlags(NT_Entry entry);
516 
530 WPI_DEPRECATED("use NT_Entry function instead")
531 void DeleteEntry(StringRef name);
532 
546 void DeleteEntry(NT_Entry entry);
547 
559 WPI_DEPRECATED("use NT_Inst function instead")
560 void DeleteAllEntries();
561 
567 void DeleteAllEntries(NT_Inst inst);
568 
583 WPI_DEPRECATED("use NT_Inst function instead")
584 std::vector<EntryInfo> GetEntryInfo(StringRef prefix, unsigned int types);
585 
591 std::vector<EntryInfo> GetEntryInfo(NT_Inst inst, const Twine& prefix,
592  unsigned int types);
593 
603 EntryInfo GetEntryInfo(NT_Entry entry);
604 
623 typedef std::function<void(NT_EntryListener entry_listener, StringRef name,
624  std::shared_ptr<Value> value, unsigned int flags)>
626 
635 WPI_DEPRECATED("use NT_Inst function instead")
636 NT_EntryListener AddEntryListener(StringRef prefix,
637  EntryListenerCallback callback,
638  unsigned int flags);
639 
645 NT_EntryListener AddEntryListener(
646  NT_Inst inst, const Twine& prefix,
647  std::function<void(const EntryNotification& event)> callback,
648  unsigned int flags);
649 
658 NT_EntryListener AddEntryListener(
659  NT_Entry entry,
660  std::function<void(const EntryNotification& event)> callback,
661  unsigned int flags);
662 
674 NT_EntryListenerPoller CreateEntryListenerPoller(NT_Inst inst);
675 
682 void DestroyEntryListenerPoller(NT_EntryListenerPoller poller);
683 
693 NT_EntryListener AddPolledEntryListener(NT_EntryListenerPoller poller,
694  const Twine& prefix,
695  unsigned int flags);
696 
706 NT_EntryListener AddPolledEntryListener(NT_EntryListenerPoller poller,
707  NT_Entry entry, unsigned int flags);
708 
718 std::vector<EntryNotification> PollEntryListener(NT_EntryListenerPoller poller);
719 
733 std::vector<EntryNotification> PollEntryListener(NT_EntryListenerPoller poller,
734  double timeout,
735  bool* timed_out);
736 
744 void CancelPollEntryListener(NT_EntryListenerPoller poller);
745 
751 void RemoveEntryListener(NT_EntryListener entry_listener);
752 
764 bool WaitForEntryListenerQueue(NT_Inst inst, double timeout);
765 
782 typedef std::function<void(NT_ConnectionListener conn_listener, bool connected,
783  const ConnectionInfo& conn)>
785 
793 WPI_DEPRECATED("use NT_Inst function instead")
794 NT_ConnectionListener AddConnectionListener(ConnectionListenerCallback callback,
795  bool immediate_notify);
796 
802 NT_ConnectionListener AddConnectionListener(
803  NT_Inst inst,
804  std::function<void(const ConnectionNotification& event)> callback,
805  bool immediate_notify);
806 
818 NT_ConnectionListenerPoller CreateConnectionListenerPoller(NT_Inst inst);
819 
826 void DestroyConnectionListenerPoller(NT_ConnectionListenerPoller poller);
827 
835 NT_ConnectionListener AddPolledConnectionListener(
836  NT_ConnectionListenerPoller poller, bool immediate_notify);
837 
849  NT_ConnectionListenerPoller poller);
850 
865  NT_ConnectionListenerPoller poller, double timeout, bool* timed_out);
866 
874 void CancelPollConnectionListener(NT_ConnectionListenerPoller poller);
875 
881 void RemoveConnectionListener(NT_ConnectionListener conn_listener);
882 
894 bool WaitForConnectionListenerQueue(NT_Inst inst, double timeout);
895 
912 void CreateRpc(NT_Entry entry, StringRef def,
913  std::function<void(const RpcAnswer& answer)> callback);
914 
926 NT_RpcCallPoller CreateRpcCallPoller(NT_Inst inst);
927 
934 void DestroyRpcCallPoller(NT_RpcCallPoller poller);
935 
945 void CreatePolledRpc(NT_Entry entry, StringRef def, NT_RpcCallPoller poller);
946 
958 std::vector<RpcAnswer> PollRpc(NT_RpcCallPoller poller);
959 
974 std::vector<RpcAnswer> PollRpc(NT_RpcCallPoller poller, double timeout,
975  bool* timed_out);
976 
983 void CancelPollRpc(NT_RpcCallPoller poller);
984 
996 bool WaitForRpcCallQueue(NT_Inst inst, double timeout);
997 
1008 bool PostRpcResponse(NT_Entry entry, NT_RpcCall call, StringRef result);
1009 
1021 NT_RpcCall CallRpc(NT_Entry entry, StringRef params);
1022 
1032 bool GetRpcResult(NT_Entry entry, NT_RpcCall call, std::string* result);
1033 
1045 bool GetRpcResult(NT_Entry entry, NT_RpcCall call, std::string* result,
1046  double timeout, bool* timed_out);
1047 
1054 void CancelRpcResult(NT_Entry entry, NT_RpcCall call);
1055 
1062 std::string PackRpcDefinition(const RpcDefinition& def);
1063 
1072 bool UnpackRpcDefinition(StringRef packed, RpcDefinition* def);
1073 
1080 std::string PackRpcValues(ArrayRef<std::shared_ptr<Value>> values);
1081 
1089 std::vector<std::shared_ptr<Value>> UnpackRpcValues(StringRef packed,
1090  ArrayRef<NT_Type> types);
1091 
1106 WPI_DEPRECATED("use NT_Inst function instead")
1107 void SetNetworkIdentity(StringRef name);
1108 
1114 void SetNetworkIdentity(NT_Inst inst, const Twine& name);
1115 
1121 WPI_DEPRECATED("use NT_Inst function instead")
1122 unsigned int GetNetworkMode();
1123 
1130 unsigned int GetNetworkMode(NT_Inst inst);
1131 
1141 WPI_DEPRECATED("use NT_Inst function instead")
1142 void StartServer(StringRef persist_filename, const char* listen_address,
1143  unsigned int port);
1144 
1150 void StartServer(NT_Inst inst, const Twine& persist_filename,
1151  const char* listen_address, unsigned int port);
1152 
1156 WPI_DEPRECATED("use NT_Inst function instead")
1157 void StopServer();
1158 
1164 void StopServer(NT_Inst inst);
1165 
1169 WPI_DEPRECATED("use NT_Inst function instead")
1170 void StartClient();
1171 
1178 WPI_DEPRECATED("use NT_Inst function instead")
1179 void StartClient(const char* server_name, unsigned int port);
1180 
1187 WPI_DEPRECATED("use NT_Inst function instead")
1188 void StartClient(ArrayRef<std::pair<StringRef, unsigned int>> servers);
1189 
1195 void StartClient(NT_Inst inst);
1196 
1202 void StartClient(NT_Inst inst, const char* server_name, unsigned int port);
1203 
1209 void StartClient(NT_Inst inst,
1210  ArrayRef<std::pair<StringRef, unsigned int>> servers);
1211 
1220 void StartClientTeam(NT_Inst inst, unsigned int team, unsigned int port);
1221 
1225 WPI_DEPRECATED("use NT_Inst function instead")
1226 void StopClient();
1227 
1232 void StopClient(NT_Inst inst);
1233 
1240 WPI_DEPRECATED("use NT_Inst function instead")
1241 void SetServer(const char* server_name, unsigned int port);
1242 
1249 WPI_DEPRECATED("use NT_Inst function instead")
1250 void SetServer(ArrayRef<std::pair<StringRef, unsigned int>> servers);
1251 
1257 void SetServer(NT_Inst inst, const char* server_name, unsigned int port);
1258 
1264 void SetServer(NT_Inst inst,
1265  ArrayRef<std::pair<StringRef, unsigned int>> servers);
1266 
1275 void SetServerTeam(NT_Inst inst, unsigned int team, unsigned int port);
1276 
1284 WPI_DEPRECATED("use NT_Inst function instead")
1285 void StartDSClient(unsigned int port);
1286 
1291 void StartDSClient(NT_Inst inst, unsigned int port);
1292 
1294 WPI_DEPRECATED("use NT_Inst function instead")
1295 void StopDSClient();
1296 
1302 void StopDSClient(NT_Inst inst);
1303 
1305 WPI_DEPRECATED("use NT_Inst function instead")
1306 void StopRpcServer();
1307 
1314 WPI_DEPRECATED("use NT_Inst function instead")
1315 void SetUpdateRate(double interval);
1316 
1322 void SetUpdateRate(NT_Inst inst, double interval);
1323 
1335 WPI_DEPRECATED("use NT_Inst function instead")
1336 void Flush();
1337 
1343 void Flush(NT_Inst inst);
1344 
1351 WPI_DEPRECATED("use NT_Inst function instead")
1352 std::vector<ConnectionInfo> GetConnections();
1353 
1359 std::vector<ConnectionInfo> GetConnections(NT_Inst inst);
1360 
1367 bool IsConnected(NT_Inst inst);
1368 
1384 WPI_DEPRECATED("use NT_Inst function instead")
1385 const char* SavePersistent(StringRef filename);
1386 
1391 const char* SavePersistent(NT_Inst inst, const Twine& filename);
1392 
1402 WPI_DEPRECATED("use NT_Inst function instead")
1403 const char* LoadPersistent(
1404  StringRef filename, std::function<void(size_t line, const char* msg)> warn);
1405 
1412 const char* LoadPersistent(
1413  NT_Inst inst, const Twine& filename,
1414  std::function<void(size_t line, const char* msg)> warn);
1415 
1425 const char* SaveEntries(NT_Inst inst, const Twine& filename,
1426  const Twine& prefix);
1427 
1438 const char* LoadEntries(NT_Inst inst, const Twine& filename,
1439  const Twine& prefix,
1440  std::function<void(size_t line, const char* msg)> warn);
1441 
1456 uint64_t Now();
1457 
1473 typedef std::function<void(unsigned int level, const char* file,
1474  unsigned int line, const char* msg)>
1476 
1487 WPI_DEPRECATED("use NT_Inst function instead")
1488 void SetLogger(LogFunc func, unsigned int min_level);
1489 
1503 NT_Logger AddLogger(NT_Inst inst,
1504  std::function<void(const LogMessage& msg)> func,
1505  unsigned int min_level, unsigned int max_level);
1506 
1514 NT_LoggerPoller CreateLoggerPoller(NT_Inst inst);
1515 
1522 void DestroyLoggerPoller(NT_LoggerPoller poller);
1523 
1534 NT_Logger AddPolledLogger(NT_LoggerPoller poller, unsigned int min_level,
1535  unsigned int max_level);
1536 
1544 std::vector<LogMessage> PollLogger(NT_LoggerPoller poller);
1545 
1557 std::vector<LogMessage> PollLogger(NT_LoggerPoller poller, double timeout,
1558  bool* timed_out);
1559 
1566 void CancelPollLogger(NT_LoggerPoller poller);
1567 
1573 void RemoveLogger(NT_Logger logger);
1574 
1586 bool WaitForLoggerQueue(NT_Inst inst, double timeout);
1587 
1591 inline bool RpcAnswer::PostResponse(StringRef result) const {
1592  auto ret = PostRpcResponse(entry, call, result);
1593  call = 0;
1594  return ret;
1595 }
1596 
1597 } // namespace nt
1598 
1599 #endif // NTCORE_NTCORE_CPP_H_
void SetNetworkIdentity(NT_Inst inst, const Twine &name)
NetworkTables Connection Information.
Definition: ntcore_cpp.h:70
bool PostResponse(StringRef result) const
Post RPC response (return value) for a polled RPC.
Definition: ntcore_cpp.h:1591
std::function< void(unsigned int level, const char *file, unsigned int line, const char *msg)> LogFunc
Log function.
Definition: ntcore_cpp.h:1475
std::function< void(NT_ConnectionListener conn_listener, bool connected, const ConnectionInfo &conn)> ConnectionListenerCallback
Connection listener callback function.
Definition: ntcore_cpp.h:784
bool IsConnected(NT_Inst inst)
Return whether or not the instance is connected to another node.
bool UnpackRpcDefinition(StringRef packed, RpcDefinition *def)
Unpack a RPC version 1 definition.
void DeleteEntry(NT_Entry entry)
Delete Entry.
unsigned int remote_port
The port number of the remote node.
Definition: ntcore_cpp.h:81
std::string name
Entry name.
Definition: ntcore_cpp.h:198
std::string remote_id
The remote identifier (as set on the remote node by NetworkTableInstance::SetNetworkIdentity() or nt:...
Definition: ntcore_cpp.h:75
NT_ConnectionListenerPoller CreateConnectionListenerPoller(NT_Inst inst)
Create a connection listener poller.
void RemoveEntryListener(NT_EntryListener entry_listener)
Remove an entry listener.
void SetServer(NT_Inst inst, ArrayRef< std::pair< StringRef, unsigned int >> servers)
const char * SavePersistent(NT_Inst inst, const Twine &filename)
NetworkTables log message.
Definition: ntcore_cpp.h:246
NetworkTables RPC Version 1 Definition.
Definition: ntcore_cpp.h:125
NT_LoggerPoller CreateLoggerPoller(NT_Inst inst)
Create a log poller.
bool SetDefaultEntryValue(NT_Entry entry, std::shared_ptr< Value > value)
Set Default Entry Value.
const char * SaveEntries(NT_Inst inst, const Twine &filename, const Twine &prefix)
Save table values to a file.
bool PostRpcResponse(NT_Entry entry, NT_RpcCall call, StringRef result)
Post RPC response (return value) for a polled RPC.
std::string PackRpcValues(ArrayRef< std::shared_ptr< Value >> values)
Pack RPC values as required for RPC version 1 definition messages.
void StopDSClient(NT_Inst inst)
Stops requesting server address from Driver Station.
bool connected
True if event is due to connection being established.
Definition: ntcore_cpp.h:231
NetworkTables Remote Procedure Call (Server Side)
Definition: ntcore_cpp.h:133
NT_Type type
Entry type.
Definition: ntcore_cpp.h:51
void SetEntryFlags(NT_Entry entry, unsigned int flags)
Set Entry Flags.
std::vector< ConnectionInfo > GetConnections(NT_Inst inst)
Get information on the currently established network connections.
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.
NetworkTables Entry Notification.
Definition: ntcore_cpp.h:179
Definition: SmallVector.h:946
void DestroyRpcCallPoller(NT_RpcCallPoller poller)
Destroy a RPC call poller.
ConnectionInfo conn
Connection that called the RPC.
Definition: ntcore_cpp.h:153
NT_Inst CreateInstance()
Create an instance.
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.
NT_Type GetEntryType(NT_Entry entry)
Gets the type for the specified entry, or unassigned if non existent.
std::shared_ptr< Value > GetEntryValue(NT_Entry entry)
Get Entry Value.
void StartClient(NT_Inst inst, ArrayRef< std::pair< StringRef, unsigned int >> servers)
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory)...
Definition: ArrayRef.h:41
void SetUpdateRate(NT_Inst inst, double interval)
NT_Entry entry
Entry handle.
Definition: ntcore_cpp.h:141
NT_ConnectionListener listener
Listener that was triggered.
Definition: ntcore_cpp.h:228
NT_RpcCall call
Call handle.
Definition: ntcore_cpp.h:144
NT_Entry entry
Entry handle.
Definition: ntcore_cpp.h:45
void RemoveConnectionListener(NT_ConnectionListener conn_listener)
Remove a connection listener.
bool WaitForLoggerQueue(NT_Inst inst, double timeout)
Wait for the incoming log event queue to be empty.
uint64_t GetEntryLastChange(NT_Entry entry)
Gets the last time the entry was changed.
std::string GetEntryName(NT_Entry entry)
Gets the name of the specified entry.
std::vector< EntryNotification > PollEntryListener(NT_EntryListenerPoller poller, double timeout, bool *timed_out)
Get the next entry listener event.
void CancelPollConnectionListener(NT_ConnectionListenerPoller poller)
Cancel a PollConnectionListener call.
NT_ConnectionListener AddConnectionListener(NT_Inst inst, std::function< void(const ConnectionNotification &event)> callback, bool immediate_notify)
NT_Entry entry
Entry handle.
Definition: ntcore_cpp.h:195
NT_Entry GetEntry(NT_Inst inst, const Twine &name)
Get Entry Handle.
void StopServer(NT_Inst inst)
Stops the server if it is running.
std::string params
Call raw parameters.
Definition: ntcore_cpp.h:150
void StartServer(NT_Inst inst, const Twine &persist_filename, const char *listen_address, unsigned int port)
NT_EntryListenerPoller CreateEntryListenerPoller(NT_Inst inst)
Create a entry listener poller.
void Flush(NT_Inst inst)
Flush Entries.
std::vector< RpcAnswer > PollRpc(NT_RpcCallPoller poller, double timeout, bool *timed_out)
Get the next incoming RPC call.
NT_Logger AddPolledLogger(NT_LoggerPoller poller, unsigned int min_level, unsigned int max_level)
Set the log level for a log poller.
EntryInfo GetEntryInfo(NT_Entry entry)
Get Entry Information.
void CancelPollEntryListener(NT_EntryListenerPoller poller)
Cancel a PollEntryListener call.
std::shared_ptr< Value > value
The new value.
Definition: ntcore_cpp.h:201
void SetLogger(LogFunc func, unsigned int min_level)
Set logger callback function.
void DestroyLoggerPoller(NT_LoggerPoller poller)
Destroy a log poller.
Definition: ITable.h:21
std::string message
The message.
Definition: ntcore_cpp.h:270
std::vector< LogMessage > PollLogger(NT_LoggerPoller poller, double timeout, bool *timed_out)
Get the next log event.
NetworkTables RPC Version 1 Definition Parameter.
Definition: ntcore_cpp.h:106
const char * LoadPersistent(NT_Inst inst, const Twine &filename, std::function< void(size_t line, const char *msg)> warn)
void DestroyInstance(NT_Inst inst)
Destroy an instance.
NetworkTables Entry Information.
Definition: ntcore_cpp.h:43
void CancelRpcResult(NT_Entry entry, NT_RpcCall call)
Ignore the result of a RPC call.
void DestroyEntryListenerPoller(NT_EntryListenerPoller poller)
Destroy a entry listener poller.
NetworkTables Connection Notification.
Definition: ntcore_cpp.h:220
void DestroyConnectionListenerPoller(NT_ConnectionListenerPoller poller)
Destroy a connection listener poller.
std::string name
Entry name.
Definition: ntcore_cpp.h:48
void CancelPollRpc(NT_RpcCallPoller poller)
Cancel a PollRpc call.
void RemoveLogger(NT_Logger logger)
Remove a logger.
void SetEntryTypeValue(NT_Entry entry, std::shared_ptr< Value > value)
Set Entry Type and Value.
unsigned int GetNetworkMode(NT_Inst inst)
Get the current network mode.
std::vector< ConnectionNotification > PollConnectionListener(NT_ConnectionListenerPoller poller, double timeout, bool *timed_out)
Get the next connection event.
NT_ConnectionListener AddPolledConnectionListener(NT_ConnectionListenerPoller poller, bool immediate_notify)
Create a polled connection listener.
void CreateRpc(NT_Entry entry, StringRef def, std::function< void(const RpcAnswer &answer)> callback)
Create a callback-based RPC entry point.
std::string PackRpcDefinition(const RpcDefinition &def)
Pack a RPC version 1 definition.
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:625
ConnectionInfo conn
Connection info.
Definition: ntcore_cpp.h:234
NT_EntryListener AddPolledEntryListener(NT_EntryListenerPoller poller, NT_Entry entry, unsigned int flags)
Create a polled entry listener.
void StopClient(NT_Inst inst)
Stops the client if it is running.
bool WaitForEntryListenerQueue(NT_Inst inst, double timeout)
Wait for the entry listener queue to be empty.
void DeleteAllEntries(NT_Inst inst)
Delete All Entries.
void StartDSClient(NT_Inst inst, unsigned int port)
std::vector< NT_Entry > GetEntries(NT_Inst inst, const Twine &prefix, unsigned int types)
Get Entry Handles.
void StartClientTeam(NT_Inst inst, unsigned int team, unsigned int port)
Starts a client using commonly known robot addresses for the specified team.
unsigned int protocol_version
The protocol version being used for this connection.
Definition: ntcore_cpp.h:93
void SetServerTeam(NT_Inst inst, unsigned int team, unsigned int port)
Sets server addresses and port for client (without restarting client).
void CreatePolledRpc(NT_Entry entry, StringRef def, NT_RpcCallPoller poller)
Create a polled RPC entry point.
bool SetEntryValue(NT_Entry entry, std::shared_ptr< Value > value)
Set Entry Value.
NT_EntryListener AddEntryListener(NT_Entry entry, std::function< void(const EntryNotification &event)> callback, unsigned int flags)
Add a listener for a single entry.
NT_Inst GetDefaultInstance()
Get default instance.
bool WaitForConnectionListenerQueue(NT_Inst inst, double timeout)
Wait for the connection listener queue to be empty.
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:49
NT_Type
NetworkTables data types.
Definition: ntcore_c.h:52
std::string name
Entry name.
Definition: ntcore_cpp.h:147
unsigned int flags
Entry flags.
Definition: ntcore_cpp.h:54
NT_RpcCall CallRpc(NT_Entry entry, StringRef params)
Call a RPC function.
NT_EntryListener listener
Listener that was triggered.
Definition: ntcore_cpp.h:192
std::string remote_ip
The IP address of the remote node.
Definition: ntcore_cpp.h:78
bool WaitForRpcCallQueue(NT_Inst inst, double timeout)
Wait for the incoming RPC call queue to be empty.
uint64_t last_change
Timestamp of last change to entry (type or value).
Definition: ntcore_cpp.h:57
NetworkTables RPC Version 1 Definition Result.
Definition: ntcore_cpp.h:116
A network table entry value.
Definition: NetworkTableValue.h:36
unsigned int line
The line number in the source file that generated the message.
Definition: ntcore_cpp.h:267
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
Definition: Twine.h:79
void CancelPollLogger(NT_LoggerPoller poller)
Cancel a PollLogger call.
std::vector< std::shared_ptr< Value > > UnpackRpcValues(StringRef packed, ArrayRef< NT_Type > types)
Unpack RPC values as required for RPC version 1 definition messages.
bool GetRpcResult(NT_Entry entry, NT_RpcCall call, std::string *result, double timeout, bool *timed_out)
Get the result (return value) of a RPC call.
unsigned int GetEntryFlags(NT_Entry entry)
Get Entry Flags.
NT_Inst GetInstanceFromHandle(NT_Handle handle)
Get instance handle from another handle.
unsigned int level
Log level of the message.
Definition: ntcore_cpp.h:261
NT_Logger logger
The logger that generated the message.
Definition: ntcore_cpp.h:258
NT_RpcCallPoller CreateRpcCallPoller(NT_Inst inst)
Create a RPC call poller.
void StopRpcServer()
Stops the RPC server if it is running.
unsigned int flags
Update flags.
Definition: ntcore_cpp.h:207
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:87
uint64_t Now()
Returns monotonic current time in 1 us increments.
const char * filename
The filename of the source file that generated the message.
Definition: ntcore_cpp.h:264