ÀÌ ÆäÀÌÁö´Â ȣȯ¼ºÀ» À§ÇØ ³²°ÜÁ³½À´Ï´Ù. [À̰÷ À¸·Î À̵¿]ÇØÁÖ¼¼¿ä.
2003³â 07¿ù 31ÀÏ 목요일
finite state machine
event°¡ ¹ß»ýÇϴµ¥, fsm¿¡ ¿ø·¡ ¾²¿©Á®¾ß ÇÏ´Â ¿¬¼ÓµÈ ÀԷ°ªÀ» ¾²Áö ¾Ê°í
ºñµ¿±â ÀÔ·ÂÀ» ¹Þ¾Æ state¸¦ Æ®·£Áö¼ÇÇÏ´Ù º¸´Ï, °©Àڱ⠳»°¡ ¹¹ÇÏ´ÂÁþÀΰ¡-_-
¶ó´Â »ý°¢ÀÌ µé¾ú´Ù. ÀÛ¾÷À» Çϱâ À§ÇØ fsmÀ» ¾²´Â°ÍÀÎÁö ¾Æ´Ï¸é fsmÀ» ¾²±â À§ÇØ
ÀÛ¾÷À» Çϴ°ÍÀÌÁö, °©ÀÚ±â ÁÖ°´ÀÌ ÀüµµµÇ¾ú´Ù´Â »ý°¢ÀÌ µé¾ú´Ù
´Ù½Ã ¸¸µé¾î¾ßÁö...-_-;;;;
¹¹ TFSM ¿¡´Ù TFSMScheduler, TFSMDispatcher°°Àº Ŭ·¡½º±îÁö µîÀåÇÏ´Ï±î ´ëü
¹¹°¡ À¯ÇÑ»óÅ ¸Ó½ÅÀÎÁö °©Àڱ⠾˵µ¸®°¡ ¾ø°Ô µÇ¹ö¸²...-_-;;;;
ÀÚ¼¼È÷ º¸±â¸¦ ´©¸£¸é finite state machine¿¡ ´ëÇÑ ¿ø·ÐÀû ¼³¸í°ú
TFSM class ¼Ò½º ÄÚµå
-----
finite state machine
In general, a state machine is any device that stores the status of something at a given time and can operate on input to change the status and/or cause an action or output to take place for any given change. A computer is basically a state machine and each machine instruction is input that changes one or more states and may cause other actions to take place. Each computer's data register stores a state. The read-only memory from which a boot program is loaded stores a state (the boot program itself is an initial state). The operating system is itself a state and each application that runs begins with some initial state that may change as it begins to handle input. Thus, at any moment in time, a computer system can be seen as a very complex set of states and each program in it as a state machine. In practice, however, state machines are used to develop and describe specific device or program interactions.
To summarize it, a state machine can be described as:
* An initial state or record of something stored someplace
* A set of possible input events
* A set of new states that may result from the input
* A set of possible actions or output events that result from a new state
In their book Real-time Object-oriented Modeling, Bran Selic & Garth Gullekson view a state machine as:
* A set of input events
* A set of output events
* A set of states
* A function that maps states and input to output
* A function that maps states and inputs to states (which is called a state transition function)
* A description of the initial state
A finite state machine is one that has a limited or finite number of possible states. (An infinite state machine can be conceived but is not practical.) A finite state machine can be used both as a development tool for approaching and solving problems and as a formal way of describing the solution for later developers and system maintainers. There are a number of ways to show state machines, from simple tables through graphically animated illustrations.
Ãâó: http://whatis.techtarget.com/definition/0,,sid9_gci213052,00.html
//------------------------------------------------------------------------------------
//
// created: 2003-4-16 14:32
//
// filename: compat\compat_fsm.h
//
// author: icedac
//
// purpose: finite state machine template
//
// reference: CUJ, April 2003, Who Moved My State?
// from c-based fsm
//
// history:
//
//------------------------------------------------------------------------------------
//------------------------------------------------------------------------------------------
// tutorial sample,,,
//------------------------------------------------------------------------------------------
//------------------------------------------------------------------------------------------
// sample fsm event
//------------------------------------------------------------------------------------------
// class KeyboardFSMEvent : public compat::FSMEvent
// {
// public:
// char code;
//
// enum
// {
// SHIFT_DEPRESSED_SIG,
// SHIFT_RELEASED_SIG,
// ANY_KEY_SIG,
// };
// };
//
// class KeyboardFSM : public compat::TFSM< KeyboardFSM, KeyboardFSMEvent >
// {
// typedef compat::TFSM TBase;
//
// public:
// KeyboardFSM()
// {
// }
// public:
// LPVOID State_Initial( const KeyboardFSMEvent* e )
// {
// T_LOG( "Keyboard Initialized!\n" );
// Transit( State_Default );
// return 0;
// }
//
// LPVOID State_Default( const KeyboardFSMEvent* e )
// {
// switch ( e->signal )
// {
// case KeyboardFSMEvent::SHIFT_DEPRESSED_SIG:
// {
// T_LOG( "Default::SHIFT_DEPRESSED\n" );
// Transit( State_Shifted );
// }
// break;
// case KeyboardFSMEvent::ANY_KEY_SIG:
// {
// T_LOG( "Default::anykey pressed\n" );
// }
// break;
// }
// return 0;
// }
// LPVOID State_Shifted( const KeyboardFSMEvent* e )
// {
// switch ( e->signal )
// {
// case KeyboardFSMEvent::SHIFT_RELEASED_SIG:
// {
// T_LOG( "Shifted::SHIFT_RELEASED_SIG\n" );
// Transit( State_Shifted );
// }
// break;
// case KeyboardFSMEvent::ANY_KEY_SIG:
// {
// T_LOG( "Shifted::anykey pressed\n" );
// }
// break;
// }
// return 0;
// }
// };
//------------------------------------------------------------------------------------------
// sample FSM test code
//------------------------------------------------------------------------------------------
// KeyboardFSM kfsm;
// kfsm.Init( 0 );
//
// KeyboardFSMEvent ke;
//
//
// ke.signal = KeyboardFSMEvent::SHIFT_DEPRESSED_SIG;
// ke.code = '6';
//
// kfsm.Dispatch( &ke );
//
// ke.signal = KeyboardFSMEvent::SHIFT_RELEASED_SIG;
// ke.code = '3';
//
// kfsm.Dispatch( &ke );
//
// ke.signal = KeyboardFSMEvent::ANY_KEY_SIG;
// ke.code = '9';
//
// kfsm.Dispatch( &ke );
//
//------------------------------------------------------------------------------------------
// output
//------------------------------------------------------------------------------------------
// Keyboard Initialized!
// Default::SHIFT_DEPRESSED
// Shifted::SHIFT_RELEASED_SIG
// Shifted::anykey pressed
//
#ifndef _COMPAT_FSM_H
#define _COMPAT_FSM_H
#include
_BEGIN_NAMESPACE_COMPAT
//------------------------------------------------------------------------------------------
// basic definition
//------------------------------------------------------------------------------------------
class FSM;
typedef int fsm_signal_t;
//------------------------------------------------------------------------------------------
// default event calss
//------------------------------------------------------------------------------------------
class FSMEvent
{
public:
fsm_signal_t signal;
};
//------------------------------------------------------------------------------------------
// FSM template class
//------------------------------------------------------------------------------------------
template < class _Base, class _Event >
class TFSM
{
public:
typedef _Base Base;
typedef _Event Event;
// helper typedef
typedef std::mem_fun1_t< LPVOID, Base, const Event* > FuntorFSMState;
typedef LPVOID (_Base::*FSMState)( const Event* e );
TFSM() : _state(0)
{
// setting inital state
Transit( &_Base::State_Initial );
}
public:
// init method
void Init( const Event* e )
{
// Invoke Initial State
Dispatch( e );
}
// excute current state with Event,
void Dispatch( const Event* e )
{
//this->*_state( e );
_state( static_cast ( this ), e );
}
//
// transit method,
// this will transit one to another
//
void Transit( FSMState _new_state )
{
_state = std::mem_fun1( _new_state );
}
// state sample & initial state;
// virtual inital state, you must ovveride this fisrt
virtual LPVOID State_Initial( const Event* e ) = 0;
protected:
// current state method functor
FuntorFSMState _state;
};
_END_NAMESPACE_COMPAT
#endif//_COMPAT_FSM_H
±Û¾´ÀÌ: icedac | ³¯Â¥: 16:59
| Æ®·¢¹é (0)
Æ®·¢¹é
TrackBack URL :
closed.
closed.






