lib: merge common CTF IR part with the remaining implementation
[babeltrace.git] / include / babeltrace / ctf-ir / trace-internal.h
1 #ifndef BABELTRACE_CTF_IR_TRACE_INTERNAL_H
2 #define BABELTRACE_CTF_IR_TRACE_INTERNAL_H
3
4 /*
5 * BabelTrace - CTF IR: Trace internal
6 *
7 * Copyright 2014 Jérémie Galarneau <jeremie.galarneau@efficios.com>
8 *
9 * Author: Jérémie Galarneau <jeremie.galarneau@efficios.com>
10 *
11 * Permission is hereby granted, free of charge, to any person obtaining a copy
12 * of this software and associated documentation files (the "Software"), to deal
13 * in the Software without restriction, including without limitation the rights
14 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
15 * copies of the Software, and to permit persons to whom the Software is
16 * furnished to do so, subject to the following conditions:
17 *
18 * The above copyright notice and this permission notice shall be included in
19 * all copies or substantial portions of the Software.
20 *
21 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
22 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
23 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
24 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
25 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
26 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
27 * SOFTWARE.
28 */
29
30 #include <babeltrace/assert-pre-internal.h>
31 #include <babeltrace/ctf-ir/trace.h>
32 #include <babeltrace/ctf-ir/stream-class-internal.h>
33 #include <babeltrace/ctf-ir/field-types.h>
34 #include <babeltrace/ctf-ir/fields.h>
35 #include <babeltrace/ctf-ir/validation-internal.h>
36 #include <babeltrace/ctf-ir/attributes-internal.h>
37 #include <babeltrace/ctf-ir/clock-class-internal.h>
38 #include <babeltrace/object-internal.h>
39 #include <babeltrace/object-pool-internal.h>
40 #include <babeltrace/babeltrace-internal.h>
41 #include <babeltrace/values.h>
42 #include <babeltrace/types.h>
43 #include <glib.h>
44 #include <sys/types.h>
45 #include <babeltrace/compat/uuid-internal.h>
46
47 struct bt_trace {
48 struct bt_object base;
49 GString *name;
50 int frozen;
51 unsigned char uuid[BABELTRACE_UUID_LEN];
52 bt_bool uuid_set;
53 enum bt_byte_order native_byte_order;
54 struct bt_value *environment;
55 GPtrArray *clock_classes; /* Array of pointers to bt_clock_class */
56 GPtrArray *stream_classes; /* Array of ptrs to bt_stream_class */
57 GPtrArray *streams; /* Array of ptrs to bt_stream */
58 struct bt_field_type *packet_header_field_type;
59 int64_t next_stream_id;
60
61 /*
62 * This flag indicates if the trace is valid. A valid
63 * trace is _always_ frozen.
64 */
65 int valid;
66
67 GPtrArray *listeners; /* Array of struct listener_wrapper */
68 GArray *is_static_listeners;
69 bt_bool is_static;
70 bt_bool in_remove_listener;
71
72 /* Pool of `struct bt_field_wrapper *` */
73 struct bt_object_pool packet_header_field_pool;
74 };
75
76 BT_HIDDEN
77 int bt_trace_object_modification(struct bt_visitor_object *object,
78 void *trace_ptr);
79
80 BT_HIDDEN
81 bt_bool bt_trace_has_clock_class(struct bt_trace *trace,
82 struct bt_clock_class *clock_class);
83
84 /**
85 @brief User function type to use with bt_trace_add_listener().
86
87 @param[in] obj New CTF IR object which is part of the trace
88 class hierarchy.
89 @param[in] data User data.
90
91 @prenotnull{obj}
92 */
93 typedef void (*bt_listener_cb)(struct bt_visitor_object *obj, void *data);
94
95 /**
96 @brief Adds the trace class modification listener \p listener to
97 the CTF IR trace class \p trace_class.
98
99 Once you add \p listener to \p trace_class, whenever \p trace_class
100 is modified, \p listener is called with the new element and with
101 \p data (user data).
102
103 @param[in] trace_class Trace class to which to add \p listener.
104 @param[in] listener Modification listener function.
105 @param[in] data User data.
106 @returns 0 on success, or a negative value on error.
107
108 @prenotnull{trace_class}
109 @prenotnull{listener}
110 @postrefcountsame{trace_class}
111 */
112 BT_HIDDEN
113 int bt_trace_add_listener(struct bt_trace *trace_class,
114 bt_listener_cb listener, void *data);
115
116 static inline
117 void bt_trace_freeze(struct bt_trace *trace)
118 {
119 int i;
120
121 if (trace->frozen) {
122 return;
123 }
124
125 BT_LOGD("Freezing trace: addr=%p, name=\"%s\"",
126 trace, bt_trace_get_name(trace));
127 BT_LOGD_STR("Freezing packet header field type.");
128 bt_field_type_freeze(trace->packet_header_field_type);
129 BT_LOGD_STR("Freezing environment attributes.");
130 bt_attributes_freeze(trace->environment);
131
132 if (trace->clock_classes->len > 0) {
133 BT_LOGD_STR("Freezing clock classes.");
134 }
135
136 for (i = 0; i < trace->clock_classes->len; i++) {
137 struct bt_clock_class *clock_class =
138 g_ptr_array_index(trace->clock_classes, i);
139
140 bt_clock_class_freeze(clock_class);
141 }
142
143 trace->frozen = 1;
144 }
145
146 #endif /* BABELTRACE_CTF_IR_TRACE_INTERNAL_H */
This page took 0.032266 seconds and 4 git commands to generate.