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"
25 /* A CTF metadata decoder object */
26 struct ctf_metadata_decoder
;
28 /* CTF metadata decoder status */
29 enum ctf_metadata_decoder_status
{
30 CTF_METADATA_DECODER_STATUS_OK
= 0,
31 CTF_METADATA_DECODER_STATUS_ERROR
= -1,
32 CTF_METADATA_DECODER_STATUS_INCOMPLETE
= -2,
33 CTF_METADATA_DECODER_STATUS_INVAL_VERSION
= -3,
34 CTF_METADATA_DECODER_STATUS_IR_VISITOR_ERROR
= -4,
37 /* Decoding configuration */
38 struct ctf_metadata_decoder_config
{
39 bt_logging_level log_level
;
40 int64_t clock_class_offset_s
;
41 int64_t clock_class_offset_ns
;
45 * Creates a CTF metadata decoder.
47 * Returns `NULL` on error.
50 struct ctf_metadata_decoder
*ctf_metadata_decoder_create(
51 bt_self_component_source
*self_comp
,
52 const struct ctf_metadata_decoder_config
*config
);
55 * Destroys a CTF metadata decoder that you created with
56 * ctf_metadata_decoder_create().
59 void ctf_metadata_decoder_destroy(
60 struct ctf_metadata_decoder
*metadata_decoder
);
63 * Decodes a new chunk of CTF metadata.
65 * This function reads the metadata from the current position of `fp`
66 * until the end of this file stream. If it finds new information (new
67 * event class, new stream class, or new clock class), it appends this
68 * information to the decoder's trace object (as returned by
69 * ctf_metadata_decoder_get_ir_trace_class()), or it creates this trace.
71 * The metadata can be packetized or not.
73 * The metadata chunk needs to be complete and scannable, that is,
74 * zero or more complete top-level blocks. If it's incomplete, this
75 * function returns `CTF_METADATA_DECODER_STATUS_INCOMPLETE`. If this
76 * function returns `CTF_METADATA_DECODER_STATUS_INCOMPLETE`, then you
77 * need to call it again with the same metadata and more to make it
78 * complete. For example:
80 * First call: event { name = hell
81 * Second call: event { name = hello_world; ... };
83 * If the conversion from the metadata text to CTF IR objects fails,
84 * this function returns `CTF_METADATA_DECODER_STATUS_IR_VISITOR_ERROR`.
86 * If everything goes as expected, this function returns
87 * `CTF_METADATA_DECODER_STATUS_OK`.
90 enum ctf_metadata_decoder_status
ctf_metadata_decoder_decode(
91 struct ctf_metadata_decoder
*metadata_decoder
, FILE *fp
);
94 bt_trace_class
*ctf_metadata_decoder_get_ir_trace_class(
95 struct ctf_metadata_decoder
*mdec
);
98 struct ctf_trace_class
*ctf_metadata_decoder_borrow_ctf_trace_class(
99 struct ctf_metadata_decoder
*mdec
);
102 * Checks whether or not a given metadata file stream is packetized, and
103 * if so, sets `*byte_order` to the byte order of the first packet.
106 bool ctf_metadata_decoder_is_packetized(FILE *fp
, int *byte_order
,
107 bt_logging_level log_level
);
110 * Decodes a packetized metadata file stream to a NULL-terminated
111 * text buffer using the given byte order.
114 int ctf_metadata_decoder_packetized_file_stream_to_buf(
115 FILE *fp
, char **buf
, int byte_order
,
116 bt_logging_level log_level
);
118 #endif /* _METADATA_DECODER_H */