]> git.saurik.com Git - wxWidgets.git/blob - src/motif/gsockmot.cpp
use unsgined int instead of int for 1 bit bitfields (SGI CC warning fix)
[wxWidgets.git] / src / motif / gsockmot.cpp
1 /* -------------------------------------------------------------------------
2 * Project: GSocket (Generic Socket) for WX
3 * Name: gsockmot.c
4 * Purpose: GSocket: Motif part
5 * CVSID: $Id$
6 * Licence: The wxWindows licence
7 * ------------------------------------------------------------------------- */
8
9 #include "wx/setup.h"
10
11 #if wxUSE_SOCKETS
12
13 #include <stdlib.h>
14 #include <X11/Intrinsic.h>
15 #include "wx/gsocket.h"
16 #include "wx/unix/gsockunx.h"
17
18 extern "C" XtAppContext wxGetAppContext();
19
20 static void _GSocket_Motif_Input(XtPointer data, int *fid,
21 XtInputId *id)
22 {
23 GSocket *socket = (GSocket *)data;
24
25 socket->Detected_Read();
26 }
27
28 static void _GSocket_Motif_Output(XtPointer data, int *fid,
29 XtInputId *id)
30 {
31 GSocket *socket = (GSocket *)data;
32
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
52 socket->m_gui_dependent = (char *)malloc(sizeof(int)*2);
53 m_id = (int *)(socket->m_gui_dependent);
54
55 m_id[0] = -1;
56 m_id[1] = -1;
57
58 return true;
59 }
60
61 void GSocketGUIFunctionsTableConcrete::Destroy_Socket(GSocket *socket)
62 {
63 free(socket->m_gui_dependent);
64 }
65
66 void GSocketGUIFunctionsTableConcrete::Install_Callback(GSocket *socket, GSocketEvent event)
67 {
68 int *m_id = (int *)(socket->m_gui_dependent);
69 int c;
70
71 if (socket->m_fd == -1)
72 return;
73
74 switch (event)
75 {
76 case GSOCK_LOST: /* fall-through */
77 case GSOCK_INPUT: c = 0; break;
78 case GSOCK_OUTPUT: c = 1; break;
79 case GSOCK_CONNECTION: c = ((socket->m_server) ? 0 : 1); break;
80 default: return;
81 }
82
83 if (m_id[c] != -1)
84 XtRemoveInput(m_id[c]);
85
86 if (c == 0)
87 {
88 m_id[0] = XtAppAddInput(wxGetAppContext(), socket->m_fd,
89 (XtPointer *)XtInputReadMask,
90 (XtInputCallbackProc) _GSocket_Motif_Input,
91 (XtPointer) socket);
92 }
93 else
94 {
95 m_id[1] = XtAppAddInput(wxGetAppContext(), socket->m_fd,
96 (XtPointer *)XtInputWriteMask,
97 (XtInputCallbackProc) _GSocket_Motif_Output,
98 (XtPointer) socket);
99 }
100 }
101
102 void GSocketGUIFunctionsTableConcrete::Uninstall_Callback(GSocket *socket, GSocketEvent event)
103 {
104 int *m_id = (int *)(socket->m_gui_dependent);
105 int c;
106
107 switch (event)
108 {
109 case GSOCK_LOST: /* fall-through */
110 case GSOCK_INPUT: c = 0; break;
111 case GSOCK_OUTPUT: c = 1; break;
112 case GSOCK_CONNECTION: c = ((socket->m_server) ? 0 : 1); break;
113 default: return;
114 }
115
116 if (m_id[c] != -1)
117 XtRemoveInput(m_id[c]);
118
119 m_id[c] = -1;
120 }
121
122 void GSocketGUIFunctionsTableConcrete::Enable_Events(GSocket *socket)
123 {
124 Install_Callback(socket, GSOCK_INPUT);
125 Install_Callback(socket, GSOCK_OUTPUT);
126 }
127
128 void GSocketGUIFunctionsTableConcrete::Disable_Events(GSocket *socket)
129 {
130 Uninstall_Callback(socket, GSOCK_INPUT);
131 Uninstall_Callback(socket, GSOCK_OUTPUT);
132 }
133
134 #else /* !wxUSE_SOCKETS */
135
136 /* some compilers don't like having empty source files */
137 static int wxDummyGsockVar = 0;
138
139 #endif /* wxUSE_SOCKETS/!wxUSE_SOCKETS */