/* */ #ifndef D_UT_METADATA_REQUEST_TRACKER_H #define D_UT_METADATA_REQUEST_TRACKER_H #include "common.h" #include #include "TimerA2.h" #include "wallclock.h" namespace aria2 { class UTMetadataRequestTracker { public: // Made public so that unnamed functor can access this struct RequestEntry { size_t index_; Timer dispatchedTime_; RequestEntry(size_t index) : index_(index) {} bool elapsed(const std::chrono::seconds t) const { return dispatchedTime_.difference(global::wallclock()) >= t; } bool operator==(const RequestEntry& e) const { return index_ == e.index_; } }; private: std::vector trackedRequests_; public: UTMetadataRequestTracker(); // Add request index to tracking list. void add(size_t index); // Returns true if request index is tracked. bool tracks(size_t index); // Remove index from tracking list. void remove(size_t index); // Returns all tracking indexes. std::vector getAllTrackedIndex() const; // Removes request index which is timed out and returns their indexes. std::vector removeTimeoutEntry(); // Returns the number of tracking list. size_t count() const { return trackedRequests_.size(); } // Returns the number of additional index this tracker can track. size_t avail() const; }; } // namespace aria2 #endif // D_UT_METADATA_REQUEST_TRACKER_H