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