tizen 2.3 release
[adaptation/xorg/driver/xserver-xorg-module-xdbg.git] / common / xdbg_types.h
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 #ifndef __XDBG_TYPES_H__
33 #define __XDBG_TYPES_H__
34
35 #include <config.h>
36
37 #include <xf86.h>
38 #include <X11/Xdefs.h>  /* for Bool */
39 #include <X11/Xlib.h>
40 #include <X11/extensions/Xfixes.h>
41 #include <list.h>
42
43
44 #define XDBG_PATH_MAX        1024
45 #define XDBG_BUF_SIZE        64
46
47 #define MAX(a,b) (((a) > (b)) ? (a) : (b))
48 #define MIN(a,b) (((a) < (b)) ? (a) : (b))
49 #define SWAP(a, b)  ({int t; t = a; a = b; b = t;})
50
51 #define WARNING_IF_FAIL(cond) \
52     {if (!(cond)) { fprintf (stderr, "[%s] '%s' failed.\n", __FUNCTION__, #cond);}}
53 #define RETURN_IF_FAIL(cond) \
54     {if (!(cond)) { fprintf (stderr, "[%s] '%s' failed.\n", __FUNCTION__, #cond); return; }}
55 #define RETURN_VAL_IF_FAIL(cond, val) \
56     {if (!(cond)) { fprintf (stderr, "[%s] '%s' failed.\n", __FUNCTION__, #cond); return val; }}
57 #define RETURN_VAL_IF_ERRNO(cond, val, errno) \
58     {if (!(cond)) { fprintf (stderr, "[%s] '%s' failed. (err=%s(%d))\n", __FUNCTION__, #cond, strerror(errno), errno); return val; }}
59 #define GOTO_IF_FAIL(cond, dst) \
60     {if (!(cond)) { fprintf (stderr, "[%s] '%s' failed.\n", __FUNCTION__, #cond); goto dst; }}
61 #define GOTO_IF_ERRNO(cond, dst, errno) \
62     {if (!(cond)) { fprintf (stderr, "[%s] '%s' failed. (err=%s(%d))\n", __FUNCTION__, #cond, strerror(errno), errno); goto dst; }}
63
64 #define XDBG_LOG(fmt, ARG...)   { fprintf (stderr, fmt, ##ARG); }
65
66 #define REPLY(fmt, ARG...)  \
67     do { \
68         if (reply && len && *len > 0) \
69         { \
70             int s = snprintf (reply, *len, fmt, ##ARG); \
71             reply += s; \
72             *len -= s; \
73         } \
74     } while (0)
75
76 #define UNKNOWN_EVENT "<unknown>"
77
78 typedef enum
79 {
80     EVENT,
81     REQUEST,
82     REPLY,
83     FLUSH,
84     ERROR
85 } EvlogType;
86
87 #define EVLOG_MASK_CLIENT    (1<<0)
88 #define EVLOG_MASK_REQUEST   (1<<1)
89 #define EVLOG_MASK_EVENT     (1<<2)
90 #define EVLOG_MASK_REPLY     (1<<3)
91 #define EVLOG_MASK_ERROR     (1<<4)
92 #define EVLOG_MASK_ATOM      (1<<5)
93 #define EVLOG_MASK_REGION    (1<<6)
94
95 #define EVLOG_PRINT_DEFAULT           0
96 #define EVLOG_PRINT_DETAIL            1
97 #define EVLOG_PRINT_REPLY_DETAIL      2
98
99
100 typedef struct _EvlogTable
101 {
102     CARD32           xid;
103     char             buf[XDBG_BUF_SIZE];
104     struct xorg_list link;
105 } EvlogAtomTable, EvlogRegionTable;
106
107 typedef struct _EvlogList
108 {
109     struct xorg_list list;
110     int              init;
111     int              size;
112 } EvlogAtom, EvlogRegion;
113
114 typedef struct _EvlogClient
115 {
116     int     index;
117     int     pid;
118     int     gid;
119     int     uid;
120     char    command[PATH_MAX+1];
121     void*   pClient;
122 } EvlogClient;
123
124 typedef struct _EvlogRequest
125 {
126     int     id;
127     CARD32  length;
128     xReq   *ptr;
129     char    name[PATH_MAX+1];
130 } EvlogRequest;
131
132 typedef struct _EvlogEvent
133 {
134     xEvent *ptr;
135     int     size;
136     char    name[PATH_MAX+1];
137 } EvlogEvent;
138
139 typedef struct _EvlogReply
140 {
141     xGenericReply  *ptr;
142     int             size;
143     char            name[PATH_MAX+1];
144     int             reqType;
145     int             reqData;
146     Bool            isStart;
147 } EvlogReply;
148
149 typedef struct _EvlogError
150 {
151     BYTE    errorCode;
152     CARD32  resourceID;
153     CARD16  minorCode;
154     CARD8   majorCode;
155 } EvlogError;
156
157 typedef struct _EvlogInfo
158 {
159     EvlogType     type;
160
161     int           mask;
162     EvlogClient   client;
163     EvlogRequest  req;
164     EvlogEvent    evt;
165     EvlogReply    rep;
166     EvlogError    err;
167     EvlogAtom     evatom;
168     EvlogRegion   evregion;
169
170     CARD32        time;
171 } EvlogInfo;
172
173
174 typedef struct _ExtensionInfo ExtensionInfo;
175
176 struct _ExtensionInfo
177 {
178     void  (*get_base_func) (ExtensionInfo *extinfo);
179     int     opcode;
180     int     evt_base;
181     int     err_base;
182     char* (*req_func) (EvlogInfo *evinfo, int detail_level, char *reply, int *len);
183     char* (*evt_func) (EvlogInfo *evinfo, int first_base, int detail_level, char *reply, int *len);
184     char* (*rep_func) (EvlogInfo *evinfo, int detail_level, char *reply, int *len);
185 };
186
187 #endif