1 #ifndef BABELTRACE_CTF_WRITER_EVENT_CLASS_INTERNAL_H
2 #define BABELTRACE_CTF_WRITER_EVENT_CLASS_INTERNAL_H
5 * Babeltrace - CTF writer: 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-internal.h>
31 #include <babeltrace/babeltrace-internal.h>
32 #include <babeltrace/ctf-writer/event.h>
33 #include <babeltrace/ctf-writer/field-types.h>
34 #include <babeltrace/ctf-writer/fields.h>
35 #include <babeltrace/ctf-writer/stream-class.h>
36 #include <babeltrace/ctf-writer/stream.h>
37 #include <babeltrace/ctf-writer/trace-internal.h>
38 #include <babeltrace/object-internal.h>
39 #include <babeltrace/values.h>
42 struct bt_ctf_event_class_common
{
43 struct bt_object base
;
44 struct bt_ctf_field_type_common
*context_field_type
;
45 struct bt_ctf_field_type_common
*payload_field_type
;
49 * This flag indicates if the event class is valid. A valid
50 * event class is _always_ frozen. However, an event class
51 * may be frozen, but not valid yet. This is okay, as long as
52 * no events are created out of this event class.
64 void bt_ctf_event_class_common_freeze(struct bt_ctf_event_class_common
*event_class
);
67 void bt_ctf_event_class_common_set_native_byte_order(
68 struct bt_ctf_event_class_common
*event_class
, int byte_order
);
71 struct bt_ctf_stream_class_common
*bt_ctf_event_class_common_borrow_stream_class(
72 struct bt_ctf_event_class_common
*event_class
)
74 BT_ASSERT(event_class
);
75 return (void *) bt_object_borrow_parent(&event_class
->base
);
78 typedef struct bt_ctf_field_type_common
*(*bt_ctf_field_type_structure_create_func
)();
81 int bt_ctf_event_class_common_initialize(struct bt_ctf_event_class_common
*event_class
,
82 const char *name
, bt_object_release_func release_func
,
83 bt_ctf_field_type_structure_create_func ft_struct_create_func
);
86 void bt_ctf_event_class_common_finalize(struct bt_object
*obj
);
89 int bt_ctf_event_class_common_validate_single_clock_class(
90 struct bt_ctf_event_class_common
*event_class
,
91 struct bt_ctf_clock_class
**expected_clock_class
);
94 const char *bt_ctf_event_class_common_get_name(
95 struct bt_ctf_event_class_common
*event_class
)
97 BT_ASSERT_PRE_NON_NULL(event_class
, "Event class");
98 BT_ASSERT(event_class
->name
);
99 return event_class
->name
->str
;
103 int64_t bt_ctf_event_class_common_get_id(
104 struct bt_ctf_event_class_common
*event_class
)
106 BT_ASSERT_PRE_NON_NULL(event_class
, "Event class");
107 return event_class
->id
;
111 int bt_ctf_event_class_common_set_id(
112 struct bt_ctf_event_class_common
*event_class
, uint64_t id_param
)
115 int64_t id
= (int64_t) id_param
;
118 BT_LOGW_STR("Invalid parameter: event class is NULL.");
123 if (event_class
->frozen
) {
124 BT_LOGW("Invalid parameter: event class is frozen: "
125 "addr=%p, name=\"%s\", id=%" PRId64
,
127 bt_ctf_event_class_common_get_name(event_class
),
128 bt_ctf_event_class_common_get_id(event_class
));
134 BT_LOGW("Invalid parameter: invalid event class's ID: "
135 "addr=%p, name=\"%s\", id=%" PRIu64
,
137 bt_ctf_event_class_common_get_name(event_class
),
143 event_class
->id
= id
;
144 BT_LOGV("Set event class's ID: "
145 "addr=%p, name=\"%s\", id=%" PRId64
,
146 event_class
, bt_ctf_event_class_common_get_name(event_class
), id
);
153 int bt_ctf_event_class_common_get_log_level(
154 struct bt_ctf_event_class_common
*event_class
)
156 BT_ASSERT_PRE_NON_NULL(event_class
, "Event class");
157 return event_class
->log_level
;
161 int bt_ctf_event_class_common_set_log_level(
162 struct bt_ctf_event_class_common
*event_class
, int log_level
)
167 BT_LOGW_STR("Invalid parameter: event class is NULL.");
172 if (event_class
->frozen
) {
173 BT_LOGW("Invalid parameter: event class is frozen: "
174 "addr=%p, name=\"%s\", id=%" PRId64
,
176 bt_ctf_event_class_common_get_name(event_class
),
177 bt_ctf_event_class_common_get_id(event_class
));
183 case BT_CTF_EVENT_CLASS_LOG_LEVEL_UNSPECIFIED
:
184 case BT_CTF_EVENT_CLASS_LOG_LEVEL_EMERGENCY
:
185 case BT_CTF_EVENT_CLASS_LOG_LEVEL_ALERT
:
186 case BT_CTF_EVENT_CLASS_LOG_LEVEL_CRITICAL
:
187 case BT_CTF_EVENT_CLASS_LOG_LEVEL_ERROR
:
188 case BT_CTF_EVENT_CLASS_LOG_LEVEL_WARNING
:
189 case BT_CTF_EVENT_CLASS_LOG_LEVEL_NOTICE
:
190 case BT_CTF_EVENT_CLASS_LOG_LEVEL_INFO
:
191 case BT_CTF_EVENT_CLASS_LOG_LEVEL_DEBUG_SYSTEM
:
192 case BT_CTF_EVENT_CLASS_LOG_LEVEL_DEBUG_PROGRAM
:
193 case BT_CTF_EVENT_CLASS_LOG_LEVEL_DEBUG_PROCESS
:
194 case BT_CTF_EVENT_CLASS_LOG_LEVEL_DEBUG_MODULE
:
195 case BT_CTF_EVENT_CLASS_LOG_LEVEL_DEBUG_UNIT
:
196 case BT_CTF_EVENT_CLASS_LOG_LEVEL_DEBUG_FUNCTION
:
197 case BT_CTF_EVENT_CLASS_LOG_LEVEL_DEBUG_LINE
:
198 case BT_CTF_EVENT_CLASS_LOG_LEVEL_DEBUG
:
201 BT_LOGW("Invalid parameter: unknown event class log level: "
202 "addr=%p, name=\"%s\", id=%" PRId64
", log-level=%d",
203 event_class
, bt_ctf_event_class_common_get_name(event_class
),
204 bt_ctf_event_class_common_get_id(event_class
), log_level
);
209 event_class
->log_level
= log_level
;
210 BT_LOGV("Set event class's log level: "
211 "addr=%p, name=\"%s\", id=%" PRId64
", log-level=%s",
212 event_class
, bt_ctf_event_class_common_get_name(event_class
),
213 bt_ctf_event_class_common_get_id(event_class
),
214 bt_ctf_event_class_log_level_string(log_level
));
221 const char *bt_ctf_event_class_common_get_emf_uri(
222 struct bt_ctf_event_class_common
*event_class
)
224 const char *emf_uri
= NULL
;
226 BT_ASSERT_PRE_NON_NULL(event_class
, "Event class");
228 if (event_class
->emf_uri
->len
> 0) {
229 emf_uri
= event_class
->emf_uri
->str
;
236 int bt_ctf_event_class_common_set_emf_uri(
237 struct bt_ctf_event_class_common
*event_class
,
243 BT_LOGW_STR("Invalid parameter: event class is NULL.");
248 if (emf_uri
&& strlen(emf_uri
) == 0) {
249 BT_LOGW_STR("Invalid parameter: EMF URI is empty.");
254 if (event_class
->frozen
) {
255 BT_LOGW("Invalid parameter: event class is frozen: "
256 "addr=%p, name=\"%s\", id=%" PRId64
,
257 event_class
, bt_ctf_event_class_common_get_name(event_class
),
258 bt_ctf_event_class_common_get_id(event_class
));
264 g_string_assign(event_class
->emf_uri
, emf_uri
);
265 BT_LOGV("Set event class's EMF URI: "
266 "addr=%p, name=\"%s\", id=%" PRId64
", emf-uri=\"%s\"",
267 event_class
, bt_ctf_event_class_common_get_name(event_class
),
268 bt_ctf_event_class_common_get_id(event_class
), emf_uri
);
270 g_string_assign(event_class
->emf_uri
, "");
271 BT_LOGV("Reset event class's EMF URI: "
272 "addr=%p, name=\"%s\", id=%" PRId64
,
273 event_class
, bt_ctf_event_class_common_get_name(event_class
),
274 bt_ctf_event_class_common_get_id(event_class
));
282 struct bt_ctf_field_type_common
*bt_ctf_event_class_common_borrow_context_field_type(
283 struct bt_ctf_event_class_common
*event_class
)
285 struct bt_ctf_field_type_common
*context_ft
= NULL
;
287 BT_ASSERT_PRE_NON_NULL(event_class
, "Event class");
289 if (!event_class
->context_field_type
) {
290 BT_LOGV("Event class has no context field type: "
291 "addr=%p, name=\"%s\", id=%" PRId64
,
292 event_class
, bt_ctf_event_class_common_get_name(event_class
),
293 bt_ctf_event_class_common_get_id(event_class
));
297 context_ft
= event_class
->context_field_type
;
304 int bt_ctf_event_class_common_set_context_field_type(
305 struct bt_ctf_event_class_common
*event_class
,
306 struct bt_ctf_field_type_common
*context_ft
)
311 BT_LOGW_STR("Invalid parameter: event class is NULL.");
316 if (event_class
->frozen
) {
317 BT_LOGW("Invalid parameter: event class is frozen: "
318 "addr=%p, name=\"%s\", id=%" PRId64
,
319 event_class
, bt_ctf_event_class_common_get_name(event_class
),
320 bt_ctf_event_class_common_get_id(event_class
));
325 if (context_ft
&& bt_ctf_field_type_common_get_type_id(context_ft
) !=
326 BT_CTF_FIELD_TYPE_ID_STRUCT
) {
327 BT_LOGW("Invalid parameter: event class's context field type must be a structure: "
328 "addr=%p, name=\"%s\", id=%" PRId64
", "
330 event_class
, bt_ctf_event_class_common_get_name(event_class
),
331 bt_ctf_event_class_common_get_id(event_class
),
332 bt_ctf_field_type_id_string(
333 bt_ctf_field_type_common_get_type_id(context_ft
)));
338 bt_object_put_ref(event_class
->context_field_type
);
339 event_class
->context_field_type
= bt_object_get_ref(context_ft
);
340 BT_LOGV("Set event class's context field type: "
341 "event-class-addr=%p, event-class-name=\"%s\", "
342 "event-class-id=%" PRId64
", context-ft-addr=%p",
343 event_class
, bt_ctf_event_class_common_get_name(event_class
),
344 bt_ctf_event_class_common_get_id(event_class
), context_ft
);
351 struct bt_ctf_field_type_common
*bt_ctf_event_class_common_borrow_payload_field_type(
352 struct bt_ctf_event_class_common
*event_class
)
354 BT_ASSERT_PRE_NON_NULL(event_class
, "Event class");
355 return event_class
->payload_field_type
;
359 int bt_ctf_event_class_common_set_payload_field_type(
360 struct bt_ctf_event_class_common
*event_class
,
361 struct bt_ctf_field_type_common
*payload_ft
)
366 BT_LOGW_STR("Invalid parameter: event class is NULL.");
371 if (payload_ft
&& bt_ctf_field_type_common_get_type_id(payload_ft
) !=
372 BT_CTF_FIELD_TYPE_ID_STRUCT
) {
373 BT_LOGW("Invalid parameter: event class's payload field type must be a structure: "
374 "addr=%p, name=\"%s\", id=%" PRId64
", "
375 "payload-ft-addr=%p, payload-ft-id=%s",
376 event_class
, bt_ctf_event_class_common_get_name(event_class
),
377 bt_ctf_event_class_common_get_id(event_class
), payload_ft
,
378 bt_ctf_field_type_id_string(
379 bt_ctf_field_type_common_get_type_id(payload_ft
)));
384 bt_object_put_ref(event_class
->payload_field_type
);
385 event_class
->payload_field_type
= bt_object_get_ref(payload_ft
);
386 BT_LOGV("Set event class's payload field type: "
387 "event-class-addr=%p, event-class-name=\"%s\", "
388 "event-class-id=%" PRId64
", payload-ft-addr=%p",
389 event_class
, bt_ctf_event_class_common_get_name(event_class
),
390 bt_ctf_event_class_common_get_id(event_class
), payload_ft
);
395 #endif /* BABELTRACE_CTF_WRITER_EVENT_CLASS_INTERNAL_H */