diff --git a/src/simplified/xf/core/behavior.cpp b/src/simplified/xf/core/behavior.cpp index 06129ad..76e5605 100644 --- a/src/simplified/xf/core/behavior.cpp +++ b/src/simplified/xf/core/behavior.cpp @@ -42,9 +42,11 @@ const XFTimeout *XFBehavior::getCurrentTimeout() { } void XFBehavior::setCurrentEvent(const XFEvent *pEvent) { - + pCurrentEvent_ = pEvent; } XFBehavior::TerminateBehavior XFBehavior::process(const XFEvent *pEvent) { - + setCurrentEvent(pEvent); + processEvent(); + return deleteOnTerminate_; } diff --git a/src/simplified/xf/port/common/dispatcher.cpp b/src/simplified/xf/port/common/dispatcher.cpp index 9d27e6e..5d9dfb7 100644 --- a/src/simplified/xf/port/common/dispatcher.cpp +++ b/src/simplified/xf/port/common/dispatcher.cpp @@ -35,7 +35,7 @@ XFDispatcher::~XFDispatcher() { } void XFDispatcher::dispatchEvent(const XFEvent *pEvent) const { - + pEvent->getBehavior()->startBehavior(); } void XFDispatcher::pushEvent(XFEvent *pEvent) { @@ -43,13 +43,11 @@ void XFDispatcher::pushEvent(XFEvent *pEvent) { } void XFDispatcher::scheduleTimeout(int timeoutId, int interval, interface::XFBehavior *pBehavior) { - XFTimeoutManager* timeoutManager = XFTimeoutManager::getInstance(); - timeoutManager->scheduleTimeout(timeoutId, interval, pBehavior); + XFTimeoutManager::getInstance()->scheduleTimeout(timeoutId, interval, pBehavior); } void XFDispatcher::unscheduleTimeout(int timeoutId, interface::XFBehavior *pBehavior) { - XFTimeoutManager* timeoutManager = XFTimeoutManager::getInstance(); - timeoutManager->unscheduleTimeout(timeoutId, pBehavior); + XFTimeoutManager::getInstance()->unscheduleTimeout(timeoutId, pBehavior); } void XFDispatcher::executeOnce() { diff --git a/src/simplified/xf/port/common/timeoutmanager.cpp b/src/simplified/xf/port/common/timeoutmanager.cpp index 569bbef..ace0dea 100644 --- a/src/simplified/xf/port/common/timeoutmanager.cpp +++ b/src/simplified/xf/port/common/timeoutmanager.cpp @@ -1,4 +1,5 @@ +#include "common/dispatcher.h" #include #if (USE_XF_COMMON_TIMEOUTMANAGER_CLASS != 0) @@ -20,21 +21,27 @@ interface::XFTimeoutManager * interface::XFTimeoutManager::getInstance() { return &timeoutManager; } -// TODO: Implement code for XFTimeoutManager class +// TODO done: Implement code for XFTimeoutManager class XFTimeoutManager::XFTimeoutManager() { } +XFTimeoutManager::~XFTimeoutManager() { + +} + void XFTimeoutManager::addTimeout(XFTimeout *pNewTimeout) { + pMutex_->lock(); timeouts_.push_front(pNewTimeout); + pMutex_->unlock(); + } void XFTimeoutManager::returnTimeout(XFTimeout *pTimeout) { + pMutex_->lock(); + XFDispatcher::getInstance()->pushEvent(pTimeout); timeouts_.remove(pTimeout); -} - -XFTimeoutManager::~XFTimeoutManager() { - + pMutex_->unlock(); } void XFTimeoutManager::start(std::function startTimeoutManagerTimer) {