WPILibC++  2018.4.1-20180824021726-1174-g488ba79
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Modules Pages
Remote Procedure Call Functions

Functions

void nt::CreateRpc (NT_Entry entry, StringRef def, std::function< void(const RpcAnswer &answer)> callback)
 Create a callback-based RPC entry point. More...
 
NT_RpcCallPoller nt::CreateRpcCallPoller (NT_Inst inst)
 Create a RPC call poller. More...
 
void nt::DestroyRpcCallPoller (NT_RpcCallPoller poller)
 Destroy a RPC call poller. More...
 
void nt::CreatePolledRpc (NT_Entry entry, StringRef def, NT_RpcCallPoller poller)
 Create a polled RPC entry point. More...
 
std::vector< RpcAnswer > nt::PollRpc (NT_RpcCallPoller poller)
 Get the next incoming RPC call. More...
 
std::vector< RpcAnswer > nt::PollRpc (NT_RpcCallPoller poller, double timeout, bool *timed_out)
 Get the next incoming RPC call. More...
 
void nt::CancelPollRpc (NT_RpcCallPoller poller)
 Cancel a PollRpc call. More...
 
bool nt::WaitForRpcCallQueue (NT_Inst inst, double timeout)
 Wait for the incoming RPC call queue to be empty. More...
 
bool nt::PostRpcResponse (NT_Entry entry, NT_RpcCall call, StringRef result)
 Post RPC response (return value) for a polled RPC. More...
 
NT_RpcCall nt::CallRpc (NT_Entry entry, StringRef params)
 Call a RPC function. More...
 
bool nt::GetRpcResult (NT_Entry entry, NT_RpcCall call, std::string *result)
 Get the result (return value) of a RPC call. More...
 
bool nt::GetRpcResult (NT_Entry entry, NT_RpcCall call, std::string *result, double timeout, bool *timed_out)
 Get the result (return value) of a RPC call. More...
 
void nt::CancelRpcResult (NT_Entry entry, NT_RpcCall call)
 Ignore the result of a RPC call. More...
 
std::string nt::PackRpcDefinition (const RpcDefinition &def)
 Pack a RPC version 1 definition. More...
 
bool nt::UnpackRpcDefinition (StringRef packed, RpcDefinition *def)
 Unpack a RPC version 1 definition. More...
 
std::string nt::PackRpcValues (ArrayRef< std::shared_ptr< Value >> values)
 Pack RPC values as required for RPC version 1 definition messages. More...
 
std::vector< std::shared_ptr
< Value > > 
nt::UnpackRpcValues (StringRef packed, ArrayRef< NT_Type > types)
 Unpack RPC values as required for RPC version 1 definition messages. More...
 

Detailed Description

Function Documentation

NT_RpcCall nt::CallRpc ( NT_Entry  entry,
StringRef  params 
)

Call a RPC function.

May be used on either the client or server. This function is non-blocking. Either GetRpcResult() or CancelRpcResult() must be called to either get or ignore the result of the call.

Parameters
entryentry handle of RPC entry
paramsparameter
Returns
RPC call handle (for use with GetRpcResult() or CancelRpcResult()).
void nt::CancelPollRpc ( NT_RpcCallPoller  poller)

Cancel a PollRpc call.

This wakes up a call to PollRpc for this poller and causes it to immediately return an empty array.

Parameters
pollerpoller handle
void nt::CancelRpcResult ( NT_Entry  entry,
NT_RpcCall  call 
)

Ignore the result of a RPC call.

This function is non-blocking.

Parameters
entryentry handle of RPC entry
callRPC call handle returned by CallRpc()
void nt::CreatePolledRpc ( NT_Entry  entry,
StringRef  def,
NT_RpcCallPoller  poller 
)

Create a polled RPC entry point.

Only valid to use on the server. The caller is responsible for calling PollRpc() to poll for servicing incoming RPC calls.

Parameters
entryentry handle of RPC entry
defRPC definition
pollerpoller handle
void nt::CreateRpc ( NT_Entry  entry,
StringRef  def,
std::function< void(const RpcAnswer &answer)>  callback 
)

Create a callback-based RPC entry point.

Only valid to use on the server. The callback function will be called when the RPC is called.

Parameters
entryentry handle of RPC entry
defRPC definition
callbackcallback function; note the callback function must call PostRpcResponse() to provide a response to the call
NT_RpcCallPoller nt::CreateRpcCallPoller ( NT_Inst  inst)

Create a RPC call poller.

Only valid to use on the server.

A poller provides a single queue of poll events. Events linked to this poller (using CreatePolledRpc()) will be stored in the queue and must be collected by calling PollRpc(). The returned handle must be destroyed with DestroyRpcCallPoller().

Parameters
instinstance handle
Returns
poller handle
void nt::DestroyRpcCallPoller ( NT_RpcCallPoller  poller)

Destroy a RPC call poller.

This will abort any blocked polling call and prevent additional events from being generated for this poller.

Parameters
pollerpoller handle
bool nt::GetRpcResult ( NT_Entry  entry,
NT_RpcCall  call,
std::string *  result 
)

Get the result (return value) of a RPC call.

This function blocks until the result is received.

Parameters
entryentry handle of RPC entry
callRPC call handle returned by CallRpc()
resultreceived result (output)
Returns
False on error, true otherwise.
bool nt::GetRpcResult ( NT_Entry  entry,
NT_RpcCall  call,
std::string *  result,
double  timeout,
bool *  timed_out 
)

Get the result (return value) of a RPC call.

This function blocks until the result is received or it times out.

Parameters
entryentry handle of RPC entry
callRPC call handle returned by CallRpc()
resultreceived result (output)
timeouttimeout, in seconds
timed_outtrue if the timeout period elapsed (output)
Returns
False on error or timeout, true otherwise.
std::string nt::PackRpcDefinition ( const RpcDefinition &  def)

Pack a RPC version 1 definition.

Parameters
defRPC version 1 definition
Returns
Raw packed bytes.
std::string nt::PackRpcValues ( ArrayRef< std::shared_ptr< Value >>  values)

Pack RPC values as required for RPC version 1 definition messages.

Parameters
valuesarray of values to pack
Returns
Raw packed bytes.
std::vector<RpcAnswer> nt::PollRpc ( NT_RpcCallPoller  poller)

Get the next incoming RPC call.

This blocks until the next incoming RPC call is received. This is intended to be used with CreatePolledRpc(); RPC calls created using CreateRpc() will not be serviced through this function. Upon successful return, PostRpcResponse() must be called to send the return value to the caller.

Parameters
pollerpoller handle
Returns
Information on the next RPC calls. Only returns empty if an error occurred (e.g. the instance was invalid or is shutting down).
std::vector<RpcAnswer> nt::PollRpc ( NT_RpcCallPoller  poller,
double  timeout,
bool *  timed_out 
)

Get the next incoming RPC call.

This blocks until the next incoming RPC call is received or it times out. This is intended to be used with CreatePolledRpc(); RPC calls created using CreateRpc() will not be serviced through this function. Upon successful return, PostRpcResponse() must be called to send the return value to the caller.

Parameters
pollerpoller handle
timeouttimeout, in seconds
timed_outtrue if the timeout period elapsed (output)
Returns
Information on the next RPC calls. If empty and timed_out is also false, an error occurred (e.g. the instance was invalid or is shutting down).
bool nt::PostRpcResponse ( NT_Entry  entry,
NT_RpcCall  call,
StringRef  result 
)

Post RPC response (return value) for a polled RPC.

The rpc and call parameters should come from the RpcAnswer returned by PollRpc().

Parameters
entryentry handle of RPC entry (from RpcAnswer)
callRPC call handle (from RpcAnswer)
resultresult raw data that will be provided to remote caller
Returns
true if the response was posted, otherwise false
bool nt::UnpackRpcDefinition ( StringRef  packed,
RpcDefinition *  def 
)

Unpack a RPC version 1 definition.

This can be used for introspection or validation.

Parameters
packedraw packed bytes
defRPC version 1 definition (output)
Returns
True if successfully unpacked, false otherwise.
std::vector<std::shared_ptr<Value> > nt::UnpackRpcValues ( StringRef  packed,
ArrayRef< NT_Type types 
)

Unpack RPC values as required for RPC version 1 definition messages.

Parameters
packedraw packed bytes
typesarray of data types (as provided in the RPC definition)
Returns
Array of values.
bool nt::WaitForRpcCallQueue ( NT_Inst  inst,
double  timeout 
)

Wait for the incoming RPC call queue to be empty.

This is primarily useful for deterministic testing. This blocks until either the RPC call queue is empty (e.g. there are no more events that need to be passed along to callbacks or poll queues) or the timeout expires.

Parameters
instinstance handle
timeouttimeout, in seconds. Set to 0 for non-blocking behavior, or a negative value to block indefinitely
Returns
False if timed out, otherwise true.