c8fe9c088fb4c0a4cd231d806778d2a23cd2a255
[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
38 #define XDBG_PATH_MAX        1024
39
40 #define MAX(a,b) (((a) > (b)) ? (a) : (b))
41 #define MIN(a,b) (((a) < (b)) ? (a) : (b))
42 #define SWAP(a, b)  ({int t; t = a; a = b; b = t;})
43
44 #define WARNING_IF_FAIL(cond) \
45     {if (!(cond)) { fprintf (stderr, "[%s] '%s' failed.\n", __FUNCTION__, #cond);}}
46 #define RETURN_IF_FAIL(cond) \
47     {if (!(cond)) { fprintf (stderr, "[%s] '%s' failed.\n", __FUNCTION__, #cond); return; }}
48 #define RETURN_VAL_IF_FAIL(cond, val) \
49     {if (!(cond)) { fprintf (stderr, "[%s] '%s' failed.\n", __FUNCTION__, #cond); return val; }}
50 #define RETURN_VAL_IF_ERRNO(cond, val, errno) \
51     {if (!(cond)) { fprintf (stderr, "[%s] '%s' failed. (err=%s(%d))\n", __FUNCTION__, #cond, strerror(errno), errno); return val; }}
52 #define GOTO_IF_FAIL(cond, dst) \
53     {if (!(cond)) { fprintf (stderr, "[%s] '%s' failed.\n", __FUNCTION__, #cond); goto dst; }}
54 #define GOTO_IF_ERRNO(cond, dst, errno) \
55     {if (!(cond)) { fprintf (stderr, "[%s] '%s' failed. (err=%s(%d))\n", __FUNCTION__, #cond, strerror(errno), errno); goto dst; }}
56
57 #define REPLY(fmt, ARG...)  \
58     do { \
59         if (reply && len && *len > 0) \
60         { \
61             int s = snprintf (reply, *len, fmt, ##ARG); \
62             reply += s; \
63             *len -= s; \
64         } \
65     } while (0)
66
67 #define UNKNOWN_EVENT "<unknown>"
68
69 typedef enum
70 {
71     EVENT,
72     REQUEST,
73     REPLY,
74     FLUSH
75 } EvlogType;
76
77 #define EVLOG_MASK_CLIENT    (1<<0)
78 #define EVLOG_MASK_REQUEST   (1<<1)
79 #define EVLOG_MASK_EVENT     (1<<2)
80
81 typedef struct _EvlogClient
82 {
83     int     index;
84     int     pid;
85     int     gid;
86     int     uid;
87     char    command[PATH_MAX+1];
88 } EvlogClient;
89
90 typedef struct _EvlogRequest
91 {
92     int     id;
93     CARD32  length;
94     xReq   *ptr;
95     char    name[PATH_MAX+1];
96 } EvlogRequest;
97
98 typedef struct _EvlogEvent
99 {
100     xEvent *ptr;
101     char    name[PATH_MAX+1];
102 } EvlogEvent;
103
104 typedef struct _EvlogInfo
105 {
106     EvlogType    type;
107
108     int          mask;
109     EvlogClient  client;
110     EvlogRequest req;
111     EvlogEvent   evt;
112
113     CARD32       time;
114 } EvlogInfo;
115
116 #endif