00001
00002
00003 #include "VisFramework/VisFrameworkBase/interface/VisQueueProcessor.h"
00004 #include "VisFramework/VisFrameworkBase/interface/VisQueue.h"
00005 #include "VisFramework/VisFrameworkBase/interface/debug.h"
00006 #include "Utilities/Threads/interface/Thread.h"
00007 #include <classlib/utils/Signal.h>
00008 #include <classlib/utils/Callback.h>
00009 #include <qapplication.h>
00010
00011
00012
00013
00014
00015
00016
00017
00018 IG_DEFINE_STATE_ELEMENT (VisQueueProcessor,
00019 "Services/Framework/Elements/QueueProcessor");
00020
00021
00022
00023
00024
00026 VisQueueProcessor::VisQueueProcessor (IgState *state)
00027 : m_state (state),
00028 m_done (false),
00029 m_dispatcher (new VisEventDispatcher ())
00030 {
00031 LOG (0, trace, LFfwvis, "VisQueueProcessor::VisQueueProcessor\n");
00032 ASSERT (m_state); m_state->put (s_key, this);
00033 }
00034
00036 VisQueueProcessor::~VisQueueProcessor (void)
00037 { ASSERT (m_state); m_state->detach (s_key); }
00038
00039 VisQueueProcessor::VisEventDispatcher
00040 VisQueueProcessor::eventDispatcher (void)
00041 {
00042 return *m_dispatcher;
00043 }
00044
00046
00090 void
00091 VisQueueProcessor::process (void)
00092 {
00093 LOG (0, trace, LFfwvis, "VisQueueProcessor::process()\n");
00094
00095
00096
00097
00098 lat::Signal::handleFatal("iguana");
00099
00100
00101 qApp->lock ();
00102 QApplication::restoreOverrideCursor ();
00103 qApp->unlock (false);
00104
00105
00106
00107 VisQueue *q = VisQueue::get (m_state);
00108 ASSERT (q);
00109
00110 for (m_done = false; ! m_done; )
00111 {
00112 lat::Callback action (q->pop ());
00113 LOG (0, trace, LFfwvis, "VisQueueProcessor: got action\n");
00114 action ();
00115 }
00116
00117 LOG (0, trace, LFfwvis, "VisQueueProcessor: loop done\n");
00118
00119
00120
00121 qApp->lock ();
00122 QApplication::setOverrideCursor (Qt::waitCursor);
00123 qApp->unlock (false);
00124
00125 LOG (0, trace, LFfwvis, "VisQueueProcessor::process() done\n");
00126 }
00127
00129
00133 void
00134 VisQueueProcessor::scheduleAbort (void)
00135 {
00136 ASSERT (VisQueue::get (m_state));
00137 VisQueue::get (m_state)
00138 ->push (lat::CreateCallback (this, &VisQueueProcessor::doAbort));
00139 }
00140
00146 void
00147 VisQueueProcessor::scheduleNextEvent (void)
00148 {
00149 LOG (0, trace, LFfwvis, "VisQueueProcessor::scheduleNextEvent()\n");
00150
00151 ASSERT (VisQueue::get (m_state));
00152 VisQueue::get (m_state)
00153 ->push (lat::CreateCallback (this, &VisQueueProcessor::doNextEvent));
00154
00155 LOG (0, trace, LFfwvis, "VisQueueProcessor::scheduleNextEvent() done\n");
00156 }
00157
00159
00160 void
00161 VisQueueProcessor::doAbort (void)
00162 {
00163
00164 }
00165
00168 void
00169 VisQueueProcessor::doNextEvent (void)
00170 {
00171 LOG (0, trace, LFfwvis, "VisQueueProcessor::doNextEvent()\n");
00172
00173 VisEventMessage event;
00174
00175 eventDispatcher ().broadcast (event);
00176 m_done = true;
00177
00178 LOG (0, trace, LFfwvis, "VisQueueProcessor::doNextEvent() done\n");
00179 }