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.
44 void bt_ctf_event_class_common_freeze(struct bt_ctf_event_class_common
*event_class
);
46 void bt_ctf_event_class_common_set_native_byte_order(
47 struct bt_ctf_event_class_common
*event_class
, int byte_order
);
50 struct bt_ctf_stream_class_common
*bt_ctf_event_class_common_borrow_stream_class(
51 struct bt_ctf_event_class_common
*event_class
)
53 BT_ASSERT_DBG(event_class
);
54 return (void *) bt_ctf_object_borrow_parent(&event_class
->base
);
57 typedef struct bt_ctf_field_type_common
*
58 (*bt_ctf_field_type_structure_create_func
)(void);
60 int bt_ctf_event_class_common_initialize(struct bt_ctf_event_class_common
*event_class
,
61 const char *name
, bt_ctf_object_release_func release_func
,
62 bt_ctf_field_type_structure_create_func ft_struct_create_func
);
64 void bt_ctf_event_class_common_finalize(struct bt_ctf_object
*obj
);
66 int bt_ctf_event_class_common_validate_single_clock_class(
67 struct bt_ctf_event_class_common
*event_class
,
68 struct bt_ctf_clock_class
**expected_clock_class
);
71 const char *bt_ctf_event_class_common_get_name(
72 struct bt_ctf_event_class_common
*event_class
)
74 BT_CTF_ASSERT_PRE_NON_NULL(event_class
, "Event class");
75 BT_ASSERT_DBG(event_class
->name
);
76 return event_class
->name
->str
;
80 int64_t bt_ctf_event_class_common_get_id(
81 struct bt_ctf_event_class_common
*event_class
)
83 BT_CTF_ASSERT_PRE_NON_NULL(event_class
, "Event class");
84 return event_class
->id
;
88 int bt_ctf_event_class_common_set_id(
89 struct bt_ctf_event_class_common
*event_class
, uint64_t id_param
)
92 int64_t id
= (int64_t) id_param
;
95 BT_LOGW_STR("Invalid parameter: event class is NULL.");
100 if (event_class
->frozen
) {
101 BT_LOGW("Invalid parameter: event class is frozen: "
102 "addr=%p, name=\"%s\", id=%" PRId64
,
104 bt_ctf_event_class_common_get_name(event_class
),
105 bt_ctf_event_class_common_get_id(event_class
));
111 BT_LOGW("Invalid parameter: invalid event class's ID: "
112 "addr=%p, name=\"%s\", id=%" PRIu64
,
114 bt_ctf_event_class_common_get_name(event_class
),
120 event_class
->id
= id
;
121 BT_LOGT("Set event class's ID: "
122 "addr=%p, name=\"%s\", id=%" PRId64
,
123 event_class
, bt_ctf_event_class_common_get_name(event_class
), id
);
130 int bt_ctf_event_class_common_get_log_level(
131 struct bt_ctf_event_class_common
*event_class
)
133 BT_CTF_ASSERT_PRE_NON_NULL(event_class
, "Event class");
134 return event_class
->log_level
;
138 int bt_ctf_event_class_common_set_log_level(
139 struct bt_ctf_event_class_common
*event_class
, int log_level
)
144 BT_LOGW_STR("Invalid parameter: event class is NULL.");
149 if (event_class
->frozen
) {
150 BT_LOGW("Invalid parameter: event class is frozen: "
151 "addr=%p, name=\"%s\", id=%" PRId64
,
153 bt_ctf_event_class_common_get_name(event_class
),
154 bt_ctf_event_class_common_get_id(event_class
));
160 case BT_CTF_EVENT_CLASS_LOG_LEVEL_UNSPECIFIED
:
161 case BT_CTF_EVENT_CLASS_LOG_LEVEL_EMERGENCY
:
162 case BT_CTF_EVENT_CLASS_LOG_LEVEL_ALERT
:
163 case BT_CTF_EVENT_CLASS_LOG_LEVEL_CRITICAL
:
164 case BT_CTF_EVENT_CLASS_LOG_LEVEL_ERROR
:
165 case BT_CTF_EVENT_CLASS_LOG_LEVEL_WARNING
:
166 case BT_CTF_EVENT_CLASS_LOG_LEVEL_NOTICE
:
167 case BT_CTF_EVENT_CLASS_LOG_LEVEL_INFO
:
168 case BT_CTF_EVENT_CLASS_LOG_LEVEL_DEBUG_SYSTEM
:
169 case BT_CTF_EVENT_CLASS_LOG_LEVEL_DEBUG_PROGRAM
:
170 case BT_CTF_EVENT_CLASS_LOG_LEVEL_DEBUG_PROCESS
:
171 case BT_CTF_EVENT_CLASS_LOG_LEVEL_DEBUG_MODULE
:
172 case BT_CTF_EVENT_CLASS_LOG_LEVEL_DEBUG_UNIT
:
173 case BT_CTF_EVENT_CLASS_LOG_LEVEL_DEBUG_FUNCTION
:
174 case BT_CTF_EVENT_CLASS_LOG_LEVEL_DEBUG_LINE
:
175 case BT_CTF_EVENT_CLASS_LOG_LEVEL_DEBUG
:
178 BT_LOGW("Invalid parameter: unknown event class log level: "
179 "addr=%p, name=\"%s\", id=%" PRId64
", log-level=%d",
180 event_class
, bt_ctf_event_class_common_get_name(event_class
),
181 bt_ctf_event_class_common_get_id(event_class
), log_level
);
186 event_class
->log_level
= log_level
;
187 BT_LOGT("Set event class's log level: "
188 "addr=%p, name=\"%s\", id=%" PRId64
", log-level=%s",
189 event_class
, bt_ctf_event_class_common_get_name(event_class
),
190 bt_ctf_event_class_common_get_id(event_class
),
191 bt_ctf_event_class_log_level_string(log_level
));
198 const char *bt_ctf_event_class_common_get_emf_uri(
199 struct bt_ctf_event_class_common
*event_class
)
201 const char *emf_uri
= NULL
;
203 BT_CTF_ASSERT_PRE_NON_NULL(event_class
, "Event class");
205 if (event_class
->emf_uri
->len
> 0) {
206 emf_uri
= event_class
->emf_uri
->str
;
213 int bt_ctf_event_class_common_set_emf_uri(
214 struct bt_ctf_event_class_common
*event_class
,
220 BT_LOGW_STR("Invalid parameter: event class is NULL.");
225 if (emf_uri
&& strlen(emf_uri
) == 0) {
226 BT_LOGW_STR("Invalid parameter: EMF URI is empty.");
231 if (event_class
->frozen
) {
232 BT_LOGW("Invalid parameter: event class is frozen: "
233 "addr=%p, name=\"%s\", id=%" PRId64
,
234 event_class
, bt_ctf_event_class_common_get_name(event_class
),
235 bt_ctf_event_class_common_get_id(event_class
));
241 g_string_assign(event_class
->emf_uri
, emf_uri
);
242 BT_LOGT("Set event class's EMF URI: "
243 "addr=%p, name=\"%s\", id=%" PRId64
", emf-uri=\"%s\"",
244 event_class
, bt_ctf_event_class_common_get_name(event_class
),
245 bt_ctf_event_class_common_get_id(event_class
), emf_uri
);
247 g_string_assign(event_class
->emf_uri
, "");
248 BT_LOGT("Reset event class's EMF URI: "
249 "addr=%p, name=\"%s\", id=%" PRId64
,
250 event_class
, bt_ctf_event_class_common_get_name(event_class
),
251 bt_ctf_event_class_common_get_id(event_class
));
259 struct bt_ctf_field_type_common
*bt_ctf_event_class_common_borrow_context_field_type(
260 struct bt_ctf_event_class_common
*event_class
)
262 struct bt_ctf_field_type_common
*context_ft
= NULL
;
264 BT_CTF_ASSERT_PRE_NON_NULL(event_class
, "Event class");
266 if (!event_class
->context_field_type
) {
267 BT_LOGT("Event class has no context field type: "
268 "addr=%p, name=\"%s\", id=%" PRId64
,
269 event_class
, bt_ctf_event_class_common_get_name(event_class
),
270 bt_ctf_event_class_common_get_id(event_class
));
274 context_ft
= event_class
->context_field_type
;
281 int bt_ctf_event_class_common_set_context_field_type(
282 struct bt_ctf_event_class_common
*event_class
,
283 struct bt_ctf_field_type_common
*context_ft
)
288 BT_LOGW_STR("Invalid parameter: event class is NULL.");
293 if (event_class
->frozen
) {
294 BT_LOGW("Invalid parameter: event class is frozen: "
295 "addr=%p, name=\"%s\", id=%" PRId64
,
296 event_class
, bt_ctf_event_class_common_get_name(event_class
),
297 bt_ctf_event_class_common_get_id(event_class
));
302 if (context_ft
&& bt_ctf_field_type_common_get_type_id(context_ft
) !=
303 BT_CTF_FIELD_TYPE_ID_STRUCT
) {
304 BT_LOGW("Invalid parameter: event class's context field type must be a structure: "
305 "addr=%p, name=\"%s\", id=%" PRId64
", "
307 event_class
, bt_ctf_event_class_common_get_name(event_class
),
308 bt_ctf_event_class_common_get_id(event_class
),
309 bt_ctf_field_type_id_string(
310 bt_ctf_field_type_common_get_type_id(context_ft
)));
315 bt_ctf_object_put_ref(event_class
->context_field_type
);
316 event_class
->context_field_type
= context_ft
;
317 bt_ctf_object_get_ref(event_class
->context_field_type
);
318 BT_LOGT("Set event class's context field type: "
319 "event-class-addr=%p, event-class-name=\"%s\", "
320 "event-class-id=%" PRId64
", context-ft-addr=%p",
321 event_class
, bt_ctf_event_class_common_get_name(event_class
),
322 bt_ctf_event_class_common_get_id(event_class
), context_ft
);
329 struct bt_ctf_field_type_common
*bt_ctf_event_class_common_borrow_payload_field_type(
330 struct bt_ctf_event_class_common
*event_class
)
332 BT_CTF_ASSERT_PRE_NON_NULL(event_class
, "Event class");
333 return event_class
->payload_field_type
;
337 int bt_ctf_event_class_common_set_payload_field_type(
338 struct bt_ctf_event_class_common
*event_class
,
339 struct bt_ctf_field_type_common
*payload_ft
)
344 BT_LOGW_STR("Invalid parameter: event class is NULL.");
349 if (payload_ft
&& bt_ctf_field_type_common_get_type_id(payload_ft
) !=
350 BT_CTF_FIELD_TYPE_ID_STRUCT
) {
351 BT_LOGW("Invalid parameter: event class's payload field type must be a structure: "
352 "addr=%p, name=\"%s\", id=%" PRId64
", "
353 "payload-ft-addr=%p, payload-ft-id=%s",
354 event_class
, bt_ctf_event_class_common_get_name(event_class
),
355 bt_ctf_event_class_common_get_id(event_class
), payload_ft
,
356 bt_ctf_field_type_id_string(
357 bt_ctf_field_type_common_get_type_id(payload_ft
)));
362 bt_ctf_object_put_ref(event_class
->payload_field_type
);
363 event_class
->payload_field_type
= payload_ft
;
364 bt_ctf_object_get_ref(event_class
->payload_field_type
);
365 BT_LOGT("Set event class's payload field type: "
366 "event-class-addr=%p, event-class-name=\"%s\", "
367 "event-class-id=%" PRId64
", payload-ft-addr=%p",
368 event_class
, bt_ctf_event_class_common_get_name(event_class
),
369 bt_ctf_event_class_common_get_id(event_class
), payload_ft
);
374 #endif /* BABELTRACE_CTF_WRITER_EVENT_CLASS_INTERNAL_H */