Fix: lttng-live enum mismatch
[babeltrace.git] / plugins / ctf / lttng-live / lttng-live.c
index 74d1ac3762e70477e932f8bdc6db55b7c4004cef..ac7d35249f8c60ff62179f68d8d631020dc9242f 100644 (file)
@@ -40,6 +40,7 @@
 #include <babeltrace/graph/notification-heap.h>
 #include <babeltrace/graph/notification-iterator.h>
 #include <babeltrace/graph/notification-inactivity.h>
+#include <babeltrace/graph/graph.h>
 #include <babeltrace/compiler-internal.h>
 #include <inttypes.h>
 #include <glib.h>
 #include <plugins-common.h>
 
 #define BT_LOG_TAG "PLUGIN-CTF-LTTNG-LIVE"
+#define BT_LOGLEVEL_NAME "BABELTRACE_PLUGIN_CTF_LTTNG_LIVE_LOG_LEVEL"
 
-#include "lttng-live-internal.h"
 #include "data-stream.h"
 #include "metadata.h"
+#include "lttng-live-internal.h"
 
 #define MAX_QUERY_SIZE         (256*1024)
 
@@ -163,10 +165,15 @@ static
 void lttng_live_destroy_trace(struct bt_object *obj)
 {
        struct lttng_live_trace *trace = container_of(obj, struct lttng_live_trace, obj);
+       int retval;
 
        BT_LOGI("Destroy trace");
        assert(bt_list_empty(&trace->streams));
        bt_list_del(&trace->node);
+
+       retval = bt_ctf_trace_set_is_static(trace->trace);
+       assert(!retval);
+
        lttng_live_metadata_fini(trace);
        BT_PUT(trace->cc_prio_map);
        g_free(trace);
@@ -263,9 +270,11 @@ void lttng_live_destroy_session(struct lttng_live_session *session)
        BT_LOGI("Destroy session");
        if (session->id != -1ULL) {
                if (lttng_live_detach_session(session)) {
-                       /* Old relayd cannot detach sessions. */
-                       BT_LOGD("Unable to detach session %" PRIu64,
-                               session->id);
+                       if (!bt_graph_is_canceled(session->lttng_live->graph)) {
+                               /* Old relayd cannot detach sessions. */
+                               BT_LOGD("Unable to detach session %" PRIu64,
+                                       session->id);
+                       }
                }
                session->id = -1ULL;
        }
@@ -395,7 +404,11 @@ enum bt_ctf_lttng_live_iterator_status lttng_live_get_session(
        struct lttng_live_trace *trace, *t;
 
        if (lttng_live_attach_session(session)) {
-               return BT_CTF_LTTNG_LIVE_ITERATOR_STATUS_ERROR;
+               if (bt_graph_is_canceled(lttng_live->graph)) {
+                       return BT_CTF_LTTNG_LIVE_ITERATOR_STATUS_AGAIN;
+               } else {
+                       return BT_CTF_LTTNG_LIVE_ITERATOR_STATUS_ERROR;
+               }
        }
        status = lttng_live_get_new_streams(session);
        if (status != BT_CTF_LTTNG_LIVE_ITERATOR_STATUS_OK &&
@@ -404,12 +417,8 @@ enum bt_ctf_lttng_live_iterator_status lttng_live_get_session(
        }
        bt_list_for_each_entry_safe(trace, t, &session->traces, node) {
                status = lttng_live_metadata_update(trace);
-               if (status == BT_CTF_LTTNG_LIVE_ITERATOR_STATUS_END) {
-                       int retval;
-
-                       retval = bt_ctf_trace_set_is_static(trace->trace);
-                       assert(!retval);
-               } else if (status != BT_CTF_LTTNG_LIVE_ITERATOR_STATUS_OK) {
+               if (status != BT_CTF_LTTNG_LIVE_ITERATOR_STATUS_OK &&
+                               status != BT_CTF_LTTNG_LIVE_ITERATOR_STATUS_END) {
                        return status;
                }
        }
@@ -442,7 +451,7 @@ void lttng_live_force_new_streams_and_metadata(struct lttng_live_component *lttn
 }
 
 static
-enum bt_notification_iterator_status lttng_live_iterator_next_handle_new_streams_and_metadata(
+enum bt_ctf_lttng_live_iterator_status lttng_live_iterator_next_handle_new_streams_and_metadata(
                struct lttng_live_component *lttng_live)
 {
        enum bt_ctf_lttng_live_iterator_status ret =
@@ -895,7 +904,6 @@ struct bt_value *lttng_live_query_list_sessions(struct bt_component_class *comp_
        struct bt_value *results = NULL;
        const char *url;
        struct bt_live_viewer_connection *viewer_connection = NULL;
-       enum bt_value_status ret;
 
        url_value = bt_value_map_get(params, "url");
        if (!url_value || bt_value_is_null(url_value) || !bt_value_is_string(url_value)) {
@@ -903,15 +911,13 @@ struct bt_value *lttng_live_query_list_sessions(struct bt_component_class *comp_
                goto error;
        }
 
-       ret = bt_value_string_get(url_value, &url);
-       if (ret != BT_VALUE_STATUS_OK) {
+       if (bt_value_string_get(url_value, &url) != BT_VALUE_STATUS_OK) {
                BT_LOGW("\"url\" parameter is required to be a string value");
                goto error;
        }
 
-       viewer_connection = bt_live_viewer_connection_create(url, stderr);
+       viewer_connection = bt_live_viewer_connection_create(url, NULL);
        if (!viewer_connection) {
-               ret = BT_COMPONENT_STATUS_NOMEM;
                goto error;
        }
 
@@ -976,7 +982,8 @@ void lttng_live_component_finalize(struct bt_private_component *component)
 
 static
 struct lttng_live_component *lttng_live_component_create(struct bt_value *params,
-               struct bt_private_component *private_component)
+               struct bt_private_component *private_component,
+               struct bt_graph *graph)
 {
        struct lttng_live_component *lttng_live;
        struct bt_value *value = NULL;
@@ -1005,17 +1012,15 @@ struct lttng_live_component *lttng_live_component_create(struct bt_value *params
                goto error;
        }
        lttng_live->viewer_connection =
-               bt_live_viewer_connection_create(lttng_live->url->str,
-                       stderr);
+               bt_live_viewer_connection_create(lttng_live->url->str, lttng_live);
        if (!lttng_live->viewer_connection) {
-               ret = BT_COMPONENT_STATUS_NOMEM;
                goto error;
        }
        if (lttng_live_create_viewer_session(lttng_live)) {
-               ret = BT_COMPONENT_STATUS_ERROR;
                goto error;
        }
        lttng_live->private_component = private_component;
+       lttng_live->graph = graph;
 
        goto end;
 
@@ -1027,16 +1032,29 @@ end:
 }
 
 BT_HIDDEN
-enum bt_component_status lttng_live_component_init(struct bt_private_component *component,
+enum bt_component_status lttng_live_component_init(
+               struct bt_private_component *private_component,
                struct bt_value *params, void *init_method_data)
 {
        struct lttng_live_component *lttng_live;
        enum bt_component_status ret = BT_COMPONENT_STATUS_OK;
+       struct bt_component *component;
+       struct bt_graph *graph;
+
+       component = bt_component_from_private_component(private_component);
+       graph = bt_component_get_graph(component);
+       bt_put(graph);  /* weak */
+       bt_put(component);
 
        /* Passes ownership of iter ref to lttng_live_component_create. */
-       lttng_live = lttng_live_component_create(params, component);
+       lttng_live = lttng_live_component_create(params, private_component,
+                       graph);
        if (!lttng_live) {
-               ret = BT_COMPONENT_STATUS_NOMEM;
+               if (bt_graph_is_canceled(graph)) {
+                       ret = BT_COMPONENT_STATUS_AGAIN;
+               } else {
+                       ret = BT_COMPONENT_STATUS_NOMEM;
+               }
                goto end;
        }
 
@@ -1050,7 +1068,7 @@ enum bt_component_status lttng_live_component_init(struct bt_private_component *
                                lttng_live->no_stream_iter);
        lttng_live->no_stream_iter->port = lttng_live->no_stream_port;
 
-       ret = bt_private_component_set_user_data(component, lttng_live);
+       ret = bt_private_component_set_user_data(private_component, lttng_live);
        if (ret != BT_COMPONENT_STATUS_OK) {
                goto error;
        }
@@ -1058,16 +1076,53 @@ enum bt_component_status lttng_live_component_init(struct bt_private_component *
 end:
        return ret;
 error:
-       (void) bt_private_component_set_user_data(component, NULL);
+       (void) bt_private_component_set_user_data(private_component, NULL);
        lttng_live_component_destroy_data(lttng_live);
        return ret;
 }
 
+BT_HIDDEN
+enum bt_component_status lttng_live_accept_port_connection(
+               struct bt_private_component *private_component,
+               struct bt_private_port *self_private_port,
+               struct bt_port *other_port)
+{
+       struct lttng_live_component *lttng_live =
+                       bt_private_component_get_user_data(private_component);
+       struct bt_component *other_component;
+       enum bt_component_status status = BT_COMPONENT_STATUS_OK;
+       struct bt_port *self_port = bt_port_from_private_port(self_private_port);
+
+       other_component = bt_port_get_component(other_port);
+       bt_put(other_component);        /* weak */
+
+       if (!lttng_live->downstream_component) {
+               lttng_live->downstream_component = other_component;
+               goto end;
+       }
+
+       /*
+        * Compare prior component to ensure we are connected to the
+        * same downstream component as prior ports.
+        */
+       if (lttng_live->downstream_component != other_component) {
+               BT_LOGW("Cannot connect ctf.lttng-live component port \"%s\" to component \"%s\": already connected to component \"%s\".",
+                       bt_port_get_name(self_port),
+                       bt_component_get_name(other_component),
+                       bt_component_get_name(lttng_live->downstream_component));
+               status = BT_COMPONENT_STATUS_REFUSE_PORT_CONNECTION;
+               goto end;
+       }
+end:
+       bt_put(self_port);
+       return status;
+}
+
 static
 void __attribute__((constructor)) bt_lttng_live_logging_ctor(void)
 {
        enum bt_logging_level log_level = BT_LOG_NONE;
-       const char *log_level_env = getenv("BABELTRACE_PLUGIN_LTTNG_LIVE_LOG_LEVEL");
+       const char *log_level_env = getenv(BT_LOGLEVEL_NAME);
 
        if (!log_level_env) {
                return;
@@ -1085,6 +1140,11 @@ void __attribute__((constructor)) bt_lttng_live_logging_ctor(void)
                log_level = BT_LOGGING_LEVEL_ERROR;
        } else if (strcmp(log_level_env, "FATAL") == 0) {
                log_level = BT_LOGGING_LEVEL_FATAL;
+       } else {
+               bt_lttng_live_log_level = BT_LOGGING_LEVEL_FATAL;
+               BT_LOGF("Incorrect log level specified in %s",
+                               BT_LOGLEVEL_NAME);
+               abort();
        }
 
         bt_lttng_live_log_level = log_level;
This page took 0.026365 seconds and 4 git commands to generate.