Move to kernel style SPDX license identifiers
[babeltrace.git] / src / plugins / ctf / common / metadata / decoder.h
CommitLineData
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>
1e649dff 12
3fadfbc0 13#include <babeltrace2/babeltrace.h>
1e649dff 14
91d81473 15#include "common/macros.h"
06be9946
PP
16#include "common/uuid.h"
17
18struct ctf_trace_class;
91d81473 19
1e649dff
PP
20/* A CTF metadata decoder object */
21struct ctf_metadata_decoder;
22
23/* CTF metadata decoder status */
24enum ctf_metadata_decoder_status {
25 CTF_METADATA_DECODER_STATUS_OK = 0,
1a6da3f9 26 CTF_METADATA_DECODER_STATUS_NONE = 1,
1e649dff
PP
27 CTF_METADATA_DECODER_STATUS_ERROR = -1,
28 CTF_METADATA_DECODER_STATUS_INCOMPLETE = -2,
29 CTF_METADATA_DECODER_STATUS_INVAL_VERSION = -3,
30 CTF_METADATA_DECODER_STATUS_IR_VISITOR_ERROR = -4,
31};
32
a2a54545
PP
33/* Decoding configuration */
34struct ctf_metadata_decoder_config {
06be9946 35 /* Active log level to use */
0746848c 36 bt_logging_level log_level;
f7b785ac 37
06be9946 38 /* Component to use for logging (can be `NULL`); weak */
f7b785ac
PP
39 bt_self_component *self_comp;
40
06be9946 41 /* Additional clock class offset to apply */
a2a54545
PP
42 int64_t clock_class_offset_s;
43 int64_t clock_class_offset_ns;
c0aa240b 44 bool force_clock_class_origin_unix_epoch;
06be9946
PP
45
46 /* True to create trace class objects */
47 bool create_trace_class;
48
49 /*
50 * True to keep the plain text when content is appended with
51 * ctf_metadata_decoder_append_content().
52 */
53 bool keep_plain_text;
a2a54545
PP
54};
55
1e649dff 56/*
862ca4ed 57 * Creates a CTF metadata decoder.
1e649dff
PP
58 *
59 * Returns `NULL` on error.
60 */
61BT_HIDDEN
55314f2a 62struct ctf_metadata_decoder *ctf_metadata_decoder_create(
862ca4ed 63 const struct ctf_metadata_decoder_config *config);
1e649dff
PP
64
65/*
66 * Destroys a CTF metadata decoder that you created with
67 * ctf_metadata_decoder_create().
68 */
69BT_HIDDEN
70void ctf_metadata_decoder_destroy(
71 struct ctf_metadata_decoder *metadata_decoder);
72
73/*
06be9946 74 * Appends content to the metadata decoder.
1e649dff
PP
75 *
76 * This function reads the metadata from the current position of `fp`
06be9946 77 * until the end of this file stream.
1e649dff
PP
78 *
79 * The metadata can be packetized or not.
80 *
06be9946
PP
81 * The metadata chunk needs to be complete and lexically scannable, that
82 * is, zero or more complete top-level blocks. If it's incomplete, this
1e649dff
PP
83 * function returns `CTF_METADATA_DECODER_STATUS_INCOMPLETE`. If this
84 * function returns `CTF_METADATA_DECODER_STATUS_INCOMPLETE`, then you
06be9946 85 * need to call it again with the _same_ metadata and more to make it
1e649dff
PP
86 * complete. For example:
87 *
88 * First call: event { name = hell
89 * Second call: event { name = hello_world; ... };
90 *
1e649dff
PP
91 * If everything goes as expected, this function returns
92 * `CTF_METADATA_DECODER_STATUS_OK`.
93 */
94BT_HIDDEN
06be9946 95enum ctf_metadata_decoder_status ctf_metadata_decoder_append_content(
1e649dff
PP
96 struct ctf_metadata_decoder *metadata_decoder, FILE *fp);
97
06be9946
PP
98/*
99 * Returns the trace IR trace class of this metadata decoder (new
100 * reference).
101 *
102 * Returns `NULL` if there's none yet or if the metadata decoder is not
103 * configured to create trace classes.
104 */
1e649dff 105BT_HIDDEN
b19ff26f 106bt_trace_class *ctf_metadata_decoder_get_ir_trace_class(
44c440bc
PP
107 struct ctf_metadata_decoder *mdec);
108
06be9946
PP
109/*
110 * Returns the CTF IR trace class of this metadata decoder.
111 *
112 * Returns `NULL` if there's none yet or if the metadata decoder is not
113 * configured to create trace classes.
114 */
44c440bc
PP
115BT_HIDDEN
116struct ctf_trace_class *ctf_metadata_decoder_borrow_ctf_trace_class(
117 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
PP
127 */
128BT_HIDDEN
06be9946
PP
129int ctf_metadata_decoder_is_packetized(FILE *fp, bool *is_packetized,
130 int *byte_order, bt_logging_level log_level,
f7b785ac 131 bt_self_component *self_comp);
1e649dff
PP
132
133/*
06be9946
PP
134 * Returns the byte order of the decoder's metadata stream as set by the
135 * last call to ctf_metadata_decoder_append_content().
136 *
137 * Returns -1 if unknown (plain text content).
1e649dff
PP
138 */
139BT_HIDDEN
06be9946
PP
140int ctf_metadata_decoder_get_byte_order(struct ctf_metadata_decoder *mdec);
141
142/*
143 * Returns the UUID of the decoder's metadata stream as set by the last
144 * call to ctf_metadata_decoder_append_content().
1a6da3f9
PP
145 */
146BT_HIDDEN
147int ctf_metadata_decoder_get_uuid(
148 struct ctf_metadata_decoder *mdec, bt_uuid_t uuid);
149
150/*
151 * Returns the UUID of the decoder's trace class, if available.
06be9946 152 *
1a6da3f9
PP
153 * Returns:
154 *
155 * * `CTF_METADATA_DECODER_STATUS_OK`: success.
156 * * `CTF_METADATA_DECODER_STATUS_NONE`: no UUID.
157 * * `CTF_METADATA_DECODER_STATUS_INCOMPLETE`: missing metadata content.
06be9946
PP
158 */
159BT_HIDDEN
1a6da3f9
PP
160enum ctf_metadata_decoder_status ctf_metadata_decoder_get_trace_class_uuid(
161 struct ctf_metadata_decoder *mdec, bt_uuid_t uuid);
06be9946
PP
162
163/*
164 * Returns the metadata decoder's current metadata text.
165 */
166BT_HIDDEN
167const char *ctf_metadata_decoder_get_text(struct ctf_metadata_decoder *mdec);
1e649dff 168
3c8252a5
PP
169static inline
170bool ctf_metadata_decoder_is_packet_version_valid(unsigned int major,
171 unsigned int minor)
172{
173 return major == 1 && minor == 8;
174}
175
1e649dff 176#endif /* _METADATA_DECODER_H */
This page took 0.070273 seconds and 4 git commands to generate.