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