ctf: allocate some structures with new
[babeltrace.git] / src / plugins / ctf / fs-src / fs.cpp
index 5cdabcadf798e2028cbaf8499ce801c86f68b639..4ffe410ba8e92fb00c78b2104ee7f15cf58fbd76 100644 (file)
@@ -7,27 +7,29 @@
  * Babeltrace CTF file system Reader Component
  */
 
+#include <glib.h>
+#include <inttypes.h>
+
+#include <babeltrace2/babeltrace.h>
+
 #define BT_COMP_LOG_SELF_COMP self_comp
-#define BT_LOG_OUTPUT_LEVEL   log_level
+#define BT_LOG_OUTPUT_LEVEL   ((enum bt_log_level) log_level)
 #define BT_LOG_TAG            "PLUGIN/SRC.CTF.FS"
 #include "logging/comp-logging.h"
 
+#include "common/assert.h"
 #include "common/common.h"
-#include <babeltrace2/babeltrace.h>
 #include "common/uuid.h"
-#include <glib.h>
-#include "common/assert.h"
-#include <inttypes.h>
-#include <stdbool.h>
-#include "fs.hpp"
-#include "metadata.hpp"
+
+#include "plugins/common/param-validation/param-validation.h"
+
+#include "../common/src/metadata/tsdl/ctf-meta-configure-ir-trace.hpp"
+#include "../common/src/msg-iter/msg-iter.hpp"
 #include "data-stream-file.hpp"
 #include "file.hpp"
-#include "../common/metadata/decoder.hpp"
-#include "../common/metadata/ctf-meta-configure-ir-trace.hpp"
-#include "../common/msg-iter/msg-iter.hpp"
+#include "fs.hpp"
+#include "metadata.hpp"
 #include "query.hpp"
-#include "plugins/common/param-validation/param-validation.h"
 
 struct tracer_info
 {
@@ -51,7 +53,7 @@ static void ctf_fs_msg_iter_data_destroy(struct ctf_fs_msg_iter_data *msg_iter_d
         ctf_fs_ds_group_medops_data_destroy(msg_iter_data->msg_iter_medops_data);
     }
 
-    g_free(msg_iter_data);
+    delete msg_iter_data;
 }
 
 static bt_message_iterator_class_next_method_status
@@ -100,7 +102,6 @@ ctf_fs_iterator_next_one(struct ctf_fs_msg_iter_data *msg_iter_data, const bt_me
     return status;
 }
 
-BT_HIDDEN
 bt_message_iterator_class_next_method_status
 ctf_fs_iterator_next(bt_self_message_iterator *iterator, bt_message_array_const msgs,
                      uint64_t capacity, uint64_t *count)
@@ -135,7 +136,7 @@ ctf_fs_iterator_next(bt_self_message_iterator *iterator, bt_message_array_const
          * accumulated message objects in the output
          * message array, so we need to return
          * BT_MESSAGE_ITERATOR_NEXT_METHOD_STATUS_OK so that they are
-         * transfered to downstream. This other status occurs
+         * transferred to downstream. This other status occurs
          * again the next time muxer_msg_iter_do_next() is
          * called, possibly without any accumulated
          * message, in which case we'll return it.
@@ -160,7 +161,6 @@ end:
     return status;
 }
 
-BT_HIDDEN
 bt_message_iterator_class_seek_beginning_method_status
 ctf_fs_iterator_seek_beginning(bt_self_message_iterator *it)
 {
@@ -175,7 +175,6 @@ ctf_fs_iterator_seek_beginning(bt_self_message_iterator *it)
     return BT_MESSAGE_ITERATOR_CLASS_SEEK_BEGINNING_METHOD_STATUS_OK;
 }
 
-BT_HIDDEN
 void ctf_fs_iterator_finalize(bt_self_message_iterator *it)
 {
     ctf_fs_msg_iter_data_destroy(
@@ -199,14 +198,12 @@ ctf_msg_iter_medium_status_to_msg_iter_initialize_status(enum ctf_msg_iter_mediu
     bt_common_abort();
 }
 
-BT_HIDDEN
 bt_message_iterator_class_initialize_method_status
 ctf_fs_iterator_init(bt_self_message_iterator *self_msg_iter,
                      bt_self_message_iterator_configuration *config,
                      bt_self_component_port_output *self_port)
 {
     struct ctf_fs_port_data *port_data;
-    struct ctf_fs_msg_iter_data *msg_iter_data = NULL;
     bt_message_iterator_class_initialize_method_status status;
     bt_logging_level log_level;
     enum ctf_msg_iter_medium_status medium_status;
@@ -216,12 +213,8 @@ ctf_fs_iterator_init(bt_self_message_iterator *self_msg_iter,
         bt_self_component_port_output_as_self_component_port(self_port));
     BT_ASSERT(port_data);
     log_level = port_data->ctf_fs->log_level;
-    msg_iter_data = g_new0(struct ctf_fs_msg_iter_data, 1);
-    if (!msg_iter_data) {
-        status = BT_MESSAGE_ITERATOR_CLASS_INITIALIZE_METHOD_STATUS_MEMORY_ERROR;
-        goto error;
-    }
 
+    ctf_fs_msg_iter_data *msg_iter_data = new ctf_fs_msg_iter_data;
     msg_iter_data->log_level = log_level;
     msg_iter_data->self_comp = self_comp;
     msg_iter_data->self_msg_iter = self_msg_iter;
@@ -289,13 +282,12 @@ static void ctf_fs_trace_destroy(struct ctf_fs_trace *ctf_fs_trace)
 
     if (ctf_fs_trace->metadata) {
         ctf_fs_metadata_fini(ctf_fs_trace->metadata);
-        g_free(ctf_fs_trace->metadata);
+        delete ctf_fs_trace->metadata;
     }
 
-    g_free(ctf_fs_trace);
+    delete ctf_fs_trace;
 }
 
-BT_HIDDEN
 void ctf_fs_destroy(struct ctf_fs_component *ctf_fs)
 {
     if (!ctf_fs) {
@@ -308,7 +300,7 @@ void ctf_fs_destroy(struct ctf_fs_component *ctf_fs)
         g_ptr_array_free(ctf_fs->port_data, TRUE);
     }
 
-    g_free(ctf_fs);
+    delete ctf_fs;
 }
 
 static void port_data_destroy(struct ctf_fs_port_data *port_data)
@@ -317,7 +309,7 @@ static void port_data_destroy(struct ctf_fs_port_data *port_data)
         return;
     }
 
-    g_free(port_data);
+    delete port_data;
 }
 
 static void port_data_destroy_notifier(void *data)
@@ -331,16 +323,9 @@ static void ctf_fs_trace_destroy_notifier(void *data)
     ctf_fs_trace_destroy(trace);
 }
 
-struct ctf_fs_component *ctf_fs_component_create(bt_logging_level log_level,
-                                                 bt_self_component *self_comp)
+struct ctf_fs_component *ctf_fs_component_create(bt_logging_level log_level)
 {
-    struct ctf_fs_component *ctf_fs;
-
-    ctf_fs = g_new0(struct ctf_fs_component, 1);
-    if (!ctf_fs) {
-        goto error;
-    }
-
+    ctf_fs_component *ctf_fs = new ctf_fs_component;
     ctf_fs->log_level = log_level;
     ctf_fs->port_data = g_ptr_array_new_with_free_func(port_data_destroy_notifier);
     if (!ctf_fs->port_data) {
@@ -408,7 +393,6 @@ gchar *ctf_fs_make_port_name(struct ctf_fs_ds_file_group *ds_file_group)
 }
 
 static int create_one_port_for_trace(struct ctf_fs_component *ctf_fs,
-                                     struct ctf_fs_trace *ctf_fs_trace,
                                      struct ctf_fs_ds_file_group *ds_file_group,
                                      bt_self_component_source *self_comp_src)
 {
@@ -426,11 +410,7 @@ static int create_one_port_for_trace(struct ctf_fs_component *ctf_fs,
     BT_COMP_LOGI("Creating one port named `%s`", port_name);
 
     /* Create output port for this file */
-    port_data = g_new0(struct ctf_fs_port_data, 1);
-    if (!port_data) {
-        goto error;
-    }
-
+    port_data = new ctf_fs_port_data;
     port_data->ctf_fs = ctf_fs;
     port_data->ds_file_group = ds_file_group;
     ret = bt_self_component_source_add_output_port(self_comp_src, port_name, port_data, NULL);
@@ -466,7 +446,7 @@ static int create_ports_for_trace(struct ctf_fs_component *ctf_fs,
         struct ctf_fs_ds_file_group *ds_file_group =
             (struct ctf_fs_ds_file_group *) g_ptr_array_index(ctf_fs_trace->ds_file_groups, i);
 
-        ret = create_one_port_for_trace(ctf_fs, ctf_fs_trace, ds_file_group, self_comp_src);
+        ret = create_one_port_for_trace(ctf_fs, ds_file_group, self_comp_src);
         if (ret) {
             BT_COMP_LOGE_APPEND_CAUSE(self_comp, "Cannot create output port.");
             goto end;
@@ -487,18 +467,12 @@ static void ctf_fs_ds_file_info_destroy(struct ctf_fs_ds_file_info *ds_file_info
         g_string_free(ds_file_info->path, TRUE);
     }
 
-    g_free(ds_file_info);
+    delete ds_file_info;
 }
 
 static struct ctf_fs_ds_file_info *ctf_fs_ds_file_info_create(const char *path, int64_t begin_ns)
 {
-    struct ctf_fs_ds_file_info *ds_file_info;
-
-    ds_file_info = g_new0(struct ctf_fs_ds_file_info, 1);
-    if (!ds_file_info) {
-        goto end;
-    }
-
+    ctf_fs_ds_file_info *ds_file_info = new ctf_fs_ds_file_info;
     ds_file_info->path = g_string_new(path);
     if (!ds_file_info->path) {
         ctf_fs_ds_file_info_destroy(ds_file_info);
@@ -525,7 +499,7 @@ static void ctf_fs_ds_file_group_destroy(struct ctf_fs_ds_file_group *ds_file_gr
     ctf_fs_ds_index_destroy(ds_file_group->index);
 
     bt_stream_put_ref(ds_file_group->stream);
-    g_free(ds_file_group);
+    delete ds_file_group;
 }
 
 static struct ctf_fs_ds_file_group *ctf_fs_ds_file_group_create(struct ctf_fs_trace *ctf_fs_trace,
@@ -533,13 +507,7 @@ static struct ctf_fs_ds_file_group *ctf_fs_ds_file_group_create(struct ctf_fs_tr
                                                                 uint64_t stream_instance_id,
                                                                 struct ctf_fs_ds_index *index)
 {
-    struct ctf_fs_ds_file_group *ds_file_group;
-
-    ds_file_group = g_new0(struct ctf_fs_ds_file_group, 1);
-    if (!ds_file_group) {
-        goto error;
-    }
-
+    ctf_fs_ds_file_group *ds_file_group = new ctf_fs_ds_file_group;
     ds_file_group->ds_file_infos =
         g_ptr_array_new_with_free_func((GDestroyNotify) ctf_fs_ds_file_info_destroy);
     if (!ds_file_group->ds_file_infos) {
@@ -660,7 +628,7 @@ static void ds_index_insert_ds_index_entry_sorted(struct ctf_fs_ds_index *index,
     if (i == index->entries->len || !ds_index_entries_equal(entry, other_entry)) {
         array_insert(index->entries, entry, i);
     } else {
-        g_free(entry);
+        delete entry;
     }
 }
 
@@ -703,7 +671,7 @@ static int add_ds_file_to_ds_file_group(struct ctf_fs_trace *ctf_fs_trace, const
      * Create a temporary ds_file to read some properties about the data
      * stream file.
      */
-    ds_file = ctf_fs_ds_file_create(ctf_fs_trace, NULL, NULL, path, log_level);
+    ds_file = ctf_fs_ds_file_create(ctf_fs_trace, NULL, path, log_level);
     if (!ds_file) {
         goto error;
     }
@@ -993,17 +961,12 @@ static struct ctf_fs_trace *ctf_fs_trace_create(bt_self_component *self_comp,
                                                 struct ctf_fs_metadata_config *metadata_config,
                                                 bt_logging_level log_level)
 {
-    struct ctf_fs_trace *ctf_fs_trace;
     int ret;
 
     /* Only one of them must be set. */
     BT_ASSERT(!self_comp != !self_comp_class);
 
-    ctf_fs_trace = g_new0(struct ctf_fs_trace, 1);
-    if (!ctf_fs_trace) {
-        goto end;
-    }
-
+    ctf_fs_trace *ctf_fs_trace = new struct ctf_fs_trace;
     ctf_fs_trace->log_level = log_level;
     ctf_fs_trace->self_comp = self_comp;
     ctf_fs_trace->self_comp_class = self_comp_class;
@@ -1012,11 +975,7 @@ static struct ctf_fs_trace *ctf_fs_trace_create(bt_self_component *self_comp,
         goto error;
     }
 
-    ctf_fs_trace->metadata = g_new0(struct ctf_fs_metadata, 1);
-    if (!ctf_fs_trace->metadata) {
-        goto error;
-    }
-
+    ctf_fs_trace->metadata = new ctf_fs_metadata;
     ctf_fs_metadata_init(ctf_fs_trace->metadata);
     ctf_fs_trace->ds_file_groups =
         g_ptr_array_new_with_free_func((GDestroyNotify) ctf_fs_ds_file_group_destroy);
@@ -1379,7 +1338,7 @@ static int decode_clock_snapshot_after_event(struct ctf_fs_trace *ctf_fs_trace,
     BT_ASSERT(index_entry);
     BT_ASSERT(index_entry->path);
 
-    ds_file = ctf_fs_ds_file_create(ctf_fs_trace, NULL, NULL, index_entry->path, log_level);
+    ds_file = ctf_fs_ds_file_create(ctf_fs_trace, NULL, index_entry->path, log_level);
     if (!ds_file) {
         BT_COMP_LOGE_APPEND_CAUSE(self_comp, "Failed to create a ctf_fs_ds_file");
         ret = -1;
@@ -2263,7 +2222,7 @@ static struct ctf_fs_component *ctf_fs_create(const bt_value *params,
     bt_self_component *self_comp = bt_self_component_source_as_self_component(self_comp_src);
 
     ctf_fs = ctf_fs_component_create(
-        bt_component_get_logging_level(bt_self_component_as_component(self_comp)), self_comp);
+        bt_component_get_logging_level(bt_self_component_as_component(self_comp)));
     if (!ctf_fs) {
         goto error;
     }
@@ -2299,10 +2258,9 @@ end:
     return ctf_fs;
 }
 
-BT_HIDDEN
-bt_component_class_initialize_method_status
-ctf_fs_init(bt_self_component_source *self_comp_src, bt_self_component_source_configuration *config,
-            const bt_value *params, __attribute__((unused)) void *init_method_data)
+bt_component_class_initialize_method_status ctf_fs_init(bt_self_component_source *self_comp_src,
+                                                        bt_self_component_source_configuration *,
+                                                        const bt_value *params, void *)
 {
     struct ctf_fs_component *ctf_fs;
     bt_component_class_initialize_method_status ret =
@@ -2316,7 +2274,6 @@ ctf_fs_init(bt_self_component_source *self_comp_src, bt_self_component_source_co
     return ret;
 }
 
-BT_HIDDEN
 bt_component_class_query_method_status ctf_fs_query(bt_self_component_class_source *comp_class,
                                                     bt_private_query_executor *priv_query_exec,
                                                     const char *object, const bt_value *params,
This page took 0.027898 seconds and 4 git commands to generate.