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) {
|
||||
|
||||
pCurrentEvent_ = pEvent;
|
||||
}
|
||||
|
||||
XFBehavior::TerminateBehavior XFBehavior::process(const XFEvent *pEvent) {
|
||||
|
||||
setCurrentEvent(pEvent);
|
||||
processEvent();
|
||||
return deleteOnTerminate_;
|
||||
}
|
||||
|
@ -1,3 +1,11 @@
|
||||
#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"
|
||||
|
||||
// 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"
|
||||
|
||||
// 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):
|
||||
XFEvent(XFEventType::Timeout, id), interval_(interval) {
|
||||
setBehavior(pBehavior);
|
||||
}
|
||||
|
||||
bool XFTimeout::operator ==(const XFTimeout &timeout) const {
|
||||
|
@ -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() {
|
||||
|
@ -1,4 +1,5 @@
|
||||
|
||||
#include "common/dispatcher.h"
|
||||
#include <config/xf-config.h>
|
||||
|
||||
#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<void (uint32_t)> startTimeoutManagerTimer) {
|
||||
|
@ -7,23 +7,19 @@
|
||||
#include <QMutexLocker>
|
||||
#include "eventqueue.h"
|
||||
|
||||
XFEventQueue::XFEventQueue()
|
||||
{
|
||||
XFEventQueue::XFEventQueue() {
|
||||
}
|
||||
|
||||
XFEventQueue::~XFEventQueue()
|
||||
{
|
||||
XFEventQueue::~XFEventQueue() {
|
||||
newEvents_.wakeAll();
|
||||
}
|
||||
|
||||
bool XFEventQueue::empty() const
|
||||
{
|
||||
bool XFEventQueue::empty() const {
|
||||
return queue_.isEmpty();
|
||||
}
|
||||
|
||||
bool XFEventQueue::push(const XFEvent * pEvent, bool fromISR)
|
||||
{
|
||||
(void)fromISR;
|
||||
bool XFEventQueue::push(const XFEvent * pEvent, bool fromISR) {
|
||||
(void)fromISR; // Just for don't have the warning
|
||||
QMutexLocker locker(&mutex_);
|
||||
queue_.enqueue(pEvent);
|
||||
// Tell waiting thread(s) there is again an event present
|
||||
@ -31,19 +27,16 @@ bool XFEventQueue::push(const XFEvent * pEvent, bool fromISR)
|
||||
return true;
|
||||
}
|
||||
|
||||
const XFEvent * XFEventQueue::front()
|
||||
{
|
||||
const XFEvent * XFEventQueue::front() {
|
||||
return queue_.front();
|
||||
}
|
||||
|
||||
void XFEventQueue::pop()
|
||||
{
|
||||
void XFEventQueue::pop() {
|
||||
QMutexLocker locker(&mutex_);
|
||||
queue_.dequeue();
|
||||
}
|
||||
|
||||
bool XFEventQueue::pend()
|
||||
{
|
||||
bool XFEventQueue::pend() {
|
||||
QMutexLocker locker(&mutex_);
|
||||
// Wait for new events. Mutex needs to be in lock-state
|
||||
// prior to call wait()!
|
||||
|
@ -10,26 +10,21 @@
|
||||
*/
|
||||
StateMachine01::StateMachine01(int repeatInterval, string text)
|
||||
: repeatInterval_(repeatInterval),
|
||||
text_(text)
|
||||
{
|
||||
text_(text) {
|
||||
currentState_ = STATE_INITIAL;
|
||||
}
|
||||
|
||||
StateMachine01::~StateMachine01()
|
||||
{
|
||||
StateMachine01::~StateMachine01() {
|
||||
|
||||
}
|
||||
|
||||
XFEventStatus StateMachine01::processEvent()
|
||||
{
|
||||
XFEventStatus StateMachine01::processEvent() {
|
||||
eEventStatus eventStatus = XFEventStatus::Unknown;
|
||||
|
||||
switch (currentState_)
|
||||
{
|
||||
switch (currentState_) {
|
||||
case STATE_INITIAL:
|
||||
{
|
||||
if (getCurrentEvent()->getEventType() == XFEvent::Initial)
|
||||
{
|
||||
if (getCurrentEvent()->getEventType() == XFEvent::Initial) {
|
||||
GEN(XFDefaultTransition());
|
||||
|
||||
currentState_ = STATE_SAY_HELLO;
|
||||
|
@ -2,31 +2,26 @@
|
||||
#include "trace/trace.h"
|
||||
#include "testfactory01.h"
|
||||
|
||||
void Factory_initialize()
|
||||
{
|
||||
void Factory_initialize() {
|
||||
TestFactory01::initialize();
|
||||
}
|
||||
|
||||
void Factory_build()
|
||||
{
|
||||
void Factory_build() {
|
||||
TestFactory01::build();
|
||||
}
|
||||
|
||||
StateMachine01 TestFactory01::task01_(1000, "Say Hello");
|
||||
StateMachine01 TestFactory01::task02_(500, "Echo");
|
||||
|
||||
TestFactory01::TestFactory01()
|
||||
{
|
||||
TestFactory01::TestFactory01() {
|
||||
}
|
||||
|
||||
// static
|
||||
void TestFactory01::initialize()
|
||||
{
|
||||
void TestFactory01::initialize() {
|
||||
}
|
||||
|
||||
// static
|
||||
void TestFactory01::build()
|
||||
{
|
||||
void TestFactory01::build() {
|
||||
Trace::out("Starting test1...");
|
||||
Trace::out("---------------------");
|
||||
|
||||
|
Reference in New Issue
Block a user