Make wxEventLoop::AddSourceForFD() static.
Any event sources should be registered with all the event loops, including the ones that will be started in the future, and not only the current (and potentially not even existing yet) one. So make AddSourceForFD() method static. To still allow it to do different things in console and GUI applications, as it must, virtualize it via the new wxEventLoopSourcesManager class which has different implementations in the two cases, returned via wxAppTraits as usual. Notice that this required moving the implementation of this method from src/osx/core/evtloop_cf.cpp to src/osx/core/utilsexc_cf.cpp as the former file is base-only and didn't have access to wxGUIAppTraits. See #10258. git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@74341 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
@@ -32,6 +32,9 @@
|
||||
#include "wx/log.h"
|
||||
#endif // WX_PRECOMP
|
||||
|
||||
#include "wx/private/eventloopsourcesmanager.h"
|
||||
#include "wx/apptrait.h"
|
||||
|
||||
#include <gtk/gtk.h>
|
||||
#include <glib.h>
|
||||
|
||||
@@ -133,41 +136,50 @@ static gboolean wx_on_channel_event(GIOChannel *channel,
|
||||
}
|
||||
}
|
||||
|
||||
wxEventLoopSource *
|
||||
wxGUIEventLoop::AddSourceForFD(int fd,
|
||||
wxEventLoopSourceHandler *handler,
|
||||
int flags)
|
||||
class wxGUIEventLoopSourcesManager : public wxEventLoopSourcesManagerBase
|
||||
{
|
||||
wxCHECK_MSG( fd != -1, NULL, "can't monitor invalid fd" );
|
||||
public:
|
||||
virtual wxEventLoopSource*
|
||||
AddSourceForFD(int fd, wxEventLoopSourceHandler *handler, int flags)
|
||||
{
|
||||
wxCHECK_MSG( fd != -1, NULL, "can't monitor invalid fd" );
|
||||
|
||||
int condition = 0;
|
||||
if (flags & wxEVENT_SOURCE_INPUT)
|
||||
condition |= G_IO_IN | G_IO_PRI;
|
||||
if (flags & wxEVENT_SOURCE_OUTPUT)
|
||||
condition |= G_IO_OUT;
|
||||
if (flags & wxEVENT_SOURCE_EXCEPTION)
|
||||
condition |= G_IO_ERR | G_IO_HUP | G_IO_NVAL;
|
||||
int condition = 0;
|
||||
if ( flags & wxEVENT_SOURCE_INPUT )
|
||||
condition |= G_IO_IN | G_IO_PRI | G_IO_HUP;
|
||||
if ( flags & wxEVENT_SOURCE_OUTPUT )
|
||||
condition |= G_IO_OUT;
|
||||
if ( flags & wxEVENT_SOURCE_EXCEPTION )
|
||||
condition |= G_IO_ERR | G_IO_NVAL;
|
||||
|
||||
GIOChannel* channel = g_io_channel_unix_new(fd);
|
||||
const unsigned sourceId = g_io_add_watch
|
||||
(
|
||||
channel,
|
||||
(GIOCondition)condition,
|
||||
&wx_on_channel_event,
|
||||
handler
|
||||
);
|
||||
// it was ref'd by g_io_add_watch() so we can unref it here
|
||||
g_io_channel_unref(channel);
|
||||
GIOChannel* channel = g_io_channel_unix_new(fd);
|
||||
const unsigned sourceId = g_io_add_watch
|
||||
(
|
||||
channel,
|
||||
(GIOCondition)condition,
|
||||
&wx_on_channel_event,
|
||||
handler
|
||||
);
|
||||
// it was ref'd by g_io_add_watch() so we can unref it here
|
||||
g_io_channel_unref(channel);
|
||||
|
||||
if ( !sourceId )
|
||||
return NULL;
|
||||
if ( !sourceId )
|
||||
return NULL;
|
||||
|
||||
wxLogTrace(wxTRACE_EVT_SOURCE,
|
||||
"Adding event loop source for fd=%d with GTK id=%u",
|
||||
fd, sourceId);
|
||||
wxLogTrace(wxTRACE_EVT_SOURCE,
|
||||
"Adding event loop source for fd=%d with GTK id=%u",
|
||||
fd, sourceId);
|
||||
|
||||
|
||||
return new wxGTKEventLoopSource(sourceId, handler, flags);
|
||||
return new wxGTKEventLoopSource(sourceId, handler, flags);
|
||||
}
|
||||
};
|
||||
|
||||
wxEventLoopSourcesManagerBase* wxGUIAppTraits::GetEventLoopSourcesManager()
|
||||
{
|
||||
static wxGUIEventLoopSourcesManager s_eventLoopSourcesManager;
|
||||
|
||||
return &s_eventLoopSourcesManager;
|
||||
}
|
||||
|
||||
wxGTKEventLoopSource::~wxGTKEventLoopSource()
|
||||
|
||||
Reference in New Issue
Block a user