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/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
;
75 BT_LOGD_STR("Setting event's packet's frozen state.");
76 bt_packet_set_is_frozen(event
->packet
, is_frozen
);
80 struct bt_event
*bt_event_new(struct bt_event_class
*event_class
)
82 struct bt_event
*event
= NULL
;
83 struct bt_stream_class
*stream_class
;
84 struct bt_field_class
*fc
;
86 BT_ASSERT(event_class
);
87 event
= g_new0(struct bt_event
, 1);
89 BT_LOGE_STR("Failed to allocate one event.");
93 bt_object_init_unique(&event
->base
);
94 stream_class
= bt_event_class_borrow_stream_class(event_class
);
95 BT_ASSERT(stream_class
);
96 fc
= stream_class
->event_common_context_fc
;
98 event
->common_context_field
= bt_field_create(fc
);
99 if (!event
->common_context_field
) {
100 /* bt_field_create() logs errors */
105 fc
= event_class
->specific_context_fc
;
107 event
->specific_context_field
= bt_field_create(fc
);
108 if (!event
->specific_context_field
) {
109 /* bt_field_create() logs errors */
114 fc
= event_class
->payload_fc
;
116 event
->payload_field
= bt_field_create(fc
);
117 if (!event
->payload_field
) {
118 /* bt_field_create() logs errors */
127 bt_event_destroy(event
);
135 struct bt_event_class
*bt_event_borrow_class(struct bt_event
*event
)
137 BT_ASSERT_PRE_NON_NULL(event
, "Event");
141 const struct bt_event_class
*bt_event_borrow_class_const(
142 const struct bt_event
*event
)
144 return bt_event_borrow_class((void *) event
);
147 struct bt_stream
*bt_event_borrow_stream(struct bt_event
*event
)
149 BT_ASSERT_PRE_NON_NULL(event
, "Event");
150 return event
->packet
? event
->packet
->stream
: NULL
;
153 const struct bt_stream
*bt_event_borrow_stream_const(
154 const struct bt_event
*event
)
156 return bt_event_borrow_stream((void *) event
);
159 struct bt_field
*bt_event_borrow_common_context_field(struct bt_event
*event
)
161 BT_ASSERT_PRE_NON_NULL(event
, "Event");
162 return event
->common_context_field
;
165 const struct bt_field
*bt_event_borrow_common_context_field_const(
166 const struct bt_event
*event
)
168 BT_ASSERT_PRE_NON_NULL(event
, "Event");
169 return event
->common_context_field
;
172 struct bt_field
*bt_event_borrow_specific_context_field(struct bt_event
*event
)
174 BT_ASSERT_PRE_NON_NULL(event
, "Event");
175 return event
->specific_context_field
;
178 const struct bt_field
*bt_event_borrow_specific_context_field_const(
179 const struct bt_event
*event
)
181 BT_ASSERT_PRE_NON_NULL(event
, "Event");
182 return event
->specific_context_field
;
185 struct bt_field
*bt_event_borrow_payload_field(struct bt_event
*event
)
187 BT_ASSERT_PRE_NON_NULL(event
, "Event");
188 return event
->payload_field
;
191 const struct bt_field
*bt_event_borrow_payload_field_const(
192 const struct bt_event
*event
)
194 BT_ASSERT_PRE_NON_NULL(event
, "Event");
195 return event
->payload_field
;
199 void bt_event_destroy(struct bt_event
*event
)
202 BT_LIB_LOGD("Destroying event: %!+e", event
);
204 if (event
->common_context_field
) {
205 BT_LOGD_STR("Destroying event's stream event context field.");
206 bt_field_destroy(event
->common_context_field
);
207 event
->common_context_field
= NULL
;
210 if (event
->specific_context_field
) {
211 BT_LOGD_STR("Destroying event's context field.");
212 bt_field_destroy(event
->specific_context_field
);
213 event
->specific_context_field
= NULL
;
216 if (event
->payload_field
) {
217 BT_LOGD_STR("Destroying event's payload field.");
218 bt_field_destroy(event
->payload_field
);
219 event
->payload_field
= NULL
;
222 BT_LOGD_STR("Putting event's class.");
223 bt_object_put_ref(event
->class);
224 BT_LOGD_STR("Putting event's packet.");
225 BT_OBJECT_PUT_REF_AND_RESET(event
->packet
);
229 struct bt_packet
*bt_event_borrow_packet(struct bt_event
*event
)
231 BT_ASSERT_PRE_NON_NULL(event
, "Event");
232 return event
->packet
;
235 const struct bt_packet
*bt_event_borrow_packet_const(
236 const struct bt_event
*event
)
238 return bt_event_borrow_packet((void *) event
);
This page took 0.034397 seconds and 4 git commands to generate.