client/commandQueue.cpp

00001 
00002 /* Copyright (c) 2007-2008, Stefan Eilemann <eile@equalizergraphics.com> 
00003  *
00004  * This library is free software; you can redistribute it and/or modify it under
00005  * the terms of the GNU Lesser General Public License version 2.1 as published
00006  * by the Free Software Foundation.
00007  *  
00008  * This library is distributed in the hope that it will be useful, but WITHOUT
00009  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
00010  * FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public License for more
00011  * details.
00012  * 
00013  * You should have received a copy of the GNU Lesser General Public License
00014  * along with this library; if not, write to the Free Software Foundation, Inc.,
00015  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
00016  */
00017 
00018 #include "commandQueue.h"
00019 
00020 #ifdef GLX
00021 #  include "glXMessagePump.h"
00022 #endif
00023 #ifdef WGL
00024 #  include "wglMessagePump.h"
00025 #endif
00026 #ifdef AGL
00027 #  include "aglMessagePump.h"
00028 #endif
00029 
00030 using namespace std;
00031 
00032 namespace eq
00033 {
00034 CommandQueue::CommandQueue()
00035         : _messagePump( 0 )
00036         , _windowSystem( WINDOW_SYSTEM_NONE )
00037 {
00038 }
00039 
00040 CommandQueue::~CommandQueue()
00041 {
00042     delete _messagePump;
00043     _messagePump = 0;
00044 }
00045 
00046 void CommandQueue::setWindowSystem( const WindowSystem windowSystem )
00047 {
00048     if( _windowSystem == windowSystem )
00049         return;
00050 
00051     EQASSERTINFO( _windowSystem == WINDOW_SYSTEM_NONE, 
00052                   "Can't switch window system from " << _windowSystem << " to "
00053                   << windowSystem );
00054     EQASSERT( !_windowSystem );
00055 
00056     _windowSystem = windowSystem;
00057 
00058     switch( windowSystem )
00059     {
00060 #ifdef GLX
00061         case WINDOW_SYSTEM_GLX:
00062             _messagePump = new GLXMessagePump();
00063             break;
00064 #endif
00065 
00066 #ifdef WGL
00067         case WINDOW_SYSTEM_WGL:
00068             _messagePump = new WGLMessagePump();
00069             break;
00070 #endif
00071 
00072 #ifdef AGL
00073         case WINDOW_SYSTEM_AGL:
00074             _messagePump = new AGLMessagePump();
00075             break;
00076 #endif
00077 
00078         default:
00079             EQUNREACHABLE;
00080     }
00081 }
00082 
00083 void CommandQueue::push(net::Command& inCommand)
00084 {
00085     net::CommandQueue::push(inCommand);
00086     if( _messagePump )
00087         _messagePump->postWakeup();
00088 }
00089 
00090 void CommandQueue::pushFront(net::Command& inCommand)
00091 {
00092     net::CommandQueue::pushFront(inCommand);
00093     if( _messagePump )
00094         _messagePump->postWakeup();
00095 }
00096 
00097 void CommandQueue::wakeup()
00098 {
00099     net::CommandQueue::wakeup();
00100     if( _messagePump )
00101         _messagePump->postWakeup();
00102 }
00103 
00104 net::Command* CommandQueue::pop()
00105 {
00106     while( true )
00107     {
00108         if( _messagePump )
00109             _messagePump->dispatchAll(); // non-blocking
00110 
00111         // Poll for a command
00112         if( !isEmpty( ))
00113             return net::CommandQueue::pop();
00114 
00115         if( _messagePump )
00116             _messagePump->dispatchOne(); // blocking - push will send wakeup
00117         else
00118             return net::CommandQueue::pop();
00119     }
00120 }
00121 
00122 net::Command* CommandQueue::tryPop()
00123 {
00124     if( _messagePump )
00125         _messagePump->dispatchAll(); // non-blocking
00126 
00127     return net::CommandQueue::tryPop();
00128 }
00129 
00130 void CommandQueue::flush()
00131 {
00132     if( _messagePump )
00133         _messagePump->dispatchDone();
00134 
00135     net::CommandQueue::flush();
00136 }
00137 
00138 }
Generated on Mon Aug 10 18:58:31 2009 for Equalizer 0.9 by  doxygen 1.5.8