skins2: remove all hardcoded hotkeys
[vlc.git] / modules / gui / skins2 / commands / cmd_callbacks.hpp
blobe3f3cfb0395c9dbbe3b1e509ad83d47951202d1d
1 /*****************************************************************************
2 * cmd_callbacks.hpp
3 *****************************************************************************
4 * Copyright (C) 2009 the VideoLAN team
5 * $Id$
7 * Author: Erwan Tulou <erwan10 aT videolan doT org >
8 * JP Dinger <jpd (at) videolan (dot) org>
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 *****************************************************************************/
25 #ifndef CMD_CALLBACKS_HPP
26 #define CMD_CALLBACKS_HPP
28 #include "cmd_generic.hpp"
29 #include "../src/vlcproc.hpp"
32 class CmdCallback : public CmdGeneric
34 public:
35 CmdCallback( intf_thread_t *pIntf, vlc_object_t *pObj, vlc_value_t newVal,
36 void (VlcProc::*func)(vlc_object_t *,vlc_value_t),
37 string label )
38 : CmdGeneric( pIntf ), m_pObj( pObj ), m_newVal( newVal ),
39 m_label( label ), m_pfExecute( func )
41 if( m_pObj )
42 vlc_object_hold( m_pObj );
44 virtual ~CmdCallback()
46 if( m_pObj )
47 vlc_object_release( m_pObj );
49 virtual void execute()
51 if( !m_pObj || !m_pfExecute )
52 return;
54 (VlcProc::instance( getIntf() )->*m_pfExecute)( m_pObj, m_newVal );
56 vlc_object_release( m_pObj );
57 m_pObj = NULL;
59 virtual string getType() const { return m_label; }
61 private:
62 vlc_object_t* m_pObj;
63 vlc_value_t m_newVal;
64 string m_label;
65 void (VlcProc::*m_pfExecute)(vlc_object_t *,vlc_value_t);
69 class CmdExecuteBlock : public CmdGeneric
71 public:
72 CmdExecuteBlock( intf_thread_t* pIntf, vlc_object_t* obj,
73 void (*func) (intf_thread_t*, vlc_object_t* ) )
74 : CmdGeneric( pIntf), m_pObj( obj ), m_pfFunc( func ),
75 m_executing( false )
77 vlc_mutex_init( &m_lock );
78 vlc_cond_init( &m_wait );
79 if( m_pObj )
80 vlc_object_hold( m_pObj );
83 virtual ~CmdExecuteBlock()
85 if( m_pObj )
86 vlc_object_release( m_pObj );
87 vlc_cond_destroy( &m_wait );
88 vlc_mutex_destroy( &m_lock );
91 static void executeWait( const CmdGenericPtr& rcCommand )
93 CmdExecuteBlock& rCmd = (CmdExecuteBlock&)*rcCommand.get();
94 vlc_mutex_locker locker( &rCmd.m_lock );
96 if( !rCmd.m_pObj || !rCmd.m_pfFunc || rCmd.m_executing )
98 msg_Err( rCmd.getIntf(), "unexpected command call" );
99 return;
102 AsyncQueue *pQueue = AsyncQueue::instance( rCmd.getIntf() );
103 pQueue->push( rcCommand, false );
105 rCmd.m_executing = true;
106 while( rCmd.m_executing )
107 vlc_cond_wait( &rCmd.m_wait, &rCmd.m_lock );
110 virtual void execute()
112 vlc_mutex_locker locker( &m_lock );
114 if( !m_pObj || !m_pfFunc || !m_executing )
116 msg_Err( getIntf(), "unexpected command call" );
117 return;
120 (*m_pfFunc)( getIntf(), m_pObj );
121 m_executing = false;
122 vlc_cond_signal( &m_wait );
125 virtual string getType() const { return "CmdExecuteBlock"; }
127 private:
128 vlc_object_t* m_pObj;
129 void (*m_pfFunc)(intf_thread_t*, vlc_object_t*);
130 bool m_executing;
132 vlc_mutex_t m_lock;
133 vlc_cond_t m_wait;
137 #endif