Classes | Public Types | Public Member Functions | Private Types | Private Member Functions | Private Attributes | List of all members
uavcan::ServiceClient< DataType_, Callback_ > Class Template Reference

#include <service_client.hpp>

Inheritance diagram for uavcan::ServiceClient< DataType_, Callback_ >:
Inheritance graph
[legend]

Classes

struct  TimeoutCallbackCaller
 

Public Types

typedef Callback_ Callback
 
typedef DataType_ DataType
 
typedef DataType::Request RequestType
 
typedef DataType::Response ResponseType
 
typedef ServiceCallResult< DataTypeServiceCallResultType
 

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 CallbackgetCallback () 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 ()
 
- Public Member Functions inherited from uavcan::GenericSubscriberBase
uint32_t getFailureCount () const
 
INodegetNode () const
 

Private Types

typedef Multiset< CallStateCallRegistry
 
typedef GenericPublisher< DataType, RequestTypePublisherType
 
typedef ServiceClient< DataType, CallbackSelfType
 
typedef GenericSubscriber< DataType, ResponseType, TransferListenerWithFilterSubscriberType
 

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_
 

Additional Inherited Members

- Static Public Member Functions inherited from uavcan::ServiceClientBase
static MonotonicDuration getDefaultRequestTimeout ()
 
static MonotonicDuration getMaxRequestTimeout ()
 
static MonotonicDuration getMinRequestTimeout ()
 
- Protected Member Functions inherited from uavcan::GenericSubscriber< DataType_, DataType_::Response, TransferListenerWithFilter >
void allowAnonymousTransfers ()
 
 GenericSubscriber (INode &node)
 
TransferListenerWithFiltergetTransferListener ()
 
virtual void handleReceivedDataStruct (ReceivedDataStructure< DataType_::Response > &)=0
 
int startAsMessageListener ()
 
int startAsServiceRequestListener ()
 
int startAsServiceResponseListener ()
 
void stop ()
 
virtual ~GenericSubscriber ()
 
- Protected Member Functions inherited from uavcan::GenericSubscriberBase
int genericStart (TransferListener *listener, bool(Dispatcher::*registration_method)(TransferListener *))
 
 GenericSubscriberBase (INode &node)
 
void stop (TransferListener *listener)
 
 ~GenericSubscriberBase ()
 
- Protected Member Functions inherited from uavcan::ServiceClientBase
int prepareToCall (INode &node, const char *dtname, NodeID server_node_id, ServiceCallID &out_call_id)
 
 ServiceClientBase (INode &node)
 
virtual ~ServiceClientBase ()
 
- Protected Member Functions inherited from uavcan::ITransferAcceptanceFilter
virtual ~ITransferAcceptanceFilter ()
 
- Protected Member Functions inherited from uavcan::DeadlineHandler
 DeadlineHandler (Scheduler &scheduler)
 
virtual ~DeadlineHandler ()
 
void generateDeadlineImmediately ()
 
MonotonicTime getDeadline () const
 
SchedulergetScheduler () const
 
bool isRunning () const
 
void startWithDeadline (MonotonicTime deadline)
 
void startWithDelay (MonotonicDuration delay)
 
void stop ()
 
- Protected Member Functions inherited from uavcan::LinkedListNode< DeadlineHandler >
 LinkedListNode ()
 
 ~LinkedListNode ()
 
DeadlineHandlergetNextListNode () const
 
void setNextListNode (DeadlineHandler *node)
 
- Protected Attributes inherited from uavcan::GenericSubscriberBase
uint32_t failure_count_
 
INodenode_
 
- Protected Attributes inherited from uavcan::ServiceClientBase
MonotonicDuration request_timeout_
 
- Protected Attributes inherited from uavcan::DeadlineHandler
Schedulerscheduler_
 

Detailed Description

template<typename DataType_, typename Callback_ = std::function<void (const ServiceCallResult<DataType_>&)>>
class uavcan::ServiceClient< DataType_, Callback_ >

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.

Template Parameters
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.

Member Typedef Documentation

◆ Callback

template<typename DataType_ , typename Callback_ = std::function<void (const ServiceCallResult<DataType_>&)>>
typedef Callback_ uavcan::ServiceClient< DataType_, Callback_ >::Callback

Definition at line 227 of file service_client.hpp.

◆ CallRegistry

template<typename DataType_ , typename Callback_ = std::function<void (const ServiceCallResult<DataType_>&)>>
typedef Multiset<CallState> uavcan::ServiceClient< DataType_, Callback_ >::CallRegistry
private

Definition at line 234 of file service_client.hpp.

◆ DataType

template<typename DataType_ , typename Callback_ = std::function<void (const ServiceCallResult<DataType_>&)>>
typedef DataType_ uavcan::ServiceClient< DataType_, Callback_ >::DataType

Definition at line 223 of file service_client.hpp.

◆ PublisherType

template<typename DataType_ , typename Callback_ = std::function<void (const ServiceCallResult<DataType_>&)>>
typedef GenericPublisher<DataType, RequestType> uavcan::ServiceClient< DataType_, Callback_ >::PublisherType
private

Definition at line 231 of file service_client.hpp.

◆ RequestType

template<typename DataType_ , typename Callback_ = std::function<void (const ServiceCallResult<DataType_>&)>>
typedef DataType::Request uavcan::ServiceClient< DataType_, Callback_ >::RequestType

Definition at line 224 of file service_client.hpp.

◆ ResponseType

template<typename DataType_ , typename Callback_ = std::function<void (const ServiceCallResult<DataType_>&)>>
typedef DataType::Response uavcan::ServiceClient< DataType_, Callback_ >::ResponseType

Definition at line 225 of file service_client.hpp.

◆ SelfType

template<typename DataType_ , typename Callback_ = std::function<void (const ServiceCallResult<DataType_>&)>>
typedef ServiceClient<DataType, Callback> uavcan::ServiceClient< DataType_, Callback_ >::SelfType
private

Definition at line 230 of file service_client.hpp.

◆ ServiceCallResultType

template<typename DataType_ , typename Callback_ = std::function<void (const ServiceCallResult<DataType_>&)>>
typedef ServiceCallResult<DataType> uavcan::ServiceClient< DataType_, Callback_ >::ServiceCallResultType

Definition at line 226 of file service_client.hpp.

◆ SubscriberType

template<typename DataType_ , typename Callback_ = std::function<void (const ServiceCallResult<DataType_>&)>>
typedef GenericSubscriber<DataType, ResponseType, TransferListenerWithFilter> uavcan::ServiceClient< DataType_, Callback_ >::SubscriberType
private

Definition at line 232 of file service_client.hpp.

Constructor & Destructor Documentation

◆ ServiceClient()

template<typename DataType_ , typename Callback_ = std::function<void (const ServiceCallResult<DataType_>&)>>
uavcan::ServiceClient< DataType_, Callback_ >::ServiceClient ( INode node,
const Callback callback = Callback() 
)
inlineexplicit
Parameters
nodeNode instance this client will be registered with.
callbackCallback instance. Optional, can be assigned later.

Definition at line 280 of file service_client.hpp.

◆ ~ServiceClient()

template<typename DataType_ , typename Callback_ = std::function<void (const ServiceCallResult<DataType_>&)>>
virtual uavcan::ServiceClient< DataType_, Callback_ >::~ServiceClient ( )
inlinevirtual

Definition at line 294 of file service_client.hpp.

Member Function Documentation

◆ addCallState()

template<typename DataType_ , typename Callback_ >
int uavcan::ServiceClient< DataType_, Callback_ >::addCallState ( ServiceCallID  call_id)
private

Definition at line 465 of file service_client.hpp.

◆ call() [1/2]

template<typename DataType_ , typename Callback_ >
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.

◆ call() [2/2]

template<typename DataType_ , typename Callback_ >
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.

◆ cancelAllCalls()

template<typename DataType_ , typename Callback_ >
void uavcan::ServiceClient< DataType_, Callback_ >::cancelAllCalls

Cancels all pending calls.

Definition at line 564 of file service_client.hpp.

◆ cancelCall()

template<typename DataType_ , typename Callback_ >
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.

◆ getCallback()

template<typename DataType_ , typename Callback_ = std::function<void (const ServiceCallResult<DataType_>&)>>
const Callback& uavcan::ServiceClient< DataType_, Callback_ >::getCallback ( ) const
inline

Service response callback must be set prior service call.

Definition at line 357 of file service_client.hpp.

◆ getCallIDByIndex()

template<typename DataType_ , typename Callback_ >
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.

◆ getNumPendingCalls()

template<typename DataType_ , typename Callback_ = std::function<void (const ServiceCallResult<DataType_>&)>>
unsigned uavcan::ServiceClient< DataType_, Callback_ >::getNumPendingCalls ( ) const
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.

◆ getPriority()

template<typename DataType_ , typename Callback_ = std::function<void (const ServiceCallResult<DataType_>&)>>
TransferPriority uavcan::ServiceClient< DataType_, Callback_ >::getPriority ( ) const
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.

◆ getRequestTimeout()

template<typename DataType_ , typename Callback_ = std::function<void (const ServiceCallResult<DataType_>&)>>
MonotonicDuration uavcan::ServiceClient< DataType_, Callback_ >::getRequestTimeout ( ) const
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.

◆ getResponseFailureCount()

template<typename DataType_ , typename Callback_ = std::function<void (const ServiceCallResult<DataType_>&)>>
uint32_t uavcan::ServiceClient< DataType_, Callback_ >::getResponseFailureCount ( ) const
inline

Returns the number of failed attempts to decode received response. Generally, a failed attempt means either:

  • Transient failure in the transport layer.
  • Incompatible data types.

Definition at line 377 of file service_client.hpp.

◆ handleDeadline()

template<typename DataType_ , typename Callback_ >
void uavcan::ServiceClient< DataType_, Callback_ >::handleDeadline ( MonotonicTime  )
privatevirtual

Implements uavcan::DeadlineHandler.

Definition at line 441 of file service_client.hpp.

◆ handleReceivedDataStruct()

template<typename DataType_ , typename Callback_ >
void uavcan::ServiceClient< DataType_, Callback_ >::handleReceivedDataStruct ( ReceivedDataStructure< ResponseType > &  response)
privatevirtual

Definition at line 429 of file service_client.hpp.

◆ hasPendingCalls()

template<typename DataType_ , typename Callback_ = std::function<void (const ServiceCallResult<DataType_>&)>>
bool uavcan::ServiceClient< DataType_, Callback_ >::hasPendingCalls ( ) const
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.

◆ hasPendingCallToServer()

template<typename DataType_ , typename Callback_ >
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.

◆ init() [1/2]

template<typename DataType_ , typename Callback_ = std::function<void (const ServiceCallResult<DataType_>&)>>
int uavcan::ServiceClient< DataType_, Callback_ >::init ( )
inline

Shall be called before first use. Returns negative error code.

Definition at line 300 of file service_client.hpp.

◆ init() [2/2]

template<typename DataType_ , typename Callback_ = std::function<void (const ServiceCallResult<DataType_>&)>>
int uavcan::ServiceClient< DataType_, Callback_ >::init ( TransferPriority  priority)
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.

◆ invokeCallback()

template<typename DataType_ , typename Callback_ >
void uavcan::ServiceClient< DataType_, Callback_ >::invokeCallback ( ServiceCallResultType result)
private

Definition at line 406 of file service_client.hpp.

◆ setCallback()

template<typename DataType_ , typename Callback_ = std::function<void (const ServiceCallResult<DataType_>&)>>
void uavcan::ServiceClient< DataType_, Callback_ >::setCallback ( const Callback cb)
inline

Definition at line 358 of file service_client.hpp.

◆ setPriority()

template<typename DataType_ , typename Callback_ = std::function<void (const ServiceCallResult<DataType_>&)>>
void uavcan::ServiceClient< DataType_, Callback_ >::setPriority ( const TransferPriority  prio)
inline

Definition at line 400 of file service_client.hpp.

◆ setRequestTimeout()

template<typename DataType_ , typename Callback_ = std::function<void (const ServiceCallResult<DataType_>&)>>
void uavcan::ServiceClient< DataType_, Callback_ >::setRequestTimeout ( MonotonicDuration  timeout)
inline

Definition at line 385 of file service_client.hpp.

◆ shouldAcceptFrame()

template<typename DataType_ , typename Callback_ >
bool uavcan::ServiceClient< DataType_, Callback_ >::shouldAcceptFrame ( const RxFrame frame) const
privatevirtual

If it returns false, the frame will be ignored, otherwise accepted.

Implements uavcan::ITransferAcceptanceFilter.

Definition at line 419 of file service_client.hpp.

Member Data Documentation

◆ call_registry_

template<typename DataType_ , typename Callback_ = std::function<void (const ServiceCallResult<DataType_>&)>>
CallRegistry uavcan::ServiceClient< DataType_, Callback_ >::call_registry_
private

Definition at line 260 of file service_client.hpp.

◆ callback_

template<typename DataType_ , typename Callback_ = std::function<void (const ServiceCallResult<DataType_>&)>>
Callback uavcan::ServiceClient< DataType_, Callback_ >::callback_
private

Definition at line 263 of file service_client.hpp.

◆ publisher_

template<typename DataType_ , typename Callback_ = std::function<void (const ServiceCallResult<DataType_>&)>>
PublisherType uavcan::ServiceClient< DataType_, Callback_ >::publisher_
private

Definition at line 262 of file service_client.hpp.


The documentation for this class was generated from the following file:


uavcan_communicator
Author(s):
autogenerated on Fri Dec 13 2024 03:10:05