ctf: save self_msg_iter in ctf_msg_iter when creating it
[babeltrace.git] / src / plugins / ctf / lttng-live / viewer-connection.c
index 6fa1456f593fb1fc28f18e75555fb21c65362421..b1f37f04a0516bc04addd95af1f4c48ba2de7678 100644 (file)
 #define BT_LOG_TAG "PLUGIN/SRC.CTF.LTTNG-LIVE/VIEWER"
 #include "logging/comp-logging.h"
 
-#include <stdio.h>
+#include <fcntl.h>
+#include <stdbool.h>
 #include <stdint.h>
+#include <stdio.h>
 #include <stdlib.h>
-#include <stdbool.h>
+#include <sys/types.h>
 #include <unistd.h>
+
 #include <glib.h>
-#include <inttypes.h>
-#include <sys/types.h>
-#include <fcntl.h>
 
 #include "compat/socket.h"
 #include "compat/endian.h"
@@ -316,15 +316,6 @@ void lttng_live_disconnect_viewer(
        }
 }
 
-static
-void connection_release(bt_object *obj)
-{
-       struct live_viewer_connection *conn =
-               container_of(obj, struct live_viewer_connection, obj);
-
-       live_viewer_connection_destroy(conn);
-}
-
 static
 int list_update_session(bt_value *results,
                const struct lttng_viewer_session *session,
@@ -821,7 +812,8 @@ error:
 
 static
 int receive_streams(struct lttng_live_session *session,
-               uint32_t stream_count)
+               uint32_t stream_count,
+               bt_self_message_iterator *self_msg_iter)
 {
        ssize_t ret_len;
        uint32_t i;
@@ -871,7 +863,7 @@ int receive_streams(struct lttng_live_session *session,
                        BT_COMP_LOGI("    stream %" PRIu64 " : %s/%s",
                                stream_id, stream.path_name, stream.channel_name);
                        live_stream = lttng_live_stream_iterator_create(session,
-                               ctf_trace_id, stream_id);
+                               ctf_trace_id, stream_id, self_msg_iter);
                        if (!live_stream) {
                                BT_COMP_LOGE_APPEND_CAUSE(self_comp,
                                        "Error creating stream");
@@ -887,7 +879,8 @@ error:
 
 BT_HIDDEN
 enum lttng_live_attach_session_status lttng_live_attach_session(
-               struct lttng_live_session *session)
+               struct lttng_live_session *session,
+               bt_self_message_iterator *self_msg_iter)
 {
        struct lttng_viewer_cmd cmd;
        enum lttng_live_attach_session_status attach_status;
@@ -969,7 +962,7 @@ enum lttng_live_attach_session_status lttng_live_attach_session(
        }
 
        /* We receive the initial list of streams. */
-       if (receive_streams(session, streams_count)) {
+       if (receive_streams(session, streams_count, self_msg_iter)) {
                BT_COMP_LOGE_APPEND_CAUSE(self_comp, "Error receiving streams");
                goto error;
        }
@@ -1352,12 +1345,12 @@ error:
 }
 
 BT_HIDDEN
-enum bt_msg_iter_medium_status lttng_live_get_stream_bytes(
+enum ctf_msg_iter_medium_status lttng_live_get_stream_bytes(
                struct lttng_live_msg_iter *lttng_live_msg_iter,
                struct lttng_live_stream_iterator *stream, uint8_t *buf,
                uint64_t offset, uint64_t req_len, uint64_t *recv_len)
 {
-       enum bt_msg_iter_medium_status retstatus = BT_MSG_ITER_MEDIUM_STATUS_OK;
+       enum ctf_msg_iter_medium_status retstatus = CTF_MSG_ITER_MEDIUM_STATUS_OK;
        struct lttng_viewer_trace_packet rp;
        struct lttng_viewer_cmd cmd;
        struct lttng_viewer_get_packet rq;
@@ -1427,7 +1420,7 @@ enum bt_msg_iter_medium_status lttng_live_get_stream_bytes(
        case LTTNG_VIEWER_GET_PACKET_RETRY:
                /* Unimplemented by relay daemon */
                BT_COMP_LOGD("Received get_data_packet response: retry");
-               retstatus = BT_MSG_ITER_MEDIUM_STATUS_AGAIN;
+               retstatus = CTF_MSG_ITER_MEDIUM_STATUS_AGAIN;
                goto end;
        case LTTNG_VIEWER_GET_PACKET_ERR:
                if (flags & LTTNG_VIEWER_FLAG_NEW_METADATA) {
@@ -1440,14 +1433,14 @@ enum bt_msg_iter_medium_status lttng_live_get_stream_bytes(
                }
                if (flags & (LTTNG_VIEWER_FLAG_NEW_METADATA
                                | LTTNG_VIEWER_FLAG_NEW_STREAM)) {
-                       retstatus = BT_MSG_ITER_MEDIUM_STATUS_AGAIN;
+                       retstatus = CTF_MSG_ITER_MEDIUM_STATUS_AGAIN;
                        goto end;
                }
                BT_COMP_LOGE_APPEND_CAUSE(self_comp,
                        "Received get_data_packet response: error");
                goto error;
        case LTTNG_VIEWER_GET_PACKET_EOF:
-               retstatus = BT_MSG_ITER_MEDIUM_STATUS_EOF;
+               retstatus = CTF_MSG_ITER_MEDIUM_STATUS_EOF;
                goto end;
        default:
                BT_COMP_LOGE_APPEND_CAUSE(self_comp,
@@ -1478,9 +1471,9 @@ end:
 
 error:
        if (lttng_live_graph_is_canceled(lttng_live_msg_iter)) {
-               retstatus = BT_MSG_ITER_MEDIUM_STATUS_AGAIN;
+               retstatus = CTF_MSG_ITER_MEDIUM_STATUS_AGAIN;
        } else {
-               retstatus = BT_MSG_ITER_MEDIUM_STATUS_ERROR;
+               retstatus = CTF_MSG_ITER_MEDIUM_STATUS_ERROR;
        }
        return retstatus;
 }
@@ -1490,7 +1483,8 @@ error:
  */
 BT_HIDDEN
 enum lttng_live_iterator_status lttng_live_get_new_streams(
-               struct lttng_live_session *session)
+               struct lttng_live_session *session,
+               bt_self_message_iterator *self_msg_iter)
 {
        enum lttng_live_iterator_status status =
                LTTNG_LIVE_ITERATOR_STATUS_OK;
@@ -1571,7 +1565,7 @@ enum lttng_live_iterator_status lttng_live_get_new_streams(
                goto error;
        }
 
-       if (receive_streams(session, streams_count)) {
+       if (receive_streams(session, streams_count, self_msg_iter)) {
                BT_COMP_LOGE_APPEND_CAUSE(self_comp, "Error receiving streams");
                goto error;
        }
@@ -1611,7 +1605,6 @@ struct live_viewer_connection *live_viewer_connection_create(
        viewer_connection->self_comp = self_comp;
        viewer_connection->self_comp_class = self_comp_class;
 
-       bt_object_init_shared(&viewer_connection->obj, connection_release);
        viewer_connection->control_sock = BT_INVALID_SOCKET;
        viewer_connection->port = -1;
        viewer_connection->in_query = in_query;
@@ -1646,20 +1639,33 @@ void live_viewer_connection_destroy(
                struct live_viewer_connection *viewer_connection)
 {
        BT_COMP_LOGI("Closing connection to url \"%s\"", viewer_connection->url->str);
+
+       if (!viewer_connection) {
+               goto end;
+       }
+
        lttng_live_disconnect_viewer(viewer_connection);
+
        if (viewer_connection->url) {
                g_string_free(viewer_connection->url, true);
        }
+
        if (viewer_connection->relay_hostname) {
                g_string_free(viewer_connection->relay_hostname, true);
        }
+
        if (viewer_connection->target_hostname) {
                g_string_free(viewer_connection->target_hostname, true);
        }
+
        if (viewer_connection->session_name) {
                g_string_free(viewer_connection->session_name, true);
        }
+
        g_free(viewer_connection);
 
        bt_socket_fini();
+
+end:
+       return;
 }
This page took 0.026869 seconds and 4 git commands to generate.