1 /*****************************************************************************
3 *****************************************************************************
4 * Copyright (C) 2003 VideoLAN
5 * $Id: fsm.hpp,v 1.1 2004/01/03 23:31:34 asmax Exp $
7 * Authors: Cyril Deguet <asmax@via.ecp.fr>
8 * Olivier Teulière <ipkiss@via.ecp.fr>
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
20 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, write to the Free Software
22 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111, USA.
23 *****************************************************************************/
28 #include "../src/skin_common.hpp"
36 /// This class implements a Finite State Machine (FSM)
37 class FSM: public SkinObject
40 FSM( intf_thread_t *pIntf ): SkinObject( pIntf ) {}
43 /// Add a state to the machine
44 void addState( const string &state );
46 /// Add a transition to the machine
47 void addTransition( const string &state1, const string &event,
49 Callback *pCmd = NULL );
51 /// Retrieve the current state
52 const string &getState() const { return m_currentState; }
54 /// Set the current state, without bothering about transitions
55 void setState( const string &state );
57 /// Find a transition from the current state with the input event,
58 /// change the state, and call the associated callback (if any).
59 void handleTransition( const string &event );
62 /// A Key_t contains the initial state of a transition, and a string
63 /// characterizing an event (for example: "mouse:left:down:ctrl")
64 typedef pair<string, string> Key_t;
66 /// A Data_t contains the final state of a transition, and a callback
67 /// to execute when the transition is applied
68 typedef pair<string, Callback*> Data_t;
70 /// Current state of the machine
71 string m_currentState;
73 /// Set containing the different states
76 /// Map containing the different transitions between defined types
77 /// It associates a final state (and potentially a callback)
78 /// with a couple of the form: (currentState, triggerEvent)
79 map<Key_t, Data_t> m_transitions;