Debian Codegraph @

xpa/xtloop.c

raw symbols SCIP
1 /*
2 * Copyright (c) 1999-2003 Smithsonian Astrophysical Observatory
3 */
4
5 #include <xpap.h>
6
7 #if HAVE_XT
8
9 #include <X11/Intrinsic.h>
10
11 /*
12 *----------------------------------------------------------------------------
13 *
14 *
15 * Private Routines and Data
16 *
17 *
18 *----------------------------------------------------------------------------
19 */
20
21 /*
22 *
23 * record struct for maintining Xt info in Xt select loop
24 *
25 */
26 typedef struct xpaxtrec{
27 int fd;
28 void *client_data;
29 XtInputId id;
30 } *XPAXt, XPAXtRec;
31
32 /* its such a pain to maintain this, so make it global! */
33 static XtAppContext xpa_app=NULL;
34
35 /*
36 *----------------------------------------------------------------------------
37 *
38 * Routine: XPAXtHandler
39 *
40 * Purpose: handle one request for an xpaset or xpaget
41 *
42 * Return: none
43 *
44 *----------------------------------------------------------------------------
45 */
46 #ifdef ANSI_FUNC
47 static void
48 XPAXtHandler (XtPointer client_data, int *fd, XtInputId *id)
49 #else
50 static void XPAXtHandler(client_data, fd, id)
51 XtPointer client_data;
52 int *fd;
53 XtInputId *id;
54 #endif
55 {
56 XPAXt xptr = (XPAXt)client_data;
57 if( (xptr == NULL) || (xptr->client_data == NULL) )
58 return;
59 XPAHandler((XPA)xptr->client_data, xptr->fd);
60 }
61
62 /*
63 *----------------------------------------------------------------------------
64 *
65 * Routine: XPAXtEnableOneInput
66 *
67 * Purpose: Enable 1 XPA entry from the Xt event loop
68 *
69 * Results: none
70 *
71 *----------------------------------------------------------------------------
72 */
73 #ifdef ANSI_FUNC
74 static void
75 XPAXtEnableOneInput (void *client_data)
76 #else
77 static void XPAXtEnableOneInput(client_data)
78 void *client_data;
79 #endif
80 {
81 XPAXt xptr = (XPAXt)client_data;
82 if( xptr == NULL )
83 return;
84 if( xptr->id != (XtInputId)NULL )
85 return;
86 if( xpa_app == NULL ){
87 xptr->id = XtAddInput(xptr->fd,
88 (XtPointer)XtInputReadMask,
89 (XtInputCallbackProc)XPAXtHandler,
90 (XtPointer)xptr);
91 }
92 else{
93 xptr->id = XtAppAddInput(xpa_app, xptr->fd,
94 (XtPointer)XtInputReadMask,
95 (XtInputCallbackProc)XPAXtHandler,
96 (XtPointer)xptr);
97 }
98 }
99
100 /*
101 *----------------------------------------------------------------------------
102 *
103 * Routine: XPAXtDisableOneInput
104 *
105 * Purpose: Disable 1 XPA entry from the Xt event loop
106 *
107 * Results: none
108 *
109 *----------------------------------------------------------------------------
110 */
111 #ifdef ANSI_FUNC
112 static void
113 XPAXtDisableOneInput (void *client_data)
114 #else
115 static void XPAXtDisableOneInput(client_data)
116 void *client_data;
117 #endif
118 {
119 XPAXt xptr = (XPAXt)client_data;
120 if( xptr == NULL )
121 return;
122 if( xptr->id == (XtInputId)NULL )
123 return;
124 XtRemoveInput(xptr->id);
125 xptr->id = (XtInputId)NULL;
126 }
127
128 /*
129 *----------------------------------------------------------------------------
130 *
131 * Routine: XPAXtAddOneInput
132 *
133 * Purpose: Add 1 XPA entry to the Xt event loop
134 *
135 * Results: none
136 *
137 *----------------------------------------------------------------------------
138 */
139 #ifdef ANSI_FUNC
140 static void *
141 XPAXtAddOneInput (void *client_data, int fd)
142 #else
143 static void *XPAXtAddOneInput(client_data, fd)
144 void *client_data;
145 int fd;
146 #endif
147 {
148 XPAXt xptr;
149 if( fd < 0 )
150 return(NULL);
151 xptr = (XPAXt)xcalloc(1, sizeof(XPAXtRec));
152 xptr->fd = fd;
153 xptr->client_data = client_data;
154 XPAXtEnableOneInput(xptr);
155 return(xptr);
156 }
157
158 /*
159 *----------------------------------------------------------------------------
160 *
161 * Routine: XPAXtDelOneInput
162 *
163 * Purpose: Delete 1 XPA entry from the Xt event loop (called by XPAFree)
164 *
165 * Results: none
166 *
167 *----------------------------------------------------------------------------
168 */
169 #ifdef ANSI_FUNC
170 static void
171 XPAXtDelOneInput (void *client_data)
172 #else
173 static void XPAXtDelOneInput(client_data)
174 void *client_data;
175 #endif
176 {
177 XPAXt xptr = (XPAXt)client_data;
178 if( xptr == NULL)
179 return;
180 XPAXtDisableOneInput(xptr);
181 xfree(xptr);
182 }
183
184 /*
185 *----------------------------------------------------------------------------
186 *
187 *
188 * Public Routines and Data
189 *
190 *
191 *----------------------------------------------------------------------------
192 */
193
194 /*
195 *----------------------------------------------------------------------------
196 *
197 * Routine: XPAXtAddInput
198 *
199 * Purpose: Add XPA entries to the Xt event loop
200 *
201 * Results: number of xpa entried added
202 *
203 *----------------------------------------------------------------------------
204 */
205 #ifdef ANSI_FUNC
206 int
207 XPAXtAddInput (void *app, XPA xpa)
208 #else
209 int XPAXtAddInput(app, xpa)
210 void *app;
211 XPA xpa;
212 #endif
213 {
214 XPA cur;
215 int got=0;
216
217 /* save the app context */
218 if( xpa_app == NULL ){
219 xpa_app = (XtAppContext)app;
220 }
221
222 /* if a specific xpa was specified, just add it */
223 if( xpa != NULL ){
224 /* remove old one */
225 if( xpa->seldel && xpa->selptr ){
226 (xpa->seldel)(xpa->selptr);
227 }
228 /* add new one */
229 xpa->seldel = XPAXtDelOneInput;
230 xpa->seladd = XPAXtAddOneInput;
231 xpa->selon = XPAXtEnableOneInput;
232 xpa->seloff = XPAXtDisableOneInput;
233 xpa->selptr = XPAXtAddOneInput((void *)xpa, xpa->fd);
234 got = 1;
235 }
236 /* otherwise set up all xpa's */
237 else{
238 for(cur=(XPA)XPAListHead(); cur!=NULL; cur=cur->next){
239 /* remove old one */
240 if( cur->seldel && cur->selptr ){
241 (cur->seldel)(cur->selptr);
242 }
243 /* add new one */
244 cur->seldel = XPAXtDelOneInput;
245 cur->seladd = XPAXtAddOneInput;
246 cur->selon = XPAXtEnableOneInput;
247 cur->seloff = XPAXtDisableOneInput;
248 cur->selptr = XPAXtAddOneInput((void *)cur, cur->fd);
249 got++;
250 }
251 }
252 return(got);
253 }
254
255 int xpa_xt = 1;
256
257 #else
258
259 int xpa_xt = 0;
260
261 #endif