1 #ifndef BABELTRACE_CTF_IR_EVENT_CLASS_INTERNAL_H
2 #define BABELTRACE_CTF_IR_EVENT_CLASS_INTERNAL_H
5 * Babeltrace - CTF IR: Event class internal
7 * Copyright 2013, 2014 Jérémie Galarneau <jeremie.galarneau@efficios.com>
9 * Author: Jérémie Galarneau <jeremie.galarneau@efficios.com>
11 * Permission is hereby granted, free of charge, to any person obtaining a copy
12 * of this software and associated documentation files (the "Software"), to deal
13 * in the Software without restriction, including without limitation the rights
14 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
15 * copies of the Software, and to permit persons to whom the Software is
16 * furnished to do so, subject to the following conditions:
18 * The above copyright notice and this permission notice shall be included in
19 * all copies or substantial portions of the Software.
21 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
22 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
23 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
24 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
25 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
26 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
30 #include <babeltrace/assert-pre-internal.h>
31 #include <babeltrace/ctf-ir/field-types.h>
32 #include <babeltrace/ctf-ir/fields.h>
33 #include <babeltrace/babeltrace-internal.h>
34 #include <babeltrace/values.h>
35 #include <babeltrace/ctf-ir/trace-internal.h>
36 #include <babeltrace/ctf-ir/stream-class.h>
37 #include <babeltrace/ctf-ir/stream.h>
38 #include <babeltrace/ctf-ir/event-class.h>
39 #include <babeltrace/object-internal.h>
40 #include <babeltrace/assert-internal.h>
41 #include <babeltrace/object-pool-internal.h>
44 struct bt_event_class_common
{
45 struct bt_object base
;
46 struct bt_field_type_common
*context_field_type
;
47 struct bt_field_type_common
*payload_field_type
;
51 * This flag indicates if the event class is valid. A valid
52 * event class is _always_ frozen. However, an event class
53 * may be frozen, but not valid yet. This is okay, as long as
54 * no events are created out of this event class.
65 struct bt_event_class
{
66 struct bt_event_class_common common
;
68 /* Pool of `struct bt_event *` */
69 struct bt_object_pool event_pool
;
73 void bt_event_class_freeze(struct bt_event_class
*event_class
);
76 void bt_event_class_common_freeze(struct bt_event_class_common
*event_class
);
79 void bt_event_class_common_set_native_byte_order(
80 struct bt_event_class_common
*event_class
, int byte_order
);
83 struct bt_stream_class_common
*bt_event_class_common_borrow_stream_class(
84 struct bt_event_class_common
*event_class
)
86 BT_ASSERT(event_class
);
87 return (void *) bt_object_borrow_parent(&event_class
->base
);
90 typedef struct bt_field_type_common
*(*bt_field_type_structure_create_func
)();
93 int bt_event_class_common_initialize(struct bt_event_class_common
*event_class
,
94 const char *name
, bt_object_release_func release_func
,
95 bt_field_type_structure_create_func ft_struct_create_func
);
98 void bt_event_class_common_finalize(struct bt_object
*obj
);
101 int bt_event_class_common_validate_single_clock_class(
102 struct bt_event_class_common
*event_class
,
103 struct bt_clock_class
**expected_clock_class
);
106 const char *bt_event_class_common_get_name(
107 struct bt_event_class_common
*event_class
)
109 BT_ASSERT_PRE_NON_NULL(event_class
, "Event class");
110 BT_ASSERT(event_class
->name
);
111 return event_class
->name
->str
;
115 int64_t bt_event_class_common_get_id(
116 struct bt_event_class_common
*event_class
)
118 BT_ASSERT_PRE_NON_NULL(event_class
, "Event class");
119 return event_class
->id
;
123 int bt_event_class_common_set_id(
124 struct bt_event_class_common
*event_class
, uint64_t id_param
)
127 int64_t id
= (int64_t) id_param
;
130 BT_LOGW_STR("Invalid parameter: event class is NULL.");
135 if (event_class
->frozen
) {
136 BT_LOGW("Invalid parameter: event class is frozen: "
137 "addr=%p, name=\"%s\", id=%" PRId64
,
139 bt_event_class_common_get_name(event_class
),
140 bt_event_class_common_get_id(event_class
));
146 BT_LOGW("Invalid parameter: invalid event class's ID: "
147 "addr=%p, name=\"%s\", id=%" PRIu64
,
149 bt_event_class_common_get_name(event_class
),
155 event_class
->id
= id
;
156 BT_LOGV("Set event class's ID: "
157 "addr=%p, name=\"%s\", id=%" PRId64
,
158 event_class
, bt_event_class_common_get_name(event_class
), id
);
165 int bt_event_class_common_get_log_level(
166 struct bt_event_class_common
*event_class
)
168 BT_ASSERT_PRE_NON_NULL(event_class
, "Event class");
169 return event_class
->log_level
;
173 int bt_event_class_common_set_log_level(
174 struct bt_event_class_common
*event_class
, int log_level
)
179 BT_LOGW_STR("Invalid parameter: event class is NULL.");
184 if (event_class
->frozen
) {
185 BT_LOGW("Invalid parameter: event class is frozen: "
186 "addr=%p, name=\"%s\", id=%" PRId64
,
188 bt_event_class_common_get_name(event_class
),
189 bt_event_class_common_get_id(event_class
));
195 case BT_EVENT_CLASS_LOG_LEVEL_UNSPECIFIED
:
196 case BT_EVENT_CLASS_LOG_LEVEL_EMERGENCY
:
197 case BT_EVENT_CLASS_LOG_LEVEL_ALERT
:
198 case BT_EVENT_CLASS_LOG_LEVEL_CRITICAL
:
199 case BT_EVENT_CLASS_LOG_LEVEL_ERROR
:
200 case BT_EVENT_CLASS_LOG_LEVEL_WARNING
:
201 case BT_EVENT_CLASS_LOG_LEVEL_NOTICE
:
202 case BT_EVENT_CLASS_LOG_LEVEL_INFO
:
203 case BT_EVENT_CLASS_LOG_LEVEL_DEBUG_SYSTEM
:
204 case BT_EVENT_CLASS_LOG_LEVEL_DEBUG_PROGRAM
:
205 case BT_EVENT_CLASS_LOG_LEVEL_DEBUG_PROCESS
:
206 case BT_EVENT_CLASS_LOG_LEVEL_DEBUG_MODULE
:
207 case BT_EVENT_CLASS_LOG_LEVEL_DEBUG_UNIT
:
208 case BT_EVENT_CLASS_LOG_LEVEL_DEBUG_FUNCTION
:
209 case BT_EVENT_CLASS_LOG_LEVEL_DEBUG_LINE
:
210 case BT_EVENT_CLASS_LOG_LEVEL_DEBUG
:
213 BT_LOGW("Invalid parameter: unknown event class log level: "
214 "addr=%p, name=\"%s\", id=%" PRId64
", log-level=%d",
215 event_class
, bt_event_class_common_get_name(event_class
),
216 bt_event_class_common_get_id(event_class
), log_level
);
221 event_class
->log_level
= log_level
;
222 BT_LOGV("Set event class's log level: "
223 "addr=%p, name=\"%s\", id=%" PRId64
", log-level=%s",
224 event_class
, bt_event_class_common_get_name(event_class
),
225 bt_event_class_common_get_id(event_class
),
226 bt_common_event_class_log_level_string(log_level
));
233 const char *bt_event_class_common_get_emf_uri(
234 struct bt_event_class_common
*event_class
)
236 const char *emf_uri
= NULL
;
238 BT_ASSERT_PRE_NON_NULL(event_class
, "Event class");
240 if (event_class
->emf_uri
->len
> 0) {
241 emf_uri
= event_class
->emf_uri
->str
;
248 int bt_event_class_common_set_emf_uri(
249 struct bt_event_class_common
*event_class
,
255 BT_LOGW_STR("Invalid parameter: event class is NULL.");
260 if (emf_uri
&& strlen(emf_uri
) == 0) {
261 BT_LOGW_STR("Invalid parameter: EMF URI is empty.");
266 if (event_class
->frozen
) {
267 BT_LOGW("Invalid parameter: event class is frozen: "
268 "addr=%p, name=\"%s\", id=%" PRId64
,
269 event_class
, bt_event_class_common_get_name(event_class
),
270 bt_event_class_common_get_id(event_class
));
276 g_string_assign(event_class
->emf_uri
, emf_uri
);
277 BT_LOGV("Set event class's EMF URI: "
278 "addr=%p, name=\"%s\", id=%" PRId64
", emf-uri=\"%s\"",
279 event_class
, bt_event_class_common_get_name(event_class
),
280 bt_event_class_common_get_id(event_class
), emf_uri
);
282 g_string_assign(event_class
->emf_uri
, "");
283 BT_LOGV("Reset event class's EMF URI: "
284 "addr=%p, name=\"%s\", id=%" PRId64
,
285 event_class
, bt_event_class_common_get_name(event_class
),
286 bt_event_class_common_get_id(event_class
));
294 struct bt_field_type_common
*bt_event_class_common_borrow_context_field_type(
295 struct bt_event_class_common
*event_class
)
297 struct bt_field_type_common
*context_ft
= NULL
;
299 BT_ASSERT_PRE_NON_NULL(event_class
, "Event class");
301 if (!event_class
->context_field_type
) {
302 BT_LOGV("Event class has no context field type: "
303 "addr=%p, name=\"%s\", id=%" PRId64
,
304 event_class
, bt_event_class_common_get_name(event_class
),
305 bt_event_class_common_get_id(event_class
));
309 context_ft
= event_class
->context_field_type
;
316 int bt_event_class_common_set_context_field_type(
317 struct bt_event_class_common
*event_class
,
318 struct bt_field_type_common
*context_ft
)
323 BT_LOGW_STR("Invalid parameter: event class is NULL.");
328 if (event_class
->frozen
) {
329 BT_LOGW("Invalid parameter: event class is frozen: "
330 "addr=%p, name=\"%s\", id=%" PRId64
,
331 event_class
, bt_event_class_common_get_name(event_class
),
332 bt_event_class_common_get_id(event_class
));
337 if (context_ft
&& bt_field_type_common_get_type_id(context_ft
) !=
338 BT_FIELD_TYPE_ID_STRUCT
) {
339 BT_LOGW("Invalid parameter: event class's context field type must be a structure: "
340 "addr=%p, name=\"%s\", id=%" PRId64
", "
342 event_class
, bt_event_class_common_get_name(event_class
),
343 bt_event_class_common_get_id(event_class
),
344 bt_common_field_type_id_string(
345 bt_field_type_common_get_type_id(context_ft
)));
350 bt_put(event_class
->context_field_type
);
351 event_class
->context_field_type
= bt_get(context_ft
);
352 BT_LOGV("Set event class's context field type: "
353 "event-class-addr=%p, event-class-name=\"%s\", "
354 "event-class-id=%" PRId64
", context-ft-addr=%p",
355 event_class
, bt_event_class_common_get_name(event_class
),
356 bt_event_class_common_get_id(event_class
), context_ft
);
363 struct bt_field_type_common
*bt_event_class_common_borrow_payload_field_type(
364 struct bt_event_class_common
*event_class
)
366 BT_ASSERT_PRE_NON_NULL(event_class
, "Event class");
367 return event_class
->payload_field_type
;
371 int bt_event_class_common_set_payload_field_type(
372 struct bt_event_class_common
*event_class
,
373 struct bt_field_type_common
*payload_ft
)
378 BT_LOGW_STR("Invalid parameter: event class is NULL.");
383 if (payload_ft
&& bt_field_type_common_get_type_id(payload_ft
) !=
384 BT_FIELD_TYPE_ID_STRUCT
) {
385 BT_LOGW("Invalid parameter: event class's payload field type must be a structure: "
386 "addr=%p, name=\"%s\", id=%" PRId64
", "
387 "payload-ft-addr=%p, payload-ft-id=%s",
388 event_class
, bt_event_class_common_get_name(event_class
),
389 bt_event_class_common_get_id(event_class
), payload_ft
,
390 bt_common_field_type_id_string(
391 bt_field_type_common_get_type_id(payload_ft
)));
396 bt_put(event_class
->payload_field_type
);
397 event_class
->payload_field_type
= bt_get(payload_ft
);
398 BT_LOGV("Set event class's payload field type: "
399 "event-class-addr=%p, event-class-name=\"%s\", "
400 "event-class-id=%" PRId64
", payload-ft-addr=%p",
401 event_class
, bt_event_class_common_get_name(event_class
),
402 bt_event_class_common_get_id(event_class
), payload_ft
);
407 #endif /* BABELTRACE_CTF_IR_EVENT_CLASS_INTERNAL_H */