summaryrefslogtreecommitdiff
path: root/Xext/xtest1di.c
blob: 47e60f6b6aa0fdcc48ce48c70841bfb792fac4b7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
/* $XdotOrg: xc/programs/Xserver/Xext/xtest1di.c,v 1.1.4.3.4.1 2004/03/04 17:47:20 eich Exp $ */
/* $Xorg: xtest1di.c,v 1.4 2001/02/09 02:04:33 xorgcvs Exp $ */
/*
 *	File:  xtest1di.c
 *
 *	This file contains the device independent parts of the input
 *	synthesis extension.
 */

/*


Copyright 1986, 1987, 1988, 1998  The Open Group

Permission to use, copy, modify, distribute, and sell this software and its
documentation for any purpose is hereby granted without fee, provided that
the above copyright notice appear in all copies and that both that
copyright notice and this permission notice appear in supporting
documentation.

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Except as contained in this notice, the name of The Open Group shall not be
used in advertising or otherwise to promote the sale, use or other dealings
in this Software without prior written authorization from The Open Group.


Copyright 1986, 1987, 1988 by Hewlett-Packard Corporation

Permission to use, copy, modify, and distribute this
software and its documentation for any purpose and without
fee is hereby granted, provided that the above copyright
notice appear in all copies and that both that copyright
notice and this permission notice appear in supporting
documentation, and that the name of Hewlett-Packard not be used in
advertising or publicity pertaining to distribution of the
software without specific, written prior permission.

Hewlett-Packard makes no representations about the 
suitability of this software for any purpose.  It is provided 
"as is" without express or implied warranty.

This software is not subject to any license of the American
Telephone and Telegraph Company or of the Regents of the
University of California.

*/
/* $XFree86: xc/programs/Xserver/Xext/xtest1di.c,v 3.5 2003/09/13 21:33:03 dawes Exp $ */

/*****************************************************************************
 * include files
 ****************************************************************************/

#define	 NEED_EVENTS
#define	 NEED_REPLIES

#include <stdio.h>
#include "X.h"
#include "Xproto.h"
#include "misc.h"
#include "os.h"
#include "gcstruct.h"   
#include "extnsionst.h"
#include "dixstruct.h"
#include "opaque.h"
#define  XTestSERVER_SIDE
#include "xtestext1.h"
#include "modinit.h"

#include "xtest1dd.h"

/*****************************************************************************
 * defines
 ****************************************************************************/

/*****************************************************************************
 * variables
 ****************************************************************************/

/*
 * Holds the request type code for this extension.  The request type code
 * for this extension may vary depending on how many extensions are installed
 * already, so the initial value given below will be added to the base request
 * code that is aquired when this extension is installed.
 */
static int 		XTestReqCode = 0;
/*
 * Holds the two event type codes for this extension.  The event type codes
 * for this extension may vary depending on how many extensions are installed
 * already, so the initial values given below will be added to the base event
 * code that is aquired when this extension is installed.
 */
int 			XTestInputActionType = 0;
int 			XTestFakeAckType = 1;
/*
 * true => monitor stealing input
 */
int			on_steal_input = FALSE;
/*
 * true => monitor alone getting input
 */
int			exclusive_steal = FALSE;
/*
 * holds the resource type assigned to this extension
 */
static RESTYPE		XTestType;
/*
 * holds the resource ID for the client currently using XTestGetInput
 */
static XID		current_client_id;

/*****************************************************************************
 * function declarations
 ****************************************************************************/

static DISPATCH_PROC(ProcXTestDispatch);
static DISPATCH_PROC(SProcXTestDispatch);
static DISPATCH_PROC(ProcTestFakeInput);
static DISPATCH_PROC(SProcTestFakeInput);
static DISPATCH_PROC(ProcTestGetInput);
static DISPATCH_PROC(SProcTestGetInput);
static DISPATCH_PROC(ProcTestStopInput);
static DISPATCH_PROC(SProcTestStopInput);
static DISPATCH_PROC(ProcTestReset);
static DISPATCH_PROC(SProcTestReset);
static DISPATCH_PROC(ProcTestQueryInputSize);
static DISPATCH_PROC(SProcTestQueryInputSize);

static void	XTestResetProc(
	ExtensionEntry *	/* unused */
	);
static void	SReplyXTestDispatch(
	ClientPtr		/* client_ptr */,
	int			/* size */,
	char *			/* reply_ptr */
	);
static void	SEventXTestDispatch(
	xEvent *		/* from */,
	xEvent *		/* to */
	);

static int	XTestCurrentClientGone(
	pointer			/* value */,
	XID			/* id */
	);

/*****************************************************************************
 *
 *	XTestExtension1Init
 *
 *	Called from InitExtensions in main() or from QueryExtension() if the
 *	extension is dynamically loaded.
 *
 *	XTestExtension1Init has no events or errors
 *	(other than the core errors).
 */
void
XTestExtension1Init(INITARGS)
{
	/*
	 * holds the pointer to the extension entry structure
	 */
	ExtensionEntry	*extEntry;

	extEntry = AddExtension(XTestEXTENSION_NAME,
				XTestEVENT_COUNT,
				0,
				ProcXTestDispatch,
				SProcXTestDispatch,
				XTestResetProc,
				StandardMinorOpcode);
	if (extEntry)
	{
		/*
		 * remember the request code assigned to this extension
		 */
		XTestReqCode = extEntry->base;
		/*
		 * make an atom saying that this extension is present
		 */
		(void) MakeAtom(XTestEXTENSION_NAME,
				strlen(XTestEXTENSION_NAME),
				TRUE);
		/*
		 * remember the event codes assigned to this extension
		 */
		XTestInputActionType += extEntry->eventBase;
		XTestFakeAckType += extEntry->eventBase;
		/*
		 * install the routine to handle byte-swapping the replies
		 * for this extension in the ReplySwapVector table
		 */
		ReplySwapVector[XTestReqCode] = (ReplySwapPtr) SReplyXTestDispatch;
		/*
		 * install the routine to handle byte-swapping the events
		 * for this extension in the EventSwapVector table
		 */
		EventSwapVector[XTestInputActionType] = SEventXTestDispatch;
		EventSwapVector[XTestFakeAckType] = SEventXTestDispatch;
		/*
		 * get the resource type for this extension
		 */
		XTestType = CreateNewResourceType(XTestCurrentClientGone);
		if (XTestType == 0)
		{
			FatalError("XTestExtension1Init: CreateNewResourceType failed\n");
		}
	} 
	else 
	{
		FatalError("XTestExtension1Init: AddExtensions failed\n");
	}
}

/*****************************************************************************
 *
 *	ProcXTestDispatch
 *
 *
 */
static int
ProcXTestDispatch(client)
	register ClientPtr	client;
{
	REQUEST(xReq);
	if (stuff->data == X_TestFakeInput)
	{
		return(ProcTestFakeInput(client));
	}
	else if (stuff->data == X_TestGetInput)
	{
		return(ProcTestGetInput(client));
	}
	else if (stuff->data == X_TestStopInput)
	{
		return(ProcTestStopInput(client));
	}
	else if (stuff->data == X_TestReset)
	{
		return(ProcTestReset(client));
	}
	else if (stuff->data == X_TestQueryInputSize)
	{
		return(ProcTestQueryInputSize(client));
	}
	else
	{
		SendErrorToClient(client,
				  XTestReqCode,
				  stuff->data,
				  None,
				  BadRequest);
		return(BadRequest);
	}
}

/*****************************************************************************
 *
 *	SProcXTestDispatch
 *
 *
 */
static int
SProcXTestDispatch(client)
	register ClientPtr	client;
{
	REQUEST(xReq);
	if (stuff->data == X_TestFakeInput)
	{
		return(SProcTestFakeInput(client));
	}
	else if (stuff->data == X_TestGetInput)
	{
		return(SProcTestGetInput(client));
	}
	else if (stuff->data == X_TestStopInput)
	{
		return(SProcTestStopInput(client));
	}
	else if (stuff->data == X_TestReset)
	{
		return(SProcTestReset(client));
	}
	else if (stuff->data == X_TestQueryInputSize)
	{
		return(SProcTestQueryInputSize(client));
	}
	else
	{
		SendErrorToClient(client,
				  XTestReqCode,
				  stuff->data,
				  None,
				  BadRequest);
		return(BadRequest);
	}
}

/*****************************************************************************
 *
 *	SProcTestFakeInput
 *
 *
 */
static int
SProcTestFakeInput(client)
	register ClientPtr	client;
{
	/*
	 * used in the swaps and swapl macros for temporary storage space
	 */
	register char	n;
	/*
	 * index counter
	 */
	int		i;
	/*
	 * pointer to the next input action in the request
	 */
	CARD8		*input_action_ptr;
	/*
	 * holds the type of the next input action in the request
	 */
	int		input_action_type;

	REQUEST(xTestFakeInputReq);
	/*
	 * byte-swap the fields in the request
	 */
	swaps(&stuff->length, n);
	swapl(&stuff->ack, n);
	/*
	 * have to parse and then byte-swap the input action list here
	 */
	for (i = 0; i < XTestMAX_ACTION_LIST_SIZE;)
	{
		/*
		 * point to the next input action in the request
		 */
		input_action_ptr = &(((xTestFakeInputReq *) stuff)->action_list[i]);
		/*
		 * figure out what type of input action it is
		 */
		input_action_type = (*input_action_ptr) & XTestACTION_TYPE_MASK;
		/*
		 * byte-swap the input action according to it's type
		 */
		switch (input_action_type)
		{
		case XTestKEY_ACTION:
			/*
			 * byte-swap the delay_time field
			 */
			swaps(&(((XTestKeyInfo *) input_action_ptr)->delay_time), n);
			/*
			 * advance to the next input action
			 */
			i += sizeof(XTestKeyInfo);
			break;
		case XTestMOTION_ACTION:
			/*
			 * byte-swap the delay_time field
			 */
			swaps(&(((XTestMotionInfo *) input_action_ptr)->delay_time), n);
			/*
			 * advance to the next input action
			 */
			i += sizeof(XTestMotionInfo);
			break;
		case XTestJUMP_ACTION:
			/*
			 * byte-swap the jumpx field
			 */
			swaps(&(((XTestJumpInfo *) input_action_ptr)->jumpx), n);
			/*
			 * byte-swap the jumpy field
			 */
			swaps(&(((XTestJumpInfo *) input_action_ptr)->jumpy), n);
			/*
			 * byte-swap the delay_time field
			 */
			swaps(&(((XTestJumpInfo *) input_action_ptr)->delay_time), n);
			/*
			 * advance to the next input action
			 */
			i += sizeof(XTestJumpInfo);
			break;
		default:
			/*
			 * if this is a delay input action, then byte-swap it,
			 * otherwise we have reached the end of the input
			 * actions in this request
			 */
			if (XTestUnpackDeviceID(*input_action_ptr) ==
			    XTestDELAY_DEVICE_ID)
			{
				/*
				 * byte-swap the delay_time field
				 */
				swapl(&(((XTestDelayInfo *) input_action_ptr)->delay_time), n);
				/*
				 * advance to the next input action
				 */
				i += sizeof(XTestDelayInfo);
			}
			else
			{
				/*
				 * if the input action header byte is 0 or
				 * ill-formed, then there are no more input
				 * actions in this request
				 */
				i = XTestMAX_ACTION_LIST_SIZE;
			}
			break;
		}
	}
	return(ProcTestFakeInput(client));
}

/*****************************************************************************
 *
 *	SProcTestGetInput
 *
 *
 */
static int
SProcTestGetInput(client)
	register ClientPtr	client;
{
	/*
	 * used in the swaps and swapl macros for temporary storage space
	 */
	register char	n;

	REQUEST(xTestGetInputReq);
	/*
	 * byte-swap the fields in the request
	 */
	swaps(&stuff->length, n);
	swapl(&stuff->mode, n);
	return(ProcTestGetInput(client));
}

/*****************************************************************************
 *
 *	SProcTestStopInput
 *
 *
 */
static int
SProcTestStopInput(client)
	register ClientPtr	client;
{
	/*
	 * used in the swaps and swapl macros for temporary storage space
	 */
	register char	n;

	REQUEST(xTestStopInputReq);
	/*
	 * byte-swap the length field in the request
	 */
	swaps(&stuff->length, n);
	return(ProcTestStopInput(client));
}

/*****************************************************************************
 *
 *	SProcTestReset
 *
 *
 */
static int
SProcTestReset(client)
	register ClientPtr	client;
{
	/*
	 * used in the swaps and swapl macros for temporary storage space
	 */
	register char	n;

	REQUEST(xTestResetReq);
	/*
	 * byte-swap the length field in the request
	 */
	swaps(&stuff->length, n);
	return(ProcTestReset(client));
}

/*****************************************************************************
 *
 *	SProcTestQueryInputSize
 *
 *
 */
static int
SProcTestQueryInputSize(client)
	register ClientPtr	client;
{
	/*
	 * used in the swaps and swapl macros for temporary storage space
	 */
	register char	n;

	REQUEST(xTestQueryInputSizeReq);
	/*
	 * byte-swap the length field in the request
	 */
	swaps(&stuff->length, n);
	return(ProcTestQueryInputSize(client));
}

/*****************************************************************************
 *
 *	ProcTestFakeInput
 *
 *
 */
static int
ProcTestFakeInput(client)
	register ClientPtr	client;
{
	REQUEST(xTestFakeInputReq);
	REQUEST_SIZE_MATCH(xTestFakeInputReq);

	if (playback_client == NULL)
	    {
	    playback_client = client;
	    current_client_id = FakeClientID(client->index);
	    AddResource(current_client_id,
		    XTestType,
		    0);
	    MakeClientGrabImpervious(client);
	    }
	if (playback_client == client)
	{
		/*
		 * This extension does not need to clean up any
		 * server state when a client using this function
		 * "goes away".  The server will just process any
		 * input actions that have already been sent to it,
		 * and will then reset its association with a client.
		 */
		parse_fake_input(client, (char *)stuff);
		return(Success);
	}
	else
	{
		/*
		 * this is a request by another client to send fake
		 * input while the server is still being used
		 */
		SendErrorToClient(client,
				  XTestReqCode,
				  X_TestFakeInput,
				  None,
				  BadAccess);
		return(BadAccess);
	}
}

/*****************************************************************************
 *
 *	ProcTestGetInput
 *
 *
 */
static int
ProcTestGetInput(client)
	register ClientPtr	client;
{
	REQUEST(xTestGetInputReq);
	REQUEST_SIZE_MATCH(xTestGetInputReq);
	if (on_steal_input)
	{
		/*
		 * this is a request by another client to get fake input
		 * while the server is still sending input to the first client
		 */
		SendErrorToClient(client,
				  XTestReqCode,
				  X_TestGetInput,
				  None,
				  BadAccess);
		return(BadAccess);
	}
	else
	{ 
		/*
		 * Set up a resource associated with the client using this
		 * function so that this extension gets called when the 
		 * client "goes away".  This allows this extension to
		 * clean up the server state.
		 */
		current_client_id = FakeClientID(client->index);
		AddResource(current_client_id,
			    XTestType,
			    0);
		/*
		 * indicate that a client is stealing input
		 */
		on_steal_input = TRUE;
		if ((stuff->mode & XTestEXCLUSIVE) == 0)
		{
			exclusive_steal = FALSE;
		}
		else 
		{
			exclusive_steal = TRUE;
		}
		steal_input(client, stuff->mode);
		return(Success);
	}
}

/*****************************************************************************
 *
 *	ProcTestStopInput
 *
 *
 */
static int
ProcTestStopInput(client)
	register ClientPtr	client;
{
	REQUEST_SIZE_MATCH(xTestStopInputReq);
	if (on_steal_input && (current_xtest_client == client)) 
	{ 
		on_steal_input = FALSE;
		exclusive_steal = FALSE;
		stop_stealing_input();	
		/*
		 * remove the resource associated with this client
		 */
		FreeResource(current_client_id, RT_NONE);
		return(Success);
	}
	else
	{
		/*
		 * this is a request to stop fake input when fake input has
		 * never been started or from a client that hasn't started
		 * fake input
		 */
		SendErrorToClient(client,
				  XTestReqCode,
				  X_TestStopInput,
				  None,
				  BadAccess);
		return(BadAccess);
	}
}

/*****************************************************************************
 *
 *	ProcTestReset
 *
 *
 */
static int
ProcTestReset(client)
	register ClientPtr	client;
{
	REQUEST_SIZE_MATCH(xTestResetReq);
	on_steal_input = FALSE;
	exclusive_steal = FALSE;
	/*
	 * defined in xtest1dd.c
	 */
	stop_stealing_input();	
	/*
	 * defined in xtest1dd.c
	 */
	abort_play_back();
	return(Success);
}

/*****************************************************************************
 *
 *	ProcTestQueryInputSize
 *
 *
 */
static int
ProcTestQueryInputSize(client)
	register ClientPtr	client;
{
	REQUEST_SIZE_MATCH(xTestQueryInputSizeReq);
	/*
	 * defined in xtest1dd.c
	 */
	return_input_array_size(client);
	return(Success);
}

/*****************************************************************************
 *
 *	XTestResetProc
 *
 *	This function is called by the server when the server has no clients
 *	connected to it.  It must put eveything back the way it was before
 *	this extension was installed.
 */
/*ARGSUSED*/
static void
XTestResetProc(unused)
	ExtensionEntry * unused;
{
	/*
	 * remove the routine to handle byte-swapping the replies
	 * for this extension in the ReplySwapVector table
	 */
	ReplySwapVector[XTestReqCode] = ReplyNotSwappd;
	/*
	 * remove the routine to handle byte-swapping the events
	 * for this extension in the EventSwapVector table
	 */
	EventSwapVector[XTestInputActionType] = NotImplemented;
	EventSwapVector[XTestFakeAckType] = NotImplemented;
	/*
	 * reset the variables initialized just once at load time
	 */
	XTestReqCode = 0;
	XTestInputActionType = 0;
	XTestFakeAckType = 1;
	on_steal_input = FALSE;
	exclusive_steal = FALSE;
	playback_client = 0;	/* Don't really need this but it looks nice */
}

/*****************************************************************************
 *
 *	PXTestCurrentClientGone
 *
 *	This routine is called when a client that has asked for input actions
 *	to be sent to it "goes away".  This routine must clean up the 
 *	server state.
 */
/*ARGSUSED*/
static int
XTestCurrentClientGone(value, id)
	pointer	value;
	XID	id;
{
	/*
	 * defined in xtest1dd.c
	 */
	on_steal_input = FALSE;
	exclusive_steal = FALSE;
	/*
	 * defined in xtestdd.c
	 */
	playback_client = 0;
	abort_play_back();
	return TRUE;
}

/*****************************************************************************
 *
 *	SReplyXTestDispatch
 *
 *	Swap any replies defined in this extension.
 */
static void
SReplyXTestDispatch(client_ptr, size, reply_ptr)
	ClientPtr	client_ptr;
	int		size;
	char		*reply_ptr;
{
	/*
	 * used in the swaps and swapl macros for temporary storage space
	 */
	register char	n;
	/*
	 * pointer to xTestQueryInputSizeReply
	 */
	xTestQueryInputSizeReply	*rep_ptr;

	/*
	 * there is only one reply in this extension, so byte-swap it
	 */
	rep_ptr = (xTestQueryInputSizeReply *) reply_ptr;
	swaps(&(rep_ptr->sequenceNumber), n);
	swapl(&(rep_ptr->length), n);
	swapl(&(rep_ptr->size_return), n);
	/*
	 * now write the swapped reply to the client
	 */
	WriteToClient(client_ptr, size, reply_ptr);
}

/*****************************************************************************
 *
 *	SEventXTestDispatch
 *
 *	Swap any events defined in this extension.
 */
static void
SEventXTestDispatch(from, to)
	xEvent	*from;
	xEvent	*to;
{
	/*
	 * used in the swaps and swapl macros for temporary storage space
	 */
	register char	n;
	/*
	 * index counter
	 */
	int		i;
	/*
	 * pointer to the next input action in the event
	 */
	CARD8		*input_action_ptr;
	/*
	 * holds the type of the next input action in the event
	 */
	int		input_action_type;


	/*
	 * copy the type information from the "from" event to the "to" event
	 */
	((xTestInputActionEvent *) to)->type =
	((xTestInputActionEvent *) from)->type;
	/*
	 * copy the sequence number information from the "from" event to the
	 * "to" event
	 */
	((xTestInputActionEvent *) to)->sequenceNumber =
	((xTestInputActionEvent *) from)->sequenceNumber;
	/*
	 * byte-swap the sequence number in the "to" event
	 */
	swaps(&(((xTestInputActionEvent *) to)->sequenceNumber), n);
	/*
	 * If the event is an xTestInputActionEvent, then it needs more
	 * processing.  Otherwise, it is an xTestFakeAckEvent, which
	 * has no other information in it.
	 */
	if ((((xTestInputActionEvent *) to)->type & 0x7f) ==
	    XTestInputActionType)
	{
		/*
		 * copy the input actions from the "from" event
		 * to the "to" event
		 */
		for (i = 0; i < XTestACTIONS_SIZE; i++)
		{
			((xTestInputActionEvent *) to)->actions[i] =
			((xTestInputActionEvent *) from)->actions[i];
		}
		/*
		 * byte-swap the input actions in the "to" event
		 */
		for (i = 0; i < XTestACTIONS_SIZE; i++)
		{
			/*
			 * point to the next input action in the event
			 */
			input_action_ptr = &(((xTestInputActionEvent *) to)->actions[i]);
			/*
			 * figure out what type of input action it is
			 */
			input_action_type = (*input_action_ptr) &
					    XTestACTION_TYPE_MASK;
			/*
			 * byte-swap the input action according to it's type
			 */
			switch (input_action_type)
			{
			case XTestKEY_ACTION:
				/*
				 * byte-swap the delay_time field
				 */
				swaps(&(((XTestKeyInfo *) input_action_ptr)->delay_time), n);
				/*
				 * advance to the next input action
				 */
				i += sizeof(XTestKeyInfo);
				break;
			case XTestMOTION_ACTION:
				/*
				 * byte-swap the delay_time field
				 */
				swaps(&(((XTestMotionInfo *) input_action_ptr)->delay_time), n);
				/*
				 * advance to the next input action
				 */
				i += sizeof(XTestMotionInfo);
				break;
			case XTestJUMP_ACTION:
				/*
				 * byte-swap the jumpx field
				 */
				swaps(&(((XTestJumpInfo *) input_action_ptr)->jumpx), n);
				/*
				 * byte-swap the jumpy field
				 */
				swaps(&(((XTestJumpInfo *) input_action_ptr)->jumpy), n);
				/*
				 * byte-swap the delay_time field
				 */
				swaps(&(((XTestJumpInfo *) input_action_ptr)->delay_time), n);
				/*
				 * advance to the next input action
				 */
				i += sizeof(XTestJumpInfo);
				break;
			default:
				/*
				 * if this is a delay input action, then
				 * byte-swap it, otherwise we have reached the
				 * end of the input actions in this event
				 */
				if (XTestUnpackDeviceID(*input_action_ptr) ==
				    XTestDELAY_DEVICE_ID)
				{
					/*
					 * byte-swap the delay_time field
					 */
					swapl(&(((XTestDelayInfo *) input_action_ptr)->delay_time), n);
					/*
					 * advance to the next input action
					 */
					i += sizeof(XTestDelayInfo);
				}
				else
				{
					/*
					 * if the input action header byte is 0
					 * or ill-formed, then there are no
					 * more input actions in this event
					 */
					i = XTestACTIONS_SIZE;
				}
				break;
			}
		}
	}
}