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" 101 :
name(name_), def_value(def_value_) {}
104 std::shared_ptr<Value> def_value;
118 unsigned int version;
120 std::vector<RpcParamDef> params;
121 std::vector<RpcResultDef> results;
130 :
entry(entry_), call(call_),
name(name_), params(params_), conn(conn_) {}
151 explicit operator bool()
const {
return call != 0; }
158 bool PostResponse(
StringRef result)
const;
175 StringRef name_, std::shared_ptr<Value> value_,
177 : listener(listener_),
217 : listener(listener_), connected(connected_), conn(conn_) {}
223 bool connected =
false;
240 LogMessage() : logger(0), level(0), filename(
""), line(0) {}
241 LogMessage(NT_Logger logger_,
unsigned int level_,
const char* filename_,
368 WPI_DEPRECATED(
"use NT_Entry function instead")
391 WPI_DEPRECATED(
"use NT_Entry function instead")
415 WPI_DEPRECATED(
"use NT_Entry function instead")
427 bool SetEntryValue(NT_Entry entry, std::shared_ptr<Value> value);
441 WPI_DEPRECATED(
"use NT_Entry function instead")
463 WPI_DEPRECATED(
"use NT_Entry function instead")
478 WPI_DEPRECATED(
"use NT_Entry function instead")
500 WPI_DEPRECATED(
"use NT_Entry function instead")
527 WPI_DEPRECATED(
"use NT_Inst function instead")
550 WPI_DEPRECATED(
"use NT_Inst function instead")
589 typedef std::function<void(NT_EntryListener entry_listener,
StringRef name,
590 std::shared_ptr<Value> value,
unsigned int flags)>
601 WPI_DEPRECATED(
"use NT_Inst function instead")
611 NT_Inst inst, const
Twine& prefix,
667 NT_Entry entry,
unsigned int flags);
737 typedef
std::function<
void(NT_ConnectionListener conn_listener,
bool connected,
748 WPI_DEPRECATED("use NT_Inst function instead")
750 bool immediate_notify);
759 bool immediate_notify);
786 NT_ConnectionListenerPoller poller,
bool immediate_notify);
798 NT_ConnectionListenerPoller poller);
813 NT_ConnectionListenerPoller poller,
double timeout,
bool* timed_out);
965 bool GetRpcResult(NT_Entry entry, NT_RpcCall call,
std::
string* result);
977 bool GetRpcResult(NT_Entry entry, NT_RpcCall call,
std::
string* result,
978 double timeout,
bool* timed_out);
1032 WPI_DEPRECATED("use NT_Inst function instead")
1045 WPI_DEPRECATED("use NT_Inst function instead")
1053 unsigned int GetNetworkMode(NT_Inst inst);
1064 WPI_DEPRECATED("use NT_Inst function instead")
1073 const
char* listen_address,
unsigned int port);
1078 WPI_DEPRECATED("use NT_Inst function instead")
1085 void StopServer(NT_Inst inst);
1090 WPI_DEPRECATED("use NT_Inst function instead")
1099 WPI_DEPRECATED("use NT_Inst function instead")
1100 void StartClient(const
char* server_name,
unsigned int port);
1108 WPI_DEPRECATED("use NT_Inst function instead")
1115 void StartClient(NT_Inst inst);
1121 void StartClient(NT_Inst inst, const
char* server_name,
unsigned int port);
1127 void StartClient(NT_Inst inst,
1128 ArrayRef<
std::pair<StringRef,
unsigned int>> servers);
1138 void StartClientTeam(NT_Inst inst,
unsigned int team,
unsigned int port);
1143 WPI_DEPRECATED("use NT_Inst function instead")
1150 void StopClient(NT_Inst inst);
1158 WPI_DEPRECATED("use NT_Inst function instead")
1159 void SetServer(const
char* server_name,
unsigned int port);
1167 WPI_DEPRECATED("use NT_Inst function instead")
1174 void SetServer(NT_Inst inst, const
char* server_name,
unsigned int port);
1181 ArrayRef<
std::pair<StringRef,
unsigned int>> servers);
1191 void SetServerTeam(NT_Inst inst,
unsigned int team,
unsigned int port);
1200 WPI_DEPRECATED("use NT_Inst function instead")
1210 WPI_DEPRECATED("use NT_Inst function instead")
1217 void StopDSClient(NT_Inst inst);
1220 WPI_DEPRECATED("use NT_Inst function instead")
1229 WPI_DEPRECATED("use NT_Inst function instead")
1248 WPI_DEPRECATED("use NT_Inst function instead")
1256 void Flush(NT_Inst inst);
1264 WPI_DEPRECATED("use NT_Inst function instead")
1294 WPI_DEPRECATED("use NT_Inst function instead")
1311 WPI_DEPRECATED("use NT_Inst function instead")
1313 StringRef filename,
std::function<
void(
size_t line, const
char* msg)> warn);
1321 NT_Inst inst, const
Twine& filename,
1322 std::function<
void(
size_t line, const
char* msg)> warn);
1333 const
Twine& prefix);
1345 const
Twine& prefix,
1346 std::function<
void(
size_t line, const
char* msg)> warn);
1377 typedef
std::function<
void(
unsigned int level, const
char* file,
1378 unsigned int line, const
char* msg)>
1391 WPI_DEPRECATED("use NT_Inst function instead")
1409 unsigned int min_level,
unsigned int max_level);
1435 NT_Logger
AddPolledLogger(NT_LoggerPoller poller,
unsigned int min_level,
1436 unsigned int max_level);
1486 inline
bool RpcAnswer::PostResponse(StringRef result)
const {
1494 #endif // NTCORE_NTCORE_CPP_H_ const char * SaveEntries(NT_Inst inst, const Twine &filename, const Twine &prefix)
Save table values to a file.
Definition: ntcore_cpp.cpp:941
NetworkTables Connection Information.
Definition: ntcore_cpp.h:62
void DestroyRpcCallPoller(NT_RpcCallPoller poller)
Destroy a RPC call poller.
Definition: ntcore_cpp.cpp:500
std::vector< ConnectionInfo > GetConnections()
Get information on the currently established network connections.
Definition: ntcore_cpp.cpp:893
void SetEntryFlags(StringRef name, unsigned int flags)
Set Entry Flags.
Definition: ntcore_cpp.cpp:157
bool SetEntryValue(StringRef name, std::shared_ptr< Value > value)
Set Entry Value.
Definition: ntcore_cpp.cpp:131
std::function< void(unsigned int level, const char *file, unsigned int line, const char *msg)> LogFunc
Log function.
Definition: ntcore_cpp.h:1379
unsigned int remote_port
The port number of the remote node.
Definition: ntcore_cpp.h:73
void SetUpdateRate(double interval)
Set the periodic update rate.
Definition: ntcore_cpp.cpp:873
bool WaitForEntryListenerQueue(NT_Inst inst, double timeout)
Wait for the entry listener queue to be empty.
Definition: ntcore_cpp.cpp:368
void SetServer(const char *server_name, unsigned int port)
Sets server address and port for client (without restarting client).
Definition: ntcore_cpp.cpp:823
NT_EntryListenerPoller CreateEntryListenerPoller(NT_Inst inst)
Create a entry listener poller.
Definition: ntcore_cpp.cpp:279
void CreatePolledRpc(NT_Entry entry, StringRef def, NT_RpcCallPoller poller)
Create a polled RPC entry point.
Definition: ntcore_cpp.cpp:509
std::string name
Entry name.
Definition: ntcore_cpp.h:190
std::string remote_id
The remote identifier (as set on the remote node by NetworkTableInstance::SetNetworkIdentity() or nt:...
Definition: ntcore_cpp.h:67
unsigned int GetEntryFlags(StringRef name)
Get Entry Flags.
Definition: ntcore_cpp.cpp:170
NetworkTables log message.
Definition: ntcore_cpp.h:238
std::vector< LogMessage > PollLogger(NT_LoggerPoller poller)
Get the next log event.
Definition: ntcore_cpp.cpp:1015
void DestroyInstance(NT_Inst inst)
Destroy an instance.
Definition: ntcore_cpp.cpp:37
void CancelPollRpc(NT_RpcCallPoller poller)
Cancel a PollRpc call.
Definition: ntcore_cpp.cpp:547
NetworkTables RPC Version 1 Definition.
Definition: ntcore_cpp.h:117
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:591
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:118
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:43
bool connected
True if event is due to connection being established.
Definition: ntcore_cpp.h:223
NetworkTables Remote Procedure Call (Server Side)
Definition: ntcore_cpp.h:125
void RemoveLogger(NT_Logger logger)
Remove a logger.
Definition: ntcore_cpp.cpp:1045
NT_Type type
Entry type.
Definition: ntcore_cpp.h:43
NT_LoggerPoller CreateLoggerPoller(NT_Inst inst)
Create a log poller.
Definition: ntcore_cpp.cpp:984
NetworkTables Entry Notification.
Definition: ntcore_cpp.h:171
Definition: SmallVector.h:946
ConnectionInfo conn
Connection that called the RPC.
Definition: ntcore_cpp.h:145
void Flush()
Flush Entries.
Definition: ntcore_cpp.cpp:884
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory)...
Definition: ArrayRef.h:41
NT_Entry entry
Entry handle.
Definition: ntcore_cpp.h:133
NT_ConnectionListener listener
Listener that was triggered.
Definition: ntcore_cpp.h:220
void RemoveConnectionListener(NT_ConnectionListener conn_listener)
Remove a connection listener.
Definition: ntcore_cpp.cpp:458
NT_RpcCall call
Call handle.
Definition: ntcore_cpp.h:136
NT_Entry entry
Entry handle.
Definition: ntcore_cpp.h:37
NT_Inst GetDefaultInstance()
Get default instance.
Definition: ntcore_cpp.cpp:29
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:242
void CancelPollLogger(NT_LoggerPoller poller)
Cancel a PollLogger call.
Definition: ntcore_cpp.cpp:1036
void CancelRpcResult(NT_Entry entry, NT_RpcCall call)
Ignore the result of a RPC call.
Definition: ntcore_cpp.cpp:619
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:703
NT_Entry entry
Entry handle.
Definition: ntcore_cpp.h:187
NT_Entry GetEntry(NT_Inst inst, const Twine &name)
Get Entry Handle.
Definition: ntcore_cpp.cpp:56
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.
Definition: ntcore_cpp.cpp:949
NT_RpcCall CallRpc(NT_Entry entry, StringRef params)
Call a RPC function.
Definition: ntcore_cpp.cpp:577
void SetEntryTypeValue(StringRef name, std::shared_ptr< Value > value)
Set Entry Type and Value.
Definition: ntcore_cpp.cpp:144
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:926
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:478
void DestroyLoggerPoller(NT_LoggerPoller poller)
Destroy a log poller.
Definition: ntcore_cpp.cpp:992
NT_ConnectionListenerPoller CreateConnectionListenerPoller(NT_Inst inst)
Create a connection listener poller.
Definition: ntcore_cpp.cpp:397
std::vector< NT_Entry > GetEntries(NT_Inst inst, const Twine &prefix, unsigned int types)
Get Entry Handles.
Definition: ntcore_cpp.cpp:66
std::string params
Call raw parameters.
Definition: ntcore_cpp.h:142
void StopServer()
Stops the server if it is running.
Definition: ntcore_cpp.cpp:759
std::vector< RpcAnswer > PollRpc(NT_RpcCallPoller poller)
Get the next incoming RPC call.
Definition: ntcore_cpp.cpp:527
void StartDSClient(unsigned int port)
Starts requesting server address from Driver Station.
Definition: ntcore_cpp.cpp:853
void StopDSClient()
Stops requesting server address from Driver Station.
Definition: ntcore_cpp.cpp:864
bool IsConnected(NT_Inst inst)
Return whether or not the instance is connected to another node.
Definition: ntcore_cpp.cpp:904
std::shared_ptr< Value > value
The new value.
Definition: ntcore_cpp.h:193
std::vector< ConnectionNotification > PollConnectionListener(NT_ConnectionListenerPoller poller)
Get the next connection event.
Definition: ntcore_cpp.cpp:427
Definition: IStorage.h:21
uint64_t Now()
Returns monotonic current time in 1 us increments.
Definition: ntcore_cpp.cpp:717
std::string message
The message.
Definition: ntcore_cpp.h:262
bool PostRpcResponse(NT_Entry entry, NT_RpcCall call, StringRef result)
Post RPC response (return value) for a polled RPC.
Definition: ntcore_cpp.cpp:563
void SetNetworkIdentity(StringRef name)
Set the network identity of this node.
Definition: ntcore_cpp.cpp:723
NetworkTables RPC Version 1 Definition Parameter.
Definition: ntcore_cpp.h:98
NT_RpcCallPoller CreateRpcCallPoller(NT_Inst inst)
Create a RPC call poller.
Definition: ntcore_cpp.cpp:492
void DestroyConnectionListenerPoller(NT_ConnectionListenerPoller poller)
Destroy a connection listener poller.
Definition: ntcore_cpp.cpp:406
void SetLogger(LogFunc func, unsigned int min_level)
Set logger callback function.
Definition: ntcore_cpp.cpp:958
NT_Type GetEntryType(NT_Entry entry)
Gets the type for the specified entry, or unassigned if non existent.
Definition: ntcore_cpp.cpp:87
bool WaitForConnectionListenerQueue(NT_Inst inst, double timeout)
Wait for the connection listener queue to be empty.
Definition: ntcore_cpp.cpp:467
NetworkTables Entry Information.
Definition: ntcore_cpp.h:35
NT_EntryListener AddPolledEntryListener(NT_EntryListenerPoller poller, const Twine &prefix, unsigned int flags)
Create a polled entry listener.
Definition: ntcore_cpp.cpp:297
NetworkTables Connection Notification.
Definition: ntcore_cpp.h:212
std::string name
Entry name.
Definition: ntcore_cpp.h:40
void CancelPollConnectionListener(NT_ConnectionListenerPoller poller)
Cancel a PollConnectionListener call.
Definition: ntcore_cpp.cpp:449
unsigned int GetNetworkMode()
Get the current network mode.
Definition: ntcore_cpp.cpp:734
bool WaitForRpcCallQueue(NT_Inst inst, double timeout)
Wait for the incoming RPC call queue to be empty.
Definition: ntcore_cpp.cpp:556
std::vector< EntryInfo > GetEntryInfo(StringRef prefix, unsigned int types)
Get Entry Information.
Definition: ntcore_cpp.cpp:208
ConnectionInfo conn
Connection info.
Definition: ntcore_cpp.h:226
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:846
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:745
std::vector< EntryNotification > PollEntryListener(NT_EntryListenerPoller poller)
Get the next entry listener event.
Definition: ntcore_cpp.cpp:327
NT_ConnectionListener AddConnectionListener(ConnectionListenerCallback callback, bool immediate_notify)
Add a connection listener.
Definition: ntcore_cpp.cpp:375
const char * SavePersistent(StringRef filename)
Save persistent values to a file.
Definition: ntcore_cpp.cpp:915
unsigned int protocol_version
The protocol version being used for this connection.
Definition: ntcore_cpp.h:85
std::string PackRpcValues(ArrayRef< std::shared_ptr< Value >> values)
Pack RPC values as required for RPC version 1 definition messages.
Definition: ntcore_cpp.cpp:697
void CancelPollEntryListener(NT_EntryListenerPoller poller)
Cancel a PollEntryListener call.
Definition: ntcore_cpp.cpp:350
bool UnpackRpcDefinition(StringRef packed, RpcDefinition *def)
Unpack a RPC version 1 definition.
Definition: ntcore_cpp.cpp:660
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:49
void DeleteAllEntries()
Delete All Entries.
Definition: ntcore_cpp.cpp:196
std::shared_ptr< Value > GetEntryValue(StringRef name)
Get Entry Value.
Definition: ntcore_cpp.cpp:105
std::string name
Entry name.
Definition: ntcore_cpp.h:139
unsigned int flags
Entry flags.
Definition: ntcore_cpp.h:46
NT_Inst CreateInstance()
Create an instance.
Definition: ntcore_cpp.cpp:33
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:971
uint64_t GetEntryLastChange(NT_Entry entry)
Gets the last time the entry was changed.
Definition: ntcore_cpp.cpp:96
NT_EntryListener listener
Listener that was triggered.
Definition: ntcore_cpp.h:184
std::string remote_ip
The IP address of the remote node.
Definition: ntcore_cpp.h:70
bool WaitForLoggerQueue(NT_Inst inst, double timeout)
Wait for the incoming log event queue to be empty.
Definition: ntcore_cpp.cpp:1055
uint64_t last_change
Timestamp of last change to entry (type or value).
Definition: ntcore_cpp.h:49
void DestroyEntryListenerPoller(NT_EntryListenerPoller poller)
Destroy a entry listener poller.
Definition: ntcore_cpp.cpp:288
NetworkTables RPC Version 1 Definition Result.
Definition: ntcore_cpp.h:108
bool GetRpcResult(NT_Entry entry, NT_RpcCall call, std::string *result)
Get the result (return value) of a RPC call.
Definition: ntcore_cpp.cpp:589
A network table entry value.
Definition: NetworkTableValue.h:35
unsigned int line
The line number in the source file that generated the message.
Definition: ntcore_cpp.h:259
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:1001
std::function< void(NT_ConnectionListener conn_listener, bool connected, const ConnectionInfo &conn)> ConnectionListenerCallback
Connection listener callback function.
Definition: ntcore_cpp.h:739
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
Definition: Twine.h:79
void DeleteEntry(StringRef name)
Delete Entry.
Definition: ntcore_cpp.cpp:183
unsigned int level
Log level of the message.
Definition: ntcore_cpp.h:253
std::string PackRpcDefinition(const RpcDefinition &def)
Pack a RPC version 1 definition.
Definition: ntcore_cpp.cpp:633
NT_Logger logger
The logger that generated the message.
Definition: ntcore_cpp.h:250
NT_ConnectionListener AddPolledConnectionListener(NT_ConnectionListenerPoller poller, bool immediate_notify)
Create a polled connection listener.
Definition: ntcore_cpp.cpp:415
void StopClient()
Stops the client if it is running.
Definition: ntcore_cpp.cpp:814
void StartClient()
Starts a client.
Definition: ntcore_cpp.cpp:768
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:806
std::string GetEntryName(NT_Entry entry)
Gets the name of the specified entry.
Definition: ntcore_cpp.cpp:78
void RemoveEntryListener(NT_EntryListener entry_listener)
Remove an entry listener.
Definition: ntcore_cpp.cpp:359
unsigned int flags
Update flags.
Definition: ntcore_cpp.h:199
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:79
const char * filename
The filename of the source file that generated the message.
Definition: ntcore_cpp.h:256