2 * Copyright 2016 - Philippe Proulx <pproulx@efficios.com>
3 * Copyright 2010-2011 - EfficiOS Inc. and Linux Foundation
5 * Some functions are based on older functions written by Mathieu Desnoyers.
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:
14 * The above copyright notice and this permission notice shall be included in
15 * all copies or substantial portions of the Software.
17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
32 #include <babeltrace/compat/uuid-internal.h>
33 #include <babeltrace/compat/memstream-internal.h>
35 #define PRINT_ERR_STREAM ctf_fs->error_fp
36 #define PRINT_PREFIX "ctf-fs-metadata"
37 #define PRINT_DBG_CHECK ctf_fs_debug
43 #include "../common/metadata/decoder.h"
45 #define NSEC_PER_SEC 1000000000LL
48 FILE *ctf_fs_metadata_open_file(const char *trace_path
)
50 GString
*metadata_path
= g_string_new(trace_path
);
57 g_string_append(metadata_path
, "/" CTF_FS_METADATA_FILENAME
);
58 fp
= fopen(metadata_path
->str
, "rb");
72 g_string_free(metadata_path
, TRUE
);
76 static struct ctf_fs_file
*get_file(struct ctf_fs_component
*ctf_fs
,
77 const char *trace_path
)
79 struct ctf_fs_file
*file
= ctf_fs_file_create(ctf_fs
);
85 g_string_append(file
->path
, trace_path
);
86 g_string_append(file
->path
, "/" CTF_FS_METADATA_FILENAME
);
88 if (ctf_fs_file_open(ctf_fs
, file
, "rb")) {
96 ctf_fs_file_destroy(file
);
104 int ctf_fs_metadata_set_trace(struct ctf_fs_component
*ctf_fs
)
107 struct ctf_fs_file
*file
= NULL
;
108 struct ctf_metadata_decoder
*metadata_decoder
= NULL
;
110 file
= get_file(ctf_fs
, ctf_fs
->trace_path
->str
);
112 PERR("Cannot create metadata file object\n");
117 metadata_decoder
= ctf_metadata_decoder_create(ctf_fs
->error_fp
,
118 ctf_fs
->options
.clock_offset
* NSEC_PER_SEC
+
119 ctf_fs
->options
.clock_offset_ns
);
120 if (!metadata_decoder
) {
121 PERR("Cannot create metadata decoder object\n");
126 ret
= ctf_metadata_decoder_decode(metadata_decoder
, file
->fp
);
128 PERR("Cannot decode metadata file\n");
132 ctf_fs
->metadata
->trace
= ctf_metadata_decoder_get_trace(
134 assert(ctf_fs
->metadata
->trace
);
137 ctf_fs_file_destroy(file
);
138 ctf_metadata_decoder_destroy(metadata_decoder
);
142 int ctf_fs_metadata_init(struct ctf_fs_metadata
*metadata
)
144 /* Nothing to initialize for the moment. */
148 void ctf_fs_metadata_fini(struct ctf_fs_metadata
*metadata
)
150 if (metadata
->text
) {
151 free(metadata
->text
);
154 if (metadata
->trace
) {
155 BT_PUT(metadata
->trace
);
This page took 0.032993 seconds and 4 git commands to generate.