Python bindings: Add UUID accessors to the Clock class
authorJérémie Galarneau <jeremie.galarneau@efficios.com>
Sat, 11 Oct 2014 01:45:49 +0000 (21:45 -0400)
committerJérémie Galarneau <jeremie.galarneau@efficios.com>
Sat, 11 Oct 2014 01:45:49 +0000 (21:45 -0400)
Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
bindings/python/babeltrace.i.in
bindings/python/examples/ctf_writer.py
bindings/python/python-complements.c
bindings/python/python-complements.h

index 724ed45d7e5d76351cdf905ca75e2690b57c9253..cdb687d5035345657ee730f3a70eca5f75e881ca 100644 (file)
@@ -114,6 +114,10 @@ const char *_bt_python_ctf_event_class_get_field_name(
                struct bt_ctf_event_class *event_class, size_t index);
 struct bt_ctf_field_type *_bt_python_ctf_event_class_get_field_type(
                struct bt_ctf_event_class *event_class, size_t index);
+int _bt_python_ctf_clock_get_uuid_index(struct bt_ctf_clock *clock,
+               size_t index, unsigned char *OUTPUT);
+int _bt_python_ctf_clock_set_uuid_index(struct bt_ctf_clock *clock,
+               size_t index, unsigned char value);
 
 /* =================================================================
                CONTEXT.H, CONTEXT-INTERNAL.H
@@ -1586,6 +1590,7 @@ void bt_ctf_writer_get(struct bt_ctf_writer *writer);
 void bt_ctf_writer_put(struct bt_ctf_writer *writer);
 
 %pythoncode %{
+import uuid
 
 class CTFWriter:
        # Used to compare to -1ULL in error checks
@@ -1731,6 +1736,32 @@ class CTFWriter:
                        if ret < 0:
                                raise ValueError("Could not set the clock's absolute attribute.")
 
+               """
+               Get a clock's UUID (an object of type UUID).
+               """
+               @property
+               def uuid(self):
+                       uuid_list = []
+                       for i in range(16):
+                               ret, value = _bt_python_ctf_clock_get_uuid_index(self._c, i)
+                               if ret < 0:
+                                       raise ValueError("Invalid clock instance")
+                               uuid_list.append(value)
+                       return uuid.UUID(bytes=bytes(uuid_list))
+
+               """
+               Set a clock's UUID (an object of type UUID).
+               """
+               @uuid.setter
+               def uuid(self, uuid):
+                       uuid_bytes = uuid.bytes
+                       if len(uuid_bytes) != 16:
+                               raise ValueError("Invalid UUID provided. UUID length must be 16 bytes")
+                       for i in range(len(uuid_bytes)):
+                               ret = _bt_python_ctf_clock_set_uuid_index(self._c, i, uuid_bytes[i])
+                               if ret < 0:
+                                       raise ValueError("Invalid clock instance")
+
                """
                Get the current time in nanoseconds since the clock's origin (offset and
                offset_s attributes).
index fd9ce1595b26a48313638700f424e2ab456d3eb7..b7bd73f2b5252fd7b8613893c81b8aa6f3ec9349 100644 (file)
@@ -36,6 +36,7 @@ print("Clock offset_seconds is {}".format(clock.offset_seconds))
 print("Clock offset is {}".format(clock.offset))
 print("Clock is absolute: {}".format(clock.absolute))
 print("Clock time is {}".format(clock.time))
+print("Clock UUID is {}".format(clock.uuid))
 
 writer.add_clock(clock)
 writer.add_environment_field("Python_version", str(sys.version_info))
index 55312fff8a1fe444255f182c6b026a2c00b957c7..872512d6848a44d4fa5e24bab8bb8f08f7e6de6e 100644 (file)
@@ -23,6 +23,7 @@
 #include <babeltrace/ctf-ir/event-fields-internal.h>
 #include <babeltrace/ctf-ir/event-types.h>
 #include <babeltrace/ctf-ir/event.h>
+#include <babeltrace/ctf-ir/clock-internal.h>
 
 /* List-related functions
    ----------------------------------------------------
@@ -342,3 +343,39 @@ struct bt_ctf_field_type *_bt_python_ctf_event_class_get_field_type(
        return !ret ? type : NULL;
 }
 
+int _bt_python_ctf_clock_get_uuid_index(struct bt_ctf_clock *clock,
+               size_t index, unsigned char *value)
+{
+       int ret = 0;
+       const unsigned char *uuid;
+
+       if (index >= 16) {
+               ret = -1;
+               goto end;
+       }
+
+       uuid = bt_ctf_clock_get_uuid(clock);
+       if (!uuid) {
+               ret = -1;
+               goto end;
+       }
+
+       *value = uuid[index];
+end:
+       return ret;
+}
+
+int _bt_python_ctf_clock_set_uuid_index(struct bt_ctf_clock *clock,
+               size_t index, unsigned char value)
+{
+       int ret = 0;
+
+       if (index >= 16) {
+               ret = -1;
+               goto end;
+       }
+
+       clock->uuid[index] = value;
+end:
+       return ret;
+}
index 0132b45e74ac3c3feefaf5c635a2e757cc2d0fe6..e2f12374bc63b12d35d5f255d552b4e2134b8c59 100644 (file)
@@ -27,6 +27,7 @@
 #include <babeltrace/iterator-internal.h>
 #include <babeltrace/ctf/events-internal.h>
 #include <babeltrace/ctf-writer/event-fields.h>
+#include <babeltrace/ctf-writer/clock.h>
 
 /* ctf-field-list */
 struct bt_definition **_bt_python_field_listcaller(
@@ -85,3 +86,7 @@ const char *_bt_python_ctf_event_class_get_field_name(
                struct bt_ctf_event_class *event_class, size_t index);
 struct bt_ctf_field_type *_bt_python_ctf_event_class_get_field_type(
                struct bt_ctf_event_class *event_class, size_t index);
+int _bt_python_ctf_clock_get_uuid_index(struct bt_ctf_clock *clock,
+               size_t index, unsigned char *value);
+int _bt_python_ctf_clock_set_uuid_index(struct bt_ctf_clock *clock,
+               size_t index, unsigned char value);
This page took 0.0291 seconds and 4 git commands to generate.