#include <babeltrace2/babeltrace.h>
+#include "cpp-common/bt2c/libc-up.hpp"
+
#include "../common/src/metadata/tsdl/decoder.hpp"
#include "fs.hpp"
#include "query.hpp"
bt_component_class_query_method_status status = BT_COMPONENT_CLASS_QUERY_METHOD_STATUS_OK;
bt_value *result = NULL;
const bt_value *path_value = NULL;
- FILE *metadata_fp = NULL;
+ bt2c::FileUP metadata_fp;
int ret;
int bo;
const char *path;
bool is_packetized;
- struct ctf_metadata_decoder *decoder = NULL;
+ ctf_metadata_decoder_up decoder;
ctf_metadata_decoder_config decoder_cfg {logger};
enum ctf_metadata_decoder_status decoder_status;
GString *g_metadata_text = NULL;
path = bt_value_string_get(path_value);
BT_ASSERT(path);
- metadata_fp = ctf_fs_metadata_open_file(path, logger);
+ metadata_fp.reset(ctf_fs_metadata_open_file(path, logger));
if (!metadata_fp) {
BT_CPPLOGE_APPEND_CAUSE_SPEC(logger, "Cannot open trace metadata: path=\"{}\".", path);
goto error;
}
- ret = ctf_metadata_decoder_is_packetized(metadata_fp, &is_packetized, &bo, logger);
+ ret = ctf_metadata_decoder_is_packetized(metadata_fp.get(), &is_packetized, &bo, logger);
if (ret) {
BT_CPPLOGE_APPEND_CAUSE_SPEC(
logger, "Cannot check whether or not the metadata stream is packetized: path=\"{}\".",
goto error;
}
- rewind(metadata_fp);
- decoder_status = ctf_metadata_decoder_append_content(decoder, metadata_fp);
+ rewind(metadata_fp.get());
+ decoder_status = ctf_metadata_decoder_append_content(decoder.get(), metadata_fp.get());
if (decoder_status) {
BT_CPPLOGE_APPEND_CAUSE_SPEC(
logger, "Cannot update metadata decoder's content: path=\"{}\".", path);
goto error;
}
- plaintext = ctf_metadata_decoder_get_text(decoder);
+ plaintext = ctf_metadata_decoder_get_text(decoder.get());
g_metadata_text = g_string_new(NULL);
if (!g_metadata_text) {
}
g_string_append(g_metadata_text, plaintext);
-
ret = bt_value_map_insert_string_entry(result, "text", g_metadata_text->str);
if (ret) {
BT_CPPLOGE_APPEND_CAUSE_SPEC(logger, "Cannot insert metadata text into query result.");
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_CPPLOGE_ERRNO_SPEC(logger, "Cannot close metadata file stream", ": path=\"{}\"",
- path);
- }
- }
*user_result = result;
return status;
double weight = 0;
bt2c::GCharUP metadata_path;
bt_value *result = NULL;
- struct ctf_metadata_decoder *metadata_decoder = NULL;
+ ctf_metadata_decoder_up metadata_decoder;
FILE *metadata_file = NULL;
char uuid_str[BT_UUID_STR_LEN + 1];
bool has_uuid = false;
goto end;
}
- decoder_status = ctf_metadata_decoder_append_content(metadata_decoder, metadata_file);
+ decoder_status = ctf_metadata_decoder_append_content(metadata_decoder.get(), metadata_file);
if (decoder_status != CTF_METADATA_DECODER_STATUS_OK) {
BT_CPPLOGW_SPEC(logger, "cannot append metadata content: metadata-decoder-status={}",
decoder_status);
weight = 0.75;
/* If the trace has a UUID, return the stringified UUID as the group. */
- if (ctf_metadata_decoder_get_trace_class_uuid(metadata_decoder, uuid) == 0) {
+ if (ctf_metadata_decoder_get_trace_class_uuid(metadata_decoder.get(), uuid) == 0) {
bt_uuid_to_str(uuid, uuid_str);
has_uuid = true;
}
end:
bt_value_put_ref(result);
- ctf_metadata_decoder_destroy(metadata_decoder);
return status;
}