lib: merge common CTF IR part with the remaining implementation
[babeltrace.git] / include / babeltrace / ctf-ir / trace-internal.h
CommitLineData
daf01357
JG
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
3dca2276 30#include <babeltrace/assert-pre-internal.h>
daf01357 31#include <babeltrace/ctf-ir/trace.h>
3dca2276 32#include <babeltrace/ctf-ir/stream-class-internal.h>
2e33ac5a
PP
33#include <babeltrace/ctf-ir/field-types.h>
34#include <babeltrace/ctf-ir/fields.h>
3dca2276
PP
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>
83509119 38#include <babeltrace/object-internal.h>
312c056a 39#include <babeltrace/object-pool-internal.h>
daf01357 40#include <babeltrace/babeltrace-internal.h>
dac5c838 41#include <babeltrace/values.h>
c55a9f58 42#include <babeltrace/types.h>
daf01357
JG
43#include <glib.h>
44#include <sys/types.h>
20eee76e 45#include <babeltrace/compat/uuid-internal.h>
daf01357 46
cb6f1f7d 47struct bt_trace {
83509119 48 struct bt_object base;
e96045d4 49 GString *name;
daf01357 50 int frozen;
20eee76e 51 unsigned char uuid[BABELTRACE_UUID_LEN];
c55a9f58 52 bt_bool uuid_set;
50842bdc 53 enum bt_byte_order native_byte_order;
dac5c838 54 struct bt_value *environment;
3dca2276 55 GPtrArray *clock_classes; /* Array of pointers to bt_clock_class */
cb6f1f7d
PP
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;
9ac68eb1 59 int64_t next_stream_id;
09840de5
PP
60
61 /*
62 * This flag indicates if the trace is valid. A valid
63 * trace is _always_ frozen.
64 */
65 int valid;
3dca2276 66
50ad4244 67 GPtrArray *listeners; /* Array of struct listener_wrapper */
3602afb0 68 GArray *is_static_listeners;
c55a9f58 69 bt_bool is_static;
8480c8cc 70 bt_bool in_remove_listener;
312c056a
PP
71
72 /* Pool of `struct bt_field_wrapper *` */
73 struct bt_object_pool packet_header_field_pool;
daf01357
JG
74};
75
9b888ff3 76BT_HIDDEN
50842bdc 77int bt_trace_object_modification(struct bt_visitor_object *object,
9b888ff3
JG
78 void *trace_ptr);
79
c9d90a34 80BT_HIDDEN
cb6f1f7d 81bt_bool bt_trace_has_clock_class(struct bt_trace *trace,
50842bdc 82 struct bt_clock_class *clock_class);
c9d90a34 83
3230ee6b 84/**
50842bdc 85@brief User function type to use with bt_trace_add_listener().
3230ee6b
PP
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*/
50842bdc 93typedef void (*bt_listener_cb)(struct bt_visitor_object *obj, void *data);
3230ee6b
PP
94
95/**
96@brief Adds the trace class modification listener \p listener to
97 the CTF IR trace class \p trace_class.
98
99Once you add \p listener to \p trace_class, whenever \p trace_class
100is 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*/
5b876b06 112BT_HIDDEN
50842bdc
PP
113int bt_trace_add_listener(struct bt_trace *trace_class,
114 bt_listener_cb listener, void *data);
3230ee6b 115
3dca2276 116static inline
cb6f1f7d 117void bt_trace_freeze(struct bt_trace *trace)
3dca2276
PP
118{
119 int i;
120
121 if (trace->frozen) {
122 return;
123 }
124
125 BT_LOGD("Freezing trace: addr=%p, name=\"%s\"",
cb6f1f7d 126 trace, bt_trace_get_name(trace));
3dca2276 127 BT_LOGD_STR("Freezing packet header field type.");
cb6f1f7d 128 bt_field_type_freeze(trace->packet_header_field_type);
3dca2276
PP
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
daf01357 146#endif /* BABELTRACE_CTF_IR_TRACE_INTERNAL_H */
This page took 0.050349 seconds and 4 git commands to generate.