X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/77ffb5937e89927b621128789401db8921fe580f..d968078adbfb147e913b9a33fc54242a36f117ce:/src/os2/gsockpm.cpp diff --git a/src/os2/gsockpm.cpp b/src/os2/gsockpm.cpp index 89d841e6e7..a02d29ef6f 100644 --- a/src/os2/gsockpm.cpp +++ b/src/os2/gsockpm.cpp @@ -2,22 +2,19 @@ * Project: GSocket (Generic Socket) for WX * Name: gsockpm.c * Purpose: GSocket: PM part - * Licence: The wxWidgets licence + * Licence: The wxWindows licence * CVSID: $Id$ * ------------------------------------------------------------------------- */ -#include "wx/setup.h" +// For compilers that support precompilation, includes "wx.h". +#include "wx/wxprec.h" #if wxUSE_SOCKETS #include -#include "wx/unix/gsockunx.h" #include "wx/gsocket.h" - -extern int wxAppAddSocketHandler(int handle, int mask, - void (*callback)(void*), void * gsock); - -extern void wxAppRemoveSocketHandler(int handle); +#include "wx/app.h" +#include "wx/apptrait.h" #define wxSockReadMask 0x01 #define wxSockWriteMask 0x02 @@ -25,101 +22,41 @@ extern void wxAppRemoveSocketHandler(int handle); static void _GSocket_PM_Input(void *data) { GSocket *socket = (GSocket *) data; - socket->m_functions->Detected_Read(socket); + socket->Detected_Read(); } static void _GSocket_PM_Output(void *data) { GSocket *socket = (GSocket *) data; - socket->m_functions->Detected_Write(socket); -} - -int _GSocket_GUI_Init(void) -{ - return 1; -} - -void _GSocket_GUI_Cleanup(void) -{ -} - -int _GSocket_GUI_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 _GSocket_GUI_Destroy_Socket(GSocket *socket) -{ - free(socket->m_gui_dependent); + socket->Detected_Write(); } -void _GSocket_Install_Callback(GSocket *socket, GSocketEvent event) +class PMSocketManager : public GSocketInputBasedManager { - int *m_id = (int *)(socket->m_gui_dependent); - int c; - - if (socket->m_fd == -1) - return; - - switch (event) +public: + virtual int AddInput(GSocket *socket, SocketDir d) { - 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) - wxAppRemoveSocketHandler(m_id[c]); - - if (c == 0) - { - m_id[0] = wxAppAddSocketHandler(socket->m_fd, wxSockReadMask, - _GSocket_PM_Input, (void *)socket); - } - else - { - m_id[1] = wxAppAddSocketHandler(socket->m_fd, wxSockWriteMask, - _GSocket_PM_Output, (void *)socket); + if (d == FD_OUTPUT) + return wxTheApp->AddSocketHandler(socket->m_fd, wxSockWriteMask, + _GSocket_PM_Output, (void *)socket); + else + return wxTheApp->AddSocketHandler(socket->m_fd, wxSockReadMask, + _GSocket_PM_Input, (void *)socket); } -} -void _GSocket_Uninstall_Callback(GSocket *socket, GSocketEvent event) -{ - int *m_id = (int *)(socket->m_gui_dependent); - int c; - switch (event) + virtual void RemoveInput(int fd) { - 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; + wxTheApp->RemoveSocketHandler(fd); } - if (m_id[c] != -1) - wxAppRemoveSocketHandler(m_id[c]); +}; - m_id[c] = -1; -} - -void _GSocket_Enable_Events(GSocket *socket) +GSocketManager *wxGUIAppTraits::GetSocketManager() { - _GSocket_Install_Callback(socket, GSOCK_INPUT); - _GSocket_Install_Callback(socket, GSOCK_OUTPUT); + static PMSocketManager s_manager; + return &s_manager; } -void _GSocket_Disable_Events(GSocket *socket) -{ - _GSocket_Uninstall_Callback(socket, GSOCK_INPUT); - _GSocket_Uninstall_Callback(socket, GSOCK_OUTPUT); -} #else /* !wxUSE_SOCKETS */