1 /*
2 Copyright (C) 2018 Red Hat, Inc.
3
4 This library is free software; you can redistribute it and/or
5 modify it under the terms of the GNU Lesser General Public
6 License as published by the Free Software Foundation; either
7 version 2.1 of the License, or (at your option) any later version.
8
9 This library is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 Lesser General Public License for more details.
13
14 You should have received a copy of the GNU Lesser General Public
15 License along with this library; if not, see <http://www.gnu.org/licenses/>.
16 */
17 /* This file include recorder library headers or if disabled provide
18 * replacement declarations */
19
20 #ifdef ENABLE_RECORDER
21 #include <common/recorder/recorder.h>
22
23 #elif defined(ENABLE_AGENT_INTERFACE)
24 #include <common/agent_interface.h>
25
26 #else
27
28 #include <stdio.h>
29 #include <stdint.h>
30 #include <spice/macros.h>
31
32 /* Replacement declarations.
33 * There declarations should generate no code (beside when no optimization are
34 * selected) but catch some possible programming warnings/errors at
35 * compile/link time like:
36 * - usage of undeclared recorders;
37 * - recording formats and arguments;
38 * - matching RECORD_TIMING_BEGIN and RECORD_TIMING_END.
39 * The only exceptions are tweaks which just generate a variable to hold the
40 * value.
41 */
42
43 typedef struct SpiceEmptyStruct {
44 char dummy[0];
45 } SpiceEmptyStruct;
46
47 typedef struct SpiceDummyTweak {
48 intptr_t tweak_value;
49 } SpiceDummyTweak;
50
51 #define RECORDER_DECLARE(rec) \
52 extern const SpiceEmptyStruct spice_recorder_ ## rec
53 #define RECORDER(rec, num_rings, comment) \
54 RECORDER_DEFINE(rec, num_rings, comment)
55 #define RECORDER_DEFINE(rec, num_rings, comment) \
56 const SpiceEmptyStruct SPICE_GNUC_UNUSED spice_recorder_ ## rec = {}
57 #define RECORDER_TRACE(rec) \
58 (sizeof(spice_recorder_ ## rec) != sizeof(SpiceEmptyStruct))
59 #define RECORDER_TWEAK_DECLARE(rec) \
60 extern const SpiceDummyTweak spice_recorder_tweak_ ## rec
61 #define RECORDER_TWEAK_DEFINE(rec, value, comment) \
62 const SpiceDummyTweak spice_recorder_tweak_ ## rec = { (value) }
63 #define RECORDER_TWEAK(rec) \
64 ((spice_recorder_tweak_ ## rec).tweak_value)
65 #define RECORD(rec, ...) do { \
66 if (sizeof((spice_recorder_ ## rec).dummy)) printf(__VA_ARGS__); \
67 } while(0)
68 #define RECORD_TIMING_BEGIN(rec) \
69 do { RECORD(rec, "begin");
70 #define RECORD_TIMING_END(rec, op, name, value) \
71 RECORD(rec, "end" op name); \
72 } while(0)
73 #define record(...) \
74 RECORD(__VA_ARGS__)
75 static inline void
recorder_dump_on_common_signals(unsigned add,unsigned remove)76 recorder_dump_on_common_signals(unsigned add, unsigned remove)
77 {
78 }
79 #endif
80
81 #if !defined(ENABLE_AGENT_INTERFACE)
82 #ifdef __cplusplus
83 extern "C" {
84 #endif // __cplusplus
85
86 /* Stubs for Agent-Interface specific definitions */
87 static inline void
agent_interface_start(unsigned int port)88 agent_interface_start(unsigned int port)
89 {
90 }
91
92 typedef void (*forward_quality_cb_t)(void *, const char *);
93 static inline void
agent_interface_set_forward_quality_cb(forward_quality_cb_t cb,void * data)94 agent_interface_set_forward_quality_cb(forward_quality_cb_t cb, void *data)
95 {
96 }
97
98 typedef int (*on_connect_cb_t)(void *);
99 static inline void
agent_interface_set_on_connect_cb(on_connect_cb_t cb,void * data)100 agent_interface_set_on_connect_cb(on_connect_cb_t cb, void *data)
101 {
102 }
103 #ifdef __cplusplus
104 }
105 #endif // __cplusplus
106 #endif
107