Commit | Line | Data |
---|---|---|
1e649dff | 1 | /* |
0235b0db | 2 | * SPDX-License-Identifier: MIT |
1e649dff | 3 | * |
0235b0db | 4 | * Copyright 2016-2017 Philippe Proulx <pproulx@efficios.com> |
1e649dff PP |
5 | */ |
6 | ||
0235b0db MJ |
7 | #ifndef _METADATA_DECODER_H |
8 | #define _METADATA_DECODER_H | |
9 | ||
1e649dff | 10 | #include <stdint.h> |
a2a54545 | 11 | #include <stdbool.h> |
087cd0f5 | 12 | #include <stdio.h> |
1e649dff | 13 | |
3fadfbc0 | 14 | #include <babeltrace2/babeltrace.h> |
1e649dff | 15 | |
91d81473 | 16 | #include "common/macros.h" |
06be9946 PP |
17 | #include "common/uuid.h" |
18 | ||
19 | struct ctf_trace_class; | |
91d81473 | 20 | |
1e649dff PP |
21 | /* A CTF metadata decoder object */ |
22 | struct ctf_metadata_decoder; | |
23 | ||
24 | /* CTF metadata decoder status */ | |
4164020e SM |
25 | enum ctf_metadata_decoder_status |
26 | { | |
27 | CTF_METADATA_DECODER_STATUS_OK = 0, | |
28 | CTF_METADATA_DECODER_STATUS_NONE = 1, | |
29 | CTF_METADATA_DECODER_STATUS_ERROR = -1, | |
30 | CTF_METADATA_DECODER_STATUS_INCOMPLETE = -2, | |
31 | CTF_METADATA_DECODER_STATUS_INVAL_VERSION = -3, | |
32 | CTF_METADATA_DECODER_STATUS_IR_VISITOR_ERROR = -4, | |
1e649dff PP |
33 | }; |
34 | ||
a2a54545 | 35 | /* Decoding configuration */ |
4164020e SM |
36 | struct ctf_metadata_decoder_config |
37 | { | |
38 | /* Active log level to use */ | |
39 | bt_logging_level log_level; | |
40 | ||
41 | /* | |
42 | * Component or component class to use for logging (exactly one of | |
43 | * them must be non-`NULL`); weak | |
44 | */ | |
45 | bt_self_component *self_comp; | |
46 | bt_self_component_class *self_comp_class; | |
47 | ||
48 | /* Additional clock class offset to apply */ | |
49 | int64_t clock_class_offset_s; | |
50 | int64_t clock_class_offset_ns; | |
51 | bool force_clock_class_origin_unix_epoch; | |
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 | */ | |
4164020e SM |
68 | struct ctf_metadata_decoder * |
69 | ctf_metadata_decoder_create(const struct ctf_metadata_decoder_config *config); | |
1e649dff PP |
70 | |
71 | /* | |
72 | * Destroys a CTF metadata decoder that you created with | |
73 | * ctf_metadata_decoder_create(). | |
74 | */ | |
4164020e | 75 | void ctf_metadata_decoder_destroy(struct ctf_metadata_decoder *metadata_decoder); |
1e649dff PP |
76 | |
77 | /* | |
06be9946 | 78 | * Appends content to the metadata decoder. |
1e649dff PP |
79 | * |
80 | * This function reads the metadata from the current position of `fp` | |
06be9946 | 81 | * until the end of this file stream. |
1e649dff PP |
82 | * |
83 | * The metadata can be packetized or not. | |
84 | * | |
06be9946 PP |
85 | * The metadata chunk needs to be complete and lexically scannable, that |
86 | * is, zero or more complete top-level blocks. If it's incomplete, this | |
1e649dff PP |
87 | * function returns `CTF_METADATA_DECODER_STATUS_INCOMPLETE`. If this |
88 | * function returns `CTF_METADATA_DECODER_STATUS_INCOMPLETE`, then you | |
06be9946 | 89 | * need to call it again with the _same_ metadata and more to make it |
1e649dff PP |
90 | * complete. For example: |
91 | * | |
92 | * First call: event { name = hell | |
93 | * Second call: event { name = hello_world; ... }; | |
94 | * | |
1e649dff PP |
95 | * If everything goes as expected, this function returns |
96 | * `CTF_METADATA_DECODER_STATUS_OK`. | |
97 | */ | |
4164020e SM |
98 | enum ctf_metadata_decoder_status |
99 | ctf_metadata_decoder_append_content(struct ctf_metadata_decoder *metadata_decoder, FILE *fp); | |
1e649dff | 100 | |
06be9946 PP |
101 | /* |
102 | * Returns the trace IR trace class of this metadata decoder (new | |
103 | * reference). | |
104 | * | |
105 | * Returns `NULL` if there's none yet or if the metadata decoder is not | |
106 | * configured to create trace classes. | |
107 | */ | |
4164020e | 108 | bt_trace_class *ctf_metadata_decoder_get_ir_trace_class(struct ctf_metadata_decoder *mdec); |
44c440bc | 109 | |
06be9946 PP |
110 | /* |
111 | * Returns the CTF IR trace class of this metadata decoder. | |
112 | * | |
113 | * Returns `NULL` if there's none yet or if the metadata decoder is not | |
114 | * configured to create trace classes. | |
115 | */ | |
4164020e SM |
116 | struct ctf_trace_class * |
117 | ctf_metadata_decoder_borrow_ctf_trace_class(struct ctf_metadata_decoder *mdec); | |
1e649dff PP |
118 | |
119 | /* | |
06be9946 PP |
120 | * Checks whether or not a given metadata file stream `fp` is |
121 | * packetized, setting `is_packetized` accordingly on success. On | |
122 | * success, also sets `*byte_order` to the byte order of the first | |
123 | * packet. | |
124 | * | |
125 | * This function uses `log_level` and `self_comp` for logging purposes. | |
126 | * `self_comp` can be `NULL` if not available. | |
1e649dff | 127 | */ |
4164020e SM |
128 | int ctf_metadata_decoder_is_packetized(FILE *fp, bool *is_packetized, int *byte_order, |
129 | bt_logging_level log_level, bt_self_component *self_comp); | |
1e649dff PP |
130 | |
131 | /* | |
06be9946 PP |
132 | * Returns the byte order of the decoder's metadata stream as set by the |
133 | * last call to ctf_metadata_decoder_append_content(). | |
134 | * | |
135 | * Returns -1 if unknown (plain text content). | |
1e649dff | 136 | */ |
06be9946 PP |
137 | int ctf_metadata_decoder_get_byte_order(struct ctf_metadata_decoder *mdec); |
138 | ||
139 | /* | |
140 | * Returns the UUID of the decoder's metadata stream as set by the last | |
141 | * call to ctf_metadata_decoder_append_content(). | |
1a6da3f9 | 142 | */ |
4164020e | 143 | int ctf_metadata_decoder_get_uuid(struct ctf_metadata_decoder *mdec, bt_uuid_t uuid); |
1a6da3f9 PP |
144 | |
145 | /* | |
146 | * Returns the UUID of the decoder's trace class, if available. | |
06be9946 | 147 | * |
1a6da3f9 PP |
148 | * Returns: |
149 | * | |
150 | * * `CTF_METADATA_DECODER_STATUS_OK`: success. | |
151 | * * `CTF_METADATA_DECODER_STATUS_NONE`: no UUID. | |
152 | * * `CTF_METADATA_DECODER_STATUS_INCOMPLETE`: missing metadata content. | |
06be9946 | 153 | */ |
4164020e SM |
154 | enum ctf_metadata_decoder_status |
155 | ctf_metadata_decoder_get_trace_class_uuid(struct ctf_metadata_decoder *mdec, bt_uuid_t uuid); | |
06be9946 PP |
156 | |
157 | /* | |
158 | * Returns the metadata decoder's current metadata text. | |
159 | */ | |
06be9946 | 160 | const char *ctf_metadata_decoder_get_text(struct ctf_metadata_decoder *mdec); |
1e649dff | 161 | |
4164020e SM |
162 | static inline bool ctf_metadata_decoder_is_packet_version_valid(unsigned int major, |
163 | unsigned int minor) | |
3c8252a5 | 164 | { |
4164020e | 165 | return major == 1 && minor == 8; |
3c8252a5 PP |
166 | } |
167 | ||
1e649dff | 168 | #endif /* _METADATA_DECODER_H */ |