1
/* $Xorg: ReqMach.c,v 1.4 2001/02/09 02:05:28 xorgcvs Exp $ */
4
Copyright 1989, 1998 The Open Group
6
Permission to use, copy, modify, distribute, and sell this software and its
7
documentation for any purpose is hereby granted without fee, provided that
8
the above copyright notice appear in all copies and that both that
9
copyright notice and this permission notice appear in supporting
12
The above copyright notice and this permission notice shall be included
13
in all copies or substantial portions of the Software.
15
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
16
OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
17
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
18
IN NO EVENT SHALL THE OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR
19
OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
20
ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
21
OTHER DEALINGS IN THE SOFTWARE.
23
Except as contained in this notice, the name of The Open Group shall
24
not be used in advertising or otherwise to promote the sale, use or
25
other dealings in this Software without prior written authorization
29
/* $XFree86: ReqMach.c,v 1.4 2001/12/14 20:00:41 dawes Exp $ */
32
* Author: Davor Matic, MIT X Consortium
35
#include <X11/IntrinsicP.h>
36
#include <X11/StringDefs.h>
37
#include <X11/Xfuncs.h>
46
/*****************************************************************************\
47
* Request Machine: stacks up and handles requests from application calls. *
48
\*****************************************************************************/
51
* Searches for a request record of a request specified by its name.
52
* Returns a pointer to the record or NULL if the request was not found.
55
FindRequest(BWRequest name)
59
for (i = 0; i < bitmapClassRec.bitmap_class.num_requests; i++)
60
if (!strcmp(name, bitmapClassRec.bitmap_class.requests[i].name))
61
return &bitmapClassRec.bitmap_class.requests[i];
67
* Adds a request to the request stack and does proper initializations.
68
* Returns TRUE if the request was found and FALSE otherwise.
71
BWAddRequest(Widget w, BWRequest name, Boolean trap,
72
XtPointer call_data, Cardinal call_data_size)
74
BitmapWidget BW = (BitmapWidget) w;
75
BWRequestRec *request;
77
request = FindRequest(name);
80
fprintf(stderr, "Adding... Cardinal: %d\n", BW->bitmap.cardinal + 1);
82
BW->bitmap.request_stack = (BWRequestStack *)
83
XtRealloc((char *)BW->bitmap.request_stack,
84
(++BW->bitmap.cardinal + 1) * sizeof(BWRequestStack));
86
BW->bitmap.request_stack[BW->bitmap.cardinal].request = request;
87
BW->bitmap.request_stack[BW->bitmap.cardinal].status =
88
XtMalloc(request->status_size);
89
BW->bitmap.request_stack[BW->bitmap.cardinal].trap = trap;
90
BW->bitmap.request_stack[BW->bitmap.cardinal].call_data =
91
XtMalloc(call_data_size);
92
memmove( BW->bitmap.request_stack[BW->bitmap.cardinal].call_data,
99
XtWarning("bad request name. BitmapWidget");
105
* Engages the request designated by the current parameter.
106
* Returnes TRUE if the request has an engage function and FALSE otherwise.
109
Engage(BitmapWidget BW, Cardinal current)
111
BW->bitmap.current = current;
114
fprintf(stderr, "Request: %s\n",
115
BW->bitmap.request_stack[current].request->name);
117
if (BW->bitmap.request_stack[current].request->engage) {
118
(*BW->bitmap.request_stack[current].request->engage)
120
BW->bitmap.request_stack[current].status,
121
BW->bitmap.request_stack[current].request->engage_client_data,
122
BW->bitmap.request_stack[current].call_data);
129
/* Boolean BWTerminateRequest();
130
Boolean BWRemoveRequest(); */
133
* Scans down the request stack removing all requests untill it finds
137
TrappingLoop(BitmapWidget BW)
141
fprintf(stderr, "Scanning... Current: %d\n", BW->bitmap.current);
142
if ((BW->bitmap.current > 0)
144
(!BW->bitmap.request_stack[BW->bitmap.current--].trap)) {
145
BWRemoveRequest((Widget) BW);
149
if (BW->bitmap.cardinal > 0) {
151
fprintf(stderr, "Trapping... Current: %d\n", BW->bitmap.current+1);
152
if(!Engage(BW, ++BW->bitmap.current))
153
BWTerminateRequest((Widget) BW, True);
157
* Terimantes the current request and continues with next request if con = TRUE
158
* Returnes TRUE if there is any number of requests left on the stack.
161
BWTerminateRequest(Widget w, Boolean cont)
163
BitmapWidget BW = (BitmapWidget) w;
165
if (BW->bitmap.current > 0) {
167
fprintf(stderr, "Terminating... Current: %d\n", BW->bitmap.current);
168
if (BW->bitmap.request_stack[BW->bitmap.current].request->terminate)
169
(*BW->bitmap.request_stack[BW->bitmap.current].request->terminate)
171
BW->bitmap.request_stack[BW->bitmap.current].status,
172
BW->bitmap.request_stack[BW->bitmap.current].request->terminate_client_data);
175
if (BW->bitmap.current == BW->bitmap.cardinal)
179
fprintf(stderr, "Continuing... Current: %d\n", BW->bitmap.current+1);
180
if (!Engage(BW, ++BW->bitmap.current))
181
BWTerminateRequest(w, True);
185
BW->bitmap.current = 0;
188
return BW->bitmap.current;
192
* Simple interface to BWTerminateRequest that takes only a widget.
197
BWTerminateRequest(w, True);
201
* Removes the top request from the request stack. If the request is active
202
* it will terminate it.
203
* Returns TRUE if the number of requests left on the stack != 0.
206
BWRemoveRequest(Widget w)
208
BitmapWidget BW = (BitmapWidget) w;
210
if (BW->bitmap.cardinal > 0) {
212
fprintf(stderr, "Removing... Cardinal: %d\n", BW->bitmap.cardinal);
213
if (BW->bitmap.current == BW->bitmap.cardinal)
214
BWTerminateRequest(w, False);
216
if (BW->bitmap.request_stack[BW->bitmap.cardinal].request->remove)
217
(*BW->bitmap.request_stack[BW->bitmap.cardinal].request->remove)
219
BW->bitmap.request_stack[BW->bitmap.cardinal].status,
220
BW->bitmap.request_stack[BW->bitmap.cardinal].request->remove_client_data);
222
XtFree(BW->bitmap.request_stack[BW->bitmap.cardinal].status);
223
XtFree(BW->bitmap.request_stack[BW->bitmap.cardinal].call_data);
224
BW->bitmap.request_stack = (BWRequestStack *)
225
XtRealloc((char *)BW->bitmap.request_stack,
226
(--BW->bitmap.cardinal + 1) * sizeof(BWRequestStack));
235
BWRemoveAllRequests(Widget w)
237
while (BWRemoveRequest(w)) {/* removes all requests from the stack */}
241
* Adds the request to the stack and performs engaging ritual.
242
* Returns TRUE if the request was found, FALSE otherwise.
245
BWEngageRequest(Widget w, BWRequest name, Boolean trap,
246
XtPointer call_data, Cardinal call_data_size)
248
BitmapWidget BW = (BitmapWidget) w;
250
if (BWAddRequest(w, name, trap, call_data, call_data_size)) {
251
BWTerminateRequest(w, False);
253
fprintf(stderr, "Engaging... Cardinal: %d\n", BW->bitmap.cardinal);
254
if (!Engage(BW, BW->bitmap.cardinal))
255
BWTerminateRequest(w, True);
263
/************************* End of the Request Machine ************************/