3a4797d01b9a93c9aa19af3548126e33f283b654
[platform/adaptation/xf86-module-xdbg.git] / common / xdbg_evlog_request.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/XI2proto.h>
53 #include <X11/Xlib.h>
54 #include <windowstr.h>
55 #include <sys/shm.h>
56 #include <X11/extensions/XShm.h>
57
58 #include "xdbg_types.h"
59 #include "xdbg_evlog_request.h"
60
61 #define UNKNOWN_EVENT "<unknown>"
62
63 #ifdef XDBG_CLIENT
64 static int base;
65 #else
66 static ExtensionEntry *xext;
67 #endif
68
69 static Bool
70 _EvlogRequestGetExtentionEntry ()
71 {
72 #ifdef XDBG_CLIENT
73
74     static int init = 0;
75     static Bool success = FALSE;
76     Display *dpy;
77
78     if (init)
79         return success;
80
81     init = 1;
82
83     dpy = XOpenDisplay (NULL);
84     if (!dpy)
85     {
86         fprintf (stderr, "failed: open display\n");
87         exit (-1);
88     }
89
90     if (!XShmQueryExtension (dpy))
91     {
92         fprintf (stderr, "[UTILX] no XShm extension. !!\n");
93         return False;
94     }
95     printf("debug request\n");
96     base = XShmGetEventBase(dpy);
97     success = TRUE;
98     XCloseDisplay (dpy);
99     return success;
100
101 #else
102
103     static int init = 0;
104     static Bool success = FALSE;
105
106     if (init)
107         return success;
108
109     init = 1;
110     xext = CheckExtension (SHMNAME);
111     RETURN_VAL_IF_FAIL (xext != NULL, FALSE);
112
113     success = TRUE;
114
115     return success;
116
117 #endif
118 }
119
120 static char *
121 _EvlogRequestCore (xReq *req, char *reply, int *len)
122 {
123     xReq *stuff = req;
124
125     switch (stuff->reqType)
126     {
127     case X_PutImage:
128         {
129             xPutImageReq *stuff = (xPutImageReq *)req;
130             REPLY (": XID(%lx) size(%dx%d) dst(%d,%d)",
131                 stuff->drawable,
132                 stuff->width,
133                 stuff->height,
134                 stuff->dstX,
135                 stuff->dstY);
136             return reply;
137         }
138     default:
139             break;
140     }
141
142     return reply;
143 }
144
145 static char *
146 _EvlogRequestShm (xReq *req, char *reply, int *len)
147 {
148     xReq *stuff = req;
149
150     switch (stuff->data)
151     {
152     case X_ShmPutImage:
153         {
154             xShmPutImageReq *stuff = (xShmPutImageReq *)req;
155             REPLY (": XID(%lx) size(%dx%d) src(%d,%d %dx%d) dst(%d,%d)",
156                 stuff->drawable,
157                 stuff->totalWidth,
158                 stuff->totalHeight,
159                 stuff->srcX,
160                 stuff->srcY,
161                 stuff->srcWidth,
162                 stuff->srcHeight,
163                 stuff->dstX,
164                 stuff->dstY);
165             return reply;
166         }
167     default:
168             break;
169     }
170
171     return reply;
172 }
173
174 char *
175 xDbgEvlogReqeust (EvlogInfo *evinfo, char *reply, int *len)
176 {
177     EvlogRequest req;
178     xReq *xReq = NULL;
179
180     RETURN_VAL_IF_FAIL (evinfo != NULL, reply);
181     RETURN_VAL_IF_FAIL (evinfo->type == REQUEST, reply);
182
183     req = evinfo->req;
184     xReq = req.ptr;
185
186     if (!_EvlogRequestGetExtentionEntry ())
187         return reply;
188
189     REPLY ("%s", req.name);
190
191     if (xReq->reqType < EXTENSION_BASE)
192     {
193         return _EvlogRequestCore (xReq, reply, len);
194     }
195     else
196     {
197
198 #ifdef XDBG_CLIENT
199         if (xReq->reqType == base)
200 #else
201         if (xReq->reqType == xext->base)
202 #endif
203
204         {
205             return _EvlogRequestShm (xReq, reply, len);
206         }
207     }
208
209     return reply;
210 }