4 * Babeltrace CTF IR - Event class
6 * Copyright 2013, 2014 Jérémie Galarneau <jeremie.galarneau@efficios.com>
8 * Author: Jérémie Galarneau <jeremie.galarneau@efficios.com>
10 * Permission is hereby granted, free of charge, to any person obtaining a copy
11 * of this software and associated documentation files (the "Software"), to deal
12 * in the Software without restriction, including without limitation the rights
13 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
14 * copies of the Software, and to permit persons to whom the Software is
15 * furnished to do so, subject to the following conditions:
17 * The above copyright notice and this permission notice shall be included in
18 * all copies or substantial portions of the Software.
20 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
21 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
22 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
23 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
24 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
25 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
29 #define BT_LOG_TAG "EVENT-CLASS"
30 #include <babeltrace/lib-logging-internal.h>
32 #include <babeltrace/assert-pre-internal.h>
33 #include <babeltrace/ctf-ir/clock-value-internal.h>
34 #include <babeltrace/ctf-ir/fields-internal.h>
35 #include <babeltrace/ctf-ir/field-types-internal.h>
36 #include <babeltrace/ctf-ir/event-class.h>
37 #include <babeltrace/ctf-ir/event-class-internal.h>
38 #include <babeltrace/ctf-ir/event-internal.h>
39 #include <babeltrace/ctf-ir/stream-class.h>
40 #include <babeltrace/ctf-ir/stream-class-internal.h>
41 #include <babeltrace/ctf-ir/trace-internal.h>
42 #include <babeltrace/ctf-ir/validation-internal.h>
43 #include <babeltrace/ctf-ir/utils.h>
44 #include <babeltrace/ctf-ir/utils-internal.h>
45 #include <babeltrace/ref.h>
46 #include <babeltrace/ctf-ir/attributes-internal.h>
47 #include <babeltrace/compiler-internal.h>
48 #include <babeltrace/endian-internal.h>
49 #include <babeltrace/types.h>
50 #include <babeltrace/values-internal.h>
51 #include <babeltrace/assert-internal.h>
56 void bt_event_class_common_finalize(struct bt_object
*obj
)
58 struct bt_event_class_common
*event_class
;
60 event_class
= container_of(obj
, struct bt_event_class_common
, base
);
61 BT_LOGD("Finalizing common event class: addr=%p, name=\"%s\", id=%" PRId64
,
62 event_class
, bt_event_class_common_get_name(event_class
),
63 bt_event_class_common_get_id(event_class
));
65 if (event_class
->name
) {
66 g_string_free(event_class
->name
, TRUE
);
69 if (event_class
->emf_uri
) {
70 g_string_free(event_class
->emf_uri
, TRUE
);
73 BT_LOGD_STR("Putting context field type.");
74 bt_put(event_class
->context_field_type
);
75 BT_LOGD_STR("Putting payload field type.");
76 bt_put(event_class
->payload_field_type
);
80 int bt_event_class_common_initialize(struct bt_event_class_common
*event_class
,
81 const char *name
, bt_object_release_func release_func
,
82 bt_field_type_structure_create_func ft_struct_create_func
)
86 BT_LOGD("Initializing common event class object: name=\"%s\"",
88 bt_object_init(event_class
, release_func
);
89 event_class
->payload_field_type
= ft_struct_create_func();
90 if (!event_class
->payload_field_type
) {
91 BT_LOGE_STR("Cannot create event class's initial payload field type object.");
96 event_class
->name
= g_string_new(name
);
97 if (!event_class
->name
) {
98 BT_LOGE_STR("Failed to allocate a GString.");
102 event_class
->emf_uri
= g_string_new(NULL
);
103 if (!event_class
->emf_uri
) {
104 BT_LOGE_STR("Failed to allocate a GString.");
108 event_class
->log_level
= BT_EVENT_CLASS_LOG_LEVEL_UNSPECIFIED
;
109 BT_LOGD("Initialized common event class object: addr=%p, name=\"%s\"",
110 event_class
, bt_event_class_common_get_name(event_class
));
119 void bt_event_class_destroy(struct bt_object
*obj
)
121 struct bt_event_class
*event_class
= (void *) obj
;
123 BT_LOGD("Destroying event class: addr=%p", obj
);
124 bt_event_class_common_finalize(obj
);
125 bt_object_pool_finalize(&event_class
->event_pool
);
130 void free_event(struct bt_event
*event
,
131 struct bt_event_class
*event_class
)
133 bt_event_destroy(event
);
136 struct bt_event_class
*bt_event_class_create(const char *name
)
139 struct bt_event_class
*event_class
= NULL
;
142 BT_LOGW_STR("Invalid parameter: name is NULL.");
146 BT_LOGD("Creating event class object: name=\"%s\"",
148 event_class
= g_new0(struct bt_event_class
, 1);
150 BT_LOGE_STR("Failed to allocate one event class.");
154 ret
= bt_event_class_common_initialize(BT_TO_COMMON(event_class
),
155 name
, bt_event_class_destroy
,
156 (bt_field_type_structure_create_func
)
157 bt_field_type_structure_create
);
162 ret
= bt_object_pool_initialize(&event_class
->event_pool
,
163 (bt_object_pool_new_object_func
) bt_event_new
,
164 (bt_object_pool_destroy_object_func
) free_event
,
167 BT_LOGE("Failed to initialize event pool: ret=%d",
172 BT_LOGD("Created event class object: addr=%p, name=\"%s\"",
173 event_class
, bt_event_class_get_name(event_class
));
183 const char *bt_event_class_get_name(struct bt_event_class
*event_class
)
185 return bt_event_class_common_get_name(BT_TO_COMMON(event_class
));
188 int64_t bt_event_class_get_id(struct bt_event_class
*event_class
)
190 return bt_event_class_common_get_id(BT_TO_COMMON(event_class
));
193 int bt_event_class_set_id(struct bt_event_class
*event_class
, uint64_t id
)
195 return bt_event_class_common_set_id(BT_TO_COMMON(event_class
), id
);
198 enum bt_event_class_log_level
bt_event_class_get_log_level(
199 struct bt_event_class
*event_class
)
201 return bt_event_class_common_get_log_level(BT_TO_COMMON(event_class
));
204 int bt_event_class_set_log_level(struct bt_event_class
*event_class
,
205 enum bt_event_class_log_level log_level
)
207 return bt_event_class_common_set_log_level(BT_TO_COMMON(event_class
),
211 const char *bt_event_class_get_emf_uri(struct bt_event_class
*event_class
)
213 return bt_event_class_common_get_emf_uri(BT_TO_COMMON(event_class
));
216 int bt_event_class_set_emf_uri(struct bt_event_class
*event_class
,
219 return bt_event_class_common_set_emf_uri(BT_TO_COMMON(event_class
),
223 struct bt_stream_class
*bt_event_class_borrow_stream_class(
224 struct bt_event_class
*event_class
)
226 BT_ASSERT_PRE_NON_NULL(event_class
, "Event class");
227 return BT_FROM_COMMON(
228 bt_event_class_common_borrow_stream_class(BT_TO_COMMON(
232 struct bt_field_type
*bt_event_class_borrow_payload_field_type(
233 struct bt_event_class
*event_class
)
235 return BT_FROM_COMMON(bt_event_class_common_borrow_payload_field_type(
236 BT_TO_COMMON(event_class
)));
239 int bt_event_class_set_payload_field_type(struct bt_event_class
*event_class
,
240 struct bt_field_type
*field_type
)
242 return bt_event_class_common_set_payload_field_type(
243 BT_TO_COMMON(event_class
), (void *) field_type
);
246 struct bt_field_type
*bt_event_class_borrow_context_field_type(
247 struct bt_event_class
*event_class
)
249 return BT_FROM_COMMON(bt_event_class_common_borrow_context_field_type(
250 BT_TO_COMMON(event_class
)));
253 int bt_event_class_set_context_field_type(
254 struct bt_event_class
*event_class
,
255 struct bt_field_type
*field_type
)
257 return bt_event_class_common_set_context_field_type(
258 BT_TO_COMMON(event_class
), (void *) field_type
);
262 void bt_event_class_common_freeze(struct bt_event_class_common
*event_class
)
264 BT_ASSERT(event_class
);
266 if (event_class
->frozen
) {
270 BT_LOGD("Freezing event class: addr=%p, name=\"%s\", id=%" PRId64
,
271 event_class
, bt_event_class_common_get_name(event_class
),
272 bt_event_class_common_get_id(event_class
));
273 event_class
->frozen
= 1;
274 BT_LOGD_STR("Freezing event class's context field type.");
275 bt_field_type_common_freeze(event_class
->context_field_type
);
276 BT_LOGD_STR("Freezing event class's payload field type.");
277 bt_field_type_common_freeze(event_class
->payload_field_type
);
281 int bt_event_class_common_validate_single_clock_class(
282 struct bt_event_class_common
*event_class
,
283 struct bt_clock_class
**expected_clock_class
)
287 BT_ASSERT(event_class
);
288 BT_ASSERT(expected_clock_class
);
289 ret
= bt_field_type_common_validate_single_clock_class(
290 event_class
->context_field_type
,
291 expected_clock_class
);
293 BT_LOGW("Event class's context field type "
294 "is not recursively mapped to the "
295 "expected clock class: "
296 "event-class-addr=%p, "
297 "event-class-name=\"%s\", "
298 "event-class-id=%" PRId64
", "
301 bt_event_class_common_get_name(event_class
),
303 event_class
->context_field_type
);
307 ret
= bt_field_type_common_validate_single_clock_class(
308 event_class
->payload_field_type
,
309 expected_clock_class
);
311 BT_LOGW("Event class's payload field type "
312 "is not recursively mapped to the "
313 "expected clock class: "
314 "event-class-addr=%p, "
315 "event-class-name=\"%s\", "
316 "event-class-id=%" PRId64
", "
319 bt_event_class_common_get_name(event_class
),
321 event_class
->payload_field_type
);
330 int bt_event_class_update_event_pool_clock_values(
331 struct bt_event_class
*event_class
)
335 struct bt_stream_class
*stream_class
=
336 bt_event_class_borrow_stream_class(event_class
);
338 BT_ASSERT(stream_class
->common
.clock_class
);
340 for (i
= 0; i
< event_class
->event_pool
.size
; i
++) {
341 struct bt_clock_value
*cv
;
342 struct bt_event
*event
=
343 event_class
->event_pool
.objects
->pdata
[i
];
347 cv
= g_hash_table_lookup(event
->clock_values
,
348 stream_class
->common
.clock_class
);
353 cv
= bt_clock_value_create(stream_class
->common
.clock_class
);
355 BT_LIB_LOGE("Cannot create clock value from clock class: "
356 "%![cc-]+K", stream_class
->common
.clock_class
);
361 g_hash_table_insert(event
->clock_values
,
362 stream_class
->common
.clock_class
, cv
);