Remove some unused includes in C++ files
[babeltrace.git] / src / plugins / ctf / fs-src / metadata.cpp
CommitLineData
e98a2d6e 1/*
0235b0db 2 * SPDX-License-Identifier: MIT
e98a2d6e 3 *
0235b0db
MJ
4 * Copyright 2016 Philippe Proulx <pproulx@efficios.com>
5 * Copyright 2010-2011 EfficiOS Inc. and Linux Foundation
e98a2d6e
PP
6 */
7
c802cacb 8#include <glib.h>
c802cacb
SM
9#include <stdio.h>
10#include <stdlib.h>
11
12#include <babeltrace2/babeltrace.h>
13
4c65a157 14#define BT_COMP_LOG_SELF_COMP self_comp
4164020e
SM
15#define BT_LOG_OUTPUT_LEVEL log_level
16#define BT_LOG_TAG "PLUGIN/SRC.CTF.FS/META"
d9c39b0a 17#include "logging/comp-logging.h"
98903a3e 18
578e048b 19#include "common/assert.h"
e98a2d6e 20
c802cacb 21#include "../common/metadata/decoder.hpp"
087cd0f5 22#include "file.hpp"
c802cacb 23#include "fs.hpp"
087cd0f5 24#include "metadata.hpp"
e98a2d6e 25
0ac40cd4
SM
26FILE *ctf_fs_metadata_open_file(const char *trace_path, bt_logging_level log_level,
27 bt_self_component_class *comp_class)
33f93973 28{
4164020e
SM
29 GString *metadata_path;
30 FILE *fp = NULL;
33f93973 31
4164020e
SM
32 metadata_path = g_string_new(trace_path);
33 if (!metadata_path) {
34 goto end;
35 }
33f93973 36
4164020e
SM
37 g_string_append(metadata_path, G_DIR_SEPARATOR_S CTF_FS_METADATA_FILENAME);
38 fp = fopen(metadata_path->str, "rb");
0ac40cd4
SM
39 if (!fp) {
40 BT_COMP_CLASS_LOGE_APPEND_CAUSE_ERRNO(comp_class, "Failed to open metadata file",
41 ": path=\"%s\"", metadata_path->str);
42 }
43
4164020e 44 g_string_free(metadata_path, TRUE);
0ac40cd4 45
4dd8c9bf 46end:
4164020e 47 return fp;
33f93973
PP
48}
49
4164020e
SM
50static struct ctf_fs_file *get_file(const char *trace_path, bt_logging_level log_level,
51 bt_self_component *self_comp)
e98a2d6e 52{
4164020e 53 struct ctf_fs_file *file = ctf_fs_file_create(log_level, self_comp);
e98a2d6e 54
4164020e
SM
55 if (!file) {
56 goto error;
57 }
e98a2d6e 58
4164020e
SM
59 g_string_append(file->path, trace_path);
60 g_string_append(file->path, G_DIR_SEPARATOR_S CTF_FS_METADATA_FILENAME);
e98a2d6e 61
4164020e
SM
62 if (ctf_fs_file_open(file, "rb")) {
63 goto error;
64 }
e98a2d6e 65
4164020e 66 goto end;
e98a2d6e
PP
67
68error:
4164020e
SM
69 if (file) {
70 ctf_fs_file_destroy(file);
71 file = NULL;
72 }
e98a2d6e
PP
73
74end:
4164020e 75 return file;
e98a2d6e
PP
76}
77
4164020e
SM
78int ctf_fs_metadata_set_trace_class(bt_self_component *self_comp, struct ctf_fs_trace *ctf_fs_trace,
79 struct ctf_fs_metadata_config *config)
e98a2d6e 80{
4164020e
SM
81 int ret = 0;
82 struct ctf_fs_file *file = NULL;
83 bt_logging_level log_level = ctf_fs_trace->log_level;
84
85 ctf_metadata_decoder_config decoder_config {};
86 decoder_config.log_level = ctf_fs_trace->log_level, decoder_config.self_comp = self_comp,
87 decoder_config.clock_class_offset_s = config ? config->clock_class_offset_s : 0,
88 decoder_config.clock_class_offset_ns = config ? config->clock_class_offset_ns : 0,
89 decoder_config.force_clock_class_origin_unix_epoch =
90 config ? config->force_clock_class_origin_unix_epoch : false,
91 decoder_config.create_trace_class = true,
92
93 file = get_file(ctf_fs_trace->path->str, log_level, self_comp);
94 if (!file) {
95 BT_COMP_LOGE("Cannot create metadata file object.");
96 ret = -1;
97 goto end;
98 }
99
100 ctf_fs_trace->metadata->decoder = ctf_metadata_decoder_create(&decoder_config);
101 if (!ctf_fs_trace->metadata->decoder) {
102 BT_COMP_LOGE("Cannot create metadata decoder object.");
103 ret = -1;
104 goto end;
105 }
106
107 ret = ctf_metadata_decoder_append_content(ctf_fs_trace->metadata->decoder, file->fp);
108 if (ret) {
109 BT_COMP_LOGE("Cannot update metadata decoder's content.");
110 goto end;
111 }
112
113 ctf_fs_trace->metadata->trace_class =
114 ctf_metadata_decoder_get_ir_trace_class(ctf_fs_trace->metadata->decoder);
115 BT_ASSERT(!self_comp || ctf_fs_trace->metadata->trace_class);
116 ctf_fs_trace->metadata->tc =
117 ctf_metadata_decoder_borrow_ctf_trace_class(ctf_fs_trace->metadata->decoder);
118 BT_ASSERT(ctf_fs_trace->metadata->tc);
4f1f88a6 119
e98a2d6e 120end:
4164020e
SM
121 ctf_fs_file_destroy(file);
122 return ret;
e98a2d6e
PP
123}
124
ecd7492f 125int ctf_fs_metadata_init(struct ctf_fs_metadata *)
e98a2d6e 126{
4164020e
SM
127 /* Nothing to initialize for the moment. */
128 return 0;
e98a2d6e
PP
129}
130
413bc2c4 131void ctf_fs_metadata_fini(struct ctf_fs_metadata *metadata)
e98a2d6e 132{
4164020e 133 free(metadata->text);
e98a2d6e 134
4164020e
SM
135 if (metadata->trace_class) {
136 BT_TRACE_CLASS_PUT_REF_AND_RESET(metadata->trace_class);
137 }
44c440bc 138
4164020e
SM
139 if (metadata->decoder) {
140 ctf_metadata_decoder_destroy(metadata->decoder);
141 }
e98a2d6e 142}
This page took 0.099686 seconds and 4 git commands to generate.