lib: bt_graph_create(): accept MIP version
[babeltrace.git] / src / bindings / python / bt2 / bt2 / graph.py
index aa6b8a74669bb112bee47bbd36e25f1cbca587b0..6c9db7ec96a24b4e97d4b44c993fc2c2a6100514 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
@@ -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')
@@ -84,31 +88,32 @@ class Graph(object._SharedObject):
         component_class,
         name,
         params=None,
+        obj=None,
         logging_level=bt2_logging.LoggingLevel.NONE,
     ):
         if isinstance(component_class, bt2_component._SourceComponentClass):
             cc_ptr = component_class._ptr
-            add_fn = native_bt.graph_add_source_component
+            add_fn = native_bt.bt2_graph_add_source_component
             cc_type = native_bt.COMPONENT_CLASS_TYPE_SOURCE
         elif isinstance(component_class, bt2_component._FilterComponentClass):
             cc_ptr = component_class._ptr
-            add_fn = native_bt.graph_add_filter_component
+            add_fn = native_bt.bt2_graph_add_filter_component
             cc_type = native_bt.COMPONENT_CLASS_TYPE_FILTER
         elif isinstance(component_class, bt2_component._SinkComponentClass):
             cc_ptr = component_class._ptr
-            add_fn = native_bt.graph_add_sink_component
+            add_fn = native_bt.bt2_graph_add_sink_component
             cc_type = native_bt.COMPONENT_CLASS_TYPE_SINK
         elif issubclass(component_class, bt2_component._UserSourceComponent):
             cc_ptr = component_class._bt_cc_ptr
-            add_fn = native_bt.graph_add_source_component
+            add_fn = native_bt.bt2_graph_add_source_component
             cc_type = native_bt.COMPONENT_CLASS_TYPE_SOURCE
         elif issubclass(component_class, bt2_component._UserSinkComponent):
             cc_ptr = component_class._bt_cc_ptr
-            add_fn = native_bt.graph_add_sink_component
+            add_fn = native_bt.bt2_graph_add_sink_component
             cc_type = native_bt.COMPONENT_CLASS_TYPE_SINK
         elif issubclass(component_class, bt2_component._UserFilterComponent):
             cc_ptr = component_class._bt_cc_ptr
-            add_fn = native_bt.graph_add_filter_component
+            add_fn = native_bt.bt2_graph_add_filter_component
             cc_type = native_bt.COMPONENT_CLASS_TYPE_FILTER
         else:
             raise TypeError(
@@ -119,11 +124,17 @@ class Graph(object._SharedObject):
 
         utils._check_str(name)
         utils._check_log_level(logging_level)
-        params = bt2.create_value(params)
+        base_cc_ptr = component_class._bt_component_class_ptr()
 
+        if obj is not None and not native_bt.bt2_is_python_component_class(base_cc_ptr):
+            raise ValueError('cannot pass a Python object to a non-Python component')
+
+        params = bt2.create_value(params)
         params_ptr = params._ptr if params is not None else None
 
-        status, comp_ptr = add_fn(self._ptr, cc_ptr, name, params_ptr, logging_level)
+        status, comp_ptr = add_fn(
+            self._ptr, cc_ptr, name, params_ptr, obj, logging_level
+        )
         utils._handle_func_status(status, 'cannot add component to graph')
         assert comp_ptr
         return bt2_component._create_component_from_ptr(comp_ptr, cc_type)
@@ -168,6 +179,10 @@ class Graph(object._SharedObject):
 
         return utils._ListenerHandle(listener_ids, self)
 
+    def run_once(self):
+        status = native_bt.graph_run_once(self._ptr)
+        utils._handle_func_status(status, 'graph object could not run once')
+
     def run(self):
         status = native_bt.graph_run(self._ptr)
 
@@ -185,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.025201 seconds and 4 git commands to generate.