Fix: invoke bt_ctf_trace_set_is_static only when trace is destroyed
[babeltrace.git] / plugins / ctf / lttng-live / lttng-live.c
index 7c1d22a4385e284a64736c65b8d0cfdb280fb665..095bef5ba55165895f7b2b109e979eb4b1969128 100644 (file)
@@ -48,6 +48,7 @@
 #include <plugins-common.h>
 
 #define BT_LOG_TAG "PLUGIN-CTF-LTTNG-LIVE"
+#define BT_LOGLEVEL_NAME "BABELTRACE_PLUGIN_CTF_LTTNG_LIVE_LOG_LEVEL"
 
 #include "data-stream.h"
 #include "metadata.h"
@@ -163,10 +164,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);
@@ -404,12 +410,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;
                }
        }
@@ -1063,11 +1065,48 @@ error:
        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 +1124,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.024847 seconds and 4 git commands to generate.