WPILibC++  unspecified
ntcore_cpp.h
1 /*----------------------------------------------------------------------------*/
2 /* Copyright (c) FIRST 2015. 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_CPP_H_
9 #define NTCORE_CPP_H_
10 
11 #include <cassert>
12 #include <functional>
13 #include <memory>
14 #include <string>
15 #include <utility>
16 #include <vector>
17 
18 #include "llvm/ArrayRef.h"
19 #include "llvm/StringRef.h"
20 #include "support/deprecated.h"
21 
22 #include "networktables/NetworkTableValue.h"
23 
24 namespace nt {
25 
26 using llvm::ArrayRef;
27 using llvm::StringRef;
28 
30 struct EntryInfo {
32  NT_Entry entry;
33 
35  std::string name;
36 
38  NT_Type type;
39 
41  unsigned int flags;
42 
44  unsigned long long last_change;
45 
46  friend void swap(EntryInfo& first, EntryInfo& second) {
47  using std::swap;
48  swap(first.entry, second.entry);
49  swap(first.name, second.name);
50  swap(first.type, second.type);
51  swap(first.flags, second.flags);
52  swap(first.last_change, second.last_change);
53  }
54 };
55 
62  std::string remote_id;
63 
65  std::string remote_ip;
66 
68  unsigned int remote_port;
69 
74  unsigned long long last_update;
75 
80  unsigned int protocol_version;
81 
82  friend void swap(ConnectionInfo& first, ConnectionInfo& second) {
83  using std::swap;
84  swap(first.remote_id, second.remote_id);
85  swap(first.remote_ip, second.remote_ip);
86  swap(first.remote_port, second.remote_port);
87  swap(first.last_update, second.last_update);
88  swap(first.protocol_version, second.protocol_version);
89  }
90 };
91 
93 struct RpcParamDef {
94  RpcParamDef() = default;
95  RpcParamDef(StringRef name_, std::shared_ptr<Value> def_value_)
96  : name(name_), def_value(def_value_) {}
97 
98  std::string name;
99  std::shared_ptr<Value> def_value;
100 };
101 
103 struct RpcResultDef {
104  RpcResultDef() = default;
105  RpcResultDef(StringRef name_, NT_Type type_) : name(name_), type(type_) {}
106 
107  std::string name;
108  NT_Type type;
109 };
110 
113  unsigned int version;
114  std::string name;
115  std::vector<RpcParamDef> params;
116  std::vector<RpcResultDef> results;
117 };
118 
120 class RpcAnswer {
121  public:
122  RpcAnswer() : entry(0), call(0) {}
123  RpcAnswer(NT_Entry entry_, NT_RpcCall call_, StringRef name_,
124  StringRef params_, const ConnectionInfo& conn_)
125  : entry(entry_), call(call_), name(name_), params(params_), conn(conn_) {}
126 
128  NT_Entry entry;
129 
131  NT_RpcCall call;
132 
134  std::string name;
135 
137  std::string params;
138 
141 
146  explicit operator bool() const { return call != 0; }
147 
152  void PostResponse(StringRef result) const;
153 
154  friend void swap(RpcAnswer& first, RpcAnswer& second) {
155  using std::swap;
156  swap(first.entry, second.entry);
157  swap(first.call, second.call);
158  swap(first.name, second.name);
159  swap(first.params, second.params);
160  swap(first.conn, second.conn);
161  }
162 };
163 
166  public:
167  EntryNotification() : listener(0), entry(0) {}
168  EntryNotification(NT_EntryListener listener_, NT_Entry entry_,
169  llvm::StringRef name_, std::shared_ptr<Value> value_,
170  unsigned int flags_)
171  : listener(listener_),
172  entry(entry_),
173  name(name_),
174  value(value_),
175  flags(flags_) {}
176 
178  NT_EntryListener listener;
179 
181  NT_Entry entry;
182 
184  std::string name;
185 
187  std::shared_ptr<Value> value;
188 
193  unsigned int flags;
194 
195  friend void swap(EntryNotification& first, EntryNotification& second) {
196  using std::swap;
197  swap(first.listener, second.listener);
198  swap(first.entry, second.entry);
199  swap(first.name, second.name);
200  swap(first.value, second.value);
201  swap(first.flags, second.flags);
202  }
203 };
204 
207  public:
208  ConnectionNotification() : listener(0), connected(false) {}
209  ConnectionNotification(NT_ConnectionListener listener_, bool connected_,
210  const ConnectionInfo& conn_)
211  : listener(listener_), connected(connected_), conn(conn_) {}
212 
214  NT_ConnectionListener listener;
215 
217  bool connected = false;
218 
221 
222  friend void swap(ConnectionNotification& first,
223  ConnectionNotification& second) {
224  using std::swap;
225  swap(first.listener, second.listener);
226  swap(first.connected, second.connected);
227  swap(first.conn, second.conn);
228  }
229 };
230 
232 class LogMessage {
233  public:
234  LogMessage() : logger(0), level(0), filename(""), line(0) {}
235  LogMessage(NT_Logger logger_, unsigned int level_, const char* filename_,
236  unsigned int line_, llvm::StringRef message_)
237  : logger(logger_),
238  level(level_),
239  filename(filename_),
240  line(line_),
241  message(message_) {}
242 
244  NT_Logger logger;
245 
247  unsigned int level;
248 
250  const char* filename;
251 
253  unsigned int line;
254 
256  std::string message;
257 
258  friend void swap(LogMessage& first, LogMessage& second) {
259  using std::swap;
260  swap(first.logger, second.logger);
261  swap(first.level, second.level);
262  swap(first.filename, second.filename);
263  swap(first.line, second.line);
264  swap(first.message, second.message);
265  }
266 };
267 
278 NT_Inst GetDefaultInstance();
279 
284 NT_Inst CreateInstance();
285 
291 void DestroyInstance(NT_Inst inst);
292 
298 NT_Inst GetInstanceFromHandle(NT_Handle handle);
299 
313 NT_Entry GetEntry(NT_Inst inst, StringRef name);
314 
328 std::vector<NT_Entry> GetEntries(NT_Inst inst, StringRef prefix,
329  unsigned int types);
330 
337 std::string GetEntryName(NT_Entry entry);
338 
344 NT_Type GetEntryType(NT_Entry entry);
345 
352 unsigned long long GetEntryLastChange(NT_Entry entry);
353 
362 WPI_DEPRECATED("use NT_Entry function instead")
363 std::shared_ptr<Value> GetEntryValue(StringRef name);
364 
373 std::shared_ptr<Value> GetEntryValue(NT_Entry entry);
374 
385 WPI_DEPRECATED("use NT_Entry function instead")
386 bool SetDefaultEntryValue(StringRef name, std::shared_ptr<Value> value);
387 
398 bool SetDefaultEntryValue(NT_Entry entry, std::shared_ptr<Value> value);
399 
409 WPI_DEPRECATED("use NT_Entry function instead")
410 bool SetEntryValue(StringRef name, std::shared_ptr<Value> value);
411 
421 bool SetEntryValue(NT_Entry entry, std::shared_ptr<Value> value);
422 
435 WPI_DEPRECATED("use NT_Entry function instead")
436 void SetEntryTypeValue(StringRef name, std::shared_ptr<Value> value);
437 
450 void SetEntryTypeValue(NT_Entry entry, std::shared_ptr<Value> value);
451 
457 WPI_DEPRECATED("use NT_Entry function instead")
458 void SetEntryFlags(StringRef name, unsigned int flags);
459 
465 void SetEntryFlags(NT_Entry entry, unsigned int flags);
466 
472 WPI_DEPRECATED("use NT_Entry function instead")
473 unsigned int GetEntryFlags(StringRef name);
474 
480 unsigned int GetEntryFlags(NT_Entry entry);
481 
494 WPI_DEPRECATED("use NT_Entry function instead")
495 void DeleteEntry(StringRef name);
496 
509 void DeleteEntry(NT_Entry entry);
510 
521 WPI_DEPRECATED("use NT_Inst function instead")
522 void DeleteAllEntries();
523 
529 void DeleteAllEntries(NT_Inst inst);
530 
544 WPI_DEPRECATED("use NT_Inst function instead")
545 std::vector<EntryInfo> GetEntryInfo(StringRef prefix, unsigned int types);
546 
552 std::vector<EntryInfo> GetEntryInfo(NT_Inst inst, StringRef prefix,
553  unsigned int types);
554 
563 EntryInfo GetEntryInfo(NT_Entry entry);
564 
583 typedef std::function<void(NT_EntryListener entry_listener, StringRef name,
584  std::shared_ptr<Value> value, unsigned int flags)>
586 
595 WPI_DEPRECATED("use NT_Inst function instead")
596 NT_EntryListener AddEntryListener(StringRef prefix,
597  EntryListenerCallback callback,
598  unsigned int flags);
599 
604 NT_EntryListener AddEntryListener(
605  NT_Inst inst, StringRef prefix,
606  std::function<void(const EntryNotification& event)> callback,
607  unsigned int flags);
608 
617 NT_EntryListener AddEntryListener(
618  NT_Entry entry,
619  std::function<void(const EntryNotification& event)> callback,
620  unsigned int flags);
621 
631 NT_EntryListenerPoller CreateEntryListenerPoller(NT_Inst inst);
632 
638 void DestroyEntryListenerPoller(NT_EntryListenerPoller poller);
639 
648 NT_EntryListener AddPolledEntryListener(NT_EntryListenerPoller poller,
649  StringRef prefix, unsigned int flags);
650 
659 NT_EntryListener AddPolledEntryListener(NT_EntryListenerPoller poller,
660  NT_Entry entry, unsigned int flags);
661 
670 std::vector<EntryNotification> PollEntryListener(NT_EntryListenerPoller poller);
671 
684 std::vector<EntryNotification> PollEntryListener(NT_EntryListenerPoller poller,
685  double timeout,
686  bool* timed_out);
687 
694 void CancelPollEntryListener(NT_EntryListenerPoller poller);
695 
700 void RemoveEntryListener(NT_EntryListener entry_listener);
701 
712 bool WaitForEntryListenerQueue(NT_Inst inst, double timeout);
713 
730 typedef std::function<void(NT_ConnectionListener conn_listener, bool connected,
731  const ConnectionInfo& conn)>
733 
741 WPI_DEPRECATED("use NT_Inst function instead")
742 NT_ConnectionListener AddConnectionListener(ConnectionListenerCallback callback,
743  bool immediate_notify);
744 
749 NT_ConnectionListener AddConnectionListener(
750  NT_Inst inst,
751  std::function<void(const ConnectionNotification& event)> callback,
752  bool immediate_notify);
753 
763 NT_ConnectionListenerPoller CreateConnectionListenerPoller(NT_Inst inst);
764 
770 void DestroyConnectionListenerPoller(NT_ConnectionListenerPoller poller);
771 
778 NT_ConnectionListener AddPolledConnectionListener(
779  NT_ConnectionListenerPoller poller, bool immediate_notify);
780 
791  NT_ConnectionListenerPoller poller);
792 
806  NT_ConnectionListenerPoller poller, double timeout, bool* timed_out);
807 
814 void CancelPollConnectionListener(NT_ConnectionListenerPoller poller);
815 
820 void RemoveConnectionListener(NT_ConnectionListener conn_listener);
821 
832 bool WaitForConnectionListenerQueue(NT_Inst inst, double timeout);
833 
849 void CreateRpc(NT_Entry entry, StringRef def,
850  std::function<void(const RpcAnswer& answer)> callback);
851 
861 NT_RpcCallPoller CreateRpcCallPoller(NT_Inst inst);
862 
868 void DestroyRpcCallPoller(NT_RpcCallPoller poller);
869 
878 void CreatePolledRpc(NT_Entry entry, StringRef def, NT_RpcCallPoller poller);
879 
890 std::vector<RpcAnswer> PollRpc(NT_RpcCallPoller poller);
891 
905 std::vector<RpcAnswer> PollRpc(NT_RpcCallPoller poller, double timeout,
906  bool* timed_out);
907 
913 void CancelPollRpc(NT_RpcCallPoller poller);
914 
925 bool WaitForRpcCallQueue(NT_Inst inst, double timeout);
926 
935 void PostRpcResponse(NT_Entry entry, NT_RpcCall call, StringRef result);
936 
947 NT_RpcCall CallRpc(NT_Entry entry, StringRef params);
948 
957 bool GetRpcResult(NT_Entry entry, NT_RpcCall call, std::string* result);
958 
969 bool GetRpcResult(NT_Entry entry, NT_RpcCall call, std::string* result,
970  double timeout, bool* timed_out);
971 
977 void CancelRpcResult(NT_Entry entry, NT_RpcCall call);
978 
984 std::string PackRpcDefinition(const RpcDefinition& def);
985 
993 bool UnpackRpcDefinition(StringRef packed, RpcDefinition* def);
994 
1000 std::string PackRpcValues(ArrayRef<std::shared_ptr<Value>> values);
1001 
1008 std::vector<std::shared_ptr<Value>> UnpackRpcValues(StringRef packed,
1009  ArrayRef<NT_Type> types);
1010 
1024 WPI_DEPRECATED("use NT_Inst function instead")
1025 void SetNetworkIdentity(StringRef name);
1026 
1031 void SetNetworkIdentity(NT_Inst inst, StringRef name);
1032 
1037 WPI_DEPRECATED("use NT_Inst function instead")
1038 unsigned int GetNetworkMode();
1039 
1045 unsigned int GetNetworkMode(NT_Inst inst);
1046 
1056 WPI_DEPRECATED("use NT_Inst function instead")
1057 void StartServer(StringRef persist_filename, const char* listen_address,
1058  unsigned int port);
1059 
1064 void StartServer(NT_Inst inst, StringRef persist_filename,
1065  const char* listen_address, unsigned int port);
1066 
1070 WPI_DEPRECATED("use NT_Inst function instead")
1071 void StopServer();
1072 
1077 void StopServer(NT_Inst inst);
1078 
1082 WPI_DEPRECATED("use NT_Inst function instead")
1083 void StartClient();
1084 
1091 WPI_DEPRECATED("use NT_Inst function instead")
1092 void StartClient(const char* server_name, unsigned int port);
1093 
1100 WPI_DEPRECATED("use NT_Inst function instead")
1101 void StartClient(ArrayRef<std::pair<StringRef, unsigned int>> servers);
1102 
1107 void StartClient(NT_Inst inst);
1108 
1113 void StartClient(NT_Inst inst, const char* server_name, unsigned int port);
1114 
1119 void StartClient(NT_Inst inst,
1120  ArrayRef<std::pair<StringRef, unsigned int>> servers);
1121 
1130 void StartClientTeam(NT_Inst inst, unsigned int team, unsigned int port);
1131 
1135 WPI_DEPRECATED("use NT_Inst function instead")
1136 void StopClient();
1137 
1142 void StopClient(NT_Inst inst);
1143 
1150 WPI_DEPRECATED("use NT_Inst function instead")
1151 void SetServer(const char* server_name, unsigned int port);
1152 
1159 WPI_DEPRECATED("use NT_Inst function instead")
1160 void SetServer(ArrayRef<std::pair<StringRef, unsigned int>> servers);
1161 
1166 void SetServer(NT_Inst inst, const char* server_name, unsigned int port);
1167 
1172 void SetServer(NT_Inst inst,
1173  ArrayRef<std::pair<StringRef, unsigned int>> servers);
1174 
1183 void SetServerTeam(NT_Inst inst, unsigned int team, unsigned int port);
1184 
1192 WPI_DEPRECATED("use NT_Inst function instead")
1193 void StartDSClient(unsigned int port);
1194 
1199 void StartDSClient(NT_Inst inst, unsigned int port);
1200 
1202 WPI_DEPRECATED("use NT_Inst function instead")
1203 void StopDSClient();
1204 
1209 void StopDSClient(NT_Inst inst);
1210 
1212 WPI_DEPRECATED("use NT_Inst function instead")
1213 void StopRpcServer();
1214 
1221 WPI_DEPRECATED("use NT_Inst function instead")
1222 void SetUpdateRate(double interval);
1223 
1228 void SetUpdateRate(NT_Inst inst, double interval);
1229 
1240 WPI_DEPRECATED("use NT_Inst function instead")
1241 void Flush();
1242 
1248 void Flush(NT_Inst inst);
1249 
1256 WPI_DEPRECATED("use NT_Inst function instead")
1257 std::vector<ConnectionInfo> GetConnections();
1258 
1263 std::vector<ConnectionInfo> GetConnections(NT_Inst inst);
1264 
1270 bool IsConnected(NT_Inst inst);
1271 
1286 WPI_DEPRECATED("use NT_Inst function instead")
1287 const char* SavePersistent(StringRef filename);
1288 
1293 const char* SavePersistent(NT_Inst inst, StringRef filename);
1294 
1303 WPI_DEPRECATED("use NT_Inst function instead")
1304 const char* LoadPersistent(
1305  StringRef filename, std::function<void(size_t line, const char* msg)> warn);
1306 
1312 const char* LoadPersistent(
1313  NT_Inst inst, StringRef filename,
1314  std::function<void(size_t line, const char* msg)> warn);
1315 
1324 const char* SaveEntries(NT_Inst inst, StringRef filename, StringRef prefix);
1325 
1335 const char* LoadEntries(NT_Inst inst, StringRef filename, StringRef prefix,
1336  std::function<void(size_t line, const char* msg)> warn);
1337 
1351 unsigned long long Now();
1352 
1367 typedef std::function<void(unsigned int level, const char* file,
1368  unsigned int line, const char* msg)>
1370 
1381 WPI_DEPRECATED("use NT_Inst function instead")
1382 void SetLogger(LogFunc func, unsigned int min_level);
1383 
1397 NT_Logger AddLogger(NT_Inst inst,
1398  std::function<void(const LogMessage& msg)> func,
1399  unsigned int min_level, unsigned int max_level);
1400 
1407 NT_LoggerPoller CreateLoggerPoller(NT_Inst inst);
1408 
1414 void DestroyLoggerPoller(NT_LoggerPoller poller);
1415 
1425 NT_Logger AddPolledLogger(NT_LoggerPoller poller, unsigned int min_level,
1426  unsigned int max_level);
1427 
1434 std::vector<LogMessage> PollLogger(NT_LoggerPoller poller);
1435 
1446 std::vector<LogMessage> PollLogger(NT_LoggerPoller poller, double timeout,
1447  bool* timed_out);
1448 
1454 void CancelPollLogger(NT_LoggerPoller poller);
1455 
1460 void RemoveLogger(NT_Logger logger);
1461 
1472 bool WaitForLoggerQueue(NT_Inst inst, double timeout);
1473 
1476 inline void RpcAnswer::PostResponse(StringRef result) const {
1477  PostRpcResponse(entry, call, result);
1478 }
1479 
1480 } // namespace nt
1481 
1482 #endif /* NTCORE_CPP_H_ */
NetworkTables Connection Information.
Definition: ntcore_cpp.h:57
void DestroyRpcCallPoller(NT_RpcCallPoller poller)
Destroy a RPC call poller.
Definition: ntcore_cpp.cpp:498
std::vector< ConnectionInfo > GetConnections()
Get information on the currently established network connections.
Definition: ntcore_cpp.cpp:891
NT_EntryListener AddPolledEntryListener(NT_EntryListenerPoller poller, StringRef prefix, unsigned int flags)
Create a polled entry listener.
Definition: ntcore_cpp.cpp:296
void SetEntryFlags(StringRef name, unsigned int flags)
Set Entry Flags.
Definition: ntcore_cpp.cpp:156
bool SetEntryValue(StringRef name, std::shared_ptr< Value > value)
Set Entry Value.
Definition: ntcore_cpp.cpp:130
std::function< void(unsigned int level, const char *file, unsigned int line, const char *msg)> LogFunc
Log function.
Definition: ntcore_cpp.h:1369
unsigned int remote_port
The port number of the remote node.
Definition: ntcore_cpp.h:68
void SetUpdateRate(double interval)
Set the periodic update rate.
Definition: ntcore_cpp.cpp:871
bool WaitForEntryListenerQueue(NT_Inst inst, double timeout)
Wait for the entry listener queue to be empty.
Definition: ntcore_cpp.cpp:366
void SetServer(const char *server_name, unsigned int port)
Sets server address and port for client (without restarting client).
Definition: ntcore_cpp.cpp:821
NT_EntryListenerPoller CreateEntryListenerPoller(NT_Inst inst)
Create a entry listener poller.
Definition: ntcore_cpp.cpp:278
void CreatePolledRpc(NT_Entry entry, StringRef def, NT_RpcCallPoller poller)
Create a polled RPC entry point.
Definition: ntcore_cpp.cpp:507
std::string name
Entry name.
Definition: ntcore_cpp.h:184
std::string remote_id
The remote identifier (as set on the remote node by NetworkTableInstance::SetNetworkIdentity() or nt:...
Definition: ntcore_cpp.h:62
unsigned int GetEntryFlags(StringRef name)
Get Entry Flags.
Definition: ntcore_cpp.cpp:169
NetworkTables log message.
Definition: ntcore_cpp.h:232
std::vector< LogMessage > PollLogger(NT_LoggerPoller poller)
Get the next log event.
Definition: ntcore_cpp.cpp:1012
void DestroyInstance(NT_Inst inst)
Destroy an instance.
Definition: ntcore_cpp.cpp:36
void CancelPollRpc(NT_RpcCallPoller poller)
Cancel a PollRpc call.
Definition: ntcore_cpp.cpp:545
NetworkTables RPC Version 1 Definition.
Definition: ntcore_cpp.h:112
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:585
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:117
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:42
bool connected
True if event is due to connection being established.
Definition: ntcore_cpp.h:217
NetworkTables Remote Procedure Call (Server Side)
Definition: ntcore_cpp.h:120
unsigned long long last_change
Timestamp of last change to entry (type or value).
Definition: ntcore_cpp.h:44
void RemoveLogger(NT_Logger logger)
Remove a logger.
Definition: ntcore_cpp.cpp:1042
NT_Type type
Entry type.
Definition: ntcore_cpp.h:38
NT_LoggerPoller CreateLoggerPoller(NT_Inst inst)
Create a log poller.
Definition: ntcore_cpp.cpp:981
NetworkTables Entry Notification.
Definition: ntcore_cpp.h:165
Definition: json.cpp:1170
ConnectionInfo conn
Connection that called the RPC.
Definition: ntcore_cpp.h:140
void Flush()
Flush Entries.
Definition: ntcore_cpp.cpp:882
NT_Entry entry
Entry handle.
Definition: ntcore_cpp.h:128
NT_ConnectionListener listener
Listener that was triggered.
Definition: ntcore_cpp.h:214
void RemoveConnectionListener(NT_ConnectionListener conn_listener)
Remove a connection listener.
Definition: ntcore_cpp.cpp:456
NT_RpcCall call
Call handle.
Definition: ntcore_cpp.h:131
const char * LoadEntries(NT_Inst inst, StringRef filename, StringRef prefix, std::function< void(size_t line, const char *msg)> warn)
Load table values from a file.
Definition: ntcore_cpp.cpp:946
NT_Entry entry
Entry handle.
Definition: ntcore_cpp.h:32
NT_Inst GetDefaultInstance()
Get default instance.
Definition: ntcore_cpp.cpp:28
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:241
void CancelPollLogger(NT_LoggerPoller poller)
Cancel a PollLogger call.
Definition: ntcore_cpp.cpp:1033
void CancelRpcResult(NT_Entry entry, NT_RpcCall call)
Ignore the result of a RPC call.
Definition: ntcore_cpp.cpp:617
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:701
std::vector< NT_Entry > GetEntries(NT_Inst inst, StringRef prefix, unsigned int types)
Get Entry Handles.
Definition: ntcore_cpp.cpp:65
NT_Entry entry
Entry handle.
Definition: ntcore_cpp.h:181
NT_RpcCall CallRpc(NT_Entry entry, StringRef params)
Call a RPC function.
Definition: ntcore_cpp.cpp:575
void SetEntryTypeValue(StringRef name, std::shared_ptr< Value > value)
Set Entry Type and Value.
Definition: ntcore_cpp.cpp:143
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:924
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:476
void PostRpcResponse(NT_Entry entry, NT_RpcCall call, StringRef result)
Post RPC response (return value) for a polled RPC.
Definition: ntcore_cpp.cpp:561
void DestroyLoggerPoller(NT_LoggerPoller poller)
Destroy a log poller.
Definition: ntcore_cpp.cpp:989
NT_ConnectionListenerPoller CreateConnectionListenerPoller(NT_Inst inst)
Create a connection listener poller.
Definition: ntcore_cpp.cpp:395
std::string params
Call raw parameters.
Definition: ntcore_cpp.h:137
void StopServer()
Stops the server if it is running.
Definition: ntcore_cpp.cpp:757
std::vector< RpcAnswer > PollRpc(NT_RpcCallPoller poller)
Get the next incoming RPC call.
Definition: ntcore_cpp.cpp:525
NT_Entry GetEntry(NT_Inst inst, StringRef name)
Get Entry Handle.
Definition: ntcore_cpp.cpp:55
void StartDSClient(unsigned int port)
Starts requesting server address from Driver Station.
Definition: ntcore_cpp.cpp:851
void StopDSClient()
Stops requesting server address from Driver Station.
Definition: ntcore_cpp.cpp:862
bool IsConnected(NT_Inst inst)
Return whether or not the instance is connected to another node.
Definition: ntcore_cpp.cpp:902
std::shared_ptr< Value > value
The new value.
Definition: ntcore_cpp.h:187
std::vector< ConnectionNotification > PollConnectionListener(NT_ConnectionListenerPoller poller)
Get the next connection event.
Definition: ntcore_cpp.cpp:425
Definition: IEntryNotifier.h:15
std::string message
The message.
Definition: ntcore_cpp.h:256
void SetNetworkIdentity(StringRef name)
Set the network identity of this node.
Definition: ntcore_cpp.cpp:721
NetworkTables RPC Version 1 Definition Parameter.
Definition: ntcore_cpp.h:93
NT_RpcCallPoller CreateRpcCallPoller(NT_Inst inst)
Create a RPC call poller.
Definition: ntcore_cpp.cpp:490
void DestroyConnectionListenerPoller(NT_ConnectionListenerPoller poller)
Destroy a connection listener poller.
Definition: ntcore_cpp.cpp:404
void SetLogger(LogFunc func, unsigned int min_level)
Set logger callback function.
Definition: ntcore_cpp.cpp:955
NT_Type GetEntryType(NT_Entry entry)
Gets the type for the specified entry, or unassigned if non existent.
Definition: ntcore_cpp.cpp:86
bool WaitForConnectionListenerQueue(NT_Inst inst, double timeout)
Wait for the connection listener queue to be empty.
Definition: ntcore_cpp.cpp:465
NetworkTables Entry Information.
Definition: ntcore_cpp.h:30
NetworkTables Connection Notification.
Definition: ntcore_cpp.h:206
std::string name
Entry name.
Definition: ntcore_cpp.h:35
void CancelPollConnectionListener(NT_ConnectionListenerPoller poller)
Cancel a PollConnectionListener call.
Definition: ntcore_cpp.cpp:447
unsigned int GetNetworkMode()
Get the current network mode.
Definition: ntcore_cpp.cpp:732
bool WaitForRpcCallQueue(NT_Inst inst, double timeout)
Wait for the incoming RPC call queue to be empty.
Definition: ntcore_cpp.cpp:554
std::vector< EntryInfo > GetEntryInfo(StringRef prefix, unsigned int types)
Get Entry Information.
Definition: ntcore_cpp.cpp:207
ConnectionInfo conn
Connection info.
Definition: ntcore_cpp.h:220
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:844
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:743
unsigned long long last_update
The last time any update was received from the remote node (same scale as returned by nt::Now())...
Definition: ntcore_cpp.h:74
std::vector< EntryNotification > PollEntryListener(NT_EntryListenerPoller poller)
Get the next entry listener event.
Definition: ntcore_cpp.cpp:325
NT_ConnectionListener AddConnectionListener(ConnectionListenerCallback callback, bool immediate_notify)
Add a connection listener.
Definition: ntcore_cpp.cpp:373
const char * SavePersistent(StringRef filename)
Save persistent values to a file.
Definition: ntcore_cpp.cpp:913
unsigned int protocol_version
The protocol version being used for this connection.
Definition: ntcore_cpp.h:80
std::string PackRpcValues(ArrayRef< std::shared_ptr< Value >> values)
Pack RPC values as required for RPC version 1 definition messages.
Definition: ntcore_cpp.cpp:695
void CancelPollEntryListener(NT_EntryListenerPoller poller)
Cancel a PollEntryListener call.
Definition: ntcore_cpp.cpp:348
bool UnpackRpcDefinition(StringRef packed, RpcDefinition *def)
Unpack a RPC version 1 definition.
Definition: ntcore_cpp.cpp:658
void DeleteAllEntries()
Delete All Entries.
Definition: ntcore_cpp.cpp:195
std::shared_ptr< Value > GetEntryValue(StringRef name)
Get Entry Value.
Definition: ntcore_cpp.cpp:104
std::string name
Entry name.
Definition: ntcore_cpp.h:134
unsigned int flags
Entry flags.
Definition: ntcore_cpp.h:41
NT_Inst CreateInstance()
Create an instance.
Definition: ntcore_cpp.cpp:32
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:968
NT_EntryListener listener
Listener that was triggered.
Definition: ntcore_cpp.h:178
unsigned long long Now()
Returns monotonic current time in 100 ns increments.
Definition: ntcore_cpp.cpp:715
std::string remote_ip
The IP address of the remote node.
Definition: ntcore_cpp.h:65
bool WaitForLoggerQueue(NT_Inst inst, double timeout)
Wait for the incoming log event queue to be empty.
Definition: ntcore_cpp.cpp:1052
void DestroyEntryListenerPoller(NT_EntryListenerPoller poller)
Destroy a entry listener poller.
Definition: ntcore_cpp.cpp:287
NetworkTables RPC Version 1 Definition Result.
Definition: ntcore_cpp.h:103
bool GetRpcResult(NT_Entry entry, NT_RpcCall call, std::string *result)
Get the result (return value) of a RPC call.
Definition: ntcore_cpp.cpp:587
const char * SaveEntries(NT_Inst inst, StringRef filename, StringRef prefix)
Save table values to a file.
Definition: ntcore_cpp.cpp:939
A network table entry value.
Definition: NetworkTableValue.h:30
unsigned int line
The line number in the source file that generated the message.
Definition: ntcore_cpp.h:253
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:998
std::function< void(NT_ConnectionListener conn_listener, bool connected, const ConnectionInfo &conn)> ConnectionListenerCallback
Connection listener callback function.
Definition: ntcore_cpp.h:732
void DeleteEntry(StringRef name)
Delete Entry.
Definition: ntcore_cpp.cpp:182
unsigned int level
Log level of the message.
Definition: ntcore_cpp.h:247
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:631
NT_Logger logger
The logger that generated the message.
Definition: ntcore_cpp.h:244
NT_ConnectionListener AddPolledConnectionListener(NT_ConnectionListenerPoller poller, bool immediate_notify)
Create a polled connection listener.
Definition: ntcore_cpp.cpp:413
void StopClient()
Stops the client if it is running.
Definition: ntcore_cpp.cpp:812
void StartClient()
Starts a client.
Definition: ntcore_cpp.cpp:766
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:804
std::string GetEntryName(NT_Entry entry)
Gets the name of the specified entry.
Definition: ntcore_cpp.cpp:77
void RemoveEntryListener(NT_EntryListener entry_listener)
Remove an entry listener.
Definition: ntcore_cpp.cpp:357
unsigned long long GetEntryLastChange(NT_Entry entry)
Gets the last time the entry was changed.
Definition: ntcore_cpp.cpp:95
unsigned int flags
Update flags.
Definition: ntcore_cpp.h:193
const char * filename
The filename of the source file that generated the message.
Definition: ntcore_cpp.h:250