From 277bcb7fc46fee9748f69b7817940b62b898c7fb Mon Sep 17 00:00:00 2001 From: Simon Marchi Date: Thu, 7 Dec 2023 15:37:16 +0000 Subject: [PATCH] src.ctf.lttng-live: add live_viewer_connection destructor Convert live_viewer_connection_destroy into a destructor. Signed-off-by: Simon Marchi Change-Id: I84651d6a2184c75b61667ebf23c28737e5a227c5 Signed-off-by: Simon Marchi Reviewed-on: https://review.lttng.org/c/babeltrace/+/8471 Reviewed-by: Philippe Proulx Reviewed-on: https://review.lttng.org/c/babeltrace/+/12386 Tested-by: jenkins --- src/plugins/ctf/lttng-live/lttng-live.cpp | 6 ++---- .../ctf/lttng-live/viewer-connection.cpp | 21 +++++-------------- .../ctf/lttng-live/viewer-connection.hpp | 4 ++-- 3 files changed, 9 insertions(+), 22 deletions(-) diff --git a/src/plugins/ctf/lttng-live/lttng-live.cpp b/src/plugins/ctf/lttng-live/lttng-live.cpp index 1fb0be8a..cdf324c2 100644 --- a/src/plugins/ctf/lttng-live/lttng-live.cpp +++ b/src/plugins/ctf/lttng-live/lttng-live.cpp @@ -163,7 +163,7 @@ static void lttng_live_msg_iter_destroy(struct lttng_live_msg_iter *lttng_live_m } if (lttng_live_msg_iter->viewer_connection) { - live_viewer_connection_destroy(lttng_live_msg_iter->viewer_connection); + delete lttng_live_msg_iter->viewer_connection; } BT_ASSERT(lttng_live_msg_iter->lttng_live_comp); BT_ASSERT(lttng_live_msg_iter->lttng_live_comp->has_msg_iter); @@ -1767,9 +1767,7 @@ error: } end: - if (viewer_connection) { - live_viewer_connection_destroy(viewer_connection); - } + delete viewer_connection; g_free(validate_error); diff --git a/src/plugins/ctf/lttng-live/viewer-connection.cpp b/src/plugins/ctf/lttng-live/viewer-connection.cpp index 0b9f7132..42faae3b 100644 --- a/src/plugins/ctf/lttng-live/viewer-connection.cpp +++ b/src/plugins/ctf/lttng-live/viewer-connection.cpp @@ -1624,28 +1624,17 @@ enum lttng_live_viewer_status live_viewer_connection_create( goto end; error: - if (viewer_connection) { - live_viewer_connection_destroy(viewer_connection); - } + delete viewer_connection; + end: return status; } -void live_viewer_connection_destroy(struct live_viewer_connection *viewer_connection) +live_viewer_connection::~live_viewer_connection() { - if (!viewer_connection) { - goto end; - } + BT_CPPLOGD_SPEC(this->logger, "Closing connection to relay: relay-url=\"{}\"", this->url); - BT_CPPLOGD_SPEC(viewer_connection->logger, "Closing connection to relay: relay-url=\"{}\"", - viewer_connection->url); - - lttng_live_disconnect_viewer(viewer_connection); - - delete viewer_connection; + lttng_live_disconnect_viewer(this); bt_socket_fini(); - -end: - return; } diff --git a/src/plugins/ctf/lttng-live/viewer-connection.hpp b/src/plugins/ctf/lttng-live/viewer-connection.hpp index 586dd7ff..e35aea88 100644 --- a/src/plugins/ctf/lttng-live/viewer-connection.hpp +++ b/src/plugins/ctf/lttng-live/viewer-connection.hpp @@ -55,6 +55,8 @@ struct live_viewer_connection { } + ~live_viewer_connection(); + bt2c::Logger logger; std::string url; @@ -99,8 +101,6 @@ enum lttng_live_viewer_status live_viewer_connection_create( const char *url, bool in_query, struct lttng_live_msg_iter *lttng_live_msg_iter, const bt2c::Logger& parentLogger, struct live_viewer_connection **viewer); -void live_viewer_connection_destroy(struct live_viewer_connection *conn); - enum lttng_live_viewer_status lttng_live_create_viewer_session(struct lttng_live_msg_iter *lttng_live_msg_iter); -- 2.34.1