]> git.saurik.com Git - wxWidgets.git/blame_incremental - src/os2/gsockpm.cpp
removed spurious #endif
[wxWidgets.git] / src / os2 / gsockpm.cpp
... / ...
CommitLineData
1/* -------------------------------------------------------------------------
2 * Project: GSocket (Generic Socket) for WX
3 * Name: gsockpm.c
4 * Purpose: GSocket: PM part
5 * Licence: The wxWindows licence
6 * CVSID: $Id$
7 * ------------------------------------------------------------------------- */
8
9// For compilers that support precompilation, includes "wx.h".
10#include "wx/wxprec.h"
11
12#if wxUSE_SOCKETS
13
14#include <stdlib.h>
15#include "wx/unix/gsockunx.h"
16#include "wx/gsocket.h"
17#include "wx/app.h"
18
19#define wxSockReadMask 0x01
20#define wxSockWriteMask 0x02
21
22static void _GSocket_PM_Input(void *data)
23{
24 GSocket *socket = (GSocket *) data;
25 socket->Detected_Read();
26}
27
28static void _GSocket_PM_Output(void *data)
29{
30 GSocket *socket = (GSocket *) data;
31 socket->Detected_Write();
32}
33
34bool GSocketGUIFunctionsTableConcrete::CanUseEventLoop()
35{ return true; }
36
37bool GSocketGUIFunctionsTableConcrete::OnInit(void)
38{
39 return 1;
40}
41
42void GSocketGUIFunctionsTableConcrete::OnExit(void)
43{
44}
45
46bool GSocketGUIFunctionsTableConcrete::Init_Socket(GSocket *socket)
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;
54 return true;
55}
56
57void GSocketGUIFunctionsTableConcrete::Destroy_Socket(GSocket *socket)
58{
59 free(socket->m_gui_dependent);
60}
61
62void GSocketGUIFunctionsTableConcrete::Install_Callback(GSocket *socket, GSocketEvent event)
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)
80 wxTheApp->RemoveSocketHandler(m_id[c]);
81
82 if (c == 0)
83 {
84 m_id[0] = wxTheApp->AddSocketHandler(socket->m_fd, wxSockReadMask,
85 _GSocket_PM_Input, (void *)socket);
86 }
87 else
88 {
89 m_id[1] = wxTheApp->AddSocketHandler(socket->m_fd, wxSockWriteMask,
90 _GSocket_PM_Output, (void *)socket);
91 }
92}
93
94void GSocketGUIFunctionsTableConcrete::Uninstall_Callback(GSocket *socket, GSocketEvent event)
95{
96 int *m_id = (int *)(socket->m_gui_dependent);
97 int c;
98 switch (event)
99 {
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;
105 }
106 if (m_id[c] != -1)
107 wxTheApp->RemoveSocketHandler(m_id[c]);
108
109 m_id[c] = -1;
110}
111
112void GSocketGUIFunctionsTableConcrete::Enable_Events(GSocket *socket)
113{
114 Install_Callback(socket, GSOCK_INPUT);
115 Install_Callback(socket, GSOCK_OUTPUT);
116}
117
118void GSocketGUIFunctionsTableConcrete::Disable_Events(GSocket *socket)
119{
120 Uninstall_Callback(socket, GSOCK_INPUT);
121 Uninstall_Callback(socket, GSOCK_OUTPUT);
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 */