Initial commit
This commit is contained in:
		
							
								
								
									
										73
									
								
								test-bench/test3/src/app/statemachine03.cpp
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										73
									
								
								test-bench/test3/src/app/statemachine03.cpp
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,73 @@ | ||||
| #include <stdio.h> | ||||
| #include "trace/trace.h" | ||||
| #include "events/evrestart.h" | ||||
| #include "statemachine03.h" | ||||
|  | ||||
| StateMachine03::StateMachine03() | ||||
| { | ||||
| 	currentState_ = STATE_INITIAL; | ||||
| } | ||||
|  | ||||
| StateMachine03::~StateMachine03() | ||||
| { | ||||
|  | ||||
| } | ||||
|  | ||||
| /** | ||||
|  * Implements state machine behavior. | ||||
|  */ | ||||
| XFEventStatus StateMachine03::processEvent() | ||||
| { | ||||
| 	eEventStatus eventStatus = XFEventStatus::Unknown; | ||||
|  | ||||
| 	switch (currentState_) | ||||
| 	{ | ||||
| 	case STATE_INITIAL: | ||||
| 		{ | ||||
| 			if (getCurrentEvent()->getEventType() == XFEvent::Initial) | ||||
| 			{ | ||||
| 				GEN(XFDefaultTransition()); | ||||
|  | ||||
| 				currentState_ = STATE_WAIT; | ||||
| 				eventStatus = XFEventStatus::Consumed; | ||||
| 			} | ||||
| 		} | ||||
| 		break; | ||||
| 	case STATE_WAIT: | ||||
| 		{ | ||||
| 			if (getCurrentEvent()->getEventType() == XFEvent::DefaultTransition || | ||||
| 				(getCurrentEvent()->getEventType() == XFEvent::Event && | ||||
| 				 getCurrentEvent()->getId() == EventId::evRestart)) | ||||
| 			{ | ||||
| 				{ | ||||
| 					Trace::out("Wait"); | ||||
| 				} | ||||
|  | ||||
|                 scheduleTimeout(Timeout_WAIT_id, 2000); | ||||
|  | ||||
| 				currentState_ = STATE_SEND_RESTART; | ||||
| 				eventStatus = XFEventStatus::Consumed; | ||||
| 			} | ||||
| 		} | ||||
| 		break; | ||||
| 	case STATE_SEND_RESTART: | ||||
| 		{ | ||||
| 			if (getCurrentEvent()->getEventType() == XFEvent::Timeout && | ||||
| 				getCurrentTimeout()->getId() == Timeout_WAIT_id) | ||||
| 			{ | ||||
| 				{ | ||||
| 					Trace::out("Wait restart"); | ||||
| 					GEN(evRestart()); | ||||
| 				} | ||||
|  | ||||
| 				currentState_ = STATE_WAIT; | ||||
| 				eventStatus = XFEventStatus::Consumed; | ||||
| 			} | ||||
| 		} | ||||
| 		break; | ||||
| 	default: | ||||
| 		break; | ||||
| 	} | ||||
|  | ||||
| 	return eventStatus; | ||||
| } | ||||
							
								
								
									
										49
									
								
								test-bench/test3/src/app/statemachine03.h
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										49
									
								
								test-bench/test3/src/app/statemachine03.h
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,49 @@ | ||||
| #ifndef STATEMACHINE03_H | ||||
| #define STATEMACHINE03_H | ||||
|  | ||||
| #include <string> | ||||
| #include "xf/behavior.h" | ||||
|  | ||||
| /** | ||||
|  * \ingroup test03 | ||||
|  * | ||||
|  * Implements a state machine sending itself an \a evRestart | ||||
|  * event, to drive the state machine further. | ||||
|  * | ||||
|  * Following you will find the state machine implemented by StateMachine03: | ||||
|  * \image html state-machine03.png "State Machine implemented by StateMachine03" | ||||
|  */ | ||||
| class StateMachine03 : public XFBehavior | ||||
| { | ||||
| public: | ||||
| 	StateMachine03(); | ||||
|     ~StateMachine03() override; | ||||
|  | ||||
| protected: | ||||
|     XFEventStatus processEvent() override; | ||||
|  | ||||
| protected: | ||||
| 	/** | ||||
| 	 * Timeout identifier(s) for this state machine | ||||
| 	 */ | ||||
| 	typedef enum | ||||
| 	{ | ||||
| 		Timeout_WAIT_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_WAIT = 2,				///< Wait state | ||||
| 		STATE_SEND_RESTART = 3		///< State sending an restart event | ||||
| 	} eMainState; | ||||
|  | ||||
|     eMainState currentState_;		///< Attribute indicating currently active state | ||||
| }; | ||||
|  | ||||
| #endif // STATEMACHINE03_H | ||||
							
								
								
									
										34
									
								
								test-bench/test3/src/app/testfactory03.cpp
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										34
									
								
								test-bench/test3/src/app/testfactory03.cpp
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,34 @@ | ||||
| #include "xf/xf.h" | ||||
| #include "trace/trace.h" | ||||
| #include "testfactory03.h" | ||||
|  | ||||
| void Factory_initialize() | ||||
| { | ||||
|     TestFactory03::initialize(); | ||||
| } | ||||
|  | ||||
| void Factory_build() | ||||
| { | ||||
|     TestFactory03::build(); | ||||
| } | ||||
|  | ||||
| StateMachine03 TestFactory03::task01_; | ||||
|  | ||||
| TestFactory03::TestFactory03() | ||||
| { | ||||
| } | ||||
|  | ||||
| // static | ||||
| void TestFactory03::initialize() | ||||
| { | ||||
| } | ||||
|  | ||||
| // static | ||||
| void TestFactory03::build() | ||||
| { | ||||
|     Trace::out("Starting test3..."); | ||||
|     Trace::out("---------------------"); | ||||
|  | ||||
|     // Start state machine | ||||
|     task01_.startBehavior(); | ||||
| } | ||||
							
								
								
									
										45
									
								
								test-bench/test3/src/app/testfactory03.h
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										45
									
								
								test-bench/test3/src/app/testfactory03.h
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,45 @@ | ||||
| #ifndef TESTFACTORY03_H | ||||
| #define TESTFACTORY03_H | ||||
|  | ||||
| // | ||||
| // What is seen only by the C++ compiler | ||||
| // | ||||
| #ifdef __cplusplus | ||||
|  | ||||
| #include "statemachine03.h" | ||||
|  | ||||
|  | ||||
| /** | ||||
|  * \ingroup test03 | ||||
|  * | ||||
|  * Factory creating all objects used in test3. | ||||
|  * | ||||
|  */ | ||||
| class TestFactory03 | ||||
| { | ||||
| public: | ||||
|     TestFactory03();                    ///< Constructor | ||||
|  | ||||
|     static void initialize();           ///< Initializes the factory | ||||
|     static void build();                ///< Creates components and initializes relations | ||||
|  | ||||
| protected: | ||||
|     static StateMachine03 task01_;		///< Instance of StateMachine03 | ||||
| }; | ||||
|  | ||||
| #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 // TESTFACTORY03_H | ||||
							
								
								
									
										24
									
								
								test-bench/test3/src/events/eventids.h
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										24
									
								
								test-bench/test3/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/test3/src/events/evrestart.cpp
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										9
									
								
								test-bench/test3/src/events/evrestart.cpp
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,9 @@ | ||||
| #include "evrestart.h" | ||||
|  | ||||
| evRestart::evRestart() : XFCustomEvent(EventId::evRestart) | ||||
| { | ||||
| } | ||||
|  | ||||
| evRestart::~evRestart() | ||||
| { | ||||
| } | ||||
							
								
								
									
										19
									
								
								test-bench/test3/src/events/evrestart.h
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										19
									
								
								test-bench/test3/src/events/evrestart.h
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,19 @@ | ||||
| #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/test3/src/main.cpp
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										14
									
								
								test-bench/test3/src/main.cpp
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,14 @@ | ||||
| #include "xf/xf.h" | ||||
| #include "app/testfactory03.h" | ||||
|  | ||||
| int main(int argc, char *argv[]) | ||||
| { | ||||
|     XF::initialize(20, argc, argv); | ||||
|  | ||||
| 	TestFactory03 factory; | ||||
|  | ||||
|     factory.initialize(); | ||||
|     factory.build(); | ||||
|  | ||||
|     return XF::exec(); | ||||
| } | ||||
		Reference in New Issue
	
	Block a user