]> git.saurik.com Git - wxWidgets.git/blame - src/motif/gsockmot.c
disable Borland C++ warnings
[wxWidgets.git] / src / motif / gsockmot.c
CommitLineData
d391a345
VZ
1/* -------------------------------------------------------------------------
2 * Project: GSocket (Generic Socket) for WX
3 * Name: gsockmot.c
4 * Purpose: GSocket: Motif part
5 * CVSID: $Id$
84969af7 6 * Licence: The wxWindows licence
d391a345 7 * ------------------------------------------------------------------------- */
813c20a6
VZ
8
9#include "wx/setup.h"
10
11#if wxUSE_SOCKETS
12
dbd300df
GL
13#include <stdlib.h>
14#include <X11/Intrinsic.h>
483249fc 15#include "wx/gsocket.h"
483249fc 16#include "wx/unix/gsockunx.h"
dbd300df 17
d391a345 18extern XtAppContext wxGetAppContext();
dbd300df
GL
19
20static void _GSocket_Motif_Input(XtPointer data, int *fid,
21 XtInputId *id)
22{
23 GSocket *socket = (GSocket *)data;
24
25 _GSocket_Detected_Read(socket);
26}
27
28static void _GSocket_Motif_Output(XtPointer data, int *fid,
29 XtInputId *id)
30{
31 GSocket *socket = (GSocket *)data;
32
33 _GSocket_Detected_Write(socket);
34}
35
27a97d02 36int _GSocket_GUI_Init(GSocket *socket)
dbd300df 37{
dbd300df
GL
38 int *m_id;
39
483249fc 40 socket->m_gui_dependent = (char *)malloc(sizeof(int)*2);
dbd300df
GL
41 m_id = (int *)(socket->m_gui_dependent);
42
483249fc
GRG
43 m_id[0] = -1;
44 m_id[1] = -1;
5ff86996
GRG
45
46 return TRUE;
dbd300df
GL
47}
48
49void _GSocket_GUI_Destroy(GSocket *socket)
50{
dbd300df
GL
51 free(socket->m_gui_dependent);
52}
53
39b91eca 54void _GSocket_Install_Callback(GSocket *socket, GSocketEvent event)
dbd300df 55{
483249fc
GRG
56 int *m_id = (int *)(socket->m_gui_dependent);
57 int c;
dbd300df 58
483249fc
GRG
59 if (socket->m_fd == -1)
60 return;
dbd300df 61
483249fc
GRG
62 switch (event)
63 {
64 case GSOCK_LOST: /* fall-through */
d391a345 65 case GSOCK_INPUT: c = 0; break;
483249fc
GRG
66 case GSOCK_OUTPUT: c = 1; break;
67 case GSOCK_CONNECTION: c = ((socket->m_server) ? 0 : 1); break;
68 default: return;
69 }
70
71 if (m_id[c] != -1)
72 XtRemoveInput(m_id[c]);
73
74 if (c == 0)
75 {
d391a345 76 m_id[0] = XtAppAddInput(wxGetAppContext(), socket->m_fd,
dbd300df
GL
77 (XtPointer *)XtInputReadMask,
78 (XtInputCallbackProc) _GSocket_Motif_Input,
79 (XtPointer) socket);
483249fc
GRG
80 }
81 else
82 {
d391a345 83 m_id[1] = XtAppAddInput(wxGetAppContext(), socket->m_fd,
dbd300df
GL
84 (XtPointer *)XtInputWriteMask,
85 (XtInputCallbackProc) _GSocket_Motif_Output,
86 (XtPointer) socket);
dbd300df
GL
87 }
88}
89
39b91eca 90void _GSocket_Uninstall_Callback(GSocket *socket, GSocketEvent event)
dbd300df 91{
483249fc 92 int *m_id = (int *)(socket->m_gui_dependent);
dbd300df 93 int c;
dbd300df 94
483249fc
GRG
95 switch (event)
96 {
97 case GSOCK_LOST: /* fall-through */
d391a345 98 case GSOCK_INPUT: c = 0; break;
483249fc
GRG
99 case GSOCK_OUTPUT: c = 1; break;
100 case GSOCK_CONNECTION: c = ((socket->m_server) ? 0 : 1); break;
101 default: return;
dbd300df
GL
102 }
103
104 if (m_id[c] != -1)
105 XtRemoveInput(m_id[c]);
106
107 m_id[c] = -1;
108}
109
483249fc 110void _GSocket_Enable_Events(GSocket *socket)
dbd300df 111{
483249fc
GRG
112 _GSocket_Install_Callback(socket, GSOCK_INPUT);
113 _GSocket_Install_Callback(socket, GSOCK_OUTPUT);
dbd300df
GL
114}
115
483249fc 116void _GSocket_Disable_Events(GSocket *socket)
dbd300df 117{
483249fc
GRG
118 _GSocket_Uninstall_Callback(socket, GSOCK_INPUT);
119 _GSocket_Uninstall_Callback(socket, GSOCK_OUTPUT);
dbd300df 120}
813c20a6 121
26dfedc4
VZ
122#else /* !wxUSE_SOCKETS */
123
124/* some compilers don't like having empty source files */
125static int wxDummyGsockVar = 0;
126
127#endif /* wxUSE_SOCKETS/!wxUSE_SOCKETS */