lib: make the "port connected" method return a status
authorPhilippe Proulx <eeppeliteloop@gmail.com>
Tue, 26 Jun 2018 17:48:36 +0000 (13:48 -0400)
committerPhilippe Proulx <eeppeliteloop@gmail.com>
Thu, 2 May 2019 04:05:45 +0000 (00:05 -0400)
commitbf55043c2e742cafb86d3a3404d0d35c4cf294a3
treed4b51985825b3d91a1db9dc230122f9239f2e516
parentd4393e0875e7b08f6ee97d617cc5f2c9286742a4
lib: make the "port connected" method return a status

Even if both components accept a port connection with their "accept port
connection" methods, an error-triggering task can still be performed
during the "port connected" method's execution, in which case the whole
component could be considered unusable, or at least this connection
cannot exist. The typical case is that the "port connected" method tries
to create a private connection notification iterator using the new
connection and this can fail for many reasons.

Without the "port connected" method returning a status code, the
mechanism to signal an error is to set an error flag on the component's
private data and check this flag at every "consume" or "next" method
call. This is inefficient when the "port connected" method can simply
return an error status.

The connection order in bt_graph_connect_ports() is to call the
upstream component's "port connected" method and then the downstream
component's.

* If the upstream component's method does not return
  `BT_COMPONENT_STATUS_OK`, then the connection is ended and
  bt_graph_connect_ports() returns an error. The graph creator's "ports
  connected" listener is not called.

* If the downstream component's method does not return
  `BT_COMPONENT_STATUS_OK`, then the connection is ended, notifying the
  upstream component that its previously connected port is now
  disconnected, and bt_graph_connect_ports() returns an error. The graph
  creator's "ports connected" listener is not called.

This patch adds new tests to `test_graph_topo.c` to make sure the
appropriate methods/listeners are called or not, and in which order,
when either the upstream or downstream component's "port connected"
method returns an error status.

Signed-off-by: Philippe Proulx <eeppeliteloop@gmail.com>
18 files changed:
include/babeltrace/graph/component-class.h
include/babeltrace/graph/component-internal.h
include/babeltrace/graph/connection-internal.h
lib/graph/component-class-sink-colander.c
lib/graph/component.c
lib/graph/connection.c
lib/graph/graph.c
plugins/text/pretty/pretty.c
plugins/text/pretty/pretty.h
plugins/utils/counter/counter.c
plugins/utils/counter/counter.h
plugins/utils/dummy/dummy.c
plugins/utils/dummy/dummy.h
plugins/utils/muxer/muxer.c
plugins/utils/muxer/muxer.h
tests/lib/test_bt_notification_iterator.c
tests/lib/test_graph_topo.c
tests/plugins/test-utils-muxer.c
This page took 0.026103 seconds and 4 git commands to generate.