1 #ifndef BABELTRACE_CTF_WRITER_EVENT_CLASS_INTERNAL_H
2 #define BABELTRACE_CTF_WRITER_EVENT_CLASS_INTERNAL_H
5 * Copyright 2013, 2014 Jérémie Galarneau <jeremie.galarneau@efficios.com>
7 * Author: Jérémie Galarneau <jeremie.galarneau@efficios.com>
9 * Permission is hereby granted, free of charge, to any person obtaining a copy
10 * of this software and associated documentation files (the "Software"), to deal
11 * in the Software without restriction, including without limitation the rights
12 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
13 * copies of the Software, and to permit persons to whom the Software is
14 * furnished to do so, subject to the following conditions:
16 * The above copyright notice and this permission notice shall be included in
17 * all copies or substantial portions of the Software.
19 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
28 #include "common/assert.h"
29 #include "common/macros.h"
30 #include <babeltrace2/ctf-writer/event.h>
31 #include <babeltrace2/ctf-writer/field-types.h>
32 #include <babeltrace2/ctf-writer/fields.h>
33 #include <babeltrace2/ctf-writer/stream-class.h>
34 #include <babeltrace2/ctf-writer/stream.h>
41 struct bt_ctf_event_class_common
{
42 struct bt_ctf_object base
;
43 struct bt_ctf_field_type_common
*context_field_type
;
44 struct bt_ctf_field_type_common
*payload_field_type
;
48 * This flag indicates if the event class is valid. A valid
49 * event class is _always_ frozen. However, an event class
50 * may be frozen, but not valid yet. This is okay, as long as
51 * no events are created out of this event class.
63 void bt_ctf_event_class_common_freeze(struct bt_ctf_event_class_common
*event_class
);
66 void bt_ctf_event_class_common_set_native_byte_order(
67 struct bt_ctf_event_class_common
*event_class
, int byte_order
);
70 struct bt_ctf_stream_class_common
*bt_ctf_event_class_common_borrow_stream_class(
71 struct bt_ctf_event_class_common
*event_class
)
73 BT_ASSERT(event_class
);
74 return (void *) bt_ctf_object_borrow_parent(&event_class
->base
);
77 typedef struct bt_ctf_field_type_common
*(*bt_ctf_field_type_structure_create_func
)();
80 int bt_ctf_event_class_common_initialize(struct bt_ctf_event_class_common
*event_class
,
81 const char *name
, bt_ctf_object_release_func release_func
,
82 bt_ctf_field_type_structure_create_func ft_struct_create_func
);
85 void bt_ctf_event_class_common_finalize(struct bt_ctf_object
*obj
);
88 int bt_ctf_event_class_common_validate_single_clock_class(
89 struct bt_ctf_event_class_common
*event_class
,
90 struct bt_ctf_clock_class
**expected_clock_class
);
93 const char *bt_ctf_event_class_common_get_name(
94 struct bt_ctf_event_class_common
*event_class
)
96 BT_CTF_ASSERT_PRE_NON_NULL(event_class
, "Event class");
97 BT_ASSERT(event_class
->name
);
98 return event_class
->name
->str
;
102 int64_t bt_ctf_event_class_common_get_id(
103 struct bt_ctf_event_class_common
*event_class
)
105 BT_CTF_ASSERT_PRE_NON_NULL(event_class
, "Event class");
106 return event_class
->id
;
110 int bt_ctf_event_class_common_set_id(
111 struct bt_ctf_event_class_common
*event_class
, uint64_t id_param
)
114 int64_t id
= (int64_t) id_param
;
117 BT_LOGW_STR("Invalid parameter: event class is NULL.");
122 if (event_class
->frozen
) {
123 BT_LOGW("Invalid parameter: event class is frozen: "
124 "addr=%p, name=\"%s\", id=%" PRId64
,
126 bt_ctf_event_class_common_get_name(event_class
),
127 bt_ctf_event_class_common_get_id(event_class
));
133 BT_LOGW("Invalid parameter: invalid event class's ID: "
134 "addr=%p, name=\"%s\", id=%" PRIu64
,
136 bt_ctf_event_class_common_get_name(event_class
),
142 event_class
->id
= id
;
143 BT_LOGV("Set event class's ID: "
144 "addr=%p, name=\"%s\", id=%" PRId64
,
145 event_class
, bt_ctf_event_class_common_get_name(event_class
), id
);
152 int bt_ctf_event_class_common_get_log_level(
153 struct bt_ctf_event_class_common
*event_class
)
155 BT_CTF_ASSERT_PRE_NON_NULL(event_class
, "Event class");
156 return event_class
->log_level
;
160 int bt_ctf_event_class_common_set_log_level(
161 struct bt_ctf_event_class_common
*event_class
, int log_level
)
166 BT_LOGW_STR("Invalid parameter: event class is NULL.");
171 if (event_class
->frozen
) {
172 BT_LOGW("Invalid parameter: event class is frozen: "
173 "addr=%p, name=\"%s\", id=%" PRId64
,
175 bt_ctf_event_class_common_get_name(event_class
),
176 bt_ctf_event_class_common_get_id(event_class
));
182 case BT_CTF_EVENT_CLASS_LOG_LEVEL_UNSPECIFIED
:
183 case BT_CTF_EVENT_CLASS_LOG_LEVEL_EMERGENCY
:
184 case BT_CTF_EVENT_CLASS_LOG_LEVEL_ALERT
:
185 case BT_CTF_EVENT_CLASS_LOG_LEVEL_CRITICAL
:
186 case BT_CTF_EVENT_CLASS_LOG_LEVEL_ERROR
:
187 case BT_CTF_EVENT_CLASS_LOG_LEVEL_WARNING
:
188 case BT_CTF_EVENT_CLASS_LOG_LEVEL_NOTICE
:
189 case BT_CTF_EVENT_CLASS_LOG_LEVEL_INFO
:
190 case BT_CTF_EVENT_CLASS_LOG_LEVEL_DEBUG_SYSTEM
:
191 case BT_CTF_EVENT_CLASS_LOG_LEVEL_DEBUG_PROGRAM
:
192 case BT_CTF_EVENT_CLASS_LOG_LEVEL_DEBUG_PROCESS
:
193 case BT_CTF_EVENT_CLASS_LOG_LEVEL_DEBUG_MODULE
:
194 case BT_CTF_EVENT_CLASS_LOG_LEVEL_DEBUG_UNIT
:
195 case BT_CTF_EVENT_CLASS_LOG_LEVEL_DEBUG_FUNCTION
:
196 case BT_CTF_EVENT_CLASS_LOG_LEVEL_DEBUG_LINE
:
197 case BT_CTF_EVENT_CLASS_LOG_LEVEL_DEBUG
:
200 BT_LOGW("Invalid parameter: unknown event class log level: "
201 "addr=%p, name=\"%s\", id=%" PRId64
", log-level=%d",
202 event_class
, bt_ctf_event_class_common_get_name(event_class
),
203 bt_ctf_event_class_common_get_id(event_class
), log_level
);
208 event_class
->log_level
= log_level
;
209 BT_LOGV("Set event class's log level: "
210 "addr=%p, name=\"%s\", id=%" PRId64
", log-level=%s",
211 event_class
, bt_ctf_event_class_common_get_name(event_class
),
212 bt_ctf_event_class_common_get_id(event_class
),
213 bt_ctf_event_class_log_level_string(log_level
));
220 const char *bt_ctf_event_class_common_get_emf_uri(
221 struct bt_ctf_event_class_common
*event_class
)
223 const char *emf_uri
= NULL
;
225 BT_CTF_ASSERT_PRE_NON_NULL(event_class
, "Event class");
227 if (event_class
->emf_uri
->len
> 0) {
228 emf_uri
= event_class
->emf_uri
->str
;
235 int bt_ctf_event_class_common_set_emf_uri(
236 struct bt_ctf_event_class_common
*event_class
,
242 BT_LOGW_STR("Invalid parameter: event class is NULL.");
247 if (emf_uri
&& strlen(emf_uri
) == 0) {
248 BT_LOGW_STR("Invalid parameter: EMF URI is empty.");
253 if (event_class
->frozen
) {
254 BT_LOGW("Invalid parameter: event class is frozen: "
255 "addr=%p, name=\"%s\", id=%" PRId64
,
256 event_class
, bt_ctf_event_class_common_get_name(event_class
),
257 bt_ctf_event_class_common_get_id(event_class
));
263 g_string_assign(event_class
->emf_uri
, emf_uri
);
264 BT_LOGV("Set event class's EMF URI: "
265 "addr=%p, name=\"%s\", id=%" PRId64
", emf-uri=\"%s\"",
266 event_class
, bt_ctf_event_class_common_get_name(event_class
),
267 bt_ctf_event_class_common_get_id(event_class
), emf_uri
);
269 g_string_assign(event_class
->emf_uri
, "");
270 BT_LOGV("Reset event class's EMF URI: "
271 "addr=%p, name=\"%s\", id=%" PRId64
,
272 event_class
, bt_ctf_event_class_common_get_name(event_class
),
273 bt_ctf_event_class_common_get_id(event_class
));
281 struct bt_ctf_field_type_common
*bt_ctf_event_class_common_borrow_context_field_type(
282 struct bt_ctf_event_class_common
*event_class
)
284 struct bt_ctf_field_type_common
*context_ft
= NULL
;
286 BT_CTF_ASSERT_PRE_NON_NULL(event_class
, "Event class");
288 if (!event_class
->context_field_type
) {
289 BT_LOGV("Event class has no context field type: "
290 "addr=%p, name=\"%s\", id=%" PRId64
,
291 event_class
, bt_ctf_event_class_common_get_name(event_class
),
292 bt_ctf_event_class_common_get_id(event_class
));
296 context_ft
= event_class
->context_field_type
;
303 int bt_ctf_event_class_common_set_context_field_type(
304 struct bt_ctf_event_class_common
*event_class
,
305 struct bt_ctf_field_type_common
*context_ft
)
310 BT_LOGW_STR("Invalid parameter: event class is NULL.");
315 if (event_class
->frozen
) {
316 BT_LOGW("Invalid parameter: event class is frozen: "
317 "addr=%p, name=\"%s\", id=%" PRId64
,
318 event_class
, bt_ctf_event_class_common_get_name(event_class
),
319 bt_ctf_event_class_common_get_id(event_class
));
324 if (context_ft
&& bt_ctf_field_type_common_get_type_id(context_ft
) !=
325 BT_CTF_FIELD_TYPE_ID_STRUCT
) {
326 BT_LOGW("Invalid parameter: event class's context field type must be a structure: "
327 "addr=%p, name=\"%s\", id=%" PRId64
", "
329 event_class
, bt_ctf_event_class_common_get_name(event_class
),
330 bt_ctf_event_class_common_get_id(event_class
),
331 bt_ctf_field_type_id_string(
332 bt_ctf_field_type_common_get_type_id(context_ft
)));
337 bt_ctf_object_put_ref(event_class
->context_field_type
);
338 event_class
->context_field_type
= context_ft
;
339 bt_ctf_object_get_ref(event_class
->context_field_type
);
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_CTF_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_ctf_object_put_ref(event_class
->payload_field_type
);
385 event_class
->payload_field_type
= payload_ft
;
386 bt_ctf_object_get_ref(event_class
->payload_field_type
);
387 BT_LOGV("Set event class's payload field type: "
388 "event-class-addr=%p, event-class-name=\"%s\", "
389 "event-class-id=%" PRId64
", payload-ft-addr=%p",
390 event_class
, bt_ctf_event_class_common_get_name(event_class
),
391 bt_ctf_event_class_common_get_id(event_class
), payload_ft
);
396 #endif /* BABELTRACE_CTF_WRITER_EVENT_CLASS_INTERNAL_H */