src.ctf.lttng-live: introduce lttng_live_msg_iter::UP and use it
authorSimon Marchi <simon.marchi@efficios.com>
Thu, 7 Dec 2023 15:53:32 +0000 (15:53 +0000)
committerSimon Marchi <simon.marchi@efficios.com>
Wed, 17 Apr 2024 17:57:53 +0000 (13:57 -0400)
Signed-off-by: Simon Marchi <simon.marchi@efficios.com>
Change-Id: Ie87efb7a6599a738dad60cc3533f8440c283da6c
Reviewed-on: https://review.lttng.org/c/babeltrace/+/8474
Reviewed-by: Philippe Proulx <eeppeliteloop@gmail.com>
Reviewed-on: https://review.lttng.org/c/babeltrace/+/12389
Tested-by: jenkins <jenkins@lttng.org>
src/plugins/ctf/lttng-live/lttng-live.cpp
src/plugins/ctf/lttng-live/lttng-live.hpp

index 43ae552a99100dc10380c609cbe6c653739c7031..1b5c90ee0252e87cea509b97c404050bc7b2a6ae 100644 (file)
@@ -168,14 +168,8 @@ lttng_live_msg_iter::~lttng_live_msg_iter()
 
 void lttng_live_msg_iter_finalize(bt_self_message_iterator *self_msg_iter)
 {
-    struct lttng_live_msg_iter *lttng_live_msg_iter;
-
-    BT_ASSERT(self_msg_iter);
-
-    lttng_live_msg_iter =
-        (struct lttng_live_msg_iter *) bt_self_message_iterator_get_data(self_msg_iter);
-    BT_ASSERT(lttng_live_msg_iter);
-    delete lttng_live_msg_iter;
+    lttng_live_msg_iter::UP {
+        static_cast<lttng_live_msg_iter *>(bt_self_message_iterator_get_data(self_msg_iter))};
 }
 
 static enum lttng_live_iterator_status
@@ -1569,15 +1563,15 @@ end:
     }
 }
 
-static struct lttng_live_msg_iter *
+static lttng_live_msg_iter::UP
 lttng_live_msg_iter_create(struct lttng_live_component *lttng_live_comp,
                            bt_self_message_iterator *self_msg_it)
 {
-    lttng_live_msg_iter *msg_iter = new lttng_live_msg_iter {lttng_live_comp->logger};
+    auto msg_iter = bt2s::make_unique<struct lttng_live_msg_iter>(lttng_live_comp->logger);
+
     msg_iter->self_comp = lttng_live_comp->self_comp;
     msg_iter->lttng_live_comp = lttng_live_comp;
     msg_iter->self_msg_iter = self_msg_it;
-
     msg_iter->active_stream_iter = 0;
     msg_iter->last_msg_ts_ns = INT64_MIN;
     msg_iter->was_interrupted = false;
@@ -1590,9 +1584,7 @@ lttng_live_msg_iter_init(bt_self_message_iterator *self_msg_it,
                          bt_self_message_iterator_configuration *, bt_self_component_port_output *)
 {
     try {
-        bt_message_iterator_class_initialize_method_status status;
         struct lttng_live_component *lttng_live;
-        struct lttng_live_msg_iter *lttng_live_msg_iter;
         enum lttng_live_viewer_status viewer_status;
         bt_self_component *self_comp = bt_self_message_iterator_borrow_component(self_msg_it);
 
@@ -1602,17 +1594,16 @@ lttng_live_msg_iter_init(bt_self_message_iterator *self_msg_it,
         BT_ASSERT(!lttng_live->has_msg_iter);
         lttng_live->has_msg_iter = true;
 
-        lttng_live_msg_iter = lttng_live_msg_iter_create(lttng_live, self_msg_it);
+        auto lttng_live_msg_iter = lttng_live_msg_iter_create(lttng_live, self_msg_it);
         if (!lttng_live_msg_iter) {
             BT_CPPLOGE_APPEND_CAUSE_SPEC(lttng_live->logger,
                                          "Failed to create lttng_live_msg_iter");
-            status = BT_MESSAGE_ITERATOR_CLASS_INITIALIZE_METHOD_STATUS_MEMORY_ERROR;
-            goto error;
+            return BT_MESSAGE_ITERATOR_CLASS_INITIALIZE_METHOD_STATUS_MEMORY_ERROR;
         }
 
         viewer_status = live_viewer_connection_create(
-            lttng_live->params.url.c_str(), false, lttng_live_msg_iter, lttng_live_msg_iter->logger,
-            lttng_live_msg_iter->viewer_connection);
+            lttng_live->params.url.c_str(), false, lttng_live_msg_iter.get(),
+            lttng_live_msg_iter->logger, lttng_live_msg_iter->viewer_connection);
         if (viewer_status != LTTNG_LIVE_VIEWER_STATUS_OK) {
             if (viewer_status == LTTNG_LIVE_VIEWER_STATUS_ERROR) {
                 BT_CPPLOGE_APPEND_CAUSE_SPEC(lttng_live_msg_iter->logger,
@@ -1626,11 +1617,10 @@ lttng_live_msg_iter_init(bt_self_message_iterator *self_msg_it,
                                              "Interrupted while creating viewer connection");
             }
 
-            status = BT_MESSAGE_ITERATOR_CLASS_INITIALIZE_METHOD_STATUS_ERROR;
-            goto error;
+            return BT_MESSAGE_ITERATOR_CLASS_INITIALIZE_METHOD_STATUS_ERROR;
         }
 
-        viewer_status = lttng_live_create_viewer_session(lttng_live_msg_iter);
+        viewer_status = lttng_live_create_viewer_session(lttng_live_msg_iter.get());
         if (viewer_status != LTTNG_LIVE_VIEWER_STATUS_OK) {
             if (viewer_status == LTTNG_LIVE_VIEWER_STATUS_ERROR) {
                 BT_CPPLOGE_APPEND_CAUSE_SPEC(lttng_live_msg_iter->logger,
@@ -1644,8 +1634,7 @@ lttng_live_msg_iter_init(bt_self_message_iterator *self_msg_it,
                                              "Interrupted when creating viewer session");
             }
 
-            status = BT_MESSAGE_ITERATOR_CLASS_INITIALIZE_METHOD_STATUS_ERROR;
-            goto error;
+            return BT_MESSAGE_ITERATOR_CLASS_INITIALIZE_METHOD_STATUS_ERROR;
         }
 
         if (lttng_live_msg_iter->sessions.empty()) {
@@ -1666,8 +1655,7 @@ lttng_live_msg_iter_init(bt_self_message_iterator *self_msg_it,
                     "component parameter: url =\"{}\"",
                     SESS_NOT_FOUND_ACTION_PARAM, SESS_NOT_FOUND_ACTION_FAIL_STR,
                     lttng_live->params.url);
-                status = BT_MESSAGE_ITERATOR_CLASS_INITIALIZE_METHOD_STATUS_ERROR;
-                goto error;
+                return BT_MESSAGE_ITERATOR_CLASS_INITIALIZE_METHOD_STATUS_ERROR;
             case SESSION_NOT_FOUND_ACTION_END:
                 BT_CPPLOGI_SPEC(lttng_live_msg_iter->logger,
                                 "Unable to connect to the requested live viewer session. "
@@ -1681,14 +1669,8 @@ lttng_live_msg_iter_init(bt_self_message_iterator *self_msg_it,
             }
         }
 
-        bt_self_message_iterator_set_data(self_msg_it, lttng_live_msg_iter);
-        status = BT_MESSAGE_ITERATOR_CLASS_INITIALIZE_METHOD_STATUS_OK;
-        goto end;
-
-error:
-        delete lttng_live_msg_iter;
-end:
-        return status;
+        bt_self_message_iterator_set_data(self_msg_it, lttng_live_msg_iter.release());
+        return BT_MESSAGE_ITERATOR_CLASS_INITIALIZE_METHOD_STATUS_OK;
     } catch (const std::bad_alloc&) {
         return BT_MESSAGE_ITERATOR_CLASS_INITIALIZE_METHOD_STATUS_MEMORY_ERROR;
     } catch (const bt2::Error&) {
index 7018888a7a5039895dc1469343a3a5a8b2e330ab..cbdf27d80d05a7016a4c0db7804a53b317ec2f6c 100644 (file)
@@ -279,6 +279,8 @@ struct lttng_live_component
 
 struct lttng_live_msg_iter
 {
+    using UP = std::unique_ptr<lttng_live_msg_iter>;
+
     explicit lttng_live_msg_iter(const bt2c::Logger& parentLogger) :
         logger {parentLogger, "PLUGIN/SRC.CTF.LTTNG-LIVE/MSG-ITER"}
     {
This page took 0.026593 seconds and 4 git commands to generate.