Cleanup: remove private babeltrace.h
[babeltrace.git] / src / plugins / ctf / common / metadata / decoder.h
CommitLineData
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>
53ac3428 19#include <stdbool.h>
1e649dff 20
71c5da58 21#include <babeltrace2/babeltrace.h>
1e649dff 22
85e7137b
MJ
23#include "common/macros.h"
24
1e649dff
PP
25/* A CTF metadata decoder object */
26struct ctf_metadata_decoder;
27
28/* CTF metadata decoder status */
29enum 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,
35};
36
53ac3428
PP
37/* Decoding configuration */
38struct ctf_metadata_decoder_config {
39 int64_t clock_class_offset_s;
40 int64_t clock_class_offset_ns;
53ac3428
PP
41};
42
1e649dff 43/*
10b7a2e4 44 * Creates a CTF metadata decoder.
1e649dff
PP
45 *
46 * Returns `NULL` on error.
47 */
48BT_HIDDEN
55314f2a 49struct ctf_metadata_decoder *ctf_metadata_decoder_create(
e5e71bf8 50 bt_self_component_source *self_comp,
10b7a2e4 51 const struct ctf_metadata_decoder_config *config);
1e649dff
PP
52
53/*
54 * Destroys a CTF metadata decoder that you created with
55 * ctf_metadata_decoder_create().
56 */
57BT_HIDDEN
58void ctf_metadata_decoder_destroy(
59 struct ctf_metadata_decoder *metadata_decoder);
60
61/*
62 * Decodes a new chunk of CTF metadata.
63 *
64 * This function reads the metadata from the current position of `fp`
65 * until the end of this file stream. If it finds new information (new
66 * event class, new stream class, or new clock class), it appends this
67 * information to the decoder's trace object (as returned by
10b7a2e4 68 * ctf_metadata_decoder_get_ir_trace_class()), or it creates this trace.
1e649dff
PP
69 *
70 * The metadata can be packetized or not.
71 *
72 * The metadata chunk needs to be complete and scannable, that is,
73 * zero or more complete top-level blocks. If it's incomplete, this
74 * function returns `CTF_METADATA_DECODER_STATUS_INCOMPLETE`. If this
75 * function returns `CTF_METADATA_DECODER_STATUS_INCOMPLETE`, then you
76 * need to call it again with the same metadata and more to make it
77 * complete. For example:
78 *
79 * First call: event { name = hell
80 * Second call: event { name = hello_world; ... };
81 *
82 * If the conversion from the metadata text to CTF IR objects fails,
83 * this function returns `CTF_METADATA_DECODER_STATUS_IR_VISITOR_ERROR`.
84 *
85 * If everything goes as expected, this function returns
86 * `CTF_METADATA_DECODER_STATUS_OK`.
87 */
88BT_HIDDEN
89enum ctf_metadata_decoder_status ctf_metadata_decoder_decode(
90 struct ctf_metadata_decoder *metadata_decoder, FILE *fp);
91
1e649dff 92BT_HIDDEN
8eee8ea2 93bt_trace_class *ctf_metadata_decoder_get_ir_trace_class(
7b33a0e0
PP
94 struct ctf_metadata_decoder *mdec);
95
96BT_HIDDEN
97struct ctf_trace_class *ctf_metadata_decoder_borrow_ctf_trace_class(
98 struct ctf_metadata_decoder *mdec);
1e649dff
PP
99
100/*
101 * Checks whether or not a given metadata file stream is packetized, and
102 * if so, sets `*byte_order` to the byte order of the first packet.
103 */
104BT_HIDDEN
105bool ctf_metadata_decoder_is_packetized(FILE *fp, int *byte_order);
106
107/*
108 * Decodes a packetized metadata file stream to a NULL-terminated
109 * text buffer using the given byte order.
110 */
111BT_HIDDEN
112int ctf_metadata_decoder_packetized_file_stream_to_buf(
113 FILE *fp, char **buf, int byte_order);
114
115#endif /* _METADATA_DECODER_H */
This page took 0.042597 seconds and 4 git commands to generate.