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