src.ctf.fs: remove uneeded check in create_streams_for_trace
[deliverable/babeltrace.git] / src / plugins / ctf / fs-src / metadata.cpp
1 /*
2 * SPDX-License-Identifier: MIT
3 *
4 * Copyright 2016 Philippe Proulx <pproulx@efficios.com>
5 * Copyright 2010-2011 EfficiOS Inc. and Linux Foundation
6 */
7
8 #define BT_CLOG_CFG logCfg
9 #define BT_LOG_TAG "PLUGIN/SRC.CTF.FS/META"
10
11 #include <stdio.h>
12 #include <stdint.h>
13 #include <stdlib.h>
14 #include "common/assert.h"
15 #include <glib.h>
16 #include "common/uuid.h"
17 #include "compat/memstream.h"
18 #include <babeltrace2/babeltrace.h>
19
20 #include "fs.hpp"
21 #include "file.hpp"
22 #include "metadata.hpp"
23 #include "../common/src/metadata/tsdl/decoder.hpp"
24 #include "cpp-common/cfg-logging.hpp"
25
26 BT_HIDDEN
27 FILE *ctf_fs_metadata_open_file(const char *trace_path)
28 {
29 GString *metadata_path;
30 FILE *fp = NULL;
31
32 metadata_path = g_string_new(trace_path);
33 if (!metadata_path) {
34 goto end;
35 }
36
37 g_string_append(metadata_path, G_DIR_SEPARATOR_S CTF_FS_METADATA_FILENAME);
38 fp = fopen(metadata_path->str, "rb");
39 g_string_free(metadata_path, TRUE);
40 end:
41 return fp;
42 }
43
44 static struct ctf_fs_file *get_file(const char *trace_path, const bt2_common::LogCfg& logCfg)
45 {
46 struct ctf_fs_file *file = ctf_fs_file_create(logCfg);
47
48 if (!file) {
49 goto error;
50 }
51
52 g_string_append(file->path, trace_path);
53 g_string_append(file->path, G_DIR_SEPARATOR_S CTF_FS_METADATA_FILENAME);
54
55 if (ctf_fs_file_open(file, "rb")) {
56 goto error;
57 }
58
59 goto end;
60
61 error:
62 if (file) {
63 ctf_fs_file_destroy(file);
64 file = NULL;
65 }
66
67 end:
68 return file;
69 }
70
71 BT_HIDDEN
72 int ctf_fs_metadata_set_trace_class(struct ctf_fs_trace *ctf_fs_trace,
73 struct ctf_fs_metadata_config *config,
74 bt_self_component *selfComp, const bt2_common::LogCfg& logCfg)
75 {
76 int ret = 0;
77 struct ctf_fs_file *file = NULL;
78
79 ctf_metadata_decoder_config decoder_config(logCfg);
80 decoder_config.clock_class_offset_s = config ? config->clock_class_offset_s : 0;
81 decoder_config.clock_class_offset_ns = config ? config->clock_class_offset_ns : 0;
82 decoder_config.force_clock_class_origin_unix_epoch =
83 config ? config->force_clock_class_origin_unix_epoch : false;
84 decoder_config.create_trace_class = true;
85 decoder_config.self_comp = selfComp;
86
87 file = get_file(ctf_fs_trace->path->str, logCfg);
88 if (!file) {
89 BT_CLOGE("Cannot create metadata file object.");
90 ret = -1;
91 goto end;
92 }
93
94 ctf_fs_trace->metadata->decoder = ctf_metadata_decoder_create(&decoder_config);
95 if (!ctf_fs_trace->metadata->decoder) {
96 BT_CLOGE("Cannot create metadata decoder object.");
97 ret = -1;
98 goto end;
99 }
100
101 ret = ctf_metadata_decoder_append_content(ctf_fs_trace->metadata->decoder.get(), file->fp);
102 if (ret) {
103 BT_CLOGE("Cannot update metadata decoder's content.");
104 goto end;
105 }
106
107 ctf_fs_trace->metadata->trace_class =
108 ctf_metadata_decoder_get_ir_trace_class(ctf_fs_trace->metadata->decoder.get());
109 ctf_fs_trace->metadata->tc =
110 ctf_metadata_decoder_borrow_ctf_trace_class(ctf_fs_trace->metadata->decoder.get());
111 BT_ASSERT(ctf_fs_trace->metadata->tc);
112
113 end:
114 ctf_fs_file_destroy(file);
115 return ret;
116 }
117
118 BT_HIDDEN
119 int ctf_fs_metadata_init(struct ctf_fs_metadata *metadata)
120 {
121 /* Nothing to initialize for the moment. */
122 return 0;
123 }
124
125 BT_HIDDEN
126 void ctf_fs_metadata_fini(struct ctf_fs_metadata *metadata)
127 {
128 free(metadata->text);
129
130 if (metadata->trace_class) {
131 BT_TRACE_CLASS_PUT_REF_AND_RESET(metadata->trace_class);
132 }
133
134 metadata->decoder.reset();
135 }
This page took 0.033379 seconds and 5 git commands to generate.