From 79aab9999ff9256b71c86275b275ce2269ba1c29 Mon Sep 17 00:00:00 2001 From: Klagarge Date: Sun, 1 Oct 2023 17:52:37 +0200 Subject: [PATCH] some more code on this project ( i don't know what i do ) --- src/simplified/xf/core/behavior.cpp | 46 ++++++++++++++++++- src/simplified/xf/port/common/dispatcher.cpp | 38 ++++++++++++++- .../xf/port/common/timeoutmanager.cpp | 26 +++++++++-- 3 files changed, 102 insertions(+), 8 deletions(-) diff --git a/src/simplified/xf/core/behavior.cpp b/src/simplified/xf/core/behavior.cpp index 6904f8b..06129ad 100644 --- a/src/simplified/xf/core/behavior.cpp +++ b/src/simplified/xf/core/behavior.cpp @@ -3,4 +3,48 @@ #include "xf/initialevent.h" #include "xf/behavior.h" -// TODO: Implement code for XFBehavior class +// TODO: Implement code for XFBehavior class + +XFBehavior::XFBehavior() { + +} + +XFBehavior::~XFBehavior() { + +} + +void XFBehavior::startBehavior() { + +} + +void XFBehavior::pushEvent(XFEvent *pEvent) { + +} + +bool XFBehavior::deleteOnTerminate() const { + return deleteOnTerminate_; +} + +void XFBehavior::setDeleteOnTerminate(bool deleteBehaviour) { + deleteOnTerminate_ = deleteBehaviour; +} + +const XFEvent *XFBehavior::getCurrentEvent() const { + return pCurrentEvent_; +} + +interface::XFDispatcher *XFBehavior::getDispatcher() { + +} + +const XFTimeout *XFBehavior::getCurrentTimeout() { + +} + +void XFBehavior::setCurrentEvent(const XFEvent *pEvent) { + +} + +XFBehavior::TerminateBehavior XFBehavior::process(const XFEvent *pEvent) { + +} diff --git a/src/simplified/xf/port/common/dispatcher.cpp b/src/simplified/xf/port/common/dispatcher.cpp index 38b2713..9d27e6e 100644 --- a/src/simplified/xf/port/common/dispatcher.cpp +++ b/src/simplified/xf/port/common/dispatcher.cpp @@ -19,12 +19,46 @@ using Mutex = interface::XFMutex; // Rename XFMutex interface class to Mut // Note: The implementation is done here because only in this file the real XFDispatcher // class is known (port specific class). An instance of the XFDispatcher class is // returned by the 'interface::XFDispatcher' class. -interface::XFDispatcher * interface::XFDispatcher::getInstance() -{ +interface::XFDispatcher * interface::XFDispatcher::getInstance() { static ::XFDispatcher dispatcher; return &dispatcher; } // TODO: Implement code for XFDispatcher class +XFDispatcher::XFDispatcher() { + +} + +XFDispatcher::~XFDispatcher() { + +} + +void XFDispatcher::dispatchEvent(const XFEvent *pEvent) const { + +} + +void XFDispatcher::pushEvent(XFEvent *pEvent) { + events_.push(pEvent); +} + +void XFDispatcher::scheduleTimeout(int timeoutId, int interval, interface::XFBehavior *pBehavior) { + XFTimeoutManager* timeoutManager = XFTimeoutManager::getInstance(); + timeoutManager->scheduleTimeout(timeoutId, interval, pBehavior); +} + +void XFDispatcher::unscheduleTimeout(int timeoutId, interface::XFBehavior *pBehavior) { + XFTimeoutManager* timeoutManager = XFTimeoutManager::getInstance(); + timeoutManager->unscheduleTimeout(timeoutId, pBehavior); +} + +void XFDispatcher::executeOnce() { + +} + +int XFDispatcher::execute(const void *param) { + +} + + #endif // USE_XF_COMMON_DISPATCHER_CLASS diff --git a/src/simplified/xf/port/common/timeoutmanager.cpp b/src/simplified/xf/port/common/timeoutmanager.cpp index 827166e..569bbef 100644 --- a/src/simplified/xf/port/common/timeoutmanager.cpp +++ b/src/simplified/xf/port/common/timeoutmanager.cpp @@ -23,7 +23,14 @@ interface::XFTimeoutManager * interface::XFTimeoutManager::getInstance() { // TODO: Implement code for XFTimeoutManager class XFTimeoutManager::XFTimeoutManager() { +} +void XFTimeoutManager::addTimeout(XFTimeout *pNewTimeout) { + timeouts_.push_front(pNewTimeout); +} + +void XFTimeoutManager::returnTimeout(XFTimeout *pTimeout) { + timeouts_.remove(pTimeout); } XFTimeoutManager::~XFTimeoutManager() { @@ -36,14 +43,23 @@ void XFTimeoutManager::start(std::function startTimeoutManagerT void XFTimeoutManager::scheduleTimeout(int32_t timeoutId, int32_t interval, interface::XFBehavior *pBehavior) { ::XFTimeout* timeout = new XFTimeout(timeoutId, interval, pBehavior); - timeouts_.push_front(timeout); + addTimeout(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); + for(XFTimeout* timeout : timeouts_) { + bool id = ( timeout->getId() == timeoutId ); + bool behavior = ( timeout->getBehavior() == pBehavior); + if( id && behavior ) { + timeouts_.remove(timeout); + } + } +} + +void XFTimeoutManager::tick() { + for(XFTimeout* timeout : timeouts_) { + timeout->substractFromRelTicks(tickInterval_); + } } #endif // USE_XF_COMMON_TIMEOUTMANAGER_CLASS