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
);
87 struct bt_stream_class
*bt_event_class_borrow_stream_class(
88 struct bt_event_class
*event_class
)
90 return BT_FROM_COMMON(bt_event_class_common_borrow_stream_class(
91 BT_TO_COMMON(event_class
)));
94 typedef struct bt_field_type_common
*(*bt_field_type_structure_create_func
)();
97 int bt_event_class_common_initialize(struct bt_event_class_common
*event_class
,
98 const char *name
, bt_object_release_func release_func
,
99 bt_field_type_structure_create_func ft_struct_create_func
);
102 void bt_event_class_common_finalize(struct bt_object
*obj
);
105 int bt_event_class_common_validate_single_clock_class(
106 struct bt_event_class_common
*event_class
,
107 struct bt_clock_class
**expected_clock_class
);
110 const char *bt_event_class_common_get_name(
111 struct bt_event_class_common
*event_class
)
113 BT_ASSERT_PRE_NON_NULL(event_class
, "Event class");
114 BT_ASSERT(event_class
->name
);
115 return event_class
->name
->str
;
119 int64_t bt_event_class_common_get_id(
120 struct bt_event_class_common
*event_class
)
122 BT_ASSERT_PRE_NON_NULL(event_class
, "Event class");
123 return event_class
->id
;
127 int bt_event_class_common_set_id(
128 struct bt_event_class_common
*event_class
, uint64_t id_param
)
131 int64_t id
= (int64_t) id_param
;
134 BT_LOGW_STR("Invalid parameter: event class is NULL.");
139 if (event_class
->frozen
) {
140 BT_LOGW("Invalid parameter: event class is frozen: "
141 "addr=%p, name=\"%s\", id=%" PRId64
,
143 bt_event_class_common_get_name(event_class
),
144 bt_event_class_common_get_id(event_class
));
150 BT_LOGW("Invalid parameter: invalid event class's ID: "
151 "addr=%p, name=\"%s\", id=%" PRIu64
,
153 bt_event_class_common_get_name(event_class
),
159 event_class
->id
= id
;
160 BT_LOGV("Set event class's ID: "
161 "addr=%p, name=\"%s\", id=%" PRId64
,
162 event_class
, bt_event_class_common_get_name(event_class
), id
);
169 int bt_event_class_common_get_log_level(
170 struct bt_event_class_common
*event_class
)
172 BT_ASSERT_PRE_NON_NULL(event_class
, "Event class");
173 return event_class
->log_level
;
177 int bt_event_class_common_set_log_level(
178 struct bt_event_class_common
*event_class
, int log_level
)
183 BT_LOGW_STR("Invalid parameter: event class is NULL.");
188 if (event_class
->frozen
) {
189 BT_LOGW("Invalid parameter: event class is frozen: "
190 "addr=%p, name=\"%s\", id=%" PRId64
,
192 bt_event_class_common_get_name(event_class
),
193 bt_event_class_common_get_id(event_class
));
199 case BT_EVENT_CLASS_LOG_LEVEL_UNSPECIFIED
:
200 case BT_EVENT_CLASS_LOG_LEVEL_EMERGENCY
:
201 case BT_EVENT_CLASS_LOG_LEVEL_ALERT
:
202 case BT_EVENT_CLASS_LOG_LEVEL_CRITICAL
:
203 case BT_EVENT_CLASS_LOG_LEVEL_ERROR
:
204 case BT_EVENT_CLASS_LOG_LEVEL_WARNING
:
205 case BT_EVENT_CLASS_LOG_LEVEL_NOTICE
:
206 case BT_EVENT_CLASS_LOG_LEVEL_INFO
:
207 case BT_EVENT_CLASS_LOG_LEVEL_DEBUG_SYSTEM
:
208 case BT_EVENT_CLASS_LOG_LEVEL_DEBUG_PROGRAM
:
209 case BT_EVENT_CLASS_LOG_LEVEL_DEBUG_PROCESS
:
210 case BT_EVENT_CLASS_LOG_LEVEL_DEBUG_MODULE
:
211 case BT_EVENT_CLASS_LOG_LEVEL_DEBUG_UNIT
:
212 case BT_EVENT_CLASS_LOG_LEVEL_DEBUG_FUNCTION
:
213 case BT_EVENT_CLASS_LOG_LEVEL_DEBUG_LINE
:
214 case BT_EVENT_CLASS_LOG_LEVEL_DEBUG
:
217 BT_LOGW("Invalid parameter: unknown event class log level: "
218 "addr=%p, name=\"%s\", id=%" PRId64
", log-level=%d",
219 event_class
, bt_event_class_common_get_name(event_class
),
220 bt_event_class_common_get_id(event_class
), log_level
);
225 event_class
->log_level
= log_level
;
226 BT_LOGV("Set event class's log level: "
227 "addr=%p, name=\"%s\", id=%" PRId64
", log-level=%s",
228 event_class
, bt_event_class_common_get_name(event_class
),
229 bt_event_class_common_get_id(event_class
),
230 bt_common_event_class_log_level_string(log_level
));
237 const char *bt_event_class_common_get_emf_uri(
238 struct bt_event_class_common
*event_class
)
240 const char *emf_uri
= NULL
;
242 BT_ASSERT_PRE_NON_NULL(event_class
, "Event class");
244 if (event_class
->emf_uri
->len
> 0) {
245 emf_uri
= event_class
->emf_uri
->str
;
252 int bt_event_class_common_set_emf_uri(
253 struct bt_event_class_common
*event_class
,
259 BT_LOGW_STR("Invalid parameter: event class is NULL.");
264 if (emf_uri
&& strlen(emf_uri
) == 0) {
265 BT_LOGW_STR("Invalid parameter: EMF URI is empty.");
270 if (event_class
->frozen
) {
271 BT_LOGW("Invalid parameter: event class is frozen: "
272 "addr=%p, name=\"%s\", id=%" PRId64
,
273 event_class
, bt_event_class_common_get_name(event_class
),
274 bt_event_class_common_get_id(event_class
));
280 g_string_assign(event_class
->emf_uri
, emf_uri
);
281 BT_LOGV("Set event class's EMF URI: "
282 "addr=%p, name=\"%s\", id=%" PRId64
", emf-uri=\"%s\"",
283 event_class
, bt_event_class_common_get_name(event_class
),
284 bt_event_class_common_get_id(event_class
), emf_uri
);
286 g_string_assign(event_class
->emf_uri
, "");
287 BT_LOGV("Reset event class's EMF URI: "
288 "addr=%p, name=\"%s\", id=%" PRId64
,
289 event_class
, bt_event_class_common_get_name(event_class
),
290 bt_event_class_common_get_id(event_class
));
298 struct bt_field_type_common
*bt_event_class_common_get_context_field_type(
299 struct bt_event_class_common
*event_class
)
301 struct bt_field_type_common
*context_ft
= NULL
;
303 BT_ASSERT_PRE_NON_NULL(event_class
, "Event class");
305 if (!event_class
->context_field_type
) {
306 BT_LOGV("Event class has no context field type: "
307 "addr=%p, name=\"%s\", id=%" PRId64
,
308 event_class
, bt_event_class_common_get_name(event_class
),
309 bt_event_class_common_get_id(event_class
));
313 context_ft
= bt_get(event_class
->context_field_type
);
320 int bt_event_class_common_set_context_field_type(
321 struct bt_event_class_common
*event_class
,
322 struct bt_field_type_common
*context_ft
)
327 BT_LOGW_STR("Invalid parameter: event class is NULL.");
332 if (event_class
->frozen
) {
333 BT_LOGW("Invalid parameter: event class is frozen: "
334 "addr=%p, name=\"%s\", id=%" PRId64
,
335 event_class
, bt_event_class_common_get_name(event_class
),
336 bt_event_class_common_get_id(event_class
));
341 if (context_ft
&& bt_field_type_common_get_type_id(context_ft
) !=
342 BT_FIELD_TYPE_ID_STRUCT
) {
343 BT_LOGW("Invalid parameter: event class's context field type must be a structure: "
344 "addr=%p, name=\"%s\", id=%" PRId64
", "
346 event_class
, bt_event_class_common_get_name(event_class
),
347 bt_event_class_common_get_id(event_class
),
348 bt_common_field_type_id_string(
349 bt_field_type_common_get_type_id(context_ft
)));
354 bt_put(event_class
->context_field_type
);
355 event_class
->context_field_type
= bt_get(context_ft
);
356 BT_LOGV("Set event class's context field type: "
357 "event-class-addr=%p, event-class-name=\"%s\", "
358 "event-class-id=%" PRId64
", context-ft-addr=%p",
359 event_class
, bt_event_class_common_get_name(event_class
),
360 bt_event_class_common_get_id(event_class
), context_ft
);
367 struct bt_field_type_common
*bt_event_class_common_get_payload_field_type(
368 struct bt_event_class_common
*event_class
)
370 BT_ASSERT_PRE_NON_NULL(event_class
, "Event class");
371 return bt_get(event_class
->payload_field_type
);
375 int bt_event_class_common_set_payload_field_type(
376 struct bt_event_class_common
*event_class
,
377 struct bt_field_type_common
*payload_ft
)
382 BT_LOGW_STR("Invalid parameter: event class is NULL.");
387 if (payload_ft
&& bt_field_type_common_get_type_id(payload_ft
) !=
388 BT_FIELD_TYPE_ID_STRUCT
) {
389 BT_LOGW("Invalid parameter: event class's payload field type must be a structure: "
390 "addr=%p, name=\"%s\", id=%" PRId64
", "
391 "payload-ft-addr=%p, payload-ft-id=%s",
392 event_class
, bt_event_class_common_get_name(event_class
),
393 bt_event_class_common_get_id(event_class
), payload_ft
,
394 bt_common_field_type_id_string(
395 bt_field_type_common_get_type_id(payload_ft
)));
400 bt_put(event_class
->payload_field_type
);
401 event_class
->payload_field_type
= bt_get(payload_ft
);
402 BT_LOGV("Set event class's payload field type: "
403 "event-class-addr=%p, event-class-name=\"%s\", "
404 "event-class-id=%" PRId64
", payload-ft-addr=%p",
405 event_class
, bt_event_class_common_get_name(event_class
),
406 bt_event_class_common_get_id(event_class
), payload_ft
);
411 #endif /* BABELTRACE_CTF_IR_EVENT_CLASS_INTERNAL_H */