fsm.hpp

Go to the documentation of this file.
00001 /*****************************************************************************
00002  * fsm.hpp
00003  *****************************************************************************
00004  * Copyright (C) 2003 the VideoLAN team
00005  * $Id$
00006  *
00007  * Authors: Cyril Deguet     <asmax@via.ecp.fr>
00008  *          Olivier Teulière <ipkiss@via.ecp.fr>
00009  *
00010  * This program is free software; you can redistribute it and/or modify
00011  * it under the terms of the GNU General Public License as published by
00012  * the Free Software Foundation; either version 2 of the License, or
00013  * (at your option) any later version.
00014  *
00015  * This program is distributed in the hope that it will be useful,
00016  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00017  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00018  * GNU General Public License for more details.
00019  *
00020  * You should have received a copy of the GNU General Public License
00021  * along with this program; if not, write to the Free Software
00022  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
00023  *****************************************************************************/
00024 
00025 #ifndef FSM_HPP
00026 #define FSM_HPP
00027 
00028 #include "../src/skin_common.hpp"
00029 #include <string>
00030 #include <map>
00031 #include <set>
00032 
00033 class EvtGeneric;
00034 class CmdGeneric;
00035 
00036 
00037 /// This class implements a Finite State Machine (FSM)
00038 class FSM: public SkinObject
00039 {
00040     public:
00041         FSM( intf_thread_t *pIntf ): SkinObject( pIntf ) {}
00042         virtual ~FSM() {}
00043 
00044         /// Add a state to the machine
00045         void addState( const string &state );
00046 
00047         /// Add a transition to the machine
00048         void addTransition( const string &state1, const string &event,
00049                             const string &state2,
00050                             CmdGeneric *pCmd = NULL );
00051 
00052         /// Retrieve the current state
00053         const string &getState() const { return m_currentState; }
00054 
00055         /// Set the current state, without bothering about transitions
00056         void setState( const string &state );
00057 
00058         /// Find a transition from the current state with the input event,
00059         /// change the state, and call the associated callback (if any).
00060         void handleTransition( const string &event );
00061 
00062     private:
00063         /// A Key_t contains the initial state of a transition, and a string
00064         /// characterizing an event (for example: "mouse:left:down:ctrl")
00065         typedef pair<string, string> Key_t;
00066 
00067         /// A Data_t contains the final state of a transition, and a callback
00068         /// to execute when the transition is applied
00069         typedef pair<string, CmdGeneric*> Data_t;
00070 
00071         /// Current state of the machine
00072         string m_currentState;
00073 
00074         /// Set containing the different states
00075         set<string> m_states;
00076 
00077         /// Map containing the different transitions between defined types
00078         /// It associates a final state (and potentially a callback)
00079         /// with a couple of the form: (currentState, triggerEvent)
00080         map<Key_t, Data_t> m_transitions;
00081 };
00082 
00083 
00084 #endif

Generated on Wed Aug 13 08:02:38 2008 for VLC by  doxygen 1.5.1