ctf: refactor metadata decoder to always have an instance
[babeltrace.git] / src / plugins / ctf / common / metadata / decoder.h
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>
19 #include <stdbool.h>
20
21 #include <babeltrace2/babeltrace.h>
22
23 #include "common/macros.h"
24 #include "common/uuid.h"
25
26 struct ctf_trace_class;
27
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
40 /* Decoding configuration */
41 struct ctf_metadata_decoder_config {
42 /* Active log level to use */
43 bt_logging_level log_level;
44
45 /* Component to use for logging (can be `NULL`); weak */
46 bt_self_component *self_comp;
47
48 /* Additional clock class offset to apply */
49 int64_t clock_class_offset_s;
50 int64_t clock_class_offset_ns;
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;
60 };
61
62 /*
63 * Creates a CTF metadata decoder.
64 *
65 * Returns `NULL` on error.
66 */
67 BT_HIDDEN
68 struct ctf_metadata_decoder *ctf_metadata_decoder_create(
69 const struct ctf_metadata_decoder_config *config);
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 /*
80 * Appends content to the metadata decoder.
81 *
82 * This function reads the metadata from the current position of `fp`
83 * until the end of this file stream.
84 *
85 * The metadata can be packetized or not.
86 *
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
89 * function returns `CTF_METADATA_DECODER_STATUS_INCOMPLETE`. If this
90 * function returns `CTF_METADATA_DECODER_STATUS_INCOMPLETE`, then you
91 * need to call it again with the _same_ metadata and more to make it
92 * complete. For example:
93 *
94 * First call: event { name = hell
95 * Second call: event { name = hello_world; ... };
96 *
97 * If everything goes as expected, this function returns
98 * `CTF_METADATA_DECODER_STATUS_OK`.
99 */
100 BT_HIDDEN
101 enum ctf_metadata_decoder_status ctf_metadata_decoder_append_content(
102 struct ctf_metadata_decoder *metadata_decoder, FILE *fp);
103
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 */
111 BT_HIDDEN
112 bt_trace_class *ctf_metadata_decoder_get_ir_trace_class(
113 struct ctf_metadata_decoder *mdec);
114
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 */
121 BT_HIDDEN
122 struct ctf_trace_class *ctf_metadata_decoder_borrow_ctf_trace_class(
123 struct ctf_metadata_decoder *mdec);
124
125 /*
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.
133 */
134 BT_HIDDEN
135 int ctf_metadata_decoder_is_packetized(FILE *fp, bool *is_packetized,
136 int *byte_order, bt_logging_level log_level,
137 bt_self_component *self_comp);
138
139 /*
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).
144 */
145 BT_HIDDEN
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);
163
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
171 #endif /* _METADATA_DECODER_H */
This page took 0.033951 seconds and 5 git commands to generate.