Commit | Line | Data |
---|---|---|
1e649dff PP |
1 | #ifndef _METADATA_DECODER_H |
2 | #define _METADATA_DECODER_H | |
3 | ||
4 | /* | |
5 | * Copyright 2016-2017 - Philippe Proulx <pproulx@efficios.com> | |
6 | * | |
7 | * Permission is hereby granted, free of charge, to any person obtaining a copy | |
8 | * of this software and associated documentation files (the "Software"), to deal | |
9 | * in the Software without restriction, including without limitation the rights | |
10 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | |
11 | * copies of the Software, and to permit persons to whom the Software is | |
12 | * furnished to do so, subject to the following conditions: | |
13 | * | |
14 | * The above copyright notice and this permission notice shall be included in | |
15 | * all copies or substantial portions of the Software. | |
16 | */ | |
17 | ||
18 | #include <stdint.h> | |
a2a54545 | 19 | #include <stdbool.h> |
1e649dff | 20 | |
3fadfbc0 | 21 | #include <babeltrace2/babeltrace.h> |
1e649dff | 22 | |
91d81473 | 23 | #include "common/macros.h" |
06be9946 PP |
24 | #include "common/uuid.h" |
25 | ||
26 | struct ctf_trace_class; | |
91d81473 | 27 | |
1e649dff PP |
28 | /* A CTF metadata decoder object */ |
29 | struct ctf_metadata_decoder; | |
30 | ||
31 | /* CTF metadata decoder status */ | |
32 | enum ctf_metadata_decoder_status { | |
33 | CTF_METADATA_DECODER_STATUS_OK = 0, | |
1a6da3f9 | 34 | CTF_METADATA_DECODER_STATUS_NONE = 1, |
1e649dff PP |
35 | CTF_METADATA_DECODER_STATUS_ERROR = -1, |
36 | CTF_METADATA_DECODER_STATUS_INCOMPLETE = -2, | |
37 | CTF_METADATA_DECODER_STATUS_INVAL_VERSION = -3, | |
38 | CTF_METADATA_DECODER_STATUS_IR_VISITOR_ERROR = -4, | |
39 | }; | |
40 | ||
a2a54545 PP |
41 | /* Decoding configuration */ |
42 | struct ctf_metadata_decoder_config { | |
06be9946 | 43 | /* Active log level to use */ |
0746848c | 44 | bt_logging_level log_level; |
f7b785ac | 45 | |
06be9946 | 46 | /* Component to use for logging (can be `NULL`); weak */ |
f7b785ac PP |
47 | bt_self_component *self_comp; |
48 | ||
06be9946 | 49 | /* Additional clock class offset to apply */ |
a2a54545 PP |
50 | int64_t clock_class_offset_s; |
51 | int64_t clock_class_offset_ns; | |
06be9946 PP |
52 | |
53 | /* True to create trace class objects */ | |
54 | bool create_trace_class; | |
55 | ||
56 | /* | |
57 | * True to keep the plain text when content is appended with | |
58 | * ctf_metadata_decoder_append_content(). | |
59 | */ | |
60 | bool keep_plain_text; | |
a2a54545 PP |
61 | }; |
62 | ||
1e649dff | 63 | /* |
862ca4ed | 64 | * Creates a CTF metadata decoder. |
1e649dff PP |
65 | * |
66 | * Returns `NULL` on error. | |
67 | */ | |
68 | BT_HIDDEN | |
55314f2a | 69 | struct ctf_metadata_decoder *ctf_metadata_decoder_create( |
862ca4ed | 70 | const struct ctf_metadata_decoder_config *config); |
1e649dff PP |
71 | |
72 | /* | |
73 | * Destroys a CTF metadata decoder that you created with | |
74 | * ctf_metadata_decoder_create(). | |
75 | */ | |
76 | BT_HIDDEN | |
77 | void ctf_metadata_decoder_destroy( | |
78 | struct ctf_metadata_decoder *metadata_decoder); | |
79 | ||
80 | /* | |
06be9946 | 81 | * Appends content to the metadata decoder. |
1e649dff PP |
82 | * |
83 | * This function reads the metadata from the current position of `fp` | |
06be9946 | 84 | * until the end of this file stream. |
1e649dff PP |
85 | * |
86 | * The metadata can be packetized or not. | |
87 | * | |
06be9946 PP |
88 | * The metadata chunk needs to be complete and lexically scannable, that |
89 | * is, zero or more complete top-level blocks. If it's incomplete, this | |
1e649dff PP |
90 | * function returns `CTF_METADATA_DECODER_STATUS_INCOMPLETE`. If this |
91 | * function returns `CTF_METADATA_DECODER_STATUS_INCOMPLETE`, then you | |
06be9946 | 92 | * need to call it again with the _same_ metadata and more to make it |
1e649dff PP |
93 | * complete. For example: |
94 | * | |
95 | * First call: event { name = hell | |
96 | * Second call: event { name = hello_world; ... }; | |
97 | * | |
1e649dff PP |
98 | * If everything goes as expected, this function returns |
99 | * `CTF_METADATA_DECODER_STATUS_OK`. | |
100 | */ | |
101 | BT_HIDDEN | |
06be9946 | 102 | enum ctf_metadata_decoder_status ctf_metadata_decoder_append_content( |
1e649dff PP |
103 | struct ctf_metadata_decoder *metadata_decoder, FILE *fp); |
104 | ||
06be9946 PP |
105 | /* |
106 | * Returns the trace IR trace class of this metadata decoder (new | |
107 | * reference). | |
108 | * | |
109 | * Returns `NULL` if there's none yet or if the metadata decoder is not | |
110 | * configured to create trace classes. | |
111 | */ | |
1e649dff | 112 | BT_HIDDEN |
b19ff26f | 113 | bt_trace_class *ctf_metadata_decoder_get_ir_trace_class( |
44c440bc PP |
114 | struct ctf_metadata_decoder *mdec); |
115 | ||
06be9946 PP |
116 | /* |
117 | * Returns the CTF IR trace class of this metadata decoder. | |
118 | * | |
119 | * Returns `NULL` if there's none yet or if the metadata decoder is not | |
120 | * configured to create trace classes. | |
121 | */ | |
44c440bc PP |
122 | BT_HIDDEN |
123 | struct ctf_trace_class *ctf_metadata_decoder_borrow_ctf_trace_class( | |
124 | struct ctf_metadata_decoder *mdec); | |
1e649dff PP |
125 | |
126 | /* | |
06be9946 PP |
127 | * Checks whether or not a given metadata file stream `fp` is |
128 | * packetized, setting `is_packetized` accordingly on success. On | |
129 | * success, also sets `*byte_order` to the byte order of the first | |
130 | * packet. | |
131 | * | |
132 | * This function uses `log_level` and `self_comp` for logging purposes. | |
133 | * `self_comp` can be `NULL` if not available. | |
1e649dff PP |
134 | */ |
135 | BT_HIDDEN | |
06be9946 PP |
136 | int ctf_metadata_decoder_is_packetized(FILE *fp, bool *is_packetized, |
137 | int *byte_order, bt_logging_level log_level, | |
f7b785ac | 138 | bt_self_component *self_comp); |
1e649dff PP |
139 | |
140 | /* | |
06be9946 PP |
141 | * Returns the byte order of the decoder's metadata stream as set by the |
142 | * last call to ctf_metadata_decoder_append_content(). | |
143 | * | |
144 | * Returns -1 if unknown (plain text content). | |
1e649dff PP |
145 | */ |
146 | BT_HIDDEN | |
06be9946 PP |
147 | int ctf_metadata_decoder_get_byte_order(struct ctf_metadata_decoder *mdec); |
148 | ||
149 | /* | |
150 | * Returns the UUID of the decoder's metadata stream as set by the last | |
151 | * call to ctf_metadata_decoder_append_content(). | |
1a6da3f9 PP |
152 | */ |
153 | BT_HIDDEN | |
154 | int ctf_metadata_decoder_get_uuid( | |
155 | struct ctf_metadata_decoder *mdec, bt_uuid_t uuid); | |
156 | ||
157 | /* | |
158 | * Returns the UUID of the decoder's trace class, if available. | |
06be9946 | 159 | * |
1a6da3f9 PP |
160 | * Returns: |
161 | * | |
162 | * * `CTF_METADATA_DECODER_STATUS_OK`: success. | |
163 | * * `CTF_METADATA_DECODER_STATUS_NONE`: no UUID. | |
164 | * * `CTF_METADATA_DECODER_STATUS_INCOMPLETE`: missing metadata content. | |
06be9946 PP |
165 | */ |
166 | BT_HIDDEN | |
1a6da3f9 PP |
167 | enum ctf_metadata_decoder_status ctf_metadata_decoder_get_trace_class_uuid( |
168 | struct ctf_metadata_decoder *mdec, bt_uuid_t uuid); | |
06be9946 PP |
169 | |
170 | /* | |
171 | * Returns the metadata decoder's current metadata text. | |
172 | */ | |
173 | BT_HIDDEN | |
174 | const char *ctf_metadata_decoder_get_text(struct ctf_metadata_decoder *mdec); | |
1e649dff | 175 | |
3c8252a5 PP |
176 | static inline |
177 | bool ctf_metadata_decoder_is_packet_version_valid(unsigned int major, | |
178 | unsigned int minor) | |
179 | { | |
180 | return major == 1 && minor == 8; | |
181 | } | |
182 | ||
1e649dff | 183 | #endif /* _METADATA_DECODER_H */ |