add supplementary log massage of each major extension
[platform/adaptation/xf86-module-xdbg.git] / common / xdbg_evlog_xext.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
55 #include <X11/extensions/XShm.h>
56 #include <X11/extensions/dpms.h>
57 #include <X11/extensions/sync.h>
58 #include <X11/extensions/xtestext1.h>
59 #include <X11/extensions/XTest.h>
60 #include <X11/Xlibint.h>
61
62 #include <X11/extensions/dpmsproto.h>
63 #include <X11/extensions/shmproto.h>
64 #include <X11/extensions/syncproto.h>
65 #include <X11/extensions/xtestext1proto.h>
66 #include <X11/extensions/xtestproto.h>
67
68 #include "xdbg_types.h"
69 #include "xdbg_evlog_xext.h"
70
71 static char *
72 _EvlogRequestXextDpms(xReq *req, char *reply, int *len)
73 {
74     xReq *stuff = req;
75
76     switch (stuff->data)
77     {
78     case X_DPMSSetTimeouts:
79         {
80             xDPMSSetTimeoutsReq *stuff = (xDPMSSetTimeoutsReq *)req;
81             REPLY (": Standby(%d) Suspend(%d) off(%d)",
82                 stuff->standby,
83                 stuff->suspend,
84                 stuff->off);
85
86             return reply;
87         }
88
89     case X_DPMSForceLevel:
90         {
91             xDPMSForceLevelReq *stuff = (xDPMSForceLevelReq *)req;
92             REPLY (": Level(%d)",
93                 stuff->level);
94
95             return reply;
96         }
97
98     default:
99             break;
100     }
101
102     return reply;
103 }
104
105
106 static char *
107 _EvlogRequestXextShm (xReq *req, char *reply, int *len)
108 {
109     xReq *stuff = req;
110
111     switch (stuff->data)
112     {
113     case X_ShmPutImage:
114         {
115             xShmPutImageReq *stuff = (xShmPutImageReq *)req;
116             REPLY (": XID(0x%lx) size(%dx%d) src(%d,%d %dx%d) dst(%d,%d)",
117                 stuff->drawable,
118                 stuff->totalWidth,
119                 stuff->totalHeight,
120                 stuff->srcX,
121                 stuff->srcY,
122                 stuff->srcWidth,
123                 stuff->srcHeight,
124                 stuff->dstX,
125                 stuff->dstY);
126
127             return reply;
128         }
129
130     case X_ShmGetImage:
131         {
132             xShmGetImageReq *stuff = (xShmGetImageReq *)req;
133             REPLY (": XID(0x%lx) size(%dx%d) coord(%d,%d)",
134                 stuff->drawable,
135                 stuff->width,
136                 stuff->height,
137                 stuff->x,
138                 stuff->y);
139
140             return reply;
141         }
142
143     case X_ShmCreatePixmap:
144         {
145             xShmCreatePixmapReq *stuff = (xShmCreatePixmapReq *)req;
146             REPLY (": Pixmap(0x%lx) Drawable(0x%lx) size(%dx%d)",
147                 stuff->pid,
148                 stuff->drawable,
149                 stuff->width,
150                 stuff->height);
151
152             return reply;
153         }
154
155     default:
156             break;
157     }
158
159     return reply;
160 }
161
162 static char *
163 _EvlogRequestXextSync(xReq *req, char *reply, int *len)
164 {
165     xReq *stuff = req;
166
167     switch (stuff->data)
168     {
169     case X_SyncCreateCounter:
170         {
171             xSyncCreateCounterReq *stuff = (xSyncCreateCounterReq *)req;
172             REPLY (": XID(0x%lx) initValue(%ld/%ld)",
173                 stuff->cid,
174                 stuff->initial_value_hi,
175                 stuff->initial_value_lo);
176
177             return reply;
178         }
179
180     case X_SyncSetCounter:
181         {
182             xSyncSetCounterReq *stuff = (xSyncSetCounterReq *)req;
183             REPLY (": XID(0x%lx) Value(%ld/%ld)",
184                 stuff->cid,
185                 stuff->value_hi,
186                 stuff->value_lo);
187
188             return reply;
189         }
190
191     case X_SyncChangeCounter:
192         {
193             xSyncChangeCounterReq *stuff = (xSyncChangeCounterReq *)req;
194             REPLY (": XID(0x%lx) Value(%ld/%ld)",
195                 stuff->cid,
196                 stuff->value_hi,
197                 stuff->value_lo);
198
199             return reply;
200         }
201
202     case X_SyncQueryCounter:
203         {
204             xSyncQueryCounterReq *stuff = (xSyncQueryCounterReq *)req;
205             REPLY (": XID(0x%lx)",
206                 stuff->counter);
207
208             return reply;
209         }
210
211     case X_SyncDestroyCounter:
212         {
213             xSyncDestroyCounterReq *stuff = (xSyncDestroyCounterReq *)req;
214             REPLY (": XID(0x%lx)",
215                 stuff->counter);
216
217             return reply;
218         }
219
220     default:
221             break;
222     }
223
224     return reply;
225 }
226
227 static char *
228 _EvlogRequestXextXtestExt1(xReq *req, char *reply, int *len)
229 {
230     xReq *stuff = req;
231
232     switch (stuff->data)
233     {
234     case X_TestFakeInput:
235         {
236             xTestFakeInputReq *stuff = (xTestFakeInputReq *)req;
237             REPLY (": XID(0x%lx)",
238                 stuff->ack);
239
240             return reply;
241         }
242
243     case X_TestGetInput:
244         {
245             xTestGetInputReq *stuff = (xTestGetInputReq *)req;
246             REPLY (": XID(0x%lx)",
247                 stuff->mode);
248
249             return reply;
250         }
251
252     default:
253             break;
254     }
255
256     return reply;
257 }
258
259
260 static char *
261 _EvlogRequestXextXtest(xReq *req, char *reply, int *len)
262 {
263     xReq *stuff = req;
264
265     switch (stuff->data)
266     {
267     case X_XTestGetVersion:
268         {
269             xXTestGetVersionReq *stuff = (xXTestGetVersionReq *)req;
270             REPLY (": MajorVersion(%d) MinorVersion(%d)",
271                 stuff->majorVersion,
272                 stuff->minorVersion);
273
274             return reply;
275         }
276
277     case X_XTestCompareCursor:
278         {
279             xXTestCompareCursorReq *stuff = (xXTestCompareCursorReq *)req;
280             REPLY (": XID(0x%lx) Cursor(0x%lx)",
281                 stuff->window,
282                 stuff->cursor);
283
284             return reply;
285         }
286
287     case X_XTestFakeInput:
288         {
289             xXTestFakeInputReq *stuff = (xXTestFakeInputReq *)req;
290             REPLY (": XID(0x%lx) coord(%d,%d)",
291                 stuff->root,
292                 stuff->rootX,
293                 stuff->rootY);
294
295             return reply;
296         }
297
298     case X_XTestGrabControl:
299         {
300             xXTestGrabControlReq *stuff = (xXTestGrabControlReq *)req;
301             REPLY (": Impervious(%s)" ,
302                 (stuff->impervious)? "TRUE" : "FALSE");
303
304             return reply;
305         }
306
307     default:
308             break;
309     }
310
311     return reply;
312 }
313
314
315 static char *
316 _EvlogEventXextDpms (xEvent *evt, int first_base, char *reply, int *len)
317 {
318     xEvent *stuff = evt;
319
320     switch ((stuff->u.u.type & 0x7F) - first_base)
321     {
322
323     default:
324             break;
325     }
326
327     return reply;
328 }
329
330
331 static char *
332 _EvlogEventXextShm (xEvent *evt, int first_base, char *reply, int *len)
333 {
334     xEvent *stuff = evt;
335
336     switch ((stuff->u.u.type & 0x7F) - first_base)
337     {
338     case ShmCompletion:
339         {
340             xShmCompletionEvent *stuff = (xShmCompletionEvent *) evt;
341             REPLY (": XID(0x%lx)",
342                 stuff->drawable);
343
344             return reply;
345         }
346
347     default:
348             break;
349     }
350
351     return reply;
352 }
353
354
355 static char *
356 _EvlogEventXextSync (xEvent *evt, int first_base, char *reply, int *len)
357 {
358     xEvent *stuff = evt;
359
360     switch ((stuff->u.u.type & 0x7F) - first_base)
361     {
362     case XSyncCounterNotify:
363         {
364             xSyncCounterNotifyEvent *stuff = (xSyncCounterNotifyEvent *) evt;
365             REPLY (": XID(0x%lx) WaitValue(0x%lx/0x%lx) CounterValue(0x%lx/0x%lx)",
366                 stuff->counter,
367                 stuff->wait_value_hi,
368                 stuff->wait_value_lo,
369                 stuff->counter_value_hi,
370                 stuff->counter_value_lo);
371
372             return reply;
373         }
374
375     case XSyncAlarmNotify:
376         {
377             xSyncAlarmNotifyEvent *stuff = (xSyncAlarmNotifyEvent *) evt;
378             REPLY (": XID(0x%lx) CounterValue(0x%lx/0x%lx) AlarmValue(0x%lx/0x%lx)",
379                 stuff->alarm,
380                 stuff->counter_value_hi,
381                 stuff->counter_value_lo,
382                 stuff->alarm_value_hi,
383                 stuff->alarm_value_lo);
384
385             return reply;
386         }
387
388     default:
389             break;
390     }
391
392     return reply;
393 }
394
395
396 static char *
397 _EvlogEventXextXtestExt1 (xEvent *evt, int first_base, char *reply, int *len)
398 {
399     xEvent *stuff = evt;
400
401     switch ((stuff->u.u.type & 0x7F) - first_base)
402     {
403
404     default:
405             break;
406     }
407
408     return reply;
409 }
410
411 static char *
412 _EvlogEventXextXtest (xEvent *evt, int first_base, char *reply, int *len)
413 {
414     xEvent *stuff = evt;
415
416     switch ((stuff->u.u.type & 0x7F) - first_base)
417     {
418
419     default:
420             break;
421     }
422
423     return reply;
424 }
425
426 void
427 xDbgEvlogXextDpmsGetBase (void *dpy, ExtensionInfo *extinfo)
428 {
429 #ifdef XDBG_CLIENT
430     Display *d = (Display*)dpy;
431
432     RETURN_IF_FAIL (d != NULL);
433     RETURN_IF_FAIL (extinfo != NULL);
434
435     if (!XQueryExtension(d, DPMSExtensionName, &extinfo->opcode, &extinfo->evt_base, &extinfo->err_base))
436     {
437         fprintf (stderr, "[UTILX] no Xext_DPMS extension. \n");
438         return;
439     }
440     extinfo->req_func = _EvlogRequestXextDpms;
441     extinfo->evt_func = _EvlogEventXextDpms;
442 #else
443     ExtensionEntry *xext = CheckExtension (DPMSExtensionName);
444     RETURN_IF_FAIL (xext != NULL);
445
446     extinfo->opcode = xext->base;
447     extinfo->evt_base = xext->eventBase;
448     extinfo->err_base = xext->errorBase;
449     extinfo->req_func = _EvlogRequestXextDpms;
450     extinfo->evt_func = _EvlogEventXextDpms;
451 #endif
452 }
453
454
455 void
456 xDbgEvlogXextShmGetBase (void *dpy, ExtensionInfo *extinfo)
457 {
458 #ifdef XDBG_CLIENT
459     Display *d = (Display*)dpy;
460
461     RETURN_IF_FAIL (d != NULL);
462     RETURN_IF_FAIL (extinfo != NULL);
463
464     if (!XQueryExtension(d, SHMNAME, &extinfo->opcode, &extinfo->evt_base, &extinfo->err_base))
465     {
466         fprintf (stderr, "[UTILX] no XShm extension. \n");
467         return;
468     }
469     extinfo->req_func = _EvlogRequestXextShm;
470     extinfo->evt_func = _EvlogEventXextShm;
471 #else
472     ExtensionEntry *xext = CheckExtension (SHMNAME);
473     RETURN_IF_FAIL (xext != NULL);
474
475     extinfo->opcode = xext->base;
476     extinfo->evt_base = xext->eventBase;
477     extinfo->err_base = xext->errorBase;
478     extinfo->req_func = _EvlogRequestXextShm;
479     extinfo->evt_func = _EvlogEventXextShm;
480 #endif
481 }
482
483
484 void
485 xDbgEvlogXextSyncGetBase (void *dpy, ExtensionInfo *extinfo)
486 {
487 #ifdef XDBG_CLIENT
488     Display *d = (Display*)dpy;
489
490     RETURN_IF_FAIL (d != NULL);
491     RETURN_IF_FAIL (extinfo != NULL);
492
493     if (!XQueryExtension(d, SYNC_NAME, &extinfo->opcode, &extinfo->evt_base, &extinfo->err_base))
494     {
495         fprintf (stderr, "[UTILX] no Sync extension. \n");
496         return;
497     }
498
499     extinfo->req_func = _EvlogRequestXextSync;
500     extinfo->evt_func = _EvlogEventXextSync;
501 #else
502     ExtensionEntry *xext = CheckExtension (SYNC_NAME);
503     RETURN_IF_FAIL (xext != NULL);
504
505     extinfo->opcode = xext->base;
506     extinfo->evt_base = xext->eventBase;
507     extinfo->err_base = xext->errorBase;
508     extinfo->req_func = _EvlogRequestXextSync;
509     extinfo->evt_func = _EvlogEventXextSync;
510 #endif
511
512 }
513
514
515 void
516 xDbgEvlogXextXtestExt1GetBase (void *dpy, ExtensionInfo *extinfo)
517 {
518 #ifdef XDBG_CLIENT
519     Display *d = (Display*)dpy;
520
521     RETURN_IF_FAIL (d != NULL);
522     RETURN_IF_FAIL (extinfo != NULL);
523
524     if (!XQueryExtension(d, XTestEXTENSION_NAME, &extinfo->opcode, &extinfo->evt_base, &extinfo->err_base))
525     {
526         fprintf (stderr, "[UTILX] no XTestExt1 extension. \n");
527         return;
528     }
529     extinfo->req_func = _EvlogRequestXextXtestExt1;
530     extinfo->evt_func = _EvlogEventXextXtestExt1;
531 #else
532     ExtensionEntry *xext = CheckExtension (XTestEXTENSION_NAME);
533     RETURN_IF_FAIL (xext != NULL);
534
535     extinfo->opcode = xext->base;
536     extinfo->evt_base = xext->eventBase;
537     extinfo->err_base = xext->errorBase;
538     extinfo->req_func = _EvlogRequestXextXtestExt1;
539     extinfo->evt_func = _EvlogEventXextXtestExt1;
540 #endif
541
542 }
543
544
545 void
546 xDbgEvlogXextXtestGetBase (void *dpy, ExtensionInfo *extinfo)
547 {
548 #ifdef XDBG_CLIENT
549     Display *d = (Display*)dpy;
550
551     RETURN_IF_FAIL (d != NULL);
552     RETURN_IF_FAIL (extinfo != NULL);
553
554     if (!XQueryExtension(d, XTestExtensionName, &extinfo->opcode, &extinfo->evt_base, &extinfo->err_base))
555     {
556         fprintf (stderr, "[UTILX] no Xext_Xtest extension. \n");
557         return;
558     }
559     extinfo->req_func = _EvlogRequestXextXtest;
560     extinfo->evt_func = _EvlogEventXextXtest;
561 #else
562     ExtensionEntry *xext = CheckExtension (XTestExtensionName);
563     RETURN_IF_FAIL (xext != NULL);
564
565     extinfo->opcode = xext->base;
566     extinfo->evt_base = xext->eventBase;
567     extinfo->err_base = xext->errorBase;
568     extinfo->req_func = _EvlogRequestXextXtest;
569     extinfo->evt_func = _EvlogEventXextXtest;
570 #endif
571
572 }