Move ctf_file_stream away from ctf-ir
authorMathieu Desnoyers <mathieu.desnoyers@efficios.com>
Thu, 23 Jun 2011 21:40:12 +0000 (17:40 -0400)
committerMathieu Desnoyers <mathieu.desnoyers@efficios.com>
Thu, 23 Jun 2011 21:40:12 +0000 (17:40 -0400)
Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
converter/babeltrace-lib.c
formats/ctf/ctf.c
formats/ctf/metadata/ctf-visitor-generate-io-struct.c
include/babeltrace/ctf-ir/metadata.h
include/babeltrace/ctf/metadata.h

index 534e4eddd5e9ffa743b9f79dd46bdd3271863724..5f5eb19a144e953fadffe720196607ba3708201f 100644 (file)
@@ -31,7 +31,7 @@ static int read_event(struct ctf_file_stream *sin)
 {
        int ret;
 
-       ret = sin->pos.parent.event_cb(&sin->pos.parent, &sin->stream);
+       ret = sin->pos.parent.event_cb(&sin->pos.parent, &sin->parent);
        if (ret == EOF)
                return EOF;
        else if (ret) {
@@ -48,7 +48,7 @@ int stream_compare(void *a, void *b)
 {
        struct ctf_file_stream *s_a = a, *s_b = b;
 
-       if (s_a->stream.timestamp < s_b->stream.timestamp)
+       if (s_a->parent.timestamp < s_b->parent.timestamp)
                return 1;
        else
                return 0;
@@ -73,8 +73,8 @@ int convert_trace(struct trace_descriptor *td_write,
 
                if (!stream)
                        continue;
-               for (filenr = 0; filenr < stream->files->len; filenr++) {
-                       struct ctf_file_stream *file_stream = g_ptr_array_index(stream->files, filenr);
+               for (filenr = 0; filenr < stream->streams->len; filenr++) {
+                       struct ctf_file_stream *file_stream = g_ptr_array_index(stream->streams, filenr);
                        ret = read_event(file_stream);
                        if (ret == EOF) {
                                ret = 0;
@@ -100,7 +100,7 @@ int convert_trace(struct trace_descriptor *td_write,
                        ret = 0;
                        break;
                }
-               ret = sout->parent.event_cb(&sout->parent, &file_stream->stream);
+               ret = sout->parent.event_cb(&sout->parent, &file_stream->parent);
                if (ret) {
                        fprintf(stdout, "[error] Writing event failed.\n");
                        goto end;
index 80f726aca7701cb699e2a221389dce2af759adde..ce21464e562b0601540f7beacb96c8da3b597c20 100644 (file)
@@ -407,7 +407,7 @@ void ctf_move_pos_slow(struct ctf_stream_pos *pos, size_t offset, int whence)
                pos->mmap_offset = index->offset;
 
                /* Lookup context/packet size in index */
-               file_stream->stream.timestamp = index->timestamp_begin;
+               file_stream->parent.timestamp = index->timestamp_begin;
                pos->content_size = index->content_size;
                pos->packet_size = index->packet_size;
                if (index->data_offset < index->content_size)
@@ -427,14 +427,14 @@ void ctf_move_pos_slow(struct ctf_stream_pos *pos, size_t offset, int whence)
        }
 
        /* update trace_packet_header and stream_packet_context */
-       if (pos->prot != PROT_WRITE && file_stream->stream.trace_packet_header) {
+       if (pos->prot != PROT_WRITE && file_stream->parent.trace_packet_header) {
                /* Read packet header */
-               ret = generic_rw(&pos->parent, &file_stream->stream.trace_packet_header->p);
+               ret = generic_rw(&pos->parent, &file_stream->parent.trace_packet_header->p);
                assert(!ret);
        }
-       if (pos->prot != PROT_WRITE && file_stream->stream.stream_packet_context) {
+       if (pos->prot != PROT_WRITE && file_stream->parent.stream_packet_context) {
                /* Read packet context */
-               ret = generic_rw(&pos->parent, &file_stream->stream.stream_packet_context->p);
+               ret = generic_rw(&pos->parent, &file_stream->parent.stream_packet_context->p);
                assert(!ret);
        }
 }
@@ -578,20 +578,23 @@ static
 int ctf_open_trace_metadata_read(struct ctf_trace *td)
 {
        struct ctf_scanner *scanner;
+       struct ctf_file_stream *metadata_stream;
        FILE *fp;
        char *buf = NULL;
        int ret = 0;
 
-       td->metadata.pos.fd = openat(td->dirfd, "metadata", O_RDONLY);
-       if (td->metadata.pos.fd < 0) {
+       metadata_stream = g_new0(struct ctf_file_stream, 1);
+       td->metadata = &metadata_stream->parent;
+       metadata_stream->pos.fd = openat(td->dirfd, "metadata", O_RDONLY);
+       if (metadata_stream->pos.fd < 0) {
                fprintf(stdout, "Unable to open metadata.\n");
-               return td->metadata.pos.fd;
+               return metadata_stream->pos.fd;
        }
 
        if (babeltrace_debug)
                yydebug = 1;
 
-       fp = fdopen(td->metadata.pos.fd, "r");
+       fp = fdopen(metadata_stream->pos.fd, "r");
        if (!fp) {
                fprintf(stdout, "[error] Unable to open metadata stream.\n");
                ret = -errno;
@@ -642,7 +645,9 @@ end_packet_read:
        fclose(fp);
        free(buf);
 end_stream:
-       close(td->metadata.pos.fd);
+       close(metadata_stream->pos.fd);
+       if (ret)
+               g_free(metadata_stream);
        return ret;
 }
 
@@ -814,17 +819,17 @@ int create_stream_packet_index(struct ctf_trace *td,
                packet_index.timestamp_end = 0;
 
                /* read and check header, set stream id (and check) */
-               if (file_stream->stream.trace_packet_header) {
+               if (file_stream->parent.trace_packet_header) {
                        /* Read packet header */
-                       ret = generic_rw(&pos->parent, &file_stream->stream.trace_packet_header->p);
+                       ret = generic_rw(&pos->parent, &file_stream->parent.trace_packet_header->p);
                        if (ret)
                                return ret;
-                       len_index = struct_declaration_lookup_field_index(file_stream->stream.trace_packet_header->declaration, g_quark_from_static_string("magic"));
+                       len_index = struct_declaration_lookup_field_index(file_stream->parent.trace_packet_header->declaration, g_quark_from_static_string("magic"));
                        if (len_index >= 0) {
                                struct definition_integer *defint;
                                struct definition *field;
 
-                               field = struct_definition_get_field_from_index(file_stream->stream.trace_packet_header, len_index);
+                               field = struct_definition_get_field_from_index(file_stream->parent.trace_packet_header, len_index);
                                assert(field->declaration->id == CTF_TYPE_INTEGER);
                                defint = container_of(field, struct definition_integer, p);
                                assert(defint->declaration->signedness == FALSE);
@@ -838,14 +843,14 @@ int create_stream_packet_index(struct ctf_trace *td,
                        }
 
                        /* check uuid */
-                       len_index = struct_declaration_lookup_field_index(file_stream->stream.trace_packet_header->declaration, g_quark_from_static_string("uuid"));
+                       len_index = struct_declaration_lookup_field_index(file_stream->parent.trace_packet_header->declaration, g_quark_from_static_string("uuid"));
                        if (len_index >= 0) {
                                struct definition_array *defarray;
                                struct definition *field;
                                uint64_t i;
                                uint8_t uuidval[UUID_LEN];
 
-                               field = struct_definition_get_field_from_index(file_stream->stream.trace_packet_header, len_index);
+                               field = struct_definition_get_field_from_index(file_stream->parent.trace_packet_header, len_index);
                                assert(field->declaration->id == CTF_TYPE_ARRAY);
                                defarray = container_of(field, struct definition_array, p);
                                assert(array_len(defarray) == UUID_LEN);
@@ -868,12 +873,12 @@ int create_stream_packet_index(struct ctf_trace *td,
                        }
 
 
-                       len_index = struct_declaration_lookup_field_index(file_stream->stream.trace_packet_header->declaration, g_quark_from_static_string("stream_id"));
+                       len_index = struct_declaration_lookup_field_index(file_stream->parent.trace_packet_header->declaration, g_quark_from_static_string("stream_id"));
                        if (len_index >= 0) {
                                struct definition_integer *defint;
                                struct definition *field;
 
-                               field = struct_definition_get_field_from_index(file_stream->stream.trace_packet_header, len_index);
+                               field = struct_definition_get_field_from_index(file_stream->parent.trace_packet_header, len_index);
                                assert(field->declaration->id == CTF_TYPE_INTEGER);
                                defint = container_of(field, struct definition_integer, p);
                                assert(defint->declaration->signedness == FALSE);
@@ -881,12 +886,12 @@ int create_stream_packet_index(struct ctf_trace *td,
                        }
                }
 
-               if (!first_packet && file_stream->stream.stream_id != stream_id) {
+               if (!first_packet && file_stream->parent.stream_id != stream_id) {
                        fprintf(stdout, "[error] Stream ID is changing within a stream.\n");
                        return -EINVAL;
                }
                if (first_packet) {
-                       file_stream->stream.stream_id = stream_id;
+                       file_stream->parent.stream_id = stream_id;
                        if (stream_id >= td->streams->len) {
                                fprintf(stdout, "[error] Stream %" PRIu64 " is not declared in metadata.\n", stream_id);
                                return -EINVAL;
@@ -896,26 +901,26 @@ int create_stream_packet_index(struct ctf_trace *td,
                                fprintf(stdout, "[error] Stream %" PRIu64 " is not declared in metadata.\n", stream_id);
                                return -EINVAL;
                        }
-                       file_stream->stream.stream_class = stream;
+                       file_stream->parent.stream_class = stream;
                }
                first_packet = 0;
 
-               ret = create_stream_definitions(td, &file_stream->stream);
+               ret = create_stream_definitions(td, &file_stream->parent);
                if (ret)
                        return ret;
 
-               if (file_stream->stream.stream_packet_context) {
+               if (file_stream->parent.stream_packet_context) {
                        /* Read packet context */
-                       ret = generic_rw(&pos->parent, &file_stream->stream.stream_packet_context->p);
+                       ret = generic_rw(&pos->parent, &file_stream->parent.stream_packet_context->p);
                        if (ret)
                                return ret;
                        /* read content size from header */
-                       len_index = struct_declaration_lookup_field_index(file_stream->stream.stream_packet_context->declaration, g_quark_from_static_string("content_size"));
+                       len_index = struct_declaration_lookup_field_index(file_stream->parent.stream_packet_context->declaration, g_quark_from_static_string("content_size"));
                        if (len_index >= 0) {
                                struct definition_integer *defint;
                                struct definition *field;
 
-                               field = struct_definition_get_field_from_index(file_stream->stream.stream_packet_context, len_index);
+                               field = struct_definition_get_field_from_index(file_stream->parent.stream_packet_context, len_index);
                                assert(field->declaration->id == CTF_TYPE_INTEGER);
                                defint = container_of(field, struct definition_integer, p);
                                assert(defint->declaration->signedness == FALSE);
@@ -926,12 +931,12 @@ int create_stream_packet_index(struct ctf_trace *td,
                        }
 
                        /* read packet size from header */
-                       len_index = struct_declaration_lookup_field_index(file_stream->stream.stream_packet_context->declaration, g_quark_from_static_string("packet_size"));
+                       len_index = struct_declaration_lookup_field_index(file_stream->parent.stream_packet_context->declaration, g_quark_from_static_string("packet_size"));
                        if (len_index >= 0) {
                                struct definition_integer *defint;
                                struct definition *field;
 
-                               field = struct_definition_get_field_from_index(file_stream->stream.stream_packet_context, len_index);
+                               field = struct_definition_get_field_from_index(file_stream->parent.stream_packet_context, len_index);
                                assert(field->declaration->id == CTF_TYPE_INTEGER);
                                defint = container_of(field, struct definition_integer, p);
                                assert(defint->declaration->signedness == FALSE);
@@ -942,12 +947,12 @@ int create_stream_packet_index(struct ctf_trace *td,
                        }
 
                        /* read timestamp begin from header */
-                       len_index = struct_declaration_lookup_field_index(file_stream->stream.stream_packet_context->declaration, g_quark_from_static_string("timestamp_begin"));
+                       len_index = struct_declaration_lookup_field_index(file_stream->parent.stream_packet_context->declaration, g_quark_from_static_string("timestamp_begin"));
                        if (len_index >= 0) {
                                struct definition_integer *defint;
                                struct definition *field;
 
-                               field = struct_definition_get_field_from_index(file_stream->stream.stream_packet_context, len_index);
+                               field = struct_definition_get_field_from_index(file_stream->parent.stream_packet_context, len_index);
                                assert(field->declaration->id == CTF_TYPE_INTEGER);
                                defint = container_of(field, struct definition_integer, p);
                                assert(defint->declaration->signedness == FALSE);
@@ -955,12 +960,12 @@ int create_stream_packet_index(struct ctf_trace *td,
                        }
 
                        /* read timestamp end from header */
-                       len_index = struct_declaration_lookup_field_index(file_stream->stream.stream_packet_context->declaration, g_quark_from_static_string("timestamp_end"));
+                       len_index = struct_declaration_lookup_field_index(file_stream->parent.stream_packet_context->declaration, g_quark_from_static_string("timestamp_end"));
                        if (len_index >= 0) {
                                struct definition_integer *defint;
                                struct definition *field;
 
-                               field = struct_definition_get_field_from_index(file_stream->stream.stream_packet_context, len_index);
+                               field = struct_definition_get_field_from_index(file_stream->parent.stream_packet_context, len_index);
                                assert(field->declaration->id == CTF_TYPE_INTEGER);
                                defint = container_of(field, struct definition_integer, p);
                                assert(defint->declaration->signedness == FALSE);
@@ -1040,19 +1045,20 @@ int ctf_open_file_stream_read(struct ctf_trace *td, const char *path, int flags)
                goto error;
        file_stream = g_new0(struct ctf_file_stream, 1);
        ctf_init_pos(&file_stream->pos, ret, flags);
-       ret = create_trace_definitions(td, &file_stream->stream);
+       ret = create_trace_definitions(td, &file_stream->parent);
        if (ret)
                goto error_def;
        ret = create_stream_packet_index(td, file_stream);
        if (ret)
                goto error_index;
        /* Add stream file to stream class */
-       g_ptr_array_add(file_stream->stream.stream_class->files, file_stream);
+       g_ptr_array_add(file_stream->parent.stream_class->streams,
+                       &file_stream->parent);
        return 0;
 
 error_index:
-       if (file_stream->stream.trace_packet_header)
-               definition_unref(&file_stream->stream.trace_packet_header->p);
+       if (file_stream->parent.trace_packet_header)
+               definition_unref(&file_stream->parent.trace_packet_header->p);
 error_def:
        ctf_fini_pos(&file_stream->pos);
        close(file_stream->pos.fd);
@@ -1192,9 +1198,9 @@ void ctf_close_trace(struct trace_descriptor *tdp)
                        stream = g_ptr_array_index(td->streams, i);
                        if (!stream)
                                continue;
-                       for (j = 0; j < stream->files->len; j++) {
+                       for (j = 0; j < stream->streams->len; j++) {
                                struct ctf_file_stream *file_stream;
-                               file_stream = g_ptr_array_index(stream->files, j);
+                               file_stream = container_of(g_ptr_array_index(stream->streams, j), struct ctf_file_stream, parent);
                                ctf_close_file_stream(file_stream);
                        }
 
index f137f6d32e9d90efe8dcd828435bc20a9450391c..bab2f7869715a1ca8c26859b1bdbbd659cddf64d 100644 (file)
@@ -1747,7 +1747,7 @@ int ctf_stream_visit(FILE *fd, int depth, struct ctf_node *node,
        stream->declaration_scope = new_declaration_scope(parent_declaration_scope);
        stream->events_by_id = g_ptr_array_new();
        stream->event_quark_to_id = g_hash_table_new(g_direct_hash, g_direct_equal);
-       stream->files = g_ptr_array_new();
+       stream->streams = g_ptr_array_new();
        if (node) {
                cds_list_for_each_entry(iter, &node->u.stream.declaration_list, siblings) {
                        ret = ctf_stream_declaration_visit(fd, depth + 1, iter, stream, trace);
@@ -1785,7 +1785,7 @@ error:
                declaration_unref(&stream->event_context_decl->p);
        if (stream->packet_context_decl)
                declaration_unref(&stream->packet_context_decl->p);
-       g_ptr_array_free(stream->files, TRUE);
+       g_ptr_array_free(stream->streams, TRUE);
        g_ptr_array_free(stream->events_by_id, TRUE);
        g_hash_table_destroy(stream->event_quark_to_id);
        free_declaration_scope(stream->declaration_scope);
index bf83aee51f826e6dea28579b2e8a9da16566e232..9c4d4500434cd16609284c328598ff818fd5607e 100644 (file)
@@ -52,11 +52,6 @@ struct ctf_stream_event {
        struct definition_struct *event_fields;
 };
 
-struct ctf_file_stream {
-       struct ctf_stream stream;
-       struct ctf_stream_pos pos;      /* current stream position */
-};
-
 #define CTF_TRACE_SET_FIELD(ctf_trace, field)                          \
        do {                                                            \
                (ctf_trace)->field_mask |= CTF_TRACE_ ## field;         \
@@ -81,7 +76,7 @@ struct ctf_trace {
        /* innermost definition scope. to be used as parent of stream. */
        struct definition_scope *definition_scope;
        GPtrArray *streams;                     /* Array of struct ctf_stream_class pointers */
-       struct ctf_file_stream metadata;
+       struct ctf_stream *metadata;
 
        /* Declarations only used when parsing */
        struct declaration_struct *packet_header_decl;
@@ -142,7 +137,7 @@ struct ctf_stream_class {
                CTF_STREAM_stream_id =  (1 << 0),
        } field_mask;
 
-       GPtrArray *files;                       /* Array of struct ctf_file_stream pointers */
+       GPtrArray *streams;     /* Array of struct ctf_stream pointers */
 };
 
 #define CTF_EVENT_SET_FIELD(ctf_event, field)                          \
index b09fcc61dc3d933914a06f55937312a8f71b7780..e985ee5f034ebae3d7e6fc149c0fcd6e4bf74e50 100644 (file)
 #define CTF_MAGIC      0xC1FC1FC1
 #define TSDL_MAGIC     0x75D11D57
 
+struct ctf_file_stream {
+       struct ctf_stream parent;
+       struct ctf_stream_pos pos;      /* current stream position */
+};
+
 #define HEADER_END             char end_field
 #define header_sizeof(type)    offsetof(typeof(type), end_field)
 
This page took 0.032739 seconds and 4 git commands to generate.