summaryrefslogtreecommitdiff
path: root/src/bin
diff options
context:
space:
mode:
authorStefan Schmidt <s.schmidt@samsung.com>2020-03-09 17:25:03 +0100
committerStefan Schmidt <s.schmidt@samsung.com>2020-03-12 16:41:07 +0100
commitb69bc02c022955c00243cbcdd1b97276fb470190 (patch)
treeee90b3011354e89533d2c196f2fe549a1647bee1 /src/bin
parent525113650d7551f57d1b7e2006fbb071232b0f5f (diff)
exactness: factor out duplicated code for debug session handling
No need to have these macros ducplicated in two file, we can just share them and reduce maintenance. Reviewed-by: Mike Blumenkrantz <michael.blumenkrantz@gmail.com> Differential Revision: https://phab.enlightenment.org/D11459
Diffstat (limited to 'src/bin')
-rw-r--r--src/bin/exactness/common.h91
-rw-r--r--src/bin/exactness/injector.c75
-rw-r--r--src/bin/exactness/player.c76
3 files changed, 91 insertions, 151 deletions
diff --git a/src/bin/exactness/common.h b/src/bin/exactness/common.h
index 1f84d80db7..2581c63392 100644
--- a/src/bin/exactness/common.h
+++ b/src/bin/exactness/common.h
@@ -6,4 +6,95 @@
6#include <Exactness.h> 6#include <Exactness.h>
7#include <exactness_private.h> 7#include <exactness_private.h>
8 8
9typedef struct
10{
11 Eina_Debug_Session *session;
12 int srcid;
13 void *buffer;
14 unsigned int size;
15} _Main_Loop_Info;
16
17#define WRAPPER_TO_XFER_MAIN_LOOP(foo) \
18static void \
19_intern_main_loop ## foo(void *data) \
20{ \
21 _Main_Loop_Info *info = data; \
22 _main_loop ## foo(info->session, info->srcid, info->buffer, info->size); \
23 free(info->buffer); \
24 free(info); \
25} \
26static Eina_Bool \
27foo(Eina_Debug_Session *session, int srcid, void *buffer, int size) \
28{ \
29 _Main_Loop_Info *info = calloc(1, sizeof(*info)); \
30 info->session = session; \
31 info->srcid = srcid; \
32 info->size = size; \
33 if (info->size) \
34 { \
35 info->buffer = malloc(info->size); \
36 memcpy(info->buffer, buffer, info->size); \
37 } \
38 ecore_main_loop_thread_safe_call_async(_intern_main_loop ## foo, info); \
39 return EINA_TRUE; \
40}
41
42#ifndef WORDS_BIGENDIAN
43#define SWAP_64(x) x
44#define SWAP_32(x) x
45#define SWAP_16(x) x
46#define SWAP_DBL(x) x
47#else
48#define SWAP_64(x) eina_swap64(x)
49#define SWAP_32(x) eina_swap32(x)
50#define SWAP_16(x) eina_swap16(x)
51#define SWAP_DBL(x) SWAP_64(x)
52#endif
53
54#define EXTRACT_INT(_buf) \
55({ \
56 int __i; \
57 memcpy(&__i, _buf, sizeof(int)); \
58 _buf += sizeof(int); \
59 SWAP_32(__i); \
60})
61
62#define EXTRACT_DOUBLE(_buf) \
63({ \
64 double __d; \
65 memcpy(&__d, _buf, sizeof(double)); \
66 _buf += sizeof(double); \
67 SWAP_DBL(__d); \
68})
69
70#define EXTRACT_STRING(_buf) \
71({ \
72 char *__s = _buf ? strdup(_buf) : NULL; \
73 int __len = (__s ? strlen(__s) : 0) + 1; \
74 _buf += __len; \
75 __s; \
76})
77
78#define STORE_INT(_buf, __i) \
79({ \
80 int __si = SWAP_32(__i); \
81 memcpy(_buf, &__si, sizeof(int)); \
82 _buf += sizeof(int); \
83})
84
85#define STORE_DOUBLE(_buf, __d) \
86{ \
87 double __d2 = SWAP_DBL(__d); \
88 memcpy(_buf, &__d2, sizeof(double)); \
89 _buf += sizeof(double); \
90}
91
92#define STORE_STRING(_buf, __s) \
93{ \
94 int __len = (__s ? strlen(__s) : 0) + 1; \
95 if (__s) memcpy(_buf, __s, __len); \
96 else *_buf = '\0'; \
97 _buf += __len; \
98}
99
9void ex_printf(int verbose, const char *fmt, ...); 100void ex_printf(int verbose, const char *fmt, ...);
diff --git a/src/bin/exactness/injector.c b/src/bin/exactness/injector.c
index 882752620d..928de47a62 100644
--- a/src/bin/exactness/injector.c
+++ b/src/bin/exactness/injector.c
@@ -16,81 +16,6 @@
16#include <Exactness.h> 16#include <Exactness.h>
17#include "common.h" 17#include "common.h"
18 18
19typedef struct
20{
21 Eina_Debug_Session *session;
22 int srcid;
23 void *buffer;
24 unsigned int size;
25} _Main_Loop_Info;
26
27#define WRAPPER_TO_XFER_MAIN_LOOP(foo) \
28static void \
29_intern_main_loop ## foo(void *data) \
30{ \
31 _Main_Loop_Info *info = data; \
32 _main_loop ## foo(info->session, info->srcid, info->buffer, info->size); \
33 free(info->buffer); \
34 free(info); \
35} \
36static Eina_Bool \
37foo(Eina_Debug_Session *session, int srcid, void *buffer, int size) \
38{ \
39 _Main_Loop_Info *info = calloc(1, sizeof(*info)); \
40 info->session = session; \
41 info->srcid = srcid; \
42 info->size = size; \
43 if (info->size) \
44 { \
45 info->buffer = malloc(info->size); \
46 memcpy(info->buffer, buffer, info->size); \
47 } \
48 ecore_main_loop_thread_safe_call_async(_intern_main_loop ## foo, info); \
49 return EINA_TRUE; \
50}
51
52#ifndef WORDS_BIGENDIAN
53#define SWAP_64(x) x
54#define SWAP_32(x) x
55#define SWAP_16(x) x
56#define SWAP_DBL(x) x
57#else
58#define SWAP_64(x) eina_swap64(x)
59#define SWAP_32(x) eina_swap32(x)
60#define SWAP_16(x) eina_swap16(x)
61#define SWAP_DBL(x) SWAP_64(x)
62#endif
63
64#define EXTRACT_INT(_buf) \
65({ \
66 int __i; \
67 memcpy(&__i, _buf, sizeof(int)); \
68 _buf += sizeof(int); \
69 SWAP_32(__i); \
70})
71
72#define STORE_INT(_buf, __i) \
73{ \
74 int __i2 = SWAP_32(__i); \
75 memcpy(_buf, &__i2, sizeof(int)); \
76 _buf += sizeof(int); \
77}
78
79#define STORE_DOUBLE(_buf, __d) \
80{ \
81 double __d2 = SWAP_DBL(__d); \
82 memcpy(_buf, &__d2, sizeof(double)); \
83 _buf += sizeof(double); \
84}
85
86#define STORE_STRING(_buf, __s) \
87{ \
88 int __len = (__s ? strlen(__s) : 0) + 1; \
89 if (__s) memcpy(_buf, __s, __len); \
90 else *_buf = '\0'; \
91 _buf += __len; \
92}
93
94static Eina_Stringshare *_src_filename = NULL; 19static Eina_Stringshare *_src_filename = NULL;
95static Exactness_Unit *_src_unit = NULL; 20static Exactness_Unit *_src_unit = NULL;
96static int _verbose = 0; 21static int _verbose = 0;
diff --git a/src/bin/exactness/player.c b/src/bin/exactness/player.c
index b11a843205..fa9f0c63d3 100644
--- a/src/bin/exactness/player.c
+++ b/src/bin/exactness/player.c
@@ -36,82 +36,6 @@
36#define IMAGE_FILENAME_EXT ".png" 36#define IMAGE_FILENAME_EXT ".png"
37#define PAUSE_KEY_STR "F2" 37#define PAUSE_KEY_STR "F2"
38 38
39typedef struct
40{
41 Eina_Debug_Session *session;
42 int srcid;
43 void *buffer;
44 unsigned int size;
45} _Main_Loop_Info;
46
47#define WRAPPER_TO_XFER_MAIN_LOOP(foo) \
48static void \
49_intern_main_loop ## foo(void *data) \
50{ \
51 _Main_Loop_Info *info = data; \
52 _main_loop ## foo(info->session, info->srcid, info->buffer, info->size); \
53 free(info->buffer); \
54 free(info); \
55} \
56static Eina_Bool \
57foo(Eina_Debug_Session *session, int srcid, void *buffer, int size) \
58{ \
59 _Main_Loop_Info *info = calloc(1, sizeof(*info)); \
60 info->session = session; \
61 info->srcid = srcid; \
62 info->size = size; \
63 if (info->size) \
64 { \
65 info->buffer = malloc(info->size); \
66 memcpy(info->buffer, buffer, info->size); \
67 } \
68 ecore_main_loop_thread_safe_call_async(_intern_main_loop ## foo, info); \
69 return EINA_TRUE; \
70}
71
72#ifndef WORDS_BIGENDIAN
73#define SWAP_64(x) x
74#define SWAP_32(x) x
75#define SWAP_16(x) x
76#define SWAP_DBL(x) x
77#else
78#define SWAP_64(x) eina_swap64(x)
79#define SWAP_32(x) eina_swap32(x)
80#define SWAP_16(x) eina_swap16(x)
81#define SWAP_DBL(x) SWAP_64(x)
82#endif
83
84#define EXTRACT_INT(_buf) \
85({ \
86 int __i; \
87 memcpy(&__i, _buf, sizeof(int)); \
88 _buf += sizeof(int); \
89 SWAP_32(__i); \
90})
91
92#define EXTRACT_DOUBLE(_buf) \
93({ \
94 double __d; \
95 memcpy(&__d, _buf, sizeof(double)); \
96 _buf += sizeof(double); \
97 SWAP_DBL(__d); \
98})
99
100#define EXTRACT_STRING(_buf) \
101({ \
102 char *__s = _buf ? strdup(_buf) : NULL; \
103 int __len = (__s ? strlen(__s) : 0) + 1; \
104 _buf += __len; \
105 __s; \
106})
107
108#define STORE_INT(_buf, __i) \
109({ \
110 int __si = SWAP_32(__i); \
111 memcpy(_buf, &__si, sizeof(int)); \
112 _buf += sizeof(int); \
113})
114
115typedef enum 39typedef enum
116{ 40{
117 FTYPE_UNKNOWN, 41 FTYPE_UNKNOWN,