lib: rename `bt_object_{get,put}_no` -> `bt_object_{get,put}_ref_no`
[babeltrace.git] / src / lib / trace-ir / trace.c
CommitLineData
bc37ae52 1/*
e2f7325d 2 * Copyright 2017-2018 Philippe Proulx <pproulx@efficios.com>
bc37ae52
JG
3 * Copyright 2014 Jérémie Galarneau <jeremie.galarneau@efficios.com>
4 *
bc37ae52
JG
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/TRACE"
c2d9d9cf 25#include "lib/logging.h"
e011d2c1 26
578e048b 27#include "lib/assert-pre.h"
3fadfbc0 28#include <babeltrace2/trace-ir/trace.h>
3fadfbc0 29#include <babeltrace2/trace-ir/trace-const.h>
3fadfbc0 30#include <babeltrace2/trace-ir/event-class.h>
578e048b
MJ
31#include "ctf-writer/functor.h"
32#include "ctf-writer/clock.h"
33#include "compat/compiler.h"
3fadfbc0
MJ
34#include <babeltrace2/value.h>
35#include <babeltrace2/value-const.h>
578e048b 36#include "lib/value.h"
3fadfbc0 37#include <babeltrace2/types.h>
578e048b
MJ
38#include "compat/endian.h"
39#include "common/assert.h"
40#include "compat/glib.h"
dc3fffef 41#include <inttypes.h>
544d0515 42#include <stdint.h>
4a32fda0 43#include <string.h>
0fbb9a9f 44#include <stdlib.h>
bc37ae52 45
578e048b
MJ
46#include "attributes.h"
47#include "clock-class.h"
48#include "event-class.h"
49#include "event.h"
50#include "field-class.h"
51#include "field-wrapper.h"
52#include "resolve-field-path.h"
53#include "stream-class.h"
54#include "stream.h"
55#include "trace-class.h"
56#include "trace.h"
57#include "utils.h"
c6962c96 58#include "lib/value.h"
d24d5663 59#include "lib/func-status.h"
578e048b 60
ad5268b5
FD
61struct bt_trace_destruction_listener_elem {
62 bt_trace_destruction_listener_func func;
3602afb0
PP
63 void *data;
64};
65
bdb288b3
PP
66#define BT_ASSERT_PRE_DEV_TRACE_HOT(_trace) \
67 BT_ASSERT_PRE_DEV_HOT((_trace), "Trace", ": %!+t", (_trace))
cb6f1f7d 68
bc37ae52 69static
44c440bc 70void destroy_trace(struct bt_object *obj)
3dca2276
PP
71{
72 struct bt_trace *trace = (void *) obj;
bc37ae52 73
44c440bc 74 BT_LIB_LOGD("Destroying trace object: %!+t", trace);
c6962c96 75 BT_OBJECT_PUT_REF_AND_RESET(trace->user_attributes);
bc37ae52 76
3dca2276 77 /*
ad5268b5
FD
78 * Call destruction listener functions so that everything else
79 * still exists in the trace.
3dca2276 80 */
ad5268b5
FD
81 if (trace->destruction_listeners) {
82 uint64_t i;
3f7d4d90 83 BT_LIB_LOGD("Calling trace destruction listener(s): %!+t", trace);
c47a6bec
SM
84
85 /*
86 * The trace's reference count is 0 if we're here. Increment
87 * it to avoid a double-destroy (possibly infinitely recursive).
88 * This could happen for example if a destruction listener did
89 * bt_object_get_ref() (or anything that causes
90 * bt_object_get_ref() to be called) on the trace (ref.
91 * count goes from 0 to 1), and then bt_object_put_ref(): the
92 * reference count would go from 1 to 0 again and this function
93 * would be called again.
94 */
95 trace->base.ref_count++;
96
ad5268b5
FD
97 /* Call all the trace destruction listeners */
98 for (i = 0; i < trace->destruction_listeners->len; i++) {
99 struct bt_trace_destruction_listener_elem elem =
100 g_array_index(trace->destruction_listeners,
101 struct bt_trace_destruction_listener_elem, i);
102
103 if (elem.func) {
104 elem.func(trace, elem.data);
3dca2276 105 }
c47a6bec
SM
106
107 /*
108 * The destruction listener should not have kept a
109 * reference to the trace.
110 */
111 BT_ASSERT_PRE(trace->base.ref_count == 1, "Destruction listener kept a reference to the trace being destroyed: %![trace-]+t", trace);
3dca2276 112 }
ad5268b5
FD
113 g_array_free(trace->destruction_listeners, TRUE);
114 trace->destruction_listeners = NULL;
bc37ae52
JG
115 }
116
44c440bc
PP
117 if (trace->name.str) {
118 g_string_free(trace->name.str, TRUE);
238b7404
PP
119 trace->name.str = NULL;
120 trace->name.value = NULL;
95c09b3a
PP
121 }
122
335a2da5
PP
123 if (trace->environment) {
124 BT_LOGD_STR("Destroying environment attributes.");
125 bt_attributes_destroy(trace->environment);
126 trace->environment = NULL;
127 }
128
44c440bc
PP
129 if (trace->streams) {
130 BT_LOGD_STR("Destroying streams.");
131 g_ptr_array_free(trace->streams, TRUE);
238b7404 132 trace->streams = NULL;
bc37ae52
JG
133 }
134
44c440bc
PP
135 if (trace->stream_classes_stream_count) {
136 g_hash_table_destroy(trace->stream_classes_stream_count);
238b7404 137 trace->stream_classes_stream_count = NULL;
44c440bc 138 }
3dca2276 139
862ca4ed
PP
140 BT_LOGD_STR("Putting trace's class.");
141 bt_object_put_ref(trace->class);
142 trace->class = NULL;
44c440bc 143 g_free(trace);
3dca2276
PP
144}
145
862ca4ed 146struct bt_trace *bt_trace_create(struct bt_trace_class *tc)
3dca2276
PP
147{
148 struct bt_trace *trace = NULL;
3dca2276 149
862ca4ed 150 BT_LIB_LOGD("Creating trace object: %![tc-]+T", tc);
3dca2276
PP
151 trace = g_new0(struct bt_trace, 1);
152 if (!trace) {
870631a2 153 BT_LIB_LOGE_APPEND_CAUSE("Failed to allocate one trace.");
3dca2276
PP
154 goto error;
155 }
156
862ca4ed 157 bt_object_init_shared(&trace->base, destroy_trace);
c6962c96
PP
158 trace->user_attributes = bt_value_map_create();
159 if (!trace->user_attributes) {
160 BT_LIB_LOGE_APPEND_CAUSE(
161 "Failed to create a map value object.");
162 goto error;
163 }
164
44c440bc
PP
165 trace->streams = g_ptr_array_new_with_free_func(
166 (GDestroyNotify) bt_object_try_spec_release);
167 if (!trace->streams) {
870631a2 168 BT_LIB_LOGE_APPEND_CAUSE("Failed to allocate one GPtrArray.");
3dca2276
PP
169 goto error;
170 }
171
44c440bc
PP
172 trace->stream_classes_stream_count = g_hash_table_new(g_direct_hash,
173 g_direct_equal);
174 if (!trace->stream_classes_stream_count) {
870631a2 175 BT_LIB_LOGE_APPEND_CAUSE("Failed to allocate one GHashTable.");
44c440bc
PP
176 goto error;
177 }
178
179 trace->name.str = g_string_new(NULL);
180 if (!trace->name.str) {
870631a2 181 BT_LIB_LOGE_APPEND_CAUSE("Failed to allocate one GString.");
44c440bc
PP
182 goto error;
183 }
184
335a2da5
PP
185 trace->environment = bt_attributes_create();
186 if (!trace->environment) {
187 BT_LIB_LOGE_APPEND_CAUSE("Cannot create empty attributes object.");
188 goto error;
189 }
190
ad5268b5
FD
191 trace->destruction_listeners = g_array_new(FALSE, TRUE,
192 sizeof(struct bt_trace_destruction_listener_elem));
193 if (!trace->destruction_listeners) {
870631a2 194 BT_LIB_LOGE_APPEND_CAUSE("Failed to allocate one GArray.");
3602afb0
PP
195 goto error;
196 }
197
862ca4ed 198 trace->class = tc;
6871026b 199 bt_object_get_ref_no_null_check(trace->class);
44c440bc
PP
200 BT_LIB_LOGD("Created trace object: %!+t", trace);
201 goto end;
bc37ae52 202
bc37ae52 203error:
65300d60 204 BT_OBJECT_PUT_REF_AND_RESET(trace);
44c440bc
PP
205
206end:
862ca4ed 207 return trace;
bc37ae52
JG
208}
209
40f4ba76 210const char *bt_trace_get_name(const struct bt_trace *trace)
e96045d4 211{
bdb288b3 212 BT_ASSERT_PRE_DEV_NON_NULL(trace, "Trace");
44c440bc 213 return trace->name.value;
e96045d4
JG
214}
215
d24d5663
PP
216enum bt_trace_set_name_status bt_trace_set_name(struct bt_trace *trace,
217 const char *name)
e96045d4 218{
44c440bc
PP
219 BT_ASSERT_PRE_NON_NULL(trace, "Trace");
220 BT_ASSERT_PRE_NON_NULL(name, "Name");
bdb288b3 221 BT_ASSERT_PRE_DEV_TRACE_HOT(trace);
44c440bc
PP
222 g_string_assign(trace->name.str, name);
223 trace->name.value = trace->name.str->str;
3f7d4d90 224 BT_LIB_LOGD("Set trace's name: %!+t", trace);
d24d5663 225 return BT_FUNC_STATUS_OK;
e96045d4
JG
226}
227
335a2da5
PP
228bt_uuid bt_trace_get_uuid(const struct bt_trace *trace)
229{
bdb288b3 230 BT_ASSERT_PRE_DEV_NON_NULL(trace, "Trace");
335a2da5
PP
231 return trace->uuid.value;
232}
233
234void bt_trace_set_uuid(struct bt_trace *trace, bt_uuid uuid)
235{
236 BT_ASSERT_PRE_NON_NULL(trace, "Trace");
237 BT_ASSERT_PRE_NON_NULL(uuid, "UUID");
bdb288b3 238 BT_ASSERT_PRE_DEV_TRACE_HOT(trace);
6162e6b7 239 bt_uuid_copy(trace->uuid.uuid, uuid);
335a2da5
PP
240 trace->uuid.value = trace->uuid.uuid;
241 BT_LIB_LOGD("Set trace's UUID: %!+t", trace);
242}
243
244BT_ASSERT_FUNC
245static
246bool trace_has_environment_entry(const struct bt_trace *trace, const char *name)
247{
248 BT_ASSERT(trace);
249
250 return bt_attributes_borrow_field_value_by_name(
5084732e 251 trace->environment, name);
335a2da5
PP
252}
253
254static
255enum bt_trace_set_environment_entry_status set_environment_entry(
256 struct bt_trace *trace,
257 const char *name, struct bt_value *value)
258{
259 int ret;
260
261 BT_ASSERT(trace);
262 BT_ASSERT(name);
263 BT_ASSERT(value);
264 BT_ASSERT_PRE(!trace->frozen ||
265 !trace_has_environment_entry(trace, name),
266 "Trace is frozen: cannot replace environment entry: "
267 "%![trace-]+t, entry-name=\"%s\"", trace, name);
268 ret = bt_attributes_set_field_value(trace->environment, name,
269 value);
270 if (ret) {
271 ret = BT_FUNC_STATUS_MEMORY_ERROR;
272 BT_LIB_LOGE_APPEND_CAUSE(
273 "Cannot set trace's environment entry: "
274 "%![trace-]+t, entry-name=\"%s\"", trace, name);
275 } else {
276 bt_value_freeze(value);
277 BT_LIB_LOGD("Set trace's environment entry: "
278 "%![trace-]+t, entry-name=\"%s\"", trace, name);
279 }
280
281 return ret;
282}
283
284enum bt_trace_set_environment_entry_status
285bt_trace_set_environment_entry_string(
286 struct bt_trace *trace, const char *name, const char *value)
287{
288 int ret;
289 struct bt_value *value_obj;
290 BT_ASSERT_PRE_NON_NULL(trace, "Trace");
291 BT_ASSERT_PRE_NON_NULL(name, "Name");
292 BT_ASSERT_PRE_NON_NULL(value, "Value");
293 value_obj = bt_value_string_create_init(value);
294 if (!value_obj) {
295 BT_LIB_LOGE_APPEND_CAUSE(
296 "Cannot create a string value object.");
297 ret = -1;
298 goto end;
299 }
300
301 /* set_environment_entry() logs errors */
302 ret = set_environment_entry(trace, name, value_obj);
303
304end:
305 bt_object_put_ref(value_obj);
306 return ret;
307}
308
309enum bt_trace_set_environment_entry_status
310bt_trace_set_environment_entry_integer(
311 struct bt_trace *trace, const char *name, int64_t value)
312{
313 int ret;
314 struct bt_value *value_obj;
315 BT_ASSERT_PRE_NON_NULL(trace, "Trace");
316 BT_ASSERT_PRE_NON_NULL(name, "Name");
9c08c816 317 value_obj = bt_value_integer_signed_create_init(value);
335a2da5
PP
318 if (!value_obj) {
319 BT_LIB_LOGE_APPEND_CAUSE(
320 "Cannot create an integer value object.");
321 ret = BT_FUNC_STATUS_MEMORY_ERROR;
322 goto end;
323 }
324
325 /* set_environment_entry() logs errors */
326 ret = set_environment_entry(trace, name, value_obj);
327
328end:
329 bt_object_put_ref(value_obj);
330 return ret;
331}
332
333uint64_t bt_trace_get_environment_entry_count(const struct bt_trace *trace)
334{
335 int64_t ret;
336
bdb288b3 337 BT_ASSERT_PRE_DEV_NON_NULL(trace, "Trace");
335a2da5
PP
338 ret = bt_attributes_get_count(trace->environment);
339 BT_ASSERT(ret >= 0);
340 return (uint64_t) ret;
341}
342
343void bt_trace_borrow_environment_entry_by_index_const(
344 const struct bt_trace *trace, uint64_t index,
345 const char **name, const struct bt_value **value)
346{
bdb288b3
PP
347 BT_ASSERT_PRE_DEV_NON_NULL(trace, "Trace");
348 BT_ASSERT_PRE_DEV_NON_NULL(name, "Name");
349 BT_ASSERT_PRE_DEV_NON_NULL(value, "Value");
350 BT_ASSERT_PRE_DEV_VALID_INDEX(index,
335a2da5
PP
351 bt_attributes_get_count(trace->environment));
352 *value = bt_attributes_borrow_field_value(trace->environment, index);
353 BT_ASSERT(*value);
354 *name = bt_attributes_get_field_name(trace->environment, index);
355 BT_ASSERT(*name);
356}
357
358const struct bt_value *bt_trace_borrow_environment_entry_value_by_name_const(
359 const struct bt_trace *trace, const char *name)
360{
bdb288b3
PP
361 BT_ASSERT_PRE_DEV_NON_NULL(trace, "Trace");
362 BT_ASSERT_PRE_DEV_NON_NULL(name, "Name");
335a2da5
PP
363 return bt_attributes_borrow_field_value_by_name(trace->environment,
364 name);
365}
366
40f4ba76 367uint64_t bt_trace_get_stream_count(const struct bt_trace *trace)
bc37ae52 368{
bdb288b3 369 BT_ASSERT_PRE_DEV_NON_NULL(trace, "Trace");
44c440bc
PP
370 return (uint64_t) trace->streams->len;
371}
95c09b3a 372
44c440bc
PP
373struct bt_stream *bt_trace_borrow_stream_by_index(
374 struct bt_trace *trace, uint64_t index)
375{
bdb288b3
PP
376 BT_ASSERT_PRE_DEV_NON_NULL(trace, "Trace");
377 BT_ASSERT_PRE_DEV_VALID_INDEX(index, trace->streams->len);
44c440bc
PP
378 return g_ptr_array_index(trace->streams, index);
379}
cb6f1f7d 380
40f4ba76
PP
381const struct bt_stream *bt_trace_borrow_stream_by_index_const(
382 const struct bt_trace *trace, uint64_t index)
e5be10ef 383{
40f4ba76 384 return bt_trace_borrow_stream_by_index((void *) trace, index);
e5be10ef
PP
385}
386
40f4ba76
PP
387struct bt_stream *bt_trace_borrow_stream_by_id(struct bt_trace *trace,
388 uint64_t id)
44c440bc
PP
389{
390 struct bt_stream *stream = NULL;
391 uint64_t i;
bc37ae52 392
bdb288b3 393 BT_ASSERT_PRE_DEV_NON_NULL(trace, "Trace");
bc37ae52 394
44c440bc
PP
395 for (i = 0; i < trace->streams->len; i++) {
396 struct bt_stream *stream_candidate =
397 g_ptr_array_index(trace->streams, i);
cfeb617e 398
44c440bc
PP
399 if (stream_candidate->id == id) {
400 stream = stream_candidate;
401 goto end;
402 }
6474e016 403 }
95c09b3a 404
bc37ae52 405end:
44c440bc 406 return stream;
bc37ae52
JG
407}
408
40f4ba76
PP
409const struct bt_stream *bt_trace_borrow_stream_by_id_const(
410 const struct bt_trace *trace, uint64_t id)
e5be10ef 411{
40f4ba76 412 return bt_trace_borrow_stream_by_id((void *) trace, id);
e5be10ef
PP
413}
414
d24d5663 415enum bt_trace_add_listener_status bt_trace_add_destruction_listener(
40f4ba76 416 const struct bt_trace *c_trace,
ad5268b5 417 bt_trace_destruction_listener_func listener,
2054a0d1 418 void *data, bt_listener_id *listener_id)
3602afb0 419{
40f4ba76 420 struct bt_trace *trace = (void *) c_trace;
44c440bc 421 uint64_t i;
ad5268b5 422 struct bt_trace_destruction_listener_elem new_elem = {
3602afb0
PP
423 .func = listener,
424 .data = data,
425 };
426
44c440bc
PP
427 BT_ASSERT_PRE_NON_NULL(trace, "Trace");
428 BT_ASSERT_PRE_NON_NULL(listener, "Listener");
8480c8cc 429
3602afb0 430 /* Find the next available spot */
ad5268b5
FD
431 for (i = 0; i < trace->destruction_listeners->len; i++) {
432 struct bt_trace_destruction_listener_elem elem =
433 g_array_index(trace->destruction_listeners,
434 struct bt_trace_destruction_listener_elem, i);
3602afb0
PP
435
436 if (!elem.func) {
437 break;
438 }
439 }
440
ad5268b5
FD
441 if (i == trace->destruction_listeners->len) {
442 g_array_append_val(trace->destruction_listeners, new_elem);
3602afb0 443 } else {
ad5268b5 444 g_array_insert_val(trace->destruction_listeners, i, new_elem);
3602afb0
PP
445 }
446
44c440bc
PP
447 if (listener_id) {
448 *listener_id = i;
449 }
3602afb0 450
3f7d4d90 451 BT_LIB_LOGD("Added destruction listener: " "%![trace-]+t, "
ad5268b5 452 "listener-id=%" PRIu64, trace, i);
d24d5663 453 return BT_FUNC_STATUS_OK;
44c440bc
PP
454}
455
44c440bc 456static
40f4ba76 457bool has_listener_id(const struct bt_trace *trace, uint64_t listener_id)
44c440bc 458{
ad5268b5
FD
459 BT_ASSERT(listener_id < trace->destruction_listeners->len);
460 return (&g_array_index(trace->destruction_listeners,
461 struct bt_trace_destruction_listener_elem,
5084732e 462 listener_id))->func;
3602afb0
PP
463}
464
d24d5663 465enum bt_trace_remove_listener_status bt_trace_remove_destruction_listener(
2054a0d1 466 const struct bt_trace *c_trace, bt_listener_id listener_id)
3602afb0 467{
40f4ba76 468 struct bt_trace *trace = (void *) c_trace;
ad5268b5 469 struct bt_trace_destruction_listener_elem *elem;
3602afb0 470
44c440bc 471 BT_ASSERT_PRE_NON_NULL(trace, "Trace");
44c440bc 472 BT_ASSERT_PRE(has_listener_id(trace, listener_id),
ad5268b5 473 "Trace has no such trace destruction listener ID: "
44c440bc 474 "%![trace-]+t, %" PRIu64, trace, listener_id);
ad5268b5
FD
475 elem = &g_array_index(trace->destruction_listeners,
476 struct bt_trace_destruction_listener_elem,
3602afb0 477 listener_id);
44c440bc 478 BT_ASSERT(elem->func);
3602afb0
PP
479
480 elem->func = NULL;
481 elem->data = NULL;
3f7d4d90 482 BT_LIB_LOGD("Removed \"trace destruction listener: "
44c440bc
PP
483 "%![trace-]+t, listener-id=%" PRIu64,
484 trace, listener_id);
d24d5663 485 return BT_FUNC_STATUS_OK;
44c440bc 486}
3602afb0 487
44c440bc 488BT_HIDDEN
40f4ba76 489void _bt_trace_freeze(const struct bt_trace *trace)
44c440bc 490{
44c440bc 491 BT_ASSERT(trace);
862ca4ed
PP
492 BT_LIB_LOGD("Freezing trace's class: %!+T", trace->class);
493 bt_trace_class_freeze(trace->class);
c6962c96
PP
494 BT_LIB_LOGD("Freezing trace's user attributes: %!+v",
495 trace->user_attributes);
496 bt_value_freeze(trace->user_attributes);
44c440bc 497 BT_LIB_LOGD("Freezing trace: %!+t", trace);
40f4ba76 498 ((struct bt_trace *) trace)->frozen = true;
5acf2ae6 499}
312c056a 500
44c440bc
PP
501BT_HIDDEN
502void bt_trace_add_stream(struct bt_trace *trace, struct bt_stream *stream)
503{
504 guint count = 0;
505
506 bt_object_set_parent(&stream->base, &trace->base);
507 g_ptr_array_add(trace->streams, stream);
cb6f1f7d 508 bt_trace_freeze(trace);
312c056a 509
44c440bc
PP
510 if (bt_g_hash_table_contains(trace->stream_classes_stream_count,
511 stream->class)) {
512 count = GPOINTER_TO_UINT(g_hash_table_lookup(
513 trace->stream_classes_stream_count, stream->class));
312c056a
PP
514 }
515
44c440bc
PP
516 g_hash_table_insert(trace->stream_classes_stream_count,
517 stream->class, GUINT_TO_POINTER(count + 1));
518}
519
520BT_HIDDEN
40f4ba76
PP
521uint64_t bt_trace_get_automatic_stream_id(const struct bt_trace *trace,
522 const struct bt_stream_class *stream_class)
44c440bc
PP
523{
524 gpointer orig_key;
525 gpointer value;
526 uint64_t id = 0;
527
528 BT_ASSERT(stream_class);
529 BT_ASSERT(trace);
530 if (g_hash_table_lookup_extended(trace->stream_classes_stream_count,
531 stream_class, &orig_key, &value)) {
532 id = (uint64_t) GPOINTER_TO_UINT(value);
533 }
534
535 return id;
312c056a 536}
862ca4ed
PP
537
538struct bt_trace_class *bt_trace_borrow_class(struct bt_trace *trace)
539{
bdb288b3 540 BT_ASSERT_PRE_DEV_NON_NULL(trace, "Trace");
862ca4ed
PP
541 return trace->class;
542}
543
544const struct bt_trace_class *bt_trace_borrow_class_const(
545 const struct bt_trace *trace)
546{
547 return bt_trace_borrow_class((void *) trace);
548}
c5b9b441 549
c6962c96
PP
550const struct bt_value *bt_trace_borrow_user_attributes_const(
551 const struct bt_trace *trace)
552{
553 BT_ASSERT_PRE_DEV_NON_NULL(trace, "Trace");
554 return trace->user_attributes;
555}
556
557struct bt_value *bt_trace_borrow_user_attributes(struct bt_trace *trace)
558{
559 return (void *) bt_trace_borrow_user_attributes_const((void *) trace);
560}
561
562void bt_trace_set_user_attributes(
563 struct bt_trace *trace,
564 const struct bt_value *user_attributes)
565{
566 BT_ASSERT_PRE_NON_NULL(trace, "Trace");
567 BT_ASSERT_PRE_NON_NULL(user_attributes, "User attributes");
568 BT_ASSERT_PRE(user_attributes->type == BT_VALUE_TYPE_MAP,
569 "User attributes object is not a map value object.");
570 BT_ASSERT_PRE_DEV_TRACE_HOT(trace);
6871026b 571 bt_object_put_ref_no_null_check(trace->user_attributes);
c6962c96 572 trace->user_attributes = (void *) user_attributes;
6871026b 573 bt_object_get_ref_no_null_check(trace->user_attributes);
c6962c96
PP
574}
575
c5b9b441
PP
576void bt_trace_get_ref(const struct bt_trace *trace)
577{
578 bt_object_get_ref(trace);
579}
580
581void bt_trace_put_ref(const struct bt_trace *trace)
582{
583 bt_object_put_ref(trace);
584}
This page took 0.108967 seconds and 4 git commands to generate.