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>
43 struct bt_event_class_common
{
44 struct bt_object base
;
45 struct bt_field_type_common
*context_field_type
;
46 struct bt_field_type_common
*payload_field_type
;
50 * This flag indicates if the event class is valid. A valid
51 * event class is _always_ frozen. However, an event class
52 * may be frozen, but not valid yet. This is okay, as long as
53 * no events are created out of this event class.
64 struct bt_event_class
{
65 struct bt_event_class_common common
;
69 void bt_event_class_freeze(struct bt_event_class
*event_class
);
72 void bt_event_class_common_freeze(struct bt_event_class_common
*event_class
);
75 void bt_event_class_common_set_native_byte_order(
76 struct bt_event_class_common
*event_class
, int byte_order
);
79 struct bt_stream_class_common
*bt_event_class_common_borrow_stream_class(
80 struct bt_event_class_common
*event_class
)
82 BT_ASSERT(event_class
);
83 return (void *) bt_object_borrow_parent(event_class
);
86 typedef struct bt_field_type_common
*(*bt_field_type_structure_create_func
)();
89 int bt_event_class_common_initialize(struct bt_event_class_common
*event_class
,
90 const char *name
, bt_object_release_func release_func
,
91 bt_field_type_structure_create_func ft_struct_create_func
);
94 void bt_event_class_common_finalize(struct bt_object
*obj
);
97 int bt_event_class_common_validate_single_clock_class(
98 struct bt_event_class_common
*event_class
,
99 struct bt_clock_class
**expected_clock_class
);
102 const char *bt_event_class_common_get_name(
103 struct bt_event_class_common
*event_class
)
105 BT_ASSERT_PRE_NON_NULL(event_class
, "Event class");
106 BT_ASSERT(event_class
->name
);
107 return event_class
->name
->str
;
111 int64_t bt_event_class_common_get_id(
112 struct bt_event_class_common
*event_class
)
114 BT_ASSERT_PRE_NON_NULL(event_class
, "Event class");
115 return event_class
->id
;
119 int bt_event_class_common_set_id(
120 struct bt_event_class_common
*event_class
, uint64_t id_param
)
123 int64_t id
= (int64_t) id_param
;
126 BT_LOGW_STR("Invalid parameter: event class is NULL.");
131 if (event_class
->frozen
) {
132 BT_LOGW("Invalid parameter: event class is frozen: "
133 "addr=%p, name=\"%s\", id=%" PRId64
,
135 bt_event_class_common_get_name(event_class
),
136 bt_event_class_common_get_id(event_class
));
142 BT_LOGW("Invalid parameter: invalid event class's ID: "
143 "addr=%p, name=\"%s\", id=%" PRIu64
,
145 bt_event_class_common_get_name(event_class
),
151 event_class
->id
= id
;
152 BT_LOGV("Set event class's ID: "
153 "addr=%p, name=\"%s\", id=%" PRId64
,
154 event_class
, bt_event_class_common_get_name(event_class
), id
);
161 int bt_event_class_common_get_log_level(
162 struct bt_event_class_common
*event_class
)
164 BT_ASSERT_PRE_NON_NULL(event_class
, "Event class");
165 return event_class
->log_level
;
169 int bt_event_class_common_set_log_level(
170 struct bt_event_class_common
*event_class
, int log_level
)
175 BT_LOGW_STR("Invalid parameter: event class is NULL.");
180 if (event_class
->frozen
) {
181 BT_LOGW("Invalid parameter: event class is frozen: "
182 "addr=%p, name=\"%s\", id=%" PRId64
,
184 bt_event_class_common_get_name(event_class
),
185 bt_event_class_common_get_id(event_class
));
191 case BT_EVENT_CLASS_LOG_LEVEL_UNSPECIFIED
:
192 case BT_EVENT_CLASS_LOG_LEVEL_EMERGENCY
:
193 case BT_EVENT_CLASS_LOG_LEVEL_ALERT
:
194 case BT_EVENT_CLASS_LOG_LEVEL_CRITICAL
:
195 case BT_EVENT_CLASS_LOG_LEVEL_ERROR
:
196 case BT_EVENT_CLASS_LOG_LEVEL_WARNING
:
197 case BT_EVENT_CLASS_LOG_LEVEL_NOTICE
:
198 case BT_EVENT_CLASS_LOG_LEVEL_INFO
:
199 case BT_EVENT_CLASS_LOG_LEVEL_DEBUG_SYSTEM
:
200 case BT_EVENT_CLASS_LOG_LEVEL_DEBUG_PROGRAM
:
201 case BT_EVENT_CLASS_LOG_LEVEL_DEBUG_PROCESS
:
202 case BT_EVENT_CLASS_LOG_LEVEL_DEBUG_MODULE
:
203 case BT_EVENT_CLASS_LOG_LEVEL_DEBUG_UNIT
:
204 case BT_EVENT_CLASS_LOG_LEVEL_DEBUG_FUNCTION
:
205 case BT_EVENT_CLASS_LOG_LEVEL_DEBUG_LINE
:
206 case BT_EVENT_CLASS_LOG_LEVEL_DEBUG
:
209 BT_LOGW("Invalid parameter: unknown event class log level: "
210 "addr=%p, name=\"%s\", id=%" PRId64
", log-level=%d",
211 event_class
, bt_event_class_common_get_name(event_class
),
212 bt_event_class_common_get_id(event_class
), log_level
);
217 event_class
->log_level
= log_level
;
218 BT_LOGV("Set event class's log level: "
219 "addr=%p, name=\"%s\", id=%" PRId64
", log-level=%s",
220 event_class
, bt_event_class_common_get_name(event_class
),
221 bt_event_class_common_get_id(event_class
),
222 bt_common_event_class_log_level_string(log_level
));
229 const char *bt_event_class_common_get_emf_uri(
230 struct bt_event_class_common
*event_class
)
232 const char *emf_uri
= NULL
;
234 BT_ASSERT_PRE_NON_NULL(event_class
, "Event class");
236 if (event_class
->emf_uri
->len
> 0) {
237 emf_uri
= event_class
->emf_uri
->str
;
244 int bt_event_class_common_set_emf_uri(
245 struct bt_event_class_common
*event_class
,
251 BT_LOGW_STR("Invalid parameter: event class is NULL.");
256 if (emf_uri
&& strlen(emf_uri
) == 0) {
257 BT_LOGW_STR("Invalid parameter: EMF URI is empty.");
262 if (event_class
->frozen
) {
263 BT_LOGW("Invalid parameter: event class is frozen: "
264 "addr=%p, name=\"%s\", id=%" PRId64
,
265 event_class
, bt_event_class_common_get_name(event_class
),
266 bt_event_class_common_get_id(event_class
));
272 g_string_assign(event_class
->emf_uri
, emf_uri
);
273 BT_LOGV("Set event class's EMF URI: "
274 "addr=%p, name=\"%s\", id=%" PRId64
", emf-uri=\"%s\"",
275 event_class
, bt_event_class_common_get_name(event_class
),
276 bt_event_class_common_get_id(event_class
), emf_uri
);
278 g_string_assign(event_class
->emf_uri
, "");
279 BT_LOGV("Reset event class's EMF URI: "
280 "addr=%p, name=\"%s\", id=%" PRId64
,
281 event_class
, bt_event_class_common_get_name(event_class
),
282 bt_event_class_common_get_id(event_class
));
290 struct bt_field_type_common
*bt_event_class_common_borrow_context_field_type(
291 struct bt_event_class_common
*event_class
)
293 struct bt_field_type_common
*context_ft
= NULL
;
295 BT_ASSERT_PRE_NON_NULL(event_class
, "Event class");
297 if (!event_class
->context_field_type
) {
298 BT_LOGV("Event class has no context field type: "
299 "addr=%p, name=\"%s\", id=%" PRId64
,
300 event_class
, bt_event_class_common_get_name(event_class
),
301 bt_event_class_common_get_id(event_class
));
305 context_ft
= event_class
->context_field_type
;
312 int bt_event_class_common_set_context_field_type(
313 struct bt_event_class_common
*event_class
,
314 struct bt_field_type_common
*context_ft
)
319 BT_LOGW_STR("Invalid parameter: event class is NULL.");
324 if (event_class
->frozen
) {
325 BT_LOGW("Invalid parameter: event class is frozen: "
326 "addr=%p, name=\"%s\", id=%" PRId64
,
327 event_class
, bt_event_class_common_get_name(event_class
),
328 bt_event_class_common_get_id(event_class
));
333 if (context_ft
&& bt_field_type_common_get_type_id(context_ft
) !=
334 BT_FIELD_TYPE_ID_STRUCT
) {
335 BT_LOGW("Invalid parameter: event class's context field type must be a structure: "
336 "addr=%p, name=\"%s\", id=%" PRId64
", "
338 event_class
, bt_event_class_common_get_name(event_class
),
339 bt_event_class_common_get_id(event_class
),
340 bt_common_field_type_id_string(
341 bt_field_type_common_get_type_id(context_ft
)));
346 bt_put(event_class
->context_field_type
);
347 event_class
->context_field_type
= bt_get(context_ft
);
348 BT_LOGV("Set event class's context field type: "
349 "event-class-addr=%p, event-class-name=\"%s\", "
350 "event-class-id=%" PRId64
", context-ft-addr=%p",
351 event_class
, bt_event_class_common_get_name(event_class
),
352 bt_event_class_common_get_id(event_class
), context_ft
);
359 struct bt_field_type_common
*bt_event_class_common_borrow_payload_field_type(
360 struct bt_event_class_common
*event_class
)
362 BT_ASSERT_PRE_NON_NULL(event_class
, "Event class");
363 return event_class
->payload_field_type
;
367 int bt_event_class_common_set_payload_field_type(
368 struct bt_event_class_common
*event_class
,
369 struct bt_field_type_common
*payload_ft
)
374 BT_LOGW_STR("Invalid parameter: event class is NULL.");
379 if (payload_ft
&& bt_field_type_common_get_type_id(payload_ft
) !=
380 BT_FIELD_TYPE_ID_STRUCT
) {
381 BT_LOGW("Invalid parameter: event class's payload field type must be a structure: "
382 "addr=%p, name=\"%s\", id=%" PRId64
", "
383 "payload-ft-addr=%p, payload-ft-id=%s",
384 event_class
, bt_event_class_common_get_name(event_class
),
385 bt_event_class_common_get_id(event_class
), payload_ft
,
386 bt_common_field_type_id_string(
387 bt_field_type_common_get_type_id(payload_ft
)));
392 bt_put(event_class
->payload_field_type
);
393 event_class
->payload_field_type
= bt_get(payload_ft
);
394 BT_LOGV("Set event class's payload field type: "
395 "event-class-addr=%p, event-class-name=\"%s\", "
396 "event-class-id=%" PRId64
", payload-ft-addr=%p",
397 event_class
, bt_event_class_common_get_name(event_class
),
398 bt_event_class_common_get_id(event_class
), payload_ft
);
403 #endif /* BABELTRACE_CTF_IR_EVENT_CLASS_INTERNAL_H */