2 * Copyright 2017 Philippe Proulx <pproulx@efficios.com>
4 * Permission is hereby granted, free of charge, to any person obtaining a copy
5 * of this software and associated documentation files (the "Software"), to deal
6 * in the Software without restriction, including without limitation the rights
7 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8 * copies of the Software, and to permit persons to whom the Software is
9 * furnished to do so, subject to the following conditions:
11 * The above copyright notice and this permission notice shall be included in
12 * all copies or substantial portions of the Software.
14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
23 #include <babeltrace/babeltrace-internal.h>
24 #include <babeltrace/ctf-ir/clock-class.h>
25 #include <babeltrace/ctf-ir/event.h>
26 #include <babeltrace/graph/clock-class-priority-map.h>
27 #include <babeltrace/graph/component-filter.h>
28 #include <babeltrace/graph/component.h>
29 #include <babeltrace/graph/notification-event.h>
30 #include <babeltrace/graph/notification-inactivity.h>
31 #include <babeltrace/graph/notification-iterator.h>
32 #include <babeltrace/graph/notification.h>
33 #include <babeltrace/graph/port.h>
34 #include <babeltrace/graph/private-component-filter.h>
35 #include <babeltrace/graph/private-component.h>
36 #include <babeltrace/graph/private-component.h>
37 #include <babeltrace/graph/private-connection.h>
38 #include <babeltrace/graph/private-notification-iterator.h>
39 #include <babeltrace/graph/private-port.h>
40 #include <plugins-common.h>
45 /* Array of struct bt_private_notification_iterator * (weak refs) */
46 GPtrArray
*muxer_notif_iters
;
49 struct bt_private_component
*priv_comp
;
50 unsigned int next_port_num
;
51 size_t available_input_ports
;
53 bool initializing_muxer_notif_iter
;
56 struct muxer_upstream_notif_iter
{
57 /* Owned by this, NULL if ended */
58 struct bt_notification_iterator
*notif_iter
;
61 struct bt_private_port
*priv_port
;
64 * This flag is true if the upstream notification iterator's
65 * current notification must be considered for the multiplexing
66 * operations. If the upstream iterator returns
67 * BT_NOTIFICATION_ITERATOR_STATUS_AGAIN, then this object
68 * is considered invalid, because its current notification is
69 * still the previous one, but we already took it into account.
71 * The value of this flag is not important if notif_iter above
72 * is NULL (which means the upstream iterator is finished).
77 struct muxer_notif_iter
{
79 * Array of struct muxer_upstream_notif_iter * (owned by this).
81 * NOTE: This array is searched in linearly to find the youngest
82 * current notification. Keep this until benchmarks confirm that
83 * another data structure is faster than this for our typical
86 GPtrArray
*muxer_upstream_notif_iters
;
89 * List of "recently" connected input ports (owned by this) to
90 * handle by this muxer notification iterator.
91 * muxer_port_connected() adds entries to this list, and the
92 * entries are removed when a notification iterator is created
93 * on the port's connection and put into
94 * muxer_upstream_notif_iters above by
95 * muxer_notif_iter_handle_newly_connected_ports().
97 GList
*newly_connected_priv_ports
;
99 /* Next thing to return by the "next" method */
100 struct bt_notification_iterator_next_return next_next_return
;
102 /* Last time returned in a notification */
103 int64_t last_returned_ts_ns
;
107 void destroy_muxer_upstream_notif_iter(
108 struct muxer_upstream_notif_iter
*muxer_upstream_notif_iter
)
110 if (!muxer_upstream_notif_iter
) {
114 bt_put(muxer_upstream_notif_iter
->notif_iter
);
115 bt_put(muxer_upstream_notif_iter
->priv_port
);
116 g_free(muxer_upstream_notif_iter
);
120 struct muxer_upstream_notif_iter
*muxer_notif_iter_add_upstream_notif_iter(
121 struct muxer_notif_iter
*muxer_notif_iter
,
122 struct bt_notification_iterator
*notif_iter
,
123 struct bt_private_port
*priv_port
)
125 struct muxer_upstream_notif_iter
*muxer_upstream_notif_iter
=
126 g_new0(struct muxer_upstream_notif_iter
, 1);
128 if (!muxer_upstream_notif_iter
) {
132 muxer_upstream_notif_iter
->notif_iter
= bt_get(notif_iter
);
133 muxer_upstream_notif_iter
->priv_port
= bt_get(priv_port
);
134 muxer_upstream_notif_iter
->is_valid
= false;
135 g_ptr_array_add(muxer_notif_iter
->muxer_upstream_notif_iters
,
136 muxer_upstream_notif_iter
);
139 return muxer_upstream_notif_iter
;
143 int ensure_available_input_port(struct bt_private_component
*priv_comp
)
145 struct muxer_comp
*muxer_comp
=
146 bt_private_component_get_user_data(priv_comp
);
148 GString
*port_name
= NULL
;
149 void *priv_port
= NULL
;
153 if (muxer_comp
->available_input_ports
>= 1) {
157 port_name
= g_string_new("in");
163 g_string_append_printf(port_name
, "%u", muxer_comp
->next_port_num
);
164 priv_port
= bt_private_component_filter_add_input_private_port(
165 priv_comp
, port_name
->str
, NULL
);
171 muxer_comp
->available_input_ports
++;
172 muxer_comp
->next_port_num
++;
176 g_string_free(port_name
, TRUE
);
184 int create_output_port(struct bt_private_component
*priv_comp
)
189 priv_port
= bt_private_component_filter_add_output_private_port(
190 priv_comp
, "out", NULL
);
200 void destroy_muxer_comp(struct muxer_comp
*muxer_comp
)
206 if (muxer_comp
->muxer_notif_iters
) {
207 g_ptr_array_free(muxer_comp
->muxer_notif_iters
, TRUE
);
214 enum bt_component_status
muxer_init(
215 struct bt_private_component
*priv_comp
,
216 struct bt_value
*params
, void *init_data
)
219 enum bt_component_status status
= BT_COMPONENT_STATUS_OK
;
220 struct muxer_comp
*muxer_comp
= g_new0(struct muxer_comp
, 1);
226 muxer_comp
->muxer_notif_iters
= g_ptr_array_new();
227 if (!muxer_comp
->muxer_notif_iters
) {
231 muxer_comp
->priv_comp
= priv_comp
;
232 ret
= bt_private_component_set_user_data(priv_comp
, muxer_comp
);
234 ret
= ensure_available_input_port(priv_comp
);
239 ret
= create_output_port(priv_comp
);
247 destroy_muxer_comp(muxer_comp
);
248 ret
= bt_private_component_set_user_data(priv_comp
, NULL
);
250 status
= BT_COMPONENT_STATUS_ERROR
;
257 void muxer_finalize(struct bt_private_component
*priv_comp
)
259 struct muxer_comp
*muxer_comp
=
260 bt_private_component_get_user_data(priv_comp
);
262 destroy_muxer_comp(muxer_comp
);
266 struct bt_notification_iterator
*create_notif_iter_on_input_port(
267 struct bt_private_port
*priv_port
, int *ret
)
269 struct bt_port
*port
= bt_port_from_private_port(priv_port
);
270 struct bt_notification_iterator
*notif_iter
= NULL
;
271 struct bt_private_connection
*priv_conn
= NULL
;
277 assert(bt_port_is_connected(port
));
278 priv_conn
= bt_private_port_get_private_connection(priv_port
);
284 // TODO: Advance the iterator to >= the time of the latest
285 // returned notification by the muxer notification
286 // iterator which creates it.
287 notif_iter
= bt_private_connection_create_notification_iterator(
301 enum bt_notification_iterator_status
muxer_upstream_notif_iter_next(
302 struct muxer_upstream_notif_iter
*muxer_upstream_notif_iter
)
304 enum bt_notification_iterator_status status
;
306 status
= bt_notification_iterator_next(
307 muxer_upstream_notif_iter
->notif_iter
);
310 case BT_NOTIFICATION_ITERATOR_STATUS_OK
:
312 * Notification iterator's current notification is valid:
313 * it must be considered for muxing operations.
315 muxer_upstream_notif_iter
->is_valid
= true;
317 case BT_NOTIFICATION_ITERATOR_STATUS_AGAIN
:
319 * Notification iterator's current notification is not
320 * valid anymore. Return
321 * BT_NOTIFICATION_ITERATOR_STATUS_AGAIN
324 muxer_upstream_notif_iter
->is_valid
= false;
326 case BT_NOTIFICATION_ITERATOR_STATUS_END
:
328 * Notification iterator reached the end: release it. It
329 * won't be considered again to find the youngest
332 BT_PUT(muxer_upstream_notif_iter
->notif_iter
);
333 muxer_upstream_notif_iter
->is_valid
= false;
334 status
= BT_NOTIFICATION_ITERATOR_STATUS_OK
;
337 /* Error or unsupported status code */
338 status
= BT_NOTIFICATION_ITERATOR_STATUS_ERROR
;
346 int muxer_notif_iter_handle_newly_connected_ports(
347 struct muxer_notif_iter
*muxer_notif_iter
)
352 * Here we create one upstream notification iterator for each
353 * newly connected port. We do not perform an initial "next" on
354 * those new upstream notification iterators: they are
355 * invalidated, to be validated later. The list of newly
356 * connected ports to handle here is updated by
357 * muxer_port_connected().
360 GList
*node
= muxer_notif_iter
->newly_connected_priv_ports
;
361 struct bt_private_port
*priv_port
;
362 struct bt_port
*port
;
363 struct bt_notification_iterator
*upstream_notif_iter
= NULL
;
364 struct muxer_upstream_notif_iter
*muxer_upstream_notif_iter
;
370 priv_port
= node
->data
;
371 port
= bt_port_from_private_port(priv_port
);
374 if (!bt_port_is_connected(port
)) {
376 * Looks like this port is not connected
377 * anymore: we can't create an upstream
378 * notification iterator on its (non-existing)
379 * connection in this case.
385 upstream_notif_iter
= create_notif_iter_on_input_port(priv_port
,
388 assert(!upstream_notif_iter
);
393 muxer_upstream_notif_iter
=
394 muxer_notif_iter_add_upstream_notif_iter(
395 muxer_notif_iter
, upstream_notif_iter
,
398 BT_PUT(upstream_notif_iter
);
399 if (!muxer_upstream_notif_iter
) {
404 bt_put(upstream_notif_iter
);
407 muxer_notif_iter
->newly_connected_priv_ports
=
409 muxer_notif_iter
->newly_connected_priv_ports
,
425 int get_notif_ts_ns(struct muxer_comp
*muxer_comp
,
426 struct bt_notification
*notif
, int64_t last_returned_ts_ns
,
429 struct bt_clock_class_priority_map
*cc_prio_map
= NULL
;
430 struct bt_ctf_clock_class
*clock_class
= NULL
;
431 struct bt_ctf_clock_value
*clock_value
= NULL
;
432 struct bt_ctf_event
*event
= NULL
;
438 switch (bt_notification_get_type(notif
)) {
439 case BT_NOTIFICATION_TYPE_EVENT
:
441 bt_notification_event_get_clock_class_priority_map(
445 case BT_NOTIFICATION_TYPE_INACTIVITY
:
447 bt_notification_inactivity_get_clock_class_priority_map(
451 /* All the other notifications have a higher priority */
452 *ts_ns
= last_returned_ts_ns
;
461 * If the clock class priority map is empty, then we consider
462 * that this notification has no time. In this case it's always
465 if (bt_clock_class_priority_map_get_clock_class_count(cc_prio_map
) == 0) {
466 *ts_ns
= last_returned_ts_ns
;
471 bt_clock_class_priority_map_get_highest_priority_clock_class(
477 if (!bt_ctf_clock_class_is_absolute(clock_class
)) {
478 // TODO: Allow this with an explicit parameter
482 switch (bt_notification_get_type(notif
)) {
483 case BT_NOTIFICATION_TYPE_EVENT
:
484 event
= bt_notification_event_get_event(notif
);
486 clock_value
= bt_ctf_event_get_clock_value(event
,
489 case BT_NOTIFICATION_TYPE_INACTIVITY
:
490 clock_value
= bt_notification_inactivity_get_clock_value(
501 ret
= bt_ctf_clock_value_get_value_ns_from_epoch(clock_value
, ts_ns
);
520 * This function finds the youngest available notification amongst the
521 * non-ended upstream notification iterators and returns the upstream
522 * notification iterator which has it, or
523 * BT_NOTIFICATION_ITERATOR_STATUS_END if there's no available
526 * This function does NOT:
528 * * Update any upstream notification iterator.
529 * * Check for newly connected ports.
530 * * Check the upstream notification iterators to retry.
532 * On sucess, this function sets *muxer_upstream_notif_iter to the
533 * upstream notification iterator of which the current notification is
534 * the youngest, and sets *ts_ns to its time.
537 enum bt_notification_iterator_status
538 muxer_notif_iter_youngest_upstream_notif_iter(
539 struct muxer_comp
*muxer_comp
,
540 struct muxer_notif_iter
*muxer_notif_iter
,
541 struct muxer_upstream_notif_iter
**muxer_upstream_notif_iter
,
546 int64_t youngest_ts_ns
= INT64_MAX
;
547 enum bt_notification_iterator_status status
=
548 BT_NOTIFICATION_ITERATOR_STATUS_OK
;
551 assert(muxer_notif_iter
);
552 assert(muxer_upstream_notif_iter
);
553 *muxer_upstream_notif_iter
= NULL
;
555 for (i
= 0; i
< muxer_notif_iter
->muxer_upstream_notif_iters
->len
; i
++) {
556 struct bt_notification
*notif
;
557 struct muxer_upstream_notif_iter
*cur_muxer_upstream_notif_iter
=
558 g_ptr_array_index(muxer_notif_iter
->muxer_upstream_notif_iters
, i
);
561 if (!cur_muxer_upstream_notif_iter
->notif_iter
) {
562 /* This upstream notification iterator is ended */
566 assert(cur_muxer_upstream_notif_iter
->is_valid
);
567 notif
= bt_notification_iterator_get_notification(
568 cur_muxer_upstream_notif_iter
->notif_iter
);
570 ret
= get_notif_ts_ns(muxer_comp
, notif
,
571 muxer_notif_iter
->last_returned_ts_ns
, ¬if_ts_ns
);
574 *muxer_upstream_notif_iter
= NULL
;
575 status
= BT_NOTIFICATION_ITERATOR_STATUS_ERROR
;
579 if (notif_ts_ns
<= youngest_ts_ns
) {
580 *muxer_upstream_notif_iter
=
581 cur_muxer_upstream_notif_iter
;
582 youngest_ts_ns
= notif_ts_ns
;
583 *ts_ns
= youngest_ts_ns
;
587 if (!*muxer_upstream_notif_iter
) {
588 status
= BT_NOTIFICATION_ITERATOR_STATUS_END
;
597 enum bt_notification_iterator_status
validate_muxer_upstream_notif_iter(
598 struct muxer_upstream_notif_iter
*muxer_upstream_notif_iter
)
600 enum bt_notification_iterator_status status
=
601 BT_NOTIFICATION_ITERATOR_STATUS_OK
;
603 if (muxer_upstream_notif_iter
->is_valid
||
604 !muxer_upstream_notif_iter
->notif_iter
) {
608 status
= muxer_upstream_notif_iter_next(muxer_upstream_notif_iter
);
615 enum bt_notification_iterator_status
validate_muxer_upstream_notif_iters(
616 struct muxer_notif_iter
*muxer_notif_iter
)
618 enum bt_notification_iterator_status status
=
619 BT_NOTIFICATION_ITERATOR_STATUS_OK
;
622 for (i
= 0; i
< muxer_notif_iter
->muxer_upstream_notif_iters
->len
; i
++) {
623 struct muxer_upstream_notif_iter
*muxer_upstream_notif_iter
=
625 muxer_notif_iter
->muxer_upstream_notif_iters
,
628 status
= validate_muxer_upstream_notif_iter(
629 muxer_upstream_notif_iter
);
630 if (status
!= BT_NOTIFICATION_ITERATOR_STATUS_OK
) {
640 struct bt_notification_iterator_next_return
muxer_notif_iter_do_next(
641 struct muxer_comp
*muxer_comp
,
642 struct muxer_notif_iter
*muxer_notif_iter
)
644 struct muxer_upstream_notif_iter
*muxer_upstream_notif_iter
= NULL
;
645 struct bt_notification_iterator_next_return next_return
= {
646 .notification
= NULL
,
647 .status
= BT_NOTIFICATION_ITERATOR_STATUS_OK
,
649 int64_t next_return_ts
;
652 int ret
= muxer_notif_iter_handle_newly_connected_ports(
657 BT_NOTIFICATION_ITERATOR_STATUS_ERROR
;
662 validate_muxer_upstream_notif_iters(muxer_notif_iter
);
663 if (next_return
.status
!= BT_NOTIFICATION_ITERATOR_STATUS_OK
) {
668 * At this point, we know that all the existing upstream
669 * notification iterators are valid. However the
670 * operations to validate them (during
671 * validate_muxer_upstream_notif_iters()) may have
672 * connected new ports. If no ports were connected
673 * during this operation, exit the loop.
675 if (!muxer_notif_iter
->newly_connected_priv_ports
) {
680 assert(!muxer_notif_iter
->newly_connected_priv_ports
);
683 * At this point we know that all the existing upstream
684 * notification iterators are valid. We can find the one,
685 * amongst those, of which the current notification is the
689 muxer_notif_iter_youngest_upstream_notif_iter(muxer_comp
,
690 muxer_notif_iter
, &muxer_upstream_notif_iter
,
692 if (next_return
.status
< 0 ||
693 next_return
.status
== BT_NOTIFICATION_ITERATOR_STATUS_END
) {
697 if (next_return_ts
< muxer_notif_iter
->last_returned_ts_ns
) {
698 next_return
.status
= BT_NOTIFICATION_ITERATOR_STATUS_ERROR
;
702 assert(next_return
.status
== BT_NOTIFICATION_ITERATOR_STATUS_OK
);
703 assert(muxer_upstream_notif_iter
);
704 next_return
.notification
= bt_notification_iterator_get_notification(
705 muxer_upstream_notif_iter
->notif_iter
);
706 assert(next_return
.notification
);
709 * We invalidate the upstream notification iterator so that, the
710 * next time this function is called,
711 * validate_muxer_upstream_notif_iters() will make it valid.
713 muxer_upstream_notif_iter
->is_valid
= false;
714 muxer_notif_iter
->last_returned_ts_ns
= next_return_ts
;
721 void destroy_muxer_notif_iter(struct muxer_notif_iter
*muxer_notif_iter
)
725 if (!muxer_notif_iter
) {
729 if (muxer_notif_iter
->muxer_upstream_notif_iters
) {
731 muxer_notif_iter
->muxer_upstream_notif_iters
, TRUE
);
734 for (node
= muxer_notif_iter
->newly_connected_priv_ports
;
735 node
; node
= g_list_next(node
)) {
739 g_list_free(muxer_notif_iter
->newly_connected_priv_ports
);
740 g_free(muxer_notif_iter
);
744 int muxer_notif_iter_init_newly_connected_ports(struct muxer_comp
*muxer_comp
,
745 struct muxer_notif_iter
*muxer_notif_iter
)
747 struct bt_component
*comp
;
753 * Add the connected input ports to this muxer notification
754 * iterator's list of newly connected ports. They will be
755 * handled by muxer_notif_iter_handle_newly_connected_ports().
757 comp
= bt_component_from_private_component(muxer_comp
->priv_comp
);
759 count
= bt_component_filter_get_input_port_count(comp
);
764 for (i
= 0; i
< count
; i
++) {
765 struct bt_private_port
*priv_port
=
766 bt_private_component_filter_get_input_private_port_by_index(
767 muxer_comp
->priv_comp
, i
);
768 struct bt_port
*port
;
771 port
= bt_port_from_private_port(priv_port
);
774 if (!bt_port_is_connected(port
)) {
781 muxer_notif_iter
->newly_connected_priv_ports
=
783 muxer_notif_iter
->newly_connected_priv_ports
,
785 if (!muxer_notif_iter
->newly_connected_priv_ports
) {
798 enum bt_notification_iterator_status
muxer_notif_iter_init(
799 struct bt_private_notification_iterator
*priv_notif_iter
,
800 struct bt_private_port
*output_priv_port
)
802 struct muxer_comp
*muxer_comp
= NULL
;
803 struct muxer_notif_iter
*muxer_notif_iter
= NULL
;
804 struct bt_private_component
*priv_comp
= NULL
;
805 enum bt_notification_iterator_status status
=
806 BT_NOTIFICATION_ITERATOR_STATUS_OK
;
809 priv_comp
= bt_private_notification_iterator_get_private_component(
812 muxer_comp
= bt_private_component_get_user_data(priv_comp
);
815 if (muxer_comp
->initializing_muxer_notif_iter
) {
817 * Weird, unhandled situation detected: downstream
818 * creates a muxer notification iterator while creating
819 * another muxer notification iterator (same component).
824 muxer_comp
->initializing_muxer_notif_iter
= true;
825 muxer_notif_iter
= g_new0(struct muxer_notif_iter
, 1);
826 if (!muxer_notif_iter
) {
830 muxer_notif_iter
->last_returned_ts_ns
= INT64_MIN
;
831 muxer_notif_iter
->muxer_upstream_notif_iters
=
832 g_ptr_array_new_with_free_func(
833 (GDestroyNotify
) destroy_muxer_upstream_notif_iter
);
834 if (!muxer_notif_iter
->muxer_upstream_notif_iters
) {
839 * Add the muxer notification iterator to the component's array
840 * of muxer notification iterators here because
841 * muxer_notif_iter_init_newly_connected_ports() can cause
842 * muxer_port_connected() to be called, which adds the newly
843 * connected port to each muxer notification iterator's list of
844 * newly connected ports.
846 g_ptr_array_add(muxer_comp
->muxer_notif_iters
, muxer_notif_iter
);
847 ret
= muxer_notif_iter_init_newly_connected_ports(muxer_comp
,
853 ret
= bt_private_notification_iterator_set_user_data(priv_notif_iter
,
859 if (g_ptr_array_index(muxer_comp
->muxer_notif_iters
,
860 muxer_comp
->muxer_notif_iters
->len
- 1) == muxer_notif_iter
) {
861 g_ptr_array_remove_index(muxer_comp
->muxer_notif_iters
,
862 muxer_comp
->muxer_notif_iters
->len
- 1);
865 destroy_muxer_notif_iter(muxer_notif_iter
);
866 ret
= bt_private_notification_iterator_set_user_data(priv_notif_iter
,
869 status
= BT_NOTIFICATION_ITERATOR_STATUS_ERROR
;
872 muxer_comp
->initializing_muxer_notif_iter
= false;
878 void muxer_notif_iter_finalize(
879 struct bt_private_notification_iterator
*priv_notif_iter
)
881 struct muxer_notif_iter
*muxer_notif_iter
=
882 bt_private_notification_iterator_get_user_data(priv_notif_iter
);
883 struct bt_private_component
*priv_comp
= NULL
;
884 struct muxer_comp
*muxer_comp
= NULL
;
886 priv_comp
= bt_private_notification_iterator_get_private_component(
889 muxer_comp
= bt_private_component_get_user_data(priv_comp
);
892 (void) g_ptr_array_remove_fast(muxer_comp
->muxer_notif_iters
,
894 destroy_muxer_notif_iter(muxer_notif_iter
);
901 struct bt_notification_iterator_next_return
muxer_notif_iter_next(
902 struct bt_private_notification_iterator
*priv_notif_iter
)
904 struct bt_notification_iterator_next_return next_ret
;
905 struct muxer_notif_iter
*muxer_notif_iter
=
906 bt_private_notification_iterator_get_user_data(priv_notif_iter
);
907 struct bt_private_component
*priv_comp
= NULL
;
908 struct muxer_comp
*muxer_comp
= NULL
;
910 assert(muxer_notif_iter
);
911 priv_comp
= bt_private_notification_iterator_get_private_component(
914 muxer_comp
= bt_private_component_get_user_data(priv_comp
);
917 /* Are we in an error state set elsewhere? */
918 if (unlikely(muxer_comp
->error
)) {
919 next_ret
.notification
= NULL
;
920 next_ret
.status
= BT_NOTIFICATION_ITERATOR_STATUS_ERROR
;
924 next_ret
= muxer_notif_iter_do_next(muxer_comp
, muxer_notif_iter
);
932 void muxer_port_connected(
933 struct bt_private_component
*priv_comp
,
934 struct bt_private_port
*self_private_port
,
935 struct bt_port
*other_port
)
937 struct bt_port
*self_port
=
938 bt_port_from_private_port(self_private_port
);
939 struct muxer_comp
*muxer_comp
=
940 bt_private_component_get_user_data(priv_comp
);
946 if (bt_port_get_type(self_port
) == BT_PORT_TYPE_INPUT
) {
949 /* One less available input port */
950 muxer_comp
->available_input_ports
--;
951 ret
= ensure_available_input_port(priv_comp
);
954 * Only way to report an error later since this
955 * method does not return anything.
957 muxer_comp
->error
= true;
962 for (i
= 0; i
< muxer_comp
->muxer_notif_iters
->len
; i
++) {
963 struct muxer_notif_iter
*muxer_notif_iter
=
964 g_ptr_array_index(muxer_comp
->muxer_notif_iters
, i
);
967 * Add this port to the list of newly connected ports
968 * for this muxer notification iterator. We append at
969 * the end of this list while
970 * muxer_notif_iter_handle_newly_connected_ports()
971 * removes the nodes from the beginning.
973 * The list node owns the private port.
975 muxer_notif_iter
->newly_connected_priv_ports
=
977 muxer_notif_iter
->newly_connected_priv_ports
,
978 bt_get(self_private_port
));
979 if (!muxer_notif_iter
->newly_connected_priv_ports
) {
980 /* Put reference taken by bt_get() above */
981 bt_put(self_private_port
);
982 muxer_comp
->error
= true;
992 void muxer_port_disconnected(struct bt_private_component
*priv_comp
,
993 struct bt_private_port
*priv_port
)
995 struct bt_port
*port
= bt_port_from_private_port(priv_port
);
996 struct muxer_comp
*muxer_comp
=
997 bt_private_component_get_user_data(priv_comp
);
1003 * There's nothing special to do when a port is disconnected
1004 * because this component deals with upstream notification
1005 * iterators which were already created thanks to connected
1006 * ports. The fact that the port is disconnected does not cancel
1007 * the upstream notification iterators created using its
1008 * connection: they still exist, even if the connection is dead.
1009 * The only way to remove an upstream notification iterator is
1010 * for its "next" operation to return
1011 * BT_NOTIFICATION_ITERATOR_STATUS_END.
1013 if (bt_port_get_type(port
) == BT_PORT_TYPE_INPUT
) {
1014 /* One more available input port */
1015 muxer_comp
->available_input_ports
++;