Use inheritance for trace descriptor and positions
authorMathieu Desnoyers <mathieu.desnoyers@efficios.com>
Fri, 6 May 2011 15:22:12 +0000 (11:22 -0400)
committerMathieu Desnoyers <mathieu.desnoyers@efficios.com>
Fri, 6 May 2011 15:22:12 +0000 (11:22 -0400)
Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
16 files changed:
converter/Makefile.am
converter/babeltrace-lib.c [new file with mode: 0644]
converter/babeltrace.c
formats/ctf/ctf.c
formats/ctf/types/float.c
formats/ctf/types/integer.c
formats/ctf/types/sequence.c
formats/ctf/types/string.c
formats/ctf/types/struct.c
include/babeltrace/babeltrace.h
include/babeltrace/ctf-text/types.h [new file with mode: 0644]
include/babeltrace/ctf/metadata.h
include/babeltrace/ctf/types.h
include/babeltrace/format.h
include/babeltrace/types.h
tests/test-dummytrace.c

index 75215f8a54382de45c44cd69d6e8ca6f3095d7aa..c7ff134d8abec6112c23bcaccffefe24c1aa5403 100644 (file)
@@ -2,9 +2,22 @@ AM_CFLAGS = $(PACKAGE_CFLAGS) -I$(top_srcdir)/include -lpopt
 
 bin_PROGRAMS = babeltrace
 
+#lib_LTLIBRARIES = libbabeltrace.la
+#
+#libbabeltrace_la_SOURCES = \
+#      babeltrace-lib.c
+#
+#libbabeltrace_la_LIBADD = \
+#      $(top_builddir)/types/libbabeltrace_types.la \
+#      $(top_builddir)/formats/libbabeltrace_registry.la \
+#      $(top_builddir)/formats/ctf/libctf.la
+
 babeltrace_SOURCES = \
        babeltrace.c
 
+#babeltrace_LDADD = \
+#      libbabeltrace.la
+
 babeltrace_LDADD = \
        $(top_builddir)/types/libbabeltrace_types.la \
        $(top_builddir)/formats/libbabeltrace_registry.la \
diff --git a/converter/babeltrace-lib.c b/converter/babeltrace-lib.c
new file mode 100644 (file)
index 0000000..3c51d84
--- /dev/null
@@ -0,0 +1,143 @@
+/*
+ * babeltrace-lib.c
+ *
+ * Babeltrace Trace Converter Library
+ *
+ * Copyright 2010 - Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ */
+
+#include <stdlib.h>
+#include <errno.h>
+#include <stdio.h>
+#include <babeltrace/babeltrace.h>
+#include <babeltrace/format.h>
+#include <babeltrace/ctf/types.h>
+#include <babeltrace/ctf/metadata.h>
+#include <babeltrace/ctf-text/types.h>
+
+static
+int print_event(struct format *fmt_write, struct ctf_text_stream_pos *sout,
+               struct format *fmt_read, struct ctf_file_stream *sin)
+{
+       struct ctf_stream *stream_class = sin->stream;
+       struct ctf_event *event_class;
+       uint64_t id = 0;
+       int len_index;
+
+       /* Read and print event header */
+       if (stream_class->event_header) {
+               fmt_read->struct_read(&sin->pos.parent, stream_class->event_header);
+
+               /* lookup event id */
+               len_index = struct_declaration_lookup_field_index(td->packet_header->declaration,
+                               g_quark_from_static_string("id"));
+               if (len_index >= 0) {
+                       struct definition_integer *defint;
+                       struct field *field;
+
+                       field = struct_definition_get_field_from_index(stream_class->event_header, len_index);
+                       assert(field->definition->declaration->id == CTF_TYPE_INTEGER);
+                       defint = container_of(field->definition, struct definition_integer, p);
+                       assert(defint->declaration->signedness == FALSE);
+                       id = defint->value._unsigned;   /* set id */
+               }
+
+               fmt_write->struct_write(&sout->parent, stream_class->event_header);
+       }
+
+       /* Read and print stream-declared event context */
+       if (stream_class->event_context) {
+               fmt_read->struct_read(&sin->pos.parent, stream_class->event_context);
+               fmt_write->struct_write(&sout->parent, stream_class->event_context);
+       }
+
+       if (id >= stream_class->events_by_id->len) {
+               fprintf(stdout, "[error] Event id %" PRIu64 " is outside range.\n", id);
+               return -EINVAL;
+       }
+       event_class = g_ptr_array_index(stream_class->events_by_id, id);
+       if (!event_class) {
+               fprintf(stdout, "[error] Event id %" PRIu64 " is unknown.\n", id);
+               return -EINVAL;
+       }
+
+       /* Read and print event-declared event context */
+       if (event_class->context) {
+               fmt_read->struct_read(&sin->pos.parent, event_class->context);
+               fmt_write->struct_write(&sout->parent, event_class->context);
+       }
+
+       /* Read and print event payload */
+       if (event_class->fields) {
+               fmt_read->struct_read(&sin->pos.parent, event_class->fields);
+               fmt_write->struct_write(&sout->parent, event_class->fields);
+       }
+
+       return 0;
+}
+
+static
+int print_stream(struct format *fmt_write, struct ctf_text_stream_pos *sout,
+                struct format *fmt_read, struct ctf_file_stream *sin)
+{
+       int ret;
+
+       /* For each event, print header, context, payload */
+       /* TODO: order events by timestamps across streams */
+       for (;;) {
+               ret = print_event(fmt_write, sout, fmt_read, sin);
+               if (ret == -EOF)
+                       break;
+               else if (ret) {
+                       fprintf(stdout, "[error] Printing event failed.\n");
+                       goto error;
+               }
+       }
+
+       return 0;
+
+error:
+       return ret;
+}
+
+int print_trace(struct format *fmt_write,
+               struct trace_descriptor *td_write,
+               struct format *fmt_read,
+               struct trace_descriptor *td_read)
+{
+       struct ctf_trace *tin = container_of(td_read, struct ctf_trace, parent);
+       struct ctf_text_stream_pos *sout = container_of(td_write, struct ctf_text_stream_pos, parent);
+       int stream_id, filenr;
+       int ret;
+
+       /* For each stream (TODO: order events by timestamp) */
+       for (stream_id = 0; stream_id < tin->streams->len; stream_id++) {
+               struct ctf_stream *stream = g_ptr_array_index(tin->streams, stream_id);
+
+               if (!stream)
+                       continue;
+               for (filenr = 0; filenr < stream->files->len; filenr++) {
+                       struct ctf_file_stream *file_stream = g_ptr_array_index(stream->files, filenr);
+                       ret = print_stream(fmt_write, sout, fmt_read, file_stream);
+                       if (ret) {
+                               fprintf(stdout, "[error] Printing stream %d failed.\n", stream_id);
+                               goto error;
+                       }
+               }
+       }
+
+       return 0;
+
+error:
+       return ret;
+}
index dd6b9a2c40c3f3079a8c920e336eaa16a112058f..0ec30162a0dcc16d56216a38d93ba08c3ae62ede 100644 (file)
@@ -206,12 +206,19 @@ int main(int argc, char **argv)
                        opt_output_path);
                goto error_td_write;
        }
-
+#if 0
+       ret = print_trace(fmt_write, td_write, fmt_read, td_read);
+       if (ret) {
+               fprintf(stdout, "Error printing trace.\n\n");
+               goto error_copy_trace;
+       }
+#endif //0
        fmt_write->close_trace(td_write);
        fmt_read->close_trace(td_read);
        exit(EXIT_SUCCESS);
 
        /* Error handling */
+error_copy_trace:
        fmt_write->close_trace(td_write);
 error_td_write:
        fmt_read->close_trace(td_read);
index 6488ffc965da2ecb667fee4ea6f08f6c9ddcdc76..614adc028d40071da0c98a4b14128887906095e6 100644 (file)
 
 extern int yydebug;
 
-struct trace_descriptor {
-       struct ctf_trace ctf_trace;
-};
-
 struct trace_descriptor *ctf_open_trace(const char *path, int flags);
 void ctf_close_trace(struct trace_descriptor *descriptor);
 
@@ -81,7 +77,7 @@ static struct format ctf_format = {
        .close_trace = ctf_close_trace,
 };
 
-void init_pos(struct stream_pos *pos, int fd)
+void ctf_init_pos(struct ctf_stream_pos *pos, int fd)
 {
        pos->fd = fd;
        pos->mmap_offset = 0;
@@ -106,7 +102,7 @@ void init_pos(struct stream_pos *pos, int fd)
                case O_RDWR:
                        pos->prot = PROT_WRITE; /* Write has priority */
                        pos->flags = MAP_SHARED;
-                       move_pos_slow(pos, 0);  /* position for write */
+                       ctf_move_pos_slow(pos, 0);      /* position for write */
                        break;
                default:
                        assert(0);
@@ -115,7 +111,7 @@ void init_pos(struct stream_pos *pos, int fd)
        }
 }
 
-void fini_pos(struct stream_pos *pos)
+void ctf_fini_pos(struct ctf_stream_pos *pos)
 {
        int ret;
 
@@ -125,7 +121,7 @@ void fini_pos(struct stream_pos *pos)
                /* unmap old base */
                ret = munmap(pos->base, pos->packet_size / CHAR_BIT);
                if (ret) {
-                       fprintf(stdout, "Unable to unmap old base: %s.\n",
+                       fprintf(stdout, "[error] Unable to unmap old base: %s.\n",
                                strerror(errno));
                        assert(0);
                }
@@ -133,7 +129,7 @@ void fini_pos(struct stream_pos *pos)
        (void) g_array_free(pos->packet_index, TRUE);
 }
 
-void move_pos_slow(struct stream_pos *pos, size_t offset)
+void ctf_move_pos_slow(struct ctf_stream_pos *pos, size_t offset)
 {
        int ret;
        off_t off;
@@ -147,14 +143,14 @@ void move_pos_slow(struct stream_pos *pos, size_t offset)
                /* unmap old base */
                ret = munmap(pos->base, pos->packet_size / CHAR_BIT);
                if (ret) {
-                       fprintf(stdout, "Unable to unmap old base: %s.\n",
+                       fprintf(stdout, "[error] Unable to unmap old base: %s.\n",
                                strerror(errno));
                        assert(0);
                }
        }
 
        /*
-        * The caller should never ask for move_pos across packets,
+        * The caller should never ask for ctf_move_pos across packets,
         * except to get exactly at the beginning of the next packet.
         */
        if (pos->prot == PROT_WRITE) {
@@ -200,58 +196,57 @@ void move_pos_slow(struct stream_pos *pos, size_t offset)
  * (without any header nor packets nor padding).
  */
 static
-int ctf_open_trace_metadata_read(struct trace_descriptor *td)
+int ctf_open_trace_metadata_read(struct ctf_trace *td)
 {
        struct ctf_scanner *scanner;
        FILE *fp;
        int ret = 0;
 
-       td->ctf_trace.metadata.pos.fd = openat(td->ctf_trace.dirfd,
-                       "metadata", O_RDONLY);
-       if (td->ctf_trace.metadata.pos.fd < 0) {
+       td->metadata.pos.fd = openat(td->dirfd, "metadata", O_RDONLY);
+       if (td->metadata.pos.fd < 0) {
                fprintf(stdout, "Unable to open metadata.\n");
-               return td->ctf_trace.metadata.pos.fd;
+               return td->metadata.pos.fd;
        }
 
        if (babeltrace_debug)
                yydebug = 1;
 
-       fp = fdopen(td->ctf_trace.metadata.pos.fd, "r");
+       fp = fdopen(td->metadata.pos.fd, "r");
        if (!fp) {
-               fprintf(stdout, "Unable to open metadata stream.\n");
+               fprintf(stdout, "[error] Unable to open metadata stream.\n");
                ret = -errno;
                goto end_stream;
        }
 
        scanner = ctf_scanner_alloc(fp);
        if (!scanner) {
-               fprintf(stdout, "Error allocating scanner\n");
+               fprintf(stdout, "[error] Error allocating scanner\n");
                ret = -ENOMEM;
                goto end_scanner_alloc;
        }
        ret = ctf_scanner_append_ast(scanner);
        if (ret) {
-               fprintf(stdout, "Error creating AST\n");
+               fprintf(stdout, "[error] Error creating AST\n");
                goto end;
        }
 
        if (babeltrace_debug) {
                ret = ctf_visitor_print_xml(stdout, 0, &scanner->ast->root);
                if (ret) {
-                       fprintf(stdout, "Error visiting AST for XML output\n");
+                       fprintf(stdout, "[error] Error visiting AST for XML output\n");
                        goto end;
                }
        }
 
        ret = ctf_visitor_semantic_check(stdout, 0, &scanner->ast->root);
        if (ret) {
-               fprintf(stdout, "Error in CTF semantic validation %d\n", ret);
+               fprintf(stdout, "[error] Error in CTF semantic validation %d\n", ret);
                goto end;
        }
        ret = ctf_visitor_construct_metadata(stdout, 0, &scanner->ast->root,
-                       &td->ctf_trace, BYTE_ORDER);
+                       td, BYTE_ORDER);
        if (ret) {
-               fprintf(stdout, "Error in CTF metadata constructor %d\n", ret);
+               fprintf(stdout, "[error] Error in CTF metadata constructor %d\n", ret);
                goto end;
        }
 end:
@@ -259,18 +254,18 @@ end:
 end_scanner_alloc:
        fclose(fp);
 end_stream:
-       close(td->ctf_trace.metadata.pos.fd);
+       close(td->metadata.pos.fd);
        return ret;
 }
 
 
 static
-int create_stream_packet_index(struct trace_descriptor *td,
+int create_stream_packet_index(struct ctf_trace *td,
                               struct ctf_file_stream *file_stream)
 {
        struct ctf_stream *stream;
        int len_index;
-       struct stream_pos *pos;
+       struct ctf_stream_pos *pos;
        struct stat filestats;
        struct packet_index packet_index;
        int first_packet = 1;
@@ -289,7 +284,7 @@ int create_stream_packet_index(struct trace_descriptor *td,
                        /* unmap old base */
                        ret = munmap(pos->base, pos->packet_size / CHAR_BIT);
                        if (ret) {
-                               fprintf(stdout, "Unable to unmap old base: %s.\n",
+                               fprintf(stdout, "[error] Unable to unmap old base: %s.\n",
                                        strerror(errno));
                                return ret;
                        }
@@ -307,17 +302,17 @@ int create_stream_packet_index(struct trace_descriptor *td,
                packet_index.packet_size = 0;
 
                /* read and check header, set stream id (and check) */
-               if (td->ctf_trace.packet_header) {
+               if (td->packet_header) {
                        /* Read packet header */
-                       td->ctf_trace.packet_header->p.declaration->copy(NULL, NULL,
-                               pos, &ctf_format, &td->ctf_trace.packet_header->p);
+                       td->packet_header->p.declaration->copy(NULL, NULL,
+                               &pos->parent, &ctf_format, &td->packet_header->p);
 
-                       len_index = struct_declaration_lookup_field_index(td->ctf_trace.packet_header->declaration, g_quark_from_static_string("magic"));
+                       len_index = struct_declaration_lookup_field_index(td->packet_header->declaration, g_quark_from_static_string("magic"));
                        if (len_index >= 0) {
                                struct definition_integer *defint;
                                struct field *field;
 
-                               field = struct_definition_get_field_from_index(td->ctf_trace.packet_header, len_index);
+                               field = struct_definition_get_field_from_index(td->packet_header, len_index);
                                assert(field->definition->declaration->id == CTF_TYPE_INTEGER);
                                defint = container_of(field->definition, struct definition_integer, p);
                                assert(defint->declaration->signedness == FALSE);
@@ -331,14 +326,14 @@ int create_stream_packet_index(struct trace_descriptor *td,
                        }
 
                        /* check uuid */
-                       len_index = struct_declaration_lookup_field_index(td->ctf_trace.packet_header->declaration, g_quark_from_static_string("trace_uuid"));
+                       len_index = struct_declaration_lookup_field_index(td->packet_header->declaration, g_quark_from_static_string("trace_uuid"));
                        if (len_index >= 0) {
                                struct definition_array *defarray;
                                struct field *field;
                                uint64_t i;
                                uint8_t uuidval[UUID_LEN];
 
-                               field = struct_definition_get_field_from_index(td->ctf_trace.packet_header, len_index);
+                               field = struct_definition_get_field_from_index(td->packet_header, len_index);
                                assert(field->definition->declaration->id == CTF_TYPE_ARRAY);
                                defarray = container_of(field->definition, struct definition_array, p);
                                assert(array_len(defarray) == UUID_LEN);
@@ -353,7 +348,7 @@ int create_stream_packet_index(struct trace_descriptor *td,
                                        defint = container_of(elem, struct definition_integer, p);
                                        uuidval[i] = defint->value._unsigned;
                                }
-                               ret = uuid_compare(td->ctf_trace.uuid, uuidval);
+                               ret = uuid_compare(td->uuid, uuidval);
                                if (ret) {
                                        fprintf(stdout, "[error] Unique Universal Identifiers do not match.\n");
                                        return -EINVAL;
@@ -361,12 +356,12 @@ int create_stream_packet_index(struct trace_descriptor *td,
                        }
 
 
-                       len_index = struct_declaration_lookup_field_index(td->ctf_trace.packet_header->declaration, g_quark_from_static_string("stream_id"));
+                       len_index = struct_declaration_lookup_field_index(td->packet_header->declaration, g_quark_from_static_string("stream_id"));
                        if (len_index >= 0) {
                                struct definition_integer *defint;
                                struct field *field;
 
-                               field = struct_definition_get_field_from_index(td->ctf_trace.packet_header, len_index);
+                               field = struct_definition_get_field_from_index(td->packet_header, len_index);
                                assert(field->definition->declaration->id == CTF_TYPE_INTEGER);
                                defint = container_of(field->definition, struct definition_integer, p);
                                assert(defint->declaration->signedness == FALSE);
@@ -380,11 +375,11 @@ int create_stream_packet_index(struct trace_descriptor *td,
                }
                if (first_packet) {
                        file_stream->stream_id = stream_id;
-                       if (stream_id >= td->ctf_trace.streams->len) {
+                       if (stream_id >= td->streams->len) {
                                fprintf(stdout, "[error] Stream %" PRIu64 " is not declared in metadata.\n", stream_id);
                                return -EINVAL;
                        }
-                       stream = g_ptr_array_index(td->ctf_trace.streams, stream_id);
+                       stream = g_ptr_array_index(td->streams, stream_id);
                        if (!stream) {
                                fprintf(stdout, "[error] Stream %" PRIu64 " is not declared in metadata.\n", stream_id);
                                return -EINVAL;
@@ -396,7 +391,7 @@ int create_stream_packet_index(struct trace_descriptor *td,
                if (stream->packet_context) {
                        /* Read packet context */
                        stream->packet_context->p.declaration->copy(NULL, NULL,
-                                       pos, &ctf_format, &stream->packet_context->p);
+                                       &pos->parent, &ctf_format, &stream->packet_context->p);
 
                        /* read content size from header */
                        len_index = struct_declaration_lookup_field_index(stream->packet_context->declaration, g_quark_from_static_string("content_size"));
@@ -450,16 +445,16 @@ int create_stream_packet_index(struct trace_descriptor *td,
  * description (metadata).
  */
 static
-int ctf_open_file_stream_read(struct trace_descriptor *td, const char *path, int flags)
+int ctf_open_file_stream_read(struct ctf_trace *td, const char *path, int flags)
 {
        int ret;
        struct ctf_file_stream *file_stream;
 
-       ret = openat(td->ctf_trace.dirfd, path, flags);
+       ret = openat(td->dirfd, path, flags);
        if (ret < 0)
                goto error;
        file_stream = g_new0(struct ctf_file_stream, 1);
-       init_pos(&file_stream->pos, ret);
+       ctf_init_pos(&file_stream->pos, ret);
        ret = create_stream_packet_index(td, file_stream);
        if (ret)
                goto error_index;
@@ -468,7 +463,7 @@ int ctf_open_file_stream_read(struct trace_descriptor *td, const char *path, int
        return 0;
 
 error_index:
-       fini_pos(&file_stream->pos);
+       ctf_fini_pos(&file_stream->pos);
        close(file_stream->pos.fd);
        g_free(file_stream);
 error:
@@ -476,31 +471,31 @@ error:
 }
 
 static
-int ctf_open_trace_read(struct trace_descriptor *td, const char *path, int flags)
+int ctf_open_trace_read(struct ctf_trace *td, const char *path, int flags)
 {
        int ret;
        struct dirent *dirent;
        struct dirent *diriter;
        size_t dirent_len;
 
-       td->ctf_trace.flags = flags;
+       td->flags = flags;
 
        /* Open trace directory */
-       td->ctf_trace.dir = opendir(path);
-       if (!td->ctf_trace.dir) {
+       td->dir = opendir(path);
+       if (!td->dir) {
                fprintf(stdout, "[error] Unable to open trace directory.\n");
                ret = -ENOENT;
                goto error;
        }
 
-       td->ctf_trace.dirfd = open(path, 0);
-       if (td->ctf_trace.dirfd < 0) {
+       td->dirfd = open(path, 0);
+       if (td->dirfd < 0) {
                fprintf(stdout, "[error] Unable to open trace directory file descriptor.\n");
                ret = -ENOENT;
                goto error_dirfd;
        }
 
-       td->ctf_trace.streams = g_ptr_array_new();
+       td->streams = g_ptr_array_new();
 
        /*
         * Keep the metadata file separate.
@@ -518,12 +513,12 @@ int ctf_open_trace_read(struct trace_descriptor *td, const char *path, int flags
         */
 
        dirent_len = offsetof(struct dirent, d_name) +
-                       fpathconf(td->ctf_trace.dirfd, _PC_NAME_MAX) + 1;
+                       fpathconf(td->dirfd, _PC_NAME_MAX) + 1;
 
        dirent = malloc(dirent_len);
 
        for (;;) {
-               ret = readdir_r(td->ctf_trace.dir, dirent, &diriter);
+               ret = readdir_r(td->dir, dirent, &diriter);
                if (ret) {
                        fprintf(stdout, "[error] Readdir error.\n");
                        goto readdir_error;
@@ -547,16 +542,16 @@ int ctf_open_trace_read(struct trace_descriptor *td, const char *path, int flags
 readdir_error:
        free(dirent);
 error_metadata:
-       g_ptr_array_free(td->ctf_trace.streams, TRUE);
-       close(td->ctf_trace.dirfd);
+       g_ptr_array_free(td->streams, TRUE);
+       close(td->dirfd);
 error_dirfd:
-       closedir(td->ctf_trace.dir);
+       closedir(td->dir);
 error:
        return ret;
 }
 
 static
-int ctf_open_trace_write(struct trace_descriptor *td, const char *path, int flags)
+int ctf_open_trace_write(struct ctf_trace *td, const char *path, int flags)
 {
        int ret;
 
@@ -565,9 +560,9 @@ int ctf_open_trace_write(struct trace_descriptor *td, const char *path, int flag
                return ret;
 
        /* Open trace directory */
-       td->ctf_trace.dir = opendir(path);
-       if (!td->ctf_trace.dir) {
-               fprintf(stdout, "Unable to open trace directory.\n");
+       td->dir = opendir(path);
+       if (!td->dir) {
+               fprintf(stdout, "[error] Unable to open trace directory.\n");
                ret = -ENOENT;
                goto error;
        }
@@ -581,10 +576,10 @@ error:
 
 struct trace_descriptor *ctf_open_trace(const char *path, int flags)
 {
-       struct trace_descriptor *td;
+       struct ctf_trace *td;
        int ret;
 
-       td = g_new0(struct trace_descriptor, 1);
+       td = g_new0(struct ctf_trace, 1);
 
        switch (flags & O_ACCMODE) {
        case O_RDONLY:
@@ -593,16 +588,20 @@ struct trace_descriptor *ctf_open_trace(const char *path, int flags)
                        goto error;
                break;
        case O_WRONLY:
+               fprintf(stdout, "[error] Opening CTF traces for output is not supported yet.\n");
+               goto error;
+#if 0
                ret = ctf_open_trace_write(td, path, flags);
                if (ret)
                        goto error;
+#endif //0
                break;
        default:
-               fprintf(stdout, "Incorrect open flags.\n");
+               fprintf(stdout, "[error] Incorrect open flags.\n");
                goto error;
        }
 
-       return td;
+       return &td->parent;
 error:
        g_free(td);
        return NULL;
@@ -611,30 +610,31 @@ error:
 static
 void ctf_close_file_stream(struct ctf_file_stream *file_stream)
 {
-       fini_pos(&file_stream->pos);
+       ctf_fini_pos(&file_stream->pos);
        close(file_stream->pos.fd);
 }
 
-void ctf_close_trace(struct trace_descriptor *td)
+void ctf_close_trace(struct trace_descriptor *tdp)
 {
+       struct ctf_trace *td = container_of(tdp, struct ctf_trace, parent);
        int i;
 
-       if (td->ctf_trace.streams) {
-               for (i = 0; i < td->ctf_trace.streams->len; i++) {
+       if (td->streams) {
+               for (i = 0; i < td->streams->len; i++) {
                        struct ctf_stream *stream;
                        int j;
 
-                       stream = g_ptr_array_index(td->ctf_trace.streams, i);
+                       stream = g_ptr_array_index(td->streams, i);
                        for (j = 0; j < stream->files->len; j++) {
                                struct ctf_file_stream *file_stream;
-                               file_stream = g_ptr_array_index(td->ctf_trace.streams, j);
+                               file_stream = g_ptr_array_index(td->streams, j);
                                ctf_close_file_stream(file_stream);
                        }
 
                }
-               g_ptr_array_free(td->ctf_trace.streams, TRUE);
+               g_ptr_array_free(td->streams, TRUE);
        }
-       closedir(td->ctf_trace.dir);
+       closedir(td->dir);
        g_free(td);
 }
 
index 3d84952bbb547480f97bbd77768d55113b42f820..d33e6ad976460a4098125d49138c061293bab47e 100644 (file)
@@ -102,8 +102,8 @@ void _ctf_float_copy(struct stream_pos *destp,
 void ctf_float_copy(struct stream_pos *dest, struct stream_pos *src,
                    const struct declaration_float *float_declaration)
 {
-       align_pos(src, float_declaration->p.alignment);
-       align_pos(dest, float_declaration->p.alignment);
+       ctf_align_pos(ctf_pos(src), float_declaration->p.alignment);
+       ctf_align_pos(ctf_pos(dest), float_declaration->p.alignment);
        _ctf_float_copy(dest, float_declaration, src, float_declaration);
 }
 
@@ -116,12 +116,12 @@ double ctf_double_read(struct stream_pos *srcp,
                                sizeof(double) * CHAR_BIT - DBL_MANT_DIG,
                                BYTE_ORDER,
                                __alignof__(double));
-       struct stream_pos destp;
+       struct ctf_stream_pos destp;
 
-       align_pos(srcp, float_declaration->p.alignment);
-       init_pos(&destp, -1);
+       ctf_align_pos(ctf_pos(srcp), float_declaration->p.alignment);
+       ctf_init_pos(&destp, -1);
        destp.base = (char *) u.bits;
-       _ctf_float_copy(&destp, dest_declaration, srcp, float_declaration);
+       _ctf_float_copy(&destp.parent, dest_declaration, srcp, float_declaration);
        declaration_unref(&dest_declaration->p);
        return u.v;
 }
@@ -136,13 +136,13 @@ void ctf_double_write(struct stream_pos *destp,
                                sizeof(double) * CHAR_BIT - DBL_MANT_DIG,
                                BYTE_ORDER,
                                __alignof__(double));
-       struct stream_pos srcp;
+       struct ctf_stream_pos srcp;
 
        u.v = v;
-       align_pos(destp, float_declaration->p.alignment);
-       init_pos(&srcp, -1);
+       ctf_align_pos(ctf_pos(destp), float_declaration->p.alignment);
+       ctf_init_pos(&srcp, -1);
        srcp.base = (char *) u.bits;
-       _ctf_float_copy(destp, float_declaration, &srcp, src_declaration);
+       _ctf_float_copy(destp, float_declaration, &srcp.parent, src_declaration);
        declaration_unref(&src_declaration->p);
 }
 
@@ -155,12 +155,12 @@ long double ctf_ldouble_read(struct stream_pos *srcp,
                                sizeof(long double) * CHAR_BIT - LDBL_MANT_DIG,
                                BYTE_ORDER,
                                __alignof__(long double));
-       struct stream_pos destp;
+       struct ctf_stream_pos destp;
 
-       align_pos(srcp, float_declaration->p.alignment);
-       init_pos(&destp, -1);
+       ctf_align_pos(ctf_pos(srcp), float_declaration->p.alignment);
+       ctf_init_pos(&destp, -1);
        destp.base = (char *) u.bits;
-       _ctf_float_copy(&destp, dest_declaration, srcp, float_declaration);
+       _ctf_float_copy(&destp.parent, dest_declaration, srcp, float_declaration);
        declaration_unref(&dest_declaration->p);
        return u.v;
 }
@@ -175,12 +175,12 @@ void ctf_ldouble_write(struct stream_pos *destp,
                                sizeof(long double) * CHAR_BIT - LDBL_MANT_DIG,
                                BYTE_ORDER,
                                __alignof__(long double));
-       struct stream_pos srcp;
+       struct ctf_stream_pos srcp;
 
        u.v = v;
-       align_pos(destp, float_declaration->p.alignment);
-       init_pos(&srcp, -1);
+       ctf_align_pos(ctf_pos(destp), float_declaration->p.alignment);
+       ctf_init_pos(&srcp, -1);
        srcp.base = (char *) u.bits;
-       _ctf_float_copy(destp, float_declaration, &srcp, src_declaration);
+       _ctf_float_copy(destp, float_declaration, &srcp.parent, src_declaration);
        declaration_unref(&src_declaration->p);
 }
index fb6e0d425d2c7cbf420b11595aeff664ff1516a6..c024530058a1a67ab811ebbbdf24c715cfb1b01b 100644 (file)
 #include <endian.h>
 
 static
-uint64_t _aligned_uint_read(struct stream_pos *pos,
-                      const struct declaration_integer *integer_declaration)
+uint64_t _aligned_uint_read(struct stream_pos *ppos,
+                           const struct declaration_integer *integer_declaration)
 {
+       struct ctf_stream_pos *pos = ctf_pos(ppos);
        int rbo = (integer_declaration->byte_order != BYTE_ORDER);      /* reverse byte order */
 
-       align_pos(pos, integer_declaration->p.alignment);
+       ctf_align_pos(pos, integer_declaration->p.alignment);
        assert(!(pos->offset % CHAR_BIT));
        switch (integer_declaration->len) {
        case 8:
@@ -36,7 +37,7 @@ uint64_t _aligned_uint_read(struct stream_pos *pos,
                uint8_t v;
 
                v = *(const uint8_t *)pos->base;
-               move_pos(pos, integer_declaration->len);
+               ctf_move_pos(pos, integer_declaration->len);
                return v;
        }
        case 16:
@@ -44,7 +45,7 @@ uint64_t _aligned_uint_read(struct stream_pos *pos,
                uint16_t v;
 
                v = *(const uint16_t *)pos->base;
-               move_pos(pos, integer_declaration->len);
+               ctf_move_pos(pos, integer_declaration->len);
                return rbo ? GUINT16_SWAP_LE_BE(v) : v;
        }
        case 32:
@@ -52,7 +53,7 @@ uint64_t _aligned_uint_read(struct stream_pos *pos,
                uint32_t v;
 
                v = *(const uint32_t *)pos->base;
-               move_pos(pos, integer_declaration->len);
+               ctf_move_pos(pos, integer_declaration->len);
                return rbo ? GUINT32_SWAP_LE_BE(v) : v;
        }
        case 64:
@@ -60,7 +61,7 @@ uint64_t _aligned_uint_read(struct stream_pos *pos,
                uint64_t v;
 
                v = *(const uint64_t *)pos->base;
-               move_pos(pos, integer_declaration->len);
+               ctf_move_pos(pos, integer_declaration->len);
                return rbo ? GUINT64_SWAP_LE_BE(v) : v;
        }
        default:
@@ -69,12 +70,13 @@ uint64_t _aligned_uint_read(struct stream_pos *pos,
 }
 
 static
-int64_t _aligned_int_read(struct stream_pos *pos,
-                    const struct declaration_integer *integer_declaration)
+int64_t _aligned_int_read(struct stream_pos *ppos,
+                         const struct declaration_integer *integer_declaration)
 {
+       struct ctf_stream_pos *pos = ctf_pos(ppos);
        int rbo = (integer_declaration->byte_order != BYTE_ORDER);      /* reverse byte order */
 
-       align_pos(pos, integer_declaration->p.alignment);
+       ctf_align_pos(pos, integer_declaration->p.alignment);
        assert(!(pos->offset % CHAR_BIT));
        switch (integer_declaration->len) {
        case 8:
@@ -82,7 +84,7 @@ int64_t _aligned_int_read(struct stream_pos *pos,
                int8_t v;
 
                v = *(const int8_t *)pos->base;
-               move_pos(pos, integer_declaration->len);
+               ctf_move_pos(pos, integer_declaration->len);
                return v;
        }
        case 16:
@@ -90,7 +92,7 @@ int64_t _aligned_int_read(struct stream_pos *pos,
                int16_t v;
 
                v = *(const int16_t *)pos->base;
-               move_pos(pos, integer_declaration->len);
+               ctf_move_pos(pos, integer_declaration->len);
                return rbo ? GUINT16_SWAP_LE_BE(v) : v;
        }
        case 32:
@@ -98,7 +100,7 @@ int64_t _aligned_int_read(struct stream_pos *pos,
                int32_t v;
 
                v = *(const int32_t *)pos->base;
-               move_pos(pos, integer_declaration->len);
+               ctf_move_pos(pos, integer_declaration->len);
                return rbo ? GUINT32_SWAP_LE_BE(v) : v;
        }
        case 64:
@@ -106,7 +108,7 @@ int64_t _aligned_int_read(struct stream_pos *pos,
                int64_t v;
 
                v = *(const int64_t *)pos->base;
-               move_pos(pos, integer_declaration->len);
+               ctf_move_pos(pos, integer_declaration->len);
                return rbo ? GUINT64_SWAP_LE_BE(v) : v;
        }
        default:
@@ -115,115 +117,121 @@ int64_t _aligned_int_read(struct stream_pos *pos,
 }
 
 static
-void _aligned_uint_write(struct stream_pos *pos,
-                   const struct declaration_integer *integer_declaration,
-                   uint64_t v)
+void _aligned_uint_write(struct stream_pos *ppos,
+                        const struct declaration_integer *integer_declaration,
+                        uint64_t v)
 {
+       struct ctf_stream_pos *pos = ctf_pos(ppos);
        int rbo = (integer_declaration->byte_order != BYTE_ORDER);      /* reverse byte order */
 
-       align_pos(pos, integer_declaration->p.alignment);
+       ctf_align_pos(pos, integer_declaration->p.alignment);
        assert(!(pos->offset % CHAR_BIT));
        if (pos->dummy)
                goto end;
 
        switch (integer_declaration->len) {
-       case 8: *(uint8_t *) get_pos_addr(pos) = (uint8_t) v;
+       case 8: *(uint8_t *) ctf_get_pos_addr(pos) = (uint8_t) v;
                break;
        case 16:
-               *(uint16_t *) get_pos_addr(pos) = rbo ?
+               *(uint16_t *) ctf_get_pos_addr(pos) = rbo ?
                                         GUINT16_SWAP_LE_BE((uint16_t) v) :
                                         (uint16_t) v;
                break;
        case 32:
-               *(uint32_t *) get_pos_addr(pos) = rbo ?
+               *(uint32_t *) ctf_get_pos_addr(pos) = rbo ?
                                         GUINT32_SWAP_LE_BE((uint32_t) v) :
                                         (uint32_t) v;
                break;
        case 64:
-               *(uint64_t *) get_pos_addr(pos) = rbo ?
+               *(uint64_t *) ctf_get_pos_addr(pos) = rbo ?
                                         GUINT64_SWAP_LE_BE(v) : v;
                break;
        default:
                assert(0);
        }
 end:
-       move_pos(pos, integer_declaration->len);
+       ctf_move_pos(pos, integer_declaration->len);
 }
 
 static
-void _aligned_int_write(struct stream_pos *pos,
-                  const struct declaration_integer *integer_declaration,
-                  int64_t v)
+void _aligned_int_write(struct stream_pos *ppos,
+                       const struct declaration_integer *integer_declaration,
+                       int64_t v)
 {
+       struct ctf_stream_pos *pos = ctf_pos(ppos);
        int rbo = (integer_declaration->byte_order != BYTE_ORDER);      /* reverse byte order */
 
-       align_pos(pos, integer_declaration->p.alignment);
+       ctf_align_pos(pos, integer_declaration->p.alignment);
        assert(!(pos->offset % CHAR_BIT));
        if (pos->dummy)
                goto end;
 
        switch (integer_declaration->len) {
-       case 8: *(int8_t *) get_pos_addr(pos) = (int8_t) v;
+       case 8: *(int8_t *) ctf_get_pos_addr(pos) = (int8_t) v;
                break;
        case 16:
-               *(int16_t *) get_pos_addr(pos) = rbo ?
+               *(int16_t *) ctf_get_pos_addr(pos) = rbo ?
                                         GUINT16_SWAP_LE_BE((int16_t) v) :
                                         (int16_t) v;
                break;
        case 32:
-               *(int32_t *) get_pos_addr(pos) = rbo ?
+               *(int32_t *) ctf_get_pos_addr(pos) = rbo ?
                                         GUINT32_SWAP_LE_BE((int32_t) v) :
                                         (int32_t) v;
                break;
        case 64:
-               *(int64_t *) get_pos_addr(pos) = rbo ?
+               *(int64_t *) ctf_get_pos_addr(pos) = rbo ?
                                         GUINT64_SWAP_LE_BE(v) : v;
                break;
        default:
                assert(0);
        }
 end:
-       move_pos(pos, integer_declaration->len);
+       ctf_move_pos(pos, integer_declaration->len);
        return;
 }
 
-uint64_t ctf_uint_read(struct stream_pos *pos,
+uint64_t ctf_uint_read(struct stream_pos *ppos,
                        const struct declaration_integer *integer_declaration)
 {
+       struct ctf_stream_pos *pos = ctf_pos(ppos);
        uint64_t v = 0;
 
-       align_pos(pos, integer_declaration->p.alignment);
+       ctf_align_pos(pos, integer_declaration->p.alignment);
        if (integer_declaration->byte_order == LITTLE_ENDIAN)
                bt_bitfield_read_le(pos->base, unsigned long, pos->offset,
                                    integer_declaration->len, &v);
        else
                bt_bitfield_read_be(pos->base, unsigned long, pos->offset,
                                    integer_declaration->len, &v);
-       move_pos(pos, integer_declaration->len);
+       ctf_move_pos(pos, integer_declaration->len);
        return v;
 }
 
-int64_t ctf_int_read(struct stream_pos *pos,
+int64_t ctf_int_read(struct stream_pos *ppos,
                        const struct declaration_integer *integer_declaration)
 {
+       struct ctf_stream_pos *pos = ctf_pos(ppos);
        int64_t v = 0;
 
-       align_pos(pos, integer_declaration->p.alignment);
+       ctf_align_pos(pos, integer_declaration->p.alignment);
        if (integer_declaration->byte_order == LITTLE_ENDIAN)
                bt_bitfield_read_le(pos->base, unsigned long, pos->offset,
                                    integer_declaration->len, &v);
        else
                bt_bitfield_read_be(pos->base, unsigned long, pos->offset,
                                    integer_declaration->len, &v);
-       move_pos(pos, integer_declaration->len);
+       ctf_move_pos(pos, integer_declaration->len);
        return v;
 }
 
-void ctf_uint_write(struct stream_pos *pos,
-                       const struct declaration_integer *integer_declaration,
-                       uint64_t v)
+void ctf_uint_write(struct stream_pos *ppos,
+                   const struct declaration_integer *integer_declaration,
+                   uint64_t v)
 {
-       align_pos(pos, integer_declaration->p.alignment);
+       struct ctf_stream_pos *pos = ctf_pos(ppos);
+
+       ctf_align_pos(pos, integer_declaration->p.alignment);
        if (pos->dummy)
                goto end;
        if (integer_declaration->byte_order == LITTLE_ENDIAN)
@@ -233,14 +241,16 @@ void ctf_uint_write(struct stream_pos *pos,
                bt_bitfield_write_be(pos->base, unsigned long, pos->offset,
                                     integer_declaration->len, v);
 end:
-       move_pos(pos, integer_declaration->len);
+       ctf_move_pos(pos, integer_declaration->len);
 }
 
-void ctf_int_write(struct stream_pos *pos,
-                       const struct declaration_integer *integer_declaration,
-                       int64_t v)
+void ctf_int_write(struct stream_pos *ppos,
+                  const struct declaration_integer *integer_declaration,
+                  int64_t v)
 {
-       align_pos(pos, integer_declaration->p.alignment);
+       struct ctf_stream_pos *pos = ctf_pos(ppos);
+
+       ctf_align_pos(pos, integer_declaration->p.alignment);
        if (pos->dummy)
                goto end;
        if (integer_declaration->byte_order == LITTLE_ENDIAN)
@@ -250,5 +260,5 @@ void ctf_int_write(struct stream_pos *pos,
                bt_bitfield_write_be(pos->base, unsigned long, pos->offset,
                                     integer_declaration->len, v);
 end:
-       move_pos(pos, integer_declaration->len);
+       ctf_move_pos(pos, integer_declaration->len);
 }
index 24e09069e57cd7f4581fbc58dd7ab65a986c5907..640f451735ada1c3867c01058e69c881063a3fce 100644 (file)
 
 #include <babeltrace/ctf/types.h>
 
-void ctf_sequence_begin(struct stream_pos *pos,
+void ctf_sequence_begin(struct stream_pos *ppos,
                        const struct declaration_sequence *sequence_declaration)
 {
-       align_pos(pos, sequence_declaration->p.alignment);
+       struct ctf_stream_pos *pos = ctf_pos(ppos);
+
+       ctf_align_pos(pos, sequence_declaration->p.alignment);
 }
 
 void ctf_sequence_end(struct stream_pos *pos,
index 31b1d593a10eeac25698dd29224015611ff164bb..ac25e1adc4c5eb81bf5262110adf602e394bea67 100644 (file)
 #include <limits.h>            /* C99 limits */
 #include <string.h>
 
-void ctf_string_copy(struct stream_pos *dest, struct stream_pos *src,
+void ctf_string_copy(struct stream_pos *pdest, struct stream_pos *psrc,
                     const struct declaration_string *string_declaration)
 {
+       struct ctf_stream_pos *dest = ctf_pos(pdest);
+       struct ctf_stream_pos *src = ctf_pos(psrc);
        size_t len;
        char *destaddr, *srcaddr;
 
-       align_pos(src, string_declaration->p.alignment);
-       srcaddr = get_pos_addr(src);
+       ctf_align_pos(src, string_declaration->p.alignment);
+       srcaddr = ctf_get_pos_addr(src);
        len = strlen(srcaddr) + 1;
        if (dest->dummy)
                goto end;
-       align_pos(dest, string_declaration->p.alignment);
-       destaddr = get_pos_addr(dest);
+       ctf_align_pos(dest, string_declaration->p.alignment);
+       destaddr = ctf_get_pos_addr(dest);
        strcpy(destaddr, srcaddr);
 end:
-       move_pos(dest, len);
-       move_pos(src, len);
+       ctf_move_pos(dest, len);
+       ctf_move_pos(src, len);
 }
 
-void ctf_string_read(char **dest, struct stream_pos *src,
+void ctf_string_read(char **dest, struct stream_pos *psrc,
                     const struct declaration_string *string_declaration)
 {
+       struct ctf_stream_pos *src = ctf_pos(psrc);
        size_t len;
        char *srcaddr;
 
-       align_pos(src, string_declaration->p.alignment);
-       srcaddr = get_pos_addr(src);
+       ctf_align_pos(src, string_declaration->p.alignment);
+       srcaddr = ctf_get_pos_addr(src);
        len = strlen(srcaddr) + 1;
        *dest = g_realloc(*dest, len);
        strcpy(*dest, srcaddr);
-       move_pos(src, len);
+       ctf_move_pos(src, len);
 }
 
-void ctf_string_write(struct stream_pos *dest, const char *src,
+void ctf_string_write(struct stream_pos *pdest, const char *src,
                      const struct declaration_string *string_declaration)
 {
+       struct ctf_stream_pos *dest = ctf_pos(pdest);
        size_t len;
        char *destaddr;
 
-       align_pos(dest, string_declaration->p.alignment);
+       ctf_align_pos(dest, string_declaration->p.alignment);
        len = strlen(src) + 1;
        if (dest->dummy)
                goto end;
-       destaddr = get_pos_addr(dest);
+       destaddr = ctf_get_pos_addr(dest);
        strcpy(destaddr, src);
 end:
-       move_pos(dest, len);
+       ctf_move_pos(dest, len);
 }
 
 void ctf_string_free_temp(char *string)
index dc3a06eb0a8bcda6b6474d7a426d275fee5f0ba8..2a3fa4c5366c4c5730f988edb9cc74e2a812ed7a 100644 (file)
 
 #include <babeltrace/ctf/types.h>
 
-void ctf_struct_begin(struct stream_pos *pos,
+void ctf_struct_begin(struct stream_pos *ppos,
                      const struct declaration_struct *struct_declaration)
 {
-       align_pos(pos, struct_declaration->p.alignment);
+       struct ctf_stream_pos *pos = ctf_pos(ppos);
+
+       ctf_align_pos(pos, struct_declaration->p.alignment);
 }
 
-void ctf_struct_end(struct stream_pos *pos,
+void ctf_struct_end(struct stream_pos *ppos,
                    const struct declaration_struct *struct_declaration)
 {
 }
index a32ed9d0f316b69a8eee4276d795bd313e1aae5a..8e410b59c23635eb995c8f5281c1f44ae9f69f87 100644 (file)
@@ -18,4 +18,8 @@ extern int babeltrace_verbose, babeltrace_debug;
                        printf("[debug] " fmt, ## args);        \
        } while (0)
 
+struct trace_descriptor;
+
+int copy_trace(struct trace_descriptor *td_write, struct trace_descriptor *td_read);
+
 #endif
diff --git a/include/babeltrace/ctf-text/types.h b/include/babeltrace/ctf-text/types.h
new file mode 100644 (file)
index 0000000..1e48b93
--- /dev/null
@@ -0,0 +1,81 @@
+#ifndef _BABELTRACE_CTF_TEXT_TYPES_H
+#define _BABELTRACE_CTF_TEXT_TYPES_H
+
+/*
+ * Common Trace Format (Text Output)
+ *
+ * Type header
+ *
+ * Copyright 2010 - Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ */
+
+#include <sys/mman.h>
+#include <errno.h>
+#include <stdint.h>
+#include <unistd.h>
+#include <glib.h>
+#include <babeltrace/babeltrace.h>
+#include <babeltrace/types.h>
+
+struct ctf_text_stream_pos {
+       struct trace_descriptor parent;
+       FILE *fp;               /* File pointer. NULL if unset. */
+};
+
+/*
+ * IMPORTANT: All lengths (len) and offsets (start, end) are expressed in bits,
+ *            *not* in bytes.
+ *
+ * All write primitives, as well as read for dynamically sized entities, can
+ * receive a NULL ptr/dest parameter. In this case, no write is performed, but
+ * the size is returned.
+ */
+
+void ctf_text_uint_write(struct stream_pos *pos,
+               const struct declaration_integer *integer_declaration,
+               uint64_t v);
+void ctf_text_int_write(struct stream_pos *pos,
+               const struct declaration_integer *integer_declaration,
+               int64_t v);
+
+void ctf_text_double_write(struct stream_pos *pos,
+               const struct declaration_float *dest,
+               double v);
+void ctf_text_ldouble_write(struct stream_pos *pos,
+               const struct declaration_float *dest,
+               long double v);
+
+void ctf_text_string_write(struct stream_pos *dest, const char *src,
+               const struct declaration_string *string_declaration);
+
+void ctf_text_enum_write(struct stream_pos *pos,
+               const struct declaration_enum *dest,
+               GQuark q);
+void ctf_text_struct_begin(struct stream_pos *pos,
+               const struct declaration_struct *struct_declaration);
+void ctf_text_struct_end(struct stream_pos *pos,
+               const struct declaration_struct *struct_declaration);
+void ctf_text_variant_begin(struct stream_pos *pos,
+               const struct declaration_variant *variant_declaration);
+void ctf_text_variant_end(struct stream_pos *pos,
+               const struct declaration_variant *variant_declaration);
+void ctf_text_array_begin(struct stream_pos *pos,
+               const struct declaration_array *array_declaration);
+void ctf_text_array_end(struct stream_pos *pos,
+               const struct declaration_array *array_declaration);
+void ctf_text_sequence_begin(struct stream_pos *pos,
+               const struct declaration_sequence *sequence_declaration);
+void ctf_text_sequence_end(struct stream_pos *pos,
+               const struct declaration_sequence *sequence_declaration);
+
+#endif /* _BABELTRACE_CTF_TEXT_TYPES_H */
index 330238ba0dc5f0a2e63c5d381c4aeda693fcdb9c..5e7fd30e11dc4f66373fcdf2cf1a2b9f2fed688f 100644 (file)
@@ -20,6 +20,7 @@
  */
 
 #include <babeltrace/types.h>
+#include <babeltrace/format.h>
 #include <babeltrace/ctf/types.h>
 #include <sys/types.h>
 #include <dirent.h>
@@ -36,7 +37,7 @@ struct ctf_event;
 struct ctf_file_stream {
        uint64_t stream_id;
        struct ctf_stream *stream;
-       struct stream_pos pos;                  /* current stream position */
+       struct ctf_stream_pos pos;                      /* current stream position */
 };
 
 #define CTF_TRACE_SET_FIELD(ctf_trace, field)                          \
@@ -55,6 +56,7 @@ struct ctf_file_stream {
 
 
 struct ctf_trace {
+       struct trace_descriptor parent;
        /* root scope */
        struct declaration_scope *root_declaration_scope;
 
index 8f9bf992e9d49e18360e09f976d72a4636585f85..d47cab8203b4e8fbcd1f8085c904b8b81f4a7eba 100644 (file)
@@ -33,9 +33,10 @@ struct packet_index {
 };
 
 /*
- * Always update stream_pos with move_pos and init_pos.
+ * Always update ctf_stream_pos with ctf_move_pos and ctf_init_pos.
  */
-struct stream_pos {
+struct ctf_stream_pos {
+       struct stream_pos parent;
        int fd;                 /* backing file fd. -1 if unset. */
        GArray *packet_index;   /* contains struct packet_index */
        int prot;               /* mmap protection */
@@ -53,6 +54,12 @@ struct stream_pos {
        int dummy;              /* dummy position, for length calculation */
 };
 
+static inline
+struct ctf_stream_pos *ctf_pos(struct stream_pos *pos)
+{
+       return container_of(pos, struct ctf_stream_pos, parent);
+}
+
 /*
  * IMPORTANT: All lengths (len) and offsets (start, end) are expressed in bits,
  *            *not* in bytes.
@@ -117,10 +124,10 @@ void ctf_sequence_begin(struct stream_pos *pos,
 void ctf_sequence_end(struct stream_pos *pos,
                const struct declaration_sequence *sequence_declaration);
 
-void move_pos_slow(struct stream_pos *pos, size_t offset);
+void ctf_move_pos_slow(struct ctf_stream_pos *pos, size_t offset);
 
-void init_pos(struct stream_pos *pos, int fd);
-void fini_pos(struct stream_pos *pos);
+void ctf_init_pos(struct ctf_stream_pos *pos, int fd);
+void ctf_fini_pos(struct ctf_stream_pos *pos);
 
 /*
  * move_pos - move position of a relative bit offset
@@ -128,14 +135,14 @@ void fini_pos(struct stream_pos *pos);
  * TODO: allow larger files by updating base too.
  */
 static inline
-void move_pos(struct stream_pos *pos, size_t bit_offset)
+void ctf_move_pos(struct ctf_stream_pos *pos, size_t bit_offset)
 {
        if (pos->fd >= 0) {
                if (((pos->prot == PROT_READ)
                      && (pos->offset + bit_offset >= pos->content_size))
                    || ((pos->prot == PROT_WRITE)
                      && (pos->offset + bit_offset >= pos->packet_size))) {
-                       move_pos_slow(pos, bit_offset);
+                       ctf_move_pos_slow(pos, bit_offset);
                        return;
                }
        }
@@ -148,13 +155,13 @@ void move_pos(struct stream_pos *pos, size_t bit_offset)
  * TODO: allow larger files by updating base too.
  */
 static inline
-void align_pos(struct stream_pos *pos, size_t bit_offset)
+void ctf_align_pos(struct ctf_stream_pos *pos, size_t bit_offset)
 {
-       move_pos(pos, offset_align(pos->offset, bit_offset));
+       ctf_move_pos(pos, offset_align(pos->offset, bit_offset));
 }
 
 static inline
-char *get_pos_addr(struct stream_pos *pos)
+char *ctf_get_pos_addr(struct ctf_stream_pos *pos)
 {
        /* Only makes sense to get the address after aligning on CHAR_BIT */
        assert(!(pos->offset % CHAR_BIT));
@@ -162,9 +169,9 @@ char *get_pos_addr(struct stream_pos *pos)
 }
 
 static inline
-void dummy_pos(struct stream_pos *pos, struct stream_pos *dummy)
+void ctf_dummy_pos(struct ctf_stream_pos *pos, struct ctf_stream_pos *dummy)
 {
-       memcpy(dummy, pos, sizeof(struct stream_pos));
+       memcpy(dummy, pos, sizeof(struct ctf_stream_pos));
        dummy->dummy = 1;
        dummy->fd = -1;
 }
@@ -174,7 +181,7 @@ void dummy_pos(struct stream_pos *pos, struct stream_pos *dummy)
  * Returns 0 for success, negative error otherwise.
  */
 static inline
-int pos_packet(struct stream_pos *dummy)
+int ctf_pos_packet(struct ctf_stream_pos *dummy)
 {
        if (dummy->offset > dummy->packet_size)
                return -ENOSPC;
@@ -182,9 +189,9 @@ int pos_packet(struct stream_pos *dummy)
 }
 
 static inline
-void pos_pad_packet(struct stream_pos *pos)
+void ctf_pos_pad_packet(struct ctf_stream_pos *pos)
 {
-       move_pos(pos, pos->packet_size - pos->offset);
+       ctf_move_pos(pos, pos->packet_size - pos->offset);
 }
 
 #endif /* _BABELTRACE_CTF_TYPES_H */
index 151bd65a1e1effd4082c17282efe26682b677d92..cbba50b0ee26e6e3604ad35035720e0f66ff5401 100644 (file)
@@ -24,7 +24,9 @@
 #include <stdio.h>
 #include <glib.h>
 
-struct trace_descriptor;
+/* Parent trace descriptor */
+struct trace_descriptor {
+};
 
 struct format {
        GQuark name;
index 232cc2038a123725a907945c609b1e7308b41232..080ea6f17a7182ef7eabc0e3ed34e124e5cc5dba 100644 (file)
@@ -35,6 +35,10 @@ struct stream_pos;
 struct format;
 struct definition;
 
+/* Parent of per-plugin positions */
+struct stream_pos {
+};
+
 /* type scope */
 struct declaration_scope {
        /* Hash table mapping type name GQuark to "struct declaration" */
index ed00f34b0a1aa75b8e9dc6d5df0cbdfed40a89e8..ad0ff2041527d0e1fd3ecbcb56d066aba313b002 100644 (file)
@@ -37,72 +37,72 @@ int babeltrace_debug = 0;
 static uuid_t s_uuid;
 
 static
-void write_packet_header(struct stream_pos *pos, uuid_t uuid)
+void write_packet_header(struct ctf_stream_pos *pos, uuid_t uuid)
 {
-       struct stream_pos dummy;
+       struct ctf_stream_pos dummy;
 
        /* magic */
-       dummy_pos(pos, &dummy);
-       align_pos(&dummy, sizeof(uint32_t) * CHAR_BIT);
-       move_pos(&dummy, sizeof(uint32_t) * CHAR_BIT);
-       assert(!pos_packet(&dummy));
+       ctf_dummy_pos(pos, &dummy);
+       ctf_align_pos(&dummy, sizeof(uint32_t) * CHAR_BIT);
+       ctf_move_pos(&dummy, sizeof(uint32_t) * CHAR_BIT);
+       assert(!ctf_pos_packet(&dummy));
        
-       align_pos(pos, sizeof(uint32_t) * CHAR_BIT);
-       *(uint32_t *) get_pos_addr(pos) = 0xC1FC1FC1;
-       move_pos(pos, sizeof(uint32_t) * CHAR_BIT);
+       ctf_align_pos(pos, sizeof(uint32_t) * CHAR_BIT);
+       *(uint32_t *) ctf_get_pos_addr(pos) = 0xC1FC1FC1;
+       ctf_move_pos(pos, sizeof(uint32_t) * CHAR_BIT);
 
        /* trace_uuid */
-       dummy_pos(pos, &dummy);
-       align_pos(&dummy, sizeof(uint8_t) * CHAR_BIT);
-       move_pos(&dummy, 16 * CHAR_BIT);
-       assert(!pos_packet(&dummy));
-
-       align_pos(pos, sizeof(uint8_t) * CHAR_BIT);
-       memcpy(get_pos_addr(pos), uuid, 16);
-       move_pos(pos, 16 * CHAR_BIT);
+       ctf_dummy_pos(pos, &dummy);
+       ctf_align_pos(&dummy, sizeof(uint8_t) * CHAR_BIT);
+       ctf_move_pos(&dummy, 16 * CHAR_BIT);
+       assert(!ctf_pos_packet(&dummy));
+
+       ctf_align_pos(pos, sizeof(uint8_t) * CHAR_BIT);
+       memcpy(ctf_get_pos_addr(pos), uuid, 16);
+       ctf_move_pos(pos, 16 * CHAR_BIT);
 }
 
 static
-void write_packet_context(struct stream_pos *pos)
+void write_packet_context(struct ctf_stream_pos *pos)
 {
-       struct stream_pos dummy;
+       struct ctf_stream_pos dummy;
 
        /* content_size */
-       dummy_pos(pos, &dummy);
-       align_pos(&dummy, sizeof(uint32_t) * CHAR_BIT);
-       move_pos(&dummy, sizeof(uint32_t) * CHAR_BIT);
-       assert(!pos_packet(&dummy));
+       ctf_dummy_pos(pos, &dummy);
+       ctf_align_pos(&dummy, sizeof(uint32_t) * CHAR_BIT);
+       ctf_move_pos(&dummy, sizeof(uint32_t) * CHAR_BIT);
+       assert(!ctf_pos_packet(&dummy));
        
-       align_pos(pos, sizeof(uint32_t) * CHAR_BIT);
-       *(uint32_t *) get_pos_addr(pos) = -1U;  /* Not known yet */
-       pos->content_size_loc = (uint32_t *) get_pos_addr(pos);
-       move_pos(pos, sizeof(uint32_t) * CHAR_BIT);
+       ctf_align_pos(pos, sizeof(uint32_t) * CHAR_BIT);
+       *(uint32_t *) ctf_get_pos_addr(pos) = -1U;      /* Not known yet */
+       pos->content_size_loc = (uint32_t *) ctf_get_pos_addr(pos);
+       ctf_move_pos(pos, sizeof(uint32_t) * CHAR_BIT);
 
        /* packet_size */
-       dummy_pos(pos, &dummy);
-       align_pos(&dummy, sizeof(uint32_t) * CHAR_BIT);
-       move_pos(&dummy, sizeof(uint32_t) * CHAR_BIT);
-       assert(!pos_packet(&dummy));
+       ctf_dummy_pos(pos, &dummy);
+       ctf_align_pos(&dummy, sizeof(uint32_t) * CHAR_BIT);
+       ctf_move_pos(&dummy, sizeof(uint32_t) * CHAR_BIT);
+       assert(!ctf_pos_packet(&dummy));
        
-       align_pos(pos, sizeof(uint32_t) * CHAR_BIT);
-       *(uint32_t *) get_pos_addr(pos) = pos->packet_size;
-       move_pos(pos, sizeof(uint32_t) * CHAR_BIT);
+       ctf_align_pos(pos, sizeof(uint32_t) * CHAR_BIT);
+       *(uint32_t *) ctf_get_pos_addr(pos) = pos->packet_size;
+       ctf_move_pos(pos, sizeof(uint32_t) * CHAR_BIT);
 }
 
 static
-void trace_string(char *line, struct stream_pos *pos, size_t len)
+void trace_string(char *line, struct ctf_stream_pos *pos, size_t len)
 {
-       struct stream_pos dummy;
+       struct ctf_stream_pos dummy;
        int attempt = 0;
 
        printf_debug("read: %s\n", line);
 retry:
-       dummy_pos(pos, &dummy);
-       align_pos(&dummy, sizeof(uint8_t) * CHAR_BIT);
-       move_pos(&dummy, len * CHAR_BIT);
-       if (pos_packet(&dummy)) {
+       ctf_dummy_pos(pos, &dummy);
+       ctf_align_pos(&dummy, sizeof(uint8_t) * CHAR_BIT);
+       ctf_move_pos(&dummy, len * CHAR_BIT);
+       if (ctf_pos_packet(&dummy)) {
                /* TODO write content size */
-               pos_pad_packet(pos);
+               ctf_pos_pad_packet(pos);
                write_packet_header(pos, s_uuid);
                write_packet_context(pos);
                if (attempt++ == 1) {
@@ -113,20 +113,20 @@ retry:
                goto retry;
        }
 
-       align_pos(pos, sizeof(uint8_t) * CHAR_BIT);
-       memcpy(get_pos_addr(pos), line, len);
-       move_pos(pos, len * CHAR_BIT);
+       ctf_align_pos(pos, sizeof(uint8_t) * CHAR_BIT);
+       memcpy(ctf_get_pos_addr(pos), line, len);
+       ctf_move_pos(pos, len * CHAR_BIT);
 }
 
 static
 void trace_text(FILE *input, int output)
 {
-       struct stream_pos pos;
+       struct ctf_stream_pos pos;
        ssize_t len;
        char *line = NULL, *nl;
        size_t linesize;
 
-       init_pos(&pos, output);
+       ctf_init_pos(&pos, output);
 
        write_packet_header(&pos, s_uuid);
        write_packet_context(&pos);
@@ -139,7 +139,7 @@ void trace_text(FILE *input, int output)
                        *nl = '\0';
                trace_string(line, &pos, nl - line + 1);
        }
-       fini_pos(&pos);
+       ctf_fini_pos(&pos);
 }
 
 int main(int argc, char **argv)
This page took 0.08461 seconds and 4 git commands to generate.