Handle negative time and offset from Epoch
[babeltrace.git] / include / babeltrace / ctf-ir / clock.h
CommitLineData
adc315b8
JG
1#ifndef BABELTRACE_CTF_IR_CLOCK_H
2#define BABELTRACE_CTF_IR_CLOCK_H
3
4/*
5 * BabelTrace - CTF IR: Clock
6 *
de9dd397 7 * Copyright 2013, 2014 Jérémie Galarneau <jeremie.galarneau@efficios.com>
adc315b8
JG
8 *
9 * Author: Jérémie Galarneau <jeremie.galarneau@efficios.com>
10 *
11 * Permission is hereby granted, free of charge, to any person obtaining a copy
12 * of this software and associated documentation files (the "Software"), to deal
13 * in the Software without restriction, including without limitation the rights
14 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
15 * copies of the Software, and to permit persons to whom the Software is
16 * furnished to do so, subject to the following conditions:
17 *
18 * The above copyright notice and this permission notice shall be included in
19 * all copies or substantial portions of the Software.
20 *
21 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
22 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
23 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
24 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
25 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
26 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
27 * SOFTWARE.
28 *
29 * The Common Trace Format (CTF) Specification is available at
30 * http://www.efficios.com/ctf
31 */
32
33#include <stdint.h>
34
35#ifdef __cplusplus
36extern "C" {
37#endif
38
39struct bt_ctf_clock;
40
41/*
42 * bt_ctf_clock_create: create a clock.
43 *
44 * Allocate a new clock setting its reference count to 1.
45 *
46 * @param name Name of the clock (will be copied).
47 *
48 * Returns an allocated clock on success, NULL on error.
49 */
50extern struct bt_ctf_clock *bt_ctf_clock_create(const char *name);
51
87d76bb1
JG
52/*
53 * bt_ctf_clock_get_name: get a clock's name.
54 *
55 * Get the clock's name.
56 *
57 * @param clock Clock instance.
58 *
59 * Returns the clock's name, NULL on error.
60 */
61extern const char *bt_ctf_clock_get_name(struct bt_ctf_clock *clock);
62
63/*
64 * bt_ctf_clock_get_description: get a clock's description.
65 *
66 * Get the clock's description.
67 *
68 * @param clock Clock instance.
69 *
70 * Returns the clock's description, NULL if unset.
71 */
72extern const char *bt_ctf_clock_get_description(struct bt_ctf_clock *clock);
73
adc315b8
JG
74/*
75 * bt_ctf_clock_set_description: set a clock's description.
76 *
77 * Set the clock's description. The description appears in the clock's TSDL
78 * meta-data.
79 *
80 * @param clock Clock instance.
81 * @param desc Description of the clock.
82 *
83 * Returns 0 on success, a negative value on error.
84 */
85extern int bt_ctf_clock_set_description(struct bt_ctf_clock *clock,
86 const char *desc);
87
87d76bb1
JG
88/*
89 * bt_ctf_clock_get_frequency: get a clock's frequency.
90 *
91 * Get the clock's frequency (Hz).
92 *
93 * @param clock Clock instance.
94 *
95 * Returns the clock's frequency, -1ULL on error.
96 */
97extern uint64_t bt_ctf_clock_get_frequency(struct bt_ctf_clock *clock);
98
adc315b8
JG
99/*
100 * bt_ctf_clock_set_frequency: set a clock's frequency.
101 *
102 * Set the clock's frequency (Hz).
103 *
104 * @param clock Clock instance.
105 * @param freq Clock's frequency in Hz, defaults to 1 000 000 000 Hz (1ns).
106 *
107 * Returns 0 on success, a negative value on error.
108 */
109extern int bt_ctf_clock_set_frequency(struct bt_ctf_clock *clock,
110 uint64_t freq);
111
87d76bb1
JG
112/*
113 * bt_ctf_clock_get_precision: get a clock's precision.
114 *
115 * Get the clock's precision (in clock ticks).
116 *
117 * @param clock Clock instance.
118 *
119 * Returns the clock's precision, -1ULL on error.
120 */
121extern uint64_t bt_ctf_clock_get_precision(struct bt_ctf_clock *clock);
122
adc315b8
JG
123/*
124 * bt_ctf_clock_set_precision: set a clock's precision.
125 *
126 * Set the clock's precision.
127 *
128 * @param clock Clock instance.
129 * @param precision Clock's precision in clock ticks, defaults to 1.
130 *
131 * Returns 0 on success, a negative value on error.
132 */
133extern int bt_ctf_clock_set_precision(struct bt_ctf_clock *clock,
134 uint64_t precision);
135
87d76bb1
JG
136/*
137 * bt_ctf_clock_get_offset_s: get a clock's offset in seconds.
138 *
139 * Get the clock's offset in seconds from POSIX.1 Epoch, 1970-01-01.
140 *
141 * @param clock Clock instance.
61cf588b 142 * @param offset_s Pointer to clock offset in seconds (output).
87d76bb1 143 *
61cf588b 144 * Returns 0 on success, a negative value on error.
87d76bb1 145 */
61cf588b
MD
146extern int bt_ctf_clock_get_offset_s(struct bt_ctf_clock *clock,
147 int64_t *offset_s);
87d76bb1 148
adc315b8
JG
149/*
150 * bt_ctf_clock_set_offset_s: set a clock's offset in seconds.
151 *
152 * Set the clock's offset in seconds from POSIX.1 Epoch, 1970-01-01,
153 * defaults to 0.
154 *
155 * @param clock Clock instance.
156 * @param offset_s Clock's offset in seconds, defaults to 0.
157 *
158 * Returns 0 on success, a negative value on error.
159 */
160extern int bt_ctf_clock_set_offset_s(struct bt_ctf_clock *clock,
61cf588b 161 int64_t offset_s);
adc315b8 162
87d76bb1 163/*
ffa6d162 164 * bt_ctf_clock_get_offset: get a clock's offset in ticks.
87d76bb1
JG
165 *
166 * Get the clock's offset in ticks from Epoch + offset_t.
167 *
168 * @param clock Clock instance.
61cf588b 169 * @param offset Clock offset in ticks from Epoch + offset_s (output).
87d76bb1 170 *
61cf588b 171 * Returns 0 on success, a negative value on error.
87d76bb1 172 */
61cf588b
MD
173extern int bt_ctf_clock_get_offset(struct bt_ctf_clock *clock,
174 int64_t *offset);
adc315b8
JG
175
176/*
177 * bt_ctf_clock_set_offset: set a clock's offset in ticks.
178 *
179 * Set the clock's offset in ticks from Epoch + offset_s.
180 *
181 * @param clock Clock instance.
182 * @param offset Clock's offset in ticks from Epoch + offset_s, defaults to 0.
183 *
184 * Returns 0 on success, a negative value on error.
185 */
186extern int bt_ctf_clock_set_offset(struct bt_ctf_clock *clock,
61cf588b 187 int64_t offset);
adc315b8 188
87d76bb1
JG
189/*
190 * bt_ctf_clock_get_is_absolute: get a clock's absolute attribute.
191 *
192 * Get the clock's absolute attribute. A clock is absolute if the clock is a
193 * global reference across the trace's other clocks.
194 *
195 * @param clock Clock instance.
196 *
197 * Returns the clock's absolute attribute, a negative value on error.
198 */
199extern int bt_ctf_clock_get_is_absolute(struct bt_ctf_clock *clock);
200
adc315b8
JG
201/*
202 * bt_ctf_clock_set_is_absolute: set a clock's absolute attribute.
203 *
87d76bb1
JG
204 * Set the clock's absolute attribute. A clock is absolute if the clock is a
205 * global reference across the trace's other clocks.
adc315b8
JG
206 *
207 * @param clock Clock instance.
208 * @param is_absolute Clock's absolute attribute, defaults to FALSE.
209 *
210 * Returns 0 on success, a negative value on error.
211 */
212extern int bt_ctf_clock_set_is_absolute(struct bt_ctf_clock *clock,
213 int is_absolute);
214
85b743f4
JG
215/*
216 * bt_ctf_clock_get_uuid: get a clock's UUID.
217 *
218 * Get the clock's UUID.
219 *
220 * @param clock Clock instance.
221 *
222 * Returns a pointer to the clock's UUID (16 byte array) on success,
223 * NULL on error.
224 */
225extern const unsigned char *bt_ctf_clock_get_uuid(struct bt_ctf_clock *clock);
226
227/*
228 * bt_ctf_clock_set_uuid: set a clock's UUID.
229 *
230 * Set a clock's UUID.
231 *
232 * @param clock Clock instance.
233 * @param uuid A 16-byte array containing a UUID.
234 *
235 * Returns 0 on success, a negative value on error.
236 */
237extern int bt_ctf_clock_set_uuid(struct bt_ctf_clock *clock,
a2875edc 238 const unsigned char *uuid);
85b743f4 239
87d76bb1
JG
240/*
241 * bt_ctf_clock_get_time: get a clock's current time value.
242 *
243 * Get the current time in nanoseconds since the clock's origin (offset and
244 * offset_s attributes).
245 *
61cf588b
MD
246 * @param clock Clock instance.
247 * @param time Clock current time value (output).
248 *
249 * Returns 0 on success, a negative value on error.
87d76bb1 250 */
61cf588b
MD
251extern int bt_ctf_clock_get_time(struct bt_ctf_clock *clock,
252 int64_t *time);
87d76bb1 253
adc315b8
JG
254/*
255 * bt_ctf_clock_set_time: set a clock's current time value.
256 *
257 * Set the current time in nanoseconds since the clock's origin (offset and
87d76bb1 258 * offset_s attributes). Defaults to 0.
adc315b8
JG
259 *
260 * Returns 0 on success, a negative value on error.
261 */
87d76bb1 262extern int bt_ctf_clock_set_time(struct bt_ctf_clock *clock,
61cf588b 263 int64_t time);
adc315b8
JG
264
265/*
266 * bt_ctf_clock_get and bt_ctf_clock_put: increment and decrement the
267 * refcount of the clock
268 *
de3dd40e
PP
269 * You may also use bt_ctf_get() and bt_ctf_put() with clock objects.
270 *
adc315b8
JG
271 * These functions ensure that the clock won't be destroyed when it
272 * is in use. The same number of get and put (plus one extra put to
273 * release the initial reference done at creation) has to be done to
274 * destroy a clock.
275 *
276 * When the clock refcount is decremented to 0 by a bt_ctf_clock_put,
277 * the clock is freed.
278 *
279 * @param clock Clock instance.
280 */
281extern void bt_ctf_clock_get(struct bt_ctf_clock *clock);
282extern void bt_ctf_clock_put(struct bt_ctf_clock *clock);
283
284#ifdef __cplusplus
285}
286#endif
287
288#endif /* BABELTRACE_CTF_IR_CLOCK_H */
This page took 0.036953 seconds and 4 git commands to generate.