8fa9b2820bb3b34b4fd9f5f55af1438ebfadb819
4 * Babeltrace CTF file system Reader Component queries
6 * Copyright 2017 Jérémie Galarneau <jeremie.galarneau@efficios.com>
8 * Permission is hereby granted, free of charge, to any person obtaining a copy
9 * of this software and associated documentation files (the "Software"), to deal
10 * in the Software without restriction, including without limitation the rights
11 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
12 * copies of the Software, and to permit persons to whom the Software is
13 * furnished to do so, subject to the following conditions:
15 * The above copyright notice and this permission notice shall be included in
16 * all copies or substantial portions of the Software.
18 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
21 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
23 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
31 #include "../common/metadata/decoder.h"
32 #include <babeltrace/common-internal.h>
34 #define BT_LOG_TAG "PLUGIN-CTF-FS-QUERY-SRC"
37 #define METADATA_TEXT_SIG "/* CTF 1.8"
40 struct bt_value
*metadata_info_query(struct bt_component_class
*comp_class
,
41 struct bt_value
*params
)
43 struct bt_value
*results
= NULL
;
44 struct bt_value
*path_value
= NULL
;
45 char *metadata_text
= NULL
;
46 FILE *metadata_fp
= NULL
;
47 GString
*g_metadata_text
= NULL
;
53 results
= bt_value_map_create();
58 if (!bt_value_is_map(params
)) {
60 "Query parameters is not a map value object\n");
64 path_value
= bt_value_map_get(params
, "path");
65 ret
= bt_value_string_get(path_value
, &path
);
68 "Cannot get `path` string parameter\n");
73 metadata_fp
= ctf_fs_metadata_open_file(path
);
76 "Cannot open trace at path `%s`\n", path
);
80 is_packetized
= ctf_metadata_decoder_is_packetized(metadata_fp
,
84 ret
= ctf_metadata_decoder_packetized_file_stream_to_buf(
85 metadata_fp
, &metadata_text
, bo
);
88 "Cannot decode packetized metadata file\n");
94 fseek(metadata_fp
, 0, SEEK_END
);
95 filesize
= ftell(metadata_fp
);
97 metadata_text
= malloc(filesize
+ 1);
100 "Cannot allocate buffer for metadata text\n");
104 if (fread(metadata_text
, filesize
, 1, metadata_fp
) != 1) {
106 "Cannot read metadata file\n");
110 metadata_text
[filesize
] = '\0';
113 g_metadata_text
= g_string_new(NULL
);
114 if (!g_metadata_text
) {
118 if (strncmp(metadata_text
, METADATA_TEXT_SIG
,
119 sizeof(METADATA_TEXT_SIG
) - 1) != 0) {
120 g_string_assign(g_metadata_text
, METADATA_TEXT_SIG
);
121 g_string_append(g_metadata_text
, " */\n\n");
124 g_string_append(g_metadata_text
, metadata_text
);
126 ret
= bt_value_map_insert_string(results
, "text",
127 g_metadata_text
->str
);
129 fprintf(stderr
, "Cannot insert metadata text into results\n");
133 ret
= bt_value_map_insert_bool(results
, "is-packetized",
136 fprintf(stderr
, "Cannot insert is packetized into results\n");
149 if (g_metadata_text
) {
150 g_string_free(g_metadata_text
, TRUE
);
This page took 0.053157 seconds and 4 git commands to generate.