X-Git-Url: http://git.efficios.com/?p=babeltrace.git;a=blobdiff_plain;f=src%2Fbindings%2Fpython%2Fbt2%2Fbt2%2Fevent_class.py;h=cbbd807cb4ab78941c6d854cc2709014c3b87eaf;hp=b165d3211ec16d655f36a791c1fc7d34d80a5d8a;hb=0235b0db7de5bcacdb3650c92461f2ce5eb2143d;hpb=7993562851b443afb3801e5bf2b88d674734808b diff --git a/src/bindings/python/bt2/bt2/event_class.py b/src/bindings/python/bt2/bt2/event_class.py index b165d321..cbbd807c 100644 --- a/src/bindings/python/bt2/bt2/event_class.py +++ b/src/bindings/python/bt2/bt2/event_class.py @@ -1,24 +1,6 @@ -# 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 field_class as bt2_field_class @@ -147,73 +129,94 @@ class _EventClass(_EventClassConst): def _user_attributes(self, user_attributes): value = bt2_value.create_value(user_attributes) - utils._check_type(value, bt2_value.MapValue) native_bt.event_class_set_user_attributes(self._ptr, value._ptr) _user_attributes = property(fset=_user_attributes) def _name(self, name): - utils._check_str(name) return native_bt.event_class_set_name(self._ptr, name) _name = property(fset=_name) def _log_level(self, log_level): - log_levels = ( - EventClassLogLevel.EMERGENCY, - EventClassLogLevel.ALERT, - EventClassLogLevel.CRITICAL, - EventClassLogLevel.ERROR, - EventClassLogLevel.WARNING, - EventClassLogLevel.NOTICE, - EventClassLogLevel.INFO, - EventClassLogLevel.DEBUG_SYSTEM, - EventClassLogLevel.DEBUG_PROGRAM, - EventClassLogLevel.DEBUG_PROCESS, - EventClassLogLevel.DEBUG_MODULE, - EventClassLogLevel.DEBUG_UNIT, - EventClassLogLevel.DEBUG_FUNCTION, - EventClassLogLevel.DEBUG_LINE, - EventClassLogLevel.DEBUG, - ) - - if log_level not in log_levels: - raise ValueError("'{}' is not a valid log level".format(log_level)) - native_bt.event_class_set_log_level(self._ptr, log_level) _log_level = property(fset=_log_level) def _emf_uri(self, emf_uri): - utils._check_str(emf_uri) status = native_bt.event_class_set_emf_uri(self._ptr, emf_uri) utils._handle_func_status(status, "cannot set event class object's EMF URI") _emf_uri = property(fset=_emf_uri) def _specific_context_field_class(self, context_field_class): - if context_field_class is not None: - utils._check_type(context_field_class, bt2_field_class._StructureFieldClass) - status = native_bt.event_class_set_specific_context_field_class( - self._ptr, context_field_class._ptr - ) - utils._handle_func_status( - status, "cannot set event class object's context field class" - ) + status = native_bt.event_class_set_specific_context_field_class( + self._ptr, context_field_class._ptr + ) + utils._handle_func_status( + status, "cannot set event class object's context field class" + ) _specific_context_field_class = property(fset=_specific_context_field_class) def _payload_field_class(self, payload_field_class): - if payload_field_class is not None: - utils._check_type(payload_field_class, bt2_field_class._StructureFieldClass) - status = native_bt.event_class_set_payload_field_class( - self._ptr, payload_field_class._ptr + status = native_bt.event_class_set_payload_field_class( + self._ptr, payload_field_class._ptr + ) + utils._handle_func_status( + status, "cannot set event class object's payload field class" + ) + + _payload_field_class = property(fset=_payload_field_class) + + @staticmethod + def _validate_create_params( + name, + user_attributes, + log_level, + emf_uri, + specific_context_field_class, + payload_field_class, + ): + if name is not None: + utils._check_str(name) + + if user_attributes is not None: + value = bt2_value.create_value(user_attributes) + utils._check_type(value, bt2_value.MapValue) + + if log_level is not None: + log_levels = ( + EventClassLogLevel.EMERGENCY, + EventClassLogLevel.ALERT, + EventClassLogLevel.CRITICAL, + EventClassLogLevel.ERROR, + EventClassLogLevel.WARNING, + EventClassLogLevel.NOTICE, + EventClassLogLevel.INFO, + EventClassLogLevel.DEBUG_SYSTEM, + EventClassLogLevel.DEBUG_PROGRAM, + EventClassLogLevel.DEBUG_PROCESS, + EventClassLogLevel.DEBUG_MODULE, + EventClassLogLevel.DEBUG_UNIT, + EventClassLogLevel.DEBUG_FUNCTION, + EventClassLogLevel.DEBUG_LINE, + EventClassLogLevel.DEBUG, ) - utils._handle_func_status( - status, "cannot set event class object's payload field class" + + if log_level not in log_levels: + raise ValueError("'{}' is not a valid log level".format(log_level)) + + if emf_uri is not None: + utils._check_str(emf_uri) + + if specific_context_field_class is not None: + utils._check_type( + specific_context_field_class, bt2_field_class._StructureFieldClass ) - _payload_field_class = property(fset=_payload_field_class) + if payload_field_class is not None: + utils._check_type(payload_field_class, bt2_field_class._StructureFieldClass) _EVENT_CLASS_LOG_LEVEL_TO_OBJ = {