X-Git-Url: http://git.efficios.com/?a=blobdiff_plain;f=src%2Fbindings%2Fpython%2Fbt2%2Fbt2%2Fcomponent.py;h=a0d29e272f43d5286cad50f47ff400c68eb33a2f;hb=5783664e46332216fd38a7b287258a7c9543af57;hp=a057019aa379c37cb7af3f471b2fe46cb070a146;hpb=3c729b9af1b926f739be5bbba4ec20a296746023;p=babeltrace.git diff --git a/src/bindings/python/bt2/bt2/component.py b/src/bindings/python/bt2/bt2/component.py index a057019a..a0d29e27 100644 --- a/src/bindings/python/bt2/bt2/component.py +++ b/src/bindings/python/bt2/bt2/component.py @@ -27,11 +27,9 @@ from bt2 import value as bt2_value from bt2 import trace_class as bt2_trace_class from bt2 import clock_class as bt2_clock_class from bt2 import query_executor as bt2_query_executor -import traceback from bt2 import port as bt2_port import sys import bt2 -import os # This class wraps a component class pointer. This component class could @@ -508,7 +506,7 @@ class _UserComponentType(type): cls._bt_cc_ptr = cc_ptr - def _bt_init_from_native(cls, comp_ptr, params_ptr): + def _bt_init_from_native(cls, comp_ptr, params_ptr, obj): # create instance, not user-initialized yet self = cls.__new__(cls) @@ -521,7 +519,7 @@ class _UserComponentType(type): else: params = None - self.__init__(params) + self.__init__(params, obj) return self def __call__(cls, *args, **kwargs): @@ -573,9 +571,29 @@ class _UserComponentType(type): def addr(cls): return int(cls._bt_cc_ptr) - def _bt_query_from_native(cls, priv_query_exec_ptr, obj, params_ptr): - # this can raise, in which case the native call to - # bt_component_class_query() returns NULL + def _bt_get_supported_mip_versions_from_native(cls, params_ptr, obj, log_level): + # this can raise, but the native side checks the exception + if params_ptr is not None: + params = bt2_value._create_from_ptr_and_get_ref(params_ptr) + else: + params = None + + # this can raise, but the native side checks the exception + range_set = cls._user_get_supported_mip_versions(params, obj, log_level) + + if type(range_set) is not bt2.UnsignedIntegerRangeSet: + # this can raise, but the native side checks the exception + range_set = bt2.UnsignedIntegerRangeSet(range_set) + + # return new reference + range_set._get_ref(range_set._ptr) + return int(range_set._ptr) + + def _user_get_supported_mip_versions(cls, params, obj, log_level): + return [0] + + def _bt_query_from_native(cls, priv_query_exec_ptr, object, params_ptr, method_obj): + # this can raise, but the native side checks the exception if params_ptr is not None: params = bt2_value._create_from_ptr_and_get_ref(params_ptr) else: @@ -585,7 +603,7 @@ class _UserComponentType(type): try: # this can raise, but the native side checks the exception - results = cls._user_query(priv_query_exec, obj, params) + results = cls._user_query(priv_query_exec, object, params, method_obj) finally: # the private query executor is a private view on the query # executor; it's not a shared object (the library does not @@ -607,7 +625,7 @@ class _UserComponentType(type): bt2_value._Value._get_ref(results_ptr) return int(results_ptr) - def _user_query(cls, priv_query_executor, obj, params): + def _user_query(cls, priv_query_executor, object, params, method_obj): raise bt2.UnknownObject def _bt_component_class_ptr(self): @@ -617,6 +635,7 @@ class _UserComponentType(type): if hasattr(cls, '_bt_cc_ptr'): cc_ptr = cls._bt_as_component_class_ptr(cls._bt_cc_ptr) native_bt.component_class_put_ref(cc_ptr) + native_bt.bt2_unregister_cc_ptr_to_py_cls(cc_ptr) # Subclasses must provide these methods or property: @@ -658,7 +677,12 @@ class _UserComponent(metaclass=_UserComponentType): def addr(self): return int(self._bt_ptr) - def __init__(self, params=None): + @property + def _graph_mip_version(self): + ptr = self._bt_as_self_component_ptr(self._bt_ptr) + return native_bt.self_component_get_graph_mip_version(ptr) + + def __init__(self, params=None, obj=None): pass def _user_finalize(self): @@ -682,7 +706,9 @@ class _UserComponent(metaclass=_UserComponentType): ) self._user_port_connected(port, other_port) - def _create_trace_class(self, assigns_automatic_stream_class_id=True): + def _create_trace_class( + self, user_attributes=None, assigns_automatic_stream_class_id=True + ): ptr = self._bt_as_self_component_ptr(self._bt_ptr) tc_ptr = native_bt.trace_class_create(ptr) @@ -692,12 +718,16 @@ class _UserComponent(metaclass=_UserComponentType): tc = bt2_trace_class._TraceClass._create_from_ptr(tc_ptr) tc._assigns_automatic_stream_class_id = assigns_automatic_stream_class_id + if user_attributes is not None: + tc._user_attributes = user_attributes + return tc def _create_clock_class( self, frequency=None, name=None, + user_attributes=None, description=None, precision=None, offset=None, @@ -718,6 +748,9 @@ class _UserComponent(metaclass=_UserComponentType): if name is not None: cc._name = name + if user_attributes is not None: + cc._user_attributes = user_attributes + if description is not None: cc._description = description @@ -871,7 +904,7 @@ class _UserSinkComponent(_UserComponent, _SinkComponent): ) if msg_iter_ptr is None: - raise bt2.CreationError('cannot create message iterator object') + raise bt2._MemoryError('cannot create message iterator object') return bt2_message_iterator._UserComponentInputPortMessageIterator(msg_iter_ptr)