2 * Copyright 2017-2018 Philippe Proulx <pproulx@efficios.com>
3 * Copyright 2013, 2014 Jérémie Galarneau <jeremie.galarneau@efficios.com>
5 * Permission is hereby granted, free of charge, to any person obtaining a copy
6 * of this software and associated documentation files (the "Software"), to deal
7 * in the Software without restriction, including without limitation the rights
8 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 * copies of the Software, and to permit persons to whom the Software is
10 * furnished to do so, subject to the following conditions:
12 * The above copyright notice and this permission notice shall be included in
13 * all copies or substantial portions of the Software.
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
24 #define BT_LOG_TAG "LIB/EVENT"
25 #include "lib/logging.h"
27 #include "lib/assert-pre.h"
28 #include <babeltrace2/trace-ir/event-const.h>
29 #include <babeltrace2/trace-ir/event-class.h>
30 #include <babeltrace2/trace-ir/stream-class.h>
31 #include <babeltrace2/trace-ir/stream-class-const.h>
32 #include <babeltrace2/trace-ir/packet.h>
33 #include <babeltrace2/trace-ir/trace.h>
34 #include "common/assert.h"
35 #include "compat/compiler.h"
39 #include "field-class.h"
41 #include "stream-class.h"
46 #include "attributes.h"
47 #include "event-class.h"
50 void _bt_event_set_is_frozen(const struct bt_event
*event
, bool is_frozen
)
53 BT_LIB_LOGD("Setting event's frozen state: %!+e, is-frozen=%d",
56 if (event
->common_context_field
) {
57 BT_LOGD_STR("Setting event's common context field's frozen state.");
58 bt_field_set_is_frozen(
59 event
->common_context_field
, is_frozen
);
62 if (event
->specific_context_field
) {
63 BT_LOGD_STR("Setting event's specific context field's frozen state.");
64 bt_field_set_is_frozen(event
->specific_context_field
,
68 if (event
->payload_field
) {
69 BT_LOGD_STR("Setting event's payload field's frozen state.");
70 bt_field_set_is_frozen(event
->payload_field
,
74 ((struct bt_event
*) event
)->frozen
= is_frozen
;
77 BT_LOGD_STR("Setting event's packet's frozen state.");
78 bt_packet_set_is_frozen(event
->packet
, is_frozen
);
83 struct bt_event
*bt_event_new(struct bt_event_class
*event_class
)
85 struct bt_event
*event
= NULL
;
86 struct bt_stream_class
*stream_class
;
87 struct bt_field_class
*fc
;
89 BT_ASSERT(event_class
);
90 event
= g_new0(struct bt_event
, 1);
92 BT_LIB_LOGE_APPEND_CAUSE("Failed to allocate one event.");
96 bt_object_init_unique(&event
->base
);
97 stream_class
= bt_event_class_borrow_stream_class(event_class
);
98 BT_ASSERT(stream_class
);
99 fc
= stream_class
->event_common_context_fc
;
101 event
->common_context_field
= bt_field_create(fc
);
102 if (!event
->common_context_field
) {
103 /* bt_field_create() logs errors */
108 fc
= event_class
->specific_context_fc
;
110 event
->specific_context_field
= bt_field_create(fc
);
111 if (!event
->specific_context_field
) {
112 /* bt_field_create() logs errors */
117 fc
= event_class
->payload_fc
;
119 event
->payload_field
= bt_field_create(fc
);
120 if (!event
->payload_field
) {
121 /* bt_field_create() logs errors */
130 bt_event_destroy(event
);
138 struct bt_event_class
*bt_event_borrow_class(struct bt_event
*event
)
140 BT_ASSERT_PRE_DEV_NON_NULL(event
, "Event");
144 const struct bt_event_class
*bt_event_borrow_class_const(
145 const struct bt_event
*event
)
147 return bt_event_borrow_class((void *) event
);
150 struct bt_stream
*bt_event_borrow_stream(struct bt_event
*event
)
152 BT_ASSERT_PRE_DEV_NON_NULL(event
, "Event");
153 return event
->stream
;
156 const struct bt_stream
*bt_event_borrow_stream_const(
157 const struct bt_event
*event
)
159 return bt_event_borrow_stream((void *) event
);
162 struct bt_field
*bt_event_borrow_common_context_field(struct bt_event
*event
)
164 BT_ASSERT_PRE_DEV_NON_NULL(event
, "Event");
165 return event
->common_context_field
;
168 const struct bt_field
*bt_event_borrow_common_context_field_const(
169 const struct bt_event
*event
)
171 BT_ASSERT_PRE_DEV_NON_NULL(event
, "Event");
172 return event
->common_context_field
;
175 struct bt_field
*bt_event_borrow_specific_context_field(struct bt_event
*event
)
177 BT_ASSERT_PRE_DEV_NON_NULL(event
, "Event");
178 return event
->specific_context_field
;
181 const struct bt_field
*bt_event_borrow_specific_context_field_const(
182 const struct bt_event
*event
)
184 BT_ASSERT_PRE_DEV_NON_NULL(event
, "Event");
185 return event
->specific_context_field
;
188 struct bt_field
*bt_event_borrow_payload_field(struct bt_event
*event
)
190 BT_ASSERT_PRE_DEV_NON_NULL(event
, "Event");
191 return event
->payload_field
;
194 const struct bt_field
*bt_event_borrow_payload_field_const(
195 const struct bt_event
*event
)
197 BT_ASSERT_PRE_DEV_NON_NULL(event
, "Event");
198 return event
->payload_field
;
202 void bt_event_destroy(struct bt_event
*event
)
205 BT_LIB_LOGD("Destroying event: %!+e", event
);
207 if (event
->common_context_field
) {
208 BT_LOGD_STR("Destroying event's stream event context field.");
209 bt_field_destroy(event
->common_context_field
);
210 event
->common_context_field
= NULL
;
213 if (event
->specific_context_field
) {
214 BT_LOGD_STR("Destroying event's context field.");
215 bt_field_destroy(event
->specific_context_field
);
216 event
->specific_context_field
= NULL
;
219 if (event
->payload_field
) {
220 BT_LOGD_STR("Destroying event's payload field.");
221 bt_field_destroy(event
->payload_field
);
222 event
->payload_field
= NULL
;
225 BT_LOGD_STR("Putting event's class.");
226 bt_object_put_ref(event
->class);
227 BT_LOGD_STR("Putting event's packet.");
228 BT_OBJECT_PUT_REF_AND_RESET(event
->packet
);
229 BT_LOGD_STR("Putting event's stream.");
230 BT_OBJECT_PUT_REF_AND_RESET(event
->stream
);
234 struct bt_packet
*bt_event_borrow_packet(struct bt_event
*event
)
236 BT_ASSERT_PRE_DEV_NON_NULL(event
, "Event");
237 return event
->packet
;
240 const struct bt_packet
*bt_event_borrow_packet_const(
241 const struct bt_event
*event
)
243 return bt_event_borrow_packet((void *) event
);
This page took 0.035157 seconds and 5 git commands to generate.