lib: have default clock snapshot in event message
[babeltrace.git] / lib / trace-ir / event.c
CommitLineData
273b65be 1/*
e2f7325d 2 * Copyright 2017-2018 Philippe Proulx <pproulx@efficios.com>
de9dd397 3 * Copyright 2013, 2014 Jérémie Galarneau <jeremie.galarneau@efficios.com>
273b65be
JG
4 *
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:
11 *
12 * The above copyright notice and this permission notice shall be included in
13 * all copies or substantial portions of the Software.
14 *
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
21 * SOFTWARE.
22 */
23
7b010242
PP
24#define BT_LOG_TAG "EVENT"
25#include <babeltrace/lib-logging-internal.h>
26
3dca2276 27#include <babeltrace/assert-pre-internal.h>
c6bd8523
PP
28#include <babeltrace/trace-ir/field-internal.h>
29#include <babeltrace/trace-ir/field-class-internal.h>
40f4ba76 30#include <babeltrace/trace-ir/event-const.h>
56e18c4c
PP
31#include <babeltrace/trace-ir/event-internal.h>
32#include <babeltrace/trace-ir/event-class.h>
33#include <babeltrace/trace-ir/event-class-internal.h>
34#include <babeltrace/trace-ir/stream-class.h>
40f4ba76 35#include <babeltrace/trace-ir/stream-class-const.h>
56e18c4c
PP
36#include <babeltrace/trace-ir/stream-class-internal.h>
37#include <babeltrace/trace-ir/stream-internal.h>
38#include <babeltrace/trace-ir/packet.h>
39#include <babeltrace/trace-ir/packet-internal.h>
40#include <babeltrace/trace-ir/trace.h>
41#include <babeltrace/trace-ir/trace-internal.h>
42#include <babeltrace/trace-ir/packet-internal.h>
56e18c4c 43#include <babeltrace/trace-ir/attributes-internal.h>
f6ccaed9 44#include <babeltrace/assert-internal.h>
c5b9b441 45#include <babeltrace/compiler-internal.h>
7b010242 46#include <inttypes.h>
273b65be 47
3dca2276 48BT_HIDDEN
40f4ba76 49void _bt_event_set_is_frozen(const struct bt_event *event, bool is_frozen)
3dca2276 50{
3dca2276 51 BT_ASSERT(event);
44c440bc
PP
52 BT_LIB_LOGD("Setting event's frozen state: %!+e, is-frozen=%d",
53 event, is_frozen);
312c056a 54
44c440bc
PP
55 if (event->common_context_field) {
56 BT_LOGD_STR("Setting event's common context field's frozen state.");
57 bt_field_set_is_frozen(
58 event->common_context_field, is_frozen);
312c056a
PP
59 }
60
44c440bc
PP
61 if (event->specific_context_field) {
62 BT_LOGD_STR("Setting event's specific context field's frozen state.");
63 bt_field_set_is_frozen(event->specific_context_field,
6c677fb5 64 is_frozen);
312c056a
PP
65 }
66
67 if (event->payload_field) {
44c440bc
PP
68 BT_LOGD_STR("Setting event's payload field's frozen state.");
69 bt_field_set_is_frozen(event->payload_field,
6c677fb5 70 is_frozen);
312c056a
PP
71 }
72
40f4ba76 73 ((struct bt_event *) event)->frozen = is_frozen;
44c440bc 74 BT_LOGD_STR("Setting event's packet's frozen state.");
cb6f1f7d 75 bt_packet_set_is_frozen(event->packet, is_frozen);
3dca2276
PP
76}
77
312c056a
PP
78BT_HIDDEN
79struct bt_event *bt_event_new(struct bt_event_class *event_class)
3dca2276 80{
3dca2276 81 struct bt_event *event = NULL;
312c056a 82 struct bt_stream_class *stream_class;
5cd6d0e5 83 struct bt_field_class *fc;
3dca2276 84
44c440bc 85 BT_ASSERT(event_class);
3dca2276
PP
86 event = g_new0(struct bt_event, 1);
87 if (!event) {
88 BT_LOGE_STR("Failed to allocate one event.");
89 goto error;
90 }
91
44c440bc 92 bt_object_init_unique(&event->base);
312c056a
PP
93 stream_class = bt_event_class_borrow_stream_class(event_class);
94 BT_ASSERT(stream_class);
40f4ba76 95 fc = stream_class->event_common_context_fc;
5cd6d0e5
PP
96 if (fc) {
97 event->common_context_field = bt_field_create(fc);
44c440bc
PP
98 if (!event->common_context_field) {
99 /* bt_field_create() logs errors */
100 goto error;
101 }
102 }
103
40f4ba76 104 fc = event_class->specific_context_fc;
5cd6d0e5
PP
105 if (fc) {
106 event->specific_context_field = bt_field_create(fc);
44c440bc
PP
107 if (!event->specific_context_field) {
108 /* bt_field_create() logs errors */
109 goto error;
110 }
111 }
112
40f4ba76 113 fc = event_class->payload_fc;
5cd6d0e5
PP
114 if (fc) {
115 event->payload_field = bt_field_create(fc);
44c440bc
PP
116 if (!event->payload_field) {
117 /* bt_field_create() logs errors */
118 goto error;
119 }
120 }
121
3dca2276
PP
122 goto end;
123
124error:
312c056a
PP
125 if (event) {
126 bt_event_destroy(event);
127 event = NULL;
128 }
129
130end:
131 return event;
132}
133
094ff7c0 134struct bt_event_class *bt_event_borrow_class(struct bt_event *event)
2f100782 135{
f6ccaed9 136 BT_ASSERT_PRE_NON_NULL(event, "Event");
cb6f1f7d 137 return event->class;
2f100782
JG
138}
139
40f4ba76
PP
140const struct bt_event_class *bt_event_borrow_class_const(
141 const struct bt_event *event)
142{
143 return bt_event_borrow_class((void *) event);
144}
145
f6ccaed9 146struct bt_stream *bt_event_borrow_stream(struct bt_event *event)
f6ccaed9
PP
147{
148 BT_ASSERT_PRE_NON_NULL(event, "Event");
094ff7c0 149 return event->packet ? event->packet->stream : NULL;
f6ccaed9
PP
150}
151
40f4ba76
PP
152const struct bt_stream *bt_event_borrow_stream_const(
153 const struct bt_event *event)
154{
155 return bt_event_borrow_stream((void *) event);
156}
157
44c440bc 158struct bt_field *bt_event_borrow_common_context_field(struct bt_event *event)
662e778c 159{
cb6f1f7d 160 BT_ASSERT_PRE_NON_NULL(event, "Event");
44c440bc 161 return event->common_context_field;
662e778c
JG
162}
163
40f4ba76
PP
164const struct bt_field *bt_event_borrow_common_context_field_const(
165 const struct bt_event *event)
e5be10ef 166{
40f4ba76
PP
167 BT_ASSERT_PRE_NON_NULL(event, "Event");
168 return event->common_context_field;
e5be10ef
PP
169}
170
44c440bc 171struct bt_field *bt_event_borrow_specific_context_field(struct bt_event *event)
f655a84d 172{
cb6f1f7d 173 BT_ASSERT_PRE_NON_NULL(event, "Event");
44c440bc 174 return event->specific_context_field;
f655a84d
JG
175}
176
40f4ba76
PP
177const struct bt_field *bt_event_borrow_specific_context_field_const(
178 const struct bt_event *event)
e5be10ef 179{
40f4ba76
PP
180 BT_ASSERT_PRE_NON_NULL(event, "Event");
181 return event->specific_context_field;
e5be10ef
PP
182}
183
44c440bc 184struct bt_field *bt_event_borrow_payload_field(struct bt_event *event)
5fd2e9fd 185{
cb6f1f7d 186 BT_ASSERT_PRE_NON_NULL(event, "Event");
44c440bc 187 return event->payload_field;
5fd2e9fd
PP
188}
189
40f4ba76
PP
190const struct bt_field *bt_event_borrow_payload_field_const(
191 const struct bt_event *event)
e5be10ef 192{
40f4ba76
PP
193 BT_ASSERT_PRE_NON_NULL(event, "Event");
194 return event->payload_field;
e5be10ef
PP
195}
196
44c440bc
PP
197BT_HIDDEN
198void bt_event_destroy(struct bt_event *event)
cb6f1f7d 199{
44c440bc
PP
200 BT_ASSERT(event);
201 BT_LIB_LOGD("Destroying event: %!+e", event);
cb6f1f7d 202
44c440bc
PP
203 if (event->common_context_field) {
204 BT_LOGD_STR("Destroying event's stream event context field.");
205 bt_field_destroy(event->common_context_field);
238b7404 206 event->common_context_field = NULL;
cb6f1f7d
PP
207 }
208
44c440bc
PP
209 if (event->specific_context_field) {
210 BT_LOGD_STR("Destroying event's context field.");
211 bt_field_destroy(event->specific_context_field);
238b7404 212 event->specific_context_field = NULL;
cb6f1f7d
PP
213 }
214
215 if (event->payload_field) {
44c440bc
PP
216 BT_LOGD_STR("Destroying event's payload field.");
217 bt_field_destroy(event->payload_field);
238b7404 218 event->payload_field = NULL;
cb6f1f7d
PP
219 }
220
44c440bc 221 BT_LOGD_STR("Putting event's class.");
65300d60 222 bt_object_put_ref(event->class);
03039f21 223 BT_LOGD_STR("Putting event's packet.");
238b7404 224 BT_OBJECT_PUT_REF_AND_RESET(event->packet);
273b65be
JG
225 g_free(event);
226}
227
094ff7c0 228struct bt_packet *bt_event_borrow_packet(struct bt_event *event)
5c0f40f4 229{
f6ccaed9 230 BT_ASSERT_PRE_NON_NULL(event, "Event");
44c440bc 231 return event->packet;
5c0f40f4
JG
232}
233
40f4ba76
PP
234const struct bt_packet *bt_event_borrow_packet_const(
235 const struct bt_event *event)
e5be10ef 236{
40f4ba76 237 return bt_event_borrow_packet((void *) event);
e5be10ef 238}
This page took 0.067014 seconds and 4 git commands to generate.