Compare commits

..

4 Commits

Author SHA1 Message Date
820aff5af4 probably full of mistake 2023-10-05 11:50:03 +02:00
3ef80d2187 implement customevent 2023-10-05 11:49:33 +02:00
ed95e01cf3 implement events 2023-10-05 11:48:10 +02:00
25f77289d7 polsih bracket 2023-10-05 11:46:23 +02:00
10 changed files with 67 additions and 50 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

@ -1,3 +1,11 @@
#include "xf/customevent.h" #include "xf/customevent.h"
// TODO: Implement code for XFCustomEvent class // TODO done: Implement code for XFCustomEvent class
XFCustomEvent::XFCustomEvent(int id, interface::XFBehavior *pBehavior):
XFEvent(XFEventType::Unknown, id){
setBehavior(pBehavior);
}

View File

@ -1,3 +1,12 @@
#include "xf/defaulttransition.h" #include "xf/defaulttransition.h"
// TODO: Implement code for XFDefaultTransition class // TODO done: Implement code for XFDefaultTransition class
XFDefaultTransition::XFDefaultTransition():
XFEvent(XFEventType::DefaultTransition) {
}
bool XFDefaultTransition::deleteAfterConsume() const {
return true;
}

View File

@ -1,3 +1,12 @@
#include "xf/initialevent.h" #include "xf/initialevent.h"
// TODO: Implement code for XFInitialEvent class // TODO done: Implement code for XFInitialEvent class
XFInitialEvent::XFInitialEvent():
XFEvent(XFEventType::Initial) {
}
bool XFInitialEvent::deleteAfterConsume() const {
return true;
}

View File

@ -4,6 +4,7 @@
XFTimeout::XFTimeout(int id, int interval, interface::XFBehavior *pBehavior): XFTimeout::XFTimeout(int id, int interval, interface::XFBehavior *pBehavior):
XFEvent(XFEventType::Timeout, id), interval_(interval) { XFEvent(XFEventType::Timeout, id), interval_(interval) {
setBehavior(pBehavior);
} }
bool XFTimeout::operator ==(const XFTimeout &timeout) const { bool XFTimeout::operator ==(const XFTimeout &timeout) const {

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) {

View File

@ -7,23 +7,19 @@
#include <QMutexLocker> #include <QMutexLocker>
#include "eventqueue.h" #include "eventqueue.h"
XFEventQueue::XFEventQueue() XFEventQueue::XFEventQueue() {
{
} }
XFEventQueue::~XFEventQueue() XFEventQueue::~XFEventQueue() {
{
newEvents_.wakeAll(); newEvents_.wakeAll();
} }
bool XFEventQueue::empty() const bool XFEventQueue::empty() const {
{
return queue_.isEmpty(); return queue_.isEmpty();
} }
bool XFEventQueue::push(const XFEvent * pEvent, bool fromISR) bool XFEventQueue::push(const XFEvent * pEvent, bool fromISR) {
{ (void)fromISR; // Just for don't have the warning
(void)fromISR;
QMutexLocker locker(&mutex_); QMutexLocker locker(&mutex_);
queue_.enqueue(pEvent); queue_.enqueue(pEvent);
// Tell waiting thread(s) there is again an event present // Tell waiting thread(s) there is again an event present
@ -31,19 +27,16 @@ bool XFEventQueue::push(const XFEvent * pEvent, bool fromISR)
return true; return true;
} }
const XFEvent * XFEventQueue::front() const XFEvent * XFEventQueue::front() {
{
return queue_.front(); return queue_.front();
} }
void XFEventQueue::pop() void XFEventQueue::pop() {
{
QMutexLocker locker(&mutex_); QMutexLocker locker(&mutex_);
queue_.dequeue(); queue_.dequeue();
} }
bool XFEventQueue::pend() bool XFEventQueue::pend() {
{
QMutexLocker locker(&mutex_); QMutexLocker locker(&mutex_);
// Wait for new events. Mutex needs to be in lock-state // Wait for new events. Mutex needs to be in lock-state
// prior to call wait()! // prior to call wait()!

View File

@ -10,26 +10,21 @@
*/ */
StateMachine01::StateMachine01(int repeatInterval, string text) StateMachine01::StateMachine01(int repeatInterval, string text)
: repeatInterval_(repeatInterval), : repeatInterval_(repeatInterval),
text_(text) text_(text) {
{
currentState_ = STATE_INITIAL; currentState_ = STATE_INITIAL;
} }
StateMachine01::~StateMachine01() StateMachine01::~StateMachine01() {
{
} }
XFEventStatus StateMachine01::processEvent() XFEventStatus StateMachine01::processEvent() {
{
eEventStatus eventStatus = XFEventStatus::Unknown; eEventStatus eventStatus = XFEventStatus::Unknown;
switch (currentState_) switch (currentState_) {
{
case STATE_INITIAL: case STATE_INITIAL:
{ {
if (getCurrentEvent()->getEventType() == XFEvent::Initial) if (getCurrentEvent()->getEventType() == XFEvent::Initial) {
{
GEN(XFDefaultTransition()); GEN(XFDefaultTransition());
currentState_ = STATE_SAY_HELLO; currentState_ = STATE_SAY_HELLO;

View File

@ -2,31 +2,26 @@
#include "trace/trace.h" #include "trace/trace.h"
#include "testfactory01.h" #include "testfactory01.h"
void Factory_initialize() void Factory_initialize() {
{
TestFactory01::initialize(); TestFactory01::initialize();
} }
void Factory_build() void Factory_build() {
{
TestFactory01::build(); TestFactory01::build();
} }
StateMachine01 TestFactory01::task01_(1000, "Say Hello"); StateMachine01 TestFactory01::task01_(1000, "Say Hello");
StateMachine01 TestFactory01::task02_(500, "Echo"); StateMachine01 TestFactory01::task02_(500, "Echo");
TestFactory01::TestFactory01() TestFactory01::TestFactory01() {
{
} }
// static // static
void TestFactory01::initialize() void TestFactory01::initialize() {
{
} }
// static // static
void TestFactory01::build() void TestFactory01::build() {
{
Trace::out("Starting test1..."); Trace::out("Starting test1...");
Trace::out("---------------------"); Trace::out("---------------------");