1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/dfb/evtloop.cpp
3 // Purpose: wxEventLoop implementation
4 // Author: Vaclav Slavik
7 // Copyright: (c) 2006 REA Elektronik GmbH
8 // Licence: wxWindows licence
9 /////////////////////////////////////////////////////////////////////////////
11 // ===========================================================================
13 // ===========================================================================
15 // ---------------------------------------------------------------------------
17 // ---------------------------------------------------------------------------
19 // For compilers that support precompilation, includes "wx.h".
20 #include "wx/wxprec.h"
22 #include "wx/evtloop.h"
28 #include "wx/thread.h"
30 #include "wx/private/socketevtdispatch.h"
31 #include "wx/dfb/private.h"
33 #define TRACE_EVENTS _T("events")
35 // ===========================================================================
37 // ===========================================================================
39 //-----------------------------------------------------------------------------
40 // wxEventLoop initialization
41 //-----------------------------------------------------------------------------
43 wxIDirectFBEventBufferPtr
wxEventLoop::ms_buffer
;
45 wxEventLoop::wxEventLoop()
52 void wxEventLoop::InitBuffer()
54 ms_buffer
= wxIDirectFB::Get()->CreateEventBuffer();
58 void wxEventLoop::CleanUp()
64 wxIDirectFBEventBufferPtr
wxEventLoop::GetDirectFBEventBuffer()
72 //-----------------------------------------------------------------------------
73 // events dispatch and loop handling
74 //-----------------------------------------------------------------------------
76 bool wxEventLoop::Pending() const
78 wxCHECK_MSG( ms_buffer
, false, _T("invalid event buffer") );
80 return ms_buffer
->HasEvent();
83 bool wxEventLoop::Dispatch()
85 wxCHECK_MSG( ms_buffer
, false, _T("invalid event buffer") );
87 // NB: we don't block indefinitely waiting for an event, but instead
88 // time out after a brief period in order to make sure that
89 // OnNextIteration() will be called frequently enough
90 const int TIMEOUT
= 100;
92 // release the GUI mutex so that other threads have a chance to post
96 bool rv
= ms_buffer
->WaitForEventWithTimeout(0, TIMEOUT
);
98 // and acquire it back before calling any event handlers:
103 switch ( ms_buffer
->GetLastResult() )
108 ms_buffer
->GetEvent(e
);
114 // timed out, pretend we processed an event so that
115 // OnNextIteration is called
119 // don't terminate the loop due to errors (they were reported
120 // already by ms_buffer)
128 void wxEventLoop::WakeUp()
130 wxCHECK_RET( ms_buffer
, _T("invalid event buffer") );
135 void wxEventLoop::OnNextIteration()
138 wxTimer::NotifyTimers();
142 // handle any pending socket events:
143 wxSocketEventDispatcher::Get().RunLoop();
147 void wxEventLoop::Yield()
149 // process all pending events:
153 // handle timers, sockets etc.
158 //-----------------------------------------------------------------------------
159 // DirectFB -> wxWidgets events translation
160 //-----------------------------------------------------------------------------
162 void wxEventLoop::HandleDFBEvent(const wxDFBEvent
& event
)
164 switch ( event
.GetClass() )
168 wxDFBWindowEvent
winevent(((const DFBEvent
&)event
).window
);
169 wxTopLevelWindowDFB::HandleDFBWindowEvent(winevent
);
176 #if wxCHECK_DFB_VERSION(0,9,23)
180 wxLogTrace(TRACE_EVENTS
,
181 _T("ignoring event of unsupported class %i"),
182 (int)event
.GetClass());