1 /*****
2  *       Xnee's Not an Event Emulator
3  *
4  * Xnee enables recording and replaying of X protocol data
5  *
6  * Copyright (C) 1999, 2000, 2001, 2002, 2003, 2013
7  *       Henrik Sandklef
8  *
9  * This program is free software; you can redistribute it and/or
10  * modify it under the terms of the GNU General Public License
11  * as published by the Free Software Foundation; either version 3
12  * of the License, or any later version.
13  *
14  *
15  * This program is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU General Public License for more details.
19  *
20  * You should have received a copy of the GNU General Public License
21  * along with this program; if not, write to the Free Software
22  * Foundation, Inc., 51 Franklin Street, Boston,
23  * MA  02110-1301, USA.
24  ****/
25 
26 
27 #ifndef XNEE_XNEE_INTERNAL_H
28 #define XNEE_XNEE_INTERNAL_H
29 
30 
31 #include <stdio.h>
32 #include <unistd.h>
33 
34 #include <signal.h>
35 
36 #include "libxnee/xnee_settings.h"
37 
38 
39 
40 #ifdef HAVE_CONFIG_H
41 #include <config.h>
42 #endif /* HAVE_CONFIG_H */
43 
44 #ifdef HAVE_STDARG_H
45 #include <stdarg.h>
46 #else
47 #include <varargs.h>
48 #endif
49 
50 
51 /* needed for the RECORD extension */
52 #ifndef NEED_EVENTS
53 #define NEED_EVENTS
54 #endif  /* NEED_EVENTS */
55 
56 #ifndef NEED_REPLIES
57 #define NEED_REPLIES
58 #endif  /* NEED_REPLIES */
59 
60 
61 
62 #ifdef HAVE_CONFIG_H
63 #  include "config.h"
64 #endif
65 
66 
67 /* If not using GNU C skip: __attribute__ */
68 #ifndef __GNUC__
69 #  define  __attribute__(x)  /*NOTHING AT ALL*/
70 #endif
71 
72 #define XNEE_FREE(a)               xnee_free(a);
73 #define XNEE_FCLOSE(a)             (void)fclose(a);
74 
75 #define XNEE_FREE_AND_NULL(a)      XNEE_FREE(a); a=NULL;
76 #define XNEE_FCLOSE_AND_NULL(a)    XNEE_FCLOSE(a); a=NULL;
77 
78 #define XNEE_FREE_IF_NOT_NULL(a)   if (a!=NULL) { XNEE_FREE_AND_NULL(a);   }
79 #define XNEE_FCLOSE_IF_NOT_NULL(a) if (a!=NULL) { XNEE_FCLOSE_AND_NULL(a); }
80 #define XNEE_CLOSE_DISPLAY_IF_NOT_NULL(a) if(a!=NULL) { XCloseDisplay(a); a=NULL; }
81 
82 
83 
84 /* ** Do NOT edit ** */
85 enum _xnee_data_types {
86   XNEE_EVENT  = 0,
87   XNEE_REQUEST  ,
88   XNEE_REPLY             ,
89   XNEE_ERROR             ,
90   XNEE_DELIVERED_EVENT   ,
91   XNEE_DEVICE_EVENT      ,
92   XNEE_EXT_REPLY_MAJOR   ,
93   XNEE_EXT_REPLY_MINOR   ,
94   XNEE_EXT_REQUEST_MAJOR ,
95   XNEE_EXT_REQUEST_MINOR ,
96   XNEE_NR_OF_TYPES       ,
97   XNEE_META_DATA         ,
98   XNEE_REPLAY_DATA       ,
99   XNEE_SETTINGS_DATA     ,
100   XNEE_MARK_DATA         ,
101   XNEE_ACTION_DATA       ,
102   XNEE_PRIMITIVE_DATA    ,
103   XNEE_PROJECT_INFORMATION_DATA,
104   XNEE_NEW_WINDOW_DATA,
105   XNEE_PREDEF_EVENTS,
106   XNEE_NO_DATA
107 } ;
108 
109 /* ** Do NOT edit ** */
110 enum _xnee_mode {
111   XNEE_NOMODE    = 0,
112   XNEE_REPLAYER     ,
113   XNEE_RECORDER     ,
114   XNEE_RETYPER      ,
115   XNEE_DISTRIBUTOR  ,
116   XNEE_SYNTAX_CHECKER
117 } ;
118 
119 
120 
121 
122 /* this macro might be dangerous
123    .. don't use when incrementing variables (e.g i++) */
124 #define XNEE_MAX(x, y)   ((x)>(y)?(x):(y))
125 
126 /* this macro might be dangerous
127    .. don't use when decrementing variables (e.g i++) */
128 #define XNEE_MIN(x, y)   ((x)>(y)?(y):(x))
129 
130 /* this macro might be dangerous
131    .. don't use when incrementing variables (e.g i++) */
132 #define XNEE_ABS(x)   ((x)>0?(x):(0-(x)))
133 
134 #ifdef XNEE_WANT_DEBUG
135 #define XNEE_DEBUG(arg) fprintf arg
136 #else
137 #define XNEE_DEBUG(arg)
138 #endif
139 
140 #ifdef XNEE_WANT_SYNC_DEBUG
141 #define XNEE_SYNC_DEBUG(arg) fprintf arg
142 #else
143 #define XNEE_SYNC_DEBUG(arg)
144 #endif
145 
146 
147 /* AIX's XTestFakeKeyEvent has a bug with the last argument
148  * requires 0 - so we use usleep instead
149  *
150  *       OBSOLETE
151  *
152  */
153 #ifdef  AIX
154 #define XTEST_ERR_SLEEP(per)  usleep (per*1000)
155 #else
156 #define XTEST_ERR_SLEEP(per)
157 #endif
158 /* EO OBSOLETE */
159 
160 
161 
162 #define XNEE_FAKE_SLEEP(per)  { if (per>1000)usleep (per*1000); }
163 
164 #define XNEE_RETURN_IF_ERR(ret_val) \
165    if (ret_val!=XNEE_OK)            \
166    {                                                                    \
167       const char *xnee_macro_tmp ;                                      \
168       (void) fprintf (stderr, "Xnee error\n");                          \
169       xnee_macro_tmp = xnee_get_err_description (ret);                  \
170       (void) fprintf (stderr, "Description: %s\n", xnee_macro_tmp );    \
171       xnee_macro_tmp = xnee_get_err_solution (ret) ;                    \
172       (void) fprintf (stderr, "Solution:    %s\n", xnee_macro_tmp);     \
173       return (ret);                                                     \
174    }
175 
176 #define XNEE_RETURN_NULL_IF_ERR(ret_val) \
177    if (ret_val != XNEE_OK)               \
178    {                                     \
179       return (NULL);                     \
180    }
181 
182 #define XNEE_RETURN_VOID_IF_ERR(ret_val) \
183    if (ret_val != XNEE_OK)               \
184    {                                     \
185       const char *xnee_macro_tmp ;                                      \
186       (void) fprintf (stderr, "Xnee error\n");                          \
187       xnee_macro_tmp = xnee_get_err_description (ret);                  \
188       (void) fprintf (stderr, "Description: %s\n", xnee_macro_tmp );    \
189       xnee_macro_tmp = xnee_get_err_solution (ret) ;                    \
190       (void) fprintf (stderr, "Solution:    %s\n", xnee_macro_tmp);     \
191       return;                            \
192    }
193 
194 #define XNEE_SILENTLY_RETURN_VOID_IF_ERR(ret_val) \
195    if (ret_val != XNEE_OK)               \
196    {                                     \
197       return;                            \
198    }
199 
200 /*
201  * Resolution states
202  *
203  */
204 enum xnee_resolution_states
205   {
206     XNEE_RESOLUTION_UNSET  = -1,
207     XNEE_RESOLUTION_USED   =  0,
208     XNEE_RESOLUTION_UNUSED =  1
209   };
210 
211 /*
212  * Grab modes/actions
213  */
214 enum xnee_grab_modes
215   {
216     XNEE_GRAB_STOP    = 0,
217     XNEE_GRAB_PAUSE   ,
218     XNEE_GRAB_RESUME  ,
219     XNEE_GRAB_INSERT  ,
220     XNEE_GRAB_EXEC    ,
221     XNEE_GRAB_LAST,
222     XNEE_GRAB_NODATA = 0,
223     XNEE_GRAB_SET    = 1,
224     XNEE_GRAB_UNKOWN  = 15
225   };
226 
227 /*
228  *  continue_process commnd enum
229  */
230 enum cont_proc_commands
231   {
232     XNEE_PROCESS_RESET = 0 ,
233     XNEE_PROCESS_INC       ,
234     XNEE_PROCESS_DEC       ,
235     XNEE_PROCESS_GET
236   };
237 
238 typedef void (*callback_ptr)( XPointer, XRecordInterceptData *);
239 typedef callback_ptr *callback_ptrptr;
240 
241 typedef void (*synch_ptr)( XPointer, XRecordInterceptData *);
242 typedef synch_ptr *synch_ptrptr;
243 
244 typedef int (*print_fptr)  ( const char*, ... );
245 typedef int (*fprint_fptr) (FILE*,  const char*, ... );
246 typedef int (*vfprint_fptr) (FILE*,  const char*, va_list ap );
247 
248 
249 #endif /*  XNEE_XNEE_INTERNAL_H */
250