Specify callback to move packet in open_trace
authorJulien Desfossez <julien.desfossez@polymtl.ca>
Tue, 13 Sep 2011 21:56:56 +0000 (17:56 -0400)
committerMathieu Desnoyers <mathieu.desnoyers@efficios.com>
Tue, 13 Sep 2011 21:56:56 +0000 (17:56 -0400)
This patch adds a new parameter to open_trace to allow the user to
specify the function to call when babeltrace needs to switch packet.
This patch is a first step for the mmap reading code integration.

Signed-off-by: Julien Desfossez <julien.desfossez@polymtl.ca>
Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
converter/babeltrace.c
formats/bt-dummy/bt-dummy.c
formats/ctf-text/ctf-text.c
formats/ctf/ctf.c
include/babeltrace/ctf/types.h
include/babeltrace/format.h

index 5c3724252936392b0ae110c2691a71bb2b37d8b5..a39c1c452e0222c10db118ad19ffb3b4695d933c 100644 (file)
@@ -212,7 +212,7 @@ static int traverse_dir(const char *fpath, const struct stat *sb,
        } else {
                close(fd);
                close(dirfd);
-               td_read = fmt_read->open_trace(fpath, O_RDONLY);
+               td_read = fmt_read->open_trace(fpath, O_RDONLY, ctf_move_pos_slow);
                if (!td_read) {
                        fprintf(stdout, "Error opening trace \"%s\" "
                                        "for reading.\n\n", fpath);
@@ -290,7 +290,7 @@ int main(int argc, char **argv)
                return 0;
        }
 
-       td_write = fmt_write->open_trace(opt_output_path, O_RDWR);
+       td_write = fmt_write->open_trace(opt_output_path, O_RDWR, NULL);
        if (!td_write) {
                fprintf(stdout, "Error opening trace \"%s\" for writing.\n\n",
                        opt_output_path ? : "<none>");
index 41cfb741202eb0d765a181a0a095dba696c9e907..0850abba8433986cbd1c6632ec6c63a006c02dcd 100644 (file)
@@ -39,7 +39,9 @@ int bt_dummy_write_event(struct stream_pos *ppos,
 }
 
 static
-struct trace_descriptor *bt_dummy_open_trace(const char *path, int flags)
+struct trace_descriptor *bt_dummy_open_trace(const char *path, int flags,
+               void (*move_pos_slow)(struct ctf_stream_pos *pos, size_t offset,
+                       int whence))
 {
        struct ctf_text_stream_pos *pos;
 
index f1ddbaf5e77b18f2f3855d9f7f2d23a708efe949..fa46a9262a184293aa396c37f3b094aef565e95d 100644 (file)
@@ -34,7 +34,9 @@
 #include <unistd.h>
 #include <stdlib.h>
 
-struct trace_descriptor *ctf_text_open_trace(const char *path, int flags);
+struct trace_descriptor *ctf_text_open_trace(const char *path, int flags,
+               void (*move_pos_slow)(struct ctf_stream_pos *pos, size_t offset,
+                       int whence));
 void ctf_text_close_trace(struct trace_descriptor *descriptor);
 
 static
@@ -225,7 +227,9 @@ error:
 }
 
 
-struct trace_descriptor *ctf_text_open_trace(const char *path, int flags)
+struct trace_descriptor *ctf_text_open_trace(const char *path, int flags,
+               void (*move_pos_slow)(struct ctf_stream_pos *pos, size_t offset,
+                       int whence))
 {
        struct ctf_text_stream_pos *pos;
        FILE *fp;
index 0d1418c1b33cf7bc471c6a692e69309cd7729bff..93d13e8a5bc5bfcbfefe75529181fe5d41ab8fc0 100644 (file)
@@ -55,7 +55,9 @@
 extern int yydebug;
 
 static
-struct trace_descriptor *ctf_open_trace(const char *path, int flags);
+struct trace_descriptor *ctf_open_trace(const char *path, int flags,
+               void (*move_pos_slow)(struct ctf_stream_pos *pos, size_t offset,
+                       int whence));
 static
 void ctf_close_trace(struct trace_descriptor *descriptor);
 
@@ -609,7 +611,9 @@ int ctf_open_trace_metadata_stream_read(struct ctf_trace *td, FILE **fp,
 }
 
 static
-int ctf_open_trace_metadata_read(struct ctf_trace *td)
+int ctf_open_trace_metadata_read(struct ctf_trace *td,
+               void (*move_pos_slow)(struct ctf_stream_pos *pos, size_t offset,
+                       int whence))
 {
        struct ctf_scanner *scanner;
        struct ctf_file_stream *metadata_stream;
@@ -618,6 +622,15 @@ int ctf_open_trace_metadata_read(struct ctf_trace *td)
        int ret = 0;
 
        metadata_stream = g_new0(struct ctf_file_stream, 1);
+
+       if (move_pos_slow) {
+               metadata_stream->pos.move_pos_slow = move_pos_slow;
+       } else {
+               fprintf(stderr, "[error] move_pos_slow function undefined.\n");
+               ret = -1;
+               goto end_stream;
+       }
+
        td->metadata = &metadata_stream->parent;
        metadata_stream->pos.fd = openat(td->dirfd, "metadata", O_RDONLY);
        if (metadata_stream->pos.fd < 0) {
@@ -1083,7 +1096,9 @@ error:
  * description (metadata).
  */
 static
-int ctf_open_file_stream_read(struct ctf_trace *td, const char *path, int flags)
+int ctf_open_file_stream_read(struct ctf_trace *td, const char *path, int flags,
+               void (*move_pos_slow)(struct ctf_stream_pos *pos, size_t offset,
+                       int whence))
 {
        int ret;
        struct ctf_file_stream *file_stream;
@@ -1092,6 +1107,15 @@ int ctf_open_file_stream_read(struct ctf_trace *td, const char *path, int flags)
        if (ret < 0)
                goto error;
        file_stream = g_new0(struct ctf_file_stream, 1);
+
+       if (move_pos_slow) {
+               file_stream->pos.move_pos_slow = move_pos_slow;
+       } else {
+               fprintf(stderr, "[error] move_pos_slow function undefined.\n");
+               ret = -1;
+               goto error_def;
+       }
+
        ctf_init_pos(&file_stream->pos, ret, flags);
        ret = create_trace_definitions(td, &file_stream->parent);
        if (ret)
@@ -1116,7 +1140,9 @@ error:
 }
 
 static
-int ctf_open_trace_read(struct ctf_trace *td, const char *path, int flags)
+int ctf_open_trace_read(struct ctf_trace *td, const char *path, int flags,
+               void (*move_pos_slow)(struct ctf_stream_pos *pos, size_t offset,
+                       int whence))
 {
        int ret;
        struct dirent *dirent;
@@ -1144,7 +1170,7 @@ int ctf_open_trace_read(struct ctf_trace *td, const char *path, int flags)
         * Keep the metadata file separate.
         */
 
-       ret = ctf_open_trace_metadata_read(td);
+       ret = ctf_open_trace_metadata_read(td, move_pos_slow);
        if (ret) {
                goto error_metadata;
        }
@@ -1173,7 +1199,7 @@ int ctf_open_trace_read(struct ctf_trace *td, const char *path, int flags)
                                || !strcmp(diriter->d_name, "..")
                                || !strcmp(diriter->d_name, "metadata"))
                        continue;
-               ret = ctf_open_file_stream_read(td, diriter->d_name, flags);
+               ret = ctf_open_file_stream_read(td, diriter->d_name, flags, move_pos_slow);
                if (ret) {
                        fprintf(stdout, "[error] Open file stream error.\n");
                        goto readdir_error;
@@ -1194,7 +1220,9 @@ error:
 }
 
 static
-struct trace_descriptor *ctf_open_trace(const char *path, int flags)
+struct trace_descriptor *ctf_open_trace(const char *path, int flags,
+               void (*move_pos_slow)(struct ctf_stream_pos *pos, size_t offset,
+                       int whence))
 {
        struct ctf_trace *td;
        int ret;
@@ -1207,7 +1235,7 @@ struct trace_descriptor *ctf_open_trace(const char *path, int flags)
                        fprintf(stdout, "[error] Path missing for input CTF trace.\n");
                        goto error;
                }
-               ret = ctf_open_trace_read(td, path, flags);
+               ret = ctf_open_trace_read(td, path, flags, move_pos_slow);
                if (ret)
                        goto error;
                break;
index 54fd84622f138f583b3eca5d14d73a28b8423778..60749a6c9f8ec8b368413b19c47f84288025a270 100644 (file)
@@ -60,6 +60,8 @@ struct ctf_stream_pos {
        char *base;             /* mmap base address */
        ssize_t offset;         /* offset from base, in bits. EOF for end of file. */
        size_t cur_index;       /* current index in packet index */
+       void (*move_pos_slow)(struct ctf_stream_pos *pos, size_t offset,
+                       int whence); /* function called to switch packet */
 
        int dummy;              /* dummy position, for length calculation */
        struct bt_stream_callbacks *cb; /* Callbacks registered for iterator. */
index c50b28dc330b8c81c23aefb4133829974b2f7cce..1b45b4ba8dfe6c9c73c2cd1e260b5e80ded03916 100644 (file)
@@ -22,6 +22,7 @@
  */
 
 #include <babeltrace/types.h>
+#include <babeltrace/ctf/types.h>
 #include <stdint.h>
 #include <stdio.h>
 #include <glib.h>
@@ -33,7 +34,9 @@ struct trace_descriptor {
 struct format {
        GQuark name;
 
-       struct trace_descriptor *(*open_trace)(const char *path, int flags);
+       struct trace_descriptor *(*open_trace)(const char *path, int flags,
+                       void (*move_pos_slow)(struct ctf_stream_pos *pos, size_t offset,
+                               int whence));
        void (*close_trace)(struct trace_descriptor *descriptor);
 };
 
This page took 0.030673 seconds and 4 git commands to generate.