]> git.saurik.com Git - wxWidgets.git/commitdiff
Implement monitoring of file descriptors in wxMotif event loop.
authorVadim Zeitlin <vadim@wxwidgets.org>
Wed, 10 Jul 2013 23:43:57 +0000 (23:43 +0000)
committerVadim Zeitlin <vadim@wxwidgets.org>
Wed, 10 Jul 2013 23:43:57 +0000 (23:43 +0000)
This allows applications using wxMotif to link again after the changes of
r74350 -- and wxExecute() unit tests actually pass, too.

Closes #15305.

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@74480 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775

src/motif/utils.cpp

index fc826976f85199a275eb08ded624e1f4640b3fa9..f85e9979449f87e884888f03b9f05814649f8f2e 100644 (file)
@@ -30,6 +30,7 @@
 
 #include "wx/apptrait.h"
 #include "wx/evtloop.h"
 
 #include "wx/apptrait.h"
 #include "wx/evtloop.h"
+#include "wx/private/eventloopsourcesmanager.h"
 #include "wx/motif/private/timer.h"
 
 #include <string.h>
 #include "wx/motif/private/timer.h"
 
 #include <string.h>
@@ -77,6 +78,94 @@ void wxFlushEvents(WXDisplay* wxdisplay)
     }
 }
 
     }
 }
 
+#if wxUSE_EVENTLOOP_SOURCE
+
+extern "C"
+{
+
+static
+void
+wxMotifInputHandler(XtPointer data,
+                    int* WXUNUSED(fd),
+                    XtInputId* WXUNUSED(inputId))
+{
+    wxEventLoopSourceHandler * const
+        handler = static_cast<wxEventLoopSourceHandler *>(data);
+
+    handler->OnReadWaiting();
+}
+
+}
+
+// This class exists just to call XtRemoveInput() in its dtor, the real work of
+// dispatching events on the file descriptor to the handler is done by
+// wxMotifInputHandler callback above.
+class wxMotifEventLoopSource : public wxEventLoopSource
+{
+public:
+    wxMotifEventLoopSource(XtInputId inputId,
+                           wxEventLoopSourceHandler *handler,
+                           int flags)
+        : wxEventLoopSource(handler, flags),
+          m_inputId(inputId)
+    {
+    }
+
+    virtual ~wxMotifEventLoopSource()
+    {
+        XtRemoveInput(m_inputId);
+    }
+
+private:
+    const XtInputId m_inputId;
+
+    wxDECLARE_NO_COPY_CLASS(wxMotifEventLoopSource);
+};
+
+class wxMotifEventLoopSourcesManager : public wxEventLoopSourcesManagerBase
+{
+public:
+    wxEventLoopSource *
+    AddSourceForFD(int fd, wxEventLoopSourceHandler* handler, int flags)
+    {
+        wxCHECK_MSG( wxTheApp, NULL, "Must create wxTheApp first" );
+
+        // The XtInputXXXMask values cannot be combined (hence "Mask" is a
+        // complete misnomer), and supporting those would make the code more
+        // complicated and we don't need them for now.
+        wxCHECK_MSG( !(flags & (wxEVENT_SOURCE_OUTPUT |
+                                wxEVENT_SOURCE_EXCEPTION)),
+                     NULL,
+                     "Monitoring FDs for output/errors not supported" );
+
+        wxCHECK_MSG( flags & wxEVENT_SOURCE_INPUT,
+                     NULL,
+                     "Should be monitoring for input" );
+
+        XtInputId inputId = XtAppAddInput
+                            (
+                                 (XtAppContext) wxTheApp->GetAppContext(),
+                                 fd,
+                                 (XtPointer) XtInputReadMask,
+                                 wxMotifInputHandler,
+                                 handler
+                            );
+        if ( inputId < 0 )
+            return 0;
+
+        return new wxMotifEventLoopSource(inputId, handler, flags);
+    }
+};
+
+wxEventLoopSourcesManagerBase* wxGUIAppTraits::GetEventLoopSourcesManager()
+{
+    static wxMotifEventLoopSourcesManager s_eventLoopSourcesManager;
+
+    return &s_eventLoopSourcesManager;
+}
+
+#endif // wxUSE_EVENTLOOP_SOURCE
+
 // ----------------------------------------------------------------------------
 // misc
 // ----------------------------------------------------------------------------
 // ----------------------------------------------------------------------------
 // misc
 // ----------------------------------------------------------------------------