X-Git-Url: http://git.efficios.com/?a=blobdiff_plain;f=src%2Fbindings%2Fpython%2Fbt2%2Fbt2%2Fstream_class.py;h=e73b40e9d61604c78f7f5c272c9ccee2edbcaafa;hb=e5914347c8eea0f26c07348d0ac64dbe020de44a;hp=ecab1df8e631ddadf8eb2ae307f28dceb33b8955;hpb=d3bf1370a437239053f532d73c4e04df53827bb9;p=babeltrace.git diff --git a/src/bindings/python/bt2/bt2/stream_class.py b/src/bindings/python/bt2/bt2/stream_class.py index ecab1df8..e73b40e9 100644 --- a/src/bindings/python/bt2/bt2/stream_class.py +++ b/src/bindings/python/bt2/bt2/stream_class.py @@ -1,26 +1,10 @@ -# The MIT License (MIT) +# SPDX-License-Identifier: 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 + +from bt2 import native_bt +from bt2 import object as bt2_object +from bt2 import utils as bt2_utils from bt2 import field_class as bt2_field_class from bt2 import event_class as bt2_event_class from bt2 import clock_class as bt2_clock_class @@ -34,9 +18,15 @@ def _bt2_trace_class(): return bt2_trace_class -class _StreamClassConst(object._SharedObject, collections.abc.Mapping): - _get_ref = staticmethod(native_bt.stream_class_get_ref) - _put_ref = staticmethod(native_bt.stream_class_put_ref) +class _StreamClassConst(bt2_object._SharedObject, collections.abc.Mapping): + @staticmethod + def _get_ref(ptr): + native_bt.stream_class_get_ref(ptr) + + @staticmethod + def _put_ref(ptr): + native_bt.stream_class_put_ref(ptr) + _borrow_event_class_ptr_by_id = staticmethod( native_bt.stream_class_borrow_event_class_by_id_const ) @@ -64,7 +54,7 @@ class _StreamClassConst(object._SharedObject, collections.abc.Mapping): _clock_class_cls = property(lambda _: bt2_clock_class._ClockClassConst) def __getitem__(self, key): - utils._check_int64(key) + bt2_utils._check_int64(key) ec_ptr = self._borrow_event_class_ptr_by_id(self._ptr, key) if ec_ptr is None: @@ -183,8 +173,14 @@ class _StreamClassConst(object._SharedObject, collections.abc.Mapping): class _StreamClass(_StreamClassConst): - _get_ref = staticmethod(native_bt.stream_class_get_ref) - _put_ref = staticmethod(native_bt.stream_class_put_ref) + @staticmethod + def _get_ref(ptr): + native_bt.stream_class_get_ref(ptr) + + @staticmethod + def _put_ref(ptr): + native_bt.stream_class_put_ref(ptr) + _borrow_event_class_ptr_by_id = staticmethod( native_bt.stream_class_borrow_event_class_by_id ) @@ -219,20 +215,30 @@ class _StreamClass(_StreamClassConst): specific_context_field_class=None, payload_field_class=None, ): + # Validate parameters before we create the object. + bt2_event_class._EventClass._validate_create_params( + name, + user_attributes, + log_level, + emf_uri, + specific_context_field_class, + payload_field_class, + ) + if self.assigns_automatic_event_class_id: if id is not None: raise ValueError( - 'id provided, but stream class assigns automatic event class ids' + "id provided, but stream class assigns automatic event class ids" ) ec_ptr = native_bt.event_class_create(self._ptr) else: if id is None: raise ValueError( - 'id not provided, but stream class does not assign automatic event class ids' + "id not provided, but stream class does not assign automatic event class ids" ) - utils._check_uint64(id) + bt2_utils._check_uint64(id) ec_ptr = native_bt.event_class_create_with_id(self._ptr, id) event_class = bt2_event_class._EventClass._create_from_ptr(ec_ptr) @@ -265,7 +271,7 @@ class _StreamClass(_StreamClassConst): def _name(self, name): status = native_bt.stream_class_set_name(self._ptr, name) - utils._handle_func_status(status, "cannot set stream class object's name") + bt2_utils._handle_func_status(status, "cannot set stream class object's name") _name = property(fset=_name) @@ -302,7 +308,7 @@ class _StreamClass(_StreamClassConst): status = native_bt.stream_class_set_packet_context_field_class( self._ptr, packet_context_field_class._ptr ) - utils._handle_func_status( + bt2_utils._handle_func_status( status, "cannot set stream class' packet context field class" ) @@ -311,7 +317,7 @@ class _StreamClass(_StreamClassConst): def _event_common_context_field_class(self, event_common_context_field_class): set_context_fn = native_bt.stream_class_set_event_common_context_field_class status = set_context_fn(self._ptr, event_common_context_field_class._ptr) - utils._handle_func_status( + bt2_utils._handle_func_status( status, "cannot set stream class' event context field type" ) @@ -342,80 +348,86 @@ class _StreamClass(_StreamClassConst): ): # Name if name is not None: - utils._check_str(name) + bt2_utils._check_str(name) # User attributes if user_attributes is not None: value = bt2_value.create_value(user_attributes) - utils._check_type(value, bt2_value.MapValue) + bt2_utils._check_type(value, bt2_value.MapValue) # Packet context field class if packet_context_field_class is not None: if not supports_packets: raise ValueError( - 'cannot have a packet context field class without supporting packets' + "cannot have a packet context field class without supporting packets" ) - utils._check_type( + bt2_utils._check_type( packet_context_field_class, bt2_field_class._StructureFieldClass ) # Event common context field class if event_common_context_field_class is not None: - utils._check_type( + bt2_utils._check_type( event_common_context_field_class, bt2_field_class._StructureFieldClass ) # Default clock class if default_clock_class is not None: - utils._check_type(default_clock_class, bt2_clock_class._ClockClass) + bt2_utils._check_type(default_clock_class, bt2_clock_class._ClockClass) # Assigns automatic event class id - utils._check_bool(assigns_automatic_event_class_id) + bt2_utils._check_bool(assigns_automatic_event_class_id) # Assigns automatic stream id - utils._check_bool(assigns_automatic_stream_id) + bt2_utils._check_bool(assigns_automatic_stream_id) # Packets - utils._check_bool(supports_packets) - utils._check_bool(packets_have_beginning_default_clock_snapshot) - utils._check_bool(packets_have_end_default_clock_snapshot) + bt2_utils._check_bool(supports_packets) + bt2_utils._check_bool(packets_have_beginning_default_clock_snapshot) + bt2_utils._check_bool(packets_have_end_default_clock_snapshot) if not supports_packets: if packets_have_beginning_default_clock_snapshot: raise ValueError( - 'cannot not support packets, but have packet beginning default clock snapshot' + "cannot not support packets, but have packet beginning default clock snapshot" ) if packets_have_end_default_clock_snapshot: raise ValueError( - 'cannot not support packets, but have packet end default clock snapshots' + "cannot not support packets, but have packet end default clock snapshots" ) # Discarded events - utils._check_bool(supports_discarded_events) - utils._check_bool(discarded_events_have_default_clock_snapshots) + bt2_utils._check_bool(supports_discarded_events) + bt2_utils._check_bool(discarded_events_have_default_clock_snapshots) - if ( - not supports_discarded_events - and discarded_events_have_default_clock_snapshots - ): - raise ValueError( - 'cannot not support discarded events, but have default clock snapshots for discarded event messages' - ) + if discarded_events_have_default_clock_snapshots: + if not supports_discarded_events: + raise ValueError( + "cannot not support discarded events, but have default clock snapshots for discarded event messages" + ) + + if default_clock_class is None: + raise ValueError( + "cannot have no default clock class, but have default clock snapshots for discarded event messages" + ) # Discarded packets - utils._check_bool(supports_discarded_packets) - utils._check_bool(discarded_packets_have_default_clock_snapshots) + bt2_utils._check_bool(supports_discarded_packets) + bt2_utils._check_bool(discarded_packets_have_default_clock_snapshots) if supports_discarded_packets and not supports_packets: raise ValueError( - 'cannot support discarded packets, but not support packets' + "cannot support discarded packets, but not support packets" ) - if ( - not supports_discarded_packets - and discarded_packets_have_default_clock_snapshots - ): - raise ValueError( - 'cannot not support discarded packets, but have default clock snapshots for discarded packet messages' - ) + if discarded_packets_have_default_clock_snapshots: + if not supports_discarded_packets: + raise ValueError( + "cannot not support discarded packets, but have default clock snapshots for discarded packet messages" + ) + + if default_clock_class is None: + raise ValueError( + "cannot have no default clock class, but have default clock snapshots for discarded packet messages" + )