]> git.saurik.com Git - wxWidgets.git/blob - src/os2/gsockpm.cpp
uninitialized variable warning fixed (modified patch 1434065)
[wxWidgets.git] / src / os2 / gsockpm.cpp
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 #include "wx/defs.h"
13
14 #if wxUSE_SOCKETS
15
16 #include <stdlib.h>
17 #include "wx/unix/gsockunx.h"
18 #include "wx/gsocket.h"
19 #include "wx/app.h"
20
21 #define wxSockReadMask 0x01
22 #define wxSockWriteMask 0x02
23
24 static void _GSocket_PM_Input(void *data)
25 {
26 GSocket *socket = (GSocket *) data;
27 socket->Detected_Read();
28 }
29
30 static void _GSocket_PM_Output(void *data)
31 {
32 GSocket *socket = (GSocket *) data;
33 socket->Detected_Write();
34 }
35
36 bool GSocketGUIFunctionsTableConcrete::CanUseEventLoop()
37 { return true; }
38
39 bool GSocketGUIFunctionsTableConcrete::OnInit(void)
40 {
41 return 1;
42 }
43
44 void GSocketGUIFunctionsTableConcrete::OnExit(void)
45 {
46 }
47
48 bool GSocketGUIFunctionsTableConcrete::Init_Socket(GSocket *socket)
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;
56 return true;
57 }
58
59 void GSocketGUIFunctionsTableConcrete::Destroy_Socket(GSocket *socket)
60 {
61 free(socket->m_gui_dependent);
62 }
63
64 void GSocketGUIFunctionsTableConcrete::Install_Callback(GSocket *socket, GSocketEvent event)
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)
82 wxTheApp->RemoveSocketHandler(m_id[c]);
83
84 if (c == 0)
85 {
86 m_id[0] = wxTheApp->AddSocketHandler(socket->m_fd, wxSockReadMask,
87 _GSocket_PM_Input, (void *)socket);
88 }
89 else
90 {
91 m_id[1] = wxTheApp->AddSocketHandler(socket->m_fd, wxSockWriteMask,
92 _GSocket_PM_Output, (void *)socket);
93 }
94 }
95
96 void GSocketGUIFunctionsTableConcrete::Uninstall_Callback(GSocket *socket, GSocketEvent event)
97 {
98 int *m_id = (int *)(socket->m_gui_dependent);
99 int c;
100 switch (event)
101 {
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;
107 }
108 if (m_id[c] != -1)
109 wxTheApp->RemoveSocketHandler(m_id[c]);
110
111 m_id[c] = -1;
112 }
113
114 void GSocketGUIFunctionsTableConcrete::Enable_Events(GSocket *socket)
115 {
116 Install_Callback(socket, GSOCK_INPUT);
117 Install_Callback(socket, GSOCK_OUTPUT);
118 }
119
120 void GSocketGUIFunctionsTableConcrete::Disable_Events(GSocket *socket)
121 {
122 Uninstall_Callback(socket, GSOCK_INPUT);
123 Uninstall_Callback(socket, GSOCK_OUTPUT);
124 }
125
126 #else /* !wxUSE_SOCKETS */
127
128 /* some compilers don't like having empty source files */
129 static int wxDummyGsockVar = 0;
130
131 #endif /* wxUSE_SOCKETS/!wxUSE_SOCKETS */