4 * Babeltrace CTF Writer
6 * Copyright 2013 EfficiOS Inc.
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
);
38 struct bt_ctf_clock
*bt_ctf_clock_create(const char *name
)
40 struct bt_ctf_clock
*clock
= NULL
;
42 if (validate_identifier(name
)) {
46 clock
= g_new0(struct bt_ctf_clock
, 1);
51 clock
->name
= g_string_new(name
);
57 clock
->frequency
= 1000000000;
58 uuid_generate(clock
->uuid
);
59 bt_ctf_ref_init(&clock
->ref_count
);
62 bt_ctf_clock_destroy(&clock
->ref_count
);
67 const char *bt_ctf_clock_get_name(struct bt_ctf_clock
*clock
)
69 const char *ret
= NULL
;
76 ret
= clock
->name
->str
;
83 const char *bt_ctf_clock_get_description(struct bt_ctf_clock
*clock
)
85 const char *ret
= NULL
;
91 if (clock
->description
) {
92 ret
= clock
->description
->str
;
98 int bt_ctf_clock_set_description(struct bt_ctf_clock
*clock
, const char *desc
)
102 if (!clock
|| !desc
|| clock
->frozen
) {
107 clock
->description
= g_string_new(desc
);
108 ret
= clock
->description
? 0 : -1;
113 uint64_t bt_ctf_clock_get_frequency(struct bt_ctf_clock
*clock
)
115 uint64_t ret
= -1ULL;
121 ret
= clock
->frequency
;
126 int bt_ctf_clock_set_frequency(struct bt_ctf_clock
*clock
, uint64_t freq
)
130 if (!clock
|| clock
->frozen
) {
135 clock
->frequency
= freq
;
140 uint64_t bt_ctf_clock_get_precision(struct bt_ctf_clock
*clock
)
142 uint64_t ret
= -1ULL;
148 ret
= clock
->precision
;
153 int bt_ctf_clock_set_precision(struct bt_ctf_clock
*clock
, uint64_t precision
)
157 if (!clock
|| clock
->frozen
) {
162 clock
->precision
= precision
;
167 uint64_t bt_ctf_clock_get_offset_s(struct bt_ctf_clock
*clock
)
169 uint64_t ret
= -1ULL;
175 ret
= clock
->offset_s
;
180 int bt_ctf_clock_set_offset_s(struct bt_ctf_clock
*clock
, uint64_t offset_s
)
184 if (!clock
|| clock
->frozen
) {
189 clock
->offset_s
= offset_s
;
194 uint64_t bt_ctf_clock_get_offset(struct bt_ctf_clock
*clock
)
196 uint64_t ret
= -1ULL;
207 int bt_ctf_clock_set_offset(struct bt_ctf_clock
*clock
, uint64_t offset
)
211 if (!clock
|| clock
->frozen
) {
216 clock
->offset
= offset
;
221 int bt_ctf_clock_get_is_absolute(struct bt_ctf_clock
*clock
)
229 ret
= clock
->absolute
;
234 int bt_ctf_clock_set_is_absolute(struct bt_ctf_clock
*clock
, int is_absolute
)
238 if (!clock
|| clock
->frozen
) {
243 clock
->absolute
= !!is_absolute
;
248 uint64_t bt_ctf_clock_get_time(struct bt_ctf_clock
*clock
)
250 uint64_t ret
= -1ULL;
261 int bt_ctf_clock_set_time(struct bt_ctf_clock
*clock
, uint64_t time
)
265 /* Timestamps are strictly monotonic */
266 if (!clock
|| time
< clock
->time
) {
276 void bt_ctf_clock_get(struct bt_ctf_clock
*clock
)
282 bt_ctf_ref_get(&clock
->ref_count
);
285 void bt_ctf_clock_put(struct bt_ctf_clock
*clock
)
291 bt_ctf_ref_put(&clock
->ref_count
, bt_ctf_clock_destroy
);
295 void bt_ctf_clock_freeze(struct bt_ctf_clock
*clock
)
305 void bt_ctf_clock_serialize(struct bt_ctf_clock
*clock
,
306 struct metadata_context
*context
)
310 if (!clock
|| !context
) {
315 g_string_append(context
->string
, "clock {\n");
316 g_string_append_printf(context
->string
, "\tname = %s;\n",
318 g_string_append_printf(context
->string
,
319 "\tuuid = \"%02x%02x%02x%02x-%02x%02x-%02x%02x-%02x%02x-%02x%02x%02x%02x%02x%02x\";\n",
320 uuid
[0], uuid
[1], uuid
[2], uuid
[3],
321 uuid
[4], uuid
[5], uuid
[6], uuid
[7],
322 uuid
[8], uuid
[9], uuid
[10], uuid
[11],
323 uuid
[12], uuid
[13], uuid
[14], uuid
[15]);
324 if (clock
->description
->len
) {
325 g_string_append_printf(context
->string
, "\tdescription = \"%s\";\n",
326 clock
->description
->str
);
329 g_string_append_printf(context
->string
, "\tfreq = %" PRIu64
";\n",
331 g_string_append_printf(context
->string
, "\tprecision = %" PRIu64
";\n",
333 g_string_append_printf(context
->string
, "\toffset_s = %" PRIu64
";\n",
335 g_string_append_printf(context
->string
, "\toffset = %" PRIu64
";\n",
337 g_string_append_printf(context
->string
, "\tabsolute = %s;\n",
338 clock
->absolute
? "TRUE" : "FALSE");
339 g_string_append(context
->string
, "};\n\n");
343 void bt_ctf_clock_destroy(struct bt_ctf_ref
*ref
)
345 struct bt_ctf_clock
*clock
;
351 clock
= container_of(ref
, struct bt_ctf_clock
, ref_count
);
353 g_string_free(clock
->name
, TRUE
);
356 if (clock
->description
) {
357 g_string_free(clock
->description
, TRUE
);
This page took 0.038499 seconds and 4 git commands to generate.