2023-09-19 15:59:49 +02:00
|
|
|
|
|
|
|
#include <config/xf-config.h>
|
|
|
|
|
|
|
|
#if (USE_XF_COMMON_TIMEOUTMANAGER_CLASS != 0)
|
|
|
|
|
|
|
|
#include <cassert>
|
|
|
|
#include "xf/interface/behavior.h"
|
|
|
|
#include "xf/interface/mutex.h"
|
|
|
|
#include "timeoutmanager.h"
|
|
|
|
|
|
|
|
using Mutex = interface::XFMutex; // Rename XFMutex interface class to Mutex for easier use.
|
|
|
|
|
|
|
|
// Implementation of the getInstance() method of the 'interface::XFTimeoutManager' class.
|
|
|
|
//
|
|
|
|
// 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.
|
2023-09-26 14:26:07 +02:00
|
|
|
interface::XFTimeoutManager * interface::XFTimeoutManager::getInstance() {
|
2023-09-19 15:59:49 +02:00
|
|
|
static ::XFTimeoutManager timeoutManager;
|
|
|
|
return &timeoutManager;
|
|
|
|
}
|
|
|
|
|
|
|
|
// TODO: Implement code for XFTimeoutManager class
|
|
|
|
|
2023-09-26 14:26:07 +02:00
|
|
|
XFTimeoutManager::XFTimeoutManager() {
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
XFTimeoutManager::~XFTimeoutManager() {
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
void XFTimeoutManager::start(std::function<void (uint32_t)> 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);
|
|
|
|
}
|
|
|
|
|
2023-09-19 15:59:49 +02:00
|
|
|
#endif // USE_XF_COMMON_TIMEOUTMANAGER_CLASS
|