#include <service_client.hpp>
Classes | |
struct | TimeoutCallbackCaller |
Public Types | |
typedef Callback_ | Callback |
typedef DataType_ | DataType |
typedef DataType::Request | RequestType |
typedef DataType::Response | ResponseType |
typedef ServiceCallResult< DataType > | ServiceCallResultType |
Public Member Functions | |
int | call (NodeID server_node_id, const RequestType &request) |
int | call (NodeID server_node_id, const RequestType &request, ServiceCallID &out_call_id) |
void | cancelAllCalls () |
void | cancelCall (ServiceCallID call_id) |
const Callback & | getCallback () const |
ServiceCallID | getCallIDByIndex (unsigned index) const |
unsigned | getNumPendingCalls () const |
TransferPriority | getPriority () const |
MonotonicDuration | getRequestTimeout () const |
uint32_t | getResponseFailureCount () const |
bool | hasPendingCalls () const |
bool | hasPendingCallToServer (NodeID server_node_id) const |
int | init () |
int | init (TransferPriority priority) |
ServiceClient (INode &node, const Callback &callback=Callback()) | |
void | setCallback (const Callback &cb) |
void | setPriority (const TransferPriority prio) |
void | setRequestTimeout (MonotonicDuration timeout) |
virtual | ~ServiceClient () |
![]() | |
uint32_t | getFailureCount () const |
INode & | getNode () const |
Private Types | |
typedef Multiset< CallState > | CallRegistry |
typedef GenericPublisher< DataType, RequestType > | PublisherType |
typedef ServiceClient< DataType, Callback > | SelfType |
typedef GenericSubscriber< DataType, ResponseType, TransferListenerWithFilter > | SubscriberType |
Private Member Functions | |
int | addCallState (ServiceCallID call_id) |
virtual void | handleDeadline (MonotonicTime) |
virtual void | handleReceivedDataStruct (ReceivedDataStructure< ResponseType > &response) |
void | invokeCallback (ServiceCallResultType &result) |
virtual bool | shouldAcceptFrame (const RxFrame &frame) const |
Private Attributes | |
CallRegistry | call_registry_ |
Callback | callback_ |
PublisherType | publisher_ |
Use this class to invoke services on remote nodes.
This class can manage multiple concurrent calls to the same or different remote servers. Number of concurrent calls is limited only by amount of available pool memory.
Note that the reference passed to the callback points to a stack-allocated object, which means that the reference invalidates once the callback returns. If you want to use this object after the callback execution, you need to copy it somewhere.
Note that by default, service client objects use lower priority than message publishers. Use setPriority() to override the default if necessary.
DataType_ | Service data type. |
Callback_ | Service response will be delivered through the callback of this type. In C++11 mode this type defaults to std::function<>. In C++03 mode this type defaults to a plain function pointer; use binder to call member functions as callbacks. |
Definition at line 217 of file service_client.hpp.
typedef Callback_ uavcan::ServiceClient< DataType_, Callback_ >::Callback |
Definition at line 227 of file service_client.hpp.
|
private |
Definition at line 234 of file service_client.hpp.
typedef DataType_ uavcan::ServiceClient< DataType_, Callback_ >::DataType |
Definition at line 223 of file service_client.hpp.
|
private |
Definition at line 231 of file service_client.hpp.
typedef DataType::Request uavcan::ServiceClient< DataType_, Callback_ >::RequestType |
Definition at line 224 of file service_client.hpp.
typedef DataType::Response uavcan::ServiceClient< DataType_, Callback_ >::ResponseType |
Definition at line 225 of file service_client.hpp.
|
private |
Definition at line 230 of file service_client.hpp.
typedef ServiceCallResult<DataType> uavcan::ServiceClient< DataType_, Callback_ >::ServiceCallResultType |
Definition at line 226 of file service_client.hpp.
|
private |
Definition at line 232 of file service_client.hpp.
|
inlineexplicit |
node | Node instance this client will be registered with. |
callback | Callback instance. Optional, can be assigned later. |
Definition at line 280 of file service_client.hpp.
|
inlinevirtual |
Definition at line 294 of file service_client.hpp.
|
private |
Definition at line 465 of file service_client.hpp.
int uavcan::ServiceClient< DataType_, Callback_ >::call | ( | NodeID | server_node_id, |
const RequestType & | request | ||
) |
Performs non-blocking service call. This method transmits the service request and returns immediately.
Service response will be delivered into the application via the callback. Note that the callback will ALWAYS be called even if the service call times out; the actual result of the call (success/failure) will be passed to the callback as well.
Returns negative error code.
Definition at line 488 of file service_client.hpp.
int uavcan::ServiceClient< DataType_, Callback_ >::call | ( | NodeID | server_node_id, |
const RequestType & | request, | ||
ServiceCallID & | out_call_id | ||
) |
Same as plain call() above, but this overload also returns the call ID of the new call. The call ID structure can be used to cancel this request later if needed.
Definition at line 495 of file service_client.hpp.
void uavcan::ServiceClient< DataType_, Callback_ >::cancelAllCalls |
Cancels all pending calls.
Definition at line 564 of file service_client.hpp.
void uavcan::ServiceClient< DataType_, Callback_ >::cancelCall | ( | ServiceCallID | call_id | ) |
Cancels certain call referred via call ID structure.
Definition at line 554 of file service_client.hpp.
|
inline |
Service response callback must be set prior service call.
Definition at line 357 of file service_client.hpp.
ServiceCallID uavcan::ServiceClient< DataType_, Callback_ >::getCallIDByIndex | ( | unsigned | index | ) | const |
This method allows to traverse pending calls. If the index is out of range, an invalid call ID will be returned. Warning: average complexity is O(index); worst case complexity is O(size).
Definition at line 577 of file service_client.hpp.
|
inline |
Complexity is O(N) of number of pending calls. Note that the number of pending calls will not be updated until the callback is executed.
Definition at line 364 of file service_client.hpp.
|
inline |
Priority of outgoing request transfers. The remote server is supposed to use the same priority for the response, but it's not guaranteed by the specification.
Definition at line 399 of file service_client.hpp.
|
inline |
Request timeouts. Note that changing the request timeout will not affect calls that are already pending. There is no such config as TX timeout - TX timeouts are configured automagically according to request timeouts. Not recommended to change.
Definition at line 384 of file service_client.hpp.
|
inline |
Returns the number of failed attempts to decode received response. Generally, a failed attempt means either:
Definition at line 377 of file service_client.hpp.
|
privatevirtual |
Implements uavcan::DeadlineHandler.
Definition at line 441 of file service_client.hpp.
|
privatevirtual |
Definition at line 429 of file service_client.hpp.
|
inline |
Complexity is O(1). Note that the number of pending calls will not be updated until the callback is executed.
Definition at line 370 of file service_client.hpp.
bool uavcan::ServiceClient< DataType_, Callback_ >::hasPendingCallToServer | ( | NodeID | server_node_id | ) | const |
Checks whether there's currently a pending call addressed to the specified node ID.
Definition at line 571 of file service_client.hpp.
|
inline |
Shall be called before first use. Returns negative error code.
Definition at line 300 of file service_client.hpp.
|
inline |
Shall be called before first use. This overload allows to set the priority, otherwise it's the same. Returns negative error code.
Definition at line 310 of file service_client.hpp.
|
private |
Definition at line 406 of file service_client.hpp.
|
inline |
Definition at line 358 of file service_client.hpp.
|
inline |
Definition at line 400 of file service_client.hpp.
|
inline |
Definition at line 385 of file service_client.hpp.
|
privatevirtual |
If it returns false, the frame will be ignored, otherwise accepted.
Implements uavcan::ITransferAcceptanceFilter.
Definition at line 419 of file service_client.hpp.
|
private |
Definition at line 260 of file service_client.hpp.
|
private |
Definition at line 263 of file service_client.hpp.
|
private |
Definition at line 262 of file service_client.hpp.