f0213868c3ad32a4ab9b1fb17f244a562ceabd22
4 * Babeltrace CTF IR - Clock
6 * Copyright 2013, 2014 Jérémie Galarneau <jeremie.galarneau@efficios.com>
8 * Author: Jérémie Galarneau <jeremie.galarneau@efficios.com>
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:
17 * The above copyright notice and this permission notice shall be included in
18 * all copies or substantial portions of the Software.
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
29 #include <babeltrace/ctf-writer/clock.h>
30 #include <babeltrace/ctf-ir/clock-internal.h>
31 #include <babeltrace/ctf-writer/writer-internal.h>
32 #include <babeltrace/compiler.h>
36 void bt_ctf_clock_destroy(struct bt_ctf_ref
*ref
);
39 struct bt_ctf_clock
*_bt_ctf_clock_create(void)
41 struct bt_ctf_clock
*clock
= g_new0(
42 struct bt_ctf_clock
, 1);
49 clock
->frequency
= 1000000000;
50 uuid_generate(clock
->uuid
);
51 bt_ctf_ref_init(&clock
->ref_count
);
57 int bt_ctf_clock_set_name(struct bt_ctf_clock
*clock
,
62 if (validate_identifier(name
)) {
68 g_string_free(clock
->name
, TRUE
);
71 clock
->name
= g_string_new(name
);
80 struct bt_ctf_clock
*bt_ctf_clock_create(const char *name
)
83 struct bt_ctf_clock
*clock
= NULL
;
85 clock
= _bt_ctf_clock_create();
90 ret
= bt_ctf_clock_set_name(clock
, name
);
97 bt_ctf_clock_destroy(&clock
->ref_count
);
102 const char *bt_ctf_clock_get_name(struct bt_ctf_clock
*clock
)
104 const char *ret
= NULL
;
111 ret
= clock
->name
->str
;
118 const char *bt_ctf_clock_get_description(struct bt_ctf_clock
*clock
)
120 const char *ret
= NULL
;
126 if (clock
->description
) {
127 ret
= clock
->description
->str
;
133 int bt_ctf_clock_set_description(struct bt_ctf_clock
*clock
, const char *desc
)
137 if (!clock
|| !desc
|| clock
->frozen
) {
142 clock
->description
= g_string_new(desc
);
143 ret
= clock
->description
? 0 : -1;
148 uint64_t bt_ctf_clock_get_frequency(struct bt_ctf_clock
*clock
)
150 uint64_t ret
= -1ULL;
156 ret
= clock
->frequency
;
161 int bt_ctf_clock_set_frequency(struct bt_ctf_clock
*clock
, uint64_t freq
)
165 if (!clock
|| clock
->frozen
) {
170 clock
->frequency
= freq
;
175 uint64_t bt_ctf_clock_get_precision(struct bt_ctf_clock
*clock
)
177 uint64_t ret
= -1ULL;
183 ret
= clock
->precision
;
188 int bt_ctf_clock_set_precision(struct bt_ctf_clock
*clock
, uint64_t precision
)
192 if (!clock
|| clock
->frozen
) {
197 clock
->precision
= precision
;
202 uint64_t bt_ctf_clock_get_offset_s(struct bt_ctf_clock
*clock
)
204 uint64_t ret
= -1ULL;
210 ret
= clock
->offset_s
;
215 int bt_ctf_clock_set_offset_s(struct bt_ctf_clock
*clock
, uint64_t offset_s
)
219 if (!clock
|| clock
->frozen
) {
224 clock
->offset_s
= offset_s
;
229 uint64_t bt_ctf_clock_get_offset(struct bt_ctf_clock
*clock
)
231 uint64_t ret
= -1ULL;
242 int bt_ctf_clock_set_offset(struct bt_ctf_clock
*clock
, uint64_t offset
)
246 if (!clock
|| clock
->frozen
) {
251 clock
->offset
= offset
;
256 int bt_ctf_clock_get_is_absolute(struct bt_ctf_clock
*clock
)
264 ret
= clock
->absolute
;
269 int bt_ctf_clock_set_is_absolute(struct bt_ctf_clock
*clock
, int is_absolute
)
273 if (!clock
|| clock
->frozen
) {
278 clock
->absolute
= !!is_absolute
;
283 const unsigned char *bt_ctf_clock_get_uuid(struct bt_ctf_clock
*clock
)
285 const unsigned char *ret
;
297 int bt_ctf_clock_set_uuid(struct bt_ctf_clock
*clock
, const unsigned char *uuid
)
301 if (!clock
|| !uuid
) {
306 memcpy(clock
->uuid
, uuid
, sizeof(uuid_t
));
311 uint64_t bt_ctf_clock_get_time(struct bt_ctf_clock
*clock
)
313 uint64_t ret
= -1ULL;
324 int bt_ctf_clock_set_time(struct bt_ctf_clock
*clock
, uint64_t time
)
328 /* Timestamps are strictly monotonic */
329 if (!clock
|| time
< clock
->time
) {
339 void bt_ctf_clock_get(struct bt_ctf_clock
*clock
)
345 bt_ctf_ref_get(&clock
->ref_count
);
348 void bt_ctf_clock_put(struct bt_ctf_clock
*clock
)
354 bt_ctf_ref_put(&clock
->ref_count
, bt_ctf_clock_destroy
);
358 void bt_ctf_clock_freeze(struct bt_ctf_clock
*clock
)
368 void bt_ctf_clock_serialize(struct bt_ctf_clock
*clock
,
369 struct metadata_context
*context
)
373 if (!clock
|| !context
) {
378 g_string_append(context
->string
, "clock {\n");
379 g_string_append_printf(context
->string
, "\tname = %s;\n",
381 g_string_append_printf(context
->string
,
382 "\tuuid = \"%02x%02x%02x%02x-%02x%02x-%02x%02x-%02x%02x-%02x%02x%02x%02x%02x%02x\";\n",
383 uuid
[0], uuid
[1], uuid
[2], uuid
[3],
384 uuid
[4], uuid
[5], uuid
[6], uuid
[7],
385 uuid
[8], uuid
[9], uuid
[10], uuid
[11],
386 uuid
[12], uuid
[13], uuid
[14], uuid
[15]);
387 if (clock
->description
->len
) {
388 g_string_append_printf(context
->string
, "\tdescription = \"%s\";\n",
389 clock
->description
->str
);
392 g_string_append_printf(context
->string
, "\tfreq = %" PRIu64
";\n",
394 g_string_append_printf(context
->string
, "\tprecision = %" PRIu64
";\n",
396 g_string_append_printf(context
->string
, "\toffset_s = %" PRIu64
";\n",
398 g_string_append_printf(context
->string
, "\toffset = %" PRIu64
";\n",
400 g_string_append_printf(context
->string
, "\tabsolute = %s;\n",
401 clock
->absolute
? "TRUE" : "FALSE");
402 g_string_append(context
->string
, "};\n\n");
406 void bt_ctf_clock_destroy(struct bt_ctf_ref
*ref
)
408 struct bt_ctf_clock
*clock
;
414 clock
= container_of(ref
, struct bt_ctf_clock
, ref_count
);
416 g_string_free(clock
->name
, TRUE
);
419 if (clock
->description
) {
420 g_string_free(clock
->description
, TRUE
);
This page took 0.037592 seconds and 3 git commands to generate.