Compare commits
4 Commits
6bfe6ee059
...
820aff5af4
Author | SHA1 | Date | |
---|---|---|---|
820aff5af4 | |||
3ef80d2187 | |||
ed95e01cf3 | |||
25f77289d7 |
@ -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_;
|
||||||
}
|
}
|
||||||
|
@ -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);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -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;
|
||||||
|
}
|
||||||
|
@ -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;
|
||||||
|
}
|
||||||
|
@ -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 {
|
||||||
|
@ -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() {
|
||||||
|
@ -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) {
|
||||||
|
@ -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()!
|
||||||
|
@ -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;
|
||||||
|
@ -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("---------------------");
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user