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