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