Helper function to extract string from fields
[babeltrace.git] / include / babeltrace / types.h
index 33311a683dae1056ff48928b4f4f0e3f83a788a4..f3a0e831b15fcdfb9a85f76dc79a0c569222ca8a 100644 (file)
@@ -6,7 +6,9 @@
  *
  * Type Header
  *
- * Copyright 2010, 2011 - Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
+ * Copyright 2010-2011 EfficiOS Inc. and Linux Foundation
+ *
+ * Author: 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
@@ -91,7 +93,8 @@ struct declaration {
        struct definition *
                (*definition_new)(struct declaration *declaration,
                                  struct definition_scope *parent_scope,
-                                 GQuark field_name, int index);
+                                 GQuark field_name, int index,
+                                 const char *root_name);
        /*
         * definition_free called with definition ref is decremented to 0.
         */
@@ -104,6 +107,7 @@ struct definition {
        GQuark name;            /* Field name in its container (or 0 if unset) */
        int ref;                /* number of references to the definition */
        GQuark path;
+       struct definition_scope *scope;
 };
 
 typedef int (*rw_dispatch)(struct stream_pos *pos,
@@ -128,6 +132,13 @@ int generic_rw(struct stream_pos *pos, struct definition *definition)
        return call(pos, definition);
 }
 
+enum ctf_string_encoding {
+       CTF_STRING_NONE = 0,
+       CTF_STRING_UTF8,
+       CTF_STRING_ASCII,
+       CTF_STRING_UNKNOWN,
+};
+
 /*
  * 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
@@ -139,6 +150,7 @@ struct declaration_integer {
        int byte_order;         /* byte order */
        int signedness;
        int base;               /* Base for pretty-printing: 2, 8, 10, 16 */
+       enum ctf_string_encoding encoding;
 };
 
 struct definition_integer {
@@ -167,7 +179,7 @@ struct definition_float {
        struct definition_integer *mantissa;
        struct definition_integer *exp;
        /* Last values read */
-       long double value;
+       double value;
 };
 
 /*
@@ -222,12 +234,6 @@ struct definition_enum {
        GArray *value;
 };
 
-enum ctf_string_encoding {
-       CTF_STRING_UTF8 = 0,
-       CTF_STRING_ASCII,
-       CTF_STRING_UNKNOWN,
-};
-
 struct declaration_string {
        struct declaration p;
        enum ctf_string_encoding encoding;
@@ -255,7 +261,6 @@ struct declaration_struct {
 struct definition_struct {
        struct definition p;
        struct declaration_struct *declaration;
-       struct definition_scope *scope;
        GPtrArray *fields;              /* Array of pointers to struct definition */
 };
 
@@ -276,7 +281,6 @@ struct declaration_variant {
 struct definition_variant {
        struct definition p;
        struct declaration_variant *declaration;
-       struct definition_scope *scope;
        struct definition *enum_tag;
        GPtrArray *fields;              /* Array of pointers to struct definition */
        struct definition *current_field;       /* Last field read */
@@ -292,13 +296,13 @@ struct declaration_array {
 struct definition_array {
        struct definition p;
        struct declaration_array *declaration;
-       struct definition_scope *scope;
        GPtrArray *elems;               /* Array of pointers to struct definition */
+       GString *string;                /* String for encoded integer children */
 };
 
 struct declaration_sequence {
        struct declaration p;
-       struct declaration_integer *len_declaration;
+       GArray *length_name;            /* Array of GQuark */
        struct declaration *elem;
        struct declaration_scope *scope;
 };
@@ -306,9 +310,9 @@ struct declaration_sequence {
 struct definition_sequence {
        struct definition p;
        struct declaration_sequence *declaration;
-       struct definition_scope *scope;
-       struct definition_integer *len;
+       struct definition_integer *length;
        GPtrArray *elems;               /* Array of pointers to struct definition */
+       GString *string;                /* String for encoded integer children */
 };
 
 int register_declaration(GQuark declaration_name,
@@ -350,21 +354,19 @@ void free_declaration_scope(struct declaration_scope *scope);
  * definition scopes.
  */
 struct definition *
-       lookup_definition(GArray *cur_path,     /* array of GQuark */
-                         GArray *lookup_path,  /* array of GQuark */
-                         struct definition_scope *scope);
+       lookup_path_definition(GArray *cur_path,        /* array of GQuark */
+                              GArray *lookup_path,     /* array of GQuark */
+                              struct definition_scope *scope);
 int register_field_definition(GQuark field_name,
                              struct definition *definition,
                              struct definition_scope *scope);
 struct definition_scope *
        new_definition_scope(struct definition_scope *parent_scope,
-                            GQuark field_name);
-void set_dynamic_definition_scope(struct definition *definition,
-                                 struct definition_scope *scope,
-                                 const char *root_name);
+                            GQuark field_name, const char *root_name);
 void free_definition_scope(struct definition_scope *scope);
 
-GQuark new_definition_path(struct definition_scope *parent_scope, GQuark field_name);
+GQuark new_definition_path(struct definition_scope *parent_scope,
+                          GQuark field_name, const char *root_name);
 
 static inline
 int compare_definition_path(struct definition *definition, GQuark path)
@@ -380,7 +382,9 @@ void definition_unref(struct definition *definition);
 
 struct declaration_integer *integer_declaration_new(size_t len, int byte_order,
                                  int signedness, size_t alignment,
-                                 int base);
+                                 int base, enum ctf_string_encoding encoding);
+uint64_t get_unsigned_int(struct definition *field);
+int64_t get_signed_int(struct definition *field);
 
 /*
  * mantissa_len is the length of the number of bytes represented by the mantissa
@@ -407,7 +411,7 @@ GArray *enum_uint_to_quark_set(const struct declaration_enum *enum_declaration,
  * Caller must release the GArray with g_array_unref().
  */
 GArray *enum_int_to_quark_set(const struct declaration_enum *enum_declaration,
-                             uint64_t v);
+                             int64_t v);
 
 /*
  * Returns a GArray of struct enum_range or NULL.
@@ -427,6 +431,7 @@ struct declaration_enum *
 
 struct declaration_string *
        string_declaration_new(enum ctf_string_encoding encoding);
+char *get_string(struct definition *field);
 
 struct declaration_struct *
        struct_declaration_new(struct declaration_scope *parent_scope,
@@ -491,13 +496,14 @@ struct declaration_array *
 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);
+GString *get_char_array(struct definition *field);
 
 /*
  * int_declaration and elem_declaration passed as parameter now belong
  * to the sequence. No need to free them explicitly.
  */
 struct declaration_sequence *
-       sequence_declaration_new(struct declaration_integer *len_declaration, 
+       sequence_declaration_new(const char *length_name,
                struct declaration *elem_declaration,
                struct declaration_scope *parent_scope);
 uint64_t sequence_len(struct definition_sequence *sequence);
@@ -509,4 +515,18 @@ int sequence_rw(struct stream_pos *pos, struct definition *definition);
  */
 void append_scope_path(const char *path, GArray *q);
 
+/*
+ * Lookup helpers.
+ */
+struct definition *lookup_definition(struct definition *definition,
+                                    const char *field_name);
+struct definition_integer *lookup_integer(struct definition *definition,
+                                         const char *field_name,
+                                         int signedness);
+struct definition_enum *lookup_enum(struct definition *definition,
+                                   const char *field_name,
+                                   int signedness);
+struct definition *lookup_variant(struct definition *definition,
+                                 const char *field_name);
+
 #endif /* _BABELTRACE_TYPES_H */
This page took 0.025603 seconds and 4 git commands to generate.