bt2: make it possible to remove a trace class or trace destruction listener
[babeltrace.git] / src / bindings / python / bt2 / bt2 / trace_class.py
index 94343552b01031238c32dab38e7c23e52fd371f8..9146efacb927b7389857ae189ed7baf8ba18ea57 100644 (file)
@@ -26,7 +26,6 @@ from bt2 import native_bt, utils, object
 from bt2 import stream_class as bt2_stream_class
 from bt2 import field_class as bt2_field_class
 from bt2 import trace as bt2_trace
-from bt2 import trace_class as bt2_trace_class
 from bt2 import value as bt2_value
 import collections.abc
 import functools
@@ -47,6 +46,9 @@ class _TraceClassConst(object._SharedObject, collections.abc.Mapping):
     _borrow_stream_class_ptr_by_id = staticmethod(
         native_bt.trace_class_borrow_stream_class_by_id_const
     )
+    _borrow_user_attributes_ptr = staticmethod(
+        native_bt.trace_class_borrow_user_attributes_const
+    )
     _stream_class_pycls = bt2_stream_class._StreamClassConst
     _create_value_from_ptr_and_get_ref = staticmethod(
         bt2_value._create_from_const_ptr_and_get_ref
@@ -54,7 +56,7 @@ class _TraceClassConst(object._SharedObject, collections.abc.Mapping):
 
     @property
     def user_attributes(self):
-        ptr = native_bt.trace_class_borrow_user_attributes(self._ptr)
+        ptr = self._borrow_user_attributes_ptr(self._ptr)
         assert ptr is not None
         return self._create_value_from_ptr_and_get_ref(ptr)
 
@@ -109,6 +111,25 @@ class _TraceClassConst(object._SharedObject, collections.abc.Mapping):
 
         return utils._ListenerHandle(listener_id, self)
 
+    def remove_destruction_listener(self, listener_handle):
+        utils._check_type(listener_handle, utils._ListenerHandle)
+
+        if listener_handle._obj.addr != self.addr:
+            raise ValueError(
+                'This trace class destruction listener does not match the trace object.'
+            )
+
+        if listener_handle._listener_id is None:
+            raise ValueError(
+                'This trace class destruction listener was already removed.'
+            )
+
+        status = native_bt.trace_class_remove_destruction_listener(
+            self._ptr, listener_handle._listener_id
+        )
+        utils._handle_func_status(status)
+        listener_handle._listener_id = None
+
 
 class _TraceClass(_TraceClassConst):
     _borrow_stream_class_ptr_by_index = staticmethod(
@@ -117,6 +138,9 @@ class _TraceClass(_TraceClassConst):
     _borrow_stream_class_ptr_by_id = staticmethod(
         native_bt.trace_class_borrow_stream_class_by_id
     )
+    _borrow_user_attributes_ptr = staticmethod(
+        native_bt.trace_class_borrow_user_attributes
+    )
     _stream_class_pycls = bt2_stream_class._StreamClass
     _create_value_from_ptr_and_get_ref = staticmethod(
         bt2_value._create_from_ptr_and_get_ref
This page took 0.02577 seconds and 4 git commands to generate.