delete ctf_fs;
}
+void ctf_fs_component_deleter::operator()(ctf_fs_component *comp)
+{
+ ctf_fs_destroy(comp);
+}
+
static void port_data_destroy(struct ctf_fs_port_data *port_data)
{
if (!port_data) {
ctf_fs_trace_destroy(trace);
}
-ctf_fs_component *ctf_fs_component_create(const bt2c::Logger& parentLogger)
+ctf_fs_component::UP ctf_fs_component_create(const bt2c::Logger& parentLogger)
{
- ctf_fs_component *ctf_fs = new ctf_fs_component {parentLogger};
+ ctf_fs_component::UP ctf_fs {new ctf_fs_component {parentLogger}};
+
ctf_fs->port_data = g_ptr_array_new_with_free_func(port_data_destroy_notifier);
if (!ctf_fs->port_data) {
goto error;
goto end;
error:
- ctf_fs_destroy(ctf_fs);
- ctf_fs = NULL;
+ ctf_fs.reset();
end:
return ctf_fs;
return ret;
}
-static struct ctf_fs_component *ctf_fs_create(const bt_value *params,
- bt_self_component_source *self_comp_src)
+static ctf_fs_component::UP ctf_fs_create(const bt_value *params,
+ bt_self_component_source *self_comp_src)
{
- struct ctf_fs_component *ctf_fs = NULL;
const bt_value *inputs_value;
const bt_value *trace_name_value;
bt_self_component *self_comp = bt_self_component_source_as_self_component(self_comp_src);
- ctf_fs = ctf_fs_component_create(
+ ctf_fs_component::UP ctf_fs = ctf_fs_component_create(
bt2c::Logger {bt2::SelfSourceComponent {self_comp_src}, "PLUGIN/SRC.CTF.FS/COMP"});
if (!ctf_fs) {
- goto error;
+ return nullptr;
}
- if (!read_src_fs_parameters(params, &inputs_value, &trace_name_value, ctf_fs)) {
- goto error;
+ if (!read_src_fs_parameters(params, &inputs_value, &trace_name_value, ctf_fs.get())) {
+ return nullptr;
}
- bt_self_component_set_data(self_comp, ctf_fs);
-
- if (ctf_fs_component_create_ctf_fs_trace(ctf_fs, inputs_value, trace_name_value, self_comp)) {
- goto error;
+ if (ctf_fs_component_create_ctf_fs_trace(ctf_fs.get(), inputs_value, trace_name_value,
+ self_comp)) {
+ return nullptr;
}
if (create_streams_for_trace(ctf_fs->trace)) {
- goto error;
+ return nullptr;
}
- if (create_ports_for_trace(ctf_fs, ctf_fs->trace, self_comp_src)) {
- goto error;
+ if (create_ports_for_trace(ctf_fs.get(), ctf_fs->trace, self_comp_src)) {
+ return nullptr;
}
- goto end;
-
-error:
- ctf_fs_destroy(ctf_fs);
- ctf_fs = NULL;
- bt_self_component_set_data(self_comp, NULL);
-
-end:
return ctf_fs;
}
const bt_value *params, void *)
{
try {
- struct ctf_fs_component *ctf_fs;
bt_component_class_initialize_method_status ret =
BT_COMPONENT_CLASS_INITIALIZE_METHOD_STATUS_OK;
- ctf_fs = ctf_fs_create(params, self_comp_src);
+ ctf_fs_component::UP ctf_fs = ctf_fs_create(params, self_comp_src);
if (!ctf_fs) {
ret = BT_COMPONENT_CLASS_INITIALIZE_METHOD_STATUS_ERROR;
}
+ bt_self_component_set_data(bt_self_component_source_as_self_component(self_comp_src),
+ ctf_fs.release());
return ret;
} catch (const std::bad_alloc&) {
return BT_COMPONENT_CLASS_INITIALIZE_METHOD_STATUS_MEMORY_ERROR;
int bo = 0;
};
+struct ctf_fs_component_deleter
+{
+ void operator()(struct ctf_fs_component *);
+};
+
struct ctf_fs_component
{
+ using UP = std::unique_ptr<ctf_fs_component, ctf_fs_component_deleter>;
+
explicit ctf_fs_component(const bt2c::Logger& parentLogger) :
logger {parentLogger, "PLUGIN/SRC.CTF.FS/COMP"}
{
/* Create and initialize a new, empty ctf_fs_component. */
-ctf_fs_component *ctf_fs_component_create(const bt2c::Logger& parentLogger);
+ctf_fs_component::UP ctf_fs_component_create(const bt2c::Logger& parentLogger);
/*
* Create one `struct ctf_fs_trace` from one trace, or multiple traces sharing
bt_component_class_query_method_status
trace_infos_query(const bt_value *params, const bt2c::Logger& logger, const bt_value **user_result)
{
- struct ctf_fs_component *ctf_fs = NULL;
+ ctf_fs_component::UP ctf_fs;
bt_component_class_query_method_status status = BT_COMPONENT_CLASS_QUERY_METHOD_STATUS_OK;
bt_value *result = NULL;
const bt_value *inputs_value = NULL;
goto error;
}
- if (!read_src_fs_parameters(params, &inputs_value, &trace_name_value, ctf_fs)) {
+ if (!read_src_fs_parameters(params, &inputs_value, &trace_name_value, ctf_fs.get())) {
status = BT_COMPONENT_CLASS_QUERY_METHOD_STATUS_ERROR;
goto error;
}
- if (ctf_fs_component_create_ctf_fs_trace(ctf_fs, inputs_value, trace_name_value, NULL)) {
+ if (ctf_fs_component_create_ctf_fs_trace(ctf_fs.get(), inputs_value, trace_name_value, NULL)) {
goto error;
}
}
end:
- if (ctf_fs) {
- ctf_fs_destroy(ctf_fs);
- ctf_fs = NULL;
- }
-
*user_result = result;
return status;
}