00001
00002
00003
00004
00005 #include "commandQueue.h"
00006
00007 #ifdef GLX
00008 # include "glXMessagePump.h"
00009 #endif
00010 #ifdef WGL
00011 # include "wglMessagePump.h"
00012 #endif
00013 #ifdef AGL
00014 # include "aglMessagePump.h"
00015 #endif
00016
00017 using namespace std;
00018
00019 namespace eq
00020 {
00021 CommandQueue::CommandQueue()
00022 : _messagePump( 0 )
00023 , _windowSystem( WINDOW_SYSTEM_NONE )
00024 {
00025 }
00026
00027 CommandQueue::~CommandQueue()
00028 {
00029 delete _messagePump;
00030 _messagePump = 0;
00031 }
00032
00033 void CommandQueue::setWindowSystem( const WindowSystem windowSystem )
00034 {
00035 if( _windowSystem == windowSystem )
00036 return;
00037
00038 EQASSERTINFO( _windowSystem == WINDOW_SYSTEM_NONE,
00039 "Can't switch window system from " << _windowSystem << " to "
00040 << windowSystem );
00041 EQASSERT( !_windowSystem );
00042
00043 _windowSystem = windowSystem;
00044
00045 switch( windowSystem )
00046 {
00047 #ifdef GLX
00048 case WINDOW_SYSTEM_GLX:
00049 _messagePump = new GLXMessagePump();
00050 break;
00051 #endif
00052
00053 #ifdef WGL
00054 case WINDOW_SYSTEM_WGL:
00055 _messagePump = new WGLMessagePump();
00056 break;
00057 #endif
00058
00059 #ifdef AGL
00060 case WINDOW_SYSTEM_AGL:
00061 _messagePump = new AGLMessagePump();
00062 break;
00063 #endif
00064
00065 default:
00066 EQUNREACHABLE;
00067 }
00068 }
00069
00070 void CommandQueue::push(net::Command& inCommand)
00071 {
00072 net::CommandQueue::push(inCommand);
00073 if( _messagePump )
00074 _messagePump->postWakeup();
00075 }
00076
00077 void CommandQueue::pushFront(net::Command& inCommand)
00078 {
00079 net::CommandQueue::pushFront(inCommand);
00080 if( _messagePump )
00081 _messagePump->postWakeup();
00082 }
00083
00084 void CommandQueue::wakeup()
00085 {
00086 net::CommandQueue::wakeup();
00087 if( _messagePump )
00088 _messagePump->postWakeup();
00089 }
00090
00091 net::Command* CommandQueue::pop()
00092 {
00093 while( true )
00094 {
00095 if( _messagePump )
00096 _messagePump->dispatchAll();
00097
00098
00099 if( !empty( ))
00100 return net::CommandQueue::pop();
00101
00102 if( _messagePump )
00103 _messagePump->dispatchOne();
00104 else
00105 return net::CommandQueue::pop();
00106 }
00107 }
00108
00109 net::Command* CommandQueue::tryPop()
00110 {
00111 if( _messagePump )
00112 _messagePump->dispatchAll();
00113
00114 return net::CommandQueue::tryPop();
00115 }
00116
00117 void CommandQueue::flush()
00118 {
00119 if( _messagePump )
00120 _messagePump->dispatchDone();
00121
00122 net::CommandQueue::flush();
00123 }
00124
00125 }