bt2: rename `object` parameter -> `object_name`
[babeltrace.git] / src / bindings / python / bt2 / bt2 / component.py
index a14b78e78e12bbb57eef3f1cfe5b58ea3adf9ab4..9ccd64528d0dc95c96b434c553a2ab575b669a21 100644 (file)
@@ -510,6 +510,9 @@ class _UserComponentType(type):
         # create instance, not user-initialized yet
         self = cls.__new__(cls)
 
+        # config object
+        config = cls._config_pycls()
+
         # pointer to native self component object (weak/borrowed)
         self._bt_ptr = comp_ptr
 
@@ -519,7 +522,7 @@ class _UserComponentType(type):
         else:
             params = None
 
-        self.__init__(params, obj)
+        self.__init__(config, params, obj)
         return self
 
     def __call__(cls, *args, **kwargs):
@@ -550,6 +553,24 @@ class _UserComponentType(type):
                 )
             )
 
+        if hasattr(iter_cls, '_user_can_seek_ns_from_origin') and not hasattr(
+            iter_cls, '_user_seek_ns_from_origin'
+        ):
+            raise bt2._IncompleteUserClass(
+                "cannot create component class '{}': message iterator class implements _user_can_seek_ns_from_origin but not _user_seek_ns_from_origin".format(
+                    cls.__name__
+                )
+            )
+
+        if hasattr(iter_cls, '_user_can_seek_beginning') and not hasattr(
+            iter_cls, '_user_seek_beginning'
+        ):
+            raise bt2._IncompleteUserClass(
+                "cannot create component class '{}': message iterator class implements _user_can_seek_beginning but not _user_seek_beginning".format(
+                    cls.__name__
+                )
+            )
+
         cls._iter_cls = iter_cls
 
     @property
@@ -592,7 +613,9 @@ class _UserComponentType(type):
     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):
+    def _bt_query_from_native(
+        cls, priv_query_exec_ptr, object_name, 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_const_ptr_and_get_ref(params_ptr)
@@ -603,7 +626,7 @@ class _UserComponentType(type):
 
         try:
             # this can raise, but the native side checks the exception
-            results = cls._user_query(priv_query_exec, object, params, method_obj)
+            results = cls._user_query(priv_query_exec, object_name, 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
@@ -625,7 +648,7 @@ class _UserComponentType(type):
         bt2_value._Value._get_ref(results_ptr)
         return int(results_ptr)
 
-    def _user_query(cls, priv_query_executor, object, params, method_obj):
+    def _user_query(cls, priv_query_executor, object_name, params, method_obj):
         raise bt2.UnknownObject
 
     def _bt_component_class_ptr(self):
@@ -638,6 +661,29 @@ class _UserComponentType(type):
             native_bt.bt2_unregister_cc_ptr_to_py_cls(cc_ptr)
 
 
+# Configuration objects for components.
+#
+# These are passed in __init__ to allow components to change some configuration
+# parameters during initialization and not after. As you can see, they are not
+# used at the moment, but are there in case we want to add such parameters.
+
+
+class _UserComponentConfiguration:
+    pass
+
+
+class _UserSourceComponentConfiguration(_UserComponentConfiguration):
+    pass
+
+
+class _UserFilterComponentConfiguration(_UserComponentConfiguration):
+    pass
+
+
+class _UserSinkComponentConfiguration(_UserComponentConfiguration):
+    pass
+
+
 # Subclasses must provide these methods or property:
 #
 #   - _bt_as_not_self_specific_component_ptr: static method, must return the passed
@@ -682,7 +728,7 @@ class _UserComponent(metaclass=_UserComponentType):
         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):
+    def __init__(self, config, params, obj):
         pass
 
     def _user_finalize(self):
@@ -775,6 +821,7 @@ class _UserSourceComponent(_UserComponent, _SourceComponentConst):
     _bt_as_self_component_ptr = staticmethod(
         native_bt.self_component_source_as_self_component
     )
+    _config_pycls = _UserSourceComponentConfiguration
 
     @property
     def _output_ports(self):
@@ -808,6 +855,7 @@ class _UserFilterComponent(_UserComponent, _FilterComponentConst):
     _bt_as_self_component_ptr = staticmethod(
         native_bt.self_component_filter_as_self_component
     )
+    _config_pycls = _UserFilterComponentConfiguration
 
     @property
     def _output_ports(self):
@@ -865,6 +913,7 @@ class _UserSinkComponent(_UserComponent, _SinkComponentConst):
     _bt_as_self_component_ptr = staticmethod(
         native_bt.self_component_sink_as_self_component
     )
+    _config_pycls = _UserSinkComponentConfiguration
 
     def _bt_graph_is_configured_from_native(self):
         self._user_graph_is_configured()
@@ -899,7 +948,10 @@ class _UserSinkComponent(_UserComponent, _SinkComponentConst):
     def _create_input_port_message_iterator(self, input_port):
         utils._check_type(input_port, bt2_port._UserComponentInputPort)
 
-        status, msg_iter_ptr = native_bt.bt2_self_component_port_input_message_iterator_create_from_sink_component(
+        (
+            status,
+            msg_iter_ptr,
+        ) = native_bt.bt2_self_component_port_input_message_iterator_create_from_sink_component(
             self._bt_ptr, input_port._ptr
         )
         utils._handle_func_status(status, 'cannot create message iterator object')
This page took 0.027666 seconds and 4 git commands to generate.