X-Git-Url: https://git.efficios.com/?a=blobdiff_plain;f=src%2Fbindings%2Fpython%2Fbt2%2Fbt2%2Fevent_class.py;h=e55e3019409330fe40f4b44085e2febcd7a3ac03;hb=88cf534320b30567b480d6b434b83a1db015ca7e;hp=dfef62137f3315e10b195d73e87a1455256b1c3e;hpb=c946c9de02e1a5a37945cb98bd0e499033336c55;p=babeltrace.git diff --git a/src/bindings/python/bt2/bt2/event_class.py b/src/bindings/python/bt2/bt2/event_class.py index dfef6213..e55e3019 100644 --- a/src/bindings/python/bt2/bt2/event_class.py +++ b/src/bindings/python/bt2/bt2/event_class.py @@ -23,9 +23,12 @@ from bt2 import native_bt, object, utils from bt2 import field_class as bt2_field_class from bt2 import value as bt2_value -from bt2 import event as bt2_event -from bt2 import stream_class as bt2_stream_class -import bt2 + + +def _bt2_stream_class(): + from bt2 import stream_class as bt2_stream_class + + return bt2_stream_class class EventClassLogLevel: @@ -46,27 +49,46 @@ class EventClassLogLevel: DEBUG = native_bt.EVENT_CLASS_LOG_LEVEL_DEBUG -class _EventClass(object._SharedObject): +class _EventClassConst(object._SharedObject): _get_ref = staticmethod(native_bt.event_class_get_ref) _put_ref = staticmethod(native_bt.event_class_put_ref) + _borrow_stream_class_ptr = staticmethod( + native_bt.event_class_borrow_stream_class_const + ) + _borrow_specific_context_field_class_ptr = staticmethod( + native_bt.event_class_borrow_specific_context_field_class_const + ) + _borrow_payload_field_class_ptr = staticmethod( + native_bt.event_class_borrow_payload_field_class_const + ) + _borrow_user_attributes_ptr = staticmethod( + native_bt.event_class_borrow_user_attributes_const + ) + _create_field_class_from_ptr_and_get_ref = staticmethod( + bt2_field_class._create_field_class_from_const_ptr_and_get_ref + ) + _create_value_from_ptr_and_get_ref = staticmethod( + bt2_value._create_from_const_ptr_and_get_ref + ) + _stream_class_pycls = property(lambda s: _bt2_stream_class()._StreamClassConst) @property def stream_class(self): - sc_ptr = native_bt.event_class_borrow_stream_class(self._ptr) + sc_ptr = self._borrow_stream_class_ptr(self._ptr) if sc_ptr is not None: - return bt2_stream_class._StreamClass._create_from_ptr_and_get_ref(sc_ptr) + return self._stream_class_pycls._create_from_ptr_and_get_ref(sc_ptr) + + @property + def user_attributes(self): + ptr = self._borrow_user_attributes_ptr(self._ptr) + assert ptr is not None + return self._create_value_from_ptr_and_get_ref(ptr) @property def name(self): return native_bt.event_class_get_name(self._ptr) - def _name(self, name): - utils._check_str(name) - return native_bt.event_class_set_name(self._ptr, name) - - _name = property(fset=_name) - @property def id(self): id = native_bt.event_class_get_id(self._ptr) @@ -81,86 +103,138 @@ class _EventClass(object._SharedObject): return _EVENT_CLASS_LOG_LEVEL_TO_OBJ[log_level] - 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, - ) + @property + def emf_uri(self): + return native_bt.event_class_get_emf_uri(self._ptr) - if log_level not in log_levels: - raise ValueError("'{}' is not a valid log level".format(log_level)) + @property + def specific_context_field_class(self): + fc_ptr = self._borrow_specific_context_field_class_ptr(self._ptr) - native_bt.event_class_set_log_level(self._ptr, log_level) + if fc_ptr is None: + return - _log_level = property(fset=_log_level) + return self._create_field_class_from_ptr_and_get_ref(fc_ptr) @property - def emf_uri(self): - return native_bt.event_class_get_emf_uri(self._ptr) + def payload_field_class(self): + fc_ptr = self._borrow_payload_field_class_ptr(self._ptr) + + if fc_ptr is None: + return + + return self._create_field_class_from_ptr_and_get_ref(fc_ptr) + + +class _EventClass(_EventClassConst): + _borrow_stream_class_ptr = staticmethod(native_bt.event_class_borrow_stream_class) + _borrow_specific_context_field_class_ptr = staticmethod( + native_bt.event_class_borrow_specific_context_field_class + ) + _borrow_payload_field_class_ptr = staticmethod( + native_bt.event_class_borrow_payload_field_class + ) + _borrow_user_attributes_ptr = staticmethod( + native_bt.event_class_borrow_user_attributes + ) + _create_field_class_from_ptr_and_get_ref = staticmethod( + bt2_field_class._create_field_class_from_ptr_and_get_ref + ) + _create_value_from_ptr_and_get_ref = staticmethod( + bt2_value._create_from_ptr_and_get_ref + ) + _stream_class_pycls = property(lambda s: _bt2_stream_class()._StreamClass) + + def _user_attributes(self, user_attributes): + value = bt2_value.create_value(user_attributes) + native_bt.event_class_set_user_attributes(self._ptr, value._ptr) + + _user_attributes = property(fset=_user_attributes) + + def _name(self, name): + return native_bt.event_class_set_name(self._ptr, name) + + _name = property(fset=_name) + + def _log_level(self, 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) - @property - def specific_context_field_class(self): - fc_ptr = native_bt.event_class_borrow_specific_context_field_class_const( - self._ptr + def _specific_context_field_class(self, 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" ) - if fc_ptr is None: - return + _specific_context_field_class = property(fset=_specific_context_field_class) + + def _payload_field_class(self, payload_field_class): + 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" + ) - return bt2_field_class._create_field_class_from_ptr_and_get_ref(fc_ptr) + _payload_field_class = property(fset=_payload_field_class) - 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" + @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, ) - _specific_context_field_class = property(fset=_specific_context_field_class) - - @property - def payload_field_class(self): - fc_ptr = native_bt.event_class_borrow_payload_field_class_const(self._ptr) + if log_level not in log_levels: + raise ValueError("'{}' is not a valid log level".format(log_level)) - if fc_ptr is None: - return + if emf_uri is not None: + utils._check_str(emf_uri) - return bt2_field_class._create_field_class_from_ptr_and_get_ref(fc_ptr) + if specific_context_field_class is not None: + utils._check_type( + specific_context_field_class, bt2_field_class._StructureFieldClass + ) - 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 - ) - utils._handle_func_status( - status, "cannot set event class object's payload field class" - ) - - _payload_field_class = property(fset=_payload_field_class) _EVENT_CLASS_LOG_LEVEL_TO_OBJ = {