Python bindings: Add UUID accessors to the Clock class
[babeltrace.git] / bindings / python / babeltrace.i.in
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).
This page took 0.024297 seconds and 4 git commands to generate.