]>
Commit | Line | Data |
---|---|---|
dbd300df GL |
1 | // ------------------------------------------------------------------------- |
2 | // Project: GSocket (Generic Socket) for WX | |
3 | // Name: gsockmot.cpp | |
4 | // Purpose: GSocket: Motif part | |
5 | // CVSID: $Id$ | |
dbd300df | 6 | // ------------------------------------------------------------------------- |
813c20a6 VZ |
7 | |
8 | #include "wx/setup.h" | |
9 | ||
10 | #if wxUSE_SOCKETS | |
11 | ||
dbd300df GL |
12 | #include <stdlib.h> |
13 | #include <X11/Intrinsic.h> | |
483249fc GRG |
14 | #include "wx/gsocket.h" |
15 | #include "wx/app.h" | |
16 | #include "wx/unix/gsockunx.h" | |
dbd300df GL |
17 | |
18 | #define wxAPP_CONTEXT ((XtAppContext)wxTheApp->GetAppContext()) | |
19 | ||
20 | static 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 | ||
28 | static 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 | ||
36 | void _GSocket_GUI_Init(GSocket *socket) | |
37 | { | |
38 | int i; | |
39 | int *m_id; | |
40 | ||
483249fc | 41 | socket->m_gui_dependent = (char *)malloc(sizeof(int)*2); |
dbd300df GL |
42 | m_id = (int *)(socket->m_gui_dependent); |
43 | ||
483249fc GRG |
44 | m_id[0] = -1; |
45 | m_id[1] = -1; | |
dbd300df GL |
46 | } |
47 | ||
48 | void _GSocket_GUI_Destroy(GSocket *socket) | |
49 | { | |
dbd300df GL |
50 | free(socket->m_gui_dependent); |
51 | } | |
52 | ||
39b91eca | 53 | void _GSocket_Install_Callback(GSocket *socket, GSocketEvent event) |
dbd300df | 54 | { |
483249fc GRG |
55 | int *m_id = (int *)(socket->m_gui_dependent); |
56 | int c; | |
dbd300df | 57 | |
483249fc GRG |
58 | if (socket->m_fd == -1) |
59 | return; | |
dbd300df | 60 | |
483249fc GRG |
61 | switch (event) |
62 | { | |
63 | case GSOCK_LOST: /* fall-through */ | |
64 | case GSOCK_INPUT: c = 0; break; | |
65 | case GSOCK_OUTPUT: c = 1; break; | |
66 | case GSOCK_CONNECTION: c = ((socket->m_server) ? 0 : 1); break; | |
67 | default: return; | |
68 | } | |
69 | ||
70 | if (m_id[c] != -1) | |
71 | XtRemoveInput(m_id[c]); | |
72 | ||
73 | if (c == 0) | |
74 | { | |
dbd300df GL |
75 | m_id[0] = XtAppAddInput(wxAPP_CONTEXT, socket->m_fd, |
76 | (XtPointer *)XtInputReadMask, | |
77 | (XtInputCallbackProc) _GSocket_Motif_Input, | |
78 | (XtPointer) socket); | |
483249fc GRG |
79 | } |
80 | else | |
81 | { | |
dbd300df GL |
82 | m_id[1] = XtAppAddInput(wxAPP_CONTEXT, socket->m_fd, |
83 | (XtPointer *)XtInputWriteMask, | |
84 | (XtInputCallbackProc) _GSocket_Motif_Output, | |
85 | (XtPointer) socket); | |
dbd300df GL |
86 | } |
87 | } | |
88 | ||
39b91eca | 89 | void _GSocket_Uninstall_Callback(GSocket *socket, GSocketEvent event) |
dbd300df | 90 | { |
483249fc | 91 | int *m_id = (int *)(socket->m_gui_dependent); |
dbd300df | 92 | int c; |
dbd300df | 93 | |
483249fc GRG |
94 | switch (event) |
95 | { | |
96 | case GSOCK_LOST: /* fall-through */ | |
97 | case GSOCK_INPUT: c = 0; break; | |
98 | case GSOCK_OUTPUT: c = 1; break; | |
99 | case GSOCK_CONNECTION: c = ((socket->m_server) ? 0 : 1); break; | |
100 | default: return; | |
dbd300df GL |
101 | } |
102 | ||
103 | if (m_id[c] != -1) | |
104 | XtRemoveInput(m_id[c]); | |
105 | ||
106 | m_id[c] = -1; | |
107 | } | |
108 | ||
483249fc | 109 | void _GSocket_Enable_Events(GSocket *socket) |
dbd300df | 110 | { |
483249fc GRG |
111 | _GSocket_Install_Callback(socket, GSOCK_INPUT); |
112 | _GSocket_Install_Callback(socket, GSOCK_OUTPUT); | |
dbd300df GL |
113 | } |
114 | ||
483249fc | 115 | void _GSocket_Disable_Events(GSocket *socket) |
dbd300df | 116 | { |
483249fc GRG |
117 | _GSocket_Uninstall_Callback(socket, GSOCK_INPUT); |
118 | _GSocket_Uninstall_Callback(socket, GSOCK_OUTPUT); | |
dbd300df | 119 | } |
813c20a6 VZ |
120 | |
121 | #endif // wxUSE_SOCKETS |