X-Git-Url: http://git.efficios.com/?a=blobdiff_plain;f=src%2Fbindings%2Fpython%2Fbt2%2Fbt2%2Fgraph.py;h=9e30c18f2645ccd45a9d4cf8e975402ffb4acf9a;hb=85906b6b4c37140f8bdd4a6861ecbc82fc62f816;hp=998d310b3b268ea8d6640b5a6a06fe2180ee7a52;hpb=578e048b5debf169e286e5b5cc747b5d6c16886d;p=babeltrace.git diff --git a/src/bindings/python/bt2/bt2/graph.py b/src/bindings/python/bt2/bt2/graph.py index 998d310b..9e30c18f 100644 --- a/src/bindings/python/bt2/bt2/graph.py +++ b/src/bindings/python/bt2/bt2/graph.py @@ -25,6 +25,7 @@ import bt2.connection import bt2.component import functools import bt2.port +import bt2.logging import bt2 @@ -64,19 +65,9 @@ class Graph(object._SharedObject): super().__init__(ptr) - def _handle_status(self, status, gen_error_msg): - if status == native_bt.GRAPH_STATUS_COMPONENT_REFUSES_PORT_CONNECTION: - raise bt2.PortConnectionRefused - elif status == native_bt.GRAPH_STATUS_CANCELED: - raise bt2.GraphCanceled - elif status == native_bt.GRAPH_STATUS_END: - raise bt2.Stop - elif status == native_bt.GRAPH_STATUS_AGAIN: - raise bt2.TryAgain - elif status < 0: - raise bt2.Error(gen_error_msg) - - def add_component(self, component_class, name, params=None): + + def add_component(self, component_class, name, params=None, + logging_level=bt2.logging.LoggingLevel.NONE): if isinstance(component_class, bt2.component._GenericSourceComponentClass): cc_ptr = component_class._ptr add_fn = native_bt.graph_add_source_component @@ -90,15 +81,15 @@ class Graph(object._SharedObject): add_fn = native_bt.graph_add_sink_component cc_type = native_bt.COMPONENT_CLASS_TYPE_SINK elif issubclass(component_class, bt2.component._UserSourceComponent): - cc_ptr = component_class._cc_ptr + cc_ptr = component_class._bt_cc_ptr add_fn = native_bt.graph_add_source_component cc_type = native_bt.COMPONENT_CLASS_TYPE_SOURCE elif issubclass(component_class, bt2.component._UserSinkComponent): - cc_ptr = component_class._cc_ptr + cc_ptr = component_class._bt_cc_ptr add_fn = native_bt.graph_add_sink_component cc_type = native_bt.COMPONENT_CLASS_TYPE_SINK elif issubclass(component_class, bt2.component._UserFilterComponent): - cc_ptr = component_class._cc_ptr + cc_ptr = component_class._bt_cc_ptr add_fn = native_bt.graph_add_filter_component cc_type = native_bt.COMPONENT_CLASS_TYPE_FILTER else: @@ -106,12 +97,14 @@ class Graph(object._SharedObject): component_class.__class__.__name__)) utils._check_str(name) + utils._check_log_level(logging_level) 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) - self._handle_status(status, 'cannot add component to graph') + status, comp_ptr = add_fn(self._ptr, cc_ptr, name, + params_ptr, 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) @@ -121,7 +114,8 @@ class Graph(object._SharedObject): status, conn_ptr = native_bt.graph_connect_ports(self._ptr, upstream_port._ptr, downstream_port._ptr) - self._handle_status(status, 'cannot connect component ports within graph') + utils._handle_func_status(status, + 'cannot connect component ports within graph') assert(conn_ptr) return bt2.connection._Connection._create_from_ptr(conn_ptr) @@ -129,7 +123,7 @@ class Graph(object._SharedObject): if not callable(listener): raise TypeError("'listener' parameter is not callable") - fn = native_bt.py3_graph_add_port_added_listener + fn = native_bt.bt2_graph_add_port_added_listener listener_from_native = functools.partial(_graph_port_added_listener_from_native, listener) @@ -142,7 +136,7 @@ class Graph(object._SharedObject): if not callable(listener): raise TypeError("'listener' parameter is not callable") - fn = native_bt.py3_graph_add_ports_connected_listener + fn = native_bt.bt2_graph_add_ports_connected_listener listener_from_native = functools.partial(_graph_ports_connected_listener_from_native, listener) @@ -154,14 +148,18 @@ class Graph(object._SharedObject): def run(self): status = native_bt.graph_run(self._ptr) - if status == native_bt.GRAPH_STATUS_END: + try: + utils._handle_func_status(status, + 'graph object stopped running because of an unexpected error') + except bt2.Stop: + # done return - - self._handle_status(status, 'graph object stopped running because of an unexpected error') + except Exception: + raise def cancel(self): status = native_bt.graph_cancel(self._ptr) - self._handle_status(status, 'cannot cancel graph object') + utils._handle_func_status(status, 'cannot cancel graph object') @property def is_canceled(self):