Commit | Line | Data |
---|---|---|
272df73e | 1 | /* |
e2f7325d | 2 | * Copyright 2017-2018 Philippe Proulx <pproulx@efficios.com> |
272df73e PP |
3 | * Copyright 2013, 2014 Jérémie Galarneau <jeremie.galarneau@efficios.com> |
4 | * | |
272df73e PP |
5 | * Permission is hereby granted, free of charge, to any person obtaining a copy |
6 | * of this software and associated documentation files (the "Software"), to deal | |
7 | * in the Software without restriction, including without limitation the rights | |
8 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | |
9 | * copies of the Software, and to permit persons to whom the Software is | |
10 | * furnished to do so, subject to the following conditions: | |
11 | * | |
12 | * The above copyright notice and this permission notice shall be included in | |
13 | * all copies or substantial portions of the Software. | |
14 | * | |
15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | |
16 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | |
17 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | |
18 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | |
19 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | |
20 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | |
21 | * SOFTWARE. | |
22 | */ | |
23 | ||
350ad6c1 | 24 | #define BT_LOG_TAG "LIB/EVENT-CLASS" |
c2d9d9cf | 25 | #include "lib/logging.h" |
f8b979f9 | 26 | |
578e048b | 27 | #include "lib/assert-pre.h" |
3fadfbc0 | 28 | #include <babeltrace2/trace-ir/field-class.h> |
3fadfbc0 MJ |
29 | #include <babeltrace2/trace-ir/event-class.h> |
30 | #include <babeltrace2/trace-ir/event-class-const.h> | |
3fadfbc0 | 31 | #include <babeltrace2/trace-ir/stream-class.h> |
578e048b MJ |
32 | #include "compat/compiler.h" |
33 | #include "compat/endian.h" | |
3fadfbc0 | 34 | #include <babeltrace2/types.h> |
578e048b MJ |
35 | #include "lib/value.h" |
36 | #include "common/assert.h" | |
dc3fffef | 37 | #include <inttypes.h> |
c4f23e30 | 38 | #include <stdbool.h> |
0fbb9a9f | 39 | #include <stdlib.h> |
272df73e | 40 | |
578e048b MJ |
41 | #include "attributes.h" |
42 | #include "clock-snapshot.h" | |
43 | #include "event-class.h" | |
44 | #include "event.h" | |
45 | #include "field-class.h" | |
46 | #include "field.h" | |
47 | #include "resolve-field-path.h" | |
48 | #include "stream-class.h" | |
49 | #include "trace.h" | |
50 | #include "utils.h" | |
d24d5663 | 51 | #include "lib/func-status.h" |
578e048b | 52 | |
bdb288b3 PP |
53 | #define BT_ASSERT_PRE_DEV_EVENT_CLASS_HOT(_ec) \ |
54 | BT_ASSERT_PRE_DEV_HOT(((const struct bt_event_class *) (_ec)), \ | |
e5be10ef | 55 | "Event class", ": %!+E", (_ec)) |
44c440bc PP |
56 | |
57 | static | |
58 | void destroy_event_class(struct bt_object *obj) | |
272df73e | 59 | { |
44c440bc | 60 | struct bt_event_class *event_class = (void *) obj; |
272df73e | 61 | |
44c440bc | 62 | BT_LIB_LOGD("Destroying event class: %!+E", event_class); |
c6962c96 | 63 | BT_OBJECT_PUT_REF_AND_RESET(event_class->user_attributes); |
f8b979f9 | 64 | |
44c440bc PP |
65 | if (event_class->name.str) { |
66 | g_string_free(event_class->name.str, TRUE); | |
238b7404 | 67 | event_class->name.str = NULL; |
cf76ce92 PP |
68 | } |
69 | ||
44c440bc PP |
70 | if (event_class->emf_uri.str) { |
71 | g_string_free(event_class->emf_uri.str, TRUE); | |
238b7404 | 72 | event_class->emf_uri.str = NULL; |
272df73e PP |
73 | } |
74 | ||
e6276565 | 75 | BT_LOGD_STR("Putting context field class."); |
238b7404 | 76 | BT_OBJECT_PUT_REF_AND_RESET(event_class->specific_context_fc); |
e6276565 | 77 | BT_LOGD_STR("Putting payload field class."); |
238b7404 | 78 | BT_OBJECT_PUT_REF_AND_RESET(event_class->payload_fc); |
312c056a | 79 | bt_object_pool_finalize(&event_class->event_pool); |
3dca2276 | 80 | g_free(obj); |
272df73e PP |
81 | } |
82 | ||
312c056a PP |
83 | static |
84 | void free_event(struct bt_event *event, | |
85 | struct bt_event_class *event_class) | |
86 | { | |
87 | bt_event_destroy(event); | |
88 | } | |
89 | ||
44c440bc | 90 | static |
40f4ba76 PP |
91 | bool event_class_id_is_unique(const struct bt_stream_class *stream_class, |
92 | uint64_t id) | |
272df73e | 93 | { |
44c440bc PP |
94 | uint64_t i; |
95 | bool is_unique = true; | |
272df73e | 96 | |
44c440bc | 97 | for (i = 0; i < stream_class->event_classes->len; i++) { |
40f4ba76 | 98 | const struct bt_event_class *ec = |
44c440bc PP |
99 | stream_class->event_classes->pdata[i]; |
100 | ||
101 | if (ec->id == id) { | |
102 | is_unique = false; | |
103 | goto end; | |
104 | } | |
cf76ce92 | 105 | } |
272df73e | 106 | |
44c440bc PP |
107 | end: |
108 | return is_unique; | |
109 | } | |
110 | ||
111 | static | |
112 | struct bt_event_class *create_event_class_with_id( | |
113 | struct bt_stream_class *stream_class, uint64_t id) | |
114 | { | |
115 | int ret; | |
116 | struct bt_event_class *event_class; | |
117 | ||
118 | BT_ASSERT(stream_class); | |
119 | BT_ASSERT_PRE(event_class_id_is_unique(stream_class, id), | |
120 | "Duplicate event class ID: %![sc-]+S, id=%" PRIu64, | |
121 | stream_class, id); | |
122 | BT_LIB_LOGD("Creating event class object: %![sc-]+S, id=%" PRIu64, | |
123 | stream_class, id); | |
3dca2276 | 124 | event_class = g_new0(struct bt_event_class, 1); |
272df73e | 125 | if (!event_class) { |
870631a2 | 126 | BT_LIB_LOGE_APPEND_CAUSE("Failed to allocate one event class."); |
3dca2276 | 127 | goto error; |
272df73e PP |
128 | } |
129 | ||
44c440bc PP |
130 | bt_object_init_shared_with_parent(&event_class->base, |
131 | destroy_event_class); | |
c6962c96 PP |
132 | event_class->user_attributes = bt_value_map_create(); |
133 | if (!event_class->user_attributes) { | |
134 | BT_LIB_LOGE_APPEND_CAUSE( | |
135 | "Failed to create a map value object."); | |
136 | goto error; | |
137 | } | |
138 | ||
44c440bc PP |
139 | event_class->id = id; |
140 | bt_property_uint_init(&event_class->log_level, | |
141 | BT_PROPERTY_AVAILABILITY_NOT_AVAILABLE, 0); | |
142 | event_class->name.str = g_string_new(NULL); | |
143 | if (!event_class->name.str) { | |
870631a2 | 144 | BT_LIB_LOGE_APPEND_CAUSE("Failed to allocate a GString."); |
c6962c96 | 145 | goto error; |
44c440bc PP |
146 | } |
147 | ||
148 | event_class->emf_uri.str = g_string_new(NULL); | |
149 | if (!event_class->emf_uri.str) { | |
870631a2 | 150 | BT_LIB_LOGE_APPEND_CAUSE("Failed to allocate a GString."); |
c6962c96 | 151 | goto error; |
272df73e PP |
152 | } |
153 | ||
312c056a PP |
154 | ret = bt_object_pool_initialize(&event_class->event_pool, |
155 | (bt_object_pool_new_object_func) bt_event_new, | |
156 | (bt_object_pool_destroy_object_func) free_event, | |
157 | event_class); | |
158 | if (ret) { | |
870631a2 PP |
159 | BT_LIB_LOGE_APPEND_CAUSE( |
160 | "Failed to initialize event pool: ret=%d", | |
312c056a PP |
161 | ret); |
162 | goto error; | |
163 | } | |
164 | ||
44c440bc PP |
165 | bt_object_set_parent(&event_class->base, &stream_class->base); |
166 | g_ptr_array_add(stream_class->event_classes, event_class); | |
167 | bt_stream_class_freeze(stream_class); | |
168 | BT_LIB_LOGD("Created event class object: %!+E", event_class); | |
3dca2276 | 169 | goto end; |
272df73e | 170 | |
3dca2276 | 171 | error: |
65300d60 | 172 | BT_OBJECT_PUT_REF_AND_RESET(event_class); |
272df73e PP |
173 | |
174 | end: | |
3dca2276 | 175 | return event_class; |
272df73e PP |
176 | } |
177 | ||
40f4ba76 PP |
178 | struct bt_event_class *bt_event_class_create( |
179 | struct bt_stream_class *stream_class) | |
44c440bc | 180 | { |
17f3083a | 181 | BT_ASSERT_PRE_NO_ERROR(); |
44c440bc PP |
182 | BT_ASSERT_PRE_NON_NULL(stream_class, "Stream class"); |
183 | BT_ASSERT_PRE(stream_class->assigns_automatic_event_class_id, | |
184 | "Stream class does not automatically assigns event class IDs: " | |
185 | "%![sc-]+S", stream_class); | |
40f4ba76 | 186 | return create_event_class_with_id(stream_class, |
44c440bc PP |
187 | (uint64_t) stream_class->event_classes->len); |
188 | } | |
189 | ||
40f4ba76 PP |
190 | struct bt_event_class *bt_event_class_create_with_id( |
191 | struct bt_stream_class *stream_class, uint64_t id) | |
44c440bc | 192 | { |
17f3083a | 193 | BT_ASSERT_PRE_NO_ERROR(); |
44c440bc PP |
194 | BT_ASSERT_PRE(!stream_class->assigns_automatic_event_class_id, |
195 | "Stream class automatically assigns event class IDs: " | |
196 | "%![sc-]+S", stream_class); | |
40f4ba76 | 197 | return create_event_class_with_id(stream_class, id); |
44c440bc PP |
198 | } |
199 | ||
40f4ba76 | 200 | const char *bt_event_class_get_name(const struct bt_event_class *event_class) |
272df73e | 201 | { |
bdb288b3 | 202 | BT_ASSERT_PRE_DEV_NON_NULL(event_class, "Event class"); |
44c440bc | 203 | return event_class->name.value; |
272df73e PP |
204 | } |
205 | ||
d24d5663 | 206 | enum bt_event_class_set_name_status bt_event_class_set_name( |
d08300f5 | 207 | struct bt_event_class *event_class, const char *name) |
272df73e | 208 | { |
17f3083a | 209 | BT_ASSERT_PRE_NO_ERROR(); |
cb6f1f7d | 210 | BT_ASSERT_PRE_NON_NULL(event_class, "Event class"); |
44c440bc | 211 | BT_ASSERT_PRE_NON_NULL(name, "Name"); |
bdb288b3 | 212 | BT_ASSERT_PRE_DEV_EVENT_CLASS_HOT(event_class); |
44c440bc PP |
213 | g_string_assign(event_class->name.str, name); |
214 | event_class->name.value = event_class->name.str->str; | |
3f7d4d90 | 215 | BT_LIB_LOGD("Set event class's name: %!+E", event_class); |
d24d5663 | 216 | return BT_FUNC_STATUS_OK; |
272df73e PP |
217 | } |
218 | ||
40f4ba76 | 219 | uint64_t bt_event_class_get_id(const struct bt_event_class *event_class) |
272df73e | 220 | { |
bdb288b3 | 221 | BT_ASSERT_PRE_DEV_NON_NULL(event_class, "Event class"); |
44c440bc | 222 | return event_class->id; |
272df73e PP |
223 | } |
224 | ||
44c440bc | 225 | enum bt_property_availability bt_event_class_get_log_level( |
40f4ba76 | 226 | const struct bt_event_class *event_class, |
44c440bc | 227 | enum bt_event_class_log_level *log_level) |
272df73e | 228 | { |
bdb288b3 PP |
229 | BT_ASSERT_PRE_DEV_NON_NULL(event_class, "Event class"); |
230 | BT_ASSERT_PRE_DEV_NON_NULL(log_level, "Log level (output)"); | |
44c440bc PP |
231 | *log_level = (enum bt_event_class_log_level) |
232 | event_class->log_level.value; | |
233 | return event_class->log_level.base.avail; | |
272df73e PP |
234 | } |
235 | ||
40f4ba76 PP |
236 | void bt_event_class_set_log_level( |
237 | struct bt_event_class *event_class, | |
3dca2276 | 238 | enum bt_event_class_log_level log_level) |
272df73e | 239 | { |
44c440bc | 240 | BT_ASSERT_PRE_NON_NULL(event_class, "Event class"); |
bdb288b3 | 241 | BT_ASSERT_PRE_DEV_EVENT_CLASS_HOT(event_class); |
44c440bc PP |
242 | bt_property_uint_set(&event_class->log_level, |
243 | (uint64_t) log_level); | |
3f7d4d90 | 244 | BT_LIB_LOGD("Set event class's log level: %!+E", event_class); |
272df73e PP |
245 | } |
246 | ||
40f4ba76 | 247 | const char *bt_event_class_get_emf_uri(const struct bt_event_class *event_class) |
272df73e | 248 | { |
bdb288b3 | 249 | BT_ASSERT_PRE_DEV_NON_NULL(event_class, "Event class"); |
44c440bc | 250 | return event_class->emf_uri.value; |
272df73e PP |
251 | } |
252 | ||
d24d5663 | 253 | enum bt_event_class_set_emf_uri_status bt_event_class_set_emf_uri( |
40f4ba76 | 254 | struct bt_event_class *event_class, |
3dca2276 | 255 | const char *emf_uri) |
272df73e | 256 | { |
17f3083a | 257 | BT_ASSERT_PRE_NO_ERROR(); |
44c440bc PP |
258 | BT_ASSERT_PRE_NON_NULL(event_class, "Event class"); |
259 | BT_ASSERT_PRE_NON_NULL(emf_uri, "EMF URI"); | |
bdb288b3 | 260 | BT_ASSERT_PRE_DEV_EVENT_CLASS_HOT(event_class); |
44c440bc PP |
261 | g_string_assign(event_class->emf_uri.str, emf_uri); |
262 | event_class->emf_uri.value = event_class->emf_uri.str->str; | |
3f7d4d90 | 263 | BT_LIB_LOGD("Set event class's EMF URI: %!+E", event_class); |
d24d5663 | 264 | return BT_FUNC_STATUS_OK; |
272df73e PP |
265 | } |
266 | ||
094ff7c0 | 267 | struct bt_stream_class *bt_event_class_borrow_stream_class( |
50842bdc | 268 | struct bt_event_class *event_class) |
272df73e | 269 | { |
bdb288b3 | 270 | BT_ASSERT_PRE_DEV_NON_NULL(event_class, "Event class"); |
44c440bc | 271 | return bt_event_class_borrow_stream_class_inline(event_class); |
272df73e PP |
272 | } |
273 | ||
40f4ba76 PP |
274 | const struct bt_stream_class * |
275 | bt_event_class_borrow_stream_class_const( | |
276 | const struct bt_event_class *event_class) | |
e5be10ef | 277 | { |
40f4ba76 | 278 | return bt_event_class_borrow_stream_class((void *) event_class); |
e5be10ef PP |
279 | } |
280 | ||
40f4ba76 PP |
281 | const struct bt_field_class * |
282 | bt_event_class_borrow_specific_context_field_class_const( | |
283 | const struct bt_event_class *event_class) | |
272df73e | 284 | { |
bdb288b3 | 285 | BT_ASSERT_PRE_DEV_NON_NULL(event_class, "Event class"); |
5cd6d0e5 | 286 | return event_class->specific_context_fc; |
272df73e PP |
287 | } |
288 | ||
740faaf4 PP |
289 | struct bt_field_class * |
290 | bt_event_class_borrow_specific_context_field_class( | |
291 | struct bt_event_class *event_class) | |
292 | { | |
bdb288b3 | 293 | BT_ASSERT_PRE_DEV_NON_NULL(event_class, "Event class"); |
740faaf4 PP |
294 | return event_class->specific_context_fc; |
295 | } | |
296 | ||
d24d5663 PP |
297 | enum bt_event_class_set_field_class_status |
298 | bt_event_class_set_specific_context_field_class( | |
40f4ba76 PP |
299 | struct bt_event_class *event_class, |
300 | struct bt_field_class *field_class) | |
272df73e | 301 | { |
44c440bc PP |
302 | int ret; |
303 | struct bt_stream_class *stream_class; | |
44c440bc | 304 | struct bt_resolve_field_path_context resolve_ctx = { |
44c440bc | 305 | .packet_context = NULL, |
44c440bc | 306 | .event_common_context = NULL, |
5cd6d0e5 | 307 | .event_specific_context = field_class, |
44c440bc PP |
308 | .event_payload = NULL, |
309 | }; | |
cb6f1f7d | 310 | |
17f3083a | 311 | BT_ASSERT_PRE_NO_ERROR(); |
44c440bc | 312 | BT_ASSERT_PRE_NON_NULL(event_class, "Event class"); |
5cd6d0e5 | 313 | BT_ASSERT_PRE_NON_NULL(field_class, "Field class"); |
bdb288b3 | 314 | BT_ASSERT_PRE_DEV_EVENT_CLASS_HOT(event_class); |
864cad70 PP |
315 | BT_ASSERT_PRE(bt_field_class_get_type(field_class) == |
316 | BT_FIELD_CLASS_TYPE_STRUCTURE, | |
e6276565 | 317 | "Specific context field class is not a structure field class: " |
5cd6d0e5 | 318 | "%!+F", field_class); |
44c440bc PP |
319 | stream_class = bt_event_class_borrow_stream_class_inline( |
320 | event_class); | |
5cd6d0e5 | 321 | resolve_ctx.packet_context = stream_class->packet_context_fc; |
44c440bc | 322 | resolve_ctx.event_common_context = |
5cd6d0e5 | 323 | stream_class->event_common_context_fc; |
44c440bc | 324 | |
5cd6d0e5 | 325 | ret = bt_resolve_field_paths(field_class, &resolve_ctx); |
44c440bc | 326 | if (ret) { |
d08300f5 PP |
327 | /* |
328 | * This is the only reason for which | |
329 | * bt_resolve_field_paths() can fail: anything else | |
330 | * would be because a precondition is not satisfied. | |
331 | */ | |
d24d5663 | 332 | ret = BT_FUNC_STATUS_MEMORY_ERROR; |
cb6f1f7d PP |
333 | goto end; |
334 | } | |
335 | ||
862ca4ed | 336 | bt_field_class_make_part_of_trace_class(field_class); |
65300d60 | 337 | bt_object_put_ref(event_class->specific_context_fc); |
398454ed | 338 | event_class->specific_context_fc = field_class; |
6871026b | 339 | bt_object_get_ref_no_null_check(event_class->specific_context_fc); |
5cd6d0e5 | 340 | bt_field_class_freeze(field_class); |
3f7d4d90 | 341 | BT_LIB_LOGD("Set event class's specific context field class: %!+E", |
44c440bc | 342 | event_class); |
cb6f1f7d | 343 | |
cb6f1f7d PP |
344 | end: |
345 | return ret; | |
272df73e PP |
346 | } |
347 | ||
40f4ba76 PP |
348 | const struct bt_field_class *bt_event_class_borrow_payload_field_class_const( |
349 | const struct bt_event_class *event_class) | |
272df73e | 350 | { |
bdb288b3 | 351 | BT_ASSERT_PRE_DEV_NON_NULL(event_class, "Event class"); |
5cd6d0e5 | 352 | return event_class->payload_fc; |
272df73e PP |
353 | } |
354 | ||
740faaf4 PP |
355 | struct bt_field_class *bt_event_class_borrow_payload_field_class( |
356 | struct bt_event_class *event_class) | |
357 | { | |
bdb288b3 | 358 | BT_ASSERT_PRE_DEV_NON_NULL(event_class, "Event class"); |
740faaf4 PP |
359 | return event_class->payload_fc; |
360 | } | |
361 | ||
d24d5663 PP |
362 | enum bt_event_class_set_field_class_status |
363 | bt_event_class_set_payload_field_class( | |
40f4ba76 PP |
364 | struct bt_event_class *event_class, |
365 | struct bt_field_class *field_class) | |
272df73e | 366 | { |
44c440bc PP |
367 | int ret; |
368 | struct bt_stream_class *stream_class; | |
44c440bc | 369 | struct bt_resolve_field_path_context resolve_ctx = { |
44c440bc | 370 | .packet_context = NULL, |
44c440bc PP |
371 | .event_common_context = NULL, |
372 | .event_specific_context = NULL, | |
5cd6d0e5 | 373 | .event_payload = field_class, |
44c440bc | 374 | }; |
cb6f1f7d | 375 | |
17f3083a | 376 | BT_ASSERT_PRE_NO_ERROR(); |
44c440bc | 377 | BT_ASSERT_PRE_NON_NULL(event_class, "Event class"); |
5cd6d0e5 | 378 | BT_ASSERT_PRE_NON_NULL(field_class, "Field class"); |
bdb288b3 | 379 | BT_ASSERT_PRE_DEV_EVENT_CLASS_HOT(event_class); |
864cad70 PP |
380 | BT_ASSERT_PRE(bt_field_class_get_type(field_class) == |
381 | BT_FIELD_CLASS_TYPE_STRUCTURE, | |
e6276565 | 382 | "Payload field class is not a structure field class: %!+F", |
5cd6d0e5 | 383 | field_class); |
44c440bc PP |
384 | stream_class = bt_event_class_borrow_stream_class_inline( |
385 | event_class); | |
5cd6d0e5 | 386 | resolve_ctx.packet_context = stream_class->packet_context_fc; |
44c440bc | 387 | resolve_ctx.event_common_context = |
5cd6d0e5 PP |
388 | stream_class->event_common_context_fc; |
389 | resolve_ctx.event_specific_context = event_class->specific_context_fc; | |
44c440bc | 390 | |
5cd6d0e5 | 391 | ret = bt_resolve_field_paths(field_class, &resolve_ctx); |
44c440bc | 392 | if (ret) { |
d08300f5 PP |
393 | /* |
394 | * This is the only reason for which | |
395 | * bt_resolve_field_paths() can fail: anything else | |
396 | * would be because a precondition is not satisfied. | |
397 | */ | |
d24d5663 | 398 | ret = BT_FUNC_STATUS_MEMORY_ERROR; |
cb6f1f7d PP |
399 | goto end; |
400 | } | |
401 | ||
862ca4ed | 402 | bt_field_class_make_part_of_trace_class(field_class); |
65300d60 | 403 | bt_object_put_ref(event_class->payload_fc); |
398454ed | 404 | event_class->payload_fc = field_class; |
6871026b | 405 | bt_object_get_ref_no_null_check(event_class->payload_fc); |
5cd6d0e5 | 406 | bt_field_class_freeze(field_class); |
3f7d4d90 | 407 | BT_LIB_LOGD("Set event class's payload field class: %!+E", event_class); |
cb6f1f7d PP |
408 | |
409 | end: | |
410 | return ret; | |
272df73e PP |
411 | } |
412 | ||
413 | BT_HIDDEN | |
40f4ba76 | 414 | void _bt_event_class_freeze(const struct bt_event_class *event_class) |
2a3ced3c | 415 | { |
5cd6d0e5 | 416 | /* The field classes are already frozen */ |
f6ccaed9 | 417 | BT_ASSERT(event_class); |
c6962c96 PP |
418 | BT_LIB_LOGD("Freezing event class's user attributes: %!+v", |
419 | event_class->user_attributes); | |
420 | bt_value_freeze(event_class->user_attributes); | |
44c440bc | 421 | BT_LIB_LOGD("Freezing event class: %!+E", event_class); |
40f4ba76 | 422 | ((struct bt_event_class *) event_class)->frozen = true; |
2a3ced3c | 423 | } |
c5b9b441 | 424 | |
c6962c96 PP |
425 | const struct bt_value *bt_event_class_borrow_user_attributes_const( |
426 | const struct bt_event_class *event_class) | |
427 | { | |
428 | BT_ASSERT_PRE_DEV_NON_NULL(event_class, "Event class"); | |
429 | return event_class->user_attributes; | |
430 | } | |
431 | ||
432 | struct bt_value *bt_event_class_borrow_user_attributes( | |
433 | struct bt_event_class *event_class) | |
434 | { | |
435 | return (void *) bt_event_class_borrow_user_attributes_const( | |
436 | (void *) event_class); | |
437 | } | |
438 | ||
439 | void bt_event_class_set_user_attributes( | |
440 | struct bt_event_class *event_class, | |
441 | const struct bt_value *user_attributes) | |
442 | { | |
443 | BT_ASSERT_PRE_NON_NULL(event_class, "Event class"); | |
444 | BT_ASSERT_PRE_NON_NULL(user_attributes, "User attributes"); | |
445 | BT_ASSERT_PRE(user_attributes->type == BT_VALUE_TYPE_MAP, | |
446 | "User attributes object is not a map value object."); | |
447 | BT_ASSERT_PRE_DEV_EVENT_CLASS_HOT(event_class); | |
6871026b | 448 | bt_object_put_ref_no_null_check(event_class->user_attributes); |
c6962c96 | 449 | event_class->user_attributes = (void *) user_attributes; |
6871026b | 450 | bt_object_get_ref_no_null_check(event_class->user_attributes); |
c6962c96 PP |
451 | } |
452 | ||
c5b9b441 PP |
453 | void bt_event_class_get_ref(const struct bt_event_class *event_class) |
454 | { | |
455 | bt_object_get_ref(event_class); | |
456 | } | |
457 | ||
458 | void bt_event_class_put_ref(const struct bt_event_class *event_class) | |
459 | { | |
460 | bt_object_put_ref(event_class); | |
461 | } |