]> git.saurik.com Git - wxWidgets.git/blame - src/os2/gsockpm.cpp
[ 1665996 ] Fixes/extensions to wxDataViewCtrl
[wxWidgets.git] / src / os2 / gsockpm.cpp
CommitLineData
05a019a2
DE
1/* -------------------------------------------------------------------------
2 * Project: GSocket (Generic Socket) for WX
3 * Name: gsockpm.c
4 * Purpose: GSocket: PM part
65571936 5 * Licence: The wxWindows licence
05a019a2
DE
6 * CVSID: $Id$
7 * ------------------------------------------------------------------------- */
8
6670f564
WS
9// For compilers that support precompilation, includes "wx.h".
10#include "wx/wxprec.h"
11
05a019a2
DE
12#if wxUSE_SOCKETS
13
14#include <stdlib.h>
15#include "wx/unix/gsockunx.h"
16#include "wx/gsocket.h"
621b4574 17#include "wx/app.h"
05a019a2
DE
18
19#define wxSockReadMask 0x01
20#define wxSockWriteMask 0x02
21
22static void _GSocket_PM_Input(void *data)
23{
24 GSocket *socket = (GSocket *) data;
a1ad0f6b 25 socket->Detected_Read();
05a019a2
DE
26}
27
28static void _GSocket_PM_Output(void *data)
29{
30 GSocket *socket = (GSocket *) data;
a1ad0f6b 31 socket->Detected_Write();
05a019a2
DE
32}
33
a1ad0f6b
DE
34bool GSocketGUIFunctionsTableConcrete::CanUseEventLoop()
35{ return true; }
36
37bool GSocketGUIFunctionsTableConcrete::OnInit(void)
05a019a2
DE
38{
39 return 1;
40}
41
a1ad0f6b 42void GSocketGUIFunctionsTableConcrete::OnExit(void)
05a019a2
DE
43{
44}
45
a1ad0f6b 46bool GSocketGUIFunctionsTableConcrete::Init_Socket(GSocket *socket)
05a019a2
DE
47{
48 int *m_id;
49 socket->m_gui_dependent = (char *)malloc(sizeof(int)*2);
50 m_id = (int *)(socket->m_gui_dependent);
51
52 m_id[0] = -1;
53 m_id[1] = -1;
948c96ef 54 return true;
05a019a2
DE
55}
56
a1ad0f6b 57void GSocketGUIFunctionsTableConcrete::Destroy_Socket(GSocket *socket)
05a019a2
DE
58{
59 free(socket->m_gui_dependent);
60}
61
a1ad0f6b 62void GSocketGUIFunctionsTableConcrete::Install_Callback(GSocket *socket, GSocketEvent event)
05a019a2
DE
63{
64 int *m_id = (int *)(socket->m_gui_dependent);
65 int c;
66
67 if (socket->m_fd == -1)
68 return;
69
70 switch (event)
71 {
72 case GSOCK_LOST: /* fall-through */
73 case GSOCK_INPUT: c = 0; break;
74 case GSOCK_OUTPUT: c = 1; break;
75 case GSOCK_CONNECTION: c = ((socket->m_server) ? 0 : 1); break;
76 default: return;
77 }
78
79 if (m_id[c] != -1)
621b4574 80 wxTheApp->RemoveSocketHandler(m_id[c]);
05a019a2
DE
81
82 if (c == 0)
83 {
621b4574
SN
84 m_id[0] = wxTheApp->AddSocketHandler(socket->m_fd, wxSockReadMask,
85 _GSocket_PM_Input, (void *)socket);
05a019a2
DE
86 }
87 else
88 {
621b4574
SN
89 m_id[1] = wxTheApp->AddSocketHandler(socket->m_fd, wxSockWriteMask,
90 _GSocket_PM_Output, (void *)socket);
05a019a2
DE
91 }
92}
93
a1ad0f6b 94void GSocketGUIFunctionsTableConcrete::Uninstall_Callback(GSocket *socket, GSocketEvent event)
05a019a2
DE
95{
96 int *m_id = (int *)(socket->m_gui_dependent);
97 int c;
98 switch (event)
99 {
6670f564
WS
100 case GSOCK_LOST: /* fall-through */
101 case GSOCK_INPUT: c = 0; break;
102 case GSOCK_OUTPUT: c = 1; break;
103 case GSOCK_CONNECTION: c = ((socket->m_server) ? 0 : 1); break;
104 default: return;
05a019a2
DE
105 }
106 if (m_id[c] != -1)
621b4574 107 wxTheApp->RemoveSocketHandler(m_id[c]);
05a019a2
DE
108
109 m_id[c] = -1;
110}
111
a1ad0f6b 112void GSocketGUIFunctionsTableConcrete::Enable_Events(GSocket *socket)
05a019a2 113{
a1ad0f6b
DE
114 Install_Callback(socket, GSOCK_INPUT);
115 Install_Callback(socket, GSOCK_OUTPUT);
05a019a2
DE
116}
117
a1ad0f6b 118void GSocketGUIFunctionsTableConcrete::Disable_Events(GSocket *socket)
05a019a2 119{
a1ad0f6b
DE
120 Uninstall_Callback(socket, GSOCK_INPUT);
121 Uninstall_Callback(socket, GSOCK_OUTPUT);
05a019a2
DE
122}
123
124#else /* !wxUSE_SOCKETS */
125
126/* some compilers don't like having empty source files */
127static int wxDummyGsockVar = 0;
128
129#endif /* wxUSE_SOCKETS/!wxUSE_SOCKETS */