Commit | Line | Data |
---|---|---|
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 | ||
9843982d | 28 | struct definition; |
c50d2a7a | 29 | struct bt_ctf_event; |
9843982d JD |
30 | |
31 | /* | |
32 | * the top-level scopes in CTF | |
33 | */ | |
34 | enum bt_ctf_scope { | |
35 | BT_TRACE_PACKET_HEADER = 0, | |
36 | BT_STREAM_PACKET_CONTEXT = 1, | |
37 | BT_STREAM_EVENT_HEADER = 2, | |
38 | BT_STREAM_EVENT_CONTEXT = 3, | |
39 | BT_EVENT_CONTEXT = 4, | |
40 | BT_EVENT_FIELDS = 5, | |
41 | }; | |
42 | ||
43 | /* | |
44 | * the supported CTF types | |
45 | */ | |
46 | enum ctf_type_id { | |
47 | CTF_TYPE_UNKNOWN = 0, | |
48 | CTF_TYPE_INTEGER, | |
49 | CTF_TYPE_FLOAT, | |
50 | CTF_TYPE_ENUM, | |
51 | CTF_TYPE_STRING, | |
52 | CTF_TYPE_STRUCT, | |
53 | CTF_TYPE_UNTAGGED_VARIANT, | |
54 | CTF_TYPE_VARIANT, | |
55 | CTF_TYPE_ARRAY, | |
56 | CTF_TYPE_SEQUENCE, | |
57 | NR_CTF_TYPES, | |
58 | }; | |
59 | ||
8673030f JD |
60 | /* |
61 | * the supported CTF string encodings | |
62 | */ | |
63 | enum ctf_string_encoding { | |
64 | CTF_STRING_NONE = 0, | |
65 | CTF_STRING_UTF8, | |
66 | CTF_STRING_ASCII, | |
67 | CTF_STRING_UNKNOWN, | |
68 | }; | |
69 | ||
9843982d JD |
70 | /* |
71 | * bt_ctf_get_top_level_scope: return a definition of the top-level scope | |
72 | * | |
73 | * Top-level scopes are defined in the bt_ctf_scope enum. | |
74 | * In order to get a field or a field list, the user needs to pass a | |
75 | * scope as argument, this scope can be a top-level scope or a scope | |
76 | * relative to an arbitrary field. This function provides the mapping | |
77 | * between the enum and the actual definition of top-level scopes. | |
78 | * On error return NULL. | |
79 | */ | |
c50d2a7a | 80 | const struct definition *bt_ctf_get_top_level_scope(const struct bt_ctf_event *event, |
9843982d JD |
81 | enum bt_ctf_scope scope); |
82 | ||
83 | /* | |
84 | * bt_ctf_event_get_name: returns the name of the event or NULL on error | |
85 | */ | |
c50d2a7a | 86 | const char *bt_ctf_event_name(const struct bt_ctf_event *event); |
9843982d JD |
87 | |
88 | /* | |
57f3005e SJD |
89 | * bt_ctf_get_timestamp_raw: returns the timestamp of the event as written in |
90 | * the packet or -1ULL on error | |
91 | */ | |
c50d2a7a | 92 | uint64_t bt_ctf_get_timestamp_raw(const struct bt_ctf_event *event); |
57f3005e SJD |
93 | |
94 | /* | |
95 | * bt_ctf_get_timestamp: returns the timestamp of the event offsetted with the | |
96 | * system clock source or -1ULL on error | |
9843982d | 97 | */ |
c50d2a7a | 98 | uint64_t bt_ctf_get_timestamp(const struct bt_ctf_event *event); |
9843982d JD |
99 | |
100 | /* | |
aacd0c69 JD |
101 | * bt_ctf_get_field_list: set list pointer to an array of definition |
102 | * pointers and set count to the number of elements in the array. | |
103 | * Return 0 on success and a negative value on error. | |
9843982d | 104 | */ |
c50d2a7a | 105 | int bt_ctf_get_field_list(const struct bt_ctf_event *event, |
04ae3991 | 106 | const struct definition *scope, |
9843982d JD |
107 | struct definition const * const **list, |
108 | unsigned int *count); | |
109 | ||
110 | /* | |
111 | * bt_ctf_get_field: returns the definition of a specific field | |
112 | */ | |
c50d2a7a | 113 | const struct definition *bt_ctf_get_field(const struct bt_ctf_event *event, |
04ae3991 | 114 | const struct definition *scope, |
9843982d JD |
115 | const char *field); |
116 | ||
117 | /* | |
118 | * bt_ctf_get_index: if the field is an array or a sequence, return the element | |
119 | * at position index, otherwise return NULL; | |
120 | */ | |
c50d2a7a | 121 | const struct definition *bt_ctf_get_index(const struct bt_ctf_event *event, |
04ae3991 | 122 | const struct definition *field, |
9843982d JD |
123 | unsigned int index); |
124 | ||
125 | /* | |
126 | * bt_ctf_field_name: returns the name of a field or NULL on error | |
127 | */ | |
128 | const char *bt_ctf_field_name(const struct definition *def); | |
129 | ||
130 | /* | |
131 | * bt_ctf_field_type: returns the type of a field or -1 if unknown | |
132 | */ | |
da320b83 | 133 | enum ctf_type_id bt_ctf_field_type(const struct definition *def); |
9843982d | 134 | |
8673030f JD |
135 | /* |
136 | * bt_ctf_get_int_signedness: return the signedness of an integer | |
137 | * | |
138 | * return 0 if unsigned | |
139 | * return 1 if signed | |
140 | * return -1 on error | |
141 | */ | |
142 | int bt_ctf_get_int_signedness(const struct definition *field); | |
143 | ||
144 | /* | |
145 | * bt_ctf_get_int_base: return the base of an int or a negative value on error | |
146 | */ | |
147 | int bt_ctf_get_int_base(const struct definition *field); | |
148 | ||
149 | /* | |
150 | * bt_ctf_get_int_byte_order: return the byte order of an int or a negative | |
151 | * value on error | |
152 | */ | |
153 | int bt_ctf_get_int_byte_order(const struct definition *field); | |
154 | ||
155 | /* | |
156 | * bt_ctf_get_encoding: return the encoding of an int or a string. | |
157 | * return a negative value on error | |
158 | */ | |
159 | enum ctf_string_encoding bt_ctf_get_encoding(const struct definition *field); | |
160 | ||
161 | /* | |
162 | * bt_ctf_get_array_len: return the len of an array or a negative | |
163 | * value on error | |
164 | */ | |
165 | int bt_ctf_get_array_len(const struct definition *field); | |
166 | ||
9843982d JD |
167 | /* |
168 | * Field access functions | |
169 | * | |
170 | * These functions return the value associated with the field passed in | |
171 | * parameter. | |
172 | * | |
173 | * If the field does not exist or is not of the type requested, the value | |
174 | * returned is undefined. To check if an error occured, use the | |
175 | * bt_ctf_field_error() function after accessing a field. | |
176 | */ | |
da320b83 JD |
177 | uint64_t bt_ctf_get_uint64(const struct definition *field); |
178 | int64_t bt_ctf_get_int64(const struct definition *field); | |
179 | char *bt_ctf_get_char_array(const struct definition *field); | |
180 | char *bt_ctf_get_string(const struct definition *field); | |
9843982d JD |
181 | |
182 | /* | |
183 | * bt_ctf_field_error: returns the last error code encountered while | |
184 | * accessing a field and reset the error flag. | |
185 | * Return 0 if no error, a negative value otherwise. | |
186 | */ | |
187 | int bt_ctf_field_get_error(void); | |
188 | ||
189 | #endif /* _BABELTRACE_CTF_EVENTS_H */ |