X-Git-Url: http://git.efficios.com/?a=blobdiff_plain;f=bindings%2Fpython%2Fbt2%2Fbt2%2Fclock_class.py;h=41c9863f6267d24d91a65ae16e230930a565cc8e;hb=1c9ed2ffbefa751380762afde8779239716c020e;hp=24b1db680783341aca38b764f0dce08eb42aa80d;hpb=1b8fb86234d51aff255b8e97435d4dbb3316eaec;p=babeltrace.git diff --git a/bindings/python/bt2/bt2/clock_class.py b/bindings/python/bt2/bt2/clock_class.py index 24b1db68..41c9863f 100644 --- a/bindings/python/bt2/bt2/clock_class.py +++ b/bindings/python/bt2/bt2/clock_class.py @@ -24,6 +24,7 @@ from bt2 import native_bt, object, utils import uuid as uuidp import numbers import bt2 +import bt2.clock_snapshot as clock_snapshot class ClockClassOffset: @@ -52,12 +53,12 @@ class ClockClassOffset: return (self.seconds, self.cycles) == (other.seconds, other.cycles) -class ClockClass(object._Object): +class ClockClass(object._SharedObject): def __init__(self, name, frequency, description=None, precision=None, offset=None, is_absolute=None, uuid=None): utils._check_str(name) utils._check_uint64(frequency) - ptr = native_bt.ctf_clock_class_create(name, frequency) + ptr = native_bt.clock_class_create(name, frequency) if ptr is None: raise bt2.CreationError('cannot create clock class object') @@ -131,81 +132,81 @@ class ClockClass(object._Object): @property def name(self): - name = native_bt.ctf_clock_class_get_name(self._ptr) + name = native_bt.clock_class_get_name(self._ptr) assert(name is not None) return name @name.setter def name(self, name): utils._check_str(name) - ret = native_bt.ctf_clock_class_set_name(self._ptr, name) + ret = native_bt.clock_class_set_name(self._ptr, name) utils._handle_ret(ret, "cannot set clock class object's name") @property def description(self): - return native_bt.ctf_clock_class_get_description(self._ptr) + return native_bt.clock_class_get_description(self._ptr) @description.setter def description(self, description): utils._check_str(description) - ret = native_bt.ctf_clock_class_set_description(self._ptr, description) + ret = native_bt.clock_class_set_description(self._ptr, description) utils._handle_ret(ret, "cannot set clock class object's description") @property def frequency(self): - frequency = native_bt.ctf_clock_class_get_frequency(self._ptr) + frequency = native_bt.clock_class_get_frequency(self._ptr) assert(frequency >= 1) return frequency @frequency.setter def frequency(self, frequency): utils._check_uint64(frequency) - ret = native_bt.ctf_clock_class_set_frequency(self._ptr, frequency) + ret = native_bt.clock_class_set_frequency(self._ptr, frequency) utils._handle_ret(ret, "cannot set clock class object's frequency") @property def precision(self): - precision = native_bt.ctf_clock_class_get_precision(self._ptr) + precision = native_bt.clock_class_get_precision(self._ptr) assert(precision >= 0) return precision @precision.setter def precision(self, precision): utils._check_uint64(precision) - ret = native_bt.ctf_clock_class_set_precision(self._ptr, precision) + ret = native_bt.clock_class_set_precision(self._ptr, precision) utils._handle_ret(ret, "cannot set clock class object's precision") @property def offset(self): - ret, offset_s = native_bt.ctf_clock_class_get_offset_s(self._ptr) + ret, offset_s = native_bt.clock_class_get_offset_s(self._ptr) assert(ret == 0) - ret, offset_cycles = native_bt.ctf_clock_class_get_offset_cycles(self._ptr) + ret, offset_cycles = native_bt.clock_class_get_offset_cycles(self._ptr) assert(ret == 0) return ClockClassOffset(offset_s, offset_cycles) @offset.setter def offset(self, offset): utils._check_type(offset, ClockClassOffset) - ret = native_bt.ctf_clock_class_set_offset_s(self._ptr, offset.seconds) + ret = native_bt.clock_class_set_offset_s(self._ptr, offset.seconds) utils._handle_ret(ret, "cannot set clock class object's offset (seconds)") - ret = native_bt.ctf_clock_class_set_offset_cycles(self._ptr, offset.cycles) + ret = native_bt.clock_class_set_offset_cycles(self._ptr, offset.cycles) utils._handle_ret(ret, "cannot set clock class object's offset (cycles)") @property def is_absolute(self): - is_absolute = native_bt.ctf_clock_class_is_absolute(self._ptr) + is_absolute = native_bt.clock_class_is_absolute(self._ptr) assert(is_absolute >= 0) return is_absolute > 0 @is_absolute.setter def is_absolute(self, is_absolute): utils._check_bool(is_absolute) - ret = native_bt.ctf_clock_class_set_is_absolute(self._ptr, int(is_absolute)) + ret = native_bt.clock_class_set_is_absolute(self._ptr, int(is_absolute)) utils._handle_ret(ret, "cannot set clock class object's absoluteness") @property def uuid(self): - uuid_bytes = native_bt.ctf_clock_class_get_uuid(self._ptr) + uuid_bytes = native_bt.clock_class_get_uuid(self._ptr) if uuid_bytes is None: return @@ -215,65 +216,8 @@ class ClockClass(object._Object): @uuid.setter def uuid(self, uuid): utils._check_type(uuid, uuidp.UUID) - ret = native_bt.ctf_clock_class_set_uuid(self._ptr, uuid.bytes) + ret = native_bt.clock_class_set_uuid(self._ptr, uuid.bytes) utils._handle_ret(ret, "cannot set clock class object's UUID") 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 + return clock_snapshot._ClockSnapshot(self._ptr, cycles)