From 79c39ab98539857548234abddaa7f728cf27a45f Mon Sep 17 00:00:00 2001 From: Philippe Proulx Date: Tue, 5 Sep 2017 19:01:03 -0400 Subject: [PATCH] bt2: split clock value module from clock class module MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit This doesn't change anything from the package's user's perspective, but it's more in line with the C API. Signed-off-by: Philippe Proulx Signed-off-by: Jérémie Galarneau --- bindings/python/bt2/bt2/__init__.py.in | 1 + bindings/python/bt2/bt2/clock_class.py | 56 ----------------- bindings/python/bt2/bt2/clock_value.py | 83 ++++++++++++++++++++++++++ 3 files changed, 84 insertions(+), 56 deletions(-) create mode 100644 bindings/python/bt2/bt2/clock_value.py diff --git a/bindings/python/bt2/bt2/__init__.py.in b/bindings/python/bt2/bt2/__init__.py.in index 0a49b7948..f12d95534 100644 --- a/bindings/python/bt2/bt2/__init__.py.in +++ b/bindings/python/bt2/bt2/__init__.py.in @@ -26,6 +26,7 @@ __version__ = '@PACKAGE_VERSION@' from bt2.clock_class import * from bt2.clock_class import _ClockValue from bt2.clock_class_priority_map import * +from bt2.clock_value import * from bt2.component import * from bt2.component import _FilterComponent from bt2.component import _GenericFilterComponentClass diff --git a/bindings/python/bt2/bt2/clock_class.py b/bindings/python/bt2/bt2/clock_class.py index 24b1db680..552ac61da 100644 --- a/bindings/python/bt2/bt2/clock_class.py +++ b/bindings/python/bt2/bt2/clock_class.py @@ -221,59 +221,3 @@ class ClockClass(object._Object): def __call__(self, cycles): return _ClockValue(self._ptr, cycles) - -def _create_clock_value_from_ptr(ptr): - clock_value = _ClockValue._create_from_ptr(ptr) - return clock_value - - -class _ClockValue(object._Object): - def __init__(self, clock_class_ptr, cycles): - utils._check_uint64(cycles) - ptr = native_bt.ctf_clock_value_create(clock_class_ptr, cycles) - - if ptr is None: - raise bt2.CreationError('cannot create clock value object') - - super().__init__(ptr) - - @property - def clock_class(self): - ptr = native_bt.ctf_clock_value_get_class(self._ptr) - assert(ptr) - return ClockClass._create_from_ptr(ptr) - - @property - def cycles(self): - ret, cycles = native_bt.ctf_clock_value_get_value(self._ptr) - assert(ret == 0) - return cycles - - @property - def ns_from_epoch(self): - ret, ns = native_bt.ctf_clock_value_get_value_ns_from_epoch(self._ptr) - utils._handle_ret(ret, "cannot get clock value object's nanoseconds from Epoch") - return ns - - def __eq__(self, other): - if isinstance(other, numbers.Integral): - return int(other) == self.cycles - - if not isinstance(other, self.__class__): - # not comparing apples to apples - return False - - if self.addr == other.addr: - return True - - self_props = self.clock_class, self.cycles - other_props = other.clock_class, other.cycles - return self_props == other_props - - def __copy__(self): - return self.clock_class(self.cycles) - - def __deepcopy__(self, memo): - cpy = self.__copy__() - memo[id(self)] = cpy - return cpy diff --git a/bindings/python/bt2/bt2/clock_value.py b/bindings/python/bt2/bt2/clock_value.py new file mode 100644 index 000000000..e35bc8ee6 --- /dev/null +++ b/bindings/python/bt2/bt2/clock_value.py @@ -0,0 +1,83 @@ +# The MIT License (MIT) +# +# Copyright (c) 2017 Philippe Proulx +# +# 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, object, utils +import uuid as uuidp +import numbers +import bt2 + + +def _create_clock_value_from_ptr(ptr): + clock_value = _ClockValue._create_from_ptr(ptr) + return clock_value + + +class _ClockValue(object._Object): + def __init__(self, clock_class_ptr, cycles): + utils._check_uint64(cycles) + ptr = native_bt.ctf_clock_value_create(clock_class_ptr, cycles) + + if ptr is None: + raise bt2.CreationError('cannot create clock value object') + + super().__init__(ptr) + + @property + def clock_class(self): + ptr = native_bt.ctf_clock_value_get_class(self._ptr) + assert(ptr) + return ClockClass._create_from_ptr(ptr) + + @property + def cycles(self): + ret, cycles = native_bt.ctf_clock_value_get_value(self._ptr) + assert(ret == 0) + return cycles + + @property + def ns_from_epoch(self): + ret, ns = native_bt.ctf_clock_value_get_value_ns_from_epoch(self._ptr) + utils._handle_ret(ret, "cannot get clock value object's nanoseconds from Epoch") + return ns + + def __eq__(self, other): + if isinstance(other, numbers.Integral): + return int(other) == self.cycles + + if not isinstance(other, self.__class__): + # not comparing apples to apples + return False + + if self.addr == other.addr: + return True + + self_props = self.clock_class, self.cycles + other_props = other.clock_class, other.cycles + return self_props == other_props + + def __copy__(self): + return self.clock_class(self.cycles) + + def __deepcopy__(self, memo): + cpy = self.__copy__() + memo[id(self)] = cpy + return cpy -- 2.34.1