Update pretty-print
authorMathieu Desnoyers <mathieu.desnoyers@efficios.com>
Mon, 9 May 2011 13:47:54 +0000 (09:47 -0400)
committerMathieu Desnoyers <mathieu.desnoyers@efficios.com>
Mon, 9 May 2011 13:47:54 +0000 (09:47 -0400)
Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
22 files changed:
converter/babeltrace-lib.c
formats/ctf-text/ctf-text.c
formats/ctf-text/types/array.c
formats/ctf-text/types/enum.c
formats/ctf-text/types/float.c
formats/ctf-text/types/integer.c
formats/ctf-text/types/sequence.c
formats/ctf-text/types/string.c
formats/ctf-text/types/struct.c
formats/ctf-text/types/variant.c
formats/ctf/ctf.c
include/babeltrace/ctf-text/types.h
include/babeltrace/types.h
types/array.c
types/enum.c
types/float.c
types/integer.c
types/sequence.c
types/string.c
types/struct.c
types/types.c
types/variant.c

index c96f38904fba89dd2dee7c8b0876d87ec9ec8d82..8f29c5a87d8c818c7dca8ffa2d6513bf45380ddd 100644 (file)
 #include <babeltrace/ctf/metadata.h>
 #include <babeltrace/ctf-text/types.h>
 
-static
-int convert_event(struct ctf_text_stream_pos *sout,
-                 struct ctf_file_stream *sin)
-{
-       struct ctf_stream *stream_class = sin->stream;
-       struct ctf_event *event_class;
-       uint64_t id = 0;
-       int len_index;
-       int ret;
-
-       if (sin->pos.offset == EOF)
-               return EOF;
-
-       /* Hide event payload struct brackets */
-       sout->depth = -1;
-
-       /* Read and print event header */
-       if (stream_class->event_header) {
-               ret = generic_rw(&sin->pos.parent, &stream_class->event_header->p);
-               if (ret)
-                       goto error;
-               /* lookup event id */
-               len_index = struct_declaration_lookup_field_index(stream_class->event_header_decl,
-                               g_quark_from_static_string("id"));
-               if (len_index >= 0) {
-                       struct definition_integer *defint;
-                       struct definition *field;
-
-                       field = struct_definition_get_field_from_index(stream_class->event_header, len_index);
-                       assert(field->declaration->id == CTF_TYPE_INTEGER);
-                       defint = container_of(field, struct definition_integer, p);
-                       assert(defint->declaration->signedness == FALSE);
-                       id = defint->value._unsigned;   /* set id */
-               }
-
-               ret = generic_rw(&sout->parent, &stream_class->event_header->p);
-               if (ret)
-                       goto error;
-       }
-
-       /* Read and print stream-declared event context */
-       if (stream_class->event_context) {
-               ret = generic_rw(&sin->pos.parent, &stream_class->event_context->p);
-               if (ret)
-                       goto error;
-               ret = generic_rw(&sout->parent, &stream_class->event_context->p);
-               if (ret)
-                       goto error;
-       }
-
-       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) {
-               ret = generic_rw(&sin->pos.parent, &event_class->context->p);
-               if (ret)
-                       goto error;
-               ret = generic_rw(&sout->parent, &event_class->context->p);
-               if (ret)
-                       goto error;
-       }
-
-       /* Read and print event payload */
-       if (event_class->fields) {
-               ret = generic_rw(&sin->pos.parent, &event_class->fields->p);
-               if (ret)
-                       goto error;
-               ret = generic_rw(&sout->parent, &event_class->fields->p);
-               if (ret)
-                       goto error;
-       }
-
-       return 0;
-
-error:
-       fprintf(stdout, "[error] Unexpected end of stream. Either the trace data stream is corrupted or metadata description does not match data layout.\n");
-       return ret;
-}
-
 static
 int convert_stream(struct ctf_text_stream_pos *sout,
                   struct ctf_file_stream *sin)
@@ -122,11 +35,16 @@ int convert_stream(struct ctf_text_stream_pos *sout,
        /* For each event, print header, context, payload */
        /* TODO: order events by timestamps across streams */
        for (;;) {
-               ret = convert_event(sout, sin);
+               ret = sin->pos.parent.event_cb(&sin->pos.parent, sin->stream);
                if (ret == EOF)
                        break;
                else if (ret) {
-                       fprintf(stdout, "[error] Printing event failed.\n");
+                       fprintf(stdout, "[error] Reading event failed.\n");
+                       goto error;
+               }
+               ret = sout->parent.event_cb(&sout->parent, sin->stream);
+               if (ret) {
+                       fprintf(stdout, "[error] Writing event failed.\n");
                        goto error;
                }
        }
index cc882f60b02d64ebbe777701c50c69755bf8007b..ceca3e4ea6c2b579bd63f44e3f992a5a3052cb9b 100644 (file)
@@ -18,6 +18,7 @@
 
 #include <babeltrace/format.h>
 #include <babeltrace/ctf-text/types.h>
+#include <babeltrace/ctf/metadata.h>
 #include <babeltrace/babeltrace.h>
 #include <inttypes.h>
 #include <uuid/uuid.h>
@@ -52,6 +53,96 @@ struct format ctf_text_format = {
        .close_trace = ctf_text_close_trace,
 };
 
+static
+int ctf_text_write_event(struct stream_pos *ppos,
+                        struct ctf_stream *stream_class)
+{
+       struct ctf_text_stream_pos *pos =
+               container_of(ppos, struct ctf_text_stream_pos, parent);
+       struct ctf_event *event_class;
+       uint64_t id = 0;
+       int len_index;
+       int ret;
+
+       /* print event header */
+       if (stream_class->event_header) {
+               /* lookup event id */
+               len_index = struct_declaration_lookup_field_index(stream_class->event_header_decl,
+                               g_quark_from_static_string("id"));
+               if (len_index >= 0) {
+                       struct definition_integer *defint;
+                       struct definition *field;
+
+                       field = struct_definition_get_field_from_index(stream_class->event_header, len_index);
+                       assert(field->declaration->id == CTF_TYPE_INTEGER);
+                       defint = container_of(field, struct definition_integer, p);
+                       assert(defint->declaration->signedness == FALSE);
+                       id = defint->value._unsigned;   /* set id */
+               }
+       }
+
+       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;
+       }
+
+       if (pos->print_names)
+               fprintf(pos->fp, "name = ");
+       fprintf(pos->fp, "%s", g_quark_to_string(event_class->name));
+
+       if (stream_class->event_header) {
+               if (pos->print_names)
+                       fprintf(pos->fp, ", stream.event.header =");
+               fprintf(pos->fp, " ");
+               ret = generic_rw(ppos, &stream_class->event_header->p);
+               if (ret)
+                       goto error;
+       }
+
+       /* print stream-declared event context */
+       if (stream_class->event_context) {
+               if (pos->print_names)
+                       fprintf(pos->fp, ", stream.event.context =");
+               fprintf(pos->fp, " ");
+               ret = generic_rw(ppos, &stream_class->event_context->p);
+               if (ret)
+                       goto error;
+       }
+
+       /* print event-declared event context */
+       if (event_class->context) {
+               if (pos->print_names)
+                       fprintf(pos->fp, ", event.context =");
+               fprintf(pos->fp, " ");
+               ret = generic_rw(ppos, &event_class->context->p);
+               if (ret)
+                       goto error;
+       }
+
+       /* Read and print event payload */
+       if (event_class->fields) {
+               if (pos->print_names)
+                       fprintf(pos->fp, ", event.fields =");
+               fprintf(pos->fp, " ");
+               ret = generic_rw(ppos, &event_class->fields->p);
+               if (ret)
+                       goto error;
+       }
+       fprintf(pos->fp, "\n");
+
+       return 0;
+
+error:
+       fprintf(stdout, "[error] Unexpected end of stream. Either the trace data stream is corrupted or metadata description does not match data layout.\n");
+       return ret;
+}
+
+
 struct trace_descriptor *ctf_text_open_trace(const char *path, int flags)
 {
        struct ctf_text_stream_pos *pos;
@@ -69,6 +160,8 @@ struct trace_descriptor *ctf_text_open_trace(const char *path, int flags)
                        goto error;
                pos->fp = fp;
                pos->parent.rw_table = write_dispatch_table;
+               pos->parent.event_cb = ctf_text_write_event;
+               pos->print_names = 1;
                break;
        case O_RDONLY:
        default:
index b7770174b4ca3340dea73554ff7b9ee05e60bc3e..f61693ab85b4245867ee80e62a8eb89955449c7a 100644 (file)
@@ -25,15 +25,22 @@ int ctf_text_array_write(struct stream_pos *ppos, struct definition *definition)
        int ret;
 
        if (!pos->dummy) {
-               print_pos_tabs(pos);
-               fprintf(pos->fp, "[\n");
+               //print_pos_tabs(pos);
+               if (definition->index != 0 && definition->index != INT_MAX)
+                       fprintf(pos->fp, ",");
+               if (definition->index != INT_MAX)
+                       fprintf(pos->fp, " ");
+               if (pos->print_names)
+                       fprintf(pos->fp, "%s = ",
+                               g_quark_to_string(definition->name));
+               fprintf(pos->fp, "[");
                pos->depth++;
        }
        ret = array_rw(ppos, definition);
        if (!pos->dummy) {
                pos->depth--;
-               print_pos_tabs(pos);
-               fprintf(pos->fp, "]\n");
+               //print_pos_tabs(pos);
+               fprintf(pos->fp, " ]");
        }
        return ret;
 }
index 33009da788a5a4dd6577649c40024e5126d14047..cf8cc4fa85d19364cf13e3d1bf3ec5f528ab5153 100644 (file)
@@ -32,11 +32,21 @@ int ctf_text_enum_write(struct stream_pos *ppos, struct definition *definition)
 
        if (pos->dummy)
                return 0;
-       print_pos_tabs(pos);
+
+       if (definition->index != 0 && definition->index != INT_MAX)
+               fprintf(pos->fp, ",");
+       if (definition->index != INT_MAX)
+               fprintf(pos->fp, " ");
+       if (pos->print_names)
+               fprintf(pos->fp, "%s = ",
+                       g_quark_to_string(definition->name));
+
+       //print_pos_tabs(pos);
        fprintf(pos->fp, "(");
        pos->depth++;
        ret = generic_rw(ppos, &integer_definition->p);
-       print_pos_tabs(pos);
+       //print_pos_tabs(pos);
+       fprintf(pos->fp, " :");
 
        qs = enum_definition->value;
        assert(qs);
@@ -44,10 +54,14 @@ int ctf_text_enum_write(struct stream_pos *ppos, struct definition *definition)
        for (i = 0; i < qs->len; i++) {
                GQuark q = g_array_index(qs, GQuark, i);
                const char *str = g_quark_to_string(q);
+
+               if (i != 0)
+                       fprintf(pos->fp, ",");
+               fprintf(pos->fp, " ");
                fprintf(pos->fp, "%s\n", str);
        }
        pos->depth--;
-       print_pos_tabs(pos);
-       fprintf(pos->fp, ")");
+       //print_pos_tabs(pos);
+       fprintf(pos->fp, " )");
        return ret;
 }
index 1f52cb078765a3c7389e1679e658b226d7024dad..d2a66d4b813b5239270f6ac17761b453a01920b2 100644 (file)
@@ -29,7 +29,16 @@ int ctf_text_float_write(struct stream_pos *ppos, struct definition *definition)
 
        if (pos->dummy)
                return 0;
-       print_pos_tabs(pos);
+       //print_pos_tabs(pos);
+
+       if (definition->index != 0 && definition->index != INT_MAX)
+               fprintf(pos->fp, ",");
+       if (definition->index != INT_MAX)
+               fprintf(pos->fp, " ");
+       if (pos->print_names)
+               fprintf(pos->fp, "%s = ",
+                       g_quark_to_string(definition->name));
+
        fprintf(pos->fp, "%Lg\n", float_definition->value);
        return 0;
 }
index 1b565a29ddf011e5f877f859b45cd112d3e3f70f..f25f4540cbc8e67348962e46a06009a657d354fd 100644 (file)
@@ -31,13 +31,33 @@ int ctf_text_integer_write(struct stream_pos *ppos, struct definition *definitio
 
        if (pos->dummy)
                return 0;
-       print_pos_tabs(pos);
+
+       if (definition->index != 0 && definition->index != INT_MAX)
+               fprintf(pos->fp, ",");
+       if (definition->index != INT_MAX)
+               fprintf(pos->fp, " ");
+       if (pos->print_names)
+               fprintf(pos->fp, "%s = ",
+                       g_quark_to_string(definition->name));
+
+       //print_pos_tabs(pos);
+
+       if (!compare_definition_path(definition, g_quark_from_static_string("stream.event.header.timestamp"))) {
+               if (!pos->print_names)
+                       fprintf(pos->fp, "[%" PRIu64 "]",
+                               integer_definition->value._unsigned);
+               else
+                       fprintf(pos->fp, "%" PRIu64,
+                               integer_definition->value._unsigned);
+               return 0;
+       }
+
        if (!integer_declaration->signedness) {
-               fprintf(pos->fp, "%" PRIu64" (0x%" PRIX64 ")\n",
+               fprintf(pos->fp, "%" PRIu64" (0x%" PRIX64 ")",
                        integer_definition->value._unsigned,
                        integer_definition->value._unsigned);
        } else {
-               fprintf(pos->fp, "%" PRId64" (0x%" PRIX64 ")\n",
+               fprintf(pos->fp, "%" PRId64" (0x%" PRIX64 ")",
                        integer_definition->value._signed,
                        integer_definition->value._signed);
        }
index 1e19885cca75b6d7d296da0df40e69ee0d7518bc..70a41dc3bb9a975d39344e59e3b83fc2d1efd83a 100644 (file)
@@ -25,15 +25,22 @@ int ctf_text_sequence_write(struct stream_pos *ppos, struct definition *definiti
        int ret;
 
        if (!pos->dummy) {
-               print_pos_tabs(pos);
-               fprintf(pos->fp, "[\n");
+               //print_pos_tabs(pos);
+               if (definition->index != 0 && definition->index != INT_MAX)
+                       fprintf(pos->fp, ",");
+               if (definition->index != INT_MAX)
+                       fprintf(pos->fp, " ");
+               if (pos->print_names)
+                       fprintf(pos->fp, "%s = ",
+                               g_quark_to_string(definition->name));
+               fprintf(pos->fp, "[");
                pos->depth++;
        }
        ret = sequence_rw(ppos, definition);
        if (!pos->dummy) {
                pos->depth--;
-               print_pos_tabs(pos);
-               fprintf(pos->fp, "]\n");
+               //print_pos_tabs(pos);
+               fprintf(pos->fp, " ]");
        }
        return ret;
 }
index d07501e5c2b510bee955ab8aa215a1636116aff7..59924dafc90d81bc6efefd24d6ef9aee94046280 100644 (file)
@@ -31,7 +31,16 @@ int ctf_text_string_write(struct stream_pos *ppos,
        assert(string_definition->value != NULL);
        if (pos->dummy)
                return 0;
-       print_pos_tabs(pos);
-       fprintf(pos->fp, "%s\n", string_definition->value);
+       //print_pos_tabs(pos);
+
+       if (definition->index != 0 && definition->index != INT_MAX)
+               fprintf(pos->fp, ",");
+       if (definition->index != INT_MAX)
+               fprintf(pos->fp, " ");
+       if (pos->print_names)
+               fprintf(pos->fp, "%s = ",
+                       g_quark_to_string(definition->name));
+
+       fprintf(pos->fp, "\"%s\"", string_definition->value);
        return 0;
 }
index 760f1727d4f37d4968b8f2456d2e9dacec2cc168..e8ffddc2bc362472ea3a4503e7e5d0fb5ef77552 100644 (file)
@@ -26,8 +26,15 @@ int ctf_text_struct_write(struct stream_pos *ppos, struct definition *definition
 
        if (!pos->dummy) {
                if (pos->depth >= 0) {
-                       print_pos_tabs(pos);
-                       fprintf(pos->fp, "{\n");
+                       //print_pos_tabs(pos);
+                       if (definition->index != 0 && definition->index != INT_MAX)
+                               fprintf(pos->fp, ",");
+                       if (definition->index != INT_MAX)
+                               fprintf(pos->fp, " ");
+                       if (pos->print_names && definition->name != 0)
+                               fprintf(pos->fp, "%s = ",
+                                       g_quark_to_string(definition->name));
+                       fprintf(pos->fp, "{");
                }
                pos->depth++;
        }
@@ -35,8 +42,8 @@ int ctf_text_struct_write(struct stream_pos *ppos, struct definition *definition
        if (!pos->dummy) {
                pos->depth--;
                if (pos->depth >= 0) {
-                       print_pos_tabs(pos);
-                       fprintf(pos->fp, "}\n");
+                       //print_pos_tabs(pos);
+                       fprintf(pos->fp, " }");
                }
        }
        return ret;
index b4b72e16afeadb33420ec4998416dd8512402a34..e6abd499db9dcc0503468c60dc38f7dfd9a6d284 100644 (file)
 #include <babeltrace/ctf-text/types.h>
 #include <stdio.h>
 
-int ctf_text_variant_write(struct stream_pos *pos, struct definition *definition)
+int ctf_text_variant_write(struct stream_pos *ppos, struct definition *definition)
 {
-       return variant_rw(pos, definition);
+       struct ctf_text_stream_pos *pos = ctf_text_pos(ppos);
+       int ret;
+
+       if (!pos->dummy) {
+               if (pos->depth >= 0) {
+                       //print_pos_tabs(pos);
+                       if (definition->index != 0 && definition->index != INT_MAX)
+                               fprintf(pos->fp, ",");
+                       if (definition->index != INT_MAX)
+                               fprintf(pos->fp, " ");
+                       if (pos->print_names)
+                               fprintf(pos->fp, "%s = ",
+                                       g_quark_to_string(definition->name));
+                       fprintf(pos->fp, "{");
+               }
+               pos->depth++;
+       }
+       ret = variant_rw(ppos, definition);
+       if (!pos->dummy) {
+               pos->depth--;
+               if (pos->depth >= 0) {
+                       //print_pos_tabs(pos);
+                       fprintf(pos->fp, " }");
+               }
+       }
+       return ret;
 }
index 1e7fedd8d3319cae443e838c45a9e2f0e74a302e..50cc93de1d866b83a3302767871707ff3c4e5799 100644 (file)
@@ -79,6 +79,144 @@ struct format ctf_format = {
        .close_trace = ctf_close_trace,
 };
 
+static
+int ctf_read_event(struct stream_pos *ppos, struct ctf_stream *stream_class)
+{
+       struct ctf_stream_pos *pos =
+               container_of(ppos, struct ctf_stream_pos, parent);
+       struct ctf_event *event_class;
+       uint64_t id = 0;
+       int len_index;
+       int ret;
+
+       if (pos->offset == EOF)
+               return EOF;
+
+       /* Read event header */
+       if (stream_class->event_header) {
+               ret = generic_rw(ppos, &stream_class->event_header->p);
+               if (ret)
+                       goto error;
+               /* lookup event id */
+               len_index = struct_declaration_lookup_field_index(stream_class->event_header_decl,
+                               g_quark_from_static_string("id"));
+               if (len_index >= 0) {
+                       struct definition_integer *defint;
+                       struct definition *field;
+
+                       field = struct_definition_get_field_from_index(stream_class->event_header, len_index);
+                       assert(field->declaration->id == CTF_TYPE_INTEGER);
+                       defint = container_of(field, struct definition_integer, p);
+                       assert(defint->declaration->signedness == FALSE);
+                       id = defint->value._unsigned;   /* set id */
+               }
+       }
+
+       /* Read stream-declared event context */
+       if (stream_class->event_context) {
+               ret = generic_rw(ppos, &stream_class->event_context->p);
+               if (ret)
+                       goto error;
+       }
+
+       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 event-declared event context */
+       if (event_class->context) {
+               ret = generic_rw(ppos, &event_class->context->p);
+               if (ret)
+                       goto error;
+       }
+
+       /* Read event payload */
+       if (event_class->fields) {
+               ret = generic_rw(ppos, &event_class->fields->p);
+               if (ret)
+                       goto error;
+       }
+
+       return 0;
+
+error:
+       fprintf(stdout, "[error] Unexpected end of stream. Either the trace data stream is corrupted or metadata description does not match data layout.\n");
+       return ret;
+}
+
+static
+int ctf_write_event(struct stream_pos *pos, struct ctf_stream *stream_class)
+{
+       struct ctf_event *event_class;
+       uint64_t id = 0;
+       int len_index;
+       int ret;
+
+       /* print event header */
+       if (stream_class->event_header) {
+               /* lookup event id */
+               len_index = struct_declaration_lookup_field_index(stream_class->event_header_decl,
+                               g_quark_from_static_string("id"));
+               if (len_index >= 0) {
+                       struct definition_integer *defint;
+                       struct definition *field;
+
+                       field = struct_definition_get_field_from_index(stream_class->event_header, len_index);
+                       assert(field->declaration->id == CTF_TYPE_INTEGER);
+                       defint = container_of(field, struct definition_integer, p);
+                       assert(defint->declaration->signedness == FALSE);
+                       id = defint->value._unsigned;   /* set id */
+               }
+
+               ret = generic_rw(pos, &stream_class->event_header->p);
+               if (ret)
+                       goto error;
+       }
+
+       /* print stream-declared event context */
+       if (stream_class->event_context) {
+               ret = generic_rw(pos, &stream_class->event_context->p);
+               if (ret)
+                       goto error;
+       }
+
+       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;
+       }
+
+       /* print event-declared event context */
+       if (event_class->context) {
+               ret = generic_rw(pos, &event_class->context->p);
+               if (ret)
+                       goto error;
+       }
+
+       /* Read and print event payload */
+       if (event_class->fields) {
+               ret = generic_rw(pos, &event_class->fields->p);
+               if (ret)
+                       goto error;
+       }
+
+       return 0;
+
+error:
+       fprintf(stdout, "[error] Unexpected end of stream. Either the trace data stream is corrupted or metadata description does not match data layout.\n");
+       return ret;
+}
+
 void ctf_init_pos(struct ctf_stream_pos *pos, int fd, int open_flags)
 {
        pos->fd = fd;
@@ -100,11 +238,13 @@ void ctf_init_pos(struct ctf_stream_pos *pos, int fd, int open_flags)
                pos->prot = PROT_READ;
                pos->flags = MAP_PRIVATE;
                pos->parent.rw_table = read_dispatch_table;
+               pos->parent.event_cb = ctf_read_event;
                break;
        case O_RDWR:
                pos->prot = PROT_WRITE; /* Write has priority */
                pos->flags = MAP_SHARED;
                pos->parent.rw_table = write_dispatch_table;
+               pos->parent.event_cb = ctf_write_event;
                if (fd >= 0)
                        ctf_move_pos_slow(pos, 0, SEEK_SET);    /* position for write */
                break;
index 9e65435ef38ebd2f4ee104a2144898caf643939d..bb837bcd5e671bbd5c4d30164cd5d22dd53fce41 100644 (file)
@@ -37,6 +37,7 @@ struct ctf_text_stream_pos {
        FILE *fp;               /* File pointer. NULL if unset. */
        int depth;
        int dummy;              /* disable output */
+       int print_names;        /* print field names */
 };
 
 static inline
index 059c371dea37cd2323b74a1d29d256ef338997d0..6bfd703d4bad08eb8dcac12671175a44752cd184 100644 (file)
@@ -31,6 +31,7 @@
 /* Preallocate this many fields for structures */
 #define DEFAULT_NR_STRUCT_FIELDS 8
 
+struct ctf_stream;
 struct stream_pos;
 struct format;
 struct definition;
@@ -102,6 +103,7 @@ struct definition {
        int index;              /* Position of the definition in its container */
        GQuark name;            /* Field name in its container (or 0 if unset) */
        int ref;                /* number of references to the definition */
+       GQuark path;
 };
 
 typedef int (*rw_dispatch)(struct stream_pos *pos,
@@ -111,6 +113,8 @@ typedef int (*rw_dispatch)(struct stream_pos *pos,
 struct stream_pos {
        /* read/write dispatch table. Specific to plugin used for stream. */
        rw_dispatch *rw_table;  /* rw dispatch table */
+       int (*event_cb)(struct stream_pos *pos,
+                       struct ctf_stream *stream_class);
 };
 
 static inline
@@ -359,6 +363,14 @@ void set_dynamic_definition_scope(struct definition *definition,
                                  const char *root_name);
 void free_definition_scope(struct definition_scope *scope);
 
+GQuark new_definition_path(struct definition_scope *parent_scope, GQuark field_name);
+
+static inline
+int compare_definition_path(struct definition *definition, GQuark path)
+{
+       return definition->path == path;
+}
+
 void declaration_ref(struct declaration *declaration);
 void declaration_unref(struct declaration *declaration);
 
@@ -493,4 +505,4 @@ int sequence_rw(struct stream_pos *pos, struct definition *definition);
  */
 void append_scope_path(const char *path, GArray *q);
 
-#endif /* _BABELTRACE_declarationS_H */
+#endif /* _BABELTRACE_TYPES_H */
index 92b8dd065d527818eead5833a74ddcdaaab29808..0bb141ce33e14cf3ba2ca12858e734535f3856a4 100644 (file)
@@ -100,6 +100,7 @@ struct definition *
        array->p.ref = 1;
        array->p.index = index;
        array->p.name = field_name;
+       array->p.path = new_definition_path(parent_scope, field_name);
        array->scope = new_definition_scope(parent_scope, field_name);
        array->elems = g_ptr_array_sized_new(array_declaration->len);
        g_ptr_array_set_size(array->elems, array_declaration->len);
index 82a02dfe26e189096c4bf36343ea0357070b942c..068651c74eecb780acec420939888a10f3f4f049 100644 (file)
@@ -410,6 +410,7 @@ struct definition *
        _enum->p.ref = 1;
        _enum->p.index = index;
        _enum->p.name = field_name;
+       _enum->p.path = new_definition_path(parent_scope, field_name);
        _enum->value = NULL;
        definition_integer_parent =
                enum_declaration->integer_declaration->p.definition_new(&enum_declaration->integer_declaration->p,
index 7ae4df6e4f39ae77ef58e93080851fe422f8f686..5ce6bb43628cfa907c32228be83c03696de8d30a 100644 (file)
@@ -104,6 +104,7 @@ struct definition *
        _float->p.ref = 1;
        _float->p.index = index;
        _float->p.name = field_name;
+       _float->p.path = new_definition_path(parent_scope, field_name);
        _float->value = 0.0;
        return &_float->p;
 }
index c43f55e64c68bd623c0b1c214c1d269f85e20ec4..5aa9c44f2440ae93118cc66cd1e1a4143e8c9265 100644 (file)
@@ -72,6 +72,7 @@ struct definition *
        integer->p.ref = 1;
        integer->p.index = index;
        integer->p.name = field_name;
+       integer->p.path = new_definition_path(parent_scope, field_name);
        integer->value._unsigned = 0;
        return &integer->p;
 }
index 5fcf77aa7e9c1e93b656b0fc996fac10e30ec296..f4262cdb99b595a8119dccd2c59bab379c1d57dd 100644 (file)
@@ -131,6 +131,7 @@ struct definition *_sequence_definition_new(struct declaration *declaration,
        sequence->p.ref = 1;
        sequence->p.index = index;
        sequence->p.name = field_name;
+       sequence->p.path = new_definition_path(parent_scope, field_name);
        sequence->scope = new_definition_scope(parent_scope, field_name);
        len_parent = sequence_declaration->len_declaration->p.definition_new(&sequence_declaration->len_declaration->p,
                                sequence->scope,
index f940155399d9a4df2497489d0dc017c4eebd3096..0f261f418b1bd2a766dcba83bd2bd0e8d8ce1f4a 100644 (file)
@@ -68,6 +68,7 @@ struct definition *
        string->p.ref = 1;
        string->p.index = index;
        string->p.name = field_name;
+       string->p.path = new_definition_path(parent_scope, field_name);
        string->value = NULL;
        string->len = 0;
        string->alloc_len = 0;
index 1a2b59d51e26e9cbb319f313aac798dba2bd0d51..6012447bc2a678194aa4ba5dc8a278ea3e58073e 100644 (file)
@@ -109,6 +109,7 @@ struct definition *
        _struct->p.ref = 1;
        _struct->p.index = index;
        _struct->p.name = field_name;
+       _struct->p.path = new_definition_path(parent_scope, field_name);
        _struct->scope = new_definition_scope(parent_scope, field_name);
        _struct->fields = g_ptr_array_sized_new(DEFAULT_NR_STRUCT_FIELDS);
        g_ptr_array_set_size(_struct->fields, struct_declaration->fields->len);
index 1766c61b1cd5e953c761720b901a2ad24292d98e..7369f30d09ffb5a272c3d54f14e5466ac3b005b2 100644 (file)
@@ -469,6 +469,30 @@ static struct definition_scope *
        return scope;
 }
 
+GQuark new_definition_path(struct definition_scope *parent_scope, GQuark field_name)
+{
+       GQuark path;
+       GString *str;
+       gchar *c_str;
+       int i;
+
+       str = g_string_new("");
+       if (parent_scope) {
+               for (i = 0; i < parent_scope->scope_path->len; i++) {
+                       GQuark q = g_array_index(parent_scope->scope_path,
+                                                GQuark, i);
+
+                       g_string_append(str, g_quark_to_string(q));
+                       g_string_append(str, ".");
+               }
+       }
+       g_string_append(str, g_quark_to_string(field_name));
+       c_str = g_string_free(str, FALSE);
+       path = g_quark_from_string(c_str);
+       g_free(c_str);
+       return path;
+}
+
 struct definition_scope *
        new_definition_scope(struct definition_scope *parent_scope,
                             GQuark field_name)
index 479b4ba4079e8ab80f4535677ae9a7aafedfe79f..8a781f67c0df03af2a114b7fdddbd2d5b6ae509f 100644 (file)
@@ -175,6 +175,7 @@ struct definition *
        variant->p.ref = 1;
        variant->p.index = index;
        variant->p.name = field_name;
+       variant->p.path = new_definition_path(parent_scope, field_name);
        variant->scope = new_definition_scope(parent_scope, field_name);
        variant->enum_tag = lookup_definition(variant->scope->scope_path,
                                              variant_declaration->tag_name,
This page took 0.039015 seconds and 4 git commands to generate.