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, | |
34 | CTF_METADATA_DECODER_STATUS_ERROR = -1, | |
35 | CTF_METADATA_DECODER_STATUS_INCOMPLETE = -2, | |
36 | CTF_METADATA_DECODER_STATUS_INVAL_VERSION = -3, | |
37 | CTF_METADATA_DECODER_STATUS_IR_VISITOR_ERROR = -4, | |
38 | }; | |
39 | ||
a2a54545 PP |
40 | /* Decoding configuration */ |
41 | struct ctf_metadata_decoder_config { | |
06be9946 | 42 | /* Active log level to use */ |
0746848c | 43 | bt_logging_level log_level; |
f7b785ac | 44 | |
06be9946 | 45 | /* Component to use for logging (can be `NULL`); weak */ |
f7b785ac PP |
46 | bt_self_component *self_comp; |
47 | ||
06be9946 | 48 | /* Additional clock class offset to apply */ |
a2a54545 PP |
49 | int64_t clock_class_offset_s; |
50 | int64_t clock_class_offset_ns; | |
06be9946 PP |
51 | |
52 | /* True to create trace class objects */ | |
53 | bool create_trace_class; | |
54 | ||
55 | /* | |
56 | * True to keep the plain text when content is appended with | |
57 | * ctf_metadata_decoder_append_content(). | |
58 | */ | |
59 | bool keep_plain_text; | |
a2a54545 PP |
60 | }; |
61 | ||
1e649dff | 62 | /* |
862ca4ed | 63 | * Creates a CTF metadata decoder. |
1e649dff PP |
64 | * |
65 | * Returns `NULL` on error. | |
66 | */ | |
67 | BT_HIDDEN | |
55314f2a | 68 | struct ctf_metadata_decoder *ctf_metadata_decoder_create( |
862ca4ed | 69 | 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 | */ | |
75 | BT_HIDDEN | |
76 | void ctf_metadata_decoder_destroy( | |
77 | struct ctf_metadata_decoder *metadata_decoder); | |
78 | ||
79 | /* | |
06be9946 | 80 | * Appends content to the metadata decoder. |
1e649dff PP |
81 | * |
82 | * This function reads the metadata from the current position of `fp` | |
06be9946 | 83 | * until the end of this file stream. |
1e649dff PP |
84 | * |
85 | * The metadata can be packetized or not. | |
86 | * | |
06be9946 PP |
87 | * The metadata chunk needs to be complete and lexically scannable, that |
88 | * is, zero or more complete top-level blocks. If it's incomplete, this | |
1e649dff PP |
89 | * function returns `CTF_METADATA_DECODER_STATUS_INCOMPLETE`. If this |
90 | * function returns `CTF_METADATA_DECODER_STATUS_INCOMPLETE`, then you | |
06be9946 | 91 | * need to call it again with the _same_ metadata and more to make it |
1e649dff PP |
92 | * complete. For example: |
93 | * | |
94 | * First call: event { name = hell | |
95 | * Second call: event { name = hello_world; ... }; | |
96 | * | |
1e649dff PP |
97 | * If everything goes as expected, this function returns |
98 | * `CTF_METADATA_DECODER_STATUS_OK`. | |
99 | */ | |
100 | BT_HIDDEN | |
06be9946 | 101 | enum ctf_metadata_decoder_status ctf_metadata_decoder_append_content( |
1e649dff PP |
102 | struct ctf_metadata_decoder *metadata_decoder, FILE *fp); |
103 | ||
06be9946 PP |
104 | /* |
105 | * Returns the trace IR trace class of this metadata decoder (new | |
106 | * reference). | |
107 | * | |
108 | * Returns `NULL` if there's none yet or if the metadata decoder is not | |
109 | * configured to create trace classes. | |
110 | */ | |
1e649dff | 111 | BT_HIDDEN |
b19ff26f | 112 | bt_trace_class *ctf_metadata_decoder_get_ir_trace_class( |
44c440bc PP |
113 | struct ctf_metadata_decoder *mdec); |
114 | ||
06be9946 PP |
115 | /* |
116 | * Returns the CTF IR trace class of this metadata decoder. | |
117 | * | |
118 | * Returns `NULL` if there's none yet or if the metadata decoder is not | |
119 | * configured to create trace classes. | |
120 | */ | |
44c440bc PP |
121 | BT_HIDDEN |
122 | struct ctf_trace_class *ctf_metadata_decoder_borrow_ctf_trace_class( | |
123 | struct ctf_metadata_decoder *mdec); | |
1e649dff PP |
124 | |
125 | /* | |
06be9946 PP |
126 | * Checks whether or not a given metadata file stream `fp` is |
127 | * packetized, setting `is_packetized` accordingly on success. On | |
128 | * success, also sets `*byte_order` to the byte order of the first | |
129 | * packet. | |
130 | * | |
131 | * This function uses `log_level` and `self_comp` for logging purposes. | |
132 | * `self_comp` can be `NULL` if not available. | |
1e649dff PP |
133 | */ |
134 | BT_HIDDEN | |
06be9946 PP |
135 | int ctf_metadata_decoder_is_packetized(FILE *fp, bool *is_packetized, |
136 | int *byte_order, bt_logging_level log_level, | |
f7b785ac | 137 | bt_self_component *self_comp); |
1e649dff PP |
138 | |
139 | /* | |
06be9946 PP |
140 | * Returns the byte order of the decoder's metadata stream as set by the |
141 | * last call to ctf_metadata_decoder_append_content(). | |
142 | * | |
143 | * Returns -1 if unknown (plain text content). | |
1e649dff PP |
144 | */ |
145 | BT_HIDDEN | |
06be9946 PP |
146 | int ctf_metadata_decoder_get_byte_order(struct ctf_metadata_decoder *mdec); |
147 | ||
148 | /* | |
149 | * Returns the UUID of the decoder's metadata stream as set by the last | |
150 | * call to ctf_metadata_decoder_append_content(). | |
151 | * | |
152 | * Returns -1 if unknown (plain text content). | |
153 | */ | |
154 | BT_HIDDEN | |
155 | int ctf_metadata_decoder_get_uuid(struct ctf_metadata_decoder *mdec, | |
156 | bt_uuid_t uuid); | |
157 | ||
158 | /* | |
159 | * Returns the metadata decoder's current metadata text. | |
160 | */ | |
161 | BT_HIDDEN | |
162 | const char *ctf_metadata_decoder_get_text(struct ctf_metadata_decoder *mdec); | |
1e649dff | 163 | |
3c8252a5 PP |
164 | static inline |
165 | bool ctf_metadata_decoder_is_packet_version_valid(unsigned int major, | |
166 | unsigned int minor) | |
167 | { | |
168 | return major == 1 && minor == 8; | |
169 | } | |
170 | ||
1e649dff | 171 | #endif /* _METADATA_DECODER_H */ |