18 #include "llvm/ArrayRef.h" 19 #include "llvm/StringRef.h" 20 #include "support/deprecated.h" 22 #include "networktables/NetworkTableValue.h" 96 :
name(name_), def_value(def_value_) {}
99 std::shared_ptr<Value> def_value;
113 unsigned int version;
115 std::vector<RpcParamDef> params;
116 std::vector<RpcResultDef> results;
125 :
entry(entry_), call(call_),
name(name_), params(params_), conn(conn_) {}
146 explicit operator bool()
const {
return call != 0; }
152 void PostResponse(
StringRef result)
const;
171 : listener(listener_),
211 : listener(listener_), connected(connected_), conn(conn_) {}
217 bool connected =
false;
234 LogMessage() : logger(0), level(0), filename(
""), line(0) {}
235 LogMessage(NT_Logger logger_,
unsigned int level_,
const char* filename_,
362 WPI_DEPRECATED(
"use NT_Entry function instead")
385 WPI_DEPRECATED(
"use NT_Entry function instead")
409 WPI_DEPRECATED(
"use NT_Entry function instead")
421 bool SetEntryValue(NT_Entry entry, std::shared_ptr<Value> value);
435 WPI_DEPRECATED(
"use NT_Entry function instead")
457 WPI_DEPRECATED(
"use NT_Entry function instead")
472 WPI_DEPRECATED(
"use NT_Entry function instead")
494 WPI_DEPRECATED(
"use NT_Entry function instead")
521 WPI_DEPRECATED(
"use NT_Inst function instead")
544 WPI_DEPRECATED(
"use NT_Inst function instead")
583 typedef std::function<void(NT_EntryListener entry_listener,
StringRef name,
584 std::shared_ptr<Value> value,
unsigned int flags)>
595 WPI_DEPRECATED(
"use NT_Inst function instead")
660 NT_Entry entry,
unsigned int flags);
730 typedef
std::function<
void(NT_ConnectionListener conn_listener,
bool connected,
741 WPI_DEPRECATED("use NT_Inst function instead")
743 bool immediate_notify);
752 bool immediate_notify);
779 NT_ConnectionListenerPoller poller,
bool immediate_notify);
791 NT_ConnectionListenerPoller poller);
806 NT_ConnectionListenerPoller poller,
double timeout,
bool* timed_out);
957 bool GetRpcResult(NT_Entry entry, NT_RpcCall call,
std::
string* result);
969 bool GetRpcResult(NT_Entry entry, NT_RpcCall call,
std::
string* result,
970 double timeout,
bool* timed_out);
1024 WPI_DEPRECATED("use NT_Inst function instead")
1037 WPI_DEPRECATED("use NT_Inst function instead")
1045 unsigned int GetNetworkMode(NT_Inst inst);
1056 WPI_DEPRECATED("use NT_Inst function instead")
1065 const
char* listen_address,
unsigned int port);
1070 WPI_DEPRECATED("use NT_Inst function instead")
1077 void StopServer(NT_Inst inst);
1082 WPI_DEPRECATED("use NT_Inst function instead")
1091 WPI_DEPRECATED("use NT_Inst function instead")
1092 void StartClient(const
char* server_name,
unsigned int port);
1100 WPI_DEPRECATED("use NT_Inst function instead")
1107 void StartClient(NT_Inst inst);
1113 void StartClient(NT_Inst inst, const
char* server_name,
unsigned int port);
1119 void StartClient(NT_Inst inst,
1120 ArrayRef<
std::pair<StringRef,
unsigned int>> servers);
1130 void StartClientTeam(NT_Inst inst,
unsigned int team,
unsigned int port);
1135 WPI_DEPRECATED("use NT_Inst function instead")
1142 void StopClient(NT_Inst inst);
1150 WPI_DEPRECATED("use NT_Inst function instead")
1151 void SetServer(const
char* server_name,
unsigned int port);
1159 WPI_DEPRECATED("use NT_Inst function instead")
1166 void SetServer(NT_Inst inst, const
char* server_name,
unsigned int port);
1173 ArrayRef<
std::pair<StringRef,
unsigned int>> servers);
1183 void SetServerTeam(NT_Inst inst,
unsigned int team,
unsigned int port);
1192 WPI_DEPRECATED("use NT_Inst function instead")
1202 WPI_DEPRECATED("use NT_Inst function instead")
1209 void StopDSClient(NT_Inst inst);
1212 WPI_DEPRECATED("use NT_Inst function instead")
1221 WPI_DEPRECATED("use NT_Inst function instead")
1240 WPI_DEPRECATED("use NT_Inst function instead")
1248 void Flush(NT_Inst inst);
1256 WPI_DEPRECATED("use NT_Inst function instead")
1286 WPI_DEPRECATED("use NT_Inst function instead")
1303 WPI_DEPRECATED("use NT_Inst function instead")
1305 StringRef filename,
std::function<
void(
size_t line, const
char* msg)> warn);
1313 NT_Inst inst, StringRef filename,
1314 std::function<
void(
size_t line, const
char* msg)> warn);
1324 const
char*
SaveEntries(NT_Inst inst, StringRef filename, StringRef prefix);
1335 const
char*
LoadEntries(NT_Inst inst, StringRef filename, StringRef prefix,
1336 std::function<
void(
size_t line, const
char* msg)> warn);
1351 unsigned long long Now();
1367 typedef
std::function<
void(
unsigned int level, const
char* file,
1368 unsigned int line, const
char* msg)>
1381 WPI_DEPRECATED("use NT_Inst function instead")
1399 unsigned int min_level,
unsigned int max_level);
1425 NT_Logger
AddPolledLogger(NT_LoggerPoller poller,
unsigned int min_level,
1426 unsigned int max_level);
1476 inline
void RpcAnswer::PostResponse(StringRef result)
const {
NetworkTables Connection Information.
Definition: ntcore_cpp.h:57
void DestroyRpcCallPoller(NT_RpcCallPoller poller)
Destroy a RPC call poller.
Definition: ntcore_cpp.cpp:498
std::vector< ConnectionInfo > GetConnections()
Get information on the currently established network connections.
Definition: ntcore_cpp.cpp:891
NT_EntryListener AddPolledEntryListener(NT_EntryListenerPoller poller, StringRef prefix, unsigned int flags)
Create a polled entry listener.
Definition: ntcore_cpp.cpp:296
void SetEntryFlags(StringRef name, unsigned int flags)
Set Entry Flags.
Definition: ntcore_cpp.cpp:156
bool SetEntryValue(StringRef name, std::shared_ptr< Value > value)
Set Entry Value.
Definition: ntcore_cpp.cpp:130
std::function< void(unsigned int level, const char *file, unsigned int line, const char *msg)> LogFunc
Log function.
Definition: ntcore_cpp.h:1369
unsigned int remote_port
The port number of the remote node.
Definition: ntcore_cpp.h:68
void SetUpdateRate(double interval)
Set the periodic update rate.
Definition: ntcore_cpp.cpp:871
bool WaitForEntryListenerQueue(NT_Inst inst, double timeout)
Wait for the entry listener queue to be empty.
Definition: ntcore_cpp.cpp:366
void SetServer(const char *server_name, unsigned int port)
Sets server address and port for client (without restarting client).
Definition: ntcore_cpp.cpp:821
NT_EntryListenerPoller CreateEntryListenerPoller(NT_Inst inst)
Create a entry listener poller.
Definition: ntcore_cpp.cpp:278
void CreatePolledRpc(NT_Entry entry, StringRef def, NT_RpcCallPoller poller)
Create a polled RPC entry point.
Definition: ntcore_cpp.cpp:507
std::string name
Entry name.
Definition: ntcore_cpp.h:184
std::string remote_id
The remote identifier (as set on the remote node by NetworkTableInstance::SetNetworkIdentity() or nt:...
Definition: ntcore_cpp.h:62
unsigned int GetEntryFlags(StringRef name)
Get Entry Flags.
Definition: ntcore_cpp.cpp:169
NetworkTables log message.
Definition: ntcore_cpp.h:232
std::vector< LogMessage > PollLogger(NT_LoggerPoller poller)
Get the next log event.
Definition: ntcore_cpp.cpp:1012
void DestroyInstance(NT_Inst inst)
Destroy an instance.
Definition: ntcore_cpp.cpp:36
void CancelPollRpc(NT_RpcCallPoller poller)
Cancel a PollRpc call.
Definition: ntcore_cpp.cpp:545
NetworkTables RPC Version 1 Definition.
Definition: ntcore_cpp.h:112
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:585
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:117
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:42
bool connected
True if event is due to connection being established.
Definition: ntcore_cpp.h:217
NetworkTables Remote Procedure Call (Server Side)
Definition: ntcore_cpp.h:120
unsigned long long last_change
Timestamp of last change to entry (type or value).
Definition: ntcore_cpp.h:44
void RemoveLogger(NT_Logger logger)
Remove a logger.
Definition: ntcore_cpp.cpp:1042
NT_Type type
Entry type.
Definition: ntcore_cpp.h:38
NT_LoggerPoller CreateLoggerPoller(NT_Inst inst)
Create a log poller.
Definition: ntcore_cpp.cpp:981
NetworkTables Entry Notification.
Definition: ntcore_cpp.h:165
Definition: json.cpp:1170
ConnectionInfo conn
Connection that called the RPC.
Definition: ntcore_cpp.h:140
void Flush()
Flush Entries.
Definition: ntcore_cpp.cpp:882
NT_Entry entry
Entry handle.
Definition: ntcore_cpp.h:128
NT_ConnectionListener listener
Listener that was triggered.
Definition: ntcore_cpp.h:214
void RemoveConnectionListener(NT_ConnectionListener conn_listener)
Remove a connection listener.
Definition: ntcore_cpp.cpp:456
NT_RpcCall call
Call handle.
Definition: ntcore_cpp.h:131
const char * LoadEntries(NT_Inst inst, StringRef filename, StringRef prefix, std::function< void(size_t line, const char *msg)> warn)
Load table values from a file.
Definition: ntcore_cpp.cpp:946
NT_Entry entry
Entry handle.
Definition: ntcore_cpp.h:32
NT_Inst GetDefaultInstance()
Get default instance.
Definition: ntcore_cpp.cpp:28
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:241
void CancelPollLogger(NT_LoggerPoller poller)
Cancel a PollLogger call.
Definition: ntcore_cpp.cpp:1033
void CancelRpcResult(NT_Entry entry, NT_RpcCall call)
Ignore the result of a RPC call.
Definition: ntcore_cpp.cpp:617
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:701
std::vector< NT_Entry > GetEntries(NT_Inst inst, StringRef prefix, unsigned int types)
Get Entry Handles.
Definition: ntcore_cpp.cpp:65
NT_Entry entry
Entry handle.
Definition: ntcore_cpp.h:181
NT_RpcCall CallRpc(NT_Entry entry, StringRef params)
Call a RPC function.
Definition: ntcore_cpp.cpp:575
void SetEntryTypeValue(StringRef name, std::shared_ptr< Value > value)
Set Entry Type and Value.
Definition: ntcore_cpp.cpp:143
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:924
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:476
void PostRpcResponse(NT_Entry entry, NT_RpcCall call, StringRef result)
Post RPC response (return value) for a polled RPC.
Definition: ntcore_cpp.cpp:561
void DestroyLoggerPoller(NT_LoggerPoller poller)
Destroy a log poller.
Definition: ntcore_cpp.cpp:989
NT_ConnectionListenerPoller CreateConnectionListenerPoller(NT_Inst inst)
Create a connection listener poller.
Definition: ntcore_cpp.cpp:395
std::string params
Call raw parameters.
Definition: ntcore_cpp.h:137
void StopServer()
Stops the server if it is running.
Definition: ntcore_cpp.cpp:757
std::vector< RpcAnswer > PollRpc(NT_RpcCallPoller poller)
Get the next incoming RPC call.
Definition: ntcore_cpp.cpp:525
NT_Entry GetEntry(NT_Inst inst, StringRef name)
Get Entry Handle.
Definition: ntcore_cpp.cpp:55
void StartDSClient(unsigned int port)
Starts requesting server address from Driver Station.
Definition: ntcore_cpp.cpp:851
void StopDSClient()
Stops requesting server address from Driver Station.
Definition: ntcore_cpp.cpp:862
bool IsConnected(NT_Inst inst)
Return whether or not the instance is connected to another node.
Definition: ntcore_cpp.cpp:902
std::shared_ptr< Value > value
The new value.
Definition: ntcore_cpp.h:187
std::vector< ConnectionNotification > PollConnectionListener(NT_ConnectionListenerPoller poller)
Get the next connection event.
Definition: ntcore_cpp.cpp:425
Definition: IEntryNotifier.h:15
std::string message
The message.
Definition: ntcore_cpp.h:256
void SetNetworkIdentity(StringRef name)
Set the network identity of this node.
Definition: ntcore_cpp.cpp:721
NetworkTables RPC Version 1 Definition Parameter.
Definition: ntcore_cpp.h:93
NT_RpcCallPoller CreateRpcCallPoller(NT_Inst inst)
Create a RPC call poller.
Definition: ntcore_cpp.cpp:490
void DestroyConnectionListenerPoller(NT_ConnectionListenerPoller poller)
Destroy a connection listener poller.
Definition: ntcore_cpp.cpp:404
void SetLogger(LogFunc func, unsigned int min_level)
Set logger callback function.
Definition: ntcore_cpp.cpp:955
NT_Type GetEntryType(NT_Entry entry)
Gets the type for the specified entry, or unassigned if non existent.
Definition: ntcore_cpp.cpp:86
bool WaitForConnectionListenerQueue(NT_Inst inst, double timeout)
Wait for the connection listener queue to be empty.
Definition: ntcore_cpp.cpp:465
NetworkTables Entry Information.
Definition: ntcore_cpp.h:30
NetworkTables Connection Notification.
Definition: ntcore_cpp.h:206
std::string name
Entry name.
Definition: ntcore_cpp.h:35
void CancelPollConnectionListener(NT_ConnectionListenerPoller poller)
Cancel a PollConnectionListener call.
Definition: ntcore_cpp.cpp:447
unsigned int GetNetworkMode()
Get the current network mode.
Definition: ntcore_cpp.cpp:732
bool WaitForRpcCallQueue(NT_Inst inst, double timeout)
Wait for the incoming RPC call queue to be empty.
Definition: ntcore_cpp.cpp:554
std::vector< EntryInfo > GetEntryInfo(StringRef prefix, unsigned int types)
Get Entry Information.
Definition: ntcore_cpp.cpp:207
ConnectionInfo conn
Connection info.
Definition: ntcore_cpp.h:220
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:844
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:743
unsigned long long last_update
The last time any update was received from the remote node (same scale as returned by nt::Now())...
Definition: ntcore_cpp.h:74
std::vector< EntryNotification > PollEntryListener(NT_EntryListenerPoller poller)
Get the next entry listener event.
Definition: ntcore_cpp.cpp:325
NT_ConnectionListener AddConnectionListener(ConnectionListenerCallback callback, bool immediate_notify)
Add a connection listener.
Definition: ntcore_cpp.cpp:373
const char * SavePersistent(StringRef filename)
Save persistent values to a file.
Definition: ntcore_cpp.cpp:913
unsigned int protocol_version
The protocol version being used for this connection.
Definition: ntcore_cpp.h:80
std::string PackRpcValues(ArrayRef< std::shared_ptr< Value >> values)
Pack RPC values as required for RPC version 1 definition messages.
Definition: ntcore_cpp.cpp:695
void CancelPollEntryListener(NT_EntryListenerPoller poller)
Cancel a PollEntryListener call.
Definition: ntcore_cpp.cpp:348
bool UnpackRpcDefinition(StringRef packed, RpcDefinition *def)
Unpack a RPC version 1 definition.
Definition: ntcore_cpp.cpp:658
void DeleteAllEntries()
Delete All Entries.
Definition: ntcore_cpp.cpp:195
std::shared_ptr< Value > GetEntryValue(StringRef name)
Get Entry Value.
Definition: ntcore_cpp.cpp:104
std::string name
Entry name.
Definition: ntcore_cpp.h:134
unsigned int flags
Entry flags.
Definition: ntcore_cpp.h:41
NT_Inst CreateInstance()
Create an instance.
Definition: ntcore_cpp.cpp:32
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:968
NT_EntryListener listener
Listener that was triggered.
Definition: ntcore_cpp.h:178
unsigned long long Now()
Returns monotonic current time in 100 ns increments.
Definition: ntcore_cpp.cpp:715
std::string remote_ip
The IP address of the remote node.
Definition: ntcore_cpp.h:65
bool WaitForLoggerQueue(NT_Inst inst, double timeout)
Wait for the incoming log event queue to be empty.
Definition: ntcore_cpp.cpp:1052
void DestroyEntryListenerPoller(NT_EntryListenerPoller poller)
Destroy a entry listener poller.
Definition: ntcore_cpp.cpp:287
NetworkTables RPC Version 1 Definition Result.
Definition: ntcore_cpp.h:103
bool GetRpcResult(NT_Entry entry, NT_RpcCall call, std::string *result)
Get the result (return value) of a RPC call.
Definition: ntcore_cpp.cpp:587
const char * SaveEntries(NT_Inst inst, StringRef filename, StringRef prefix)
Save table values to a file.
Definition: ntcore_cpp.cpp:939
A network table entry value.
Definition: NetworkTableValue.h:30
unsigned int line
The line number in the source file that generated the message.
Definition: ntcore_cpp.h:253
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:998
std::function< void(NT_ConnectionListener conn_listener, bool connected, const ConnectionInfo &conn)> ConnectionListenerCallback
Connection listener callback function.
Definition: ntcore_cpp.h:732
void DeleteEntry(StringRef name)
Delete Entry.
Definition: ntcore_cpp.cpp:182
unsigned int level
Log level of the message.
Definition: ntcore_cpp.h:247
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:631
NT_Logger logger
The logger that generated the message.
Definition: ntcore_cpp.h:244
NT_ConnectionListener AddPolledConnectionListener(NT_ConnectionListenerPoller poller, bool immediate_notify)
Create a polled connection listener.
Definition: ntcore_cpp.cpp:413
void StopClient()
Stops the client if it is running.
Definition: ntcore_cpp.cpp:812
void StartClient()
Starts a client.
Definition: ntcore_cpp.cpp:766
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:804
std::string GetEntryName(NT_Entry entry)
Gets the name of the specified entry.
Definition: ntcore_cpp.cpp:77
void RemoveEntryListener(NT_EntryListener entry_listener)
Remove an entry listener.
Definition: ntcore_cpp.cpp:357
unsigned long long GetEntryLastChange(NT_Entry entry)
Gets the last time the entry was changed.
Definition: ntcore_cpp.cpp:95
unsigned int flags
Update flags.
Definition: ntcore_cpp.h:193
const char * filename
The filename of the source file that generated the message.
Definition: ntcore_cpp.h:250