move struct ctf_stream -> struct ctf_stream_class
[babeltrace.git] / include / babeltrace / types.h
index 9704efed5e08229bc82243b30e715b1e2316e86e..fa543bf2ddaed57323aea6d4331ce2ce7586e477 100644 (file)
 /* Preallocate this many fields for structures */
 #define DEFAULT_NR_STRUCT_FIELDS 8
 
-/*
- * Always update stream_pos with move_pos and init_pos.
- */
-struct stream_pos {
-       char *base;             /* Base address */
-       size_t offset;          /* Offset from base, in bits */
-       int dummy;              /* Dummy position, for length calculation */
-};
-
-static inline
-void init_pos(struct stream_pos *pos, char *base)
-{
-       pos->base = base;       /* initial base, page-aligned */
-       pos->offset = 0;
-       pos->dummy = false;
-}
-
-/*
- * move_pos - move position of a relative bit offset
- *
- * TODO: allow larger files by updating base too.
- */
-static inline
-void move_pos(struct stream_pos *pos, size_t offset)
-{
-       pos->offset = pos->offset + offset;
-}
-
-/*
- * align_pos - align position on a bit offset (> 0)
- *
- * TODO: allow larger files by updating base too.
- */
-static inline
-void align_pos(struct stream_pos *pos, size_t offset)
-{
-       pos->offset += offset_align(pos->offset, offset);
-}
-
-static inline
-void copy_pos(struct stream_pos *dest, struct stream_pos *src)
-{
-       memcpy(dest, src, sizeof(struct stream_pos));
-}
-
-static inline
-char *get_pos_addr(struct stream_pos *pos)
-{
-       /* Only makes sense to get the address after aligning on CHAR_BIT */
-       assert(!(pos->offset % CHAR_BIT));
-       return pos->base + (pos->offset / CHAR_BIT);
-}
-
+struct ctf_stream_class;
+struct stream_pos;
 struct format;
 struct definition;
 
@@ -147,21 +96,38 @@ struct declaration {
         * definition_free called with definition ref is decremented to 0.
         */
        void (*definition_free)(struct definition *definition);
-       /*
-        * Definition copy function. Knows how to find the child
-        * definition from the parent definition.
-        */
-       void (*copy)(struct stream_pos *dest, const struct format *fdest, 
-                    struct stream_pos *src, const struct format *fsrc,
-                    struct definition *definition);
 };
 
 struct definition {
        struct declaration *declaration;
        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,
+                          struct definition *definition);
+
+/* Parent of per-plugin positions */
+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_class *stream_class);
+};
+
+static inline
+int generic_rw(struct stream_pos *pos, struct definition *definition)
+{
+       enum ctf_type_id dispatch_id = definition->declaration->id;
+       rw_dispatch call;
+
+       assert(pos->rw_table[dispatch_id] != NULL);
+       call = pos->rw_table[dispatch_id];
+       return call(pos, definition);
+}
+
 /*
  * Because we address in bits, bitfields end up being exactly the same as
  * integers, except that their read/write functions must be able to deal with
@@ -196,6 +162,9 @@ struct declaration_float {
 struct definition_float {
        struct definition p;
        struct declaration_float *declaration;
+       struct definition_integer *sign;
+       struct definition_integer *mantissa;
+       struct definition_integer *exp;
        /* Last values read */
        long double value;
 };
@@ -267,6 +236,7 @@ struct definition_string {
        struct definition p;
        struct declaration_string *declaration;
        char *value;    /* freed at definition_string teardown */
+       size_t len, alloc_len;
 };
 
 struct declaration_field {
@@ -274,11 +244,6 @@ struct declaration_field {
        struct declaration *declaration;
 };
 
-struct field {
-       GQuark name;
-       struct definition *definition;
-};
-
 struct declaration_struct {
        struct declaration p;
        GHashTable *fields_by_name;     /* Tuples (field name, field index) */
@@ -290,7 +255,7 @@ struct definition_struct {
        struct definition p;
        struct declaration_struct *declaration;
        struct definition_scope *scope;
-       GArray *fields;                 /* Array of struct field */
+       GPtrArray *fields;              /* Array of pointers to struct definition */
 };
 
 struct declaration_untagged_variant {
@@ -312,8 +277,8 @@ struct definition_variant {
        struct declaration_variant *declaration;
        struct definition_scope *scope;
        struct definition *enum_tag;
-       GArray *fields;                 /* Array of struct field */
-       struct field *current_field;    /* Last field read */
+       GPtrArray *fields;              /* Array of pointers to struct definition */
+       struct definition *current_field;       /* Last field read */
 };
 
 struct declaration_array {
@@ -327,7 +292,7 @@ struct definition_array {
        struct definition p;
        struct declaration_array *declaration;
        struct definition_scope *scope;
-       struct field current_element;           /* struct field */
+       GPtrArray *elems;               /* Array of pointers to struct definition */
 };
 
 struct declaration_sequence {
@@ -342,7 +307,7 @@ struct definition_sequence {
        struct declaration_sequence *declaration;
        struct definition_scope *scope;
        struct definition_integer *len;
-       struct field current_element;           /* struct field */
+       GPtrArray *elems;               /* Array of pointers to struct definition */
 };
 
 int register_declaration(GQuark declaration_name,
@@ -398,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);
 
@@ -461,17 +434,18 @@ void struct_declaration_add_field(struct declaration_struct *struct_declaration,
 /*
  * Returns the index of a field within a structure.
  */
-unsigned long struct_declaration_lookup_field_index(struct declaration_struct *struct_declaration,
+int struct_declaration_lookup_field_index(struct declaration_struct *struct_declaration,
                                                    GQuark field_name);
 /*
  * field returned only valid as long as the field structure is not appended to.
  */
 struct declaration_field *
 struct_declaration_get_field_from_index(struct declaration_struct *struct_declaration,
-                                       unsigned long index);
-struct field *
-struct_get_field_from_index(struct definition_struct *struct_definition,
-                           unsigned long index);
+                                       int index);
+struct definition *
+struct_definition_get_field_from_index(struct definition_struct *struct_definition,
+                                      int index);
+int struct_rw(struct stream_pos *pos, struct definition *definition);
 
 /*
  * The tag enumeration is validated to ensure that it contains only mappings
@@ -499,7 +473,8 @@ int variant_definition_set_tag(struct definition_variant *variant,
  * field returned only valid as long as the variant structure is not appended
  * to.
  */
-struct field *variant_get_current_field(struct definition_variant *variant);
+struct definition *variant_get_current_field(struct definition_variant *variant);
+int variant_rw(struct stream_pos *pos, struct definition *definition);
 
 /*
  * elem_declaration passed as parameter now belongs to the array. No
@@ -509,6 +484,9 @@ struct field *variant_get_current_field(struct definition_variant *variant);
 struct declaration_array *
        array_declaration_new(size_t len, struct declaration *elem_declaration,
                struct declaration_scope *parent_scope);
+uint64_t array_len(struct definition_array *array);
+struct definition *array_index(struct definition_array *array, uint64_t i);
+int array_rw(struct stream_pos *pos, struct definition *definition);
 
 /*
  * int_declaration and elem_declaration passed as parameter now belong
@@ -518,10 +496,13 @@ struct declaration_sequence *
        sequence_declaration_new(struct declaration_integer *len_declaration, 
                struct declaration *elem_declaration,
                struct declaration_scope *parent_scope);
+uint64_t sequence_len(struct definition_sequence *sequence);
+struct definition *sequence_index(struct definition_sequence *sequence, uint64_t i);
+int sequence_rw(struct stream_pos *pos, struct definition *definition);
 
 /*
  * in: path (dot separated), out: q (GArray of GQuark)
  */
 void append_scope_path(const char *path, GArray *q);
 
-#endif /* _BABELTRACE_declarationS_H */
+#endif /* _BABELTRACE_TYPES_H */
This page took 0.025515 seconds and 4 git commands to generate.