Move to kernel style SPDX license identifiers
[babeltrace.git] / src / bindings / python / bt2 / bt2 / trace_class.py
index dc9439eb6aa424215d3ac883249699b115796852..e99874499d6c9f1d3b1b93fa694aaa34011b8320 100644 (file)
@@ -1,26 +1,8 @@
-# The MIT License (MIT)
+# SPDX-License-Identifier: MIT
 #
 # Copyright (c) 2017 Philippe Proulx <pproulx@efficios.com>
 # Copyright (c) 2018 Francis Deslauriers <francis.deslauriers@efficios.com>
 # Copyright (c) 2019 Simon Marchi <simon.marchi@efficios.com>
-#
-# Permission is hereby granted, free of charge, to any person obtaining a copy
-# of this software and associated documentation files (the "Software"), to deal
-# in the Software without restriction, including without limitation the rights
-# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
-# copies of the Software, and to permit persons to whom the Software is
-# furnished to do so, subject to the following conditions:
-#
-# The above copyright notice and this permission notice shall be included in
-# all copies or substantial portions of the Software.
-#
-# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
-# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
-# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
-# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
-# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
-# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
-# THE SOFTWARE.
 
 from bt2 import native_bt, utils, object
 from bt2 import stream_class as bt2_stream_class
@@ -33,9 +15,12 @@ import functools
 import bt2
 
 
-def _trace_class_destruction_listener_from_native(user_listener, trace_class_ptr):
+def _trace_class_destruction_listener_from_native(
+    user_listener, handle, trace_class_ptr
+):
     trace_class = _TraceClass._create_from_ptr_and_get_ref(trace_class_ptr)
     user_listener(trace_class)
+    handle._invalidate()
 
 
 class _TraceClassConst(object._SharedObject, collections.abc.Mapping):
@@ -100,22 +85,26 @@ class _TraceClassConst(object._SharedObject, collections.abc.Mapping):
         if not callable(listener):
             raise TypeError("'listener' parameter is not callable")
 
-        fn = native_bt.bt2_trace_class_add_destruction_listener
+        handle = utils._ListenerHandle(self.addr)
+
         listener_from_native = functools.partial(
-            _trace_class_destruction_listener_from_native, listener
+            _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'
         )
 
-        return utils._ListenerHandle(listener_id, self)
+        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._obj.addr != self.addr:
+        if listener_handle._addr != self.addr:
             raise ValueError(
                 'This trace class destruction listener does not match the trace class object.'
             )
@@ -129,7 +118,7 @@ class _TraceClassConst(object._SharedObject, collections.abc.Mapping):
             self._ptr, listener_handle._listener_id
         )
         utils._handle_func_status(status)
-        listener_handle._listener_id = None
+        listener_handle._invalidate()
 
 
 class _TraceClass(_TraceClassConst):
This page took 0.025272 seconds and 4 git commands to generate.