lib: remove output port message iterator
[babeltrace.git] / src / bindings / python / bt2 / bt2 / component.py
index d26adc8f8b06081e63bf1251d4722af325426163..8052e8a4b0c5ac35af07dbd32387d75f9ec870fe 100644 (file)
@@ -484,9 +484,9 @@ class _UserComponentType(type):
                 cls, comp_cls_name, comp_cls_descr, comp_cls_help
             )
         elif _UserSinkComponent in bases:
-            if not hasattr(cls, '_consume'):
+            if not hasattr(cls, '_user_consume'):
                 raise bt2._IncompleteUserClass(
-                    "cannot create component class '{}': missing a _consume() method".format(
+                    "cannot create component class '{}': missing a _user_consume() method".format(
                         class_name
                     )
                 )
@@ -508,7 +508,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 +521,7 @@ class _UserComponentType(type):
         else:
             params = None
 
-        self.__init__(params)
+        self.__init__(params, obj)
         return self
 
     def __call__(cls, *args, **kwargs):
@@ -573,7 +573,7 @@ class _UserComponentType(type):
     def addr(cls):
         return int(cls._bt_cc_ptr)
 
-    def _bt_query_from_native(cls, query_exec_ptr, obj, params_ptr, log_level):
+    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
         if params_ptr is not None:
@@ -581,12 +581,19 @@ class _UserComponentType(type):
         else:
             params = None
 
-        query_exec = bt2_query_executor.QueryExecutor._create_from_ptr_and_get_ref(
-            query_exec_ptr
-        )
+        priv_query_exec = bt2_query_executor._PrivateQueryExecutor(priv_query_exec_ptr)
 
-        # this can raise, but the native side checks the exception
-        results = cls._query(query_exec, obj, params, log_level)
+        try:
+            # this can raise, but the native side checks the exception
+            results = cls._user_query(priv_query_exec, obj, params)
+        finally:
+            # the private query executor is a private view on the query
+            # executor; it's not a shared object (the library does not
+            # offer an API to get/put a reference, just like "self"
+            # objects) from this query's point of view, so invalidate
+            # the object in case the user kept a reference and uses it
+            # later
+            priv_query_exec._invalidate()
 
         # this can raise, but the native side checks the exception
         results = bt2.create_value(results)
@@ -594,16 +601,14 @@ class _UserComponentType(type):
         if results is None:
             results_ptr = native_bt.value_null
         else:
-            # return new reference
             results_ptr = results._ptr
 
-        # We return a new reference.
+        # return new reference
         bt2_value._Value._get_ref(results_ptr)
-
         return int(results_ptr)
 
-    def _query(cls, query_executor, obj, params, log_level):
-        raise NotImplementedError
+    def _user_query(cls, priv_query_executor, obj, params):
+        raise bt2.UnknownObject
 
     def _bt_component_class_ptr(self):
         return self._bt_as_component_class_ptr(self._bt_cc_ptr)
@@ -612,6 +617,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:
@@ -653,13 +659,13 @@ class _UserComponent(metaclass=_UserComponentType):
     def addr(self):
         return int(self._bt_ptr)
 
-    def __init__(self, params=None):
+    def __init__(self, params=None, obj=None):
         pass
 
-    def _finalize(self):
+    def _user_finalize(self):
         pass
 
-    def _port_connected(self, port, other_port):
+    def _user_port_connected(self, port, other_port):
         pass
 
     def _bt_port_connected_from_native(
@@ -675,7 +681,7 @@ class _UserComponent(metaclass=_UserComponentType):
         other_port = bt2_port._create_from_ptr_and_get_ref(
             other_port_ptr, other_port_type
         )
-        self._port_connected(port, other_port)
+        self._user_port_connected(port, other_port)
 
     def _create_trace_class(self, assigns_automatic_stream_class_id=True):
         ptr = self._bt_as_self_component_ptr(self._bt_ptr)
@@ -829,9 +835,9 @@ class _UserSinkComponent(_UserComponent, _SinkComponent):
     )
 
     def _bt_graph_is_configured_from_native(self):
-        self._graph_is_configured()
+        self._user_graph_is_configured()
 
-    def _graph_is_configured(self):
+    def _user_graph_is_configured(self):
         pass
 
     @property
This page took 0.027547 seconds and 4 git commands to generate.