2 * SPDX-License-Identifier: MIT
4 * Copyright 2013, 2014 Jérémie Galarneau <jeremie.galarneau@efficios.com>
7 #ifndef BABELTRACE_CTF_WRITER_EVENT_CLASS_INTERNAL_H
8 #define BABELTRACE_CTF_WRITER_EVENT_CLASS_INTERNAL_H
10 #include "common/assert.h"
11 #include "common/macros.h"
12 #include <babeltrace2-ctf-writer/event.h>
13 #include <babeltrace2-ctf-writer/field-types.h>
14 #include <babeltrace2-ctf-writer/fields.h>
15 #include <babeltrace2-ctf-writer/stream-class.h>
16 #include <babeltrace2-ctf-writer/stream.h>
23 struct bt_ctf_event_class_common
{
24 struct bt_ctf_object base
;
25 struct bt_ctf_field_type_common
*context_field_type
;
26 struct bt_ctf_field_type_common
*payload_field_type
;
30 * This flag indicates if the event class is valid. A valid
31 * event class is _always_ frozen. However, an event class
32 * may be frozen, but not valid yet. This is okay, as long as
33 * no events are created out of this event class.
45 void bt_ctf_event_class_common_freeze(struct bt_ctf_event_class_common
*event_class
);
48 void bt_ctf_event_class_common_set_native_byte_order(
49 struct bt_ctf_event_class_common
*event_class
, int byte_order
);
52 struct bt_ctf_stream_class_common
*bt_ctf_event_class_common_borrow_stream_class(
53 struct bt_ctf_event_class_common
*event_class
)
55 BT_ASSERT_DBG(event_class
);
56 return (void *) bt_ctf_object_borrow_parent(&event_class
->base
);
59 typedef struct bt_ctf_field_type_common
*
60 (*bt_ctf_field_type_structure_create_func
)(void);
63 int bt_ctf_event_class_common_initialize(struct bt_ctf_event_class_common
*event_class
,
64 const char *name
, bt_ctf_object_release_func release_func
,
65 bt_ctf_field_type_structure_create_func ft_struct_create_func
);
68 void bt_ctf_event_class_common_finalize(struct bt_ctf_object
*obj
);
71 int bt_ctf_event_class_common_validate_single_clock_class(
72 struct bt_ctf_event_class_common
*event_class
,
73 struct bt_ctf_clock_class
**expected_clock_class
);
76 const char *bt_ctf_event_class_common_get_name(
77 struct bt_ctf_event_class_common
*event_class
)
79 BT_CTF_ASSERT_PRE_NON_NULL(event_class
, "Event class");
80 BT_ASSERT_DBG(event_class
->name
);
81 return event_class
->name
->str
;
85 int64_t bt_ctf_event_class_common_get_id(
86 struct bt_ctf_event_class_common
*event_class
)
88 BT_CTF_ASSERT_PRE_NON_NULL(event_class
, "Event class");
89 return event_class
->id
;
93 int bt_ctf_event_class_common_set_id(
94 struct bt_ctf_event_class_common
*event_class
, uint64_t id_param
)
97 int64_t id
= (int64_t) id_param
;
100 BT_LOGW_STR("Invalid parameter: event class is NULL.");
105 if (event_class
->frozen
) {
106 BT_LOGW("Invalid parameter: event class is frozen: "
107 "addr=%p, name=\"%s\", id=%" PRId64
,
109 bt_ctf_event_class_common_get_name(event_class
),
110 bt_ctf_event_class_common_get_id(event_class
));
116 BT_LOGW("Invalid parameter: invalid event class's ID: "
117 "addr=%p, name=\"%s\", id=%" PRIu64
,
119 bt_ctf_event_class_common_get_name(event_class
),
125 event_class
->id
= id
;
126 BT_LOGT("Set event class's ID: "
127 "addr=%p, name=\"%s\", id=%" PRId64
,
128 event_class
, bt_ctf_event_class_common_get_name(event_class
), id
);
135 int bt_ctf_event_class_common_get_log_level(
136 struct bt_ctf_event_class_common
*event_class
)
138 BT_CTF_ASSERT_PRE_NON_NULL(event_class
, "Event class");
139 return event_class
->log_level
;
143 int bt_ctf_event_class_common_set_log_level(
144 struct bt_ctf_event_class_common
*event_class
, int log_level
)
149 BT_LOGW_STR("Invalid parameter: event class is NULL.");
154 if (event_class
->frozen
) {
155 BT_LOGW("Invalid parameter: event class is frozen: "
156 "addr=%p, name=\"%s\", id=%" PRId64
,
158 bt_ctf_event_class_common_get_name(event_class
),
159 bt_ctf_event_class_common_get_id(event_class
));
165 case BT_CTF_EVENT_CLASS_LOG_LEVEL_UNSPECIFIED
:
166 case BT_CTF_EVENT_CLASS_LOG_LEVEL_EMERGENCY
:
167 case BT_CTF_EVENT_CLASS_LOG_LEVEL_ALERT
:
168 case BT_CTF_EVENT_CLASS_LOG_LEVEL_CRITICAL
:
169 case BT_CTF_EVENT_CLASS_LOG_LEVEL_ERROR
:
170 case BT_CTF_EVENT_CLASS_LOG_LEVEL_WARNING
:
171 case BT_CTF_EVENT_CLASS_LOG_LEVEL_NOTICE
:
172 case BT_CTF_EVENT_CLASS_LOG_LEVEL_INFO
:
173 case BT_CTF_EVENT_CLASS_LOG_LEVEL_DEBUG_SYSTEM
:
174 case BT_CTF_EVENT_CLASS_LOG_LEVEL_DEBUG_PROGRAM
:
175 case BT_CTF_EVENT_CLASS_LOG_LEVEL_DEBUG_PROCESS
:
176 case BT_CTF_EVENT_CLASS_LOG_LEVEL_DEBUG_MODULE
:
177 case BT_CTF_EVENT_CLASS_LOG_LEVEL_DEBUG_UNIT
:
178 case BT_CTF_EVENT_CLASS_LOG_LEVEL_DEBUG_FUNCTION
:
179 case BT_CTF_EVENT_CLASS_LOG_LEVEL_DEBUG_LINE
:
180 case BT_CTF_EVENT_CLASS_LOG_LEVEL_DEBUG
:
183 BT_LOGW("Invalid parameter: unknown event class log level: "
184 "addr=%p, name=\"%s\", id=%" PRId64
", log-level=%d",
185 event_class
, bt_ctf_event_class_common_get_name(event_class
),
186 bt_ctf_event_class_common_get_id(event_class
), log_level
);
191 event_class
->log_level
= log_level
;
192 BT_LOGT("Set event class's log level: "
193 "addr=%p, name=\"%s\", id=%" PRId64
", log-level=%s",
194 event_class
, bt_ctf_event_class_common_get_name(event_class
),
195 bt_ctf_event_class_common_get_id(event_class
),
196 bt_ctf_event_class_log_level_string(log_level
));
203 const char *bt_ctf_event_class_common_get_emf_uri(
204 struct bt_ctf_event_class_common
*event_class
)
206 const char *emf_uri
= NULL
;
208 BT_CTF_ASSERT_PRE_NON_NULL(event_class
, "Event class");
210 if (event_class
->emf_uri
->len
> 0) {
211 emf_uri
= event_class
->emf_uri
->str
;
218 int bt_ctf_event_class_common_set_emf_uri(
219 struct bt_ctf_event_class_common
*event_class
,
225 BT_LOGW_STR("Invalid parameter: event class is NULL.");
230 if (emf_uri
&& strlen(emf_uri
) == 0) {
231 BT_LOGW_STR("Invalid parameter: EMF URI is empty.");
236 if (event_class
->frozen
) {
237 BT_LOGW("Invalid parameter: event class is frozen: "
238 "addr=%p, name=\"%s\", id=%" PRId64
,
239 event_class
, bt_ctf_event_class_common_get_name(event_class
),
240 bt_ctf_event_class_common_get_id(event_class
));
246 g_string_assign(event_class
->emf_uri
, emf_uri
);
247 BT_LOGT("Set event class's EMF URI: "
248 "addr=%p, name=\"%s\", id=%" PRId64
", emf-uri=\"%s\"",
249 event_class
, bt_ctf_event_class_common_get_name(event_class
),
250 bt_ctf_event_class_common_get_id(event_class
), emf_uri
);
252 g_string_assign(event_class
->emf_uri
, "");
253 BT_LOGT("Reset event class's EMF URI: "
254 "addr=%p, name=\"%s\", id=%" PRId64
,
255 event_class
, bt_ctf_event_class_common_get_name(event_class
),
256 bt_ctf_event_class_common_get_id(event_class
));
264 struct bt_ctf_field_type_common
*bt_ctf_event_class_common_borrow_context_field_type(
265 struct bt_ctf_event_class_common
*event_class
)
267 struct bt_ctf_field_type_common
*context_ft
= NULL
;
269 BT_CTF_ASSERT_PRE_NON_NULL(event_class
, "Event class");
271 if (!event_class
->context_field_type
) {
272 BT_LOGT("Event class has no context field type: "
273 "addr=%p, name=\"%s\", id=%" PRId64
,
274 event_class
, bt_ctf_event_class_common_get_name(event_class
),
275 bt_ctf_event_class_common_get_id(event_class
));
279 context_ft
= event_class
->context_field_type
;
286 int bt_ctf_event_class_common_set_context_field_type(
287 struct bt_ctf_event_class_common
*event_class
,
288 struct bt_ctf_field_type_common
*context_ft
)
293 BT_LOGW_STR("Invalid parameter: event class is NULL.");
298 if (event_class
->frozen
) {
299 BT_LOGW("Invalid parameter: event class is frozen: "
300 "addr=%p, name=\"%s\", id=%" PRId64
,
301 event_class
, bt_ctf_event_class_common_get_name(event_class
),
302 bt_ctf_event_class_common_get_id(event_class
));
307 if (context_ft
&& bt_ctf_field_type_common_get_type_id(context_ft
) !=
308 BT_CTF_FIELD_TYPE_ID_STRUCT
) {
309 BT_LOGW("Invalid parameter: event class's context field type must be a structure: "
310 "addr=%p, name=\"%s\", id=%" PRId64
", "
312 event_class
, bt_ctf_event_class_common_get_name(event_class
),
313 bt_ctf_event_class_common_get_id(event_class
),
314 bt_ctf_field_type_id_string(
315 bt_ctf_field_type_common_get_type_id(context_ft
)));
320 bt_ctf_object_put_ref(event_class
->context_field_type
);
321 event_class
->context_field_type
= context_ft
;
322 bt_ctf_object_get_ref(event_class
->context_field_type
);
323 BT_LOGT("Set event class's context field type: "
324 "event-class-addr=%p, event-class-name=\"%s\", "
325 "event-class-id=%" PRId64
", context-ft-addr=%p",
326 event_class
, bt_ctf_event_class_common_get_name(event_class
),
327 bt_ctf_event_class_common_get_id(event_class
), context_ft
);
334 struct bt_ctf_field_type_common
*bt_ctf_event_class_common_borrow_payload_field_type(
335 struct bt_ctf_event_class_common
*event_class
)
337 BT_CTF_ASSERT_PRE_NON_NULL(event_class
, "Event class");
338 return event_class
->payload_field_type
;
342 int bt_ctf_event_class_common_set_payload_field_type(
343 struct bt_ctf_event_class_common
*event_class
,
344 struct bt_ctf_field_type_common
*payload_ft
)
349 BT_LOGW_STR("Invalid parameter: event class is NULL.");
354 if (payload_ft
&& bt_ctf_field_type_common_get_type_id(payload_ft
) !=
355 BT_CTF_FIELD_TYPE_ID_STRUCT
) {
356 BT_LOGW("Invalid parameter: event class's payload field type must be a structure: "
357 "addr=%p, name=\"%s\", id=%" PRId64
", "
358 "payload-ft-addr=%p, payload-ft-id=%s",
359 event_class
, bt_ctf_event_class_common_get_name(event_class
),
360 bt_ctf_event_class_common_get_id(event_class
), payload_ft
,
361 bt_ctf_field_type_id_string(
362 bt_ctf_field_type_common_get_type_id(payload_ft
)));
367 bt_ctf_object_put_ref(event_class
->payload_field_type
);
368 event_class
->payload_field_type
= payload_ft
;
369 bt_ctf_object_get_ref(event_class
->payload_field_type
);
370 BT_LOGT("Set event class's payload field type: "
371 "event-class-addr=%p, event-class-name=\"%s\", "
372 "event-class-id=%" PRId64
", payload-ft-addr=%p",
373 event_class
, bt_ctf_event_class_common_get_name(event_class
),
374 bt_ctf_event_class_common_get_id(event_class
), payload_ft
);
379 #endif /* BABELTRACE_CTF_WRITER_EVENT_CLASS_INTERNAL_H */