1 #ifndef _METADATA_DECODER_H
2 #define _METADATA_DECODER_H
5 * Copyright 2016-2017 - Philippe Proulx <pproulx@efficios.com>
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:
14 * The above copyright notice and this permission notice shall be included in
15 * all copies or substantial portions of the Software.
21 #include <babeltrace2/babeltrace.h>
23 #include "common/macros.h"
24 #include "common/uuid.h"
26 struct ctf_trace_class
;
28 /* A CTF metadata decoder object */
29 struct ctf_metadata_decoder
;
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,
40 /* Decoding configuration */
41 struct ctf_metadata_decoder_config
{
42 /* Active log level to use */
43 bt_logging_level log_level
;
45 /* Component to use for logging (can be `NULL`); weak */
46 bt_self_component
*self_comp
;
48 /* Additional clock class offset to apply */
49 int64_t clock_class_offset_s
;
50 int64_t clock_class_offset_ns
;
52 /* True to create trace class objects */
53 bool create_trace_class
;
56 * True to keep the plain text when content is appended with
57 * ctf_metadata_decoder_append_content().
63 * Creates a CTF metadata decoder.
65 * Returns `NULL` on error.
68 struct ctf_metadata_decoder
*ctf_metadata_decoder_create(
69 const struct ctf_metadata_decoder_config
*config
);
72 * Destroys a CTF metadata decoder that you created with
73 * ctf_metadata_decoder_create().
76 void ctf_metadata_decoder_destroy(
77 struct ctf_metadata_decoder
*metadata_decoder
);
80 * Appends content to the metadata decoder.
82 * This function reads the metadata from the current position of `fp`
83 * until the end of this file stream.
85 * The metadata can be packetized or not.
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:
94 * First call: event { name = hell
95 * Second call: event { name = hello_world; ... };
97 * If everything goes as expected, this function returns
98 * `CTF_METADATA_DECODER_STATUS_OK`.
101 enum ctf_metadata_decoder_status
ctf_metadata_decoder_append_content(
102 struct ctf_metadata_decoder
*metadata_decoder
, FILE *fp
);
105 * Returns the trace IR trace class of this metadata decoder (new
108 * Returns `NULL` if there's none yet or if the metadata decoder is not
109 * configured to create trace classes.
112 bt_trace_class
*ctf_metadata_decoder_get_ir_trace_class(
113 struct ctf_metadata_decoder
*mdec
);
116 * Returns the CTF IR trace class of this metadata decoder.
118 * Returns `NULL` if there's none yet or if the metadata decoder is not
119 * configured to create trace classes.
122 struct ctf_trace_class
*ctf_metadata_decoder_borrow_ctf_trace_class(
123 struct ctf_metadata_decoder
*mdec
);
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
131 * This function uses `log_level` and `self_comp` for logging purposes.
132 * `self_comp` can be `NULL` if not available.
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
);
140 * Returns the byte order of the decoder's metadata stream as set by the
141 * last call to ctf_metadata_decoder_append_content().
143 * Returns -1 if unknown (plain text content).
146 int ctf_metadata_decoder_get_byte_order(struct ctf_metadata_decoder
*mdec
);
149 * Returns the UUID of the decoder's metadata stream as set by the last
150 * call to ctf_metadata_decoder_append_content().
152 * Returns -1 if unknown (plain text content).
155 int ctf_metadata_decoder_get_uuid(struct ctf_metadata_decoder
*mdec
,
159 * Returns the metadata decoder's current metadata text.
162 const char *ctf_metadata_decoder_get_text(struct ctf_metadata_decoder
*mdec
);
165 bool ctf_metadata_decoder_is_packet_version_valid(unsigned int major
,
168 return major
== 1 && minor
== 8;
171 #endif /* _METADATA_DECODER_H */