cbe87f2fceed1f2bf17cb8f23ed9145c9ed6dd02
[adaptation/xorg/driver/xserver-xorg-module-xdbg.git] / common / xdbg_evlog_event.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/extensions/damageproto.h>
53 #include <X11/extensions/damagewire.h>
54 #include <X11/extensions/XI2proto.h>
55 #include <X11/Xlib.h>
56 #include <windowstr.h>
57 #include <X11/extensions/Xdamage.h>
58
59 #include "xdbg_types.h"
60 #include "xdbg_evlog_event.h"
61
62
63 #define UNKNOWN_EVENT "<unknown>"
64
65 #ifdef XDBG_CLIENT
66 static int damage_base;
67 static int damage_err_base;
68 #else
69 static ExtensionEntry *damage;
70 #endif
71
72 static Bool
73 _EvlogEventGetExtentionEntry ()
74 {
75 #ifdef XDBG_CLIENT
76
77     static int init = 0;
78     static Bool success = FALSE;
79     Display *dpy;
80
81     if (init)
82         return success;
83
84     init = 1;
85
86     dpy = XOpenDisplay (NULL);
87     if (!dpy)
88     {
89         fprintf (stderr, "failed: open display\n");
90         exit (-1);
91     }
92
93     if (!XDamageQueryExtension(dpy, &damage_base, &damage_err_base))
94     {
95         fprintf (stderr, "[UTILX] no X Damage extension. \n");
96         return False;
97     }
98     success = TRUE;
99     XCloseDisplay (dpy);
100     return success;
101
102 #else
103
104     static int init = 0;
105     static Bool success = FALSE;
106
107     if (init)
108         return success;
109
110     init = 1;
111     damage = CheckExtension (DAMAGE_NAME);
112     RETURN_VAL_IF_FAIL (damage != NULL, FALSE);
113
114     success = TRUE;
115
116     return success;
117
118 #endif
119 }
120
121
122 char *
123 xDbgEvlogEvent (EvlogInfo *evinfo, char *reply, int *len)
124 {
125     EvlogEvent   ev;
126     xEvent *xEvt = NULL;
127
128     RETURN_VAL_IF_FAIL (evinfo != NULL, reply);
129     RETURN_VAL_IF_FAIL (evinfo->type == EVENT, reply);
130
131     ev = evinfo->evt;
132     xEvt = ev.ptr;
133
134     if (!_EvlogEventGetExtentionEntry ())
135         return reply;
136
137     REPLY ("%s", ev.name);
138
139 #ifdef XDBG_CLIENT
140     if (xEvt->u.u.type == damage_base + XDamageNotify)
141 #else
142     if (xEvt->u.u.type == damage->eventBase + XDamageNotify)
143 #endif
144     {
145         xDamageNotifyEvent *damage_e = (xDamageNotifyEvent*)xEvt;
146         REPLY (": XID(%lx) area(%d,%d %dx%d) geo(%d,%d %dx%d)",
147             damage_e->drawable,
148             damage_e->area.x,
149             damage_e->area.y,
150             damage_e->area.width,
151             damage_e->area.height,
152             damage_e->geometry.x,
153             damage_e->geometry.y,
154             damage_e->geometry.width,
155             damage_e->geometry.height);
156         return reply;
157     }
158     return reply;
159 }