probably full of mistake

This commit is contained in:
Rémi Heredero 2023-10-05 11:50:03 +02:00
parent 3ef80d2187
commit 820aff5af4
3 changed files with 19 additions and 12 deletions

View File

@ -42,9 +42,11 @@ const XFTimeout *XFBehavior::getCurrentTimeout() {
} }
void XFBehavior::setCurrentEvent(const XFEvent *pEvent) { void XFBehavior::setCurrentEvent(const XFEvent *pEvent) {
pCurrentEvent_ = pEvent;
} }
XFBehavior::TerminateBehavior XFBehavior::process(const XFEvent *pEvent) { XFBehavior::TerminateBehavior XFBehavior::process(const XFEvent *pEvent) {
setCurrentEvent(pEvent);
processEvent();
return deleteOnTerminate_;
} }

View File

@ -35,7 +35,7 @@ XFDispatcher::~XFDispatcher() {
} }
void XFDispatcher::dispatchEvent(const XFEvent *pEvent) const { void XFDispatcher::dispatchEvent(const XFEvent *pEvent) const {
pEvent->getBehavior()->startBehavior();
} }
void XFDispatcher::pushEvent(XFEvent *pEvent) { void XFDispatcher::pushEvent(XFEvent *pEvent) {
@ -43,13 +43,11 @@ void XFDispatcher::pushEvent(XFEvent *pEvent) {
} }
void XFDispatcher::scheduleTimeout(int timeoutId, int interval, interface::XFBehavior *pBehavior) { void XFDispatcher::scheduleTimeout(int timeoutId, int interval, interface::XFBehavior *pBehavior) {
XFTimeoutManager* timeoutManager = XFTimeoutManager::getInstance(); XFTimeoutManager::getInstance()->scheduleTimeout(timeoutId, interval, pBehavior);
timeoutManager->scheduleTimeout(timeoutId, interval, pBehavior);
} }
void XFDispatcher::unscheduleTimeout(int timeoutId, interface::XFBehavior *pBehavior) { void XFDispatcher::unscheduleTimeout(int timeoutId, interface::XFBehavior *pBehavior) {
XFTimeoutManager* timeoutManager = XFTimeoutManager::getInstance(); XFTimeoutManager::getInstance()->unscheduleTimeout(timeoutId, pBehavior);
timeoutManager->unscheduleTimeout(timeoutId, pBehavior);
} }
void XFDispatcher::executeOnce() { void XFDispatcher::executeOnce() {

View File

@ -1,4 +1,5 @@
#include "common/dispatcher.h"
#include <config/xf-config.h> #include <config/xf-config.h>
#if (USE_XF_COMMON_TIMEOUTMANAGER_CLASS != 0) #if (USE_XF_COMMON_TIMEOUTMANAGER_CLASS != 0)
@ -20,21 +21,27 @@ interface::XFTimeoutManager * interface::XFTimeoutManager::getInstance() {
return &timeoutManager; return &timeoutManager;
} }
// TODO: Implement code for XFTimeoutManager class // TODO done: Implement code for XFTimeoutManager class
XFTimeoutManager::XFTimeoutManager() { XFTimeoutManager::XFTimeoutManager() {
} }
XFTimeoutManager::~XFTimeoutManager() {
}
void XFTimeoutManager::addTimeout(XFTimeout *pNewTimeout) { void XFTimeoutManager::addTimeout(XFTimeout *pNewTimeout) {
pMutex_->lock();
timeouts_.push_front(pNewTimeout); timeouts_.push_front(pNewTimeout);
pMutex_->unlock();
} }
void XFTimeoutManager::returnTimeout(XFTimeout *pTimeout) { void XFTimeoutManager::returnTimeout(XFTimeout *pTimeout) {
pMutex_->lock();
XFDispatcher::getInstance()->pushEvent(pTimeout);
timeouts_.remove(pTimeout); timeouts_.remove(pTimeout);
} pMutex_->unlock();
XFTimeoutManager::~XFTimeoutManager() {
} }
void XFTimeoutManager::start(std::function<void (uint32_t)> startTimeoutManagerTimer) { void XFTimeoutManager::start(std::function<void (uint32_t)> startTimeoutManagerTimer) {