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>
46 #define ASSUME_ABSOLUTE_CLOCK_CLASSES_PARAM_NAME "assume-absolute-clock-classes"
49 /* Array of struct bt_private_notification_iterator * (weak refs) */
50 GPtrArray
*muxer_notif_iters
;
53 struct bt_private_component
*priv_comp
;
54 unsigned int next_port_num
;
55 size_t available_input_ports
;
57 bool initializing_muxer_notif_iter
;
61 struct muxer_upstream_notif_iter
{
62 /* Owned by this, NULL if ended */
63 struct bt_notification_iterator
*notif_iter
;
66 struct bt_private_port
*priv_port
;
69 * This flag is true if the upstream notification iterator's
70 * current notification must be considered for the multiplexing
71 * operations. If the upstream iterator returns
72 * BT_NOTIFICATION_ITERATOR_STATUS_AGAIN, then this object
73 * is considered invalid, because its current notification is
74 * still the previous one, but we already took it into account.
76 * The value of this flag is not important if notif_iter above
77 * is NULL (which means the upstream iterator is finished).
82 struct muxer_notif_iter
{
84 * Array of struct muxer_upstream_notif_iter * (owned by this).
86 * NOTE: This array is searched in linearly to find the youngest
87 * current notification. Keep this until benchmarks confirm that
88 * another data structure is faster than this for our typical
91 GPtrArray
*muxer_upstream_notif_iters
;
94 * List of "recently" connected input ports (weak) to
95 * handle by this muxer notification iterator.
96 * muxer_port_connected() adds entries to this list, and the
97 * entries are removed when a notification iterator is created
98 * on the port's connection and put into
99 * muxer_upstream_notif_iters above by
100 * muxer_notif_iter_handle_newly_connected_ports().
102 GList
*newly_connected_priv_ports
;
104 /* Next thing to return by the "next" method */
105 struct bt_notification_iterator_next_return next_next_return
;
107 /* Last time returned in a notification */
108 int64_t last_returned_ts_ns
;
112 void destroy_muxer_upstream_notif_iter(
113 struct muxer_upstream_notif_iter
*muxer_upstream_notif_iter
)
115 if (!muxer_upstream_notif_iter
) {
119 bt_put(muxer_upstream_notif_iter
->notif_iter
);
120 g_free(muxer_upstream_notif_iter
);
124 struct muxer_upstream_notif_iter
*muxer_notif_iter_add_upstream_notif_iter(
125 struct muxer_notif_iter
*muxer_notif_iter
,
126 struct bt_notification_iterator
*notif_iter
,
127 struct bt_private_port
*priv_port
)
129 struct muxer_upstream_notif_iter
*muxer_upstream_notif_iter
=
130 g_new0(struct muxer_upstream_notif_iter
, 1);
132 if (!muxer_upstream_notif_iter
) {
136 muxer_upstream_notif_iter
->notif_iter
= bt_get(notif_iter
);
137 muxer_upstream_notif_iter
->priv_port
= priv_port
;
138 muxer_upstream_notif_iter
->is_valid
= false;
139 g_ptr_array_add(muxer_notif_iter
->muxer_upstream_notif_iters
,
140 muxer_upstream_notif_iter
);
143 return muxer_upstream_notif_iter
;
147 int ensure_available_input_port(struct bt_private_component
*priv_comp
)
149 struct muxer_comp
*muxer_comp
=
150 bt_private_component_get_user_data(priv_comp
);
152 GString
*port_name
= NULL
;
153 void *priv_port
= NULL
;
157 if (muxer_comp
->available_input_ports
>= 1) {
161 port_name
= g_string_new("in");
167 g_string_append_printf(port_name
, "%u", muxer_comp
->next_port_num
);
168 priv_port
= bt_private_component_filter_add_input_private_port(
169 priv_comp
, port_name
->str
, NULL
);
175 muxer_comp
->available_input_ports
++;
176 muxer_comp
->next_port_num
++;
180 g_string_free(port_name
, TRUE
);
188 int create_output_port(struct bt_private_component
*priv_comp
)
193 priv_port
= bt_private_component_filter_add_output_private_port(
194 priv_comp
, "out", NULL
);
204 void destroy_muxer_comp(struct muxer_comp
*muxer_comp
)
210 if (muxer_comp
->muxer_notif_iters
) {
211 g_ptr_array_free(muxer_comp
->muxer_notif_iters
, TRUE
);
218 struct bt_value
*get_default_params(void)
220 struct bt_value
*params
;
223 params
= bt_value_map_create();
228 ret
= bt_value_map_insert_bool(params
,
229 ASSUME_ABSOLUTE_CLOCK_CLASSES_PARAM_NAME
, false);
244 int configure_muxer_comp(struct muxer_comp
*muxer_comp
, struct bt_value
*params
)
246 struct bt_value
*default_params
= NULL
;
247 struct bt_value
*real_params
= NULL
;
248 struct bt_value
*ignore_absolute
= NULL
;
252 default_params
= get_default_params();
253 if (!default_params
) {
257 real_params
= bt_value_map_extend(default_params
, params
);
262 ignore_absolute
= bt_value_map_get(real_params
,
263 ASSUME_ABSOLUTE_CLOCK_CLASSES_PARAM_NAME
);
264 if (!bt_value_is_bool(ignore_absolute
)) {
268 if (bt_value_bool_get(ignore_absolute
, &bool_val
)) {
272 muxer_comp
->ignore_absolute
= (bool) bool_val
;
280 bt_put(default_params
);
282 bt_put(ignore_absolute
);
287 enum bt_component_status
muxer_init(
288 struct bt_private_component
*priv_comp
,
289 struct bt_value
*params
, void *init_data
)
292 enum bt_component_status status
= BT_COMPONENT_STATUS_OK
;
293 struct muxer_comp
*muxer_comp
= g_new0(struct muxer_comp
, 1);
299 ret
= configure_muxer_comp(muxer_comp
, params
);
304 muxer_comp
->muxer_notif_iters
= g_ptr_array_new();
305 if (!muxer_comp
->muxer_notif_iters
) {
309 muxer_comp
->priv_comp
= priv_comp
;
310 ret
= bt_private_component_set_user_data(priv_comp
, muxer_comp
);
312 ret
= ensure_available_input_port(priv_comp
);
317 ret
= create_output_port(priv_comp
);
325 destroy_muxer_comp(muxer_comp
);
326 ret
= bt_private_component_set_user_data(priv_comp
, NULL
);
328 status
= BT_COMPONENT_STATUS_ERROR
;
335 void muxer_finalize(struct bt_private_component
*priv_comp
)
337 struct muxer_comp
*muxer_comp
=
338 bt_private_component_get_user_data(priv_comp
);
340 destroy_muxer_comp(muxer_comp
);
344 struct bt_notification_iterator
*create_notif_iter_on_input_port(
345 struct bt_private_port
*priv_port
, int *ret
)
347 struct bt_port
*port
= bt_port_from_private_port(priv_port
);
348 struct bt_notification_iterator
*notif_iter
= NULL
;
349 struct bt_private_connection
*priv_conn
= NULL
;
355 assert(bt_port_is_connected(port
));
356 priv_conn
= bt_private_port_get_private_connection(priv_port
);
362 // TODO: Advance the iterator to >= the time of the latest
363 // returned notification by the muxer notification
364 // iterator which creates it.
365 notif_iter
= bt_private_connection_create_notification_iterator(
379 enum bt_notification_iterator_status
muxer_upstream_notif_iter_next(
380 struct muxer_upstream_notif_iter
*muxer_upstream_notif_iter
)
382 enum bt_notification_iterator_status status
;
384 status
= bt_notification_iterator_next(
385 muxer_upstream_notif_iter
->notif_iter
);
388 case BT_NOTIFICATION_ITERATOR_STATUS_OK
:
390 * Notification iterator's current notification is valid:
391 * it must be considered for muxing operations.
393 muxer_upstream_notif_iter
->is_valid
= true;
395 case BT_NOTIFICATION_ITERATOR_STATUS_AGAIN
:
397 * Notification iterator's current notification is not
398 * valid anymore. Return
399 * BT_NOTIFICATION_ITERATOR_STATUS_AGAIN
402 muxer_upstream_notif_iter
->is_valid
= false;
404 case BT_NOTIFICATION_ITERATOR_STATUS_END
: /* Fall-through. */
405 case BT_NOTIFICATION_ITERATOR_STATUS_CANCELED
:
407 * Notification iterator reached the end: release it. It
408 * won't be considered again to find the youngest
411 BT_PUT(muxer_upstream_notif_iter
->notif_iter
);
412 muxer_upstream_notif_iter
->is_valid
= false;
413 status
= BT_NOTIFICATION_ITERATOR_STATUS_OK
;
416 /* Error or unsupported status code */
417 status
= BT_NOTIFICATION_ITERATOR_STATUS_ERROR
;
425 int muxer_notif_iter_handle_newly_connected_ports(
426 struct muxer_notif_iter
*muxer_notif_iter
)
431 * Here we create one upstream notification iterator for each
432 * newly connected port. We do not perform an initial "next" on
433 * those new upstream notification iterators: they are
434 * invalidated, to be validated later. The list of newly
435 * connected ports to handle here is updated by
436 * muxer_port_connected().
439 GList
*node
= muxer_notif_iter
->newly_connected_priv_ports
;
440 struct bt_private_port
*priv_port
;
441 struct bt_port
*port
;
442 struct bt_notification_iterator
*upstream_notif_iter
= NULL
;
443 struct muxer_upstream_notif_iter
*muxer_upstream_notif_iter
;
449 priv_port
= node
->data
;
450 port
= bt_port_from_private_port(priv_port
);
453 if (!bt_port_is_connected(port
)) {
455 * Looks like this port is not connected
456 * anymore: we can't create an upstream
457 * notification iterator on its (non-existing)
458 * connection in this case.
464 upstream_notif_iter
= create_notif_iter_on_input_port(priv_port
,
467 assert(!upstream_notif_iter
);
471 muxer_upstream_notif_iter
=
472 muxer_notif_iter_add_upstream_notif_iter(
473 muxer_notif_iter
, upstream_notif_iter
,
475 BT_PUT(upstream_notif_iter
);
476 if (!muxer_upstream_notif_iter
) {
481 bt_put(upstream_notif_iter
);
483 muxer_notif_iter
->newly_connected_priv_ports
=
485 muxer_notif_iter
->newly_connected_priv_ports
,
501 int get_notif_ts_ns(struct muxer_comp
*muxer_comp
,
502 struct bt_notification
*notif
, int64_t last_returned_ts_ns
,
505 struct bt_clock_class_priority_map
*cc_prio_map
= NULL
;
506 struct bt_ctf_clock_class
*clock_class
= NULL
;
507 struct bt_ctf_clock_value
*clock_value
= NULL
;
508 struct bt_ctf_event
*event
= NULL
;
514 switch (bt_notification_get_type(notif
)) {
515 case BT_NOTIFICATION_TYPE_EVENT
:
517 bt_notification_event_get_clock_class_priority_map(
521 case BT_NOTIFICATION_TYPE_INACTIVITY
:
523 bt_notification_inactivity_get_clock_class_priority_map(
527 /* All the other notifications have a higher priority */
528 *ts_ns
= last_returned_ts_ns
;
537 * If the clock class priority map is empty, then we consider
538 * that this notification has no time. In this case it's always
541 if (bt_clock_class_priority_map_get_clock_class_count(cc_prio_map
) == 0) {
542 *ts_ns
= last_returned_ts_ns
;
547 bt_clock_class_priority_map_get_highest_priority_clock_class(
553 if (!muxer_comp
->ignore_absolute
&&
554 !bt_ctf_clock_class_is_absolute(clock_class
)) {
558 switch (bt_notification_get_type(notif
)) {
559 case BT_NOTIFICATION_TYPE_EVENT
:
560 event
= bt_notification_event_get_event(notif
);
562 clock_value
= bt_ctf_event_get_clock_value(event
,
565 case BT_NOTIFICATION_TYPE_INACTIVITY
:
566 clock_value
= bt_notification_inactivity_get_clock_value(
577 ret
= bt_ctf_clock_value_get_value_ns_from_epoch(clock_value
, ts_ns
);
596 * This function finds the youngest available notification amongst the
597 * non-ended upstream notification iterators and returns the upstream
598 * notification iterator which has it, or
599 * BT_NOTIFICATION_ITERATOR_STATUS_END if there's no available
602 * This function does NOT:
604 * * Update any upstream notification iterator.
605 * * Check for newly connected ports.
606 * * Check the upstream notification iterators to retry.
608 * On sucess, this function sets *muxer_upstream_notif_iter to the
609 * upstream notification iterator of which the current notification is
610 * the youngest, and sets *ts_ns to its time.
613 enum bt_notification_iterator_status
614 muxer_notif_iter_youngest_upstream_notif_iter(
615 struct muxer_comp
*muxer_comp
,
616 struct muxer_notif_iter
*muxer_notif_iter
,
617 struct muxer_upstream_notif_iter
**muxer_upstream_notif_iter
,
622 int64_t youngest_ts_ns
= INT64_MAX
;
623 enum bt_notification_iterator_status status
=
624 BT_NOTIFICATION_ITERATOR_STATUS_OK
;
627 assert(muxer_notif_iter
);
628 assert(muxer_upstream_notif_iter
);
629 *muxer_upstream_notif_iter
= NULL
;
631 for (i
= 0; i
< muxer_notif_iter
->muxer_upstream_notif_iters
->len
; i
++) {
632 struct bt_notification
*notif
;
633 struct muxer_upstream_notif_iter
*cur_muxer_upstream_notif_iter
=
634 g_ptr_array_index(muxer_notif_iter
->muxer_upstream_notif_iters
, i
);
637 if (!cur_muxer_upstream_notif_iter
->notif_iter
) {
638 /* This upstream notification iterator is ended */
642 assert(cur_muxer_upstream_notif_iter
->is_valid
);
643 notif
= bt_notification_iterator_get_notification(
644 cur_muxer_upstream_notif_iter
->notif_iter
);
646 ret
= get_notif_ts_ns(muxer_comp
, notif
,
647 muxer_notif_iter
->last_returned_ts_ns
, ¬if_ts_ns
);
650 *muxer_upstream_notif_iter
= NULL
;
651 status
= BT_NOTIFICATION_ITERATOR_STATUS_ERROR
;
655 if (notif_ts_ns
<= youngest_ts_ns
) {
656 *muxer_upstream_notif_iter
=
657 cur_muxer_upstream_notif_iter
;
658 youngest_ts_ns
= notif_ts_ns
;
659 *ts_ns
= youngest_ts_ns
;
663 if (!*muxer_upstream_notif_iter
) {
664 status
= BT_NOTIFICATION_ITERATOR_STATUS_END
;
673 enum bt_notification_iterator_status
validate_muxer_upstream_notif_iter(
674 struct muxer_upstream_notif_iter
*muxer_upstream_notif_iter
)
676 enum bt_notification_iterator_status status
=
677 BT_NOTIFICATION_ITERATOR_STATUS_OK
;
679 if (muxer_upstream_notif_iter
->is_valid
||
680 !muxer_upstream_notif_iter
->notif_iter
) {
684 status
= muxer_upstream_notif_iter_next(muxer_upstream_notif_iter
);
691 enum bt_notification_iterator_status
validate_muxer_upstream_notif_iters(
692 struct muxer_notif_iter
*muxer_notif_iter
)
694 enum bt_notification_iterator_status status
=
695 BT_NOTIFICATION_ITERATOR_STATUS_OK
;
698 for (i
= 0; i
< muxer_notif_iter
->muxer_upstream_notif_iters
->len
; i
++) {
699 struct muxer_upstream_notif_iter
*muxer_upstream_notif_iter
=
701 muxer_notif_iter
->muxer_upstream_notif_iters
,
704 status
= validate_muxer_upstream_notif_iter(
705 muxer_upstream_notif_iter
);
706 if (status
!= BT_NOTIFICATION_ITERATOR_STATUS_OK
) {
716 struct bt_notification_iterator_next_return
muxer_notif_iter_do_next(
717 struct muxer_comp
*muxer_comp
,
718 struct muxer_notif_iter
*muxer_notif_iter
)
720 struct muxer_upstream_notif_iter
*muxer_upstream_notif_iter
= NULL
;
721 struct bt_notification_iterator_next_return next_return
= {
722 .notification
= NULL
,
723 .status
= BT_NOTIFICATION_ITERATOR_STATUS_OK
,
725 int64_t next_return_ts
;
728 int ret
= muxer_notif_iter_handle_newly_connected_ports(
733 BT_NOTIFICATION_ITERATOR_STATUS_ERROR
;
738 validate_muxer_upstream_notif_iters(muxer_notif_iter
);
739 if (next_return
.status
!= BT_NOTIFICATION_ITERATOR_STATUS_OK
) {
744 * At this point, we know that all the existing upstream
745 * notification iterators are valid. However the
746 * operations to validate them (during
747 * validate_muxer_upstream_notif_iters()) may have
748 * connected new ports. If no ports were connected
749 * during this operation, exit the loop.
751 if (!muxer_notif_iter
->newly_connected_priv_ports
) {
756 assert(!muxer_notif_iter
->newly_connected_priv_ports
);
759 * At this point we know that all the existing upstream
760 * notification iterators are valid. We can find the one,
761 * amongst those, of which the current notification is the
765 muxer_notif_iter_youngest_upstream_notif_iter(muxer_comp
,
766 muxer_notif_iter
, &muxer_upstream_notif_iter
,
768 if (next_return
.status
< 0 ||
769 next_return
.status
== BT_NOTIFICATION_ITERATOR_STATUS_END
||
770 next_return
.status
== BT_NOTIFICATION_ITERATOR_STATUS_CANCELED
) {
774 if (next_return_ts
< muxer_notif_iter
->last_returned_ts_ns
) {
775 next_return
.status
= BT_NOTIFICATION_ITERATOR_STATUS_ERROR
;
779 assert(next_return
.status
== BT_NOTIFICATION_ITERATOR_STATUS_OK
);
780 assert(muxer_upstream_notif_iter
);
781 next_return
.notification
= bt_notification_iterator_get_notification(
782 muxer_upstream_notif_iter
->notif_iter
);
783 assert(next_return
.notification
);
786 * We invalidate the upstream notification iterator so that, the
787 * next time this function is called,
788 * validate_muxer_upstream_notif_iters() will make it valid.
790 muxer_upstream_notif_iter
->is_valid
= false;
791 muxer_notif_iter
->last_returned_ts_ns
= next_return_ts
;
798 void destroy_muxer_notif_iter(struct muxer_notif_iter
*muxer_notif_iter
)
800 if (!muxer_notif_iter
) {
804 if (muxer_notif_iter
->muxer_upstream_notif_iters
) {
806 muxer_notif_iter
->muxer_upstream_notif_iters
, TRUE
);
809 g_list_free(muxer_notif_iter
->newly_connected_priv_ports
);
810 g_free(muxer_notif_iter
);
814 int muxer_notif_iter_init_newly_connected_ports(struct muxer_comp
*muxer_comp
,
815 struct muxer_notif_iter
*muxer_notif_iter
)
817 struct bt_component
*comp
;
823 * Add the connected input ports to this muxer notification
824 * iterator's list of newly connected ports. They will be
825 * handled by muxer_notif_iter_handle_newly_connected_ports().
827 comp
= bt_component_from_private_component(muxer_comp
->priv_comp
);
829 count
= bt_component_filter_get_input_port_count(comp
);
834 for (i
= 0; i
< count
; i
++) {
835 struct bt_private_port
*priv_port
=
836 bt_private_component_filter_get_input_private_port_by_index(
837 muxer_comp
->priv_comp
, i
);
838 struct bt_port
*port
;
841 port
= bt_port_from_private_port(priv_port
);
844 if (!bt_port_is_connected(port
)) {
852 muxer_notif_iter
->newly_connected_priv_ports
=
854 muxer_notif_iter
->newly_connected_priv_ports
,
856 if (!muxer_notif_iter
->newly_connected_priv_ports
) {
868 enum bt_notification_iterator_status
muxer_notif_iter_init(
869 struct bt_private_notification_iterator
*priv_notif_iter
,
870 struct bt_private_port
*output_priv_port
)
872 struct muxer_comp
*muxer_comp
= NULL
;
873 struct muxer_notif_iter
*muxer_notif_iter
= NULL
;
874 struct bt_private_component
*priv_comp
= NULL
;
875 enum bt_notification_iterator_status status
=
876 BT_NOTIFICATION_ITERATOR_STATUS_OK
;
879 priv_comp
= bt_private_notification_iterator_get_private_component(
882 muxer_comp
= bt_private_component_get_user_data(priv_comp
);
885 if (muxer_comp
->initializing_muxer_notif_iter
) {
887 * Weird, unhandled situation detected: downstream
888 * creates a muxer notification iterator while creating
889 * another muxer notification iterator (same component).
894 muxer_comp
->initializing_muxer_notif_iter
= true;
895 muxer_notif_iter
= g_new0(struct muxer_notif_iter
, 1);
896 if (!muxer_notif_iter
) {
900 muxer_notif_iter
->last_returned_ts_ns
= INT64_MIN
;
901 muxer_notif_iter
->muxer_upstream_notif_iters
=
902 g_ptr_array_new_with_free_func(
903 (GDestroyNotify
) destroy_muxer_upstream_notif_iter
);
904 if (!muxer_notif_iter
->muxer_upstream_notif_iters
) {
909 * Add the muxer notification iterator to the component's array
910 * of muxer notification iterators here because
911 * muxer_notif_iter_init_newly_connected_ports() can cause
912 * muxer_port_connected() to be called, which adds the newly
913 * connected port to each muxer notification iterator's list of
914 * newly connected ports.
916 g_ptr_array_add(muxer_comp
->muxer_notif_iters
, muxer_notif_iter
);
917 ret
= muxer_notif_iter_init_newly_connected_ports(muxer_comp
,
923 ret
= bt_private_notification_iterator_set_user_data(priv_notif_iter
,
929 if (g_ptr_array_index(muxer_comp
->muxer_notif_iters
,
930 muxer_comp
->muxer_notif_iters
->len
- 1) == muxer_notif_iter
) {
931 g_ptr_array_remove_index(muxer_comp
->muxer_notif_iters
,
932 muxer_comp
->muxer_notif_iters
->len
- 1);
935 destroy_muxer_notif_iter(muxer_notif_iter
);
936 ret
= bt_private_notification_iterator_set_user_data(priv_notif_iter
,
939 status
= BT_NOTIFICATION_ITERATOR_STATUS_ERROR
;
942 muxer_comp
->initializing_muxer_notif_iter
= false;
948 void muxer_notif_iter_finalize(
949 struct bt_private_notification_iterator
*priv_notif_iter
)
951 struct muxer_notif_iter
*muxer_notif_iter
=
952 bt_private_notification_iterator_get_user_data(priv_notif_iter
);
953 struct bt_private_component
*priv_comp
= NULL
;
954 struct muxer_comp
*muxer_comp
= NULL
;
956 priv_comp
= bt_private_notification_iterator_get_private_component(
959 muxer_comp
= bt_private_component_get_user_data(priv_comp
);
962 (void) g_ptr_array_remove_fast(muxer_comp
->muxer_notif_iters
,
964 destroy_muxer_notif_iter(muxer_notif_iter
);
971 struct bt_notification_iterator_next_return
muxer_notif_iter_next(
972 struct bt_private_notification_iterator
*priv_notif_iter
)
974 struct bt_notification_iterator_next_return next_ret
;
975 struct muxer_notif_iter
*muxer_notif_iter
=
976 bt_private_notification_iterator_get_user_data(priv_notif_iter
);
977 struct bt_private_component
*priv_comp
= NULL
;
978 struct muxer_comp
*muxer_comp
= NULL
;
980 assert(muxer_notif_iter
);
981 priv_comp
= bt_private_notification_iterator_get_private_component(
984 muxer_comp
= bt_private_component_get_user_data(priv_comp
);
987 /* Are we in an error state set elsewhere? */
988 if (unlikely(muxer_comp
->error
)) {
989 next_ret
.notification
= NULL
;
990 next_ret
.status
= BT_NOTIFICATION_ITERATOR_STATUS_ERROR
;
994 next_ret
= muxer_notif_iter_do_next(muxer_comp
, muxer_notif_iter
);
1002 void muxer_port_connected(
1003 struct bt_private_component
*priv_comp
,
1004 struct bt_private_port
*self_private_port
,
1005 struct bt_port
*other_port
)
1007 struct bt_port
*self_port
=
1008 bt_port_from_private_port(self_private_port
);
1009 struct muxer_comp
*muxer_comp
=
1010 bt_private_component_get_user_data(priv_comp
);
1017 if (bt_port_get_type(self_port
) == BT_PORT_TYPE_OUTPUT
) {
1021 for (i
= 0; i
< muxer_comp
->muxer_notif_iters
->len
; i
++) {
1022 struct muxer_notif_iter
*muxer_notif_iter
=
1023 g_ptr_array_index(muxer_comp
->muxer_notif_iters
, i
);
1026 * Add this port to the list of newly connected ports
1027 * for this muxer notification iterator. We append at
1028 * the end of this list while
1029 * muxer_notif_iter_handle_newly_connected_ports()
1030 * removes the nodes from the beginning.
1032 * The list node owns the private port.
1034 muxer_notif_iter
->newly_connected_priv_ports
=
1036 muxer_notif_iter
->newly_connected_priv_ports
,
1038 if (!muxer_notif_iter
->newly_connected_priv_ports
) {
1039 /* Put reference taken by bt_get() above */
1040 muxer_comp
->error
= true;
1045 /* One less available input port */
1046 muxer_comp
->available_input_ports
--;
1047 ret
= ensure_available_input_port(priv_comp
);
1050 * Only way to report an error later since this
1051 * method does not return anything.
1053 muxer_comp
->error
= true;
1062 void muxer_port_disconnected(struct bt_private_component
*priv_comp
,
1063 struct bt_private_port
*priv_port
)
1065 struct bt_port
*port
= bt_port_from_private_port(priv_port
);
1066 struct muxer_comp
*muxer_comp
=
1067 bt_private_component_get_user_data(priv_comp
);
1073 * There's nothing special to do when a port is disconnected
1074 * because this component deals with upstream notification
1075 * iterators which were already created thanks to connected
1076 * ports. The fact that the port is disconnected does not cancel
1077 * the upstream notification iterators created using its
1078 * connection: they still exist, even if the connection is dead.
1079 * The only way to remove an upstream notification iterator is
1080 * for its "next" operation to return
1081 * BT_NOTIFICATION_ITERATOR_STATUS_END.
1083 if (bt_port_get_type(port
) == BT_PORT_TYPE_INPUT
) {
1084 /* One more available input port */
1085 muxer_comp
->available_input_ports
++;