]> git.saurik.com Git - wxWidgets.git/blame - src/x11/gsockx11.c
(probably) fixed wxLocale::Init with Borland C++
[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
83df96d6
JS
5 * CVSID: $Id$
6 * ------------------------------------------------------------------------- */
7
8#include "wx/setup.h"
9
10#if wxUSE_SOCKETS
11
12#include <stdlib.h>
83df96d6
JS
13#include "wx/gsocket.h"
14#include "wx/unix/gsockunx.h"
15
52127426 16/*
2d1084ea 17 * FIXME: have these in a common header instead of being repeated
52127426
JS
18 * in evtloop.cpp and gsockx11.c
19 */
bc797f4c 20
52127426 21typedef void (*wxSocketCallback) (int fd, void* data);
83df96d6 22
52127426
JS
23typedef enum
24{ wxSocketTableInput, wxSocketTableOutput } wxSocketTableType ;
25
26void wxRegisterSocketCallback(int fd, wxSocketTableType socketType, wxSocketCallback cback, void* data);
27void wxUnregisterSocketCallback(int fd, wxSocketTableType socketType);
28
29
30static void _GSocket_X11_Input(int *fid, void* data)
83df96d6
JS
31{
32 GSocket *socket = (GSocket *)data;
2b5f62a0 33
83df96d6
JS
34 _GSocket_Detected_Read(socket);
35}
36
52127426 37static void _GSocket_X11_Output(int *fid, void* data)
83df96d6
JS
38{
39 GSocket *socket = (GSocket *)data;
40
41 _GSocket_Detected_Write(socket);
42}
43
44int _GSocket_GUI_Init(GSocket *socket)
45{
46 int *m_id;
47
48 socket->m_gui_dependent = (char *)malloc(sizeof(int)*2);
49 m_id = (int *)(socket->m_gui_dependent);
50
51 m_id[0] = -1;
52 m_id[1] = -1;
53
54 return TRUE;
55}
56
57void _GSocket_GUI_Destroy(GSocket *socket)
58{
59 free(socket->m_gui_dependent);
60}
61
62void _GSocket_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
2b5f62a0
VZ
79#if 0
80 if (m_id[c] != -1)
81 XtRemoveInput(m_id[c]);
82#endif /* 0 */
83df96d6
JS
83
84 if (c == 0)
85 {
52127426
JS
86 m_id[0] = socket->m_fd;
87
88 wxRegisterSocketCallback(socket->m_fd, wxSocketTableInput,
89 (wxSocketCallback) _GSocket_X11_Input, (void*) socket);
83df96d6
JS
90 }
91 else
92 {
52127426
JS
93 m_id[1] = socket->m_fd;
94
95 wxRegisterSocketCallback(socket->m_fd, wxSocketTableOutput,
96 (wxSocketCallback) _GSocket_X11_Output, (void*) socket);
83df96d6
JS
97 }
98}
99
100void _GSocket_Uninstall_Callback(GSocket *socket, GSocketEvent event)
101{
102 int *m_id = (int *)(socket->m_gui_dependent);
103 int c;
104
105 switch (event)
106 {
107 case GSOCK_LOST: /* fall-through */
108 case GSOCK_INPUT: c = 0; break;
109 case GSOCK_OUTPUT: c = 1; break;
110 case GSOCK_CONNECTION: c = ((socket->m_server) ? 0 : 1); break;
111 default: return;
112 }
113
114 if (m_id[c] != -1)
52127426
JS
115 {
116 if (c == 0)
117 wxUnregisterSocketCallback(m_id[c], wxSocketTableInput);
118 else
119 wxUnregisterSocketCallback(m_id[c], wxSocketTableOutput);
120 }
83df96d6
JS
121
122 m_id[c] = -1;
123}
124
125void _GSocket_Enable_Events(GSocket *socket)
126{
127 _GSocket_Install_Callback(socket, GSOCK_INPUT);
128 _GSocket_Install_Callback(socket, GSOCK_OUTPUT);
129}
130
131void _GSocket_Disable_Events(GSocket *socket)
132{
133 _GSocket_Uninstall_Callback(socket, GSOCK_INPUT);
134 _GSocket_Uninstall_Callback(socket, GSOCK_OUTPUT);
135}
136
137#else /* !wxUSE_SOCKETS */
138
139/* some compilers don't like having empty source files */
140static int wxDummyGsockVar = 0;
141
142#endif /* wxUSE_SOCKETS/!wxUSE_SOCKETS */