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"
110 : name(name_), def_value(def_value_) {}
113 std::shared_ptr<Value> def_value;
127 unsigned int version;
129 std::vector<RpcParamDef> params;
130 std::vector<RpcResultDef> results;
160 explicit operator bool()
const {
return call != 0; }
184 StringRef name_, std::shared_ptr<Value> value_,
250 LogMessage(NT_Logger logger_,
unsigned int level_,
const char* filename_,
333 NT_Entry
GetEntry(NT_Inst inst,
const Twine& name);
349 std::vector<NT_Entry>
GetEntries(NT_Inst inst,
const Twine& prefix,
387 WPI_DEPRECATED(
"use NT_Entry function instead")
412 WPI_DEPRECATED("use NT_Entry function instead")
438 WPI_DEPRECATED("use NT_Entry function instead")
466 WPI_DEPRECATED("use NT_Entry function instead")
490 WPI_DEPRECATED("use NT_Entry function instead")
507 WPI_DEPRECATED("use NT_Entry function instead")
531 WPI_DEPRECATED("use NT_Entry function instead")
560 WPI_DEPRECATED("use NT_Inst function instead")
568 void DeleteAllEntries(NT_Inst inst);
584 WPI_DEPRECATED("use NT_Inst function instead")
585 std::vector<EntryInfo>
GetEntryInfo(StringRef prefix,
unsigned int types);
624 typedef
std::function<
void(NT_EntryListener entry_listener, StringRef name,
625 std::shared_ptr<Value> value,
unsigned int flags)>
636 WPI_DEPRECATED("use NT_Inst function instead")
647 NT_Inst inst, const
Twine& prefix,
708 NT_Entry entry,
unsigned int flags);
783 typedef
std::function<
void(NT_ConnectionListener conn_listener,
bool connected,
794 WPI_DEPRECATED("use NT_Inst function instead")
796 bool immediate_notify);
806 bool immediate_notify);
837 NT_ConnectionListenerPoller poller,
bool immediate_notify);
850 NT_ConnectionListenerPoller poller);
866 NT_ConnectionListenerPoller poller,
double timeout,
bool* timed_out);
1033 bool GetRpcResult(NT_Entry entry, NT_RpcCall call,
std::
string* result);
1046 bool GetRpcResult(NT_Entry entry, NT_RpcCall call,
std::
string* result,
1047 double timeout,
bool* timed_out);
1107 WPI_DEPRECATED("use NT_Inst function instead")
1122 WPI_DEPRECATED("use NT_Inst function instead")
1131 unsigned int GetNetworkMode(NT_Inst inst);
1142 WPI_DEPRECATED("use NT_Inst function instead")
1152 const
char* listen_address,
unsigned int port);
1157 WPI_DEPRECATED("use NT_Inst function instead")
1165 void StopServer(NT_Inst inst);
1170 WPI_DEPRECATED("use NT_Inst function instead")
1179 WPI_DEPRECATED("use NT_Inst function instead")
1180 void StartClient(const
char* server_name,
unsigned int port);
1188 WPI_DEPRECATED("use NT_Inst function instead")
1196 void StartClient(NT_Inst inst);
1203 void StartClient(NT_Inst inst, const
char* server_name,
unsigned int port);
1210 void StartClient(NT_Inst inst,
1211 ArrayRef<
std::pair<StringRef,
unsigned int>> servers);
1221 void StartClientTeam(NT_Inst inst,
unsigned int team,
unsigned int port);
1226 WPI_DEPRECATED("use NT_Inst function instead")
1233 void StopClient(NT_Inst inst);
1241 WPI_DEPRECATED("use NT_Inst function instead")
1242 void SetServer(const
char* server_name,
unsigned int port);
1250 WPI_DEPRECATED("use NT_Inst function instead")
1258 void SetServer(NT_Inst inst, const
char* server_name,
unsigned int port);
1266 ArrayRef<
std::pair<StringRef,
unsigned int>> servers);
1276 void SetServerTeam(NT_Inst inst,
unsigned int team,
unsigned int port);
1285 WPI_DEPRECATED("use NT_Inst function instead")
1295 WPI_DEPRECATED("use NT_Inst function instead")
1303 void StopDSClient(NT_Inst inst);
1306 WPI_DEPRECATED("use NT_Inst function instead")
1315 WPI_DEPRECATED("use NT_Inst function instead")
1336 WPI_DEPRECATED("use NT_Inst function instead")
1344 void Flush(NT_Inst inst);
1352 WPI_DEPRECATED("use NT_Inst function instead")
1385 WPI_DEPRECATED("use NT_Inst function instead")
1403 WPI_DEPRECATED("use NT_Inst function instead")
1405 StringRef filename,
std::function<
void(
size_t line, const
char* msg)> warn);
1414 NT_Inst inst, const
Twine& filename,
1415 std::function<
void(
size_t line, const
char* msg)> warn);
1427 const
Twine& prefix);
1440 const
Twine& prefix,
1441 std::function<
void(
size_t line, const
char* msg)> warn);
1474 typedef
std::function<
void(
unsigned int level, const
char* file,
1475 unsigned int line, const
char* msg)>
1488 WPI_DEPRECATED("use NT_Inst function instead")
1506 unsigned int min_level,
unsigned int max_level);
1535 NT_Logger
AddPolledLogger(NT_LoggerPoller poller,
unsigned int min_level,
1536 unsigned int max_level);
1592 inline
bool RpcAnswer::PostResponse(StringRef result)
const {
1600 #endif // NTCORE_NTCORE_CPP_H_
NetworkTables Connection Information.
Definition: ntcore_cpp.h:71
std::vector< EntryNotification > PollEntryListener(NT_EntryListenerPoller poller)
Get the next entry listener event.
void SetUpdateRate(double interval)
Set the periodic update rate.
std::vector< LogMessage > PollLogger(NT_LoggerPoller poller)
Get the next log event.
bool PostResponse(StringRef result) const
Post RPC response (return value) for a polled RPC.
Definition: ntcore_cpp.h:1592
std::function< void(unsigned int level, const char *file, unsigned int line, const char *msg)> LogFunc
Log function.
Definition: ntcore_cpp.h:1476
std::function< void(NT_ConnectionListener conn_listener, bool connected, const ConnectionInfo &conn)> ConnectionListenerCallback
Connection listener callback function.
Definition: ntcore_cpp.h:785
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.
NT_EntryListener AddEntryListener(StringRef prefix, EntryListenerCallback callback, unsigned int flags)
Add a listener for all entries starting with a certain prefix.
unsigned int remote_port
The port number of the remote node.
Definition: ntcore_cpp.h:82
std::string name
Entry name.
Definition: ntcore_cpp.h:199
std::string remote_id
The remote identifier (as set on the remote node by NetworkTableInstance::SetNetworkIdentity() or nt:...
Definition: ntcore_cpp.h:76
NT_ConnectionListenerPoller CreateConnectionListenerPoller(NT_Inst inst)
Create a connection listener poller.
void RemoveEntryListener(NT_EntryListener entry_listener)
Remove an entry listener.
NetworkTables log message.
Definition: ntcore_cpp.h:247
NetworkTables RPC Version 1 Definition.
Definition: ntcore_cpp.h:126
NT_LoggerPoller CreateLoggerPoller(NT_Inst inst)
Create a log poller.
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.
bool connected
True if event is due to connection being established.
Definition: ntcore_cpp.h:232
NetworkTables Remote Procedure Call (Server Side)
Definition: ntcore_cpp.h:134
bool GetRpcResult(NT_Entry entry, NT_RpcCall call, std::string *result)
Get the result (return value) of a RPC call.
NT_Type type
Entry type.
Definition: ntcore_cpp.h:52
std::vector< ConnectionInfo > GetConnections()
Get information on the currently established network connections.
NT_EntryListener AddPolledEntryListener(NT_EntryListenerPoller poller, const Twine &prefix, unsigned int flags)
Create a polled entry listener.
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:180
void SetServer(const char *server_name, unsigned int port)
Sets server address and port for client (without restarting client).
Definition: optional.h:885
void DestroyRpcCallPoller(NT_RpcCallPoller poller)
Destroy a RPC call poller.
ConnectionInfo conn
Connection that called the RPC.
Definition: ntcore_cpp.h:154
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.
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory)...
Definition: ArrayRef.h:41
bool SetEntryValue(StringRef name, std::shared_ptr< Value > value)
Set Entry Value.
NT_Entry entry
Entry handle.
Definition: ntcore_cpp.h:142
NT_ConnectionListener listener
Listener that was triggered.
Definition: ntcore_cpp.h:229
void StartDSClient(unsigned int port)
Starts requesting server address from Driver Station.
NT_RpcCall call
Call handle.
Definition: ntcore_cpp.h:145
NT_Entry entry
Entry handle.
Definition: ntcore_cpp.h:46
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.
void DeleteEntry(StringRef name)
Delete Entry.
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.
void CancelPollConnectionListener(NT_ConnectionListenerPoller poller)
Cancel a PollConnectionListener call.
NT_Entry entry
Entry handle.
Definition: ntcore_cpp.h:196
void StartServer(StringRef persist_filename, const char *listen_address, unsigned int port)
Starts a server using the specified filename, listening address, and port.
void StopServer()
Stops the server if it is running.
NT_Entry GetEntry(NT_Inst inst, const Twine &name)
Get Entry Handle.
std::vector< EntryInfo > GetEntryInfo(StringRef prefix, unsigned int types)
Get Entry Information.
std::string params
Call raw parameters.
Definition: ntcore_cpp.h:151
NT_EntryListenerPoller CreateEntryListenerPoller(NT_Inst inst)
Create a entry listener poller.
NT_Logger AddPolledLogger(NT_LoggerPoller poller, unsigned int min_level, unsigned int max_level)
Set the log level for a log poller.
unsigned int GetEntryFlags(StringRef name)
Get Entry Flags.
void CancelPollEntryListener(NT_EntryListenerPoller poller)
Cancel a PollEntryListener call.
std::shared_ptr< Value > value
The new value.
Definition: ntcore_cpp.h:202
void SetLogger(LogFunc func, unsigned int min_level)
Set logger callback function.
void DestroyLoggerPoller(NT_LoggerPoller poller)
Destroy a log poller.
NetworkTables (ntcore) namespace.
Definition: ITable.h:21
std::shared_ptr< Value > GetEntryValue(StringRef name)
Get Entry Value.
void StopClient()
Stops the client if it is running.
std::string message
The message.
Definition: ntcore_cpp.h:271
void DeleteAllEntries()
Delete All Entries.
NetworkTables RPC Version 1 Definition Parameter.
Definition: ntcore_cpp.h:107
void DestroyInstance(NT_Inst inst)
Destroy an instance.
void SetEntryFlags(StringRef name, unsigned int flags)
Set Entry Flags.
NetworkTables Entry Information.
Definition: ntcore_cpp.h:44
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:221
bool SetDefaultEntryValue(StringRef name, std::shared_ptr< Value > value)
Set Default Entry Value.
void DestroyConnectionListenerPoller(NT_ConnectionListenerPoller poller)
Destroy a connection listener poller.
const char * LoadPersistent(StringRef filename, std::function< void(size_t line, const char *msg)> warn)
Load persistent values from a file.
std::string name
Entry name.
Definition: ntcore_cpp.h:49
void CancelPollRpc(NT_RpcCallPoller poller)
Cancel a PollRpc call.
void RemoveLogger(NT_Logger logger)
Remove a logger.
void StartClient()
Starts a client.
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:626
ConnectionInfo conn
Connection info.
Definition: ntcore_cpp.h:235
bool WaitForEntryListenerQueue(NT_Inst inst, double timeout)
Wait for the entry listener queue to be empty.
void SetEntryTypeValue(StringRef name, std::shared_ptr< Value > value)
Set Entry Type and Value.
void Flush()
Flush Entries.
const char * SavePersistent(StringRef filename)
Save persistent values to a file.
NT_ConnectionListener AddConnectionListener(ConnectionListenerCallback callback, bool immediate_notify)
Add a connection listener.
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:94
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.
NT_Inst GetDefaultInstance()
Get default instance.
bool WaitForConnectionListenerQueue(NT_Inst inst, double timeout)
Wait for the connection listener queue to be empty.
unsigned int GetNetworkMode()
Get the current network mode.
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:148
unsigned int flags
Entry flags.
Definition: ntcore_cpp.h:55
NT_RpcCall CallRpc(NT_Entry entry, StringRef params)
Call a RPC function.
NT_EntryListener listener
Listener that was triggered.
Definition: ntcore_cpp.h:193
std::string remote_ip
The IP address of the remote node.
Definition: ntcore_cpp.h:79
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:58
NetworkTables RPC Version 1 Definition Result.
Definition: ntcore_cpp.h:117
A network table entry value.
Definition: NetworkTableValue.h:36
void SetNetworkIdentity(StringRef name)
Set the network identity of this node.
unsigned int line
The line number in the source file that generated the message.
Definition: ntcore_cpp.h:268
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
Definition: Twine.h:79
std::vector< ConnectionNotification > PollConnectionListener(NT_ConnectionListenerPoller poller)
Get the next connection event.
void CancelPollLogger(NT_LoggerPoller poller)
Cancel a PollLogger call.
std::vector< RpcAnswer > PollRpc(NT_RpcCallPoller poller)
Get the next incoming RPC 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.
NT_Inst GetInstanceFromHandle(NT_Handle handle)
Get instance handle from another handle.
void StopDSClient()
Stops requesting server address from Driver Station.
unsigned int level
Log level of the message.
Definition: ntcore_cpp.h:262
NT_Logger logger
The logger that generated the message.
Definition: ntcore_cpp.h:259
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:208
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:88
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:265