8 #ifndef NTCORE_NTCORE_CPP_H_
9 #define NTCORE_NTCORE_CPP_H_
21 #include <wpi/ArrayRef.h>
22 #include <wpi/StringRef.h>
23 #include <wpi/Twine.h>
24 #include <wpi/deprecated.h>
26 #include "networktables/NetworkTableValue.h"
109 : name(name_), def_value(def_value_) {}
112 std::shared_ptr<Value> def_value;
126 unsigned int version;
128 std::vector<RpcParamDef> params;
129 std::vector<RpcResultDef> results;
159 explicit operator bool()
const {
return call != 0; }
183 StringRef name_, std::shared_ptr<Value> value_,
249 LogMessage(NT_Logger logger_,
unsigned int level_,
const char* filename_,
332 NT_Entry
GetEntry(NT_Inst inst,
const Twine& name);
348 std::vector<NT_Entry>
GetEntries(NT_Inst inst,
const Twine& prefix,
386 WPI_DEPRECATED(
"use NT_Entry function instead")
411 WPI_DEPRECATED("use NT_Entry function instead")
437 WPI_DEPRECATED("use NT_Entry function instead")
465 WPI_DEPRECATED("use NT_Entry function instead")
489 WPI_DEPRECATED("use NT_Entry function instead")
506 WPI_DEPRECATED("use NT_Entry function instead")
530 WPI_DEPRECATED("use NT_Entry function instead")
559 WPI_DEPRECATED("use NT_Inst function instead")
567 void DeleteAllEntries(NT_Inst inst);
583 WPI_DEPRECATED("use NT_Inst function instead")
584 std::vector<EntryInfo>
GetEntryInfo(StringRef prefix,
unsigned int types);
623 typedef
std::function<
void(NT_EntryListener entry_listener, StringRef name,
624 std::shared_ptr<Value> value,
unsigned int flags)>
635 WPI_DEPRECATED("use NT_Inst function instead")
646 NT_Inst inst, const
Twine& prefix,
707 NT_Entry entry,
unsigned int flags);
782 typedef
std::function<
void(NT_ConnectionListener conn_listener,
bool connected,
793 WPI_DEPRECATED("use NT_Inst function instead")
795 bool immediate_notify);
805 bool immediate_notify);
836 NT_ConnectionListenerPoller poller,
bool immediate_notify);
849 NT_ConnectionListenerPoller poller);
865 NT_ConnectionListenerPoller poller,
double timeout,
bool* timed_out);
1032 bool GetRpcResult(NT_Entry entry, NT_RpcCall call,
std::
string* result);
1045 bool GetRpcResult(NT_Entry entry, NT_RpcCall call,
std::
string* result,
1046 double timeout,
bool* timed_out);
1106 WPI_DEPRECATED("use NT_Inst function instead")
1121 WPI_DEPRECATED("use NT_Inst function instead")
1130 unsigned int GetNetworkMode(NT_Inst inst);
1141 WPI_DEPRECATED("use NT_Inst function instead")
1151 const
char* listen_address,
unsigned int port);
1156 WPI_DEPRECATED("use NT_Inst function instead")
1164 void StopServer(NT_Inst inst);
1169 WPI_DEPRECATED("use NT_Inst function instead")
1178 WPI_DEPRECATED("use NT_Inst function instead")
1179 void StartClient(const
char* server_name,
unsigned int port);
1187 WPI_DEPRECATED("use NT_Inst function instead")
1195 void StartClient(NT_Inst inst);
1202 void StartClient(NT_Inst inst, const
char* server_name,
unsigned int port);
1209 void StartClient(NT_Inst inst,
1210 ArrayRef<
std::pair<StringRef,
unsigned int>> servers);
1220 void StartClientTeam(NT_Inst inst,
unsigned int team,
unsigned int port);
1225 WPI_DEPRECATED("use NT_Inst function instead")
1232 void StopClient(NT_Inst inst);
1240 WPI_DEPRECATED("use NT_Inst function instead")
1241 void SetServer(const
char* server_name,
unsigned int port);
1249 WPI_DEPRECATED("use NT_Inst function instead")
1257 void SetServer(NT_Inst inst, const
char* server_name,
unsigned int port);
1265 ArrayRef<
std::pair<StringRef,
unsigned int>> servers);
1275 void SetServerTeam(NT_Inst inst,
unsigned int team,
unsigned int port);
1284 WPI_DEPRECATED("use NT_Inst function instead")
1294 WPI_DEPRECATED("use NT_Inst function instead")
1302 void StopDSClient(NT_Inst inst);
1305 WPI_DEPRECATED("use NT_Inst function instead")
1314 WPI_DEPRECATED("use NT_Inst function instead")
1335 WPI_DEPRECATED("use NT_Inst function instead")
1343 void Flush(NT_Inst inst);
1351 WPI_DEPRECATED("use NT_Inst function instead")
1384 WPI_DEPRECATED("use NT_Inst function instead")
1402 WPI_DEPRECATED("use NT_Inst function instead")
1404 StringRef filename,
std::function<
void(
size_t line, const
char* msg)> warn);
1413 NT_Inst inst, const
Twine& filename,
1414 std::function<
void(
size_t line, const
char* msg)> warn);
1426 const
Twine& prefix);
1439 const
Twine& prefix,
1440 std::function<
void(
size_t line, const
char* msg)> warn);
1473 typedef
std::function<
void(
unsigned int level, const
char* file,
1474 unsigned int line, const
char* msg)>
1487 WPI_DEPRECATED("use NT_Inst function instead")
1505 unsigned int min_level,
unsigned int max_level);
1534 NT_Logger
AddPolledLogger(NT_LoggerPoller poller,
unsigned int min_level,
1535 unsigned int max_level);
1591 inline
bool RpcAnswer::PostResponse(StringRef result)
const {
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.
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