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/fields-internal.h>
34 #include <babeltrace/ctf-ir/field-types-internal.h>
35 #include <babeltrace/ctf-ir/event-class.h>
36 #include <babeltrace/ctf-ir/event-class-internal.h>
37 #include <babeltrace/ctf-ir/stream-class.h>
38 #include <babeltrace/ctf-ir/stream-class-internal.h>
39 #include <babeltrace/ctf-ir/trace-internal.h>
40 #include <babeltrace/ctf-ir/validation-internal.h>
41 #include <babeltrace/ctf-ir/utils.h>
42 #include <babeltrace/ctf-ir/utils-internal.h>
43 #include <babeltrace/ref.h>
44 #include <babeltrace/ctf-ir/attributes-internal.h>
45 #include <babeltrace/compiler-internal.h>
46 #include <babeltrace/endian-internal.h>
47 #include <babeltrace/types.h>
48 #include <babeltrace/values-internal.h>
49 #include <babeltrace/assert-internal.h>
54 void bt_event_class_common_finalize(struct bt_object
*obj
)
56 struct bt_event_class_common
*event_class
;
58 event_class
= container_of(obj
, struct bt_event_class_common
, base
);
59 BT_LOGD("Finalizing common event class: addr=%p, name=\"%s\", id=%" PRId64
,
60 event_class
, bt_event_class_common_get_name(event_class
),
61 bt_event_class_common_get_id(event_class
));
63 if (event_class
->name
) {
64 g_string_free(event_class
->name
, TRUE
);
67 if (event_class
->emf_uri
) {
68 g_string_free(event_class
->emf_uri
, TRUE
);
71 BT_LOGD_STR("Putting context field type.");
72 bt_put(event_class
->context_field_type
);
73 BT_LOGD_STR("Putting payload field type.");
74 bt_put(event_class
->payload_field_type
);
78 int bt_event_class_common_initialize(struct bt_event_class_common
*event_class
,
79 const char *name
, bt_object_release_func release_func
,
80 bt_field_type_structure_create_func ft_struct_create_func
)
84 BT_LOGD("Initializing common event class object: name=\"%s\"",
86 bt_object_init(event_class
, release_func
);
87 event_class
->payload_field_type
= ft_struct_create_func();
88 if (!event_class
->payload_field_type
) {
89 BT_LOGE_STR("Cannot create event class's initial payload field type object.");
94 event_class
->name
= g_string_new(name
);
95 if (!event_class
->name
) {
96 BT_LOGE_STR("Failed to allocate a GString.");
100 event_class
->emf_uri
= g_string_new(NULL
);
101 if (!event_class
->emf_uri
) {
102 BT_LOGE_STR("Failed to allocate a GString.");
106 event_class
->log_level
= BT_EVENT_CLASS_LOG_LEVEL_UNSPECIFIED
;
107 BT_LOGD("Initialized common event class object: addr=%p, name=\"%s\"",
108 event_class
, bt_event_class_common_get_name(event_class
));
117 void bt_event_class_destroy(struct bt_object
*obj
)
119 BT_LOGD("Destroying event class: addr=%p", obj
);
120 bt_event_class_common_finalize(obj
);
124 struct bt_event_class
*bt_event_class_create(const char *name
)
127 struct bt_event_class
*event_class
= NULL
;
130 BT_LOGW_STR("Invalid parameter: name is NULL.");
134 BT_LOGD("Creating event class object: name=\"%s\"",
136 event_class
= g_new0(struct bt_event_class
, 1);
138 BT_LOGE_STR("Failed to allocate one event class.");
142 ret
= bt_event_class_common_initialize(BT_TO_COMMON(event_class
),
143 name
, bt_event_class_destroy
,
144 (bt_field_type_structure_create_func
)
145 bt_field_type_structure_create
);
150 BT_LOGD("Created event class object: addr=%p, name=\"%s\"",
151 event_class
, bt_event_class_get_name(event_class
));
161 const char *bt_event_class_get_name(struct bt_event_class
*event_class
)
163 return bt_event_class_common_get_name(BT_TO_COMMON(event_class
));
166 int64_t bt_event_class_get_id(struct bt_event_class
*event_class
)
168 return bt_event_class_common_get_id(BT_TO_COMMON(event_class
));
171 int bt_event_class_set_id(struct bt_event_class
*event_class
, uint64_t id
)
173 return bt_event_class_common_set_id(BT_TO_COMMON(event_class
), id
);
176 enum bt_event_class_log_level
bt_event_class_get_log_level(
177 struct bt_event_class
*event_class
)
179 return bt_event_class_common_get_log_level(BT_TO_COMMON(event_class
));
182 int bt_event_class_set_log_level(struct bt_event_class
*event_class
,
183 enum bt_event_class_log_level log_level
)
185 return bt_event_class_common_set_log_level(BT_TO_COMMON(event_class
),
189 const char *bt_event_class_get_emf_uri(struct bt_event_class
*event_class
)
191 return bt_event_class_common_get_emf_uri(BT_TO_COMMON(event_class
));
194 int bt_event_class_set_emf_uri(struct bt_event_class
*event_class
,
197 return bt_event_class_common_set_emf_uri(BT_TO_COMMON(event_class
),
201 struct bt_stream_class
*bt_event_class_borrow_stream_class(
202 struct bt_event_class
*event_class
)
204 BT_ASSERT_PRE_NON_NULL(event_class
, "Event class");
205 return BT_FROM_COMMON(
206 bt_event_class_common_borrow_stream_class(BT_TO_COMMON(
210 struct bt_field_type
*bt_event_class_borrow_payload_field_type(
211 struct bt_event_class
*event_class
)
213 return BT_FROM_COMMON(bt_event_class_common_borrow_payload_field_type(
214 BT_TO_COMMON(event_class
)));
217 int bt_event_class_set_payload_field_type(struct bt_event_class
*event_class
,
218 struct bt_field_type
*field_type
)
220 return bt_event_class_common_set_payload_field_type(
221 BT_TO_COMMON(event_class
), (void *) field_type
);
224 struct bt_field_type
*bt_event_class_borrow_context_field_type(
225 struct bt_event_class
*event_class
)
227 return BT_FROM_COMMON(bt_event_class_common_borrow_context_field_type(
228 BT_TO_COMMON(event_class
)));
231 int bt_event_class_set_context_field_type(
232 struct bt_event_class
*event_class
,
233 struct bt_field_type
*field_type
)
235 return bt_event_class_common_set_context_field_type(
236 BT_TO_COMMON(event_class
), (void *) field_type
);
240 void bt_event_class_common_freeze(struct bt_event_class_common
*event_class
)
242 BT_ASSERT(event_class
);
244 if (event_class
->frozen
) {
248 BT_LOGD("Freezing event class: addr=%p, name=\"%s\", id=%" PRId64
,
249 event_class
, bt_event_class_common_get_name(event_class
),
250 bt_event_class_common_get_id(event_class
));
251 event_class
->frozen
= 1;
252 BT_LOGD_STR("Freezing event class's context field type.");
253 bt_field_type_common_freeze(event_class
->context_field_type
);
254 BT_LOGD_STR("Freezing event class's payload field type.");
255 bt_field_type_common_freeze(event_class
->payload_field_type
);
259 int bt_event_class_common_validate_single_clock_class(
260 struct bt_event_class_common
*event_class
,
261 struct bt_clock_class
**expected_clock_class
)
265 BT_ASSERT(event_class
);
266 BT_ASSERT(expected_clock_class
);
267 ret
= bt_field_type_common_validate_single_clock_class(
268 event_class
->context_field_type
,
269 expected_clock_class
);
271 BT_LOGW("Event class's context field type "
272 "is not recursively mapped to the "
273 "expected clock class: "
274 "event-class-addr=%p, "
275 "event-class-name=\"%s\", "
276 "event-class-id=%" PRId64
", "
279 bt_event_class_common_get_name(event_class
),
281 event_class
->context_field_type
);
285 ret
= bt_field_type_common_validate_single_clock_class(
286 event_class
->payload_field_type
,
287 expected_clock_class
);
289 BT_LOGW("Event class's payload field type "
290 "is not recursively mapped to the "
291 "expected clock class: "
292 "event-class-addr=%p, "
293 "event-class-name=\"%s\", "
294 "event-class-id=%" PRId64
", "
297 bt_event_class_common_get_name(event_class
),
299 event_class
->payload_field_type
);