Commit | Line | Data |
---|---|---|
273b65be | 1 | /* |
0235b0db MJ |
2 | * SPDX-License-Identifier: MIT |
3 | * | |
e2f7325d | 4 | * Copyright 2017-2018 Philippe Proulx <pproulx@efficios.com> |
de9dd397 | 5 | * Copyright 2013, 2014 Jérémie Galarneau <jeremie.galarneau@efficios.com> |
273b65be JG |
6 | */ |
7 | ||
350ad6c1 | 8 | #define BT_LOG_TAG "LIB/EVENT" |
c2d9d9cf | 9 | #include "lib/logging.h" |
7b010242 | 10 | |
d98421f2 | 11 | #include "lib/assert-cond.h" |
43c59509 | 12 | #include <babeltrace2/trace-ir/event.h> |
3fadfbc0 | 13 | #include <babeltrace2/trace-ir/event-class.h> |
3fadfbc0 | 14 | #include <babeltrace2/trace-ir/stream-class.h> |
3fadfbc0 | 15 | #include <babeltrace2/trace-ir/packet.h> |
3fadfbc0 | 16 | #include <babeltrace2/trace-ir/trace.h> |
578e048b MJ |
17 | #include "common/assert.h" |
18 | #include "compat/compiler.h" | |
7b010242 | 19 | #include <inttypes.h> |
c4f23e30 | 20 | #include <stdbool.h> |
273b65be | 21 | |
578e048b MJ |
22 | #include "field.h" |
23 | #include "field-class.h" | |
24 | #include "event.h" | |
25 | #include "stream-class.h" | |
26 | #include "stream.h" | |
27 | #include "packet.h" | |
28 | #include "trace.h" | |
29 | #include "packet.h" | |
30 | #include "attributes.h" | |
31 | #include "event-class.h" | |
32 | ||
3dca2276 | 33 | BT_HIDDEN |
40f4ba76 | 34 | void _bt_event_set_is_frozen(const struct bt_event *event, bool is_frozen) |
3dca2276 | 35 | { |
98b15851 | 36 | BT_ASSERT_DBG(event); |
44c440bc PP |
37 | BT_LIB_LOGD("Setting event's frozen state: %!+e, is-frozen=%d", |
38 | event, is_frozen); | |
312c056a | 39 | |
44c440bc PP |
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); | |
312c056a PP |
44 | } |
45 | ||
44c440bc PP |
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, | |
6c677fb5 | 49 | is_frozen); |
312c056a PP |
50 | } |
51 | ||
52 | if (event->payload_field) { | |
44c440bc PP |
53 | BT_LOGD_STR("Setting event's payload field's frozen state."); |
54 | bt_field_set_is_frozen(event->payload_field, | |
6c677fb5 | 55 | is_frozen); |
312c056a PP |
56 | } |
57 | ||
40f4ba76 | 58 | ((struct bt_event *) event)->frozen = is_frozen; |
26fc5aed PP |
59 | |
60 | if (event->packet) { | |
61 | BT_LOGD_STR("Setting event's packet's frozen state."); | |
62 | bt_packet_set_is_frozen(event->packet, is_frozen); | |
63 | } | |
3dca2276 PP |
64 | } |
65 | ||
312c056a PP |
66 | BT_HIDDEN |
67 | struct bt_event *bt_event_new(struct bt_event_class *event_class) | |
3dca2276 | 68 | { |
3dca2276 | 69 | struct bt_event *event = NULL; |
312c056a | 70 | struct bt_stream_class *stream_class; |
5cd6d0e5 | 71 | struct bt_field_class *fc; |
3dca2276 | 72 | |
44c440bc | 73 | BT_ASSERT(event_class); |
3dca2276 PP |
74 | event = g_new0(struct bt_event, 1); |
75 | if (!event) { | |
870631a2 | 76 | BT_LIB_LOGE_APPEND_CAUSE("Failed to allocate one event."); |
3dca2276 PP |
77 | goto error; |
78 | } | |
79 | ||
44c440bc | 80 | bt_object_init_unique(&event->base); |
312c056a PP |
81 | stream_class = bt_event_class_borrow_stream_class(event_class); |
82 | BT_ASSERT(stream_class); | |
40f4ba76 | 83 | fc = stream_class->event_common_context_fc; |
5cd6d0e5 PP |
84 | if (fc) { |
85 | event->common_context_field = bt_field_create(fc); | |
44c440bc PP |
86 | if (!event->common_context_field) { |
87 | /* bt_field_create() logs errors */ | |
88 | goto error; | |
89 | } | |
90 | } | |
91 | ||
40f4ba76 | 92 | fc = event_class->specific_context_fc; |
5cd6d0e5 PP |
93 | if (fc) { |
94 | event->specific_context_field = bt_field_create(fc); | |
44c440bc PP |
95 | if (!event->specific_context_field) { |
96 | /* bt_field_create() logs errors */ | |
97 | goto error; | |
98 | } | |
99 | } | |
100 | ||
40f4ba76 | 101 | fc = event_class->payload_fc; |
5cd6d0e5 PP |
102 | if (fc) { |
103 | event->payload_field = bt_field_create(fc); | |
44c440bc PP |
104 | if (!event->payload_field) { |
105 | /* bt_field_create() logs errors */ | |
106 | goto error; | |
107 | } | |
108 | } | |
109 | ||
3dca2276 PP |
110 | goto end; |
111 | ||
112 | error: | |
312c056a PP |
113 | if (event) { |
114 | bt_event_destroy(event); | |
115 | event = NULL; | |
116 | } | |
117 | ||
118 | end: | |
119 | return event; | |
120 | } | |
121 | ||
094ff7c0 | 122 | struct bt_event_class *bt_event_borrow_class(struct bt_event *event) |
2f100782 | 123 | { |
d5b13b9b | 124 | BT_ASSERT_PRE_DEV_EVENT_NON_NULL(event); |
cb6f1f7d | 125 | return event->class; |
2f100782 JG |
126 | } |
127 | ||
40f4ba76 PP |
128 | const struct bt_event_class *bt_event_borrow_class_const( |
129 | const struct bt_event *event) | |
130 | { | |
131 | return bt_event_borrow_class((void *) event); | |
132 | } | |
133 | ||
f6ccaed9 | 134 | struct bt_stream *bt_event_borrow_stream(struct bt_event *event) |
f6ccaed9 | 135 | { |
d5b13b9b | 136 | BT_ASSERT_PRE_DEV_EVENT_NON_NULL(event); |
26fc5aed | 137 | return event->stream; |
f6ccaed9 PP |
138 | } |
139 | ||
40f4ba76 PP |
140 | const struct bt_stream *bt_event_borrow_stream_const( |
141 | const struct bt_event *event) | |
142 | { | |
143 | return bt_event_borrow_stream((void *) event); | |
144 | } | |
145 | ||
44c440bc | 146 | struct bt_field *bt_event_borrow_common_context_field(struct bt_event *event) |
662e778c | 147 | { |
d5b13b9b | 148 | BT_ASSERT_PRE_DEV_EVENT_NON_NULL(event); |
44c440bc | 149 | return event->common_context_field; |
662e778c JG |
150 | } |
151 | ||
40f4ba76 PP |
152 | const struct bt_field *bt_event_borrow_common_context_field_const( |
153 | const struct bt_event *event) | |
e5be10ef | 154 | { |
d5b13b9b | 155 | BT_ASSERT_PRE_DEV_EVENT_NON_NULL(event); |
40f4ba76 | 156 | return event->common_context_field; |
e5be10ef PP |
157 | } |
158 | ||
44c440bc | 159 | struct bt_field *bt_event_borrow_specific_context_field(struct bt_event *event) |
f655a84d | 160 | { |
d5b13b9b | 161 | BT_ASSERT_PRE_DEV_EVENT_NON_NULL(event); |
44c440bc | 162 | return event->specific_context_field; |
f655a84d JG |
163 | } |
164 | ||
40f4ba76 PP |
165 | const struct bt_field *bt_event_borrow_specific_context_field_const( |
166 | const struct bt_event *event) | |
e5be10ef | 167 | { |
d5b13b9b | 168 | BT_ASSERT_PRE_DEV_EVENT_NON_NULL(event); |
40f4ba76 | 169 | return event->specific_context_field; |
e5be10ef PP |
170 | } |
171 | ||
44c440bc | 172 | struct bt_field *bt_event_borrow_payload_field(struct bt_event *event) |
5fd2e9fd | 173 | { |
d5b13b9b | 174 | BT_ASSERT_PRE_DEV_EVENT_NON_NULL(event); |
44c440bc | 175 | return event->payload_field; |
5fd2e9fd PP |
176 | } |
177 | ||
40f4ba76 PP |
178 | const struct bt_field *bt_event_borrow_payload_field_const( |
179 | const struct bt_event *event) | |
e5be10ef | 180 | { |
d5b13b9b | 181 | BT_ASSERT_PRE_DEV_EVENT_NON_NULL(event); |
40f4ba76 | 182 | return event->payload_field; |
e5be10ef PP |
183 | } |
184 | ||
44c440bc PP |
185 | BT_HIDDEN |
186 | void bt_event_destroy(struct bt_event *event) | |
cb6f1f7d | 187 | { |
44c440bc PP |
188 | BT_ASSERT(event); |
189 | BT_LIB_LOGD("Destroying event: %!+e", event); | |
cb6f1f7d | 190 | |
44c440bc PP |
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); | |
238b7404 | 194 | event->common_context_field = NULL; |
cb6f1f7d PP |
195 | } |
196 | ||
44c440bc PP |
197 | if (event->specific_context_field) { |
198 | BT_LOGD_STR("Destroying event's context field."); | |
199 | bt_field_destroy(event->specific_context_field); | |
238b7404 | 200 | event->specific_context_field = NULL; |
cb6f1f7d PP |
201 | } |
202 | ||
203 | if (event->payload_field) { | |
44c440bc PP |
204 | BT_LOGD_STR("Destroying event's payload field."); |
205 | bt_field_destroy(event->payload_field); | |
238b7404 | 206 | event->payload_field = NULL; |
cb6f1f7d PP |
207 | } |
208 | ||
44c440bc | 209 | BT_LOGD_STR("Putting event's class."); |
65300d60 | 210 | bt_object_put_ref(event->class); |
03039f21 | 211 | BT_LOGD_STR("Putting event's packet."); |
238b7404 | 212 | BT_OBJECT_PUT_REF_AND_RESET(event->packet); |
26fc5aed PP |
213 | BT_LOGD_STR("Putting event's stream."); |
214 | BT_OBJECT_PUT_REF_AND_RESET(event->stream); | |
273b65be JG |
215 | g_free(event); |
216 | } | |
217 | ||
094ff7c0 | 218 | struct bt_packet *bt_event_borrow_packet(struct bt_event *event) |
5c0f40f4 | 219 | { |
d5b13b9b | 220 | BT_ASSERT_PRE_DEV_EVENT_NON_NULL(event); |
44c440bc | 221 | return event->packet; |
5c0f40f4 JG |
222 | } |
223 | ||
40f4ba76 PP |
224 | const struct bt_packet *bt_event_borrow_packet_const( |
225 | const struct bt_event *event) | |
e5be10ef | 226 | { |
40f4ba76 | 227 | return bt_event_borrow_packet((void *) event); |
e5be10ef | 228 | } |