thread: remove vlc_cond_destroy()
[vlc.git] / modules / gui / skins2 / commands / cmd_callbacks.hpp
blobd0433b55baefa183feb3caf8f11c77ca3df3aa3d
1 /*****************************************************************************
2 * cmd_callbacks.hpp
3 *****************************************************************************
4 * Copyright (C) 2009 the VideoLAN team
6 * Author: Erwan Tulou <erwan10 aT videolan doT org >
7 * JP Dinger <jpd (at) videolan (dot) org>
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public License along
20 * with this program; if not, write to the Free Software Foundation, Inc.,
21 * 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
22 *****************************************************************************/
24 #ifndef CMD_CALLBACKS_HPP
25 #define CMD_CALLBACKS_HPP
27 #include "cmd_generic.hpp"
28 #include "../src/vlcproc.hpp"
31 class CmdCallback : public CmdGeneric
33 public:
34 CmdCallback( intf_thread_t *pIntf, vlc_value_t newVal,
35 void (VlcProc::*func)(vlc_value_t),
36 std::string label )
37 : CmdGeneric( pIntf ), m_newVal( newVal ),
38 m_label( label ), m_pfExecute( func )
41 virtual ~CmdCallback()
44 virtual void execute()
46 if( !m_pfExecute )
47 return;
49 (VlcProc::instance( getIntf() )->*m_pfExecute)( m_newVal );
51 virtual std::string getType() const { return m_label; }
53 private:
54 vlc_value_t m_newVal;
55 std::string m_label;
56 void (VlcProc::*m_pfExecute)(vlc_value_t);
59 class CmdExecuteBlock : public CmdGeneric
61 public:
62 CmdExecuteBlock( intf_thread_t* pIntf, vlc_object_t* obj,
63 void (*func) (intf_thread_t*, vlc_object_t* ) )
64 : CmdGeneric( pIntf), m_pObj( obj ), m_pfFunc( func ),
65 m_executing( false )
67 vlc_mutex_init( &m_lock );
68 vlc_cond_init( &m_wait );
71 virtual ~CmdExecuteBlock()
75 static void executeWait( const CmdGenericPtr& rcCommand )
77 CmdExecuteBlock& rCmd = (CmdExecuteBlock&)*rcCommand.get();
78 vlc_mutex_locker locker( &rCmd.m_lock );
80 if( !rCmd.m_pObj || !rCmd.m_pfFunc || rCmd.m_executing )
82 msg_Err( rCmd.getIntf(), "unexpected command call" );
83 return;
86 AsyncQueue *pQueue = AsyncQueue::instance( rCmd.getIntf() );
87 pQueue->push( rcCommand, false );
89 rCmd.m_executing = true;
90 while( rCmd.m_executing )
91 vlc_cond_wait( &rCmd.m_wait, &rCmd.m_lock );
94 virtual void execute()
96 vlc_mutex_locker locker( &m_lock );
98 if( !m_pObj || !m_pfFunc || !m_executing )
100 msg_Err( getIntf(), "unexpected command call" );
101 return;
104 (*m_pfFunc)( getIntf(), m_pObj );
105 m_executing = false;
106 vlc_cond_signal( &m_wait );
109 virtual std::string getType() const { return "CmdExecuteBlock"; }
111 private:
112 vlc_object_t* m_pObj;
113 void (*m_pfFunc)(intf_thread_t*, vlc_object_t*);
114 bool m_executing;
116 vlc_mutex_t m_lock;
117 vlc_cond_t m_wait;
120 #endif