1 /*****************************************************************************
3 *****************************************************************************
4 * Copyright (C) 2003 the VideoLAN team
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 along
21 * with this program; if not, write to the Free Software Foundation, Inc.,
22 * 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
23 *****************************************************************************/
28 #include "../src/skin_common.hpp"
37 /// This class implements a Finite State Machine (FSM)
38 class FSM: public SkinObject
41 FSM( intf_thread_t *pIntf ): SkinObject( pIntf ) { }
44 /// Add a state to the machine
45 void addState( const string &state );
47 /// Add a transition to the machine
48 void addTransition( const string &state1, const string &event,
50 CmdGeneric *pCmd = NULL );
52 /// Retrieve the current state
53 const string &getState() const { return m_currentState; }
55 /// Set the current state, without bothering about transitions
56 void setState( const string &state );
58 /// Find a transition from the current state with the input event,
59 /// change the state, and call the associated callback (if any).
60 void handleTransition( const string &event );
63 /// A Key_t contains the initial state of a transition, and a string
64 /// characterizing an event (for example: "mouse:left:down:ctrl")
65 typedef pair<string, string> Key_t;
67 /// A Data_t contains the final state of a transition, and a callback
68 /// to execute when the transition is applied
69 typedef pair<string, CmdGeneric*> Data_t;
71 /// Current state of the machine
72 string m_currentState;
74 /// Set containing the different states
77 /// Map containing the different transitions between defined types
78 /// It associates a final state (and potentially a callback)
79 /// with a couple of the form: (currentState, triggerEvent)
80 map<Key_t, Data_t> m_transitions;