Make bt_private_component_*_add_*_port() return a status code
[babeltrace.git] / plugins / ctf / lttng-live / lttng-live.c
index ac7d35249f8c60ff62179f68d8d631020dc9242f..4831c81af77d142b9b78cfc01b577bd5f3d8a048 100644 (file)
@@ -27,6 +27,9 @@
  * SOFTWARE.
  */
 
+#define BT_LOG_TAG "PLUGIN-CTF-LTTNG-LIVE-SRC"
+#include "logging.h"
+
 #include <babeltrace/ctf-ir/packet.h>
 #include <babeltrace/graph/component-source.h>
 #include <babeltrace/graph/private-port.h>
@@ -48,9 +51,6 @@
 #include <unistd.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 "data-stream.h"
 #include "metadata.h"
 #include "lttng-live-internal.h"
@@ -83,9 +83,6 @@ static const char *print_state(struct lttng_live_stream_iterator *s)
                        print_state(stream), stream->last_returned_inactivity_timestamp,        \
                        stream->current_inactivity_timestamp)
 
-BT_HIDDEN
-int bt_lttng_live_log_level = BT_LOG_NONE;
-
 BT_HIDDEN
 int lttng_live_add_port(struct lttng_live_component *lttng_live,
                struct lttng_live_stream_iterator *stream_iter)
@@ -97,9 +94,10 @@ int lttng_live_add_port(struct lttng_live_component *lttng_live,
        ret = sprintf(name, STREAM_NAME_PREFIX "%" PRIu64, stream_iter->viewer_stream_id);
        assert(ret > 0);
        strcpy(stream_iter->name, name);
-       private_port = bt_private_component_source_add_output_private_port(
-                       lttng_live->private_component, name, stream_iter);
-       if (!private_port) {
+       ret = bt_private_component_source_add_output_private_port(
+                       lttng_live->private_component, name, stream_iter,
+                       &private_port);
+       if (ret) {
                return -1;
        }
        BT_LOGI("Added port %s", name);
@@ -132,10 +130,10 @@ int lttng_live_remove_port(struct lttng_live_component *lttng_live,
        BT_PUT(component);
        if (nr_ports == 1) {
                assert(!lttng_live->no_stream_port);
-               lttng_live->no_stream_port =
-                       bt_private_component_source_add_output_private_port(lttng_live->private_component,
-                               "no-stream", lttng_live->no_stream_iter);
-               if (!lttng_live->no_stream_port) {
+               ret = bt_private_component_source_add_output_private_port(lttng_live->private_component,
+                               "no-stream", lttng_live->no_stream_iter,
+                               &lttng_live->no_stream_port);
+               if (ret) {
                        return -1;
                }
                lttng_live->no_stream_iter->port = lttng_live->no_stream_port;
@@ -236,7 +234,9 @@ void lttng_live_close_trace_streams(struct lttng_live_trace *trace)
 }
 
 BT_HIDDEN
-int lttng_live_add_session(struct lttng_live_component *lttng_live, uint64_t session_id)
+int lttng_live_add_session(struct lttng_live_component *lttng_live,
+               uint64_t session_id, const char *hostname,
+               const char *session_name)
 {
        int ret = 0;
        struct lttng_live_session *s;
@@ -250,8 +250,11 @@ int lttng_live_add_session(struct lttng_live_component *lttng_live, uint64_t ses
        BT_INIT_LIST_HEAD(&s->traces);
        s->lttng_live = lttng_live;
        s->new_streams_needed = true;
+       s->hostname = g_string_new(hostname);
+       s->session_name = g_string_new(session_name);
 
-       BT_LOGI("Reading from session %" PRIu64, s->id);
+       BT_LOGI("Reading from session: %" PRIu64 " hostname: %s session_name: %s",
+               s->id, hostname, session_name);
        bt_list_add(&s->node, &lttng_live->sessions);
        goto end;
 error:
@@ -282,6 +285,12 @@ void lttng_live_destroy_session(struct lttng_live_session *session)
                lttng_live_close_trace_streams(trace);
        }
        bt_list_del(&session->node);
+       if (session->hostname) {
+               g_string_free(session->hostname, TRUE);
+       }
+       if (session->session_name) {
+               g_string_free(session->session_name, TRUE);
+       }
        g_free(session);
 }
 
@@ -1061,11 +1070,14 @@ enum bt_component_status lttng_live_component_init(
        lttng_live->no_stream_iter = g_new0(struct lttng_live_no_stream_iterator, 1);
        lttng_live->no_stream_iter->p.type = LIVE_STREAM_TYPE_NO_STREAM;
        lttng_live->no_stream_iter->lttng_live = lttng_live;
-
-       lttng_live->no_stream_port =
-               bt_private_component_source_add_output_private_port(
+       ret = bt_private_component_source_add_output_private_port(
                                lttng_live->private_component, "no-stream",
-                               lttng_live->no_stream_iter);
+                               lttng_live->no_stream_iter,
+                               &lttng_live->no_stream_port);
+       if (ret != BT_COMPONENT_STATUS_OK) {
+               goto end;
+       }
+
        lttng_live->no_stream_iter->port = lttng_live->no_stream_port;
 
        ret = bt_private_component_set_user_data(private_component, lttng_live);
@@ -1117,35 +1129,3 @@ 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(BT_LOGLEVEL_NAME);
-
-       if (!log_level_env) {
-               return;
-       }
-
-       if (strcmp(log_level_env, "VERBOSE") == 0) {
-               log_level = BT_LOGGING_LEVEL_VERBOSE;
-       } else if (strcmp(log_level_env, "DEBUG") == 0) {
-               log_level = BT_LOGGING_LEVEL_DEBUG;
-       } else if (strcmp(log_level_env, "INFO") == 0) {
-               log_level = BT_LOGGING_LEVEL_INFO;
-       } else if (strcmp(log_level_env, "WARN") == 0) {
-               log_level = BT_LOGGING_LEVEL_WARN;
-       } else if (strcmp(log_level_env, "ERROR") == 0) {
-               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.045224 seconds and 4 git commands to generate.