Rename bt_ctf_X -> bt_X, maintain backward compat. for pre-2.0 CTF writer
[babeltrace.git] / plugins / ctf / lttng-live / metadata.c
index b71a42a535632430147049b7116385be9de44d82..4a3b50b0ceae3c0f3fd32d776ecf48a1ccb9962e 100644 (file)
@@ -33,7 +33,7 @@
 #include <glib.h>
 #include <babeltrace/compat/uuid-internal.h>
 #include <babeltrace/compat/memstream-internal.h>
-#include <babeltrace/graph/graph.h>
+#include <babeltrace/babeltrace.h>
 
 #include "metadata.h"
 #include "../common/metadata/decoder.h"
@@ -54,11 +54,11 @@ struct packet_header {
 } __attribute__((__packed__));
 
 static
-enum bt_ctf_lttng_live_iterator_status lttng_live_update_clock_map(
+enum bt_lttng_live_iterator_status lttng_live_update_clock_map(
                struct lttng_live_trace *trace)
 {
-       enum bt_ctf_lttng_live_iterator_status status =
-                       BT_CTF_LTTNG_LIVE_ITERATOR_STATUS_OK;
+       enum bt_lttng_live_iterator_status status =
+                       BT_LTTNG_LIVE_ITERATOR_STATUS_OK;
        size_t i;
        int count, ret;
 
@@ -68,12 +68,12 @@ enum bt_ctf_lttng_live_iterator_status lttng_live_update_clock_map(
                goto error;
        }
 
-       count = bt_ctf_trace_get_clock_class_count(trace->trace);
+       count = bt_trace_get_clock_class_count(trace->trace);
        assert(count >= 0);
 
        for (i = 0; i < count; i++) {
-               struct bt_ctf_clock_class *clock_class =
-                       bt_ctf_trace_get_clock_class_by_index(trace->trace, i);
+               struct bt_clock_class *clock_class =
+                       bt_trace_get_clock_class_by_index(trace->trace, i);
 
                assert(clock_class);
                ret = bt_clock_class_priority_map_add_clock_class(
@@ -87,13 +87,13 @@ enum bt_ctf_lttng_live_iterator_status lttng_live_update_clock_map(
 
        goto end;
 error:
-       status = BT_CTF_LTTNG_LIVE_ITERATOR_STATUS_ERROR;
+       status = BT_LTTNG_LIVE_ITERATOR_STATUS_ERROR;
 end:
        return status;
 }
 
 BT_HIDDEN
-enum bt_ctf_lttng_live_iterator_status lttng_live_metadata_update(
+enum bt_lttng_live_iterator_status lttng_live_metadata_update(
                struct lttng_live_trace *trace)
 {
        struct lttng_live_session *session = trace->session;
@@ -103,20 +103,24 @@ enum bt_ctf_lttng_live_iterator_status lttng_live_metadata_update(
        char *metadata_buf = NULL;
        FILE *fp = NULL;
        enum ctf_metadata_decoder_status decoder_status;
-       enum bt_ctf_lttng_live_iterator_status status =
-               BT_CTF_LTTNG_LIVE_ITERATOR_STATUS_OK;
+       enum bt_lttng_live_iterator_status status =
+               BT_LTTNG_LIVE_ITERATOR_STATUS_OK;
 
        /* No metadata stream yet. */
        if (!metadata) {
                if (session->new_streams_needed) {
-                       status = BT_CTF_LTTNG_LIVE_ITERATOR_STATUS_AGAIN;
+                       status = BT_LTTNG_LIVE_ITERATOR_STATUS_AGAIN;
                } else {
                        session->new_streams_needed = true;
-                       status = BT_CTF_LTTNG_LIVE_ITERATOR_STATUS_CONTINUE;
+                       status = BT_LTTNG_LIVE_ITERATOR_STATUS_CONTINUE;
                }
                goto end;
        }
 
+       if (!metadata->trace) {
+               trace->new_metadata_needed = false;
+       }
+
        if (!trace->new_metadata_needed) {
                goto end;
        }
@@ -156,10 +160,11 @@ enum bt_ctf_lttng_live_iterator_status lttng_live_metadata_update(
                         * the data streams are done.
                         */
                        lttng_live_unref_trace(metadata->trace);
+                       metadata->trace = NULL;
                }
                if (errno == EINTR) {
-                       if (bt_graph_is_canceled(session->lttng_live->graph)) {
-                               status = BT_CTF_LTTNG_LIVE_ITERATOR_STATUS_AGAIN;
+                       if (lttng_live_is_canceled(session->lttng_live)) {
+                               status = BT_LTTNG_LIVE_ITERATOR_STATUS_AGAIN;
                                goto end;
                        }
                }
@@ -173,17 +178,13 @@ enum bt_ctf_lttng_live_iterator_status lttng_live_metadata_update(
 
        if (len_read == 0) {
                if (!trace->trace) {
-                       status = BT_CTF_LTTNG_LIVE_ITERATOR_STATUS_AGAIN;
+                       status = BT_LTTNG_LIVE_ITERATOR_STATUS_AGAIN;
                        goto end;
                }
                trace->new_metadata_needed = false;
                goto end;
        }
 
-       if (babeltrace_debug) {
-               // yydebug = 1;
-       }
-
        fp = bt_fmemopen(metadata_buf, len_read, "rb");
        if (!fp) {
                BT_LOGE("Cannot memory-open metadata buffer: %s",
@@ -198,12 +199,12 @@ enum bt_ctf_lttng_live_iterator_status lttng_live_metadata_update(
                trace->trace = ctf_metadata_decoder_get_trace(metadata->decoder);
                trace->new_metadata_needed = false;
                status = lttng_live_update_clock_map(trace);
-               if (status != BT_CTF_LTTNG_LIVE_ITERATOR_STATUS_OK) {
+               if (status != BT_LTTNG_LIVE_ITERATOR_STATUS_OK) {
                        goto end;
                }
                break;
        case CTF_METADATA_DECODER_STATUS_INCOMPLETE:
-               status = BT_CTF_LTTNG_LIVE_ITERATOR_STATUS_AGAIN;
+               status = BT_LTTNG_LIVE_ITERATOR_STATUS_AGAIN;
                break;
        case CTF_METADATA_DECODER_STATUS_ERROR:
        case CTF_METADATA_DECODER_STATUS_INVAL_VERSION:
@@ -213,7 +214,7 @@ enum bt_ctf_lttng_live_iterator_status lttng_live_metadata_update(
 
        goto end;
 error:
-       status = BT_CTF_LTTNG_LIVE_ITERATOR_STATUS_ERROR;
+       status = BT_LTTNG_LIVE_ITERATOR_STATUS_ERROR;
 end:
        if (fp) {
                int closeret;
@@ -223,16 +224,19 @@ end:
                        BT_LOGE("Error on fclose");
                }
        }
+       free(metadata_buf);
        return status;
 }
 
 BT_HIDDEN
 int lttng_live_metadata_create_stream(struct lttng_live_session *session,
                uint64_t ctf_trace_id,
-               uint64_t stream_id)
+               uint64_t stream_id,
+               const char *trace_name)
 {
        struct lttng_live_metadata *metadata = NULL;
        struct lttng_live_trace *trace;
+       const char *match;
 
        metadata = g_new0(struct lttng_live_metadata, 1);
        if (!metadata) {
@@ -240,9 +244,12 @@ int lttng_live_metadata_create_stream(struct lttng_live_session *session,
        }
        metadata->stream_id = stream_id;
        //TODO: add clock offset option
-       //TODO: add (preferably unique) trace's name
-       metadata->decoder = ctf_metadata_decoder_create(stderr, 0,
-               "lttng-live");
+       match = strstr(trace_name, session->session_name->str);
+       if (!match) {
+               goto error;
+       }
+       metadata->decoder = ctf_metadata_decoder_create(NULL,
+               match);
        if (!metadata->decoder) {
                goto error;
        }
@@ -273,7 +280,6 @@ void lttng_live_metadata_fini(struct lttng_live_trace *trace)
        }
        ctf_metadata_decoder_destroy(metadata->decoder);
        trace->metadata = NULL;
-       lttng_live_unref_trace(trace);
        if (!metadata->closed) {
                lttng_live_unref_trace(metadata->trace);
        }
This page took 0.025805 seconds and 4 git commands to generate.