ir: consolidate reference counting functions
[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.
142 *
143 * Returns the clock's offset in seconds, -1ULL on error.
144 */
145extern uint64_t bt_ctf_clock_get_offset_s(struct bt_ctf_clock *clock);
146
adc315b8
JG
147/*
148 * bt_ctf_clock_set_offset_s: set a clock's offset in seconds.
149 *
150 * Set the clock's offset in seconds from POSIX.1 Epoch, 1970-01-01,
151 * defaults to 0.
152 *
153 * @param clock Clock instance.
154 * @param offset_s Clock's offset in seconds, defaults to 0.
155 *
156 * Returns 0 on success, a negative value on error.
157 */
158extern int bt_ctf_clock_set_offset_s(struct bt_ctf_clock *clock,
159 uint64_t offset_s);
160
87d76bb1 161/*
ffa6d162 162 * bt_ctf_clock_get_offset: get a clock's offset in ticks.
87d76bb1
JG
163 *
164 * Get the clock's offset in ticks from Epoch + offset_t.
165 *
166 * @param clock Clock instance.
167 *
168 * Returns the clock's offset in ticks from Epoch + offset_s, -1ULL on error.
169 */
170extern uint64_t bt_ctf_clock_get_offset(struct bt_ctf_clock *clock);
adc315b8
JG
171
172/*
173 * bt_ctf_clock_set_offset: set a clock's offset in ticks.
174 *
175 * Set the clock's offset in ticks from Epoch + offset_s.
176 *
177 * @param clock Clock instance.
178 * @param offset Clock's offset in ticks from Epoch + offset_s, defaults to 0.
179 *
180 * Returns 0 on success, a negative value on error.
181 */
182extern int bt_ctf_clock_set_offset(struct bt_ctf_clock *clock,
183 uint64_t offset);
184
87d76bb1
JG
185/*
186 * bt_ctf_clock_get_is_absolute: get a clock's absolute attribute.
187 *
188 * Get the clock's absolute attribute. A clock is absolute if the clock is a
189 * global reference across the trace's other clocks.
190 *
191 * @param clock Clock instance.
192 *
193 * Returns the clock's absolute attribute, a negative value on error.
194 */
195extern int bt_ctf_clock_get_is_absolute(struct bt_ctf_clock *clock);
196
adc315b8
JG
197/*
198 * bt_ctf_clock_set_is_absolute: set a clock's absolute attribute.
199 *
87d76bb1
JG
200 * Set the clock's absolute attribute. A clock is absolute if the clock is a
201 * global reference across the trace's other clocks.
adc315b8
JG
202 *
203 * @param clock Clock instance.
204 * @param is_absolute Clock's absolute attribute, defaults to FALSE.
205 *
206 * Returns 0 on success, a negative value on error.
207 */
208extern int bt_ctf_clock_set_is_absolute(struct bt_ctf_clock *clock,
209 int is_absolute);
210
85b743f4
JG
211/*
212 * bt_ctf_clock_get_uuid: get a clock's UUID.
213 *
214 * Get the clock's UUID.
215 *
216 * @param clock Clock instance.
217 *
218 * Returns a pointer to the clock's UUID (16 byte array) on success,
219 * NULL on error.
220 */
221extern const unsigned char *bt_ctf_clock_get_uuid(struct bt_ctf_clock *clock);
222
223/*
224 * bt_ctf_clock_set_uuid: set a clock's UUID.
225 *
226 * Set a clock's UUID.
227 *
228 * @param clock Clock instance.
229 * @param uuid A 16-byte array containing a UUID.
230 *
231 * Returns 0 on success, a negative value on error.
232 */
233extern int bt_ctf_clock_set_uuid(struct bt_ctf_clock *clock,
a2875edc 234 const unsigned char *uuid);
85b743f4 235
87d76bb1
JG
236/*
237 * bt_ctf_clock_get_time: get a clock's current time value.
238 *
239 * Get the current time in nanoseconds since the clock's origin (offset and
240 * offset_s attributes).
241 *
242 * Returns the clock's current time value, -1ULL on error.
243 */
244extern uint64_t bt_ctf_clock_get_time(struct bt_ctf_clock *clock);
245
adc315b8
JG
246/*
247 * bt_ctf_clock_set_time: set a clock's current time value.
248 *
249 * Set the current time in nanoseconds since the clock's origin (offset and
87d76bb1 250 * offset_s attributes). Defaults to 0.
adc315b8
JG
251 *
252 * Returns 0 on success, a negative value on error.
253 */
87d76bb1
JG
254extern int bt_ctf_clock_set_time(struct bt_ctf_clock *clock,
255 uint64_t time);
adc315b8
JG
256
257/*
258 * bt_ctf_clock_get and bt_ctf_clock_put: increment and decrement the
259 * refcount of the clock
260 *
de3dd40e
PP
261 * You may also use bt_ctf_get() and bt_ctf_put() with clock objects.
262 *
adc315b8
JG
263 * These functions ensure that the clock won't be destroyed when it
264 * is in use. The same number of get and put (plus one extra put to
265 * release the initial reference done at creation) has to be done to
266 * destroy a clock.
267 *
268 * When the clock refcount is decremented to 0 by a bt_ctf_clock_put,
269 * the clock is freed.
270 *
271 * @param clock Clock instance.
272 */
273extern void bt_ctf_clock_get(struct bt_ctf_clock *clock);
274extern void bt_ctf_clock_put(struct bt_ctf_clock *clock);
275
276#ifdef __cplusplus
277}
278#endif
279
280#endif /* BABELTRACE_CTF_IR_CLOCK_H */
This page took 0.036894 seconds and 4 git commands to generate.