+ @property
+ def assigns_automatic_stream_class_id(self):
+ return native_bt.trace_class_assigns_automatic_stream_class_id(self._ptr)
+
+ # Add a listener to be called when the trace class is destroyed.
+
+ def add_destruction_listener(self, listener):
+
+ if not callable(listener):
+ raise TypeError("'listener' parameter is not callable")
+
+ handle = utils._ListenerHandle(self.addr)
+
+ listener_from_native = functools.partial(
+ _trace_class_destruction_listener_from_native, listener, handle
+ )
+
+ fn = native_bt.bt2_trace_class_add_destruction_listener
+ status, listener_id = fn(self._ptr, listener_from_native)
+ utils._handle_func_status(
+ status, 'cannot add destruction listener to trace class object'
+ )
+
+ handle._set_listener_id(listener_id)
+
+ return handle
+
+ def remove_destruction_listener(self, listener_handle):
+ utils._check_type(listener_handle, utils._ListenerHandle)
+
+ if listener_handle._addr != self.addr:
+ raise ValueError(
+ 'This trace class destruction listener does not match the trace class 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._invalidate()
+
+
+class _TraceClass(_TraceClassConst):
+ _borrow_stream_class_ptr_by_index = staticmethod(
+ native_bt.trace_class_borrow_stream_class_by_index
+ )
+ _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
+ )
+
+ # Instantiate a trace of this class.
+
+ def __call__(self, name=None, user_attributes=None, uuid=None, environment=None):
+ trace_ptr = native_bt.trace_create(self._ptr)
+
+ if trace_ptr is None:
+ raise bt2._MemoryError('cannot create trace class object')
+
+ trace = bt2_trace._Trace._create_from_ptr(trace_ptr)
+
+ if name is not None:
+ trace._name = name
+
+ if user_attributes is not None:
+ trace._user_attributes = user_attributes
+
+ if uuid is not None:
+ trace._uuid = uuid
+
+ if environment is not None:
+ for key, value in environment.items():
+ trace.environment[key] = value
+
+ return trace
+