8 #ifndef NTCORE_NTCORE_CPP_H_ 9 #define NTCORE_NTCORE_CPP_H_ 20 #include <llvm/ArrayRef.h> 21 #include <llvm/StringRef.h> 22 #include <llvm/Twine.h> 23 #include <support/deprecated.h> 25 #include "networktables/NetworkTableValue.h" 100 :
name(name_), def_value(def_value_) {}
103 std::shared_ptr<Value> def_value;
117 unsigned int version;
119 std::vector<RpcParamDef> params;
120 std::vector<RpcResultDef> results;
129 :
entry(entry_), call(call_),
name(name_), params(params_), conn(conn_) {}
150 explicit operator bool()
const {
return call != 0; }
156 void PostResponse(
StringRef result)
const;
173 StringRef name_, std::shared_ptr<Value> value_,
175 : listener(listener_),
215 : listener(listener_), connected(connected_), conn(conn_) {}
221 bool connected =
false;
238 LogMessage() : logger(0), level(0), filename(
""), line(0) {}
239 LogMessage(NT_Logger logger_,
unsigned int level_,
const char* filename_,
366 WPI_DEPRECATED(
"use NT_Entry function instead")
389 WPI_DEPRECATED(
"use NT_Entry function instead")
413 WPI_DEPRECATED(
"use NT_Entry function instead")
425 bool SetEntryValue(NT_Entry entry, std::shared_ptr<Value> value);
439 WPI_DEPRECATED(
"use NT_Entry function instead")
461 WPI_DEPRECATED(
"use NT_Entry function instead")
476 WPI_DEPRECATED(
"use NT_Entry function instead")
498 WPI_DEPRECATED(
"use NT_Entry function instead")
525 WPI_DEPRECATED(
"use NT_Inst function instead")
548 WPI_DEPRECATED(
"use NT_Inst function instead")
587 typedef std::function<void(NT_EntryListener entry_listener,
StringRef name,
588 std::shared_ptr<Value> value,
unsigned int flags)>
599 WPI_DEPRECATED(
"use NT_Inst function instead")
609 NT_Inst inst, const
Twine& prefix,
665 NT_Entry entry,
unsigned int flags);
735 typedef
std::function<
void(NT_ConnectionListener conn_listener,
bool connected,
746 WPI_DEPRECATED("use NT_Inst function instead")
748 bool immediate_notify);
757 bool immediate_notify);
784 NT_ConnectionListenerPoller poller,
bool immediate_notify);
796 NT_ConnectionListenerPoller poller);
811 NT_ConnectionListenerPoller poller,
double timeout,
bool* timed_out);
962 bool GetRpcResult(NT_Entry entry, NT_RpcCall call,
std::
string* result);
974 bool GetRpcResult(NT_Entry entry, NT_RpcCall call,
std::
string* result,
975 double timeout,
bool* timed_out);
1029 WPI_DEPRECATED("use NT_Inst function instead")
1042 WPI_DEPRECATED("use NT_Inst function instead")
1050 unsigned int GetNetworkMode(NT_Inst inst);
1061 WPI_DEPRECATED("use NT_Inst function instead")
1070 const
char* listen_address,
unsigned int port);
1075 WPI_DEPRECATED("use NT_Inst function instead")
1082 void StopServer(NT_Inst inst);
1087 WPI_DEPRECATED("use NT_Inst function instead")
1096 WPI_DEPRECATED("use NT_Inst function instead")
1097 void StartClient(const
char* server_name,
unsigned int port);
1105 WPI_DEPRECATED("use NT_Inst function instead")
1112 void StartClient(NT_Inst inst);
1118 void StartClient(NT_Inst inst, const
char* server_name,
unsigned int port);
1124 void StartClient(NT_Inst inst,
1125 ArrayRef<
std::pair<StringRef,
unsigned int>> servers);
1135 void StartClientTeam(NT_Inst inst,
unsigned int team,
unsigned int port);
1140 WPI_DEPRECATED("use NT_Inst function instead")
1147 void StopClient(NT_Inst inst);
1155 WPI_DEPRECATED("use NT_Inst function instead")
1156 void SetServer(const
char* server_name,
unsigned int port);
1164 WPI_DEPRECATED("use NT_Inst function instead")
1171 void SetServer(NT_Inst inst, const
char* server_name,
unsigned int port);
1178 ArrayRef<
std::pair<StringRef,
unsigned int>> servers);
1188 void SetServerTeam(NT_Inst inst,
unsigned int team,
unsigned int port);
1197 WPI_DEPRECATED("use NT_Inst function instead")
1207 WPI_DEPRECATED("use NT_Inst function instead")
1214 void StopDSClient(NT_Inst inst);
1217 WPI_DEPRECATED("use NT_Inst function instead")
1226 WPI_DEPRECATED("use NT_Inst function instead")
1245 WPI_DEPRECATED("use NT_Inst function instead")
1253 void Flush(NT_Inst inst);
1261 WPI_DEPRECATED("use NT_Inst function instead")
1291 WPI_DEPRECATED("use NT_Inst function instead")
1308 WPI_DEPRECATED("use NT_Inst function instead")
1310 StringRef filename,
std::function<
void(
size_t line, const
char* msg)> warn);
1318 NT_Inst inst, const
Twine& filename,
1319 std::function<
void(
size_t line, const
char* msg)> warn);
1330 const
Twine& prefix);
1342 const
Twine& prefix,
1343 std::function<
void(
size_t line, const
char* msg)> warn);
1374 typedef
std::function<
void(
unsigned int level, const
char* file,
1375 unsigned int line, const
char* msg)>
1388 WPI_DEPRECATED("use NT_Inst function instead")
1406 unsigned int min_level,
unsigned int max_level);
1432 NT_Logger
AddPolledLogger(NT_LoggerPoller poller,
unsigned int min_level,
1433 unsigned int max_level);
1483 inline
void RpcAnswer::PostResponse(StringRef result)
const {
1489 #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:61
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:1376
unsigned int remote_port
The port number of the remote node.
Definition: ntcore_cpp.h:72
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:188
std::string remote_id
The remote identifier (as set on the remote node by NetworkTableInstance::SetNetworkIdentity() or nt:...
Definition: ntcore_cpp.h:66
unsigned int GetEntryFlags(StringRef name)
Get Entry Flags.
Definition: ntcore_cpp.cpp:170
NetworkTables log message.
Definition: ntcore_cpp.h:236
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:116
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:589
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:221
NetworkTables Remote Procedure Call (Server Side)
Definition: ntcore_cpp.h:124
void RemoveLogger(NT_Logger logger)
Remove a logger.
Definition: ntcore_cpp.cpp:1045
NT_Type type
Entry type.
Definition: ntcore_cpp.h:42
NT_LoggerPoller CreateLoggerPoller(NT_Inst inst)
Create a log poller.
Definition: ntcore_cpp.cpp:984
NetworkTables Entry Notification.
Definition: ntcore_cpp.h:169
Definition: json.cpp:1170
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
Definition: Twine.h:79
ConnectionInfo conn
Connection that called the RPC.
Definition: ntcore_cpp.h:144
void Flush()
Flush Entries.
Definition: ntcore_cpp.cpp:884
NT_Entry entry
Entry handle.
Definition: ntcore_cpp.h:132
NT_ConnectionListener listener
Listener that was triggered.
Definition: ntcore_cpp.h:218
void RemoveConnectionListener(NT_ConnectionListener conn_listener)
Remove a connection listener.
Definition: ntcore_cpp.cpp:458
NT_RpcCall call
Call handle.
Definition: ntcore_cpp.h:135
NT_Entry entry
Entry handle.
Definition: ntcore_cpp.h:36
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
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:703
NT_Entry entry
Entry handle.
Definition: ntcore_cpp.h:185
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 PostRpcResponse(NT_Entry entry, NT_RpcCall call, StringRef result)
Post RPC response (return value) for a polled RPC.
Definition: ntcore_cpp.cpp:563
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:141
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:191
std::vector< ConnectionNotification > PollConnectionListener(NT_ConnectionListenerPoller poller)
Get the next connection event.
Definition: ntcore_cpp.cpp:427
Definition: IEntryNotifier.h:16
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:260
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:97
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:34
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:210
std::string name
Entry name.
Definition: ntcore_cpp.h:39
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:224
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:84
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
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:138
unsigned int flags
Entry flags.
Definition: ntcore_cpp.h:45
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:182
std::string remote_ip
The IP address of the remote node.
Definition: ntcore_cpp.h:69
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:48
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:107
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:257
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:737
void DeleteEntry(StringRef name)
Delete Entry.
Definition: ntcore_cpp.cpp:183
unsigned int level
Log level of the message.
Definition: ntcore_cpp.h:251
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:633
NT_Logger logger
The logger that generated the message.
Definition: ntcore_cpp.h:248
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:197
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:78
const char * filename
The filename of the source file that generated the message.
Definition: ntcore_cpp.h:254