Fix: split ctf/event.c
[babeltrace.git] / include / babeltrace / ctf / events.h
CommitLineData
9843982d
JD
1#ifndef _BABELTRACE_CTF_EVENTS_H
2#define _BABELTRACE_CTF_EVENTS_H
3
4/*
5 * BabelTrace
6 *
7 * CTF events API
8 *
9 * Copyright 2011-2012 EfficiOS Inc. and Linux Foundation
10 *
11 * Author: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
12 * Julien Desfossez <julien.desfossez@efficios.com>
13 *
14 * Permission is hereby granted, free of charge, to any person obtaining
15 * a copy of this software and associated documentation files (the
16 * "Software"), to deal in the Software without restriction, including
17 * without limitation the rights to use, copy, modify, merge, publish,
18 * distribute, sublicense, and/or sell copies of the Software, and to
19 * permit persons to whom the Software is furnished to do so, subject to
20 * the following conditions:
21 *
22 * The above copyright notice and this permission notice shall be
23 * included in all copies or substantial portions of the Software.
24 */
25
26#include <stdint.h>
27
28struct ctf_stream;
29struct ctf_stream_event;
30struct definition;
31
32/*
33 * the top-level scopes in CTF
34 */
35enum bt_ctf_scope {
36 BT_TRACE_PACKET_HEADER = 0,
37 BT_STREAM_PACKET_CONTEXT = 1,
38 BT_STREAM_EVENT_HEADER = 2,
39 BT_STREAM_EVENT_CONTEXT = 3,
40 BT_EVENT_CONTEXT = 4,
41 BT_EVENT_FIELDS = 5,
42};
43
44/*
45 * the supported CTF types
46 */
47enum ctf_type_id {
48 CTF_TYPE_UNKNOWN = 0,
49 CTF_TYPE_INTEGER,
50 CTF_TYPE_FLOAT,
51 CTF_TYPE_ENUM,
52 CTF_TYPE_STRING,
53 CTF_TYPE_STRUCT,
54 CTF_TYPE_UNTAGGED_VARIANT,
55 CTF_TYPE_VARIANT,
56 CTF_TYPE_ARRAY,
57 CTF_TYPE_SEQUENCE,
58 NR_CTF_TYPES,
59};
60
8673030f
JD
61/*
62 * the supported CTF string encodings
63 */
64enum ctf_string_encoding {
65 CTF_STRING_NONE = 0,
66 CTF_STRING_UTF8,
67 CTF_STRING_ASCII,
68 CTF_STRING_UNKNOWN,
69};
70
9843982d
JD
71/*
72 * the structure to manipulate events
73 */
74struct bt_ctf_event {
75 struct ctf_stream *stream;
76 struct ctf_stream_event *event;
77};
78
79/*
80 * bt_ctf_get_top_level_scope: return a definition of the top-level scope
81 *
82 * Top-level scopes are defined in the bt_ctf_scope enum.
83 * In order to get a field or a field list, the user needs to pass a
84 * scope as argument, this scope can be a top-level scope or a scope
85 * relative to an arbitrary field. This function provides the mapping
86 * between the enum and the actual definition of top-level scopes.
87 * On error return NULL.
88 */
89struct definition *bt_ctf_get_top_level_scope(struct bt_ctf_event *event,
90 enum bt_ctf_scope scope);
91
92/*
93 * bt_ctf_event_get_name: returns the name of the event or NULL on error
94 */
95const char *bt_ctf_event_name(struct bt_ctf_event *event);
96
97/*
57f3005e
SJD
98 * bt_ctf_get_timestamp_raw: returns the timestamp of the event as written in
99 * the packet or -1ULL on error
100 */
101uint64_t bt_ctf_get_timestamp_raw(struct bt_ctf_event *event);
102
103/*
104 * bt_ctf_get_timestamp: returns the timestamp of the event offsetted with the
105 * system clock source or -1ULL on error
9843982d
JD
106 */
107uint64_t bt_ctf_get_timestamp(struct bt_ctf_event *event);
108
109/*
aacd0c69
JD
110 * bt_ctf_get_field_list: set list pointer to an array of definition
111 * pointers and set count to the number of elements in the array.
112 * Return 0 on success and a negative value on error.
9843982d
JD
113 */
114int bt_ctf_get_field_list(struct bt_ctf_event *event,
115 struct definition *scope,
116 struct definition const * const **list,
117 unsigned int *count);
118
119/*
120 * bt_ctf_get_field: returns the definition of a specific field
121 */
122struct definition *bt_ctf_get_field(struct bt_ctf_event *event,
123 struct definition *scope,
124 const char *field);
125
126/*
127 * bt_ctf_get_index: if the field is an array or a sequence, return the element
128 * at position index, otherwise return NULL;
129 */
130struct definition *bt_ctf_get_index(struct bt_ctf_event *event,
131 struct definition *field,
132 unsigned int index);
133
134/*
135 * bt_ctf_field_name: returns the name of a field or NULL on error
136 */
137const char *bt_ctf_field_name(const struct definition *def);
138
139/*
140 * bt_ctf_field_type: returns the type of a field or -1 if unknown
141 */
da320b83 142enum ctf_type_id bt_ctf_field_type(const struct definition *def);
9843982d 143
8673030f
JD
144/*
145 * bt_ctf_get_int_signedness: return the signedness of an integer
146 *
147 * return 0 if unsigned
148 * return 1 if signed
149 * return -1 on error
150 */
151int bt_ctf_get_int_signedness(const struct definition *field);
152
153/*
154 * bt_ctf_get_int_base: return the base of an int or a negative value on error
155 */
156int bt_ctf_get_int_base(const struct definition *field);
157
158/*
159 * bt_ctf_get_int_byte_order: return the byte order of an int or a negative
160 * value on error
161 */
162int bt_ctf_get_int_byte_order(const struct definition *field);
163
164/*
165 * bt_ctf_get_encoding: return the encoding of an int or a string.
166 * return a negative value on error
167 */
168enum ctf_string_encoding bt_ctf_get_encoding(const struct definition *field);
169
170/*
171 * bt_ctf_get_array_len: return the len of an array or a negative
172 * value on error
173 */
174int bt_ctf_get_array_len(const struct definition *field);
175
9843982d
JD
176/*
177 * Field access functions
178 *
179 * These functions return the value associated with the field passed in
180 * parameter.
181 *
182 * If the field does not exist or is not of the type requested, the value
183 * returned is undefined. To check if an error occured, use the
184 * bt_ctf_field_error() function after accessing a field.
185 */
da320b83
JD
186uint64_t bt_ctf_get_uint64(const struct definition *field);
187int64_t bt_ctf_get_int64(const struct definition *field);
188char *bt_ctf_get_char_array(const struct definition *field);
189char *bt_ctf_get_string(const struct definition *field);
9843982d
JD
190
191/*
192 * bt_ctf_field_error: returns the last error code encountered while
193 * accessing a field and reset the error flag.
194 * Return 0 if no error, a negative value otherwise.
195 */
196int bt_ctf_field_get_error(void);
197
198#endif /* _BABELTRACE_CTF_EVENTS_H */
This page took 0.030002 seconds and 4 git commands to generate.