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")
439 bool SetEntryValue(StringRef name, std::shared_ptr<Value> value);
451 bool SetEntryValue(NT_Entry entry, std::shared_ptr<Value> value);
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")
584 WPI_DEPRECATED("use NT_Inst function instead")
585 std::vector<EntryInfo>
GetEntryInfo(StringRef prefix,
unsigned int types);
592 std::vector<EntryInfo>
GetEntryInfo(NT_Inst inst, const Twine& prefix,
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);
914 std::function<
void(const
RpcAnswer& answer)> callback);
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")
1155 WPI_DEPRECATED("use NT_Inst function instead")
1165 const
char* listen_address,
unsigned int port);
1170 WPI_DEPRECATED("use NT_Inst function instead")
1183 WPI_DEPRECATED("use NT_Inst function instead")
1192 WPI_DEPRECATED("use NT_Inst function instead")
1193 void StartClient(const
char* server_name,
unsigned int port);
1201 WPI_DEPRECATED("use NT_Inst function instead")
1216 void StartClient(NT_Inst inst, const
char* server_name,
unsigned int port);
1234 void StartClientTeam(NT_Inst inst,
unsigned int team,
unsigned int port);
1239 WPI_DEPRECATED("use NT_Inst function instead")
1254 WPI_DEPRECATED("use NT_Inst function instead")
1255 void SetServer(const
char* server_name,
unsigned int port);
1263 WPI_DEPRECATED("use NT_Inst function instead")
1271 void SetServer(NT_Inst inst, const
char* server_name,
unsigned int port);
1289 void SetServerTeam(NT_Inst inst,
unsigned int team,
unsigned int port);
1298 WPI_DEPRECATED("use NT_Inst function instead")
1308 WPI_DEPRECATED("use NT_Inst function instead")
1319 WPI_DEPRECATED("use NT_Inst function instead")
1328 WPI_DEPRECATED("use NT_Inst function instead")
1349 WPI_DEPRECATED("use NT_Inst function instead")
1357 void Flush(NT_Inst inst);
1365 WPI_DEPRECATED("use NT_Inst function instead")
1398 WPI_DEPRECATED("use NT_Inst function instead")
1416 WPI_DEPRECATED("use NT_Inst function instead")
1418 StringRef filename, std::function<
void(
size_t line, const
char* msg)> warn);
1427 NT_Inst inst, const
Twine& filename,
1428 std::function<
void(
size_t line, const
char* msg)> warn);
1440 const
Twine& prefix);
1453 const
Twine& prefix,
1454 std::function<
void(
size_t line, const
char* msg)> warn);
1487 typedef std::function<
void(
unsigned int level, const
char* file,
1488 unsigned int line, const
char* msg)>
1501 WPI_DEPRECATED("use NT_Inst function instead")
1518 std::function<
void(const
LogMessage& msg)> func,
1519 unsigned int min_level,
unsigned int max_level);
1548 NT_Logger
AddPolledLogger(NT_LoggerPoller poller,
unsigned int min_level,
1549 unsigned int max_level);
1613 #endif // NTCORE_NTCORE_CPP_H_
NT_Inst GetDefaultInstance()
Get default instance.
void StartClientTeam(NT_Inst inst, unsigned int team, unsigned int port)
Starts a client using commonly known robot addresses for the specified team.
std::function< void(unsigned int level, const char *file, unsigned int line, const char *msg)> LogFunc
Log function.
Definition: ntcore_cpp.h:1489
void CancelPollEntryListener(NT_EntryListenerPoller poller)
Cancel a PollEntryListener call.
void SetServerTeam(NT_Inst inst, unsigned int team, unsigned int port)
Sets server addresses and port for client (without restarting client).
std::string name
Entry name.
Definition: ntcore_cpp.h:49
NT_RpcCall call
Call handle.
Definition: ntcore_cpp.h:145
void DestroyEntryListenerPoller(NT_EntryListenerPoller poller)
Destroy a entry listener poller.
std::vector< ConnectionInfo > GetConnections()
Get information on the currently established network connections.
bool PostResponse(StringRef result) const
Post RPC response (return value) for a polled RPC.
Definition: ntcore_cpp.h:1605
std::function< void(NT_ConnectionListener conn_listener, bool connected, const ConnectionInfo &conn)> ConnectionListenerCallback
Connection listener callback function.
Definition: ntcore_cpp.h:785
std::vector< LogMessage > PollLogger(NT_LoggerPoller poller)
Get the next log event.
void DestroyRpcCallPoller(NT_RpcCallPoller poller)
Destroy a RPC call poller.
std::string PackRpcValues(ArrayRef< std::shared_ptr< Value >> values)
Pack RPC values as required for RPC version 1 definition messages.
NT_ConnectionListenerPoller CreateConnectionListenerPoller(NT_Inst inst)
Create a connection listener poller.
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
bool IsConnected(NT_Inst inst)
Return whether or not the instance is connected to another node.
NetworkTables RPC Version 1 Definition.
Definition: ntcore_cpp.h:126
ConnectionInfo conn
Connection that called the RPC.
Definition: ntcore_cpp.h:154
uint64_t Now()
Returns monotonic current time in 1 us increments.
bool PostRpcResponse(NT_Entry entry, NT_RpcCall call, StringRef result)
Post RPC response (return value) for a polled RPC.
NT_LoggerPoller CreateLoggerPoller(NT_Inst inst)
Create a log poller.
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory),...
Definition: ArrayRef.h:42
std::shared_ptr< Value > value
The new value.
Definition: ntcore_cpp.h:202
void DeleteEntry(StringRef name)
Delete Entry.
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.
ConnectionInfo conn
Connection info.
Definition: ntcore_cpp.h:235
unsigned int flags
Entry flags.
Definition: ntcore_cpp.h:55
bool WaitForEntryListenerQueue(NT_Inst inst, double timeout)
Wait for the entry listener queue to be empty.
void StopServer()
Stops the server if it is running.
NT_Inst GetInstanceFromHandle(NT_Handle handle)
Get instance handle from another handle.
unsigned int flags
Update flags.
Definition: ntcore_cpp.h:208
unsigned int line
The line number in the source file that generated the message.
Definition: ntcore_cpp.h:268
NT_EntryListener AddEntryListener(StringRef prefix, EntryListenerCallback callback, unsigned int flags)
Add a listener for all entries starting with a certain prefix.
NT_EntryListener listener
Listener that was triggered.
Definition: ntcore_cpp.h:193
NetworkTables log message.
Definition: ntcore_cpp.h:247
void DeleteAllEntries()
Delete All Entries.
std::string remote_ip
The IP address of the remote node.
Definition: ntcore_cpp.h:79
NT_EntryListenerPoller CreateEntryListenerPoller(NT_Inst inst)
Create a entry listener poller.
unsigned int protocol_version
The protocol version being used for this connection.
Definition: ntcore_cpp.h:94
void CancelPollConnectionListener(NT_ConnectionListenerPoller poller)
Cancel a PollConnectionListener call.
void RemoveConnectionListener(NT_ConnectionListener conn_listener)
Remove a connection listener.
NetworkTables Entry Notification.
Definition: ntcore_cpp.h:180
bool WaitForLoggerQueue(NT_Inst inst, double timeout)
Wait for the incoming log event queue to be empty.
void CancelRpcResult(NT_Entry entry, NT_RpcCall call)
Ignore the result of a RPC call.
NT_Logger logger
The logger that generated the message.
Definition: ntcore_cpp.h:259
void CreateRpc(NT_Entry entry, StringRef def, std::function< void(const RpcAnswer &answer)> callback)
Create a callback-based RPC entry point.
unsigned int level
Log level of the message.
Definition: ntcore_cpp.h:262
std::string params
Call raw parameters.
Definition: ntcore_cpp.h:151
NT_ConnectionListener listener
Listener that was triggered.
Definition: ntcore_cpp.h:229
NT_Inst CreateInstance()
Create an instance.
void StartServer(StringRef persist_filename, const char *listen_address, unsigned int port)
Starts a server using the specified filename, listening address, and port.
void SetUpdateRate(double interval)
Set the periodic update rate.
uint64_t last_change
Timestamp of last change to entry (type or value).
Definition: ntcore_cpp.h:58
unsigned int GetEntryFlags(StringRef name)
Get Entry Flags.
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.
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
NT_Logger AddPolledLogger(NT_LoggerPoller poller, unsigned int min_level, unsigned int max_level)
Set the log level for a log poller.
NT_Type GetEntryType(NT_Entry entry)
Gets the type for the specified entry, or unassigned if non existent.
void DestroyLoggerPoller(NT_LoggerPoller poller)
Destroy a log poller.
bool SetEntryValue(StringRef name, std::shared_ptr< Value > value)
Set Entry Value.
std::vector< EntryNotification > PollEntryListener(NT_EntryListenerPoller poller)
Get the next entry listener event.
std::string name
Entry name.
Definition: ntcore_cpp.h:148
NetworkTables Remote Procedure Call (Server Side)
Definition: ntcore_cpp.h:134
bool connected
True if event is due to connection being established.
Definition: ntcore_cpp.h:232
const char * SaveEntries(NT_Inst inst, const Twine &filename, const Twine &prefix)
Save table values to a file.
void SetServer(const char *server_name, unsigned int port)
Sets server address and port for client (without restarting client).
void SetEntryTypeValue(StringRef name, std::shared_ptr< Value > value)
Set Entry Type and Value.
void StopLocal(NT_Inst inst)
Stops local-only operation.
std::vector< EntryInfo > GetEntryInfo(StringRef prefix, unsigned int types)
Get Entry Information.
bool SetDefaultEntryValue(StringRef name, std::shared_ptr< Value > value)
Set Default Entry Value.
NetworkTables Connection Notification.
Definition: ntcore_cpp.h:221
const char * filename
The filename of the source file that generated the message.
Definition: ntcore_cpp.h:265
void SetLogger(LogFunc func, unsigned int min_level)
Set logger callback function.
void CreatePolledRpc(NT_Entry entry, StringRef def, NT_RpcCallPoller poller)
Create a polled RPC entry point.
NT_Entry entry
Entry handle.
Definition: ntcore_cpp.h:142
std::shared_ptr< Value > GetEntryValue(StringRef name)
Get Entry Value.
void DestroyConnectionListenerPoller(NT_ConnectionListenerPoller poller)
Destroy a connection listener poller.
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.
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:49
NT_Entry GetEntry(NT_Inst inst, const Twine &name)
Get Entry Handle.
std::string PackRpcDefinition(const RpcDefinition &def)
Pack a RPC version 1 definition.
void StartClient()
Starts a client.
NT_RpcCall CallRpc(NT_Entry entry, StringRef params)
Call a RPC function.
void StartDSClient(unsigned int port)
Starts requesting server address from Driver Station.
bool WaitForRpcCallQueue(NT_Inst inst, double timeout)
Wait for the incoming RPC call queue to be empty.
void RemoveEntryListener(NT_EntryListener entry_listener)
Remove an entry listener.
std::vector< NT_Entry > GetEntries(NT_Inst inst, const Twine &prefix, unsigned int types)
Get Entry Handles.
NT_ConnectionListener AddPolledConnectionListener(NT_ConnectionListenerPoller poller, bool immediate_notify)
Create a polled connection listener.
NT_Entry entry
Entry handle.
Definition: ntcore_cpp.h:196
NetworkTables RPC Version 1 Definition Result.
Definition: ntcore_cpp.h:117
void RemoveLogger(NT_Logger logger)
Remove a logger.
NT_EntryListener AddPolledEntryListener(NT_EntryListenerPoller poller, const Twine &prefix, unsigned int flags)
Create a polled entry listener.
NT_ConnectionListener AddConnectionListener(ConnectionListenerCallback callback, bool immediate_notify)
Add a connection listener.
bool WaitForConnectionListenerQueue(NT_Inst inst, double timeout)
Wait for the connection listener queue to be empty.
void SetEntryFlags(StringRef name, unsigned int flags)
Set Entry Flags.
const char * LoadPersistent(StringRef filename, std::function< void(size_t line, const char *msg)> warn)
Load persistent values from a file.
void StopDSClient()
Stops requesting server address from Driver Station.
void StopClient()
Stops the client if it is running.
void DestroyInstance(NT_Inst inst)
Destroy an instance.
NetworkTables RPC Version 1 Definition Parameter.
Definition: ntcore_cpp.h:107
NT_Type type
Entry type.
Definition: ntcore_cpp.h:52
std::string name
Entry name.
Definition: ntcore_cpp.h:199
A network table entry value.
Definition: NetworkTableValue.h:37
NT_Entry entry
Entry handle.
Definition: ntcore_cpp.h:46
const char * SavePersistent(StringRef filename)
Save persistent values to a file.
NT_Type
NetworkTables data types.
Definition: ntcore_c.h:52
void CancelPollRpc(NT_RpcCallPoller poller)
Cancel a PollRpc call.
unsigned int GetNetworkMode()
Get the current network mode.
unsigned int remote_port
The port number of the remote node.
Definition: ntcore_cpp.h:82
NetworkTables Connection Information.
Definition: ntcore_cpp.h:71
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.
std::vector< ConnectionNotification > PollConnectionListener(NT_ConnectionListenerPoller poller)
Get the next connection event.
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
Definition: Twine.h:85
NetworkTables (ntcore) namespace.
Definition: NetworkTableValue.h:27
std::string remote_id
The remote identifier (as set on the remote node by NetworkTableInstance::SetNetworkIdentity() or nt:...
Definition: ntcore_cpp.h:76
void Flush()
Flush Entries.
void StartLocal(NT_Inst inst)
Starts local-only operation.
void SetNetworkIdentity(StringRef name)
Set the network identity of this node.
void StopRpcServer()
Stops the RPC server if it is running.
bool UnpackRpcDefinition(StringRef packed, RpcDefinition *def)
Unpack a RPC version 1 definition.
void CancelPollLogger(NT_LoggerPoller poller)
Cancel a PollLogger call.
bool GetRpcResult(NT_Entry entry, NT_RpcCall call, std::string *result)
Get the result (return value) of a RPC call.
NT_RpcCallPoller CreateRpcCallPoller(NT_Inst inst)
Create a RPC call poller.
std::string message
The message.
Definition: ntcore_cpp.h:271
NetworkTables Entry Information.
Definition: ntcore_cpp.h:44