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 <babeltrace2/assert-internal.h>
29 #include <babeltrace2/babeltrace-internal.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>
35 #include <babeltrace2/ctf-writer/trace-internal.h>
36 #include <babeltrace2/ctf-writer/object-internal.h>
37 #include <babeltrace2/ctf-writer/values-internal.h>
40 struct bt_ctf_event_class_common
{
41 struct bt_ctf_object base
;
42 struct bt_ctf_field_type_common
*context_field_type
;
43 struct bt_ctf_field_type_common
*payload_field_type
;
47 * This flag indicates if the event class is valid. A valid
48 * event class is _always_ frozen. However, an event class
49 * may be frozen, but not valid yet. This is okay, as long as
50 * no events are created out of this event class.
62 void bt_ctf_event_class_common_freeze(struct bt_ctf_event_class_common
*event_class
);
65 void bt_ctf_event_class_common_set_native_byte_order(
66 struct bt_ctf_event_class_common
*event_class
, int byte_order
);
69 struct bt_ctf_stream_class_common
*bt_ctf_event_class_common_borrow_stream_class(
70 struct bt_ctf_event_class_common
*event_class
)
72 BT_ASSERT(event_class
);
73 return (void *) bt_ctf_object_borrow_parent(&event_class
->base
);
76 typedef struct bt_ctf_field_type_common
*(*bt_ctf_field_type_structure_create_func
)();
79 int bt_ctf_event_class_common_initialize(struct bt_ctf_event_class_common
*event_class
,
80 const char *name
, bt_ctf_object_release_func release_func
,
81 bt_ctf_field_type_structure_create_func ft_struct_create_func
);
84 void bt_ctf_event_class_common_finalize(struct bt_ctf_object
*obj
);
87 int bt_ctf_event_class_common_validate_single_clock_class(
88 struct bt_ctf_event_class_common
*event_class
,
89 struct bt_ctf_clock_class
**expected_clock_class
);
92 const char *bt_ctf_event_class_common_get_name(
93 struct bt_ctf_event_class_common
*event_class
)
95 BT_ASSERT_PRE_NON_NULL(event_class
, "Event class");
96 BT_ASSERT(event_class
->name
);
97 return event_class
->name
->str
;
101 int64_t bt_ctf_event_class_common_get_id(
102 struct bt_ctf_event_class_common
*event_class
)
104 BT_ASSERT_PRE_NON_NULL(event_class
, "Event class");
105 return event_class
->id
;
109 int bt_ctf_event_class_common_set_id(
110 struct bt_ctf_event_class_common
*event_class
, uint64_t id_param
)
113 int64_t id
= (int64_t) id_param
;
116 BT_LOGW_STR("Invalid parameter: event class is NULL.");
121 if (event_class
->frozen
) {
122 BT_LOGW("Invalid parameter: event class is frozen: "
123 "addr=%p, name=\"%s\", id=%" PRId64
,
125 bt_ctf_event_class_common_get_name(event_class
),
126 bt_ctf_event_class_common_get_id(event_class
));
132 BT_LOGW("Invalid parameter: invalid event class's ID: "
133 "addr=%p, name=\"%s\", id=%" PRIu64
,
135 bt_ctf_event_class_common_get_name(event_class
),
141 event_class
->id
= id
;
142 BT_LOGV("Set event class's ID: "
143 "addr=%p, name=\"%s\", id=%" PRId64
,
144 event_class
, bt_ctf_event_class_common_get_name(event_class
), id
);
151 int bt_ctf_event_class_common_get_log_level(
152 struct bt_ctf_event_class_common
*event_class
)
154 BT_ASSERT_PRE_NON_NULL(event_class
, "Event class");
155 return event_class
->log_level
;
159 int bt_ctf_event_class_common_set_log_level(
160 struct bt_ctf_event_class_common
*event_class
, int log_level
)
165 BT_LOGW_STR("Invalid parameter: event class is NULL.");
170 if (event_class
->frozen
) {
171 BT_LOGW("Invalid parameter: event class is frozen: "
172 "addr=%p, name=\"%s\", id=%" PRId64
,
174 bt_ctf_event_class_common_get_name(event_class
),
175 bt_ctf_event_class_common_get_id(event_class
));
181 case BT_CTF_EVENT_CLASS_LOG_LEVEL_UNSPECIFIED
:
182 case BT_CTF_EVENT_CLASS_LOG_LEVEL_EMERGENCY
:
183 case BT_CTF_EVENT_CLASS_LOG_LEVEL_ALERT
:
184 case BT_CTF_EVENT_CLASS_LOG_LEVEL_CRITICAL
:
185 case BT_CTF_EVENT_CLASS_LOG_LEVEL_ERROR
:
186 case BT_CTF_EVENT_CLASS_LOG_LEVEL_WARNING
:
187 case BT_CTF_EVENT_CLASS_LOG_LEVEL_NOTICE
:
188 case BT_CTF_EVENT_CLASS_LOG_LEVEL_INFO
:
189 case BT_CTF_EVENT_CLASS_LOG_LEVEL_DEBUG_SYSTEM
:
190 case BT_CTF_EVENT_CLASS_LOG_LEVEL_DEBUG_PROGRAM
:
191 case BT_CTF_EVENT_CLASS_LOG_LEVEL_DEBUG_PROCESS
:
192 case BT_CTF_EVENT_CLASS_LOG_LEVEL_DEBUG_MODULE
:
193 case BT_CTF_EVENT_CLASS_LOG_LEVEL_DEBUG_UNIT
:
194 case BT_CTF_EVENT_CLASS_LOG_LEVEL_DEBUG_FUNCTION
:
195 case BT_CTF_EVENT_CLASS_LOG_LEVEL_DEBUG_LINE
:
196 case BT_CTF_EVENT_CLASS_LOG_LEVEL_DEBUG
:
199 BT_LOGW("Invalid parameter: unknown event class log level: "
200 "addr=%p, name=\"%s\", id=%" PRId64
", log-level=%d",
201 event_class
, bt_ctf_event_class_common_get_name(event_class
),
202 bt_ctf_event_class_common_get_id(event_class
), log_level
);
207 event_class
->log_level
= log_level
;
208 BT_LOGV("Set event class's log level: "
209 "addr=%p, name=\"%s\", id=%" PRId64
", log-level=%s",
210 event_class
, bt_ctf_event_class_common_get_name(event_class
),
211 bt_ctf_event_class_common_get_id(event_class
),
212 bt_ctf_event_class_log_level_string(log_level
));
219 const char *bt_ctf_event_class_common_get_emf_uri(
220 struct bt_ctf_event_class_common
*event_class
)
222 const char *emf_uri
= NULL
;
224 BT_ASSERT_PRE_NON_NULL(event_class
, "Event class");
226 if (event_class
->emf_uri
->len
> 0) {
227 emf_uri
= event_class
->emf_uri
->str
;
234 int bt_ctf_event_class_common_set_emf_uri(
235 struct bt_ctf_event_class_common
*event_class
,
241 BT_LOGW_STR("Invalid parameter: event class is NULL.");
246 if (emf_uri
&& strlen(emf_uri
) == 0) {
247 BT_LOGW_STR("Invalid parameter: EMF URI is empty.");
252 if (event_class
->frozen
) {
253 BT_LOGW("Invalid parameter: event class is frozen: "
254 "addr=%p, name=\"%s\", id=%" PRId64
,
255 event_class
, bt_ctf_event_class_common_get_name(event_class
),
256 bt_ctf_event_class_common_get_id(event_class
));
262 g_string_assign(event_class
->emf_uri
, emf_uri
);
263 BT_LOGV("Set event class's EMF URI: "
264 "addr=%p, name=\"%s\", id=%" PRId64
", emf-uri=\"%s\"",
265 event_class
, bt_ctf_event_class_common_get_name(event_class
),
266 bt_ctf_event_class_common_get_id(event_class
), emf_uri
);
268 g_string_assign(event_class
->emf_uri
, "");
269 BT_LOGV("Reset event class's EMF URI: "
270 "addr=%p, name=\"%s\", id=%" PRId64
,
271 event_class
, bt_ctf_event_class_common_get_name(event_class
),
272 bt_ctf_event_class_common_get_id(event_class
));
280 struct bt_ctf_field_type_common
*bt_ctf_event_class_common_borrow_context_field_type(
281 struct bt_ctf_event_class_common
*event_class
)
283 struct bt_ctf_field_type_common
*context_ft
= NULL
;
285 BT_ASSERT_PRE_NON_NULL(event_class
, "Event class");
287 if (!event_class
->context_field_type
) {
288 BT_LOGV("Event class has no context field type: "
289 "addr=%p, name=\"%s\", id=%" PRId64
,
290 event_class
, bt_ctf_event_class_common_get_name(event_class
),
291 bt_ctf_event_class_common_get_id(event_class
));
295 context_ft
= event_class
->context_field_type
;
302 int bt_ctf_event_class_common_set_context_field_type(
303 struct bt_ctf_event_class_common
*event_class
,
304 struct bt_ctf_field_type_common
*context_ft
)
309 BT_LOGW_STR("Invalid parameter: event class is NULL.");
314 if (event_class
->frozen
) {
315 BT_LOGW("Invalid parameter: event class is frozen: "
316 "addr=%p, name=\"%s\", id=%" PRId64
,
317 event_class
, bt_ctf_event_class_common_get_name(event_class
),
318 bt_ctf_event_class_common_get_id(event_class
));
323 if (context_ft
&& bt_ctf_field_type_common_get_type_id(context_ft
) !=
324 BT_CTF_FIELD_TYPE_ID_STRUCT
) {
325 BT_LOGW("Invalid parameter: event class's context field type must be a structure: "
326 "addr=%p, name=\"%s\", id=%" PRId64
", "
328 event_class
, bt_ctf_event_class_common_get_name(event_class
),
329 bt_ctf_event_class_common_get_id(event_class
),
330 bt_ctf_field_type_id_string(
331 bt_ctf_field_type_common_get_type_id(context_ft
)));
336 bt_ctf_object_put_ref(event_class
->context_field_type
);
337 event_class
->context_field_type
= context_ft
;
338 bt_ctf_object_get_ref(event_class
->context_field_type
);
339 BT_LOGV("Set event class's context field type: "
340 "event-class-addr=%p, event-class-name=\"%s\", "
341 "event-class-id=%" PRId64
", context-ft-addr=%p",
342 event_class
, bt_ctf_event_class_common_get_name(event_class
),
343 bt_ctf_event_class_common_get_id(event_class
), context_ft
);
350 struct bt_ctf_field_type_common
*bt_ctf_event_class_common_borrow_payload_field_type(
351 struct bt_ctf_event_class_common
*event_class
)
353 BT_ASSERT_PRE_NON_NULL(event_class
, "Event class");
354 return event_class
->payload_field_type
;
358 int bt_ctf_event_class_common_set_payload_field_type(
359 struct bt_ctf_event_class_common
*event_class
,
360 struct bt_ctf_field_type_common
*payload_ft
)
365 BT_LOGW_STR("Invalid parameter: event class is NULL.");
370 if (payload_ft
&& bt_ctf_field_type_common_get_type_id(payload_ft
) !=
371 BT_CTF_FIELD_TYPE_ID_STRUCT
) {
372 BT_LOGW("Invalid parameter: event class's payload field type must be a structure: "
373 "addr=%p, name=\"%s\", id=%" PRId64
", "
374 "payload-ft-addr=%p, payload-ft-id=%s",
375 event_class
, bt_ctf_event_class_common_get_name(event_class
),
376 bt_ctf_event_class_common_get_id(event_class
), payload_ft
,
377 bt_ctf_field_type_id_string(
378 bt_ctf_field_type_common_get_type_id(payload_ft
)));
383 bt_ctf_object_put_ref(event_class
->payload_field_type
);
384 event_class
->payload_field_type
= payload_ft
;
385 bt_ctf_object_get_ref(event_class
->payload_field_type
);
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 */