From 2123853cae81aaeb58745344266910093b6d943c Mon Sep 17 00:00:00 2001 From: Pavel Kirienko Date: Sun, 17 May 2015 00:01:49 +0300 Subject: [PATCH] Using concurrent calls in NodeInfoRetriever --- .../uavcan/protocol/node_info_retriever.hpp | 26 +++++++++++++++---- 1 file changed, 21 insertions(+), 5 deletions(-) diff --git a/libuavcan/include/uavcan/protocol/node_info_retriever.hpp b/libuavcan/include/uavcan/protocol/node_info_retriever.hpp index 1d9d16322d..ceffa9bf28 100644 --- a/libuavcan/include/uavcan/protocol/node_info_retriever.hpp +++ b/libuavcan/include/uavcan/protocol/node_info_retriever.hpp @@ -69,7 +69,6 @@ class UAVCAN_EXPORT NodeInfoRetriever : NodeStatusMonitor { public: enum { MaxNumRequestAttempts = 254 }; - enum { DefaultNumRequestAttempts = 30 }; enum { UnlimitedRequestAttempts = 0 }; private: @@ -136,6 +135,9 @@ private: } }; + enum { NumStaticCalls = 4 }; + enum { DefaultNumRequestAttempts = 30 }; + /* * State */ @@ -143,11 +145,12 @@ private: Multiset listeners_; - ServiceClient get_node_info_client_; + ServiceClient get_node_info_client_; mutable uint8_t last_picked_node_; uint8_t num_attempts_; + uint8_t max_concurrent_requests_; /* * Methods @@ -185,7 +188,9 @@ private: (last_picked_node_ <= NodeID::Max)); const Entry& entry = getEntry(last_picked_node_); - if (entry.request_needed && entry.updated_since_last_attempt) + if (entry.request_needed && + entry.updated_since_last_attempt && + !get_node_info_client_.hasPendingCallToServer(last_picked_node_)) { UAVCAN_TRACE("NodeInfoRetriever", "Next node to query: %d", int(last_picked_node_)); return NodeID(last_picked_node_); @@ -196,9 +201,9 @@ private: virtual void handleTimerEvent(const TimerEvent&) { - if (get_node_info_client_.hasPendingCalls()) // If request is pending, this condition will fail every second time + if (get_node_info_client_.getNumPendingCalls() >= max_concurrent_requests_) { - return; // TODO FIXME Concurrent calls!! + return; } const NodeID next = pickNextNodeToQuery(); @@ -313,6 +318,7 @@ public: , get_node_info_client_(node) , last_picked_node_(1) , num_attempts_(DefaultNumRequestAttempts) + , max_concurrent_requests_(NumStaticCalls * 2) { } /** @@ -382,6 +388,16 @@ public: { num_attempts_ = min(static_cast(MaxNumRequestAttempts), num); } + + /** + * Number of concurrent requests limits the number of simultaneous service calls to different nodes. + * This value cannot be less than one. + */ + uint8_t getNumConcurrentRequests() const { return max_concurrent_requests_; } + void setNumConcurrentRequests(uint8_t num) + { + max_concurrent_requests_ = max(static_cast(1), num); + } }; }