X-Git-Url: http://git.efficios.com/?a=blobdiff_plain;f=bindings%2Fpython%2Fbt2%2Fbt2%2Fclock_class.py;h=59a93cd7884a8bf596352ed15f49d20bb64c0d21;hb=2c6f8520ad68e1ca0c9554d705c39790e7d3ef5f;hp=552ac61da6f515aac7d57ef7d9bc95376342007e;hpb=79c39ab98539857548234abddaa7f728cf27a45f;p=babeltrace.git diff --git a/bindings/python/bt2/bt2/clock_class.py b/bindings/python/bt2/bt2/clock_class.py index 552ac61d..59a93cd7 100644 --- a/bindings/python/bt2/bt2/clock_class.py +++ b/bindings/python/bt2/bt2/clock_class.py @@ -21,9 +21,8 @@ # THE SOFTWARE. from bt2 import native_bt, object, utils -import uuid as uuidp -import numbers import bt2 +import uuid as uuidp class ClockClassOffset: @@ -41,9 +40,6 @@ class ClockClassOffset: def cycles(self): return self._cycles - def __hash__(self): - return hash((self.seconds, self.cycles)) - def __eq__(self, other): if not isinstance(other, self.__class__): # not comparing apples to apples @@ -52,172 +48,97 @@ class ClockClassOffset: return (self.seconds, self.cycles) == (other.seconds, other.cycles) -class ClockClass(object._Object): - 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) - - if ptr is None: - raise bt2.CreationError('cannot create clock class object') - - super().__init__(ptr) - - if description is not None: - self.description = description - - if frequency is not None: - self.frequency = frequency - - if precision is not None: - self.precision = precision - - if offset is not None: - self.offset = offset - - if is_absolute is not None: - self.is_absolute = is_absolute - - if uuid is not None: - self.uuid = uuid - - def __eq__(self, other): - if type(self) is not type(other): - # not comparing apples to apples - return False - - self_props = ( - self.name, - self.description, - self.frequency, - self.precision, - self.offset, - self.is_absolute, - self.uuid - ) - other_props = ( - other.name, - other.description, - other.frequency, - other.precision, - other.offset, - other.is_absolute, - other.uuid - ) - return self_props == other_props - - def __copy__(self): - return ClockClass(name=self.name, description=self.description, - frequency=self.frequency, precision=self.precision, - offset=self.offset, is_absolute=self.is_absolute, - uuid=self.uuid) - - def __deepcopy__(self, memo): - cpy = self.__copy__() - memo[id(self)] = cpy - return cpy - - def __hash__(self): - return hash(( - self.name, - self.description, - self.frequency, - self.precision, - self.offset.seconds, - self.offset.cycles, - self.is_absolute, - self.uuid)) +class _ClockClass(object._SharedObject): + _get_ref = staticmethod(native_bt.clock_class_get_ref) + _put_ref = staticmethod(native_bt.clock_class_put_ref) @property def name(self): - name = native_bt.ctf_clock_class_get_name(self._ptr) - assert(name is not None) - return name + return native_bt.clock_class_get_name(self._ptr) - @name.setter - def name(self, name): + 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") + _name = property(fset=_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): + 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") + _description = property(fset=_description) + @property def frequency(self): - frequency = native_bt.ctf_clock_class_get_frequency(self._ptr) - assert(frequency >= 1) - return frequency + return native_bt.clock_class_get_frequency(self._ptr) - @frequency.setter - def frequency(self, frequency): + def _frequency(self, frequency): utils._check_uint64(frequency) - ret = native_bt.ctf_clock_class_set_frequency(self._ptr, frequency) - utils._handle_ret(ret, "cannot set clock class object's frequency") + native_bt.clock_class_set_frequency(self._ptr, frequency) + + _frequency = property(fset=_frequency) @property def precision(self): - precision = native_bt.ctf_clock_class_get_precision(self._ptr) - assert(precision >= 0) + precision = native_bt.clock_class_get_precision(self._ptr) return precision - @precision.setter - def precision(self, precision): + def _precision(self, precision): utils._check_uint64(precision) - ret = native_bt.ctf_clock_class_set_precision(self._ptr, precision) - utils._handle_ret(ret, "cannot set clock class object's precision") + native_bt.clock_class_set_precision(self._ptr, precision) + + _precision = property(fset=_precision) @property def offset(self): - ret, offset_s = native_bt.ctf_clock_class_get_offset_s(self._ptr) - assert(ret == 0) - ret, offset_cycles = native_bt.ctf_clock_class_get_offset_cycles(self._ptr) - assert(ret == 0) + offset_s, offset_cycles = native_bt.clock_class_get_offset(self._ptr) return ClockClassOffset(offset_s, offset_cycles) - @offset.setter - def offset(self, offset): + def _offset(self, offset): utils._check_type(offset, ClockClassOffset) - ret = native_bt.ctf_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) - utils._handle_ret(ret, "cannot set clock class object's offset (cycles)") + native_bt.clock_class_set_offset(self._ptr, offset.seconds, offset.cycles) + + _offset = property(fset=_offset) @property - def is_absolute(self): - is_absolute = native_bt.ctf_clock_class_is_absolute(self._ptr) - assert(is_absolute >= 0) - return is_absolute > 0 + def origin_is_unix_epoch(self): + return native_bt.clock_class_origin_is_unix_epoch(self._ptr) + + def _origin_is_unix_epoch(self, origin_is_unix_epoch): + utils._check_bool(origin_is_unix_epoch) + native_bt.clock_class_set_origin_is_unix_epoch(self._ptr, int(origin_is_unix_epoch)) - @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)) - utils._handle_ret(ret, "cannot set clock class object's absoluteness") + _origin_is_unix_epoch = property(fset=_origin_is_unix_epoch) @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 return uuidp.UUID(bytes=uuid_bytes) - @uuid.setter - def uuid(self, uuid): + def _uuid(self, uuid): utils._check_type(uuid, uuidp.UUID) - ret = native_bt.ctf_clock_class_set_uuid(self._ptr, uuid.bytes) - utils._handle_ret(ret, "cannot set clock class object's UUID") + native_bt.clock_class_set_uuid(self._ptr, uuid.bytes) + + _uuid = property(fset=_uuid) + + def cycles_to_ns_from_origin(self, cycles): + utils._check_uint64(cycles) + ret, ns = native_bt.clock_class_cycles_to_ns_from_origin(self._ptr, cycles) + + error_msg = "cannot convert clock value to nanoseconds from origin for given clock class" - def __call__(self, cycles): - return _ClockValue(self._ptr, cycles) + if ret == native_bt.CLOCK_CLASS_STATUS_OVERFLOW: + raise OverflowError(error_msg) + utils._handle_ret(ret, error_msg) + return ns