1 /*****************************************************************************
3 *****************************************************************************
4 * Copyright (C) 2009 the VideoLAN team
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
35 CmdCallback( intf_thread_t
*pIntf
, vlc_object_t
*pObj
, vlc_value_t newVal
,
36 void (VlcProc::*func
)(vlc_object_t
*,vlc_value_t
),
38 : CmdGeneric( pIntf
), m_pObj( pObj
), m_newVal( newVal
),
39 m_label( label
), m_pfExecute( func
)
42 vlc_object_hold( m_pObj
);
44 virtual ~CmdCallback()
47 vlc_object_release( m_pObj
);
49 virtual void execute()
51 if( !m_pObj
|| !m_pfExecute
)
54 (VlcProc::instance( getIntf() )->*m_pfExecute
)( m_pObj
, m_newVal
);
56 vlc_object_release( m_pObj
);
59 virtual string
getType() const { return m_label
; }
65 void (VlcProc::*m_pfExecute
)(vlc_object_t
*,vlc_value_t
);
69 class CmdExecuteBlock
: public CmdGeneric
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
),
77 vlc_mutex_init( &m_lock
);
78 vlc_cond_init( &m_wait
);
80 vlc_object_hold( m_pObj
);
83 virtual ~CmdExecuteBlock()
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" );
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" );
120 (*m_pfFunc
)( getIntf(), m_pObj
);
122 vlc_cond_signal( &m_wait
);
125 virtual string
getType() const { return "CmdExecuteBlock"; }
128 vlc_object_t
* m_pObj
;
129 void (*m_pfFunc
)(intf_thread_t
*, vlc_object_t
*);