b973798a819343eaa98c54bd801a551f4e2b76ad
2 * SPDX-License-Identifier: MIT
4 * Copyright 2017-2018 Philippe Proulx <pproulx@efficios.com>
5 * Copyright 2013, 2014 Jérémie Galarneau <jeremie.galarneau@efficios.com>
8 #define BT_LOG_TAG "LIB/EVENT"
9 #include "lib/logging.h"
11 #include "lib/assert-cond.h"
12 #include <babeltrace2/trace-ir/event.h>
13 #include <babeltrace2/trace-ir/event-class.h>
14 #include <babeltrace2/trace-ir/stream-class.h>
15 #include <babeltrace2/trace-ir/packet.h>
16 #include <babeltrace2/trace-ir/trace.h>
17 #include "common/assert.h"
18 #include "compat/compiler.h"
23 #include "field-class.h"
25 #include "stream-class.h"
30 #include "attributes.h"
31 #include "event-class.h"
34 void _bt_event_set_is_frozen(const struct bt_event
*event
, bool is_frozen
)
37 BT_LIB_LOGD("Setting event's frozen state: %!+e, is-frozen=%d",
40 if (event
->common_context_field
) {
41 BT_LOGD_STR("Setting event's common context field's frozen state.");
42 bt_field_set_is_frozen(
43 event
->common_context_field
, is_frozen
);
46 if (event
->specific_context_field
) {
47 BT_LOGD_STR("Setting event's specific context field's frozen state.");
48 bt_field_set_is_frozen(event
->specific_context_field
,
52 if (event
->payload_field
) {
53 BT_LOGD_STR("Setting event's payload field's frozen state.");
54 bt_field_set_is_frozen(event
->payload_field
,
58 ((struct bt_event
*) event
)->frozen
= is_frozen
;
61 BT_LOGD_STR("Setting event's packet's frozen state.");
62 bt_packet_set_is_frozen(event
->packet
, is_frozen
);
67 struct bt_event
*bt_event_new(struct bt_event_class
*event_class
)
69 struct bt_event
*event
= NULL
;
70 struct bt_stream_class
*stream_class
;
71 struct bt_field_class
*fc
;
73 BT_ASSERT(event_class
);
74 event
= g_new0(struct bt_event
, 1);
76 BT_LIB_LOGE_APPEND_CAUSE("Failed to allocate one event.");
80 bt_object_init_unique(&event
->base
);
81 stream_class
= bt_event_class_borrow_stream_class(event_class
);
82 BT_ASSERT(stream_class
);
83 fc
= stream_class
->event_common_context_fc
;
85 event
->common_context_field
= bt_field_create(fc
);
86 if (!event
->common_context_field
) {
87 /* bt_field_create() logs errors */
92 fc
= event_class
->specific_context_fc
;
94 event
->specific_context_field
= bt_field_create(fc
);
95 if (!event
->specific_context_field
) {
96 /* bt_field_create() logs errors */
101 fc
= event_class
->payload_fc
;
103 event
->payload_field
= bt_field_create(fc
);
104 if (!event
->payload_field
) {
105 /* bt_field_create() logs errors */
114 bt_event_destroy(event
);
122 struct bt_event_class
*bt_event_borrow_class(struct bt_event
*event
)
124 BT_ASSERT_PRE_DEV_NON_NULL(event
, "Event");
128 const struct bt_event_class
*bt_event_borrow_class_const(
129 const struct bt_event
*event
)
131 return bt_event_borrow_class((void *) event
);
134 struct bt_stream
*bt_event_borrow_stream(struct bt_event
*event
)
136 BT_ASSERT_PRE_DEV_NON_NULL(event
, "Event");
137 return event
->stream
;
140 const struct bt_stream
*bt_event_borrow_stream_const(
141 const struct bt_event
*event
)
143 return bt_event_borrow_stream((void *) event
);
146 struct bt_field
*bt_event_borrow_common_context_field(struct bt_event
*event
)
148 BT_ASSERT_PRE_DEV_NON_NULL(event
, "Event");
149 return event
->common_context_field
;
152 const struct bt_field
*bt_event_borrow_common_context_field_const(
153 const struct bt_event
*event
)
155 BT_ASSERT_PRE_DEV_NON_NULL(event
, "Event");
156 return event
->common_context_field
;
159 struct bt_field
*bt_event_borrow_specific_context_field(struct bt_event
*event
)
161 BT_ASSERT_PRE_DEV_NON_NULL(event
, "Event");
162 return event
->specific_context_field
;
165 const struct bt_field
*bt_event_borrow_specific_context_field_const(
166 const struct bt_event
*event
)
168 BT_ASSERT_PRE_DEV_NON_NULL(event
, "Event");
169 return event
->specific_context_field
;
172 struct bt_field
*bt_event_borrow_payload_field(struct bt_event
*event
)
174 BT_ASSERT_PRE_DEV_NON_NULL(event
, "Event");
175 return event
->payload_field
;
178 const struct bt_field
*bt_event_borrow_payload_field_const(
179 const struct bt_event
*event
)
181 BT_ASSERT_PRE_DEV_NON_NULL(event
, "Event");
182 return event
->payload_field
;
186 void bt_event_destroy(struct bt_event
*event
)
189 BT_LIB_LOGD("Destroying event: %!+e", event
);
191 if (event
->common_context_field
) {
192 BT_LOGD_STR("Destroying event's stream event context field.");
193 bt_field_destroy(event
->common_context_field
);
194 event
->common_context_field
= NULL
;
197 if (event
->specific_context_field
) {
198 BT_LOGD_STR("Destroying event's context field.");
199 bt_field_destroy(event
->specific_context_field
);
200 event
->specific_context_field
= NULL
;
203 if (event
->payload_field
) {
204 BT_LOGD_STR("Destroying event's payload field.");
205 bt_field_destroy(event
->payload_field
);
206 event
->payload_field
= NULL
;
209 BT_LOGD_STR("Putting event's class.");
210 bt_object_put_ref(event
->class);
211 BT_LOGD_STR("Putting event's packet.");
212 BT_OBJECT_PUT_REF_AND_RESET(event
->packet
);
213 BT_LOGD_STR("Putting event's stream.");
214 BT_OBJECT_PUT_REF_AND_RESET(event
->stream
);
218 struct bt_packet
*bt_event_borrow_packet(struct bt_event
*event
)
220 BT_ASSERT_PRE_DEV_NON_NULL(event
, "Event");
221 return event
->packet
;
224 const struct bt_packet
*bt_event_borrow_packet_const(
225 const struct bt_event
*event
)
227 return bt_event_borrow_packet((void *) event
);
This page took 0.032623 seconds and 3 git commands to generate.