remove fprintf/printf
[adaptation/xorg/driver/xserver-xorg-module-xdbg.git] / common / xdbg_evlog_core.c
1 /**************************************************************************
2
3 xdbg
4
5 Copyright (c) 2013 Samsung Electronics Co., Ltd All Rights Reserved
6
7 Contact: Boram Park <boram1288.park@samsung.com>
8          Sangjin LEE <lsj119@samsung.com>
9
10 Permission is hereby granted, free of charge, to any person obtaining a
11 copy of this software and associated documentation files (the
12 "Software"), to deal in the Software without restriction, including
13 without limitation the rights to use, copy, modify, merge, publish,
14 distribute, sub license, and/or sell copies of the Software, and to
15 permit persons to whom the Software is furnished to do so, subject to
16 the following conditions:
17
18 The above copyright notice and this permission notice (including the
19 next paragraph) shall be included in all copies or substantial portions
20 of the Software.
21
22 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
23 OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
24 MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
25 IN NO EVENT SHALL PRECISION INSIGHT AND/OR ITS SUPPLIERS BE LIABLE FOR
26 ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
27 TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
28 SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
29
30 **************************************************************************/
31
32 #ifdef HAVE_CONFIG_H
33 #include "config.h"
34 #endif
35
36 #include <stdio.h>
37 #include <string.h>
38 #include <strings.h>
39 #include <sys/types.h>
40 #include <sys/fcntl.h>
41 #include <unistd.h>
42 #include <stdarg.h>
43 #include <fcntl.h>
44 #include <unistd.h>
45
46 #include <dix.h>
47 #define XREGISTRY
48 #include <registry.h>
49 #include <xace.h>
50 #include <xacestr.h>
51 #include <X11/Xatom.h>
52 #include <X11/Xlib.h>
53 #include <windowstr.h>
54 #include <X11/extensions/XI2proto.h>
55
56 #include "xdbg_types.h"
57 #include "xdbg_evlog_core.h"
58
59 char * xDbgEvlogRequestCore (xReq *req, char *reply, int *len)
60 {
61     xReq *stuff = req;
62
63     switch (stuff->reqType)
64     {
65     case X_CreateWindow:
66         {
67             xCreateWindowReq *stuff = (xCreateWindowReq *)req;
68
69             REPLY (": Window(0x%lx) Parent(0x%lx) size(%dx%d) boaderWid(%d) coordinate(%d,%d)",
70                 stuff->wid,
71                 stuff->parent,
72                 stuff->width,
73                 stuff->height,
74                 stuff->borderWidth,
75                 stuff->x,
76                 stuff->y);
77
78             return reply;
79         }
80
81     case X_ChangeWindowAttributes:
82         {
83             xChangeWindowAttributesReq *stuff = (xChangeWindowAttributesReq *)req;
84             REPLY (": XID(0x%lx)",
85                 stuff->window);
86
87             return reply;
88         }
89
90     case X_ChangeSaveSet:
91         {
92             xChangeSaveSetReq *stuff = (xChangeSaveSetReq *)req;
93             REPLY (": XID(0x%lx)",
94                 stuff->window);
95
96             return reply;
97         }
98
99     case X_ReparentWindow:
100         {
101             xReparentWindowReq *stuff = (xReparentWindowReq *)req;
102             REPLY (": Window(0x%lx) Parent(0x%lx) coord(%d,%d)",
103                 stuff->window,
104                 stuff->parent,
105                 stuff->x,
106                 stuff->y);
107
108             return reply;
109         }
110
111     case X_ConfigureWindow:
112         {
113             xConfigureWindowReq *stuff = (xConfigureWindowReq *)req;
114             REPLY (": XID(0x%lx)",
115                 stuff->window);
116
117             return reply;
118         }
119
120     case X_CirculateWindow:
121         {
122             xCirculateWindowReq *stuff = (xCirculateWindowReq *)req;
123             REPLY (": XID(0x%lx)",
124                 stuff->window);
125
126             return reply;
127         }
128
129     case X_ChangeProperty:
130         {
131             xChangePropertyReq *stuff = (xChangePropertyReq *)req;
132             REPLY (": XID(0x%lx) Property(0x%lx) Type(0x%lx)",
133                 stuff->window,
134                 stuff->property,
135                 stuff->type);
136
137             return reply;
138         }
139
140     case X_DeleteProperty:
141         {
142             xDeletePropertyReq *stuff = (xDeletePropertyReq *)req;
143             REPLY (": XID(0x%lx) Property(0x%lx)",
144                 stuff->window,
145                 stuff->property);
146
147             return reply;
148         }
149
150     case X_SetSelectionOwner:
151         {
152             xSetSelectionOwnerReq *stuff = (xSetSelectionOwnerReq *)req;
153             REPLY (": XID(0x%lx) Selection(0x%lx)",
154                 stuff->window,
155                 stuff->selection);
156
157             return reply;
158         }
159
160     case X_ConvertSelection:
161         {
162             xConvertSelectionReq *stuff = (xConvertSelectionReq *)req;
163             REPLY (": XID(0x%lx) Selection(0x%lx) Target(0x%lx) Property(0x%lx)",
164                 stuff->requestor,
165                 stuff->selection,
166                 stuff->target,
167                 stuff->property);
168
169             return reply;
170         }
171
172     case X_SendEvent:
173         {
174             xSendEventReq *stuff = (xSendEventReq *)req;
175             REPLY (": XID(0x%lx)",
176                 stuff->destination);
177
178             return reply;
179         }
180
181     case X_GrabPointer:
182         {
183             xGrabPointerReq *stuff = (xGrabPointerReq *)req;
184             REPLY (": XID(0x%lx) ConfineTo(0x%lx) Cursor(0x%lx)",
185                 stuff->grabWindow,
186                 stuff->confineTo,
187                 stuff->cursor);
188
189             return reply;
190         }
191
192     case X_GrabButton:
193         {
194             xGrabButtonReq *stuff = (xGrabButtonReq *)req;
195             REPLY (": XID(0x%lx) ConfineTo(0x%lx) Cursor(0x%lx)",
196                 stuff->grabWindow,
197                 stuff->confineTo,
198                 stuff->cursor);
199
200             return reply;
201         }
202
203     case X_UngrabButton:
204         {
205             xUngrabButtonReq *stuff = (xUngrabButtonReq *)req;
206             REPLY (": XID(0x%lx)",
207                 stuff->grabWindow);
208
209             return reply;
210         }
211
212     case X_ChangeActivePointerGrab:
213         {
214             xChangeActivePointerGrabReq *stuff = (xChangeActivePointerGrabReq *)req;
215             REPLY (": Cursor(0x%lx)",
216                 stuff->cursor);
217
218             return reply;
219         }
220
221     case X_GrabKeyboard:
222         {
223             xGrabKeyboardReq *stuff = (xGrabKeyboardReq *)req;
224             REPLY (": XID(0x%lx)",
225                 stuff->grabWindow);
226
227             return reply;
228         }
229
230     case X_GrabKey:
231         {
232             xGrabKeyReq *stuff = (xGrabKeyReq *)req;
233             REPLY (": XID(0x%lx)",
234                 stuff->grabWindow);
235
236             return reply;
237         }
238
239     case X_UngrabKey:
240         {
241             xUngrabKeyReq *stuff = (xUngrabKeyReq *)req;
242             REPLY (": XID(0x%lx)",
243                 stuff->grabWindow);
244
245             return reply;
246         }
247
248     case X_SetInputFocus:
249         {
250             xSetInputFocusReq *stuff = (xSetInputFocusReq *)req;
251             REPLY (": XID(0x%lx)",
252                 stuff->focus);
253
254             return reply;
255         }
256
257     case X_CreatePixmap:
258         {
259             xCreatePixmapReq *stuff = (xCreatePixmapReq *)req;
260             REPLY (": Pixmap(0x%lx) Drawable(0x%lx) size(%dx%d)",
261                 stuff->pid,
262                 stuff->drawable,
263                 stuff->width,
264                 stuff->height);
265
266             return reply;
267         }
268
269     case X_ClearArea:
270         {
271             xClearAreaReq *stuff = (xClearAreaReq *)req;
272             REPLY (": XID(0x%lx) area(%d,%d %dx%d)",
273                 stuff->window,
274                 stuff->x,
275                 stuff->y,
276                 stuff->width,
277                 stuff->height);
278
279         \r   return reply;
280         }
281
282     case X_CopyArea:
283         {
284             xCopyAreaReq *stuff = (xCopyAreaReq *)req;
285             REPLY (": srcXID(0x%lx) dstXID(0x%lx) gc(0x%lx) size(%dx%d) src(%d,%d) dst(%d,%d)",
286                 stuff->srcDrawable,
287                 stuff->dstDrawable,
288                 stuff->gc,
289                 stuff->width,
290                 stuff->height,
291                 stuff->srcX,
292                 stuff->srcY,
293                 stuff->dstX,
294                 stuff->dstY);
295
296             return reply;
297         }
298
299     case X_CopyPlane:
300         {
301             xCopyPlaneReq *stuff = (xCopyPlaneReq *)req;
302             REPLY (": srcXID(0x%lx) dstXID(0x%lx) gc(0x%lx) size(%dx%d) src(%d,%d) dst(%d,%d)",
303                 stuff->srcDrawable,
304                 stuff->dstDrawable,
305                 stuff->gc,
306                 stuff->width,
307                 stuff->height,
308                 stuff->srcX,
309                 stuff->srcY,
310                 stuff->dstX,
311                 stuff->dstY);
312
313             return reply;
314         }
315
316     case X_PolyPoint:
317         {
318             xPolyPointReq *stuff = (xPolyPointReq *)req;
319             REPLY (": XID(0x%lx) gc(0x%lx)",
320                 stuff->drawable,
321                 stuff->gc);
322
323             return reply;
324         }
325
326     case X_PolyLine:
327         {
328             xPolyLineReq *stuff = (xPolyLineReq *)req;
329             REPLY (": XID(0x%lx gc(0x%lx)",
330                 stuff->drawable,
331                 stuff->gc);
332
333             return reply;
334         }
335
336     case X_PolySegment:
337         {
338             xPolySegmentReq *stuff = (xPolySegmentReq *)req;
339             REPLY (": XID(0x%lx) gc(0x%lx)",
340                 stuff->drawable,
341                 stuff->gc);
342
343             return reply;
344         }
345
346     case X_PolyRectangle:
347         {
348             xPolyRectangleReq *stuff = (xPolyRectangleReq *)req;
349             REPLY (": XID(0x%lx) gc(0x%lx)",
350                 stuff->drawable,
351                 stuff->gc);
352
353             return reply;
354         }
355
356     case X_PolyArc:
357         {
358             xPolyArcReq *stuff = (xPolyArcReq *)req;
359             REPLY (": XID(0x%lx) gc(0x%lx)",
360                 stuff->drawable,
361                 stuff->gc);
362
363             return reply;
364         }
365
366     case X_FillPoly:
367         {
368             xFillPolyReq *stuff = (xFillPolyReq *)req;
369             REPLY (": XID(0x%lx) gc(0x%lx)",
370                 stuff->drawable,
371                 stuff->gc);
372
373             return reply;
374         }
375
376     case X_PolyFillRectangle:
377         {
378             xPolyFillRectangleReq *stuff = (xPolyFillRectangleReq *)req;
379             REPLY (": XID(0x%lx) gc(0x%lx)",
380                 stuff->drawable,
381                 stuff->gc);
382
383             return reply;
384         }
385
386     case X_PolyFillArc:
387         {
388             xPolyFillArcReq *stuff = (xPolyFillArcReq *)req;
389             REPLY (": XID(0x%lx) gc(0x%lx)",
390                 stuff->drawable,
391                 stuff->gc);
392
393             return reply;
394         }
395
396     case X_PutImage:
397         {
398             xPutImageReq *stuff = (xPutImageReq *)req;
399             REPLY (": XID(0x%lx) gc(0x%lx) size(%dx%d) dst(%d,%d)",
400                 stuff->drawable,
401                 stuff->gc,
402                 stuff->width,
403                 stuff->height,
404                 stuff->dstX,
405                 stuff->dstY);
406             return reply;
407         }
408
409     case X_GetImage:
410         {
411             xGetImageReq *stuff = (xGetImageReq *)req;
412             REPLY (": XID(0x%lx) size(%dx%d) dst(%d,%d)",
413                 stuff->drawable,
414                 stuff->width,
415                 stuff->height,
416                 stuff->x,
417                 stuff->y);
418
419             return reply;
420         }
421
422     case X_PolyText8:
423         {
424             xPolyText8Req *stuff = (xPolyText8Req *)req;
425             REPLY (": XID(0x%lx) gc(0x%lx) coord(%d,%d)",
426                 stuff->drawable,
427                 stuff->gc,
428                 stuff->x,
429                 stuff->y);
430
431             return reply;
432         }
433
434     case X_PolyText16:
435         {
436             xPolyText16Req *stuff = (xPolyText16Req *)req;
437             REPLY (": XID(0x%lx) gc(0x%lx) coord(%d,%d)",
438                 stuff->drawable,
439                 stuff->gc,
440                 stuff->x,
441                 stuff->y);
442
443             return reply;
444         }
445
446     case X_ImageText8:
447         {
448             xImageText8Req *stuff = (xImageText8Req *)req;
449             REPLY (": XID(0x%lx) gc(0x%lx) coord(%d,%d)",
450                 stuff->drawable,
451                 stuff->gc,
452                 stuff->x,
453                 stuff->y);
454
455             return reply;
456         }
457
458     case X_ImageText16:
459         {
460             xImageText16Req *stuff = (xImageText16Req *)req;
461             REPLY (": XID(0x%lx) gc(0x%lx) coord(%d,%d)",
462                 stuff->drawable,
463                 stuff->gc,
464                 stuff->x,
465                 stuff->y);
466
467             return reply;
468         }
469
470     case X_ChangeKeyboardMapping:
471         {
472             xChangeKeyboardMappingReq *stuff = (xChangeKeyboardMappingReq *)req;
473             REPLY (": Key(%d) FstKey(%d) KeySyms(%d)",
474                 stuff->firstKeyCode,
475                 stuff->keyCodes,
476                 stuff->keySymsPerKeyCode);
477
478             return reply;
479         }
480
481     case X_GetKeyboardMapping:
482         {
483             xGetKeyboardMappingReq *stuff = (xGetKeyboardMappingReq *)req;
484             REPLY (": FstKey(%d) Count(%d)",
485                 stuff->firstKeyCode,
486                 stuff->count);
487
488             return reply;
489         }
490
491     case X_ChangePointerControl:
492         {
493             xChangePointerControlReq *stuff = (xChangePointerControlReq *)req;
494             REPLY (": accelNum(%d) accelDenum(%d) threshold(%d)",
495                 stuff->accelNum,
496                 stuff->accelDenum,
497                 stuff->threshold);
498
499             return reply;
500         }
501
502     case X_SetPointerMapping:
503         {
504             xSetPointerMappingReq *stuff = (xSetPointerMappingReq *)req;
505             REPLY (": Elts(%d)",
506                 stuff->nElts);
507
508             return reply;
509         }
510
511     case X_SetModifierMapping:
512         {
513             xSetModifierMappingReq *stuff =(xSetModifierMappingReq *)req;
514             REPLY (": NumkeyPerModifier(%d)",
515                 stuff->numKeyPerModifier);
516
517             return reply;
518         }
519
520     case X_DestroyWindow:
521     case X_DestroySubwindows:
522     case X_MapWindow:
523     case X_MapSubwindows:
524     case X_UnmapWindow:
525     case X_UnmapSubwindows:
526     case X_GetGeometry:
527     case X_QueryTree:
528     case X_UngrabPointer:
529     case X_UngrabKeyboard:
530     case X_FreePixmap:
531     case X_KillClient:
532         {
533             xResourceReq *stuff = (xResourceReq *)req;
534             REPLY (": XID(0x%lx)",
535                 stuff->id);
536
537             return reply;
538         }
539
540     default:
541             break;
542     }
543
544     return reply;
545 }
546
547
548 char * xDbgEvlogEventCore (xEvent *evt, char *reply, int *len)
549 {
550     switch (evt->u.u.type & 0x7F)
551     {
552     case KeyPress:
553     case KeyRelease:
554     case ButtonPress:
555     case ButtonRelease:
556     case MotionNotify:
557         {
558             REPLY (": Root(0x%lx %d,%d) Event(0x%lx %d,%d) Child(0x%lx)",
559                 evt->u.keyButtonPointer.root,
560                 evt->u.keyButtonPointer.rootX,
561                 evt->u.keyButtonPointer.rootY,
562                 evt->u.keyButtonPointer.event,
563                 evt->u.keyButtonPointer.eventX,
564                 evt->u.keyButtonPointer.eventY,
565                 evt->u.keyButtonPointer.child);
566
567             return reply;
568                 }
569
570     case EnterNotify:
571     case LeaveNotify:
572         {
573             REPLY (": Root(0x%lx %d,%d) Event(0x%lx %d,%d) Child(0x%lx)",
574                 evt->u.enterLeave.root,
575                 evt->u.enterLeave.rootX,
576                 evt->u.enterLeave.rootY,
577                 evt->u.enterLeave.event,
578                 evt->u.enterLeave.eventX,
579                 evt->u.enterLeave.eventY,
580                 evt->u.enterLeave.child);
581
582             return reply;
583                 }
584
585     case FocusIn:
586     case FocusOut:
587     case KeymapNotify:
588         {
589             REPLY (": XID(0x%lx)",
590                 evt->u.focus.window);
591
592             return reply;
593                 }
594
595     case Expose:
596         {
597             REPLY (": XID(0x%lx) size(%dx%d) coord(%d,%d)",
598                 evt->u.expose.window,
599                 evt->u.expose.width,
600                 evt->u.expose.height,
601                 evt->u.expose.x,
602                 evt->u.expose.y);
603
604             return reply;
605                 }
606
607     case GraphicsExpose:
608         {
609             REPLY (": XID(0x%lx) size(%dx%d) coord(%d,%d)",
610                 evt->u.graphicsExposure.drawable,
611                 evt->u.graphicsExposure.width,
612                 evt->u.graphicsExposure.height,
613                 evt->u.graphicsExposure.x,
614                 evt->u.graphicsExposure.y);
615
616             return reply;
617                 }
618
619     case NoExpose:
620         {
621             REPLY (": XID(0x%lx)",
622                 evt->u.noExposure.drawable);
623
624             return reply;
625                 }
626
627
628     case VisibilityNotify:
629         {
630             REPLY (": XID(0x%lx)",
631                 evt->u.visibility.window);
632
633             return reply;
634                 }
635
636     case CreateNotify:
637         {
638             REPLY (": Window(0x%lx) Parent(0x%lx) size(%dx%d) coord(%d,%d) borderWidth(%d)",
639                 evt->u.createNotify.window,
640                 evt->u.createNotify.parent,
641                 evt->u.createNotify.width,
642                 evt->u.createNotify.height,
643                 evt->u.createNotify.x,
644                 evt->u.createNotify.y,
645                 evt->u.createNotify.borderWidth);
646
647             return reply;
648                 }
649
650     case DestroyNotify:
651         {
652             REPLY (": Window(0x%lx) Event(0x%lx)",
653                 evt->u.destroyNotify.window,
654                 evt->u.destroyNotify.event);
655
656             return reply;
657                 }
658
659     case UnmapNotify:
660         {
661             REPLY (": Window(0x%lx) Event(0x%lx)",
662                 evt->u.unmapNotify.window,
663                 evt->u.unmapNotify.event);
664
665             return reply;
666                 }
667
668     case MapNotify:
669         {
670             REPLY (": Window(0x%lx) Event(0x%lx)",
671                 evt->u.mapNotify.window,
672                 evt->u.mapNotify.event);
673
674             return reply;
675                 }
676
677     case MapRequest:
678         {
679             REPLY (": Window(0x%lx) Parent(0x%lx)",
680                 evt->u.mapRequest.window,
681                 evt->u.mapRequest.parent);
682
683             return reply;
684                 }
685
686     case ReparentNotify:
687         {
688             REPLY (": Window(0x%lx) Event(0x%lx) parent(0x%lx) coord(%d,%d)",
689                 evt->u.reparent.window,
690                 evt->u.reparent.event,
691                 evt->u.reparent.parent,
692                 evt->u.reparent.x,
693                 evt->u.reparent.y);
694
695             return reply;
696                 }
697
698     case ConfigureNotify:
699         {
700             REPLY (": Window(0x%lx) Event(0x%lx) aboveSibling(0x%lx) size(%dx%d) coord(%d,%d) borderWidth(%d)",
701                 evt->u.configureNotify.window,
702                 evt->u.configureNotify.event,
703                 evt->u.configureNotify.aboveSibling,
704                 evt->u.configureNotify.width,
705                 evt->u.configureNotify.height,
706                 evt->u.configureNotify.x,
707                 evt->u.configureNotify.y,
708                 evt->u.configureNotify.borderWidth);
709
710             return reply;
711                 }
712
713     case ConfigureRequest:
714         {
715             REPLY (": Window(0x%lx) Parent(0x%lx) Sibling(0x%lx) size(%dx%d) coord(%d,%d) borderWidth(%d)",
716                 evt->u.configureRequest.window,
717                 evt->u.configureRequest.parent,
718                 evt->u.configureRequest.sibling,
719                 evt->u.configureRequest.width,
720                 evt->u.configureRequest.height,
721                 evt->u.configureRequest.x,
722                 evt->u.configureRequest.y,
723                 evt->u.configureRequest.borderWidth);
724
725             return reply;
726                 }
727
728     case GravityNotify:
729         {
730             REPLY (": Window(0x%lx) Event(0x%lx) coord(%d,%d)",
731                 evt->u.gravity.window,
732                 evt->u.gravity.event,
733                 evt->u.gravity.x,
734                 evt->u.gravity.y);
735
736             return reply;
737                 }
738
739     case ResizeRequest:
740         {
741             REPLY (": Window(0x%lx) size(%dx%d)",
742                 evt->u.resizeRequest.window,
743                 evt->u.resizeRequest.width,
744                 evt->u.resizeRequest.height);
745
746             return reply;
747                 }
748
749     case CirculateNotify:
750     case CirculateRequest:
751         {
752             REPLY (": Window(0x%lx) Event(0x%lx) parent(0x%lx)",
753                 evt->u.circulate.window,
754                 evt->u.circulate.event,
755                 evt->u.circulate.parent);
756
757             return reply;
758                 }
759
760     case PropertyNotify:
761         {
762             REPLY (": Window(0x%lx) atom(0x%lx)",
763                 evt->u.property.window,
764                 evt->u.property.atom);
765
766             return reply;
767                 }
768
769     case SelectionClear:
770         {
771             REPLY (": Window(0x%lx) atom(0x%lx)",
772                 evt->u.selectionClear.window,
773                 evt->u.selectionClear.atom);
774
775             return reply;
776                 }
777
778     case SelectionRequest:
779         {
780             REPLY (": Owner(0x%lx) Requestor(0x%lx) Selcection(0x%lx) Target(0x%lx) Property(0x%lx)",
781                 evt->u.selectionRequest.owner,
782                 evt->u.selectionRequest.requestor,
783                 evt->u.selectionRequest.selection,
784                 evt->u.selectionRequest.target,
785                 evt->u.selectionRequest.property);
786
787             return reply;
788                 }
789
790     case SelectionNotify:
791         {
792             REPLY (": Requestor(0x%lx) Selcection(0x%lx) Target(0x%lx) Property(0x%lx)",
793                 evt->u.selectionNotify.requestor,
794                 evt->u.selectionNotify.selection,
795                 evt->u.selectionNotify.target,
796                 evt->u.selectionNotify.property);
797
798             return reply;
799                 }
800
801     case ColormapNotify:
802         {
803             REPLY (": XID(0x%lx) Colormap(0x%lx)",
804                 evt->u.colormap.window,
805                 evt->u.colormap.colormap);
806
807             return reply;
808                 }
809
810     case ClientMessage:
811         {
812             REPLY (": XID(0x%lx) Atom(0x%lx)",
813                 evt->u.clientMessage.window,
814                 evt->u.clientMessage.u.b.type);
815
816             return reply;
817                 }
818
819     case MappingNotify:
820     case GenericEvent:
821     default:
822             break;
823     }
824
825     return reply;
826 }