ServiceClient<>::hasPendingCallToServer()

This commit is contained in:
Pavel Kirienko
2015-05-16 23:57:11 +03:00
parent 0553d18cf9
commit 5e5540b8ce
2 changed files with 27 additions and 0 deletions
@@ -165,6 +165,13 @@ protected:
bool operator()(const CallState& state) const { return (state.getCallID() == id) && !state.hasTimedOut(); }
};
struct ServerSearchPredicate
{
const NodeID server_node_id;
ServerSearchPredicate(NodeID nid) : server_node_id(nid) { }
bool operator()(const CallState& state) const { return state.getCallID().server_node_id == server_node_id; }
};
MonotonicDuration request_timeout_;
ServiceClientBase(INode& node)
@@ -329,6 +336,11 @@ public:
*/
void cancelAllCalls();
/**
* Checks whether there's currently a pending call addressed to the specified node ID.
*/
bool hasPendingCallToServer(NodeID server_node_id) const;
/**
* Service response callback must be set prior service call.
*/
@@ -538,6 +550,12 @@ void ServiceClient<DataType_, Callback_, NumStaticCalls_>::cancelAllCalls()
SubscriberType::stop();
}
template <typename DataType_, typename Callback_, unsigned NumStaticCalls_>
bool ServiceClient<DataType_, Callback_, NumStaticCalls_>::hasPendingCallToServer(NodeID server_node_id) const
{
return NULL != call_registry_.find(ServerSearchPredicate(server_node_id));
}
}
#endif // UAVCAN_NODE_SERVICE_CLIENT_HPP_INCLUDED