Initial commit

This commit is contained in:
2023-09-19 15:59:49 +02:00
commit bef0bade14
1860 changed files with 582828 additions and 0 deletions

View File

@ -0,0 +1,102 @@
#include <stdio.h>
#include "trace/trace.h"
#include "statemachine02.h"
uint32_t StateMachine02::nextId = 1; // Static attribute initialization.
StateMachine02::StateMachine02() :
id(nextId++),
counter(0)
{
_currentState = STATE_INITIAL;
Trace::out("Called constructor of StateMachine02 object '%d' (obj%02d)", id, id);
}
StateMachine02::~StateMachine02()
{
Trace::out("obj%02d: Called destructor", id);
}
/**
* Implements state machine behavior.
*/
XFEventStatus StateMachine02::processEvent()
{
eEventStatus eventStatus = XFEventStatus::Unknown;
switch (_currentState)
{
case STATE_INITIAL:
{
if (getCurrentEvent()->getEventType() == XFEvent::Initial)
{
{
counter = 5;
}
GEN(XFDefaultTransition());
_currentState = STATE_PRINT_COUNT;
eventStatus = XFEventStatus::Consumed;
}
}
break;
case STATE_PRINT_COUNT:
{
if (getCurrentEvent()->getEventType() == XFEvent::DefaultTransition)
{
{
Trace::out("obj%02d: counter %d", id, counter);
}
scheduleTimeout(Timeout_PRINT_COUNT_id, 1000);
_currentState = STATE_CONDITION_01;
eventStatus = XFEventStatus::Consumed;
}
}
break;
case STATE_CONDITION_01:
{
if (getCurrentEvent()->getEventType() == XFEvent::Timeout &&
getCurrentTimeout()->getId() == Timeout_PRINT_COUNT_id)
{
{
counter--;
}
if (counter)
{
_currentState = STATE_PRINT_COUNT;
}
else
{
_currentState = STATE_TERMINATION_01;
}
GEN(XFDefaultTransition());
eventStatus = XFEventStatus::Consumed;
}
}
break;
case STATE_TERMINATION_01:
{
if (getCurrentEvent()->getEventType() == XFEvent::DefaultTransition)
{
Trace::out("obj%02d: Terminating State Machine", id);
eventStatus = XFEventStatus::Terminate;
}
}
break;
default:
break;
}
return eventStatus;
}

View File

@ -0,0 +1,55 @@
#ifndef STATEMACHINE02_H
#define STATEMACHINE02_H
#include <string>
#include "xf/behavior.h"
/**
* \ingroup test02
*
* Task implementing a state machine doing a count down
* from 5 to 1 and terminating.
*
* Following you will find the state machine implemented by StateMachine02:
* \image html state-machine02.png "State Machine implemented by StateMachine02"
*/
class StateMachine02 : public XFBehavior
{
public:
StateMachine02();
~StateMachine02() override;
protected:
XFEventStatus processEvent() override;
protected:
/**
* Timeout identifier(s) for this state machine
*/
typedef enum
{
Timeout_PRINT_COUNT_id = 1 ///< Timeout id for WAIT
} eTimeoutId;
/**
* Enumeration used to have a unique identifier for every
* state in the state machine.
*/
typedef enum
{
STATE_UNKOWN = 0, ///< Unkown state.
STATE_INITIAL = 1, ///< Initial state.
STATE_PRINT_COUNT = 2, ///< Print count state.
STATE_CONDITION_01 = 3, ///< Condition after print count state.
STATE_TERMINATION_01 = 4 ///< Termination state.
} eMainState;
eMainState _currentState; ///< Attribute indicating currently active state.
static uint32_t nextId; ///< Static attribute providing identifier for next object.
const uint32_t id; ///< Object identifier.
int counter; ///< Count down attribute used in state machine.
};
#endif // STATEMACHINE02_H

View File

@ -0,0 +1,62 @@
#include <cassert>
#include "xf/xf.h"
#include "trace/trace.h"
#include "testfactory02.h"
void Factory_initialize()
{
TestFactory02::initialize();
}
void Factory_build()
{
TestFactory02::build();
}
TestFactory02::TestFactory02()
{
}
// static
void TestFactory02::initialize()
{
// Object is statically created. Object cannot be deleted by the XF
getStaticTask().setDeleteOnTerminate(false);
// Object is dynamically created. Object must be deleted by the XF
// when after event processing the behavior wants to be deleted
getDynamicTask().setDeleteOnTerminate(true);
}
// static
void TestFactory02::build()
{
Trace::out("Starting test2...");
Trace::out("---------------------");
// Start state machines
getStaticTask().startBehavior();
getDynamicTask().startBehavior();
}
// static
StateMachine02 &TestFactory02::getStaticTask()
{
static StateMachine02 staticTask;
return staticTask;
}
// static
StateMachine02 &TestFactory02::getDynamicTask()
{
static StateMachine02 * dynamicTask = nullptr;
if (!dynamicTask)
{
dynamicTask = new StateMachine02;
}
assert(dynamicTask); // Check heap
return *dynamicTask;
}

View File

@ -0,0 +1,45 @@
#ifndef TESTFACTORY02_H
#define TESTFACTORY02_H
//
// What is seen only by the C++ compiler
//
#ifdef __cplusplus
#include "statemachine02.h"
/**
* \ingroup test02
*
* Factory creating all objects used in test2.
*
*/
class TestFactory02
{
public:
TestFactory02(); ///< Constructor.
static void initialize(); ///< Initializes the factory.
static void build(); ///< Creates components and initializes relations.
protected:
static StateMachine02 & getStaticTask(); ///< Returns reference to static instance of StateMachine02.
static StateMachine02 & getDynamicTask(); ///< Returns reference to dynamically allocated instance of StateMachine02.
};
#endif // __cplusplus
//
// What is seen by the C and C++ compiler
//
#ifdef __cplusplus
extern "C" {
#endif // __cplusplus
void Factory_initialize();
void Factory_build();
#ifdef __cplusplus
}
#endif // __cplusplus
#endif // TESTFACTORY02_H

View File

@ -0,0 +1,14 @@
#include "xf/xf.h"
#include "app/testfactory02.h"
int main(int argc, char *argv[])
{
XF::initialize(20, argc, argv);
TestFactory02 factory;
factory.initialize();
factory.build();
return XF::exec();
}