* Babeltrace CTF file system Reader Component queries
*/
-#define BT_LOG_OUTPUT_LEVEL log_level
-#define BT_LOG_TAG "PLUGIN/SRC.CTF.FS/QUERY"
-#include "logging/log.h"
-
-#include "query.hpp"
-#include <stdbool.h>
#include <glib.h>
#include <glib/gstdio.h>
-#include <fcntl.h>
#include <sys/types.h>
-#include <sys/stat.h>
-#include "common/assert.h"
-#include "metadata.hpp"
-#include "../common/metadata/decoder.hpp"
-#include "common/common.h"
-#include "common/macros.h"
+
#include <babeltrace2/babeltrace.h>
-#include "fs.hpp"
+
+#define BT_LOG_OUTPUT_LEVEL ((enum bt_log_level) log_level)
+#define BT_LOG_TAG "PLUGIN/SRC.CTF.FS/QUERY"
#include "logging/comp-logging.h"
+#include "logging/log.h"
+
+#include "common/assert.h"
+
+#include "../common/src/metadata/tsdl/decoder.hpp"
+#include "fs.hpp"
+#include "metadata.hpp"
+#include "query.hpp"
#define METADATA_TEXT_SIG "/* CTF 1.8"
const char *path;
bool is_packetized;
struct ctf_metadata_decoder *decoder = NULL;
- ctf_metadata_decoder_config decoder_cfg {};
+ ctf_metadata_decoder_config decoder_cfg;
enum ctf_metadata_decoder_status decoder_status;
+ GString *g_metadata_text = NULL;
+ const char *plaintext;
result = bt_value_map_create();
if (!result) {
path = bt_value_string_get(path_value);
BT_ASSERT(path);
- metadata_fp = ctf_fs_metadata_open_file(path);
+ metadata_fp = ctf_fs_metadata_open_file(path, log_level, self_comp_class);
if (!metadata_fp) {
BT_COMP_CLASS_LOGE_APPEND_CAUSE(self_comp_class, "Cannot open trace metadata: path=\"%s\".",
path);
goto error;
}
- ret = bt_value_map_insert_string_entry(result, "text", ctf_metadata_decoder_get_text(decoder));
+ plaintext = ctf_metadata_decoder_get_text(decoder);
+ g_metadata_text = g_string_new(NULL);
+
+ if (!g_metadata_text) {
+ goto error;
+ }
+
+ if (strncmp(plaintext, METADATA_TEXT_SIG, sizeof(METADATA_TEXT_SIG) - 1) != 0) {
+ g_string_assign(g_metadata_text, METADATA_TEXT_SIG);
+ g_string_append(g_metadata_text, " */\n\n");
+ }
+
+ g_string_append(g_metadata_text, plaintext);
+
+ ret = bt_value_map_insert_string_entry(result, "text", g_metadata_text->str);
if (ret) {
BT_COMP_CLASS_LOGE_APPEND_CAUSE(self_comp_class,
"Cannot insert metadata text into query result.");
}
end:
+ if (g_metadata_text) {
+ g_string_free(g_metadata_text, TRUE);
+ }
ctf_metadata_decoder_destroy(decoder);
if (metadata_fp) {
ret = fclose(metadata_fp);
if (ret) {
- BT_LOGE_ERRNO("Cannot close metatada file stream", ": path=\"%s\"", path);
+ BT_LOGE_ERRNO("Cannot close metadata file stream", ": path=\"%s\"", path);
}
}
goto error;
}
- ctf_fs = ctf_fs_component_create(log_level, NULL);
+ ctf_fs = ctf_fs_component_create(log_level);
if (!ctf_fs) {
goto error;
}
metadata_file = g_fopen(metadata_path, "rb");
if (metadata_file) {
- ctf_metadata_decoder_config metadata_decoder_config {};
enum ctf_metadata_decoder_status decoder_status;
bt_uuid_t uuid;
+ ctf_metadata_decoder_config metadata_decoder_config;
metadata_decoder_config.log_level = log_level;
metadata_decoder_config.self_comp_class =
bt_self_component_class_source_as_self_component_class(comp_class);