]> git.sesse.net Git - vlc/blob - modules/gui/skins2/commands/async_queue.cpp
* skins2/src/window_manager.cpp: Added the vlc.isOnTop boolean variable
[vlc] / modules / gui / skins2 / commands / async_queue.cpp
1 /*****************************************************************************
2  * async_queue.cpp
3  *****************************************************************************
4  * Copyright (C) 2003 VideoLAN
5  * $Id$
6  *
7  * Authors: Cyril Deguet     <asmax@via.ecp.fr>
8  *          Olivier Teulière <ipkiss@via.ecp.fr>
9  *
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.
14  *
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.
19  *
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  *****************************************************************************/
24
25 #include "async_queue.hpp"
26 #include "../src/os_factory.hpp"
27 #include "../src/os_timer.hpp"
28
29
30 AsyncQueue::AsyncQueue( intf_thread_t *pIntf ): SkinObject( pIntf )
31 {
32     // Create a timer
33     OSFactory *pOsFactory = OSFactory::instance( pIntf );
34     m_pTimer = pOsFactory->createOSTimer( Callback( this, &doFlush ) );
35
36     // Flush the queue every 10 ms
37     m_pTimer->start( 10, false );
38 }
39
40
41 AsyncQueue::~AsyncQueue()
42 {
43     delete( m_pTimer );
44 }
45
46
47 AsyncQueue *AsyncQueue::instance( intf_thread_t *pIntf )
48 {
49     if( ! pIntf->p_sys->p_queue )
50     {
51         AsyncQueue *pQueue;
52         pQueue = new AsyncQueue( pIntf );
53         if( pQueue )
54         {
55              // Initialization succeeded
56              pIntf->p_sys->p_queue = pQueue;
57         }
58      }
59      return pIntf->p_sys->p_queue;
60 }
61
62
63 void AsyncQueue::destroy( intf_thread_t *pIntf )
64 {
65     if( pIntf->p_sys->p_queue )
66     {
67         delete pIntf->p_sys->p_queue;
68         pIntf->p_sys->p_queue = NULL;
69     }
70 }
71
72
73 void AsyncQueue::push( const CmdGenericPtr &rcCommand )
74 {
75     m_cmdList.push_back( rcCommand );
76 }
77
78
79 void AsyncQueue::remove( const string &rType )
80 {
81     list<CmdGenericPtr>::iterator it;
82     for( it = m_cmdList.begin(); it != m_cmdList.end(); it++ )
83     {
84         // Remove the command if it is of the given type
85         if( (*it).get()->getType() == rType )
86         {
87             list<CmdGenericPtr>::iterator itNew = it;
88             itNew++;
89             m_cmdList.erase( it );
90             it = itNew;
91         }
92     }
93 }
94
95
96 void AsyncQueue::flush()
97 {
98     while( m_cmdList.size() > 0 )
99     {
100         // Execute the first command in the queue
101         CmdGenericPtr &rcCommand = m_cmdList.front();
102         rcCommand.get()->execute();
103         // And remove it
104         m_cmdList.pop_front();
105     }
106 }
107
108
109 void AsyncQueue::doFlush( SkinObject *pObj )
110 {
111     AsyncQueue *pThis = (AsyncQueue*)pObj;
112     // Flush the queue
113     pThis->flush();
114 }