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