summaryrefslogtreecommitdiff
path: root/src/bin/exactness/common.h
blob: c34bc6f8ba7d96020180cf617c3ce74d8c7acf81 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
#ifdef HAVE_CONFIG_H
# include <config.h>
#endif

#include <Eet.h>
#include <Evas.h>
#include <Elementary.h>

typedef struct
{
   Eina_Debug_Session *session;
   int srcid;
   void *buffer;
   unsigned int size;
} _Main_Loop_Info;

#define WRAPPER_TO_XFER_MAIN_LOOP(foo) \
static void \
_intern_main_loop ## foo(void *data) \
{ \
   _Main_Loop_Info *info = data; \
   _main_loop ## foo(info->session, info->srcid, info->buffer, info->size); \
   free(info->buffer); \
   free(info); \
} \
static Eina_Bool \
foo(Eina_Debug_Session *session, int srcid, void *buffer, int size) \
{ \
   _Main_Loop_Info *info = calloc(1, sizeof(*info)); \
   info->session = session; \
   info->srcid = srcid; \
   info->size = size; \
   if (info->size) \
     { \
        info->buffer = malloc(info->size); \
        memcpy(info->buffer, buffer, info->size); \
     } \
   ecore_main_loop_thread_safe_call_async(_intern_main_loop ## foo, info); \
   return EINA_TRUE; \
}

#ifndef WORDS_BIGENDIAN
#define SWAP_64(x) x
#define SWAP_32(x) x
#define SWAP_16(x) x
#define SWAP_DBL(x) x
#else
#define SWAP_64(x) eina_swap64(x)
#define SWAP_32(x) eina_swap32(x)
#define SWAP_16(x) eina_swap16(x)
#define SWAP_DBL(x) SWAP_64(x)
#endif

#define EXTRACT_INT(_buf) \
({ \
   int __i; \
   memcpy(&__i, _buf, sizeof(int)); \
   _buf += sizeof(int); \
   SWAP_32(__i); \
})

#define EXTRACT_DOUBLE(_buf) \
({ \
   double __d; \
   memcpy(&__d, _buf, sizeof(double)); \
   _buf += sizeof(double); \
   SWAP_DBL(__d); \
})

#define EXTRACT_STRING(_buf) \
({ \
   char *__s = _buf ? strdup(_buf) : NULL; \
   int __len = (__s ? strlen(__s) : 0) + 1; \
   _buf += __len; \
   __s; \
})

#define STORE_INT(_buf, __i) \
({ \
   int __si = SWAP_32(__i); \
   memcpy(_buf, &__si, sizeof(int)); \
   _buf += sizeof(int); \
})

#define STORE_DOUBLE(_buf, __d) \
{ \
   double __d2 = SWAP_DBL(__d); \
   memcpy(_buf, &__d2, sizeof(double)); \
   _buf += sizeof(double); \
}

#define STORE_STRING(_buf, __s) \
{ \
   int __len = (__s ? strlen(__s) : 0) + 1; \
   if (__s) memcpy(_buf, __s, __len); \
   else *_buf = '\0'; \
   _buf += __len; \
}

#define SHOT_DELIMITER '+'

/**
 * @page exactness_main Exactness
 *
 * @date 2018 (created)
 *
 * This page describes the public structures and APIs available for Exactness.
 *
 * @addtogroup Exactness
 * @{
 */

/**
 * @typedef Exactness_Action_Type
 * The type values for an Exactness action.
 */
typedef enum
{
   EXACTNESS_ACTION_UNKNOWN = 0,
   EXACTNESS_ACTION_MOUSE_IN,
   EXACTNESS_ACTION_MOUSE_OUT,
   EXACTNESS_ACTION_MOUSE_WHEEL,
   EXACTNESS_ACTION_MULTI_DOWN,
   EXACTNESS_ACTION_MULTI_UP,
   EXACTNESS_ACTION_MULTI_MOVE,
   EXACTNESS_ACTION_KEY_DOWN,
   EXACTNESS_ACTION_KEY_UP,
   EXACTNESS_ACTION_TAKE_SHOT,
   EXACTNESS_ACTION_EFL_EVENT,
   EXACTNESS_ACTION_CLICK_ON,
   EXACTNESS_ACTION_STABILIZE,
   EXACTNESS_ACTION_LAST = EXACTNESS_ACTION_STABILIZE
   /* Add any supported actions here and update _LAST */
} Exactness_Action_Type;

/**
 * @typedef Exactness_Action_Mouse_Wheel
 * The type for the Exactness Mouse Wheel action.
 */
typedef struct
{
   int direction;
   int z;
} Exactness_Action_Mouse_Wheel;

/**
 * @typedef Exactness_Action_Key_Down_Up
 * The type for the Exactness Key Down Up action.
 */
typedef struct
{
   const char *keyname;
   const char *key;
   const char *string;
   const char *compose;
   unsigned int keycode;
} Exactness_Action_Key_Down_Up;

/**
 * @typedef Exactness_Action_Multi_Event
 * The type for the Exactness Multi Event action.
 */
typedef struct
{
   int d;
   int b; /* In case of simple mouse down/up, corresponds to the button */
   int x;
   int y;
   double rad;
   double radx;
   double rady;
   double pres;
   double ang;
   double fx;
   double fy;
   Evas_Button_Flags flags;
} Exactness_Action_Multi_Event;

/**
 * @typedef Exactness_Action_Multi_Move
 * The type for the Exactness Multi Move action.
 */
typedef struct
{
   int d;
   int x;
   int y;
   double rad;
   double radx;
   double rady;
   double pres;
   double ang;
   double fx;
   double fy;
} Exactness_Action_Multi_Move;

/**
 * @typedef Exactness_Action_Efl_Event
 * The type for the Exactness EFL Event action.
 */
typedef struct
{
   char *wdg_name;
   char *event_name;
} Exactness_Action_Efl_Event;

/**
 * @typedef Exactness_Action_Click_On
 * The type for the Exactness Click on (widget) action.
 */
typedef struct
{
   char *wdg_name;
} Exactness_Action_Click_On;

/**
 * @typedef Exactness_Action
 * The type for the Exactness action.
 */
typedef struct
{
   Exactness_Action_Type type;   /**< The action type */
   unsigned int n_evas;          /**< The evas number on which the action has to be applied */
   unsigned int delay_ms;        /**< The delay (in ms) to wait for this action */
   void *data;                   /**< The specific action data */
} Exactness_Action;

/**
 * @typedef Exactness_Object
 * The type for the Exactness object.
 */
typedef struct
{
   long long id;                 /**< The Eo pointer */
   long long parent_id;          /**< The Eo parent pointer */
   const char *kl_name;          /**< The class name */

   Eina_List *children; /* NOT EET */

   /* Evas stuff */
   int x;   /**< The X coordinate */
   int y;   /**< The Y coordinate */
   int w;   /**< The object width */
   int h;   /**< The object height */
} Exactness_Object;

/**
 * @typedef Exactness_Objects
 * The type for the Exactness objects list.
 */
typedef struct
{
   Eina_List *objs;        /**< List of all the objects */
   /* main_objs not in EET */
   Eina_List *main_objs;   /**< List of the main objects */
} Exactness_Objects;

/**
 * @typedef Exactness_Image
 * The type for the Exactness Image.
 */
typedef struct
{
   unsigned int w;   /**< Width of the image */
   unsigned int h;   /**< Height of the image */
   void *pixels;     /**< Pixels of the image */
} Exactness_Image;

typedef struct
{
   char *language; /**< String describing the language of the content e.g "C"...*/
   char *content; /**< Content used as source */
   char *command; /**< Command needed to generate the application from the content */
} Exactness_Source_Code;

typedef struct
{
   Eina_List *actions;  /**< List of Exactness_Action */
   /* imgs not in EET */
   Eina_List *imgs;     /**< List of Exactness_Image */
   Eina_List *objs;     /**< List of Exactness_Objects */
   Eina_List *codes;    /**< List of Exactness_Source_Code */
   const char *fonts_path; /**< Path to the fonts to use, relative to the fonts dir given in parameter to the player/recorder */
   int nb_shots;        /**< The number of shots present in the unit */
} Exactness_Unit;

Evas *(*_evas_new)(void);
const char *_exactness_action_type_to_string_get(Exactness_Action_Type type);

/**
 * @brief Read an unit from a given file
 *
 * @param filename Name of the file containing the unit
 *
 * @return the unit
 */
Exactness_Unit *exactness_unit_file_read(const char *filename);

/**
 * @brief Write an unit into the given file
 *
 * @param unit Unit to store
 * @param filename Name of the file containing the unit
 *
 * @return EINA_TRUE on success, EINA_FALSE otherwise
 */
Eina_Bool exactness_unit_file_write(Exactness_Unit *unit, const char *filename);

/**
 * @brief Compare two images
 *
 * @param img1 first image
 * @param img2 second image
 * @param imgO pointer for the diff image. Can be NULL
 *
 * @return EINA_TRUE if the images are different, EINA_FALSE otherwise
 */
Eina_Bool exactness_image_compare(Exactness_Image *img1, Exactness_Image *img2, Exactness_Image **imgO);

/**
 * @brief Free the given image
 *
 * @param img the image
 *
 */
void exactness_image_free(Exactness_Image *img);

/**
 * @}
 */

void ex_printf(int verbose, const char *fmt, ...);
int ex_prg_invoke(const char *full_path, int argc, char **argv, Eina_Bool player);
Eina_Stringshare *ex_prg_full_path_guess(const char *prg);