From 422f5d744884e851e1ccbb698dfd75c397bb0dcf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9mi=20Heredero?= Date: Tue, 26 Sep 2023 14:26:07 +0200 Subject: [PATCH] start to implement timeoutmanager --- .../xf/include/xf/interface/timeoutmanager.h | 3 +-- .../xf/port/common/timeoutmanager.cpp | 27 +++++++++++++++++-- 2 files changed, 26 insertions(+), 4 deletions(-) diff --git a/src/simplified/xf/include/xf/interface/timeoutmanager.h b/src/simplified/xf/include/xf/interface/timeoutmanager.h index 30a0da7..d964779 100644 --- a/src/simplified/xf/include/xf/interface/timeoutmanager.h +++ b/src/simplified/xf/include/xf/interface/timeoutmanager.h @@ -22,8 +22,7 @@ namespace interface { * - Implements the Singleton pattern * - Handle timeouts (hold, decrement, re-inject) */ -class XFTimeoutManager -{ +class XFTimeoutManager { public: virtual ~XFTimeoutManager() = default; diff --git a/src/simplified/xf/port/common/timeoutmanager.cpp b/src/simplified/xf/port/common/timeoutmanager.cpp index 0fcd487..827166e 100644 --- a/src/simplified/xf/port/common/timeoutmanager.cpp +++ b/src/simplified/xf/port/common/timeoutmanager.cpp @@ -15,12 +15,35 @@ using Mutex = interface::XFMutex; // Rename XFMutex interface class to Mut // Note: The implementation is done here because only in this file the real XFTimeoutManager // class is known (port specific class). An instance of the XFTimeoutManager class is // returned by the 'interface::XFTimeoutManager' class. -interface::XFTimeoutManager * interface::XFTimeoutManager::getInstance() -{ +interface::XFTimeoutManager * interface::XFTimeoutManager::getInstance() { static ::XFTimeoutManager timeoutManager; return &timeoutManager; } // TODO: Implement code for XFTimeoutManager class +XFTimeoutManager::XFTimeoutManager() { + +} + +XFTimeoutManager::~XFTimeoutManager() { + +} + +void XFTimeoutManager::start(std::function startTimeoutManagerTimer) { + startTimeoutManagerTimer(tickInterval_); +} + +void XFTimeoutManager::scheduleTimeout(int32_t timeoutId, int32_t interval, interface::XFBehavior *pBehavior) { + ::XFTimeout* timeout = new XFTimeout(timeoutId, interval, pBehavior); + timeouts_.push_front(timeout); +} + +int32_t timeoutIdComparison; +bool myPredicate(XFTimeout* timeout) {return (timeout->getId()==timeoutIdComparison);} +void XFTimeoutManager::unscheduleTimeout(int32_t timeoutId, interface::XFBehavior *pBehavior) { + timeoutIdComparison = timeoutId; + timeouts_.remove_if(myPredicate); +} + #endif // USE_XF_COMMON_TIMEOUTMANAGER_CLASS