1 /*****************************************************************************
3 *****************************************************************************
4 * Copyright (C) 2003 VideoLAN
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 *****************************************************************************/
25 #include "async_queue.hpp"
26 #include "../src/os_factory.hpp"
27 #include "../src/os_timer.hpp"
30 AsyncQueue::AsyncQueue( intf_thread_t *pIntf ): SkinObject( pIntf )
33 OSFactory *pOsFactory = OSFactory::instance( pIntf );
34 m_pTimer = pOsFactory->createOSTimer( Callback( this, &doFlush ) );
36 // Flush the queue every 10 ms
37 m_pTimer->start( 10, false );
41 AsyncQueue::~AsyncQueue()
47 AsyncQueue *AsyncQueue::instance( intf_thread_t *pIntf )
49 if( ! pIntf->p_sys->p_queue )
52 pQueue = new AsyncQueue( pIntf );
55 // Initialization succeeded
56 pIntf->p_sys->p_queue = pQueue;
59 return pIntf->p_sys->p_queue;
63 void AsyncQueue::destroy( intf_thread_t *pIntf )
65 if( pIntf->p_sys->p_queue )
67 delete pIntf->p_sys->p_queue;
68 pIntf->p_sys->p_queue = NULL;
73 void AsyncQueue::push( const CmdGenericPtr &rcCommand )
75 m_cmdList.push_back( rcCommand );
79 void AsyncQueue::remove( const string &rType )
81 list<CmdGenericPtr>::iterator it;
82 for( it = m_cmdList.begin(); it != m_cmdList.end(); it++ )
84 // Remove the command if it is of the given type
85 if( (*it).get()->getType() == rType )
87 list<CmdGenericPtr>::iterator itNew = it;
89 m_cmdList.erase( it );
96 void AsyncQueue::flush()
98 while( m_cmdList.size() > 0 )
100 // Execute the first command in the queue
101 CmdGenericPtr &rcCommand = m_cmdList.front();
102 rcCommand.get()->execute();
104 m_cmdList.pop_front();
109 void AsyncQueue::doFlush( SkinObject *pObj )
111 AsyncQueue *pThis = (AsyncQueue*)pObj;