Add sequence
authorMathieu Desnoyers <mathieu.desnoyers@efficios.com>
Tue, 5 Oct 2010 03:18:02 +0000 (23:18 -0400)
committerMathieu Desnoyers <mathieu.desnoyers@efficios.com>
Tue, 5 Oct 2010 03:18:02 +0000 (23:18 -0400)
Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
include/babeltrace/types.h
types/array.c
types/sequence.c [new file with mode: 0644]

index cc1965a0aa6fec46e2e74ae93c5f25926b46c67d..7da11af24bab4c8e02b9c56f1322afaa45768f0c 100644 (file)
@@ -150,7 +150,7 @@ struct type_class_array {
 
 struct type_class_sequence {
        struct type_class p;
-       struct type_class_integer *len;
+       struct type_class_integer *len_class;
        struct type_class *elem;
 };
 
@@ -228,7 +228,7 @@ void array_type_free(struct type_class_array *array_class);
  * need to free them explicitely.
  */
 struct type_class_sequence *sequence_type_new(const char *name,
-                                       struct type_class_integer *int_class, 
+                                       struct type_class_integer *len_class, 
                                        struct type_class *elem_class);
 void sequence_type_free(struct type_class_sequence *sequence_class);
 
index 153a38e62e43e8c11a583a268c6285b0f5f9af8a..ebd3c9a60ab67fcaeac2ed6991fe14aab3badd5b 100644 (file)
@@ -77,6 +77,7 @@ struct type_class_array *array_type_new(const char *name, size_t len,
        return array_class;
 
 error_register:
+       array_class->elem->free(&array_class->elem->p);
        g_free(array_class);
        return NULL;
 }
diff --git a/types/sequence.c b/types/sequence.c
new file mode 100644 (file)
index 0000000..39a0470
--- /dev/null
@@ -0,0 +1,91 @@
+/*
+ * BabelTrace - Sequence Type Converter
+ *
+ * Copyright (c) 2010 Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#include <babeltrace/compiler.h>
+#include <babeltrace/types.h>
+
+void sequence_copy(struct stream_pos *dest, const struct format *fdest, 
+                  struct stream_pos *src, const struct format *fsrc,
+                  const struct type_class *type_class)
+{
+       struct type_class_sequence *sequence_class =
+               container_of(type_class, struct type_class_sequence, p);
+       unsigned int i;
+       size_t len;
+
+       fsrc->sequence_begin(src, sequence_class);
+       fdest->sequence_begin(dest, sequence_class);
+
+       len = fsrc->uint_read(src, sequence_class->len_class);
+       fdest->uint_write(dest, sequence_class->len_class, len);
+
+       for (i = 0; i < len; i++) {
+               struct type_class *elem_class = sequence_class->elem;
+               elem_class->copy(dest, fdest, src, fsrc, &elem_class->p);
+       }
+       fsrc->sequence_end(src, sequence_class);
+       fdest->sequence_end(dest, sequence_class);
+}
+
+void sequence_type_free(struct type_class_sequence *sequence_class)
+{
+       sequence_class->elem->free(&sequence_class->elem->p);
+       g_free(sequence_class);
+}
+
+static void _sequence_type_free(struct type_class *type_class)
+{
+       struct type_class_struct *sequence_class =
+               container_of(type_class, struct type_class_sequence, p);
+       sequence_type_free(sequence_class);
+}
+
+struct type_class_sequence *
+sequence_type_new(const char *name, struct type_class_integer *len_class,
+                 struct type_class *elem)
+{
+       struct type_class_sequence *sequence_class;
+       int ret;
+
+       sequence_class = g_new(struct type_class_sequence, 1);
+       type_class = &float_class->p;
+
+       assert(!len_class->signedness);
+
+       sequence_class->len = len;
+       type_class->name = g_quark_from_string(name);
+       type_class->alignment = max(len_class->p.alignment,
+                                   elem->p.alignment);
+       type_class->copy = sequence_copy;
+       type_class->free = _sequence_type_free;
+
+       if (type_class->name) {
+               ret = ctf_register_type(type_class);
+               if (ret)
+                       goto error_register;
+       }
+       return sequence_class;
+
+error_register:
+       len_class->p.free(&len_class->p);
+       sequence_class->elem->free(&sequence_class->elem->p);
+       g_free(sequence_class);
+       return NULL;
+}
This page took 0.036974 seconds and 4 git commands to generate.