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