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>
Fri, 12 Apr 2019 21:25:05 +0000 (17:25 -0400)
commit1f40c0ec132290762af6842e3f59d10827c38f10
tree984ee97b5f7646eba3e26e87f2b32c71a86db695
parent0d6f8bf6e0b33c258df29b21accef9aaf1c9e499
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.03167 seconds and 5 git commands to generate.