Add support for floating point fields in the Python bindings
authorJérémie Galarneau <jeremie.galarneau@efficios.com>
Fri, 13 Sep 2013 21:35:41 +0000 (17:35 -0400)
committerJérémie Galarneau <jeremie.galarneau@efficios.com>
Wed, 13 Nov 2013 02:57:01 +0000 (21:57 -0500)
get_value() now returns a floating point field's value.

Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
bindings/python/babeltrace.i.in
formats/ctf/events.c
formats/ctf/types/float.c
include/babeltrace/ctf/events.h
include/babeltrace/types.h

index f3a00f588fde0d4ca267d6c155ef54792770045d..3e228ecccc7aed2c056b6346587d3ef349cb0645 100644 (file)
@@ -568,6 +568,7 @@ struct bt_ctf_event *bt_ctf_iter_read_event(struct bt_ctf_iter *iter);
 %rename("_bt_ctf_get_int64") bt_ctf_get_int64(const struct bt_definition *field);
 %rename("_bt_ctf_get_char_array") bt_ctf_get_char_array(const struct bt_definition *field);
 %rename("_bt_ctf_get_string") bt_ctf_get_string(const struct bt_definition *field);
 %rename("_bt_ctf_get_int64") bt_ctf_get_int64(const struct bt_definition *field);
 %rename("_bt_ctf_get_char_array") bt_ctf_get_char_array(const struct bt_definition *field);
 %rename("_bt_ctf_get_string") bt_ctf_get_string(const struct bt_definition *field);
+%rename("_bt_ctf_get_float") bt_ctf_get_float(const struct bt_definition *field);
 %rename("_bt_ctf_field_get_error") bt_ctf_field_get_error(void);
 %rename("_bt_ctf_get_decl_event_name") bt_ctf_get_decl_event_name(const struct
                bt_ctf_event_decl *event);
 %rename("_bt_ctf_field_get_error") bt_ctf_field_get_error(void);
 %rename("_bt_ctf_get_decl_event_name") bt_ctf_get_decl_event_name(const struct
                bt_ctf_event_decl *event);
@@ -605,6 +606,7 @@ uint64_t bt_ctf_get_uint64(const struct bt_definition *field);
 int64_t bt_ctf_get_int64(const struct bt_definition *field);
 char *bt_ctf_get_char_array(const struct bt_definition *field);
 char *bt_ctf_get_string(const struct bt_definition *field);
 int64_t bt_ctf_get_int64(const struct bt_definition *field);
 char *bt_ctf_get_char_array(const struct bt_definition *field);
 char *bt_ctf_get_string(const struct bt_definition *field);
+double bt_ctf_get_float(const struct bt_definition *field);
 int bt_ctf_field_get_error(void);
 const char *bt_ctf_get_decl_event_name(const struct bt_ctf_event_decl *event);
 const char *bt_ctf_get_decl_field_name(const struct bt_ctf_field_decl *field);
 int bt_ctf_field_get_error(void);
 const char *bt_ctf_get_decl_event_name(const struct bt_ctf_event_decl *event);
 const char *bt_ctf_get_decl_field_name(const struct bt_ctf_field_decl *field);
@@ -1036,6 +1038,15 @@ class ctf:
                        """
                        return _bt_ctf_get_string(self._d)
 
                        """
                        return _bt_ctf_get_string(self._d)
 
+               def get_float(self):
+                       """
+                       Return the value associated with the field.
+                       If the field does not exist or is not of the type requested,
+                       the value returned is undefined. To check if an error occured,
+                       use the ctf.field_error() function after accessing a field.
+                       """
+                       return _bt_ctf_get_float(self._d)
+
                def get_value(self):
                        """
                        Return the value associated with the field according to its type.
                def get_value(self):
                        """
                        Return the value associated with the field according to its type.
@@ -1063,6 +1074,9 @@ class ctf:
                                for i in range(seq_len):
                                        evDef = self.get_sequence_element_at(i)
                                        value.append(evDef.get_value())
                                for i in range(seq_len):
                                        evDef = self.get_sequence_element_at(i)
                                        value.append(evDef.get_value())
+                       elif id == ctf.type_id.FLOAT:
+                               value = self.get_float()
+
                        if ctf.field_error():
                                raise ctf.FieldError("Error occured while accessing field {} of type {}".format(self.field_name(), ctf.type_id.get_type_id_name(self.field_type())))
                        return value
                        if ctf.field_error():
                                raise ctf.FieldError("Error occured while accessing field {} of type {}".format(self.field_name(), ctf.type_id.get_type_id_name(self.field_type())))
                        return value
index af376a4412b8c8b0c807cf432748302cda5301a8..15d5a7dcde0147205a585baff63e7422cd596c20 100644 (file)
@@ -608,6 +608,19 @@ char *bt_ctf_get_string(const struct bt_definition *field)
        return ret;
 }
 
        return ret;
 }
 
+double bt_ctf_get_float(const struct bt_definition *field)
+{
+       double ret = 0.0;
+
+       if (field && bt_ctf_field_type(bt_ctf_get_decl_from_def(field)) == CTF_TYPE_FLOAT) {
+               ret = bt_get_float(field);
+       } else {
+               bt_ctf_field_set_error(-EINVAL);
+       }
+
+       return ret;
+}
+
 int bt_ctf_get_event_decl_list(int handle_id, struct bt_context *ctx,
                struct bt_ctf_event_decl * const **list,
                unsigned int *count)
 int bt_ctf_get_event_decl_list(int handle_id, struct bt_context *ctx,
                struct bt_ctf_event_decl * const **list,
                unsigned int *count)
index 689028360d4fe8f258d307e014e54103fb03201e..9c60b737815ab587444a8a46b9ae12a63d003e3d 100644 (file)
@@ -278,6 +278,14 @@ end:
        return ret;
 }
 
        return ret;
 }
 
+double bt_get_float(const struct bt_definition *field)
+{
+       struct definition_float *definition =
+               container_of(field, struct definition_float, p);
+
+       return definition->value;
+}
+
 static
 void __attribute__((constructor)) ctf_float_init(void)
 {
 static
 void __attribute__((constructor)) ctf_float_init(void)
 {
index c92470cf83de30effd11a2da27928f804f501980..c57cde74310b7d42f286bbb730cee8670e1764e2 100644 (file)
@@ -231,6 +231,7 @@ const struct bt_definition *bt_ctf_get_enum_int(const struct bt_definition *fiel
 const char *bt_ctf_get_enum_str(const struct bt_definition *field);
 char *bt_ctf_get_char_array(const struct bt_definition *field);
 char *bt_ctf_get_string(const struct bt_definition *field);
 const char *bt_ctf_get_enum_str(const struct bt_definition *field);
 char *bt_ctf_get_char_array(const struct bt_definition *field);
 char *bt_ctf_get_string(const struct bt_definition *field);
+double bt_ctf_get_float(const struct bt_definition *field);
 
 /*
  * bt_ctf_field_get_error: returns the last error code encountered while
 
 /*
  * bt_ctf_field_get_error: returns the last error code encountered while
index 8d660bea0e747fa21b0e20221a038dc4fbb5fab0..7db83164f6c36eead37443dd05a83ec312555426 100644 (file)
@@ -435,6 +435,8 @@ struct declaration_string *
 char *bt_get_string(const struct bt_definition *field);
 enum ctf_string_encoding bt_get_string_encoding(const struct bt_definition *field);
 
 char *bt_get_string(const struct bt_definition *field);
 enum ctf_string_encoding bt_get_string_encoding(const struct bt_definition *field);
 
+double bt_get_float(const struct bt_definition *field);
+
 struct declaration_struct *
        bt_struct_declaration_new(struct declaration_scope *parent_scope,
                               uint64_t min_align);
 struct declaration_struct *
        bt_struct_declaration_new(struct declaration_scope *parent_scope,
                               uint64_t min_align);
This page took 0.028489 seconds and 4 git commands to generate.