Collect useless graph's connections
[babeltrace.git] / lib / ctf-ir / clock-class.c
CommitLineData
273b65be 1/*
ac0c6bdd 2 * clock-class.c
273b65be 3 *
ac0c6bdd 4 * Babeltrace CTF IR - Clock class
273b65be 5 *
de9dd397 6 * Copyright 2013, 2014 Jérémie Galarneau <jeremie.galarneau@efficios.com>
273b65be
JG
7 *
8 * Author: Jérémie Galarneau <jeremie.galarneau@efficios.com>
9 *
10 * Permission is hereby granted, free of charge, to any person obtaining a copy
11 * of this software and associated documentation files (the "Software"), to deal
12 * in the Software without restriction, including without limitation the rights
13 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
14 * copies of the Software, and to permit persons to whom the Software is
15 * furnished to do so, subject to the following conditions:
16 *
17 * The above copyright notice and this permission notice shall be included in
18 * all copies or substantial portions of the Software.
19 *
20 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
21 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
22 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
23 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
24 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
25 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
26 * SOFTWARE.
27 */
28
ac0c6bdd 29#include <babeltrace/ctf-ir/clock-class-internal.h>
654c1444 30#include <babeltrace/ctf-ir/utils.h>
83509119 31#include <babeltrace/ref.h>
83509119 32#include <babeltrace/object-internal.h>
3d9990ac 33#include <babeltrace/compiler-internal.h>
c55a9f58 34#include <babeltrace/types.h>
273b65be
JG
35#include <inttypes.h>
36
5134570b
PP
37#define BT_LOG_TAG "CLOCK-CLASS"
38#include <babeltrace/lib-logging-internal.h>
39
273b65be 40static
ac0c6bdd 41void bt_ctf_clock_class_destroy(struct bt_object *obj);
273b65be 42
4c426c17 43BT_HIDDEN
c55a9f58 44bt_bool bt_ctf_clock_class_is_valid(struct bt_ctf_clock_class *clock_class)
c06116f3 45{
ac0c6bdd 46 return clock_class && clock_class->name;
c06116f3
PP
47}
48
ac0c6bdd 49int bt_ctf_clock_class_set_name(struct bt_ctf_clock_class *clock_class,
4c426c17
JG
50 const char *name)
51{
52 int ret = 0;
273b65be 53
5134570b
PP
54 if (!clock_class) {
55 BT_LOGW_STR("Invalid parameter: clock class is NULL.");
56 ret = -1;
57 goto end;
58 }
59
60 if (clock_class->frozen) {
61 BT_LOGW("Invalid parameter: clock class is frozen: addr=%p",
62 clock_class);
c06116f3
PP
63 ret = -1;
64 goto end;
65 }
66
654c1444 67 if (bt_ctf_validate_identifier(name)) {
5134570b
PP
68 BT_LOGE("Clock class's name is not a valid CTF identifier: "
69 "clock-class-addr=%p, name=\"%s\"",
70 clock_class, name);
4c426c17
JG
71 ret = -1;
72 goto end;
273b65be
JG
73 }
74
ac0c6bdd
PP
75 if (clock_class->name) {
76 g_string_assign(clock_class->name, name);
e1ae7645 77 } else {
ac0c6bdd
PP
78 clock_class->name = g_string_new(name);
79 if (!clock_class->name) {
5134570b 80 BT_LOGE_STR("Failed to allocate a GString.");
e1ae7645
JG
81 ret = -1;
82 goto end;
83 }
273b65be
JG
84 }
85
5134570b
PP
86 BT_LOGV("Set clock class's name: clock-class-addr=%p, name=\"%s\"",
87 clock_class, name);
88
4c426c17
JG
89end:
90 return ret;
91}
92
ac0c6bdd 93struct bt_ctf_clock_class *bt_ctf_clock_class_create(const char *name)
4c426c17
JG
94{
95 int ret;
5134570b 96 struct bt_ctf_clock_class *clock_class;
4c426c17 97
5134570b
PP
98 BT_LOGD("Creating default clock class object: name=\"%s\"",
99 name);
100 clock_class = g_new0(struct bt_ctf_clock_class, 1);
ac0c6bdd 101 if (!clock_class) {
5134570b 102 BT_LOGE_STR("Failed to allocate one clock class.");
4c426c17
JG
103 goto error;
104 }
105
ac0c6bdd
PP
106 clock_class->precision = 1;
107 clock_class->frequency = 1000000000;
108 bt_object_init(clock_class, bt_ctf_clock_class_destroy);
85380e99
JG
109
110 if (name) {
ac0c6bdd 111 ret = bt_ctf_clock_class_set_name(clock_class, name);
85380e99 112 if (ret) {
5134570b
PP
113 BT_LOGE("Cannot set clock class's name: "
114 "clock-class-addr=%p, name=\"%s\"",
115 clock_class, name);
85380e99
JG
116 goto error;
117 }
273b65be
JG
118 }
119
ac0c6bdd 120 ret = bt_uuid_generate(clock_class->uuid);
be018f15 121 if (ret) {
5134570b 122 BT_LOGE_STR("Failed to generate a UUID.");
83509119 123 goto error;
be018f15
JG
124 }
125
ac0c6bdd 126 clock_class->uuid_set = 1;
5134570b 127 BT_LOGD("Created clock class object: addr=%p", clock_class);
ac0c6bdd 128 return clock_class;
273b65be 129error:
ac0c6bdd
PP
130 BT_PUT(clock_class);
131 return clock_class;
87d76bb1
JG
132}
133
ac0c6bdd 134const char *bt_ctf_clock_class_get_name(struct bt_ctf_clock_class *clock_class)
87d76bb1
JG
135{
136 const char *ret = NULL;
137
ac0c6bdd 138 if (!clock_class) {
5134570b 139 BT_LOGW_STR("Invalid parameter: clock class is NULL.");
87d76bb1
JG
140 goto end;
141 }
142
ac0c6bdd
PP
143 if (clock_class->name) {
144 ret = clock_class->name->str;
87d76bb1
JG
145 }
146
147end:
148 return ret;
149}
150
ac0c6bdd
PP
151const char *bt_ctf_clock_class_get_description(
152 struct bt_ctf_clock_class *clock_class)
87d76bb1
JG
153{
154 const char *ret = NULL;
155
ac0c6bdd 156 if (!clock_class) {
5134570b 157 BT_LOGW_STR("Invalid parameter: clock class is NULL.");
87d76bb1
JG
158 goto end;
159 }
160
ac0c6bdd
PP
161 if (clock_class->description) {
162 ret = clock_class->description->str;
87d76bb1
JG
163 }
164end:
165 return ret;
273b65be
JG
166}
167
ac0c6bdd
PP
168int bt_ctf_clock_class_set_description(struct bt_ctf_clock_class *clock_class,
169 const char *desc)
273b65be
JG
170{
171 int ret = 0;
172
5134570b
PP
173 if (!clock_class || !desc) {
174 BT_LOGW("Invalid parameter: clock class or description is NULL: "
175 "clock-class-addr=%p, desc-addr=%p",
176 clock_class, desc);
177 ret = -1;
178 goto end;
179 }
180
181 if (clock_class->frozen) {
182 BT_LOGW("Invalid parameter: clock class is frozen: addr=%p",
183 clock_class);
273b65be
JG
184 ret = -1;
185 goto end;
186 }
187
ac0c6bdd
PP
188 clock_class->description = g_string_new(desc);
189 ret = clock_class->description ? 0 : -1;
5134570b
PP
190 BT_LOGV("Set clock class's description: clock-class-addr=%p, desc=\"%s\"",
191 clock_class, desc);
273b65be
JG
192end:
193 return ret;
194}
195
ac0c6bdd
PP
196uint64_t bt_ctf_clock_class_get_frequency(
197 struct bt_ctf_clock_class *clock_class)
87d76bb1
JG
198{
199 uint64_t ret = -1ULL;
200
ac0c6bdd 201 if (!clock_class) {
5134570b 202 BT_LOGW_STR("Invalid parameter: clock class is NULL.");
87d76bb1
JG
203 goto end;
204 }
205
ac0c6bdd 206 ret = clock_class->frequency;
87d76bb1
JG
207end:
208 return ret;
209}
210
ac0c6bdd
PP
211int bt_ctf_clock_class_set_frequency(struct bt_ctf_clock_class *clock_class,
212 uint64_t freq)
273b65be
JG
213{
214 int ret = 0;
215
5134570b
PP
216 if (!clock_class || freq == -1ULL) {
217 BT_LOGW("Invalid parameter: clock class is NULL or frequency is invalid: "
218 "clock-class-addr=%p, freq=%" PRIu64,
219 clock_class, freq);
220 ret = -1;
221 goto end;
222 }
223
224 if (clock_class->frozen) {
225 BT_LOGW("Invalid parameter: clock class is frozen: addr=%p",
226 clock_class);
273b65be
JG
227 ret = -1;
228 goto end;
229 }
230
ac0c6bdd 231 clock_class->frequency = freq;
5134570b
PP
232 BT_LOGV("Set clock class's frequency: clock-class-addr=%p, freq=%" PRIu64,
233 clock_class, freq);
273b65be
JG
234end:
235 return ret;
236}
237
ac0c6bdd 238uint64_t bt_ctf_clock_class_get_precision(struct bt_ctf_clock_class *clock_class)
87d76bb1
JG
239{
240 uint64_t ret = -1ULL;
241
ac0c6bdd 242 if (!clock_class) {
5134570b 243 BT_LOGW_STR("Invalid parameter: clock class is NULL.");
87d76bb1
JG
244 goto end;
245 }
246
ac0c6bdd 247 ret = clock_class->precision;
87d76bb1
JG
248end:
249 return ret;
250}
251
ac0c6bdd
PP
252int bt_ctf_clock_class_set_precision(struct bt_ctf_clock_class *clock_class,
253 uint64_t precision)
273b65be
JG
254{
255 int ret = 0;
256
5134570b
PP
257 if (!clock_class || precision == -1ULL) {
258 BT_LOGW("Invalid parameter: clock class is NULL or precision is invalid: "
259 "clock-class-addr=%p, precision=%" PRIu64,
260 clock_class, precision);
261 ret = -1;
262 goto end;
263 }
264
265 if (clock_class->frozen) {
266 BT_LOGW("Invalid parameter: clock class is frozen: addr=%p",
267 clock_class);
273b65be
JG
268 ret = -1;
269 goto end;
270 }
271
ac0c6bdd 272 clock_class->precision = precision;
5134570b
PP
273 BT_LOGV("Set clock class's precision: clock-class-addr=%p, precision=%" PRIu64,
274 clock_class, precision);
273b65be
JG
275end:
276 return ret;
277}
278
ac0c6bdd
PP
279int bt_ctf_clock_class_get_offset_s(struct bt_ctf_clock_class *clock_class,
280 int64_t *offset_s)
87d76bb1 281{
61cf588b 282 int ret = 0;
87d76bb1 283
ac0c6bdd 284 if (!clock_class || !offset_s) {
5134570b
PP
285 BT_LOGW("Invalid parameter: clock class or offset pointer is NULL: "
286 "clock-class-addr=%p, offset-addr=%p",
287 clock_class, offset_s);
61cf588b 288 ret = -1;
87d76bb1
JG
289 goto end;
290 }
291
ac0c6bdd 292 *offset_s = clock_class->offset_s;
87d76bb1
JG
293end:
294 return ret;
295}
296
ac0c6bdd
PP
297int bt_ctf_clock_class_set_offset_s(struct bt_ctf_clock_class *clock_class,
298 int64_t offset_s)
273b65be
JG
299{
300 int ret = 0;
301
5134570b
PP
302 if (!clock_class) {
303 BT_LOGW_STR("Invalid parameter: clock class is NULL.");
304 ret = -1;
305 goto end;
306 }
307
308 if (clock_class->frozen) {
309 BT_LOGW("Invalid parameter: clock class is frozen: addr=%p",
310 clock_class);
273b65be
JG
311 ret = -1;
312 goto end;
313 }
314
ac0c6bdd 315 clock_class->offset_s = offset_s;
5134570b
PP
316 BT_LOGV("Set clock class's offset (seconds): clock-class-addr=%p, offset-s=%" PRId64,
317 clock_class, offset_s);
273b65be
JG
318end:
319 return ret;
320}
321
ac0c6bdd
PP
322int bt_ctf_clock_class_get_offset_cycles(struct bt_ctf_clock_class *clock_class,
323 int64_t *offset)
87d76bb1 324{
61cf588b 325 int ret = 0;
87d76bb1 326
ac0c6bdd 327 if (!clock_class || !offset) {
5134570b
PP
328 BT_LOGW("Invalid parameter: clock class or offset pointer is NULL: "
329 "clock-class-addr=%p, offset-addr=%p",
330 clock_class, offset);
61cf588b 331 ret = -1;
87d76bb1
JG
332 goto end;
333 }
334
ac0c6bdd 335 *offset = clock_class->offset;
87d76bb1
JG
336end:
337 return ret;
338}
339
ac0c6bdd
PP
340int bt_ctf_clock_class_set_offset_cycles(struct bt_ctf_clock_class *clock_class,
341 int64_t offset)
273b65be
JG
342{
343 int ret = 0;
344
5134570b
PP
345 if (!clock_class) {
346 BT_LOGW_STR("Invalid parameter: clock class is NULL.");
347 ret = -1;
348 goto end;
349 }
350
351 if (clock_class->frozen) {
352 BT_LOGW("Invalid parameter: clock class is frozen: addr=%p",
353 clock_class);
273b65be
JG
354 ret = -1;
355 goto end;
356 }
357
ac0c6bdd 358 clock_class->offset = offset;
5134570b
PP
359 BT_LOGV("Set clock class's offset (cycles): clock-class-addr=%p, offset-cycles=%" PRId64,
360 clock_class, offset);
273b65be
JG
361end:
362 return ret;
363}
364
a2b94977 365bt_bool bt_ctf_clock_class_is_absolute(struct bt_ctf_clock_class *clock_class)
87d76bb1
JG
366{
367 int ret = -1;
368
ac0c6bdd 369 if (!clock_class) {
5134570b 370 BT_LOGW_STR("Invalid parameter: clock class is NULL.");
87d76bb1
JG
371 goto end;
372 }
373
ac0c6bdd 374 ret = clock_class->absolute;
87d76bb1
JG
375end:
376 return ret;
377}
378
ac0c6bdd 379int bt_ctf_clock_class_set_is_absolute(struct bt_ctf_clock_class *clock_class,
a2b94977 380 bt_bool is_absolute)
273b65be
JG
381{
382 int ret = 0;
383
5134570b
PP
384 if (!clock_class) {
385 BT_LOGW_STR("Invalid parameter: clock class is NULL.");
386 ret = -1;
387 goto end;
388 }
389
390 if (clock_class->frozen) {
391 BT_LOGW("Invalid parameter: clock class is frozen: addr=%p",
392 clock_class);
273b65be
JG
393 ret = -1;
394 goto end;
395 }
396
ac0c6bdd 397 clock_class->absolute = !!is_absolute;
5134570b
PP
398 BT_LOGV("Set clock class's absolute flag: clock-class-addr=%p, is-absolute=%d",
399 clock_class, !!is_absolute);
273b65be
JG
400end:
401 return ret;
402}
403
ac0c6bdd
PP
404const unsigned char *bt_ctf_clock_class_get_uuid(
405 struct bt_ctf_clock_class *clock_class)
85b743f4
JG
406{
407 const unsigned char *ret;
408
5134570b
PP
409 if (!clock_class) {
410 BT_LOGW_STR("Invalid parameter: clock class is NULL.");
411 ret = NULL;
412 goto end;
413 }
414
415 if (!clock_class->uuid_set) {
416 BT_LOGV("Clock class's UUID is not set: clock-class-addr=%p",
417 clock_class);
85b743f4
JG
418 ret = NULL;
419 goto end;
420 }
421
ac0c6bdd 422 ret = clock_class->uuid;
85b743f4
JG
423end:
424 return ret;
425}
426
ac0c6bdd
PP
427int bt_ctf_clock_class_set_uuid(struct bt_ctf_clock_class *clock_class,
428 const unsigned char *uuid)
85b743f4
JG
429{
430 int ret = 0;
431
5134570b
PP
432 if (!clock_class || !uuid) {
433 BT_LOGW("Invalid parameter: clock class or UUID is NULL: "
434 "clock-class-addr=%p, uuid-addr=%p",
435 clock_class, uuid);
436 ret = -1;
437 goto end;
438 }
439
440 if (clock_class->frozen) {
441 BT_LOGW("Invalid parameter: clock class is frozen: addr=%p",
442 clock_class);
85b743f4
JG
443 ret = -1;
444 goto end;
445 }
446
ac0c6bdd
PP
447 memcpy(clock_class->uuid, uuid, sizeof(uuid_t));
448 clock_class->uuid_set = 1;
5134570b
PP
449 BT_LOGV("Set clock class's UUID: clock-class-addr=%p, "
450 "uuid=\"%02x%02x%02x%02x-%02x%02x-%02x%02x-%02x%02x-%02x%02x%02x%02x%02x%02x\"",
451 clock_class,
452 (unsigned int) uuid[0],
453 (unsigned int) uuid[1],
454 (unsigned int) uuid[2],
455 (unsigned int) uuid[3],
456 (unsigned int) uuid[4],
457 (unsigned int) uuid[5],
458 (unsigned int) uuid[6],
459 (unsigned int) uuid[7],
460 (unsigned int) uuid[8],
461 (unsigned int) uuid[9],
462 (unsigned int) uuid[10],
463 (unsigned int) uuid[11],
464 (unsigned int) uuid[12],
465 (unsigned int) uuid[13],
466 (unsigned int) uuid[14],
467 (unsigned int) uuid[15]);
85b743f4
JG
468end:
469 return ret;
470}
471
ac0c6bdd 472static uint64_t ns_from_value(uint64_t frequency, uint64_t value)
4ef18cab
PP
473{
474 uint64_t ns;
475
476 if (frequency == 1000000000) {
477 ns = value;
478 } else {
479 ns = (uint64_t) ((1e9 * (double) value) / (double) frequency);
480 }
481
482 return ns;
483}
484
273b65be 485BT_HIDDEN
ac0c6bdd 486void bt_ctf_clock_class_freeze(struct bt_ctf_clock_class *clock_class)
273b65be 487{
ac0c6bdd 488 if (!clock_class) {
5134570b 489 BT_LOGW_STR("Invalid parameter: clock class is NULL.");
273b65be
JG
490 return;
491 }
492
5134570b
PP
493 if (!clock_class->frozen) {
494 BT_LOGD("Freezing clock class: addr=%p", clock_class);
495 clock_class->frozen = 1;
496 }
273b65be
JG
497}
498
499BT_HIDDEN
ac0c6bdd 500void bt_ctf_clock_class_serialize(struct bt_ctf_clock_class *clock_class,
273b65be
JG
501 struct metadata_context *context)
502{
503 unsigned char *uuid;
504
5134570b
PP
505 BT_LOGD("Serializing clock class's metadata: clock-class-addr=%p, "
506 "metadata-context-addr=%p", clock_class, context);
507
ac0c6bdd 508 if (!clock_class || !context) {
5134570b
PP
509 BT_LOGW("Invalid parameter: clock class or metadata context is NULL: "
510 "clock-class-addr=%p, metadata-context-addr=%p",
511 clock_class, context);
273b65be
JG
512 return;
513 }
514
ac0c6bdd 515 uuid = clock_class->uuid;
273b65be
JG
516 g_string_append(context->string, "clock {\n");
517 g_string_append_printf(context->string, "\tname = %s;\n",
ac0c6bdd 518 clock_class->name->str);
273b65be
JG
519 g_string_append_printf(context->string,
520 "\tuuid = \"%02x%02x%02x%02x-%02x%02x-%02x%02x-%02x%02x-%02x%02x%02x%02x%02x%02x\";\n",
521 uuid[0], uuid[1], uuid[2], uuid[3],
522 uuid[4], uuid[5], uuid[6], uuid[7],
523 uuid[8], uuid[9], uuid[10], uuid[11],
524 uuid[12], uuid[13], uuid[14], uuid[15]);
ac0c6bdd 525 if (clock_class->description) {
273b65be 526 g_string_append_printf(context->string, "\tdescription = \"%s\";\n",
ac0c6bdd 527 clock_class->description->str);
273b65be
JG
528 }
529
530 g_string_append_printf(context->string, "\tfreq = %" PRIu64 ";\n",
ac0c6bdd 531 clock_class->frequency);
273b65be 532 g_string_append_printf(context->string, "\tprecision = %" PRIu64 ";\n",
ac0c6bdd 533 clock_class->precision);
273b65be 534 g_string_append_printf(context->string, "\toffset_s = %" PRIu64 ";\n",
ac0c6bdd 535 clock_class->offset_s);
273b65be 536 g_string_append_printf(context->string, "\toffset = %" PRIu64 ";\n",
ac0c6bdd 537 clock_class->offset);
273b65be 538 g_string_append_printf(context->string, "\tabsolute = %s;\n",
ac0c6bdd 539 clock_class->absolute ? "TRUE" : "FALSE");
273b65be
JG
540 g_string_append(context->string, "};\n\n");
541}
542
273b65be 543static
ac0c6bdd 544void bt_ctf_clock_class_destroy(struct bt_object *obj)
273b65be 545{
ac0c6bdd 546 struct bt_ctf_clock_class *clock_class;
273b65be 547
5134570b 548 BT_LOGD("Destroying clock class: addr=%p", obj);
ac0c6bdd
PP
549 clock_class = container_of(obj, struct bt_ctf_clock_class, base);
550 if (clock_class->name) {
551 g_string_free(clock_class->name, TRUE);
273b65be 552 }
ac0c6bdd
PP
553 if (clock_class->description) {
554 g_string_free(clock_class->description, TRUE);
273b65be
JG
555 }
556
ac0c6bdd 557 g_free(clock_class);
273b65be 558}
4ef18cab 559
61ec14e6
JG
560static
561void bt_ctf_clock_value_destroy(struct bt_object *obj)
562{
563 struct bt_ctf_clock_value *value;
564
5134570b
PP
565 BT_LOGD("Destroying clock value: addr=%p", obj);
566
61ec14e6
JG
567 if (!obj) {
568 return;
569 }
570
571 value = container_of(obj, struct bt_ctf_clock_value, base);
572 bt_put(value->clock_class);
573 g_free(value);
574}
575
576struct bt_ctf_clock_value *bt_ctf_clock_value_create(
ac0c6bdd 577 struct bt_ctf_clock_class *clock_class, uint64_t value)
4ef18cab 578{
61ec14e6 579 struct bt_ctf_clock_value *ret = NULL;
4ef18cab 580
5134570b
PP
581 BT_LOGD("Creating clock value object: clock-class-addr=%p, "
582 "value=%" PRIu64, clock_class, value);
583
ac0c6bdd 584 if (!clock_class) {
5134570b 585 BT_LOGW_STR("Invalid parameter: clock class is NULL.");
4ef18cab
PP
586 goto end;
587 }
588
61ec14e6
JG
589 ret = g_new0(struct bt_ctf_clock_value, 1);
590 if (!ret) {
5134570b 591 BT_LOGE_STR("Failed to allocate one clock value.");
61ec14e6
JG
592 goto end;
593 }
594
595 bt_object_init(ret, bt_ctf_clock_value_destroy);
ac0c6bdd 596 ret->clock_class = bt_get(clock_class);
61ec14e6 597 ret->value = value;
5134570b 598 BT_LOGD("Created clock value object: addr=%p", ret);
61ec14e6
JG
599end:
600 return ret;
601}
4ef18cab 602
61ec14e6
JG
603int bt_ctf_clock_value_get_value(
604 struct bt_ctf_clock_value *clock_value, uint64_t *raw_value)
605{
606 int ret = 0;
4ef18cab 607
61ec14e6 608 if (!clock_value || !raw_value) {
5134570b
PP
609 BT_LOGW("Invalid parameter: clock value or raw value is NULL: "
610 "clock-value-addr=%p, raw-value-addr=%p",
611 clock_value, raw_value);
61ec14e6
JG
612 ret = -1;
613 goto end;
614 }
4ef18cab 615
61ec14e6 616 *raw_value = clock_value->value;
4ef18cab 617end:
61ec14e6
JG
618 return ret;
619}
620
1556a1af 621int bt_ctf_clock_value_get_value_ns_from_epoch(struct bt_ctf_clock_value *value,
61ec14e6
JG
622 int64_t *ret_value_ns)
623{
624 int ret = 0;
625 int64_t ns;
626
627 if (!value || !ret_value_ns) {
5134570b
PP
628 BT_LOGW("Invalid parameter: clock value or return value pointer is NULL: "
629 "clock-value-addr=%p, ret-value-addr=%p",
630 value, ret_value_ns);
61ec14e6
JG
631 ret = -1;
632 goto end;
633 }
634
635 /* Initialize nanosecond timestamp to clock's offset in seconds. */
9ac68eb1 636 ns = value->clock_class->offset_s * (int64_t) 1000000000;
61ec14e6
JG
637
638 /* Add offset in cycles, converted to nanoseconds. */
639 ns += ns_from_value(value->clock_class->frequency,
640 value->clock_class->offset);
641
642 /* Add given value, converter to nanoseconds. */
643 ns += ns_from_value(value->clock_class->frequency, value->value);
644
645 *ret_value_ns = ns;
646end:
647 return ret;
4ef18cab 648}
6f57e458
PP
649
650struct bt_ctf_clock_class *bt_ctf_clock_value_get_class(
651 struct bt_ctf_clock_value *clock_value)
652{
653 struct bt_ctf_clock_class *clock_class = NULL;
654
655 if (!clock_value) {
5134570b 656 BT_LOGW_STR("Invalid parameter: clock value is NULL.");
6f57e458
PP
657 goto end;
658 }
659
660 clock_class = bt_get(clock_value->clock_class);
661
662end:
663 return clock_class;
664}
This page took 0.076596 seconds and 4 git commands to generate.