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