60ec42e1036817b30e06675cdf6e1d8c3dd85f30
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"
33 #define METADATA_TEXT_SIG "/* CTF 1.8"
36 struct bt_value
*metadata_info_query(struct bt_component_class
*comp_class
,
37 struct bt_value
*params
)
39 struct bt_value
*results
= NULL
;
40 struct bt_value
*path_value
= NULL
;
41 char *metadata_text
= NULL
;
42 FILE *metadata_fp
= NULL
;
43 GString
*g_metadata_text
= NULL
;
49 results
= bt_value_map_create();
54 if (!bt_value_is_map(params
)) {
56 "Query parameters is not a map value object\n");
60 path_value
= bt_value_map_get(params
, "path");
61 ret
= bt_value_string_get(path_value
, &path
);
64 "Cannot get `path` string parameter\n");
69 metadata_fp
= ctf_fs_metadata_open_file(path
);
72 "Cannot open trace at path `%s`\n", path
);
76 is_packetized
= ctf_metadata_decoder_is_packetized(metadata_fp
,
80 ret
= ctf_metadata_decoder_packetized_file_stream_to_buf(
81 metadata_fp
, &metadata_text
, bo
);
84 "Cannot decode packetized metadata file\n");
90 fseek(metadata_fp
, 0, SEEK_END
);
91 filesize
= ftell(metadata_fp
);
93 metadata_text
= malloc(filesize
+ 1);
96 "Cannot allocate buffer for metadata text\n");
100 if (fread(metadata_text
, filesize
, 1, metadata_fp
) != 1) {
102 "Cannot read metadata file\n");
106 metadata_text
[filesize
] = '\0';
109 g_metadata_text
= g_string_new(NULL
);
110 if (!g_metadata_text
) {
114 if (strncmp(metadata_text
, METADATA_TEXT_SIG
,
115 sizeof(METADATA_TEXT_SIG
) - 1) != 0) {
116 g_string_assign(g_metadata_text
, METADATA_TEXT_SIG
);
117 g_string_append(g_metadata_text
, " */\n\n");
120 g_string_append(g_metadata_text
, metadata_text
);
122 ret
= bt_value_map_insert_string(results
, "text",
123 g_metadata_text
->str
);
125 fprintf(stderr
, "Cannot insert metadata text into results\n");
129 ret
= bt_value_map_insert_bool(results
, "is-packetized",
132 fprintf(stderr
, "Cannot insert is packetized into results\n");
145 if (g_metadata_text
) {
146 g_string_free(g_metadata_text
, TRUE
);
This page took 0.040062 seconds and 3 git commands to generate.