ServiceClient<>::getCallIDByIndex()

This commit is contained in:
Pavel Kirienko
2015-05-24 15:59:32 +03:00
parent 4f64e2378e
commit 8729d6a2d6
2 changed files with 19 additions and 0 deletions
@@ -341,6 +341,12 @@ public:
*/
bool hasPendingCallToServer(NodeID server_node_id) 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).
*/
ServiceCallID getCallIDByIndex(unsigned index) const;
/**
* Service response callback must be set prior service call.
*/
@@ -556,6 +562,13 @@ bool ServiceClient<DataType_, Callback_, NumStaticCalls_>::hasPendingCallToServe
return NULL != call_registry_.find(ServerSearchPredicate(server_node_id));
}
template <typename DataType_, typename Callback_, unsigned NumStaticCalls_>
ServiceCallID ServiceClient<DataType_, Callback_, NumStaticCalls_>::getCallIDByIndex(unsigned index) const
{
const CallState* const id = call_registry_.getByIndex(index);
return (id == NULL) ? ServiceCallID() : id->getCallID();
}
}
#endif // UAVCAN_NODE_SERVICE_CLIENT_HPP_INCLUDED
+6
View File
@@ -147,6 +147,9 @@ TEST(ServiceClient, Basic)
ASSERT_EQ(1, client2.getNumPendingCalls());
ASSERT_EQ(2, client3.getNumPendingCalls());
ASSERT_EQ(uavcan::NodeID(1), client2.getCallIDByIndex(0).server_node_id);
ASSERT_EQ(uavcan::NodeID(), client2.getCallIDByIndex(1).server_node_id);
nodes.spinBoth(uavcan::MonotonicDuration::fromMSec(20));
std::cout << "!!! Spin finished!" << std::endl;
@@ -216,6 +219,9 @@ TEST(ServiceClient, Rejection)
ASSERT_LT(0, client1.call(1, request));
ASSERT_EQ(uavcan::NodeID(1), client1.getCallIDByIndex(0).server_node_id);
ASSERT_EQ(uavcan::NodeID(), client1.getCallIDByIndex(1).server_node_id);
ASSERT_EQ(1, nodes.b.getDispatcher().getNumServiceResponseListeners());
ASSERT_TRUE(client1.hasPendingCalls());
ASSERT_TRUE(client1.hasPendingCallToServer(1));