tizen 2.4 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     XERROR
86 } EvlogType;
87
88 #define EVLOG_MASK_CLIENT    (1<<0)
89 #define EVLOG_MASK_REQUEST   (1<<1)
90 #define EVLOG_MASK_EVENT     (1<<2)
91 #define EVLOG_MASK_REPLY     (1<<3)
92 #define EVLOG_MASK_ERROR     (1<<4)
93 #define EVLOG_MASK_ATOM      (1<<5)
94 #define EVLOG_MASK_REGION    (1<<6)
95
96 #define EVLOG_PRINT_DEFAULT           0
97 #define EVLOG_PRINT_DETAIL            1
98 #define EVLOG_PRINT_REPLY_DETAIL      2
99
100
101 typedef struct _EvlogTable
102 {
103     CARD32           xid;
104     char             buf[XDBG_BUF_SIZE];
105     struct xorg_list link;
106 } EvlogAtomTable, EvlogRegionTable;
107
108 typedef struct _EvlogList
109 {
110     struct xorg_list list;
111     int              init;
112     int              size;
113 } EvlogAtom, EvlogRegion;
114
115 typedef struct _EvlogClient
116 {
117     int     index;
118     int     pid;
119     int     gid;
120     int     uid;
121     char    command[PATH_MAX+1];
122     void*   pClient;
123 } EvlogClient;
124
125 typedef struct _EvlogRequest
126 {
127     int     id;
128     CARD32  length;
129     xReq   *ptr;
130     char    name[PATH_MAX+1];
131 } EvlogRequest;
132
133 typedef struct _EvlogEvent
134 {
135     xEvent *ptr;
136     int     size;
137     char    name[PATH_MAX+1];
138 } EvlogEvent;
139
140 typedef struct _EvlogReply
141 {
142     xGenericReply  *ptr;
143     int             size;
144     char            name[PATH_MAX+1];
145     int             reqType;
146     int             reqData;
147     Bool            isStart;
148 } EvlogReply;
149
150 typedef struct _EvlogError
151 {
152     char errorName[PATH_MAX+1];
153     char majorName[PATH_MAX+1];
154     BYTE    errorCode;
155     CARD32  resourceID;
156     CARD16  minorCode;
157     CARD8   majorCode;
158 } EvlogError;
159
160 typedef struct _EvlogInfo
161 {
162     EvlogType     type;
163
164     int           mask;
165     EvlogClient   client;
166     EvlogRequest  req;
167     EvlogEvent    evt;
168     EvlogReply    rep;
169     EvlogError    err;
170     EvlogAtom     evatom;
171     EvlogRegion   evregion;
172
173     CARD32        time;
174 } EvlogInfo;
175
176
177 typedef struct _ExtensionInfo ExtensionInfo;
178
179 struct _ExtensionInfo
180 {
181     void  (*get_base_func) (ExtensionInfo *extinfo);
182     int     opcode;
183     int     evt_base;
184     int     err_base;
185     char* (*req_func) (EvlogInfo *evinfo, int detail_level, char *reply, int *len);
186     char* (*evt_func) (EvlogInfo *evinfo, int first_base, int detail_level, char *reply, int *len);
187     char* (*rep_func) (EvlogInfo *evinfo, int detail_level, char *reply, int *len);
188 };
189
190 #endif