bt2: Add `Const` suffix to non-user component-related classes and adapt tests
[babeltrace.git] / src / bindings / python / bt2 / bt2 / graph.py
index 6c75d52b843d1de01911b07632bc7d2e849971bb..82708025c19032b91c72b063d977567b95ca4995 100644 (file)
@@ -24,7 +24,6 @@ from bt2 import native_bt, object, utils
 from bt2 import interrupter as bt2_interrupter
 from bt2 import connection as bt2_connection
 from bt2 import component as bt2_component
-from bt2 import message_iterator as bt2_message_iterator
 import functools
 from bt2 import port as bt2_port
 from bt2 import logging as bt2_logging
@@ -34,10 +33,10 @@ import bt2
 def _graph_port_added_listener_from_native(
     user_listener, component_ptr, component_type, port_ptr, port_type
 ):
-    component = bt2_component._create_component_from_ptr_and_get_ref(
+    component = bt2_component._create_component_from_const_ptr_and_get_ref(
         component_ptr, component_type
     )
-    port = bt2_port._create_from_ptr_and_get_ref(port_ptr, port_type)
+    port = bt2_port._create_from_const_ptr_and_get_ref(port_ptr, port_type)
     user_listener(component, port)
 
 
@@ -50,16 +49,16 @@ def _graph_ports_connected_listener_from_native(
     downstream_component_type,
     downstream_port_ptr,
 ):
-    upstream_component = bt2_component._create_component_from_ptr_and_get_ref(
+    upstream_component = bt2_component._create_component_from_const_ptr_and_get_ref(
         upstream_component_ptr, upstream_component_type
     )
-    upstream_port = bt2_port._create_from_ptr_and_get_ref(
+    upstream_port = bt2_port._create_from_const_ptr_and_get_ref(
         upstream_port_ptr, native_bt.PORT_TYPE_OUTPUT
     )
-    downstream_component = bt2_component._create_component_from_ptr_and_get_ref(
+    downstream_component = bt2_component._create_component_from_const_ptr_and_get_ref(
         downstream_component_ptr, downstream_component_type
     )
-    downstream_port = bt2_port._create_from_ptr_and_get_ref(
+    downstream_port = bt2_port._create_from_const_ptr_and_get_ref(
         downstream_port_ptr, native_bt.PORT_TYPE_INPUT
     )
     user_listener(
@@ -71,8 +70,13 @@ class Graph(object._SharedObject):
     _get_ref = staticmethod(native_bt.graph_get_ref)
     _put_ref = staticmethod(native_bt.graph_put_ref)
 
-    def __init__(self):
-        ptr = native_bt.graph_create()
+    def __init__(self, mip_version=0):
+        utils._check_uint64(mip_version)
+
+        if mip_version > bt2.get_maximal_mip_version():
+            raise ValueError('unknown MIP version {}'.format(mip_version))
+
+        ptr = native_bt.graph_create(mip_version)
 
         if ptr is None:
             raise bt2._MemoryError('cannot create graph object')
@@ -87,15 +91,15 @@ class Graph(object._SharedObject):
         obj=None,
         logging_level=bt2_logging.LoggingLevel.NONE,
     ):
-        if isinstance(component_class, bt2_component._SourceComponentClass):
+        if isinstance(component_class, bt2_component._SourceComponentClassConst):
             cc_ptr = component_class._ptr
             add_fn = native_bt.bt2_graph_add_source_component
             cc_type = native_bt.COMPONENT_CLASS_TYPE_SOURCE
-        elif isinstance(component_class, bt2_component._FilterComponentClass):
+        elif isinstance(component_class, bt2_component._FilterComponentClassConst):
             cc_ptr = component_class._ptr
             add_fn = native_bt.bt2_graph_add_filter_component
             cc_type = native_bt.COMPONENT_CLASS_TYPE_FILTER
-        elif isinstance(component_class, bt2_component._SinkComponentClass):
+        elif isinstance(component_class, bt2_component._SinkComponentClassConst):
             cc_ptr = component_class._ptr
             add_fn = native_bt.bt2_graph_add_sink_component
             cc_type = native_bt.COMPONENT_CLASS_TYPE_SINK
@@ -133,17 +137,17 @@ class Graph(object._SharedObject):
         )
         utils._handle_func_status(status, 'cannot add component to graph')
         assert comp_ptr
-        return bt2_component._create_component_from_ptr(comp_ptr, cc_type)
+        return bt2_component._create_component_from_const_ptr(comp_ptr, cc_type)
 
     def connect_ports(self, upstream_port, downstream_port):
-        utils._check_type(upstream_port, bt2_port._OutputPort)
-        utils._check_type(downstream_port, bt2_port._InputPort)
+        utils._check_type(upstream_port, bt2_port._OutputPortConst)
+        utils._check_type(downstream_port, bt2_port._InputPortConst)
         status, conn_ptr = native_bt.graph_connect_ports(
             self._ptr, upstream_port._ptr, downstream_port._ptr
         )
         utils._handle_func_status(status, 'cannot connect component ports within graph')
         assert conn_ptr
-        return bt2_connection._Connection._create_from_ptr(conn_ptr)
+        return bt2_connection._ConnectionConst._create_from_ptr(conn_ptr)
 
     def add_port_added_listener(self, listener):
         if not callable(listener):
@@ -196,14 +200,3 @@ class Graph(object._SharedObject):
 
     def interrupt(self):
         native_bt.graph_interrupt(self._ptr)
-
-    def create_output_port_message_iterator(self, output_port):
-        utils._check_type(output_port, bt2_port._OutputPort)
-        msg_iter_ptr = native_bt.port_output_message_iterator_create(
-            self._ptr, output_port._ptr
-        )
-
-        if msg_iter_ptr is None:
-            raise bt2._MemoryError('cannot create output port message iterator')
-
-        return bt2_message_iterator._OutputPortMessageIterator(msg_iter_ptr)
This page took 0.024328 seconds and 4 git commands to generate.