X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/b3c861501a451503b31c075ccb59d16b0ae01e99..0d19936d71032ba7658616faed3b63d4c930e5b4:/src/dfb/evtloop.cpp diff --git a/src/dfb/evtloop.cpp b/src/dfb/evtloop.cpp index fcfeb0b25c..7f7807ac72 100644 --- a/src/dfb/evtloop.cpp +++ b/src/dfb/evtloop.cpp @@ -25,10 +25,13 @@ #include "wx/app.h" #endif -#include "wx/timer.h" +#include "wx/thread.h" +#include "wx/generic/private/timer.h" +#include "wx/private/fdiodispatcher.h" #include "wx/dfb/private.h" +#include "wx/nonownedwnd.h" -#define TRACE_EVENTS _T("events") +#define TRACE_EVENTS "events" // =========================================================================== // implementation @@ -38,23 +41,28 @@ // wxEventLoop initialization //----------------------------------------------------------------------------- -IDirectFBEventBufferPtr wxEventLoop::ms_buffer; +wxIDirectFBEventBufferPtr wxGUIEventLoop::ms_buffer; -wxEventLoop::wxEventLoop() +wxGUIEventLoop::wxGUIEventLoop() { if ( !ms_buffer ) InitBuffer(); } /* static */ -void wxEventLoop::InitBuffer() +void wxGUIEventLoop::InitBuffer() { - IDirectFBPtr dfb(wxTheApp->GetDirectFBInterface()); - DFB_CALL( dfb->CreateEventBuffer(dfb, &ms_buffer) ); + ms_buffer = wxIDirectFB::Get()->CreateEventBuffer(); } /* static */ -IDirectFBEventBufferPtr wxEventLoop::GetDirectFBEventBuffer() +void wxGUIEventLoop::CleanUp() +{ + ms_buffer.Reset(); +} + +/* static */ +wxIDirectFBEventBufferPtr wxGUIEventLoop::GetDirectFBEventBuffer() { if ( !ms_buffer ) InitBuffer(); @@ -66,91 +74,120 @@ IDirectFBEventBufferPtr wxEventLoop::GetDirectFBEventBuffer() // events dispatch and loop handling //----------------------------------------------------------------------------- -bool wxEventLoop::Pending() const +bool wxGUIEventLoop::Pending() const { - wxCHECK_MSG( ms_buffer, false, _T("invalid event buffer") ); + wxCHECK_MSG( ms_buffer, false, "invalid event buffer" ); - // returns DFB_OK if there is >=1 event, DFB_BUFFER_EMPTY otherwise - return ms_buffer->HasEvent(ms_buffer) == DFB_OK; + return ms_buffer->HasEvent(); } -bool wxEventLoop::Dispatch() +bool wxGUIEventLoop::Dispatch() { - wxCHECK_MSG( ms_buffer, false, _T("invalid event buffer") ); - // NB: we don't block indefinitely waiting for an event, but instead // time out after a brief period in order to make sure that // OnNextIteration() will be called frequently enough // - // FIXME: call NotifyTimers() from here (and loop) instead? + // TODO: remove this hack, instead use CreateFileDescriptor() to properly + // multiplex GUI and socket input const int TIMEOUT = 100; - DFBResult ret = ms_buffer->WaitForEventWithTimeout(ms_buffer, 0, TIMEOUT); + // treat time out (-1 return value) as normal successful return so that + // OnNextIteration() is called + return !!DispatchTimeout(TIMEOUT); +} + +int wxGUIEventLoop::DispatchTimeout(unsigned long timeout) +{ + wxCHECK_MSG( ms_buffer, 0, "invalid event buffer" ); + + // release the GUI mutex so that other threads have a chance to post + // events: + wxMutexGuiLeave(); + + bool rv = ms_buffer->WaitForEventWithTimeout(0, timeout); + + // and acquire it back before calling any event handlers: + wxMutexGuiEnter(); - switch ( ret ) + if ( rv ) { - case DFB_OK: + switch ( ms_buffer->GetLastResult() ) { - wxDFBEvent e; - ms_buffer->GetEvent(ms_buffer, &e); - HandleDFBEvent(e); - break; + case DFB_OK: + { + wxDFBEvent e; + ms_buffer->GetEvent(e); + HandleDFBEvent(e); + break; + } + + case DFB_TIMEOUT: + return -1; + + default: + // don't terminate the loop due to errors (they were reported + // already by ms_buffer) + break; } - - case DFB_TIMEOUT: - // timed out, pretend we processed an event so that OnNextIteration - // is called - break; - - default: - // report any errors, but don't terminate the loop due to them - wxDfbCheckReturn(ret); - break; } - return true; + return 1; } -void wxEventLoop::WakeUp() +void wxGUIEventLoop::WakeUp() { - wxCHECK_RET( ms_buffer, _T("invalid event buffer") ); + wxCHECK_RET( ms_buffer, "invalid event buffer" ); - DFB_CALL( ms_buffer->WakeUp(ms_buffer) ); + ms_buffer->WakeUp(); } -void wxEventLoop::OnNextIteration() +void wxGUIEventLoop::OnNextIteration() { #if wxUSE_TIMER - // see the comment in Dispatch - wxTimer::NotifyTimers(); + wxGenericTimerImpl::NotifyTimers(); +#endif + +#if wxUSE_SOCKETS + // handle any pending socket events: + wxFDIODispatcher::DispatchPending(); #endif } -#warning "FIXME: cleanup wxEventLoop::ms_buffer before exiting" +void wxGUIEventLoop::Yield() +{ + // process all pending events: + while ( Pending() ) + Dispatch(); + + // handle timers, sockets etc. + OnNextIteration(); +} //----------------------------------------------------------------------------- // DirectFB -> wxWidgets events translation //----------------------------------------------------------------------------- -void wxEventLoop::HandleDFBEvent(const wxDFBEvent& event) +void wxGUIEventLoop::HandleDFBEvent(const wxDFBEvent& event) { switch ( event.GetClass() ) { case DFEC_WINDOW: { wxDFBWindowEvent winevent(((const DFBEvent&)event).window); - wxTopLevelWindowDFB::HandleDFBWindowEvent(winevent); + wxNonOwnedWindow::HandleDFBWindowEvent(winevent); break; } case DFEC_NONE: case DFEC_INPUT: case DFEC_USER: +#if wxCHECK_DFB_VERSION(0,9,23) case DFEC_UNIVERSAL: +#endif { wxLogTrace(TRACE_EVENTS, - _T("ignoring event of unsupported class %i"), + "ignoring event of unsupported class %i", (int)event.GetClass()); } }