]> git.saurik.com Git - wxWidgets.git/blame - src/motif/gsockmot.cpp
Fix wxCRT_GetenvW WXDLLEXPORT. Use more efficient preincrement operator on iterators.
[wxWidgets.git] / src / motif / gsockmot.cpp
CommitLineData
355b4d3d
WS
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/////////////////////////////////////////////////////////////////////////////
793ba541 8
355b4d3d
WS
9// For compilers that support precompilation, includes "wx.h".
10#include "wx/wxprec.h"
793ba541
DE
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
0a647691 19extern "C" XtAppContext wxGetAppContext();
793ba541 20
355b4d3d
WS
21static void _GSocket_Motif_Input(XtPointer data, int *WXUNUSED(fid),
22 XtInputId *WXUNUSED(id))
793ba541 23{
355b4d3d 24 GSocket *socket = (GSocket *)data;
793ba541 25
355b4d3d 26 socket->Detected_Read();
793ba541
DE
27}
28
355b4d3d
WS
29static void _GSocket_Motif_Output(XtPointer data, int *WXUNUSED(fid),
30 XtInputId *WXUNUSED(id))
793ba541 31{
355b4d3d 32 GSocket *socket = (GSocket *)data;
793ba541 33
355b4d3d 34 socket->Detected_Write();
793ba541
DE
35}
36
0a647691 37bool GSocketGUIFunctionsTableConcrete::CanUseEventLoop()
355b4d3d
WS
38{
39 return true;
40}
0a647691
DE
41
42bool GSocketGUIFunctionsTableConcrete::OnInit(void)
793ba541
DE
43{
44 return 1;
45}
46
0a647691 47void GSocketGUIFunctionsTableConcrete::OnExit(void)
793ba541
DE
48{
49}
50
0a647691 51bool GSocketGUIFunctionsTableConcrete::Init_Socket(GSocket *socket)
793ba541 52{
355b4d3d 53 int *m_id;
793ba541 54
355b4d3d
WS
55 socket->m_gui_dependent = (char *)malloc(sizeof(int)*2);
56 m_id = (int *)(socket->m_gui_dependent);
793ba541 57
355b4d3d
WS
58 m_id[0] = -1;
59 m_id[1] = -1;
793ba541 60
355b4d3d 61 return true;
793ba541
DE
62}
63
0a647691 64void GSocketGUIFunctionsTableConcrete::Destroy_Socket(GSocket *socket)
793ba541 65{
355b4d3d 66 free(socket->m_gui_dependent);
793ba541
DE
67}
68
0a647691 69void GSocketGUIFunctionsTableConcrete::Install_Callback(GSocket *socket, GSocketEvent event)
793ba541 70{
355b4d3d
WS
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 }
793ba541
DE
103}
104
0a647691 105void GSocketGUIFunctionsTableConcrete::Uninstall_Callback(GSocket *socket, GSocketEvent event)
793ba541 106{
355b4d3d
WS
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;
793ba541
DE
123}
124
0a647691 125void GSocketGUIFunctionsTableConcrete::Enable_Events(GSocket *socket)
793ba541 126{
355b4d3d
WS
127 Install_Callback(socket, GSOCK_INPUT);
128 Install_Callback(socket, GSOCK_OUTPUT);
793ba541
DE
129}
130
0a647691 131void GSocketGUIFunctionsTableConcrete::Disable_Events(GSocket *socket)
793ba541 132{
355b4d3d
WS
133 Uninstall_Callback(socket, GSOCK_INPUT);
134 Uninstall_Callback(socket, GSOCK_OUTPUT);
793ba541
DE
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 */