Initial commit
This commit is contained in:
		
							
								
								
									
										62
									
								
								test-bench/test5/src/app/statemachine05a.cpp
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										62
									
								
								test-bench/test5/src/app/statemachine05a.cpp
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,62 @@
 | 
			
		||||
#include <stdio.h>
 | 
			
		||||
#include "trace/trace.h"
 | 
			
		||||
#include "statemachine05a.h"
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * Constructor
 | 
			
		||||
 *
 | 
			
		||||
 * \param text Text to display by the state machine.
 | 
			
		||||
 */
 | 
			
		||||
StateMachine05a::StateMachine05a(string text)
 | 
			
		||||
 : text_(text)
 | 
			
		||||
{
 | 
			
		||||
	currentState_ = STATE_INITIAL;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
StateMachine05a::~StateMachine05a()
 | 
			
		||||
{
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
XFEventStatus StateMachine05a::processEvent()
 | 
			
		||||
{
 | 
			
		||||
	eEventStatus eventStatus = XFEventStatus::Unknown;
 | 
			
		||||
 | 
			
		||||
	switch (currentState_)
 | 
			
		||||
	{
 | 
			
		||||
	case STATE_INITIAL:
 | 
			
		||||
		{
 | 
			
		||||
			if (getCurrentEvent()->getEventType() == XFEvent::Initial)
 | 
			
		||||
			{
 | 
			
		||||
				GEN(XFDefaultTransition());
 | 
			
		||||
 | 
			
		||||
				currentState_ = STATE_SAY_TEXT;
 | 
			
		||||
 | 
			
		||||
				eventStatus = XFEventStatus::Consumed;
 | 
			
		||||
			}
 | 
			
		||||
		}
 | 
			
		||||
		break;
 | 
			
		||||
	case STATE_SAY_TEXT:
 | 
			
		||||
		{
 | 
			
		||||
			if (getCurrentEvent()->getEventType() == XFEvent::DefaultTransition ||
 | 
			
		||||
				(getCurrentEvent()->getEventType() == XFEvent::Timeout &&
 | 
			
		||||
				 getCurrentTimeout()->getId() == Timeout_SAY_HELLO_id))
 | 
			
		||||
			{
 | 
			
		||||
				{
 | 
			
		||||
					Trace::out(getText());
 | 
			
		||||
				}
 | 
			
		||||
 | 
			
		||||
                scheduleTimeout(Timeout_SAY_HELLO_id, 500);
 | 
			
		||||
 | 
			
		||||
				currentState_ = STATE_SAY_TEXT;
 | 
			
		||||
 | 
			
		||||
				eventStatus = XFEventStatus::Consumed;
 | 
			
		||||
			}
 | 
			
		||||
		}
 | 
			
		||||
		break;
 | 
			
		||||
	default:
 | 
			
		||||
		break;
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	return eventStatus;
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										54
									
								
								test-bench/test5/src/app/statemachine05a.h
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										54
									
								
								test-bench/test5/src/app/statemachine05a.h
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,54 @@
 | 
			
		||||
#ifndef STATEMACHINE05A_H
 | 
			
		||||
#define STATEMACHINE05A_H
 | 
			
		||||
 | 
			
		||||
#include <string>
 | 
			
		||||
#include "xf/behavior.h"
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * \ingroup test05
 | 
			
		||||
 *
 | 
			
		||||
 * Task implementing a little state machine saying something
 | 
			
		||||
 * in a predefined time interval. The text to output is passed
 | 
			
		||||
 * to the object at construction time. The time interval is fixed
 | 
			
		||||
 * to 500 milliseconds.
 | 
			
		||||
 *
 | 
			
		||||
 * Following you will find the state machine implemented by StateMachine05a:
 | 
			
		||||
 * \image html state-machine05a.png "State Machine implemented by StateMachine05a"
 | 
			
		||||
 */
 | 
			
		||||
class StateMachine05a : public XFBehavior
 | 
			
		||||
{
 | 
			
		||||
public:
 | 
			
		||||
    StateMachine05a(std::string text);
 | 
			
		||||
    ~StateMachine05a() override;
 | 
			
		||||
 | 
			
		||||
protected:
 | 
			
		||||
    XFEventStatus processEvent() override;                              ///< Remplementation from XFReactive
 | 
			
		||||
 | 
			
		||||
    inline std::string getText() const { return text_; }				///< Returns text. Accessor for #_text.
 | 
			
		||||
 | 
			
		||||
protected:
 | 
			
		||||
	/**
 | 
			
		||||
	 * Timeout identifier(s) for this state machine
 | 
			
		||||
	 */
 | 
			
		||||
	typedef enum
 | 
			
		||||
	{
 | 
			
		||||
		Timeout_SAY_HELLO_id = 1	///< Timeout id for WAIT
 | 
			
		||||
	} eTimeoutId;
 | 
			
		||||
 | 
			
		||||
	/**
 | 
			
		||||
	 * Enumeration used to have a unique identifier for every
 | 
			
		||||
	 * state in the state machine.
 | 
			
		||||
	 */
 | 
			
		||||
	typedef enum
 | 
			
		||||
	{
 | 
			
		||||
		STATE_UNKNOWN = 0,			///< Unknown state
 | 
			
		||||
		STATE_INITIAL = 1,			///< Initial state
 | 
			
		||||
		STATE_SAY_TEXT = 2			///< Say "text" state
 | 
			
		||||
	} eMainState;
 | 
			
		||||
 | 
			
		||||
    eMainState currentState_;		///< Attribute indicating currently active state
 | 
			
		||||
 | 
			
		||||
    std::string text_;				///< Text to display in state machine state
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
#endif // STATEMACHINE05A_H
 | 
			
		||||
							
								
								
									
										62
									
								
								test-bench/test5/src/app/statemachine05b.cpp
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										62
									
								
								test-bench/test5/src/app/statemachine05b.cpp
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,62 @@
 | 
			
		||||
#include <stdio.h>
 | 
			
		||||
#include "trace/trace.h"
 | 
			
		||||
#include "statemachine05b.h"
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * Constructor
 | 
			
		||||
 *
 | 
			
		||||
 * \param text Text to display by the state machine.
 | 
			
		||||
 */
 | 
			
		||||
StateMachine05b::StateMachine05b(string text)
 | 
			
		||||
 : text_(text)
 | 
			
		||||
{
 | 
			
		||||
	currentState_ = STATE_INITIAL;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
StateMachine05b::~StateMachine05b()
 | 
			
		||||
{
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
XFEventStatus StateMachine05b::processEvent()
 | 
			
		||||
{
 | 
			
		||||
	eEventStatus eventStatus = XFEventStatus::Unknown;
 | 
			
		||||
 | 
			
		||||
	switch (currentState_)
 | 
			
		||||
	{
 | 
			
		||||
	case STATE_INITIAL:
 | 
			
		||||
		{
 | 
			
		||||
			if (getCurrentEvent()->getEventType() == XFEvent::Initial)
 | 
			
		||||
			{
 | 
			
		||||
				GEN(XFDefaultTransition());
 | 
			
		||||
 | 
			
		||||
				currentState_ = STATE_SAY_TEXT;
 | 
			
		||||
 | 
			
		||||
				eventStatus = XFEventStatus::Consumed;
 | 
			
		||||
			}
 | 
			
		||||
		}
 | 
			
		||||
		break;
 | 
			
		||||
	case STATE_SAY_TEXT:
 | 
			
		||||
		{
 | 
			
		||||
			if (getCurrentEvent()->getEventType() == XFEvent::DefaultTransition ||
 | 
			
		||||
				(getCurrentEvent()->getEventType() == XFEvent::Timeout &&
 | 
			
		||||
				 getCurrentTimeout()->getId() == Timeout_SAY_HELLO_id))
 | 
			
		||||
			{
 | 
			
		||||
				{
 | 
			
		||||
					Trace::out(getText());
 | 
			
		||||
				}
 | 
			
		||||
 | 
			
		||||
                scheduleTimeout(Timeout_SAY_HELLO_id, 1000);
 | 
			
		||||
 | 
			
		||||
				currentState_ = STATE_SAY_TEXT;
 | 
			
		||||
 | 
			
		||||
				eventStatus = XFEventStatus::Consumed;
 | 
			
		||||
			}
 | 
			
		||||
		}
 | 
			
		||||
		break;
 | 
			
		||||
	default:
 | 
			
		||||
		break;
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	return eventStatus;
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										54
									
								
								test-bench/test5/src/app/statemachine05b.h
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										54
									
								
								test-bench/test5/src/app/statemachine05b.h
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,54 @@
 | 
			
		||||
#ifndef STATEMACHINE05B_H
 | 
			
		||||
#define STATEMACHINE05B_H
 | 
			
		||||
 | 
			
		||||
#include <string>
 | 
			
		||||
#include "xf/behavior.h"
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * \ingroup test05
 | 
			
		||||
 *
 | 
			
		||||
 * Task implementing a little state machine saying something
 | 
			
		||||
 * in a predefined time interval. The text to output is passed
 | 
			
		||||
 * to the object at construction time. The time interval is fixed
 | 
			
		||||
 * to one second.
 | 
			
		||||
 *
 | 
			
		||||
 * Following you will find the state machine implemented by StateMachine05b:
 | 
			
		||||
 * \image html state-machine05b.png "State Machine implemented by StateMachine05b"
 | 
			
		||||
 */
 | 
			
		||||
class StateMachine05b : public XFBehavior
 | 
			
		||||
{
 | 
			
		||||
public:
 | 
			
		||||
    StateMachine05b(std::string text);
 | 
			
		||||
    ~StateMachine05b() override;
 | 
			
		||||
 | 
			
		||||
protected:
 | 
			
		||||
    XFEventStatus processEvent() override;                              ///< Remplementation from XFReactive
 | 
			
		||||
 | 
			
		||||
    inline std::string getText() const { return text_; }				///< Returns text. Accessor for #_text.
 | 
			
		||||
 | 
			
		||||
protected:
 | 
			
		||||
	/**
 | 
			
		||||
	 * Timeout identifier(s) for this state machine
 | 
			
		||||
	 */
 | 
			
		||||
	typedef enum
 | 
			
		||||
	{
 | 
			
		||||
		Timeout_SAY_HELLO_id = 1	///< Timeout id for WAIT
 | 
			
		||||
	} eTimeoutId;
 | 
			
		||||
 | 
			
		||||
	/**
 | 
			
		||||
	 * Enumeration used to have a unique identifier for every
 | 
			
		||||
	 * state in the state machine.
 | 
			
		||||
	 */
 | 
			
		||||
	typedef enum
 | 
			
		||||
	{
 | 
			
		||||
		STATE_UNKNOWN = 0,			///< Unknown state
 | 
			
		||||
		STATE_INITIAL = 1,			///< Initial state
 | 
			
		||||
		STATE_SAY_TEXT = 2			///< Say "text" state
 | 
			
		||||
	} eMainState;
 | 
			
		||||
 | 
			
		||||
    eMainState currentState_;		///< Attribute indicating currently active state
 | 
			
		||||
 | 
			
		||||
    std::string text_;				///< Text to display in state machine state
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
#endif // STATEMACHINE05B_H
 | 
			
		||||
							
								
								
									
										39
									
								
								test-bench/test5/src/app/testfactory05.cpp
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										39
									
								
								test-bench/test5/src/app/testfactory05.cpp
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,39 @@
 | 
			
		||||
#include "xf/xf.h"
 | 
			
		||||
#include "trace/trace.h"
 | 
			
		||||
#include "testfactory05.h"
 | 
			
		||||
 | 
			
		||||
void Factory_initialize()
 | 
			
		||||
{
 | 
			
		||||
    TestFactory05::initialize();
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void Factory_build()
 | 
			
		||||
{
 | 
			
		||||
    TestFactory05::build();
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
StateMachine05a TestFactory05::task01_("Tick 500ms");
 | 
			
		||||
StateMachine05b TestFactory05::task02_(" One");
 | 
			
		||||
StateMachine05b TestFactory05::task03_("  Two");
 | 
			
		||||
StateMachine05b TestFactory05::task04_("   Three");
 | 
			
		||||
 | 
			
		||||
TestFactory05::TestFactory05()
 | 
			
		||||
{
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// static
 | 
			
		||||
void TestFactory05::initialize()
 | 
			
		||||
{
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// static
 | 
			
		||||
void TestFactory05::build()
 | 
			
		||||
{
 | 
			
		||||
	Trace::out("Starting test5...");
 | 
			
		||||
	Trace::out("---------------------");
 | 
			
		||||
	// Start state machine(s)
 | 
			
		||||
	task01_.startBehavior();
 | 
			
		||||
	task02_.startBehavior();
 | 
			
		||||
	task03_.startBehavior();
 | 
			
		||||
	task04_.startBehavior();
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										49
									
								
								test-bench/test5/src/app/testfactory05.h
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										49
									
								
								test-bench/test5/src/app/testfactory05.h
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,49 @@
 | 
			
		||||
#ifndef TESTFACTORY05_H
 | 
			
		||||
#define TESTFACTORY05_H
 | 
			
		||||
 | 
			
		||||
//
 | 
			
		||||
// What is seen only by the C++ compiler
 | 
			
		||||
//
 | 
			
		||||
#ifdef __cplusplus
 | 
			
		||||
 | 
			
		||||
#include "statemachine05a.h"
 | 
			
		||||
#include "statemachine05b.h"
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * \ingroup test05
 | 
			
		||||
 *
 | 
			
		||||
 * @brief Factory creating all objects used in test5.
 | 
			
		||||
 *
 | 
			
		||||
 */
 | 
			
		||||
class TestFactory05
 | 
			
		||||
{
 | 
			
		||||
public:
 | 
			
		||||
	TestFactory05();			///< Constructor
 | 
			
		||||
 | 
			
		||||
    static void initialize();   ///< Initializes the factory
 | 
			
		||||
    static void build();        ///< Creates components and initializes relations
 | 
			
		||||
 | 
			
		||||
protected:
 | 
			
		||||
    static StateMachine05a task01_;		///< Instance of StateMachine05a saying 'Tick 500ms'
 | 
			
		||||
    static StateMachine05b task02_;		///< Instance of StateMachine05b saying 'One' every second.
 | 
			
		||||
    static StateMachine05b task03_;		///< Instance of StateMachine05b saying 'Two' every second.
 | 
			
		||||
    static StateMachine05b task04_;		///< Instance of StateMachine05b saying 'Three' every second.
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
#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 // TESTFACTORY05_H
 | 
			
		||||
							
								
								
									
										24
									
								
								test-bench/test5/src/events/eventids.h
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										24
									
								
								test-bench/test5/src/events/eventids.h
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,24 @@
 | 
			
		||||
#ifndef EVENTIDS_H
 | 
			
		||||
#define EVENTIDS_H
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * This class is responsible to distribute to every event
 | 
			
		||||
 * used in the project a different event id.
 | 
			
		||||
 *
 | 
			
		||||
 * Only values grater than zero should be used
 | 
			
		||||
 *
 | 
			
		||||
 */
 | 
			
		||||
class EventId
 | 
			
		||||
{
 | 
			
		||||
public:
 | 
			
		||||
	/**
 | 
			
		||||
	 * The event identifiers available
 | 
			
		||||
	 */
 | 
			
		||||
	typedef enum
 | 
			
		||||
	{
 | 
			
		||||
		Unknown = 0,		///< Unknown event. Must not be used.
 | 
			
		||||
		evRestart = 1		///< Restart event
 | 
			
		||||
	} eEventId;
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
#endif // EVENTIDS_H
 | 
			
		||||
							
								
								
									
										9
									
								
								test-bench/test5/src/events/evrestart.cpp
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										9
									
								
								test-bench/test5/src/events/evrestart.cpp
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,9 @@
 | 
			
		||||
#include "evrestart.h"
 | 
			
		||||
 | 
			
		||||
evRestart::evRestart() : XFCustomEvent(EventId::evRestart)
 | 
			
		||||
{
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
evRestart::~evRestart()
 | 
			
		||||
{
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										17
									
								
								test-bench/test5/src/events/evrestart.h
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										17
									
								
								test-bench/test5/src/events/evrestart.h
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,17 @@
 | 
			
		||||
#ifndef EVRESTART_H
 | 
			
		||||
#define EVRESTART_H
 | 
			
		||||
 | 
			
		||||
#include "xf/customevent.h"
 | 
			
		||||
#include "eventids.h"
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * Restart event used to reset a state machine
 | 
			
		||||
 */
 | 
			
		||||
class evRestart : public XFCustomEvent
 | 
			
		||||
{
 | 
			
		||||
public:
 | 
			
		||||
	evRestart();
 | 
			
		||||
    ~evRestart() override;
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
#endif // EVRESTART_H
 | 
			
		||||
							
								
								
									
										14
									
								
								test-bench/test5/src/main.cpp
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										14
									
								
								test-bench/test5/src/main.cpp
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,14 @@
 | 
			
		||||
#include "xf/xf.h"
 | 
			
		||||
#include "app/testfactory05.h"
 | 
			
		||||
 | 
			
		||||
int main(int argc, char *argv[])
 | 
			
		||||
{
 | 
			
		||||
    XF::initialize(20, argc, argv);
 | 
			
		||||
 | 
			
		||||
	TestFactory05 factory;
 | 
			
		||||
 | 
			
		||||
    factory.initialize();
 | 
			
		||||
    factory.build();
 | 
			
		||||
 | 
			
		||||
    return XF::exec();
 | 
			
		||||
}
 | 
			
		||||
		Reference in New Issue
	
	Block a user