2 * SPDX-License-Identifier: MIT
4 * Copyright 2016 Philippe Proulx <pproulx@efficios.com>
5 * Copyright 2010-2011 EfficiOS Inc. and Linux Foundation
8 #include "common/assert.h"
10 #include "../common/src/metadata/tsdl/decoder.hpp"
13 #include "metadata.hpp"
15 FILE *ctf_fs_metadata_open_file(const char *trace_path
, const bt2c::Logger
& logger
)
17 GString
*metadata_path
;
20 metadata_path
= g_string_new(trace_path
);
25 g_string_append(metadata_path
, G_DIR_SEPARATOR_S CTF_FS_METADATA_FILENAME
);
26 fp
= fopen(metadata_path
->str
, "rb");
28 BT_CPPLOGE_ERRNO_APPEND_CAUSE_SPEC(logger
, "Failed to open metadata file", ": path=\"{}\"",
32 g_string_free(metadata_path
, TRUE
);
38 static struct ctf_fs_file
*get_file(const char *trace_path
, const bt2c::Logger
& logger
)
40 struct ctf_fs_file
*file
= ctf_fs_file_create(logger
);
46 g_string_append(file
->path
, trace_path
);
47 g_string_append(file
->path
, G_DIR_SEPARATOR_S CTF_FS_METADATA_FILENAME
);
49 if (ctf_fs_file_open(file
, "rb")) {
57 ctf_fs_file_destroy(file
);
65 int ctf_fs_metadata_set_trace_class(bt_self_component
*self_comp
, struct ctf_fs_trace
*ctf_fs_trace
,
66 const ctf::src::ClkClsCfg
& clkClsCfg
)
69 struct ctf_fs_file
*file
= NULL
;
70 ctf_metadata_decoder_config decoder_config
{ctf_fs_trace
->logger
};
72 decoder_config
.self_comp
= self_comp
;
73 decoder_config
.clkClsCfg
= clkClsCfg
;
74 decoder_config
.create_trace_class
= true;
76 file
= get_file(ctf_fs_trace
->path
->str
, ctf_fs_trace
->logger
);
78 BT_CPPLOGE_SPEC(ctf_fs_trace
->logger
, "Cannot create metadata file object.");
83 ctf_fs_trace
->metadata
->decoder
= ctf_metadata_decoder_create(&decoder_config
);
84 if (!ctf_fs_trace
->metadata
->decoder
) {
85 BT_CPPLOGE_SPEC(ctf_fs_trace
->logger
, "Cannot create metadata decoder object.");
90 ret
= ctf_metadata_decoder_append_content(ctf_fs_trace
->metadata
->decoder
.get(), file
->fp
);
92 BT_CPPLOGE_SPEC(ctf_fs_trace
->logger
, "Cannot update metadata decoder's content.");
96 ctf_fs_trace
->metadata
->trace_class
=
97 ctf_metadata_decoder_get_ir_trace_class(ctf_fs_trace
->metadata
->decoder
.get());
98 BT_ASSERT(!self_comp
|| ctf_fs_trace
->metadata
->trace_class
);
99 ctf_fs_trace
->metadata
->tc
=
100 ctf_metadata_decoder_borrow_ctf_trace_class(ctf_fs_trace
->metadata
->decoder
.get());
101 BT_ASSERT(ctf_fs_trace
->metadata
->tc
);
104 ctf_fs_file_destroy(file
);
108 int ctf_fs_metadata_init(struct ctf_fs_metadata
*)
110 /* Nothing to initialize for the moment. */
114 void ctf_fs_metadata_fini(struct ctf_fs_metadata
*metadata
)
116 free(metadata
->text
);
118 if (metadata
->trace_class
) {
119 BT_TRACE_CLASS_PUT_REF_AND_RESET(metadata
->trace_class
);
122 metadata
->decoder
.reset();