Sort includes in C++ files
[babeltrace.git] / src / plugins / ctf / lttng-live / viewer-connection.cpp
index 804a88d87d7f61337f8827ef360a3cd107a0a04c..eb4bd1291d15245b01e67112ea80b54363329d0a 100644 (file)
@@ -5,12 +5,8 @@
  * Copyright 2016 Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
  */
 
-#define BT_COMP_LOG_SELF_COMP (viewer_connection->self_comp)
-#define BT_LOG_OUTPUT_LEVEL   (viewer_connection->log_level)
-#define BT_LOG_TAG            "PLUGIN/SRC.CTF.LTTNG-LIVE/VIEWER"
-#include "logging/comp-logging.h"
-
 #include <fcntl.h>
+#include <glib.h>
 #include <stdbool.h>
 #include <stdint.h>
 #include <stdio.h>
 #include <sys/types.h>
 #include <unistd.h>
 
-#include <glib.h>
+#include <babeltrace2/babeltrace.h>
+
+#define BT_COMP_LOG_SELF_COMP (viewer_connection->self_comp)
+#define BT_LOG_OUTPUT_LEVEL   (viewer_connection->log_level)
+#define BT_LOG_TAG            "PLUGIN/SRC.CTF.LTTNG-LIVE/VIEWER"
+#include "logging/comp-logging.h"
 
-#include "compat/socket.h"
-#include "compat/endian.h"
-#include "compat/compiler.h"
 #include "common/common.h"
-#include <babeltrace2/babeltrace.h>
+#include "compat/compiler.h"
+#include "compat/endian.h"
+#include "compat/socket.h"
 
+#include "data-stream.hpp"
 #include "lttng-live.hpp"
-#include "viewer-connection.hpp"
 #include "lttng-viewer-abi.hpp"
-#include "data-stream.hpp"
 #include "metadata.hpp"
+#include "viewer-connection.hpp"
 
 #define viewer_handle_send_recv_status(_self_comp, _self_comp_class, _status, _action, _msg_str)   \
     do {                                                                                           \
@@ -336,7 +336,7 @@ static int parse_url(struct live_viewer_connection *viewer_connection)
     char error_buf[256] = {0};
     bt_self_component *self_comp = viewer_connection->self_comp;
     bt_self_component_class *self_comp_class = viewer_connection->self_comp_class;
-    struct bt_common_lttng_live_url_parts lttng_live_url_parts = {0};
+    struct bt_common_lttng_live_url_parts lttng_live_url_parts = {};
     int ret = -1;
     const char *path = viewer_connection->url->str;
 
@@ -793,7 +793,6 @@ end:
  *   }
  */
 
-BT_HIDDEN
 bt_component_class_query_method_status
 live_viewer_connection_list_sessions(struct live_viewer_connection *viewer_connection,
                                      const bt_value **user_result)
@@ -937,7 +936,6 @@ end:
     return status;
 }
 
-BT_HIDDEN
 enum lttng_live_viewer_status
 lttng_live_create_viewer_session(struct lttng_live_msg_iter *lttng_live_msg_iter)
 {
@@ -1015,8 +1013,7 @@ static enum lttng_live_viewer_status receive_streams(struct lttng_live_session *
         if (stream.metadata_flag) {
             BT_COMP_LOGI("    metadata stream %" PRIu64 " : %s/%s", stream_id, stream.path_name,
                          stream.channel_name);
-            if (lttng_live_metadata_create_stream(session, ctf_trace_id, stream_id,
-                                                  stream.path_name)) {
+            if (lttng_live_metadata_create_stream(session, ctf_trace_id, stream_id)) {
                 BT_COMP_LOGE_APPEND_CAUSE(self_comp, "Error creating metadata stream");
                 status = LTTNG_LIVE_VIEWER_STATUS_ERROR;
                 goto end;
@@ -1040,7 +1037,6 @@ end:
     return status;
 }
 
-BT_HIDDEN
 enum lttng_live_viewer_status lttng_live_session_attach(struct lttng_live_session *session,
                                                         bt_self_message_iterator *self_msg_iter)
 {
@@ -1136,7 +1132,6 @@ end:
     return status;
 }
 
-BT_HIDDEN
 enum lttng_live_viewer_status lttng_live_session_detach(struct lttng_live_session *session)
 {
     struct lttng_viewer_cmd cmd;
@@ -1213,7 +1208,6 @@ end:
     return status;
 }
 
-BT_HIDDEN
 enum lttng_live_get_one_metadata_status
 lttng_live_get_one_metadata_packet(struct lttng_live_trace *trace, FILE *fp, size_t *reply_len)
 {
@@ -1288,6 +1282,17 @@ lttng_live_get_one_metadata_packet(struct lttng_live_trace *trace, FILE *fp, siz
     }
 
     len = be64toh(rp.len);
+    if (len == 0) {
+        /*
+         * We received a `LTTNG_VIEWER_METADATA_OK` with a packet
+         * length of 0. This means we must try again. This scenario
+         * arises when a clear command is performed on an lttng session.
+         */
+        BT_COMP_LOGD(
+            "Expecting a metadata packet of size 0. Retry to get a packet from the relay.");
+        goto empty_metadata_packet_retry;
+    }
+
     BT_COMP_LOGD("Writing %" PRIu64 " bytes to metadata", len);
     if (len <= 0) {
         BT_COMP_LOGE_APPEND_CAUSE(self_comp, "Erroneous response length");
@@ -1319,6 +1324,7 @@ lttng_live_get_one_metadata_packet(struct lttng_live_trace *trace, FILE *fp, siz
         goto end;
     }
 
+empty_metadata_packet_retry:
     *reply_len = len;
     status = LTTNG_LIVE_GET_ONE_METADATA_STATUS_OK;
 
@@ -1359,7 +1365,6 @@ static void lttng_live_need_new_streams(struct lttng_live_msg_iter *lttng_live_m
     }
 }
 
-BT_HIDDEN
 enum lttng_live_iterator_status
 lttng_live_get_next_index(struct lttng_live_msg_iter *lttng_live_msg_iter,
                           struct lttng_live_stream_iterator *stream, struct packet_index *index)
@@ -1494,7 +1499,6 @@ end:
     return status;
 }
 
-BT_HIDDEN
 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,
@@ -1617,7 +1621,6 @@ end:
 /*
  * Request new streams for a session.
  */
-BT_HIDDEN
 enum lttng_live_iterator_status
 lttng_live_session_get_new_streams(struct lttng_live_session *session,
                                    bt_self_message_iterator *self_msg_iter)
@@ -1711,7 +1714,6 @@ end:
     return status;
 }
 
-BT_HIDDEN
 enum lttng_live_viewer_status live_viewer_connection_create(
     bt_self_component *self_comp, bt_self_component_class *self_comp_class,
     bt_logging_level log_level, const char *url, bool in_query,
@@ -1777,7 +1779,6 @@ end:
     return status;
 }
 
-BT_HIDDEN
 void live_viewer_connection_destroy(struct live_viewer_connection *viewer_connection)
 {
     bt_self_component *self_comp = viewer_connection->self_comp;
This page took 0.041712 seconds and 4 git commands to generate.