]> git.saurik.com Git - wxWidgets.git/blame_incremental - src/x11/gsockx11.cpp
Crash fix under VC++
[wxWidgets.git] / src / x11 / gsockx11.cpp
... / ...
CommitLineData
1/* -------------------------------------------------------------------------
2 * Project: GSocket (Generic Socket) for WX
3 * Name: gsockmot.c
4 * Purpose: GSocket: X11 part
5 * Licence: The wxWindows licence
6 * CVSID: $Id$
7 * ------------------------------------------------------------------------- */
8
9#include "wx/setup.h"
10
11#if wxUSE_SOCKETS
12
13#include <stdlib.h>
14#include "wx/gsocket.h"
15#include "wx/unix/gsockunx.h"
16
17/*
18 * FIXME: have these in a common header instead of being repeated
19 * in evtloop.cpp and gsockx11.c
20 */
21
22typedef void (*wxSocketCallback) (int fd, void* data);
23
24typedef enum
25{ wxSocketTableInput, wxSocketTableOutput } wxSocketTableType ;
26
27extern "C" void wxRegisterSocketCallback(int fd, wxSocketTableType socketType, wxSocketCallback cback, void* data);
28extern "C" void wxUnregisterSocketCallback(int fd, wxSocketTableType socketType);
29
30
31static void _GSocket_X11_Input(int *fid, void* data)
32{
33 GSocket *socket = (GSocket *)data;
34
35 socket->Detected_Read();
36}
37
38static void _GSocket_X11_Output(int *fid, void* data)
39{
40 GSocket *socket = (GSocket *)data;
41
42 socket->Detected_Write();
43}
44
45bool GSocketGUIFunctionsTableConcrete::CanUseEventLoop()
46{ return true; }
47
48bool GSocketGUIFunctionsTableConcrete::OnInit(void)
49{
50 return 1;
51}
52
53void GSocketGUIFunctionsTableConcrete::OnExit(void)
54{
55}
56
57bool GSocketGUIFunctionsTableConcrete::Init_Socket(GSocket *socket)
58{
59 int *m_id;
60
61 socket->m_gui_dependent = (char *)malloc(sizeof(int)*2);
62 m_id = (int *)(socket->m_gui_dependent);
63
64 m_id[0] = -1;
65 m_id[1] = -1;
66
67 return true;
68}
69
70void GSocketGUIFunctionsTableConcrete::Destroy_Socket(GSocket *socket)
71{
72 free(socket->m_gui_dependent);
73}
74
75void GSocketGUIFunctionsTableConcrete::Install_Callback(GSocket *socket, GSocketEvent event)
76{
77 int *m_id = (int *)(socket->m_gui_dependent);
78 int c;
79
80 if (socket->m_fd == -1)
81 return;
82
83 switch (event)
84 {
85 case GSOCK_LOST: /* fall-through */
86 case GSOCK_INPUT: c = 0; break;
87 case GSOCK_OUTPUT: c = 1; break;
88 case GSOCK_CONNECTION: c = ((socket->m_server) ? 0 : 1); break;
89 default: return;
90 }
91
92#if 0
93 if (m_id[c] != -1)
94 XtRemoveInput(m_id[c]);
95#endif /* 0 */
96
97 if (c == 0)
98 {
99 m_id[0] = socket->m_fd;
100
101 wxRegisterSocketCallback(socket->m_fd, wxSocketTableInput,
102 (wxSocketCallback) _GSocket_X11_Input, (void*) socket);
103 }
104 else
105 {
106 m_id[1] = socket->m_fd;
107
108 wxRegisterSocketCallback(socket->m_fd, wxSocketTableOutput,
109 (wxSocketCallback) _GSocket_X11_Output, (void*) socket);
110 }
111}
112
113void GSocketGUIFunctionsTableConcrete::Uninstall_Callback(GSocket *socket, GSocketEvent event)
114{
115 int *m_id = (int *)(socket->m_gui_dependent);
116 int c;
117
118 switch (event)
119 {
120 case GSOCK_LOST: /* fall-through */
121 case GSOCK_INPUT: c = 0; break;
122 case GSOCK_OUTPUT: c = 1; break;
123 case GSOCK_CONNECTION: c = ((socket->m_server) ? 0 : 1); break;
124 default: return;
125 }
126
127 if (m_id[c] != -1)
128 {
129 if (c == 0)
130 wxUnregisterSocketCallback(m_id[c], wxSocketTableInput);
131 else
132 wxUnregisterSocketCallback(m_id[c], wxSocketTableOutput);
133 }
134
135 m_id[c] = -1;
136}
137
138void GSocketGUIFunctionsTableConcrete::Enable_Events(GSocket *socket)
139{
140 Install_Callback(socket, GSOCK_INPUT);
141 Install_Callback(socket, GSOCK_OUTPUT);
142}
143
144void GSocketGUIFunctionsTableConcrete::Disable_Events(GSocket *socket)
145{
146 Uninstall_Callback(socket, GSOCK_INPUT);
147 Uninstall_Callback(socket, GSOCK_OUTPUT);
148}
149
150#else /* !wxUSE_SOCKETS */
151
152/* some compilers don't like having empty source files */
153static int wxDummyGsockVar = 0;
154
155#endif /* wxUSE_SOCKETS/!wxUSE_SOCKETS */