@COND_TOOLKIT_COCOA@ monodll_gsockosx.o monodll_hid.o monodll_utilsexc_cf.o
COND_TOOLKIT_DFB___LOWLEVEL_SRC_OBJECTS = \
monodll_fontmgrcmn.o \
+ monodll_socketevtdispatch.o \
monodll_caret.o \
monodll_colour.o \
monodll_icon.o \
monodll_fontutil.o \
monodll_utilsx11.o \
monodll_displayx11.o \
+ monodll_socketevtdispatch.o \
monodll_icon.o \
monodll_timer.o \
monodll_app.o \
monodll_dcscreen.o \
monodll_evtloop.o \
monodll_font.o \
- monodll_gsockx11.o \
monodll_minifram.o \
monodll_nanox.o \
monodll_palette.o \
@COND_TOOLKIT_COCOA@ monodll_gsockosx.o monodll_hid.o monodll_utilsexc_cf.o
COND_TOOLKIT_DFB___LOWLEVEL_SRC_OBJECTS_1 = \
monodll_fontmgrcmn.o \
+ monodll_socketevtdispatch.o \
monodll_caret.o \
monodll_colour.o \
monodll_icon.o \
monodll_fontutil.o \
monodll_utilsx11.o \
monodll_displayx11.o \
+ monodll_socketevtdispatch.o \
monodll_icon.o \
monodll_timer.o \
monodll_app.o \
monodll_dcscreen.o \
monodll_evtloop.o \
monodll_font.o \
- monodll_gsockx11.o \
monodll_minifram.o \
monodll_nanox.o \
monodll_palette.o \
@COND_TOOLKIT_COCOA@ monolib_gsockosx.o monolib_hid.o monolib_utilsexc_cf.o
COND_TOOLKIT_DFB___LOWLEVEL_SRC_OBJECTS_2 = \
monolib_fontmgrcmn.o \
+ monolib_socketevtdispatch.o \
monolib_caret.o \
monolib_colour.o \
monolib_icon.o \
monolib_fontutil.o \
monolib_utilsx11.o \
monolib_displayx11.o \
+ monolib_socketevtdispatch.o \
monolib_icon.o \
monolib_timer.o \
monolib_app.o \
monolib_dcscreen.o \
monolib_evtloop.o \
monolib_font.o \
- monolib_gsockx11.o \
monolib_minifram.o \
monolib_nanox.o \
monolib_palette.o \
@COND_TOOLKIT_COCOA@ monolib_gsockosx.o monolib_hid.o monolib_utilsexc_cf.o
COND_TOOLKIT_DFB___LOWLEVEL_SRC_OBJECTS_3 = \
monolib_fontmgrcmn.o \
+ monolib_socketevtdispatch.o \
monolib_caret.o \
monolib_colour.o \
monolib_icon.o \
monolib_fontutil.o \
monolib_utilsx11.o \
monolib_displayx11.o \
+ monolib_socketevtdispatch.o \
monolib_icon.o \
monolib_timer.o \
monolib_app.o \
monolib_dcscreen.o \
monolib_evtloop.o \
monolib_font.o \
- monolib_gsockx11.o \
monolib_minifram.o \
monolib_nanox.o \
monolib_palette.o \
@COND_TOOLKIT_COCOA@ coredll_gsockosx.o coredll_hid.o coredll_utilsexc_cf.o
COND_TOOLKIT_DFB___LOWLEVEL_SRC_OBJECTS_4 = \
coredll_fontmgrcmn.o \
+ coredll_socketevtdispatch.o \
coredll_caret.o \
coredll_colour.o \
coredll_icon.o \
coredll_fontutil.o \
coredll_utilsx11.o \
coredll_displayx11.o \
+ coredll_socketevtdispatch.o \
coredll_icon.o \
coredll_timer.o \
coredll_app.o \
coredll_dcscreen.o \
coredll_evtloop.o \
coredll_font.o \
- coredll_gsockx11.o \
coredll_minifram.o \
coredll_nanox.o \
coredll_palette.o \
@COND_TOOLKIT_COCOA@ coredll_gsockosx.o coredll_hid.o coredll_utilsexc_cf.o
COND_TOOLKIT_DFB___LOWLEVEL_SRC_OBJECTS_5 = \
coredll_fontmgrcmn.o \
+ coredll_socketevtdispatch.o \
coredll_caret.o \
coredll_colour.o \
coredll_icon.o \
coredll_fontutil.o \
coredll_utilsx11.o \
coredll_displayx11.o \
+ coredll_socketevtdispatch.o \
coredll_icon.o \
coredll_timer.o \
coredll_app.o \
coredll_dcscreen.o \
coredll_evtloop.o \
coredll_font.o \
- coredll_gsockx11.o \
coredll_minifram.o \
coredll_nanox.o \
coredll_palette.o \
@COND_TOOLKIT_COCOA@ corelib_gsockosx.o corelib_hid.o corelib_utilsexc_cf.o
COND_TOOLKIT_DFB___LOWLEVEL_SRC_OBJECTS_6 = \
corelib_fontmgrcmn.o \
+ corelib_socketevtdispatch.o \
corelib_caret.o \
corelib_colour.o \
corelib_icon.o \
corelib_fontutil.o \
corelib_utilsx11.o \
corelib_displayx11.o \
+ corelib_socketevtdispatch.o \
corelib_icon.o \
corelib_timer.o \
corelib_app.o \
corelib_dcscreen.o \
corelib_evtloop.o \
corelib_font.o \
- corelib_gsockx11.o \
corelib_minifram.o \
corelib_nanox.o \
corelib_palette.o \
@COND_TOOLKIT_COCOA@ corelib_gsockosx.o corelib_hid.o corelib_utilsexc_cf.o
COND_TOOLKIT_DFB___LOWLEVEL_SRC_OBJECTS_7 = \
corelib_fontmgrcmn.o \
+ corelib_socketevtdispatch.o \
corelib_caret.o \
corelib_colour.o \
corelib_icon.o \
corelib_fontutil.o \
corelib_utilsx11.o \
corelib_displayx11.o \
+ corelib_socketevtdispatch.o \
corelib_icon.o \
corelib_timer.o \
corelib_app.o \
corelib_dcscreen.o \
corelib_evtloop.o \
corelib_font.o \
- corelib_gsockx11.o \
corelib_minifram.o \
corelib_nanox.o \
corelib_palette.o \
@COND_TOOLKIT_COCOA_USE_GUI_1@monodll_utilsexc_cf.o: $(srcdir)/src/mac/corefoundation/utilsexc_cf.cpp $(MONODLL_ODEP)
@COND_TOOLKIT_COCOA_USE_GUI_1@ $(CXXC) -c -o $@ $(MONODLL_CXXFLAGS) $(srcdir)/src/mac/corefoundation/utilsexc_cf.cpp
-@COND_TOOLKIT_X11_USE_GUI_1@monodll_gsockx11.o: $(srcdir)/src/x11/gsockx11.cpp $(MONODLL_ODEP)
-@COND_TOOLKIT_X11_USE_GUI_1@ $(CXXC) -c -o $@ $(MONODLL_CXXFLAGS) $(srcdir)/src/x11/gsockx11.cpp
+@COND_TOOLKIT_X11_USE_GUI_1@monodll_socketevtdispatch.o: $(srcdir)/src/common/socketevtdispatch.cpp $(MONODLL_ODEP)
+@COND_TOOLKIT_X11_USE_GUI_1@ $(CXXC) -c -o $@ $(MONODLL_CXXFLAGS) $(srcdir)/src/common/socketevtdispatch.cpp
+
+@COND_TOOLKIT_DFB_USE_GUI_1@monodll_socketevtdispatch.o: $(srcdir)/src/common/socketevtdispatch.cpp $(MONODLL_ODEP)
+@COND_TOOLKIT_DFB_USE_GUI_1@ $(CXXC) -c -o $@ $(MONODLL_CXXFLAGS) $(srcdir)/src/common/socketevtdispatch.cpp
@COND_TOOLKIT_X11_USE_GUI_1@monodll_nanox.o: $(srcdir)/src/x11/nanox.c $(MONODLL_ODEP)
@COND_TOOLKIT_X11_USE_GUI_1@ $(CCC) -c -o $@ $(MONODLL_CFLAGS) $(srcdir)/src/x11/nanox.c
@COND_TOOLKIT_COCOA_USE_GUI_1@monolib_utilsexc_cf.o: $(srcdir)/src/mac/corefoundation/utilsexc_cf.cpp $(MONOLIB_ODEP)
@COND_TOOLKIT_COCOA_USE_GUI_1@ $(CXXC) -c -o $@ $(MONOLIB_CXXFLAGS) $(srcdir)/src/mac/corefoundation/utilsexc_cf.cpp
-@COND_TOOLKIT_X11_USE_GUI_1@monolib_gsockx11.o: $(srcdir)/src/x11/gsockx11.cpp $(MONOLIB_ODEP)
-@COND_TOOLKIT_X11_USE_GUI_1@ $(CXXC) -c -o $@ $(MONOLIB_CXXFLAGS) $(srcdir)/src/x11/gsockx11.cpp
+@COND_TOOLKIT_X11_USE_GUI_1@monolib_socketevtdispatch.o: $(srcdir)/src/common/socketevtdispatch.cpp $(MONOLIB_ODEP)
+@COND_TOOLKIT_X11_USE_GUI_1@ $(CXXC) -c -o $@ $(MONOLIB_CXXFLAGS) $(srcdir)/src/common/socketevtdispatch.cpp
+
+@COND_TOOLKIT_DFB_USE_GUI_1@monolib_socketevtdispatch.o: $(srcdir)/src/common/socketevtdispatch.cpp $(MONOLIB_ODEP)
+@COND_TOOLKIT_DFB_USE_GUI_1@ $(CXXC) -c -o $@ $(MONOLIB_CXXFLAGS) $(srcdir)/src/common/socketevtdispatch.cpp
@COND_TOOLKIT_X11_USE_GUI_1@monolib_nanox.o: $(srcdir)/src/x11/nanox.c $(MONOLIB_ODEP)
@COND_TOOLKIT_X11_USE_GUI_1@ $(CCC) -c -o $@ $(MONOLIB_CFLAGS) $(srcdir)/src/x11/nanox.c
@COND_TOOLKIT_COCOA_USE_GUI_1@coredll_utilsexc_cf.o: $(srcdir)/src/mac/corefoundation/utilsexc_cf.cpp $(COREDLL_ODEP)
@COND_TOOLKIT_COCOA_USE_GUI_1@ $(CXXC) -c -o $@ $(COREDLL_CXXFLAGS) $(srcdir)/src/mac/corefoundation/utilsexc_cf.cpp
-@COND_TOOLKIT_X11_USE_GUI_1@coredll_gsockx11.o: $(srcdir)/src/x11/gsockx11.cpp $(COREDLL_ODEP)
-@COND_TOOLKIT_X11_USE_GUI_1@ $(CXXC) -c -o $@ $(COREDLL_CXXFLAGS) $(srcdir)/src/x11/gsockx11.cpp
+@COND_TOOLKIT_X11_USE_GUI_1@coredll_socketevtdispatch.o: $(srcdir)/src/common/socketevtdispatch.cpp $(COREDLL_ODEP)
+@COND_TOOLKIT_X11_USE_GUI_1@ $(CXXC) -c -o $@ $(COREDLL_CXXFLAGS) $(srcdir)/src/common/socketevtdispatch.cpp
+
+@COND_TOOLKIT_DFB_USE_GUI_1@coredll_socketevtdispatch.o: $(srcdir)/src/common/socketevtdispatch.cpp $(COREDLL_ODEP)
+@COND_TOOLKIT_DFB_USE_GUI_1@ $(CXXC) -c -o $@ $(COREDLL_CXXFLAGS) $(srcdir)/src/common/socketevtdispatch.cpp
@COND_TOOLKIT_X11_USE_GUI_1@coredll_nanox.o: $(srcdir)/src/x11/nanox.c $(COREDLL_ODEP)
@COND_TOOLKIT_X11_USE_GUI_1@ $(CCC) -c -o $@ $(COREDLL_CFLAGS) $(srcdir)/src/x11/nanox.c
@COND_TOOLKIT_COCOA_USE_GUI_1@corelib_utilsexc_cf.o: $(srcdir)/src/mac/corefoundation/utilsexc_cf.cpp $(CORELIB_ODEP)
@COND_TOOLKIT_COCOA_USE_GUI_1@ $(CXXC) -c -o $@ $(CORELIB_CXXFLAGS) $(srcdir)/src/mac/corefoundation/utilsexc_cf.cpp
-@COND_TOOLKIT_X11_USE_GUI_1@corelib_gsockx11.o: $(srcdir)/src/x11/gsockx11.cpp $(CORELIB_ODEP)
-@COND_TOOLKIT_X11_USE_GUI_1@ $(CXXC) -c -o $@ $(CORELIB_CXXFLAGS) $(srcdir)/src/x11/gsockx11.cpp
+@COND_TOOLKIT_X11_USE_GUI_1@corelib_socketevtdispatch.o: $(srcdir)/src/common/socketevtdispatch.cpp $(CORELIB_ODEP)
+@COND_TOOLKIT_X11_USE_GUI_1@ $(CXXC) -c -o $@ $(CORELIB_CXXFLAGS) $(srcdir)/src/common/socketevtdispatch.cpp
+
+@COND_TOOLKIT_DFB_USE_GUI_1@corelib_socketevtdispatch.o: $(srcdir)/src/common/socketevtdispatch.cpp $(CORELIB_ODEP)
+@COND_TOOLKIT_DFB_USE_GUI_1@ $(CXXC) -c -o $@ $(CORELIB_CXXFLAGS) $(srcdir)/src/common/socketevtdispatch.cpp
@COND_TOOLKIT_X11_USE_GUI_1@corelib_nanox.o: $(srcdir)/src/x11/nanox.c $(CORELIB_ODEP)
@COND_TOOLKIT_X11_USE_GUI_1@ $(CCC) -c -o $@ $(CORELIB_CFLAGS) $(srcdir)/src/x11/nanox.c
<set var="X11_LOWLEVEL_SRC" hints="files">
$(XWIN_LOWLEVEL_SRC)
+ src/common/socketevtdispatch.cpp
src/generic/icon.cpp
src/generic/timer.cpp
src/x11/app.cpp
src/x11/dcscreen.cpp
src/x11/evtloop.cpp
src/x11/font.cpp
- src/x11/gsockx11.cpp
src/x11/minifram.cpp
src/x11/nanox.c
src/x11/palette.cpp
<set var="DFB_LOWLEVEL_SRC" hints="files">
src/common/fontmgrcmn.cpp
+ src/common/socketevtdispatch.cpp
src/generic/caret.cpp
src/generic/colour.cpp
src/generic/icon.cpp
--- /dev/null
+/////////////////////////////////////////////////////////////////////////////
+// Name: wx/private/socketevtdispatch.h
+// Purpose: wxSocketEventDispatcher class
+// Authors: Angel Vidal
+// Modified by:
+// Created: August 2006
+// Copyright: (c) Angel Vidal
+// RCS-ID: $Id$
+// Licence: wxWindows licence
+/////////////////////////////////////////////////////////////////////////////
+
+#ifndef _WX_PRIVATE_SOCKETEVTDISPATCH_H_
+#define _WX_PRIVATE_SOCKETEVTDISPATCH_H_
+
+#include "wx/defs.h"
+
+#if wxUSE_SOCKETS
+
+#include "wx/hash.h"
+
+// forward declarations
+class wxSocketEventDispatcherEntry;
+class GSocket;
+
+enum wxSocketEventDispatcherType
+{
+ wxSocketEventDispatcherInput,
+ wxSocketEventDispatcherOutput
+};
+
+class WXDLLIMPEXP_CORE wxSocketEventDispatcher : public wxHashTable
+{
+protected:
+ wxSocketEventDispatcher() : wxHashTable(wxKEY_INTEGER) {}
+
+public:
+ // returns instance of the table
+ static wxSocketEventDispatcher& Get();
+
+ virtual ~wxSocketEventDispatcher()
+ {
+ WX_CLEAR_HASH_TABLE(*this)
+ }
+
+ void RegisterCallback(int fd, wxSocketEventDispatcherType socketType,
+ GSocket* socket);
+
+ void UnregisterCallback(int fd, wxSocketEventDispatcherType socketType);
+
+ void RunLoop(int timeout = 0);
+
+private:
+ void AddEvents(fd_set* readset, fd_set* writeset);
+
+ int FillSets(fd_set* readset, fd_set* writeset);
+
+ wxSocketEventDispatcherEntry* FindEntry(int fd);
+
+private:
+ static wxSocketEventDispatcher *ms_instance;
+
+ friend class wxSocketEventDispatcherModule;
+};
+
+#endif // wxUSE_SOCKETS
+
+#endif // _WX_PRIVATE_SOCKETEVTDISPATCH_H_
--- /dev/null
+///////////////////////////////////////////////////////////////////////////////
+// Name: src/common/socketevtdispatch.cpp
+// Purpose: implements wxSocketEventDispatcher for platforms with no
+// socket events notification
+// Author: Angel Vidal
+// Modified by:
+// Created: 08.24.06
+// RCS-ID: $Id$
+// Copyright: (c) 2006 Angel vidal
+// License: wxWindows licence
+///////////////////////////////////////////////////////////////////////////////
+
+// ============================================================================
+// declarations
+// ============================================================================
+
+// ----------------------------------------------------------------------------
+// headers
+// ----------------------------------------------------------------------------
+
+// for compilers that support precompilation, includes "wx.h".
+#include "wx/wxprec.h"
+
+#if wxUSE_SOCKETS
+
+#include "wx/private/socketevtdispatch.h"
+#include "wx/module.h"
+#include "wx/unix/private.h"
+#include "wx/gsocket.h"
+#include "wx/unix/gsockunx.h"
+
+#ifndef WX_PRECOMP
+ #include "wx/hash.h"
+#endif
+
+#include <sys/time.h>
+#include <unistd.h>
+
+#ifdef HAVE_SYS_SELECT_H
+# include <sys/select.h>
+#endif
+
+// ============================================================================
+// implementation
+// ============================================================================
+
+// ----------------------------------------------------------------------------
+// wxSocketEventDispatcherEntry
+// ----------------------------------------------------------------------------
+
+class wxSocketEventDispatcherEntry: public wxObject
+{
+ public:
+ wxSocketEventDispatcherEntry()
+ {
+ m_fdInput = -1; m_fdOutput = -1;
+ m_socket = NULL;
+ }
+
+ int m_fdInput;
+ int m_fdOutput;
+ GSocket* m_socket;
+};
+
+// ----------------------------------------------------------------------------
+// wxSocketEventDispatcher
+// ----------------------------------------------------------------------------
+
+wxSocketEventDispatcher* wxSocketEventDispatcher::ms_instance = NULL;
+
+/* static */
+wxSocketEventDispatcher& wxSocketEventDispatcher::Get()
+{
+ if ( !ms_instance )
+ ms_instance = new wxSocketEventDispatcher;
+ return *ms_instance;
+}
+
+wxSocketEventDispatcherEntry* wxSocketEventDispatcher::FindEntry(int fd)
+{
+ wxSocketEventDispatcherEntry* entry =
+ (wxSocketEventDispatcherEntry*) wxHashTable::Get(fd);
+ return entry;
+}
+
+void
+wxSocketEventDispatcher::RegisterCallback(int fd,
+ wxSocketEventDispatcherType socketType,
+ GSocket* socket)
+{
+ wxSocketEventDispatcherEntry* entry = FindEntry(fd);
+ if (!entry)
+ {
+ entry = new wxSocketEventDispatcherEntry();
+ Put(fd, entry);
+ }
+
+ if (socketType == wxSocketEventDispatcherInput)
+ entry->m_fdInput = fd;
+ else
+ entry->m_fdOutput = fd;
+
+ entry->m_socket = socket;
+}
+
+void
+wxSocketEventDispatcher::UnregisterCallback(int fd,
+ wxSocketEventDispatcherType socketType)
+{
+ wxSocketEventDispatcherEntry* entry = FindEntry(fd);
+ if (entry)
+ {
+ if (socketType == wxSocketEventDispatcherInput)
+ entry->m_fdInput = -1;
+ else
+ entry->m_fdOutput = -1;
+
+ if (entry->m_fdInput == -1 && entry->m_fdOutput == -1)
+ {
+ entry->m_socket = NULL;
+ Delete(fd);
+ delete entry;
+ }
+ }
+}
+
+int wxSocketEventDispatcher::FillSets(fd_set* readset, fd_set* writeset)
+{
+ int max_fd = 0;
+
+ wxFD_ZERO(readset);
+ wxFD_ZERO(writeset);
+
+ BeginFind();
+ wxHashTable::compatibility_iterator node = Next();
+ while (node)
+ {
+ wxSocketEventDispatcherEntry* entry =
+ (wxSocketEventDispatcherEntry*) node->GetData();
+
+ if (entry->m_fdInput != -1)
+ {
+ wxFD_SET(entry->m_fdInput, readset);
+ if (entry->m_fdInput > max_fd)
+ max_fd = entry->m_fdInput;
+ }
+
+ if (entry->m_fdOutput != -1)
+ {
+ wxFD_SET(entry->m_fdOutput, writeset);
+ if (entry->m_fdOutput > max_fd)
+ max_fd = entry->m_fdOutput;
+ }
+
+ node = Next();
+ }
+
+ return max_fd;
+}
+
+void wxSocketEventDispatcher::AddEvents(fd_set* readset, fd_set* writeset)
+{
+ BeginFind();
+ wxHashTable::compatibility_iterator node = Next();
+ while (node)
+ {
+ // We have to store the next node here, because the event processing can
+ // destroy the object before we call Next()
+
+ wxHashTable::compatibility_iterator next_node = Next();
+
+ wxSocketEventDispatcherEntry* entry =
+ (wxSocketEventDispatcherEntry*) node->GetData();
+
+ wxCHECK_RET(entry->m_socket, wxT("Critical: Processing a NULL socket in wxSocketEventDispatcher"));
+
+ if (entry->m_fdInput != -1 && wxFD_ISSET(entry->m_fdInput, readset))
+ entry->m_socket->Detected_Read();
+
+ if (entry->m_fdOutput != -1 && wxFD_ISSET(entry->m_fdOutput, writeset))
+ entry->m_socket->Detected_Write();;
+
+ node = next_node;
+ }
+}
+
+void wxSocketEventDispatcher::RunLoop(int timeout)
+{
+ struct timeval tv;
+ tv.tv_sec = 0;
+ tv.tv_usec = timeout;
+ fd_set readset;
+ fd_set writeset;
+
+ int max_fd = FillSets( &readset, &writeset);
+ if (select( max_fd+1, &readset, &writeset, NULL, &tv ) == 0)
+ {
+ // No socket input/output. Don't add events.
+ return;
+ }
+ else
+ {
+ AddEvents(&readset, &writeset);
+ }
+}
+
+// ----------------------------------------------------------------------------
+// wxSocketEventDispatcherModule
+// ----------------------------------------------------------------------------
+
+class wxSocketEventDispatcherModule: public wxModule
+{
+public:
+ bool OnInit() { return true; }
+ void OnExit() { wxDELETE(wxSocketEventDispatcher::ms_instance); }
+
+private:
+ DECLARE_DYNAMIC_CLASS(wxSocketEventDispatcherModule)
+};
+
+IMPLEMENT_DYNAMIC_CLASS(wxSocketEventDispatcherModule, wxModule)
+
+
+// ----------------------------------------------------------------------------
+// GSocket interface
+// ----------------------------------------------------------------------------
+
+bool GSocketGUIFunctionsTableConcrete::CanUseEventLoop()
+{
+ return true;
+}
+
+bool GSocketGUIFunctionsTableConcrete::OnInit(void)
+{
+ return 1;
+}
+
+void GSocketGUIFunctionsTableConcrete::OnExit(void)
+{
+}
+
+bool GSocketGUIFunctionsTableConcrete::Init_Socket(GSocket *socket)
+{
+ int *m_id;
+
+ socket->m_gui_dependent = (char *)malloc(sizeof(int)*2);
+ m_id = (int *)(socket->m_gui_dependent);
+
+ m_id[0] = -1;
+ m_id[1] = -1;
+
+ return true;
+}
+
+void GSocketGUIFunctionsTableConcrete::Destroy_Socket(GSocket *socket)
+{
+ free(socket->m_gui_dependent);
+}
+
+void GSocketGUIFunctionsTableConcrete::Install_Callback(GSocket *socket,
+ GSocketEvent event)
+{
+ int *m_id = (int *)(socket->m_gui_dependent);
+ int c;
+
+ if (socket->m_fd == -1)
+ return;
+
+ switch (event)
+ {
+ case GSOCK_LOST: /* fall-through */
+ case GSOCK_INPUT: c = 0; break;
+ case GSOCK_OUTPUT: c = 1; break;
+ case GSOCK_CONNECTION: c = ((socket->m_server) ? 0 : 1); break;
+ default: return;
+ }
+
+#if 0
+ if (m_id[c] != -1)
+ XtRemoveInput(m_id[c]);
+#endif /* 0 */
+
+ if (c == 0)
+ {
+ m_id[0] = socket->m_fd;
+
+ wxSocketEventDispatcher::Get().RegisterCallback(
+ socket->m_fd, wxSocketEventDispatcherInput, socket);
+ }
+ else
+ {
+ m_id[1] = socket->m_fd;
+
+ wxSocketEventDispatcher::Get().RegisterCallback(
+ socket->m_fd, wxSocketEventDispatcherOutput, socket);
+ }
+}
+
+void GSocketGUIFunctionsTableConcrete::Uninstall_Callback(GSocket *socket,
+ GSocketEvent event)
+{
+ int *m_id = (int *)(socket->m_gui_dependent);
+ int c;
+
+ switch (event)
+ {
+ case GSOCK_LOST: /* fall-through */
+ case GSOCK_INPUT: c = 0; break;
+ case GSOCK_OUTPUT: c = 1; break;
+ case GSOCK_CONNECTION: c = ((socket->m_server) ? 0 : 1); break;
+ default: return;
+ }
+
+ if (m_id[c] != -1)
+ {
+ if (c == 0)
+ wxSocketEventDispatcher::Get().UnregisterCallback(
+ m_id[c], wxSocketEventDispatcherInput);
+ else
+ wxSocketEventDispatcher::Get().UnregisterCallback(
+ m_id[c], wxSocketEventDispatcherOutput);
+ }
+
+ m_id[c] = -1;
+}
+
+void GSocketGUIFunctionsTableConcrete::Enable_Events(GSocket *socket)
+{
+ Install_Callback(socket, GSOCK_INPUT);
+ Install_Callback(socket, GSOCK_OUTPUT);
+}
+
+void GSocketGUIFunctionsTableConcrete::Disable_Events(GSocket *socket)
+{
+ Uninstall_Callback(socket, GSOCK_INPUT);
+ Uninstall_Callback(socket, GSOCK_OUTPUT);
+}
+
+#endif // wxUSE_SOCKETS
#endif
#include "wx/timer.h"
+#include "wx/private/socketevtdispatch.h"
#include "wx/dfb/private.h"
#define TRACE_EVENTS _T("events")
// 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?
+ // FIXME: call NotifyTimers() and wxSocketEventDispatcher::RunLoop() from here
+ // (and loop) instead?
const int TIMEOUT = 100;
if ( ms_buffer->WaitForEventWithTimeout(0, TIMEOUT) )
void wxEventLoop::OnNextIteration()
{
-#if wxUSE_TIMER
// see the comment in Dispatch
+
+#if wxUSE_TIMER
wxTimer::NotifyTimers();
#endif
+
+#if wxUSE_SOCKETS
+ // handle any pending socket events:
+ wxSocketEventDispatcher::Get().RunLoop();
+#endif
}
#include "wx/module.h"
#endif
-#include "wx/tooltip.h"
+#include "wx/private/socketevtdispatch.h"
#include "wx/unix/private.h"
#include "wx/x11/private.h"
#include "X11/Xlib.h"
# include <sys/select.h>
#endif
-#if wxUSE_SOCKETS
-// ----------------------------------------------------------------------------
-// wxSocketTable
-// ----------------------------------------------------------------------------
-
-typedef void (*wxSocketCallback) (int fd, void* data);
-
-class wxSocketTableEntry: public wxObject
-{
- public:
- wxSocketTableEntry()
- {
- m_fdInput = -1; m_fdOutput = -1;
- m_callbackInput = NULL; m_callbackOutput = NULL;
- m_dataInput = NULL; m_dataOutput = NULL;
- }
-
- int m_fdInput;
- int m_fdOutput;
- wxSocketCallback m_callbackInput;
- wxSocketCallback m_callbackOutput;
- void* m_dataInput;
- void* m_dataOutput;
-};
-
-typedef enum
-{ wxSocketTableInput, wxSocketTableOutput } wxSocketTableType ;
-
-class wxSocketTable: public wxHashTable
-{
- public:
- wxSocketTable(): wxHashTable(wxKEY_INTEGER)
- {
- }
- virtual ~wxSocketTable()
- {
- WX_CLEAR_HASH_TABLE(*this)
- }
-
- wxSocketTableEntry* FindEntry(int fd);
-
- void RegisterCallback(int fd, wxSocketTableType socketType, wxSocketCallback callback, void* data);
-
- void UnregisterCallback(int fd, wxSocketTableType socketType);
-
- bool CallCallback(int fd, wxSocketTableType socketType);
-
- void FillSets(fd_set* readset, fd_set* writeset, int* highest);
-
- void ProcessEvents(fd_set* readset, fd_set* writeset);
-};
-
-wxSocketTableEntry* wxSocketTable::FindEntry(int fd)
-{
- wxSocketTableEntry* entry = (wxSocketTableEntry*) Get(fd);
- return entry;
-}
-
-void wxSocketTable::RegisterCallback(int fd, wxSocketTableType socketType, wxSocketCallback callback, void* data)
-{
- wxSocketTableEntry* entry = FindEntry(fd);
- if (!entry)
- {
- entry = new wxSocketTableEntry();
- Put(fd, entry);
- }
-
- if (socketType == wxSocketTableInput)
- {
- entry->m_fdInput = fd;
- entry->m_dataInput = data;
- entry->m_callbackInput = callback;
- }
- else
- {
- entry->m_fdOutput = fd;
- entry->m_dataOutput = data;
- entry->m_callbackOutput = callback;
- }
-}
-
-void wxSocketTable::UnregisterCallback(int fd, wxSocketTableType socketType)
-{
- wxSocketTableEntry* entry = FindEntry(fd);
- if (entry)
- {
- if (socketType == wxSocketTableInput)
- {
- entry->m_fdInput = -1;
- entry->m_dataInput = NULL;
- entry->m_callbackInput = NULL;
- }
- else
- {
- entry->m_fdOutput = -1;
- entry->m_dataOutput = NULL;
- entry->m_callbackOutput = NULL;
- }
- if (entry->m_fdInput == -1 && entry->m_fdOutput == -1)
- {
- Delete(fd);
- delete entry;
- }
- }
-}
-
-bool wxSocketTable::CallCallback(int fd, wxSocketTableType socketType)
-{
- wxSocketTableEntry* entry = FindEntry(fd);
- if (entry)
- {
- if (socketType == wxSocketTableInput)
- {
- if (entry->m_fdInput != -1 && entry->m_callbackInput)
- {
- (entry->m_callbackInput) (entry->m_fdInput, entry->m_dataInput);
- }
- }
- else
- {
- if (entry->m_fdOutput != -1 && entry->m_callbackOutput)
- {
- (entry->m_callbackOutput) (entry->m_fdOutput, entry->m_dataOutput);
- }
- }
- return true;
- }
- else
- return false;
-}
-
-void wxSocketTable::FillSets(fd_set* readset, fd_set* writeset, int* highest)
-{
- BeginFind();
- wxHashTable::compatibility_iterator node = Next();
- while (node)
- {
- wxSocketTableEntry* entry = (wxSocketTableEntry*) node->GetData();
-
- if (entry->m_fdInput != -1)
- {
- wxFD_SET(entry->m_fdInput, readset);
- if (entry->m_fdInput > *highest)
- * highest = entry->m_fdInput;
- }
-
- if (entry->m_fdOutput != -1)
- {
- wxFD_SET(entry->m_fdOutput, writeset);
- if (entry->m_fdOutput > *highest)
- * highest = entry->m_fdOutput;
- }
-
- node = Next();
- }
-}
-
-void wxSocketTable::ProcessEvents(fd_set* readset, fd_set* writeset)
-{
- BeginFind();
- wxHashTable::compatibility_iterator node = Next();
- while (node)
- {
- wxSocketTableEntry* entry = (wxSocketTableEntry*) node->GetData();
-
- if (entry->m_fdInput != -1 && wxFD_ISSET(entry->m_fdInput, readset))
- {
- (entry->m_callbackInput) (entry->m_fdInput, entry->m_dataInput);
- }
-
- if (entry->m_fdOutput != -1 && wxFD_ISSET(entry->m_fdOutput, writeset))
- {
- (entry->m_callbackOutput) (entry->m_fdOutput, entry->m_dataOutput);
- }
-
- node = Next();
- }
-}
-
-wxSocketTable* wxTheSocketTable = NULL;
-
-class wxSocketTableModule: public wxModule
-{
-DECLARE_DYNAMIC_CLASS(wxSocketTableModule)
-public:
- wxSocketTableModule() {}
- bool OnInit() { wxTheSocketTable = new wxSocketTable; return true; };
- void OnExit() { delete wxTheSocketTable; wxTheSocketTable = NULL; };
-};
-
-IMPLEMENT_DYNAMIC_CLASS(wxSocketTableModule, wxModule)
-
-// Implement registration functions as C functions so they
-// can be called from gsock11.c
-
-extern "C" void wxRegisterSocketCallback(int fd, wxSocketTableType socketType, wxSocketCallback callback, void* data)
-{
- if (wxTheSocketTable)
- {
- wxTheSocketTable->RegisterCallback(fd, socketType, callback, data);
- }
-}
-
-extern "C" void wxUnregisterSocketCallback(int fd, wxSocketTableType socketType)
-{
- if (wxTheSocketTable)
- {
- wxTheSocketTable->UnregisterCallback(fd, socketType);
- }
-}
-#endif
-
// ----------------------------------------------------------------------------
// wxEventLoopImpl
// ----------------------------------------------------------------------------
fd_set readset;
fd_set writeset;
- int highest = fd;
wxFD_ZERO(&readset);
wxFD_ZERO(&writeset);
-
wxFD_SET(fd, &readset);
-#if wxUSE_SOCKETS
- if (wxTheSocketTable)
- wxTheSocketTable->FillSets( &readset, &writeset, &highest );
-#endif
-
- if (select( highest+1, &readset, &writeset, NULL, &tv ) == 0)
+ if (select( fd+1, &readset, &writeset, NULL, &tv ) != 0)
{
- // Timed out, so no event to process
- return true;
- }
- else
- {
- // An X11 event was pending, so get it
+ // An X11 event was pending, get it
if (wxFD_ISSET( fd, &readset ))
XNextEvent( wxGlobalDisplay(), &event );
-
-#if wxUSE_SOCKETS
- // Check if any socket events were pending,
- // and if so, call their callbacks
- if (wxTheSocketTable)
- wxTheSocketTable->ProcessEvents( &readset, &writeset );
-#endif
- }
+ }
#endif
}
else
XNextEvent( wxGlobalDisplay(), &event );
}
+#if wxUSE_SOCKETS
+ // handle any pending socket events:
+ wxSocketEventDispatcher::Get().RunLoop();
+#endif
(void) m_impl->ProcessEvent( &event );
return true;
+++ /dev/null
-/* -------------------------------------------------------------------------
- * Project: GSocket (Generic Socket) for WX
- * Name: src/x11/gsockx11.cpp
- * Purpose: GSocket: X11 part
- * Licence: The wxWindows licence
- * CVSID: $Id$
- * ------------------------------------------------------------------------- */
-
-// for compilers that support precompilation, includes "wx.h".
-#include "wx/wxprec.h"
-
-#if defined(__BORLANDC__)
-#pragma hdrstop
-#endif
-
-#if wxUSE_SOCKETS
-
-#include <stdlib.h>
-#include "wx/gsocket.h"
-#include "wx/unix/gsockunx.h"
-
-/*
- * FIXME: have these in a common header instead of being repeated
- * in evtloop.cpp and gsockx11.c
- */
-
-typedef void (*wxSocketCallback) (int fd, void* data);
-
-typedef enum
-{ wxSocketTableInput, wxSocketTableOutput } wxSocketTableType ;
-
-extern "C" void wxRegisterSocketCallback(int fd, wxSocketTableType socketType, wxSocketCallback cback, void* data);
-extern "C" void wxUnregisterSocketCallback(int fd, wxSocketTableType socketType);
-
-
-static void _GSocket_X11_Input(int *fid, void* data)
-{
- GSocket *socket = (GSocket *)data;
-
- socket->Detected_Read();
-}
-
-static void _GSocket_X11_Output(int *fid, void* data)
-{
- GSocket *socket = (GSocket *)data;
-
- socket->Detected_Write();
-}
-
-bool GSocketGUIFunctionsTableConcrete::CanUseEventLoop()
-{ return true; }
-
-bool GSocketGUIFunctionsTableConcrete::OnInit(void)
-{
- return 1;
-}
-
-void GSocketGUIFunctionsTableConcrete::OnExit(void)
-{
-}
-
-bool GSocketGUIFunctionsTableConcrete::Init_Socket(GSocket *socket)
-{
- int *m_id;
-
- socket->m_gui_dependent = (char *)malloc(sizeof(int)*2);
- m_id = (int *)(socket->m_gui_dependent);
-
- m_id[0] = -1;
- m_id[1] = -1;
-
- return true;
-}
-
-void GSocketGUIFunctionsTableConcrete::Destroy_Socket(GSocket *socket)
-{
- free(socket->m_gui_dependent);
-}
-
-void GSocketGUIFunctionsTableConcrete::Install_Callback(GSocket *socket, GSocketEvent event)
-{
- int *m_id = (int *)(socket->m_gui_dependent);
- int c;
-
- if (socket->m_fd == -1)
- return;
-
- switch (event)
- {
- case GSOCK_LOST: /* fall-through */
- case GSOCK_INPUT: c = 0; break;
- case GSOCK_OUTPUT: c = 1; break;
- case GSOCK_CONNECTION: c = ((socket->m_server) ? 0 : 1); break;
- default: return;
- }
-
-#if 0
- if (m_id[c] != -1)
- XtRemoveInput(m_id[c]);
-#endif /* 0 */
-
- if (c == 0)
- {
- m_id[0] = socket->m_fd;
-
- wxRegisterSocketCallback(socket->m_fd, wxSocketTableInput,
- (wxSocketCallback) _GSocket_X11_Input, (void*) socket);
- }
- else
- {
- m_id[1] = socket->m_fd;
-
- wxRegisterSocketCallback(socket->m_fd, wxSocketTableOutput,
- (wxSocketCallback) _GSocket_X11_Output, (void*) socket);
- }
-}
-
-void GSocketGUIFunctionsTableConcrete::Uninstall_Callback(GSocket *socket, GSocketEvent event)
-{
- int *m_id = (int *)(socket->m_gui_dependent);
- int c;
-
- switch (event)
- {
- case GSOCK_LOST: /* fall-through */
- case GSOCK_INPUT: c = 0; break;
- case GSOCK_OUTPUT: c = 1; break;
- case GSOCK_CONNECTION: c = ((socket->m_server) ? 0 : 1); break;
- default: return;
- }
-
- if (m_id[c] != -1)
- {
- if (c == 0)
- wxUnregisterSocketCallback(m_id[c], wxSocketTableInput);
- else
- wxUnregisterSocketCallback(m_id[c], wxSocketTableOutput);
- }
-
- m_id[c] = -1;
-}
-
-void GSocketGUIFunctionsTableConcrete::Enable_Events(GSocket *socket)
-{
- Install_Callback(socket, GSOCK_INPUT);
- Install_Callback(socket, GSOCK_OUTPUT);
-}
-
-void GSocketGUIFunctionsTableConcrete::Disable_Events(GSocket *socket)
-{
- Uninstall_Callback(socket, GSOCK_INPUT);
- Uninstall_Callback(socket, GSOCK_OUTPUT);
-}
-
-#else /* !wxUSE_SOCKETS */
-
-/* some compilers don't like having empty source files */
-static int wxDummyGsockVar = 0;
-
-#endif /* wxUSE_SOCKETS/!wxUSE_SOCKETS */