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"
29 #include "wx/generic/private/timer.h"
30 #include "wx/private/fdiodispatcher.h"
31 #include "wx/dfb/private.h"
32 #include "wx/nonownedwnd.h"
34 #define TRACE_EVENTS "events"
36 // ===========================================================================
38 // ===========================================================================
40 //-----------------------------------------------------------------------------
41 // wxEventLoop initialization
42 //-----------------------------------------------------------------------------
44 wxIDirectFBEventBufferPtr
wxGUIEventLoop::ms_buffer
;
46 wxGUIEventLoop::wxGUIEventLoop()
53 void wxGUIEventLoop::InitBuffer()
55 ms_buffer
= wxIDirectFB::Get()->CreateEventBuffer();
59 void wxGUIEventLoop::CleanUp()
65 wxIDirectFBEventBufferPtr
wxGUIEventLoop::GetDirectFBEventBuffer()
73 //-----------------------------------------------------------------------------
74 // events dispatch and loop handling
75 //-----------------------------------------------------------------------------
77 bool wxGUIEventLoop::Pending() const
79 wxCHECK_MSG( ms_buffer
, false, "invalid event buffer" );
81 return ms_buffer
->HasEvent();
84 bool wxGUIEventLoop::Dispatch()
86 // NB: we don't block indefinitely waiting for an event, but instead
87 // time out after a brief period in order to make sure that
88 // OnNextIteration() will be called frequently enough
90 // TODO: remove this hack, instead use CreateFileDescriptor() to properly
91 // multiplex GUI and socket input
92 const int TIMEOUT
= 100;
94 // treat time out (-1 return value) as normal successful return so that
95 // OnNextIteration() is called
96 return !!DispatchTimeout(TIMEOUT
);
99 int wxGUIEventLoop::DispatchTimeout(unsigned long timeout
)
101 wxCHECK_MSG( ms_buffer
, 0, "invalid event buffer" );
103 // release the GUI mutex so that other threads have a chance to post
107 bool rv
= ms_buffer
->WaitForEventWithTimeout(0, timeout
);
109 // and acquire it back before calling any event handlers:
114 switch ( ms_buffer
->GetLastResult() )
119 ms_buffer
->GetEvent(e
);
128 // don't terminate the loop due to errors (they were reported
129 // already by ms_buffer)
137 void wxGUIEventLoop::WakeUp()
139 wxCHECK_RET( ms_buffer
, "invalid event buffer" );
144 void wxGUIEventLoop::OnNextIteration()
147 wxGenericTimerImpl::NotifyTimers();
151 // handle any pending socket events:
152 wxFDIODispatcher::DispatchPending();
156 void wxGUIEventLoop::Yield()
158 // process all pending events:
162 // handle timers, sockets etc.
167 //-----------------------------------------------------------------------------
168 // DirectFB -> wxWidgets events translation
169 //-----------------------------------------------------------------------------
171 void wxGUIEventLoop::HandleDFBEvent(const wxDFBEvent
& event
)
173 switch ( event
.GetClass() )
177 wxDFBWindowEvent
winevent(((const DFBEvent
&)event
).window
);
178 wxNonOwnedWindow::HandleDFBWindowEvent(winevent
);
185 #if wxCHECK_DFB_VERSION(0,9,23)
189 wxLogTrace(TRACE_EVENTS
,
190 "ignoring event of unsupported class %i",
191 (int)event
.GetClass());