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 #define BT_LOG_TAG "PLUGIN-UTILS-MUXER-FLT"
26 #include <babeltrace/babeltrace-internal.h>
27 #include <babeltrace/compat/uuid-internal.h>
28 #include <babeltrace/babeltrace.h>
29 #include <babeltrace/values-internal.h>
30 #include <babeltrace/graph/component-internal.h>
31 #include <babeltrace/graph/notification-iterator-internal.h>
32 #include <babeltrace/graph/connection-internal.h>
33 #include <plugins-common.h>
37 #include <babeltrace/assert-internal.h>
41 #define ASSUME_ABSOLUTE_CLOCK_CLASSES_PARAM_NAME "assume-absolute-clock-classes"
46 * bt_private_connection_private_notification_iterator *
49 GPtrArray
*muxer_notif_iters
;
52 struct bt_private_component
*priv_comp
;
53 unsigned int next_port_num
;
54 size_t available_input_ports
;
56 bool initializing_muxer_notif_iter
;
57 bool assume_absolute_clock_classes
;
60 struct muxer_upstream_notif_iter
{
61 /* Owned by this, NULL if ended */
62 struct bt_notification_iterator
*notif_iter
;
65 * This flag is true if the upstream notification iterator's
66 * current notification must be considered for the multiplexing
67 * operations. If the upstream iterator returns
68 * BT_NOTIFICATION_ITERATOR_STATUS_AGAIN, then this object
69 * is considered invalid, because its current notification is
70 * still the previous one, but we already took it into account.
72 * The value of this flag is not important if notif_iter above
73 * is NULL (which means the upstream iterator is finished).
78 enum muxer_notif_iter_clock_class_expectation
{
79 MUXER_NOTIF_ITER_CLOCK_CLASS_EXPECTATION_ANY
= 0,
80 MUXER_NOTIF_ITER_CLOCK_CLASS_EXPECTATION_ABSOLUTE
,
81 MUXER_NOTIF_ITER_CLOCK_CLASS_EXPECTATION_NOT_ABS_SPEC_UUID
,
82 MUXER_NOTIF_ITER_CLOCK_CLASS_EXPECTATION_NOT_ABS_NO_UUID
,
85 struct muxer_notif_iter
{
87 * Array of struct muxer_upstream_notif_iter * (owned by this).
89 * NOTE: This array is searched in linearly to find the youngest
90 * current notification. Keep this until benchmarks confirm that
91 * another data structure is faster than this for our typical
94 GPtrArray
*muxer_upstream_notif_iters
;
97 * List of "recently" connected input ports (weak) to
98 * handle by this muxer notification iterator.
99 * muxer_port_connected() adds entries to this list, and the
100 * entries are removed when a notification iterator is created
101 * on the port's connection and put into
102 * muxer_upstream_notif_iters above by
103 * muxer_notif_iter_handle_newly_connected_ports().
105 GList
*newly_connected_priv_ports
;
107 /* Next thing to return by the "next" method */
108 struct bt_notification_iterator_next_method_return next_next_return
;
110 /* Last time returned in a notification */
111 int64_t last_returned_ts_ns
;
113 /* Clock class expectation state */
114 enum muxer_notif_iter_clock_class_expectation clock_class_expectation
;
117 * Expected clock class UUID, only valid when
118 * clock_class_expectation is
119 * MUXER_NOTIF_ITER_CLOCK_CLASS_EXPECTATION_NOT_ABS_SPEC_UUID.
121 unsigned char expected_clock_class_uuid
[BABELTRACE_UUID_LEN
];
125 void destroy_muxer_upstream_notif_iter(
126 struct muxer_upstream_notif_iter
*muxer_upstream_notif_iter
)
128 if (!muxer_upstream_notif_iter
) {
132 BT_LOGD("Destroying muxer's upstream notification iterator wrapper: "
133 "addr=%p, notif-iter-addr=%p, is-valid=%d",
134 muxer_upstream_notif_iter
,
135 muxer_upstream_notif_iter
->notif_iter
,
136 muxer_upstream_notif_iter
->is_valid
);
137 bt_put(muxer_upstream_notif_iter
->notif_iter
);
138 g_free(muxer_upstream_notif_iter
);
142 struct muxer_upstream_notif_iter
*muxer_notif_iter_add_upstream_notif_iter(
143 struct muxer_notif_iter
*muxer_notif_iter
,
144 struct bt_notification_iterator
*notif_iter
,
145 struct bt_private_port
*priv_port
)
147 struct muxer_upstream_notif_iter
*muxer_upstream_notif_iter
=
148 g_new0(struct muxer_upstream_notif_iter
, 1);
150 if (!muxer_upstream_notif_iter
) {
151 BT_LOGE_STR("Failed to allocate one muxer's upstream notification iterator wrapper.");
155 muxer_upstream_notif_iter
->notif_iter
= bt_get(notif_iter
);
156 muxer_upstream_notif_iter
->is_valid
= false;
157 g_ptr_array_add(muxer_notif_iter
->muxer_upstream_notif_iters
,
158 muxer_upstream_notif_iter
);
159 BT_LOGD("Added muxer's upstream notification iterator wrapper: "
160 "addr=%p, muxer-notif-iter-addr=%p, notif-iter-addr=%p",
161 muxer_upstream_notif_iter
, muxer_notif_iter
,
165 return muxer_upstream_notif_iter
;
169 enum bt_component_status
ensure_available_input_port(
170 struct bt_private_component
*priv_comp
)
172 struct muxer_comp
*muxer_comp
=
173 bt_private_component_get_user_data(priv_comp
);
174 enum bt_component_status status
= BT_COMPONENT_STATUS_OK
;
175 GString
*port_name
= NULL
;
177 BT_ASSERT(muxer_comp
);
179 if (muxer_comp
->available_input_ports
>= 1) {
183 port_name
= g_string_new("in");
185 BT_LOGE_STR("Failed to allocate a GString.");
186 status
= BT_COMPONENT_STATUS_NOMEM
;
190 g_string_append_printf(port_name
, "%u", muxer_comp
->next_port_num
);
191 status
= bt_private_component_filter_add_input_private_port(
192 priv_comp
, port_name
->str
, NULL
, NULL
);
193 if (status
!= BT_COMPONENT_STATUS_OK
) {
194 BT_LOGE("Cannot add input port to muxer component: "
195 "port-name=\"%s\", comp-addr=%p, status=%s",
196 port_name
->str
, priv_comp
,
197 bt_component_status_string(status
));
201 muxer_comp
->available_input_ports
++;
202 muxer_comp
->next_port_num
++;
203 BT_LOGD("Added one input port to muxer component: "
204 "port-name=\"%s\", comp-addr=%p",
205 port_name
->str
, priv_comp
);
208 g_string_free(port_name
, TRUE
);
215 enum bt_component_status
create_output_port(
216 struct bt_private_component
*priv_comp
)
218 return bt_private_component_filter_add_output_private_port(
219 priv_comp
, "out", NULL
, NULL
);
223 void destroy_muxer_comp(struct muxer_comp
*muxer_comp
)
229 BT_LOGD("Destroying muxer component: muxer-comp-addr=%p, "
230 "muxer-notif-iter-count=%u", muxer_comp
,
231 muxer_comp
->muxer_notif_iters
?
232 muxer_comp
->muxer_notif_iters
->len
: 0);
234 if (muxer_comp
->muxer_notif_iters
) {
235 g_ptr_array_free(muxer_comp
->muxer_notif_iters
, TRUE
);
242 struct bt_value
*get_default_params(void)
244 struct bt_value
*params
;
247 params
= bt_value_map_create();
249 BT_LOGE_STR("Cannot create a map value object.");
253 ret
= bt_value_map_insert_bool(params
,
254 ASSUME_ABSOLUTE_CLOCK_CLASSES_PARAM_NAME
, false);
256 BT_LOGE_STR("Cannot add boolean value to map value object.");
270 int configure_muxer_comp(struct muxer_comp
*muxer_comp
, struct bt_value
*params
)
272 struct bt_value
*default_params
= NULL
;
273 struct bt_value
*real_params
= NULL
;
274 struct bt_value
*assume_absolute_clock_classes
= NULL
;
278 default_params
= get_default_params();
279 if (!default_params
) {
280 BT_LOGE("Cannot get default parameters: "
281 "muxer-comp-addr=%p", muxer_comp
);
285 real_params
= bt_value_map_extend(default_params
, params
);
287 BT_LOGE("Cannot extend default parameters map value: "
288 "muxer-comp-addr=%p, def-params-addr=%p, "
289 "params-addr=%p", muxer_comp
, default_params
,
294 assume_absolute_clock_classes
= bt_value_map_get(real_params
,
295 ASSUME_ABSOLUTE_CLOCK_CLASSES_PARAM_NAME
);
296 if (assume_absolute_clock_classes
&&
297 !bt_value_is_bool(assume_absolute_clock_classes
)) {
298 BT_LOGE("Expecting a boolean value for the `%s` parameter: "
299 "muxer-comp-addr=%p, value-type=%s",
300 ASSUME_ABSOLUTE_CLOCK_CLASSES_PARAM_NAME
, muxer_comp
,
301 bt_value_type_string(
302 bt_value_get_type(assume_absolute_clock_classes
)));
306 ret
= bt_value_bool_get(assume_absolute_clock_classes
, &bool_val
);
308 muxer_comp
->assume_absolute_clock_classes
= (bool) bool_val
;
309 BT_LOGD("Configured muxer component: muxer-comp-addr=%p, "
310 "assume-absolute-clock-classes=%d",
311 muxer_comp
, muxer_comp
->assume_absolute_clock_classes
);
318 bt_put(default_params
);
320 bt_put(assume_absolute_clock_classes
);
325 enum bt_component_status
muxer_init(
326 struct bt_private_component
*priv_comp
,
327 struct bt_value
*params
, void *init_data
)
330 enum bt_component_status status
= BT_COMPONENT_STATUS_OK
;
331 struct muxer_comp
*muxer_comp
= g_new0(struct muxer_comp
, 1);
333 BT_LOGD("Initializing muxer component: "
334 "comp-addr=%p, params-addr=%p", priv_comp
, params
);
337 BT_LOGE_STR("Failed to allocate one muxer component.");
341 ret
= configure_muxer_comp(muxer_comp
, params
);
343 BT_LOGE("Cannot configure muxer component: "
344 "muxer-comp-addr=%p, params-addr=%p",
349 muxer_comp
->muxer_notif_iters
= g_ptr_array_new();
350 if (!muxer_comp
->muxer_notif_iters
) {
351 BT_LOGE_STR("Failed to allocate a GPtrArray.");
355 muxer_comp
->priv_comp
= priv_comp
;
356 ret
= bt_private_component_set_user_data(priv_comp
, muxer_comp
);
358 status
= ensure_available_input_port(priv_comp
);
359 if (status
!= BT_COMPONENT_STATUS_OK
) {
360 BT_LOGE("Cannot ensure that at least one muxer component's input port is available: "
361 "muxer-comp-addr=%p, status=%s",
363 bt_component_status_string(status
));
367 status
= create_output_port(priv_comp
);
369 BT_LOGE("Cannot create muxer component's output port: "
370 "muxer-comp-addr=%p, status=%s",
372 bt_component_status_string(status
));
376 BT_LOGD("Initialized muxer component: "
377 "comp-addr=%p, params-addr=%p, muxer-comp-addr=%p",
378 priv_comp
, params
, muxer_comp
);
383 destroy_muxer_comp(muxer_comp
);
384 ret
= bt_private_component_set_user_data(priv_comp
, NULL
);
387 if (status
== BT_COMPONENT_STATUS_OK
) {
388 status
= BT_COMPONENT_STATUS_ERROR
;
396 void muxer_finalize(struct bt_private_component
*priv_comp
)
398 struct muxer_comp
*muxer_comp
=
399 bt_private_component_get_user_data(priv_comp
);
401 BT_LOGD("Finalizing muxer component: comp-addr=%p",
403 destroy_muxer_comp(muxer_comp
);
407 struct bt_notification_iterator
*create_notif_iter_on_input_port(
408 struct bt_private_port
*priv_port
, int *ret
)
410 struct bt_port
*port
= bt_port_from_private(priv_port
);
411 struct bt_notification_iterator
*notif_iter
= NULL
;
412 struct bt_private_connection
*priv_conn
= NULL
;
413 enum bt_connection_status conn_status
;
418 BT_ASSERT(bt_port_is_connected(port
));
419 priv_conn
= bt_private_port_get_private_connection(priv_port
);
420 BT_ASSERT(priv_conn
);
422 // TODO: Advance the iterator to >= the time of the latest
423 // returned notification by the muxer notification
424 // iterator which creates it.
425 conn_status
= bt_private_connection_create_notification_iterator(
426 priv_conn
, ¬if_iter
);
427 if (conn_status
!= BT_CONNECTION_STATUS_OK
) {
428 BT_LOGE("Cannot create upstream notification iterator on input port's connection: "
429 "port-addr=%p, port-name=\"%s\", conn-addr=%p, "
431 port
, bt_port_get_name(port
), priv_conn
,
432 bt_connection_status_string(conn_status
));
437 BT_LOGD("Created upstream notification iterator on input port's connection: "
438 "port-addr=%p, port-name=\"%s\", conn-addr=%p, "
439 "notif-iter-addr=%p",
440 port
, bt_port_get_name(port
), priv_conn
, notif_iter
);
449 enum bt_notification_iterator_status
muxer_upstream_notif_iter_next(
450 struct muxer_upstream_notif_iter
*muxer_upstream_notif_iter
)
452 enum bt_notification_iterator_status status
;
454 BT_LOGV("Calling upstream notification iterator's \"next\" method: "
455 "muxer-upstream-notif-iter-wrap-addr=%p, notif-iter-addr=%p",
456 muxer_upstream_notif_iter
,
457 muxer_upstream_notif_iter
->notif_iter
);
458 status
= bt_notification_iterator_next(
459 muxer_upstream_notif_iter
->notif_iter
);
460 BT_LOGV("Upstream notification iterator's \"next\" method returned: "
461 "status=%s", bt_notification_iterator_status_string(status
));
464 case BT_NOTIFICATION_ITERATOR_STATUS_OK
:
466 * Notification iterator's current notification is valid:
467 * it must be considered for muxing operations.
469 BT_LOGV_STR("Validated upstream notification iterator wrapper.");
470 muxer_upstream_notif_iter
->is_valid
= true;
472 case BT_NOTIFICATION_ITERATOR_STATUS_AGAIN
:
474 * Notification iterator's current notification is not
475 * valid anymore. Return
476 * BT_NOTIFICATION_ITERATOR_STATUS_AGAIN
479 BT_LOGV_STR("Invalidated upstream notification iterator wrapper because of BT_NOTIFICATION_ITERATOR_STATUS_AGAIN.");
480 muxer_upstream_notif_iter
->is_valid
= false;
482 case BT_NOTIFICATION_ITERATOR_STATUS_END
: /* Fall-through. */
483 case BT_NOTIFICATION_ITERATOR_STATUS_CANCELED
:
485 * Notification iterator reached the end: release it. It
486 * won't be considered again to find the youngest
489 BT_LOGV_STR("Invalidated upstream notification iterator wrapper because of BT_NOTIFICATION_ITERATOR_STATUS_END or BT_NOTIFICATION_ITERATOR_STATUS_CANCELED.");
490 BT_PUT(muxer_upstream_notif_iter
->notif_iter
);
491 muxer_upstream_notif_iter
->is_valid
= false;
492 status
= BT_NOTIFICATION_ITERATOR_STATUS_OK
;
495 /* Error or unsupported status code */
496 BT_LOGE("Error or unsupported status code: "
497 "status-code=%d", status
);
498 status
= BT_NOTIFICATION_ITERATOR_STATUS_ERROR
;
506 int muxer_notif_iter_handle_newly_connected_ports(
507 struct muxer_notif_iter
*muxer_notif_iter
)
511 BT_LOGV("Handling newly connected ports: "
512 "muxer-notif-iter-addr=%p", muxer_notif_iter
);
515 * Here we create one upstream notification iterator for each
516 * newly connected port. We do not perform an initial "next" on
517 * those new upstream notification iterators: they are
518 * invalidated, to be validated later. The list of newly
519 * connected ports to handle here is updated by
520 * muxer_port_connected().
523 GList
*node
= muxer_notif_iter
->newly_connected_priv_ports
;
524 struct bt_private_port
*priv_port
;
525 struct bt_port
*port
;
526 struct bt_notification_iterator
*upstream_notif_iter
= NULL
;
527 struct muxer_upstream_notif_iter
*muxer_upstream_notif_iter
;
533 priv_port
= node
->data
;
534 port
= bt_port_from_private(priv_port
);
537 if (!bt_port_is_connected(port
)) {
539 * Looks like this port is not connected
540 * anymore: we can't create an upstream
541 * notification iterator on its (non-existing)
542 * connection in this case.
548 upstream_notif_iter
= create_notif_iter_on_input_port(priv_port
,
551 /* create_notif_iter_on_input_port() logs errors */
552 BT_ASSERT(!upstream_notif_iter
);
556 muxer_upstream_notif_iter
=
557 muxer_notif_iter_add_upstream_notif_iter(
558 muxer_notif_iter
, upstream_notif_iter
,
560 BT_PUT(upstream_notif_iter
);
561 if (!muxer_upstream_notif_iter
) {
563 * muxer_notif_iter_add_upstream_notif_iter()
570 bt_put(upstream_notif_iter
);
572 muxer_notif_iter
->newly_connected_priv_ports
=
574 muxer_notif_iter
->newly_connected_priv_ports
,
590 int get_notif_ts_ns(struct muxer_comp
*muxer_comp
,
591 struct muxer_notif_iter
*muxer_notif_iter
,
592 struct bt_notification
*notif
, int64_t last_returned_ts_ns
,
595 struct bt_clock_class_priority_map
*cc_prio_map
= NULL
;
596 struct bt_clock_class
*clock_class
= NULL
;
597 struct bt_clock_value
*clock_value
= NULL
;
598 struct bt_event
*event
= NULL
;
600 const unsigned char *cc_uuid
;
606 BT_LOGV("Getting notification's timestamp: "
607 "muxer-notif-iter-addr=%p, notif-addr=%p, "
608 "last-returned-ts=%" PRId64
,
609 muxer_notif_iter
, notif
, last_returned_ts_ns
);
611 switch (bt_notification_get_type(notif
)) {
612 case BT_NOTIFICATION_TYPE_EVENT
:
614 bt_notification_event_get_clock_class_priority_map(
618 case BT_NOTIFICATION_TYPE_INACTIVITY
:
620 bt_notification_inactivity_get_clock_class_priority_map(
624 /* All the other notifications have a higher priority */
625 BT_LOGV_STR("Notification has no timestamp: using the last returned timestamp.");
626 *ts_ns
= last_returned_ts_ns
;
631 BT_LOGE("Cannot get notification's clock class priority map: "
632 "notif-addr=%p", notif
);
637 * If the clock class priority map is empty, then we consider
638 * that this notification has no time. In this case it's always
641 if (bt_clock_class_priority_map_get_clock_class_count(cc_prio_map
) == 0) {
642 BT_LOGV_STR("Notification's clock class priority map contains 0 clock classes: "
643 "using the last returned timestamp.");
644 *ts_ns
= last_returned_ts_ns
;
649 bt_clock_class_priority_map_get_highest_priority_clock_class(
652 BT_LOGE("Cannot get the clock class with the highest priority from clock class priority map: "
653 "cc-prio-map-addr=%p", cc_prio_map
);
657 cc_uuid
= bt_clock_class_get_uuid(clock_class
);
658 cc_name
= bt_clock_class_get_name(clock_class
);
660 if (muxer_notif_iter
->clock_class_expectation
==
661 MUXER_NOTIF_ITER_CLOCK_CLASS_EXPECTATION_ANY
) {
663 * This is the first clock class that this muxer
664 * notification iterator encounters. Its properties
665 * determine what to expect for the whole lifetime of
666 * the iterator without a true
667 * `assume-absolute-clock-classes` parameter.
669 if (bt_clock_class_is_absolute(clock_class
)) {
670 /* Expect absolute clock classes */
671 muxer_notif_iter
->clock_class_expectation
=
672 MUXER_NOTIF_ITER_CLOCK_CLASS_EXPECTATION_ABSOLUTE
;
676 * Expect non-absolute clock classes
677 * with a specific UUID.
679 muxer_notif_iter
->clock_class_expectation
=
680 MUXER_NOTIF_ITER_CLOCK_CLASS_EXPECTATION_NOT_ABS_SPEC_UUID
;
681 memcpy(muxer_notif_iter
->expected_clock_class_uuid
,
682 cc_uuid
, BABELTRACE_UUID_LEN
);
685 * Expect non-absolute clock classes
688 muxer_notif_iter
->clock_class_expectation
=
689 MUXER_NOTIF_ITER_CLOCK_CLASS_EXPECTATION_NOT_ABS_NO_UUID
;
694 if (!muxer_comp
->assume_absolute_clock_classes
) {
695 switch (muxer_notif_iter
->clock_class_expectation
) {
696 case MUXER_NOTIF_ITER_CLOCK_CLASS_EXPECTATION_ABSOLUTE
:
697 if (!bt_clock_class_is_absolute(clock_class
)) {
698 BT_LOGE("Expecting an absolute clock class, "
699 "but got a non-absolute one: "
700 "clock-class-addr=%p, clock-class-name=\"%s\"",
701 clock_class
, cc_name
);
705 case MUXER_NOTIF_ITER_CLOCK_CLASS_EXPECTATION_NOT_ABS_NO_UUID
:
706 if (bt_clock_class_is_absolute(clock_class
)) {
707 BT_LOGE("Expecting a non-absolute clock class with no UUID, "
708 "but got an absolute one: "
709 "clock-class-addr=%p, clock-class-name=\"%s\"",
710 clock_class
, cc_name
);
715 BT_LOGE("Expecting a non-absolute clock class with no UUID, "
716 "but got one with a UUID: "
717 "clock-class-addr=%p, clock-class-name=\"%s\", "
718 "uuid=\"%02x%02x%02x%02x-%02x%02x-%02x%02x-%02x%02x-%02x%02x%02x%02x%02x%02x\"",
719 clock_class
, cc_name
,
720 (unsigned int) cc_uuid
[0],
721 (unsigned int) cc_uuid
[1],
722 (unsigned int) cc_uuid
[2],
723 (unsigned int) cc_uuid
[3],
724 (unsigned int) cc_uuid
[4],
725 (unsigned int) cc_uuid
[5],
726 (unsigned int) cc_uuid
[6],
727 (unsigned int) cc_uuid
[7],
728 (unsigned int) cc_uuid
[8],
729 (unsigned int) cc_uuid
[9],
730 (unsigned int) cc_uuid
[10],
731 (unsigned int) cc_uuid
[11],
732 (unsigned int) cc_uuid
[12],
733 (unsigned int) cc_uuid
[13],
734 (unsigned int) cc_uuid
[14],
735 (unsigned int) cc_uuid
[15]);
739 case MUXER_NOTIF_ITER_CLOCK_CLASS_EXPECTATION_NOT_ABS_SPEC_UUID
:
740 if (bt_clock_class_is_absolute(clock_class
)) {
741 BT_LOGE("Expecting a non-absolute clock class with a specific UUID, "
742 "but got an absolute one: "
743 "clock-class-addr=%p, clock-class-name=\"%s\"",
744 clock_class
, cc_name
);
749 BT_LOGE("Expecting a non-absolute clock class with a specific UUID, "
750 "but got one with no UUID: "
751 "clock-class-addr=%p, clock-class-name=\"%s\"",
752 clock_class
, cc_name
);
756 if (memcmp(muxer_notif_iter
->expected_clock_class_uuid
,
757 cc_uuid
, BABELTRACE_UUID_LEN
) != 0) {
758 BT_LOGE("Expecting a non-absolute clock class with a specific UUID, "
759 "but got one with different UUID: "
760 "clock-class-addr=%p, clock-class-name=\"%s\", "
761 "expected-uuid=\"%02x%02x%02x%02x-%02x%02x-%02x%02x-%02x%02x-%02x%02x%02x%02x%02x%02x\", "
762 "uuid=\"%02x%02x%02x%02x-%02x%02x-%02x%02x-%02x%02x-%02x%02x%02x%02x%02x%02x\"",
763 clock_class
, cc_name
,
764 (unsigned int) muxer_notif_iter
->expected_clock_class_uuid
[0],
765 (unsigned int) muxer_notif_iter
->expected_clock_class_uuid
[1],
766 (unsigned int) muxer_notif_iter
->expected_clock_class_uuid
[2],
767 (unsigned int) muxer_notif_iter
->expected_clock_class_uuid
[3],
768 (unsigned int) muxer_notif_iter
->expected_clock_class_uuid
[4],
769 (unsigned int) muxer_notif_iter
->expected_clock_class_uuid
[5],
770 (unsigned int) muxer_notif_iter
->expected_clock_class_uuid
[6],
771 (unsigned int) muxer_notif_iter
->expected_clock_class_uuid
[7],
772 (unsigned int) muxer_notif_iter
->expected_clock_class_uuid
[8],
773 (unsigned int) muxer_notif_iter
->expected_clock_class_uuid
[9],
774 (unsigned int) muxer_notif_iter
->expected_clock_class_uuid
[10],
775 (unsigned int) muxer_notif_iter
->expected_clock_class_uuid
[11],
776 (unsigned int) muxer_notif_iter
->expected_clock_class_uuid
[12],
777 (unsigned int) muxer_notif_iter
->expected_clock_class_uuid
[13],
778 (unsigned int) muxer_notif_iter
->expected_clock_class_uuid
[14],
779 (unsigned int) muxer_notif_iter
->expected_clock_class_uuid
[15],
780 (unsigned int) cc_uuid
[0],
781 (unsigned int) cc_uuid
[1],
782 (unsigned int) cc_uuid
[2],
783 (unsigned int) cc_uuid
[3],
784 (unsigned int) cc_uuid
[4],
785 (unsigned int) cc_uuid
[5],
786 (unsigned int) cc_uuid
[6],
787 (unsigned int) cc_uuid
[7],
788 (unsigned int) cc_uuid
[8],
789 (unsigned int) cc_uuid
[9],
790 (unsigned int) cc_uuid
[10],
791 (unsigned int) cc_uuid
[11],
792 (unsigned int) cc_uuid
[12],
793 (unsigned int) cc_uuid
[13],
794 (unsigned int) cc_uuid
[14],
795 (unsigned int) cc_uuid
[15]);
801 BT_LOGF("Unexpected clock class expectation: "
802 "expectation-code=%d",
803 muxer_notif_iter
->clock_class_expectation
);
808 switch (bt_notification_get_type(notif
)) {
809 case BT_NOTIFICATION_TYPE_EVENT
:
810 event
= bt_notification_event_get_event(notif
);
812 clock_value
= bt_event_get_clock_value(event
,
815 case BT_NOTIFICATION_TYPE_INACTIVITY
:
816 clock_value
= bt_notification_inactivity_get_clock_value(
820 BT_LOGF("Unexpected notification type at this point: "
821 "type=%d", bt_notification_get_type(notif
));
826 BT_LOGE("Cannot get notification's clock value for clock class: "
827 "clock-class-addr=%p, clock-class-name=\"%s\"",
828 clock_class
, cc_name
);
832 ret
= bt_clock_value_get_value_ns_from_epoch(clock_value
, ts_ns
);
834 BT_LOGE("Cannot get nanoseconds from Epoch of clock value: "
835 "clock-value-addr=%p", clock_value
);
846 BT_LOGV("Found notification's timestamp: "
847 "muxer-notif-iter-addr=%p, notif-addr=%p, "
848 "last-returned-ts=%" PRId64
", ts=%" PRId64
,
849 muxer_notif_iter
, notif
, last_returned_ts_ns
,
861 * This function finds the youngest available notification amongst the
862 * non-ended upstream notification iterators and returns the upstream
863 * notification iterator which has it, or
864 * BT_NOTIFICATION_ITERATOR_STATUS_END if there's no available
867 * This function does NOT:
869 * * Update any upstream notification iterator.
870 * * Check for newly connected ports.
871 * * Check the upstream notification iterators to retry.
873 * On sucess, this function sets *muxer_upstream_notif_iter to the
874 * upstream notification iterator of which the current notification is
875 * the youngest, and sets *ts_ns to its time.
878 enum bt_notification_iterator_status
879 muxer_notif_iter_youngest_upstream_notif_iter(
880 struct muxer_comp
*muxer_comp
,
881 struct muxer_notif_iter
*muxer_notif_iter
,
882 struct muxer_upstream_notif_iter
**muxer_upstream_notif_iter
,
887 int64_t youngest_ts_ns
= INT64_MAX
;
888 enum bt_notification_iterator_status status
=
889 BT_NOTIFICATION_ITERATOR_STATUS_OK
;
891 BT_ASSERT(muxer_comp
);
892 BT_ASSERT(muxer_notif_iter
);
893 BT_ASSERT(muxer_upstream_notif_iter
);
894 *muxer_upstream_notif_iter
= NULL
;
896 for (i
= 0; i
< muxer_notif_iter
->muxer_upstream_notif_iters
->len
; i
++) {
897 struct bt_notification
*notif
;
898 struct muxer_upstream_notif_iter
*cur_muxer_upstream_notif_iter
=
899 g_ptr_array_index(muxer_notif_iter
->muxer_upstream_notif_iters
, i
);
902 if (!cur_muxer_upstream_notif_iter
->notif_iter
) {
903 /* This upstream notification iterator is ended */
904 BT_LOGV("Skipping ended upstream notification iterator: "
905 "muxer-upstream-notif-iter-wrap-addr=%p",
906 cur_muxer_upstream_notif_iter
);
910 BT_ASSERT(cur_muxer_upstream_notif_iter
->is_valid
);
911 notif
= bt_notification_iterator_get_notification(
912 cur_muxer_upstream_notif_iter
->notif_iter
);
914 ret
= get_notif_ts_ns(muxer_comp
, muxer_notif_iter
, notif
,
915 muxer_notif_iter
->last_returned_ts_ns
, ¬if_ts_ns
);
918 /* get_notif_ts_ns() logs errors */
919 *muxer_upstream_notif_iter
= NULL
;
920 status
= BT_NOTIFICATION_ITERATOR_STATUS_ERROR
;
924 if (notif_ts_ns
<= youngest_ts_ns
) {
925 *muxer_upstream_notif_iter
=
926 cur_muxer_upstream_notif_iter
;
927 youngest_ts_ns
= notif_ts_ns
;
928 *ts_ns
= youngest_ts_ns
;
932 if (!*muxer_upstream_notif_iter
) {
933 status
= BT_NOTIFICATION_ITERATOR_STATUS_END
;
942 enum bt_notification_iterator_status
validate_muxer_upstream_notif_iter(
943 struct muxer_upstream_notif_iter
*muxer_upstream_notif_iter
)
945 enum bt_notification_iterator_status status
=
946 BT_NOTIFICATION_ITERATOR_STATUS_OK
;
948 BT_LOGV("Validating muxer's upstream notification iterator wrapper: "
949 "muxer-upstream-notif-iter-wrap-addr=%p",
950 muxer_upstream_notif_iter
);
952 if (muxer_upstream_notif_iter
->is_valid
||
953 !muxer_upstream_notif_iter
->notif_iter
) {
957 /* muxer_upstream_notif_iter_next() logs details/errors */
958 status
= muxer_upstream_notif_iter_next(muxer_upstream_notif_iter
);
965 enum bt_notification_iterator_status
validate_muxer_upstream_notif_iters(
966 struct muxer_notif_iter
*muxer_notif_iter
)
968 enum bt_notification_iterator_status status
=
969 BT_NOTIFICATION_ITERATOR_STATUS_OK
;
972 BT_LOGV("Validating muxer's upstream notification iterator wrappers: "
973 "muxer-notif-iter-addr=%p", muxer_notif_iter
);
975 for (i
= 0; i
< muxer_notif_iter
->muxer_upstream_notif_iters
->len
; i
++) {
976 struct muxer_upstream_notif_iter
*muxer_upstream_notif_iter
=
978 muxer_notif_iter
->muxer_upstream_notif_iters
,
981 status
= validate_muxer_upstream_notif_iter(
982 muxer_upstream_notif_iter
);
983 if (status
!= BT_NOTIFICATION_ITERATOR_STATUS_OK
) {
985 BT_LOGE("Cannot validate muxer's upstream notification iterator wrapper: "
986 "muxer-notif-iter-addr=%p, "
987 "muxer-upstream-notif-iter-wrap-addr=%p",
989 muxer_upstream_notif_iter
);
991 BT_LOGV("Cannot validate muxer's upstream notification iterator wrapper: "
992 "muxer-notif-iter-addr=%p, "
993 "muxer-upstream-notif-iter-wrap-addr=%p",
995 muxer_upstream_notif_iter
);
1002 * Remove this muxer upstream notification iterator
1003 * if it's ended or canceled.
1005 if (!muxer_upstream_notif_iter
->notif_iter
) {
1007 * Use g_ptr_array_remove_fast() because the
1008 * order of those elements is not important.
1010 BT_LOGV("Removing muxer's upstream notification iterator wrapper: ended or canceled: "
1011 "muxer-notif-iter-addr=%p, "
1012 "muxer-upstream-notif-iter-wrap-addr=%p",
1013 muxer_notif_iter
, muxer_upstream_notif_iter
);
1014 g_ptr_array_remove_index_fast(
1015 muxer_notif_iter
->muxer_upstream_notif_iters
,
1026 struct bt_notification_iterator_next_method_return
muxer_notif_iter_do_next(
1027 struct muxer_comp
*muxer_comp
,
1028 struct muxer_notif_iter
*muxer_notif_iter
)
1030 struct muxer_upstream_notif_iter
*muxer_upstream_notif_iter
= NULL
;
1031 struct bt_notification_iterator_next_method_return next_return
= {
1032 .notification
= NULL
,
1033 .status
= BT_NOTIFICATION_ITERATOR_STATUS_OK
,
1035 int64_t next_return_ts
;
1038 int ret
= muxer_notif_iter_handle_newly_connected_ports(
1042 BT_LOGE("Cannot handle newly connected input ports for muxer's notification iterator: "
1043 "muxer-comp-addr=%p, muxer-notif-iter-addr=%p, "
1045 muxer_comp
, muxer_notif_iter
, ret
);
1046 next_return
.status
=
1047 BT_NOTIFICATION_ITERATOR_STATUS_ERROR
;
1051 next_return
.status
=
1052 validate_muxer_upstream_notif_iters(muxer_notif_iter
);
1053 if (next_return
.status
!= BT_NOTIFICATION_ITERATOR_STATUS_OK
) {
1054 /* validate_muxer_upstream_notif_iters() logs details */
1059 * At this point, we know that all the existing upstream
1060 * notification iterators are valid. However the
1061 * operations to validate them (during
1062 * validate_muxer_upstream_notif_iters()) may have
1063 * connected new ports. If no ports were connected
1064 * during this operation, exit the loop.
1066 if (!muxer_notif_iter
->newly_connected_priv_ports
) {
1067 BT_LOGV("Not breaking this loop: muxer's notification iterator still has newly connected input ports to handle: "
1068 "muxer-comp-addr=%p", muxer_comp
);
1073 BT_ASSERT(!muxer_notif_iter
->newly_connected_priv_ports
);
1076 * At this point we know that all the existing upstream
1077 * notification iterators are valid. We can find the one,
1078 * amongst those, of which the current notification is the
1081 next_return
.status
=
1082 muxer_notif_iter_youngest_upstream_notif_iter(muxer_comp
,
1083 muxer_notif_iter
, &muxer_upstream_notif_iter
,
1085 if (next_return
.status
< 0 ||
1086 next_return
.status
== BT_NOTIFICATION_ITERATOR_STATUS_END
||
1087 next_return
.status
== BT_NOTIFICATION_ITERATOR_STATUS_CANCELED
) {
1088 if (next_return
.status
< 0) {
1089 BT_LOGE("Cannot find the youngest upstream notification iterator wrapper: "
1091 bt_notification_iterator_status_string(next_return
.status
));
1093 BT_LOGV("Cannot find the youngest upstream notification iterator wrapper: "
1095 bt_notification_iterator_status_string(next_return
.status
));
1101 if (next_return_ts
< muxer_notif_iter
->last_returned_ts_ns
) {
1102 BT_LOGE("Youngest upstream notification iterator wrapper's timestamp is less than muxer's notification iterator's last returned timestamp: "
1103 "muxer-notif-iter-addr=%p, ts=%" PRId64
", "
1104 "last-returned-ts=%" PRId64
,
1105 muxer_notif_iter
, next_return_ts
,
1106 muxer_notif_iter
->last_returned_ts_ns
);
1107 next_return
.status
= BT_NOTIFICATION_ITERATOR_STATUS_ERROR
;
1111 BT_LOGV("Found youngest upstream notification iterator wrapper: "
1112 "muxer-notif-iter-addr=%p, "
1113 "muxer-upstream-notif-iter-wrap-addr=%p, "
1115 muxer_notif_iter
, muxer_upstream_notif_iter
, next_return_ts
);
1116 BT_ASSERT(next_return
.status
== BT_NOTIFICATION_ITERATOR_STATUS_OK
);
1117 BT_ASSERT(muxer_upstream_notif_iter
);
1118 next_return
.notification
= bt_notification_iterator_get_notification(
1119 muxer_upstream_notif_iter
->notif_iter
);
1120 BT_ASSERT(next_return
.notification
);
1123 * We invalidate the upstream notification iterator so that, the
1124 * next time this function is called,
1125 * validate_muxer_upstream_notif_iters() will make it valid.
1127 muxer_upstream_notif_iter
->is_valid
= false;
1128 muxer_notif_iter
->last_returned_ts_ns
= next_return_ts
;
1135 void destroy_muxer_notif_iter(struct muxer_notif_iter
*muxer_notif_iter
)
1137 if (!muxer_notif_iter
) {
1141 BT_LOGD("Destroying muxer component's notification iterator: "
1142 "muxer-notif-iter-addr=%p", muxer_notif_iter
);
1144 if (muxer_notif_iter
->muxer_upstream_notif_iters
) {
1145 BT_LOGD_STR("Destroying muxer's upstream notification iterator wrappers.");
1147 muxer_notif_iter
->muxer_upstream_notif_iters
, TRUE
);
1150 g_list_free(muxer_notif_iter
->newly_connected_priv_ports
);
1151 g_free(muxer_notif_iter
);
1155 int muxer_notif_iter_init_newly_connected_ports(struct muxer_comp
*muxer_comp
,
1156 struct muxer_notif_iter
*muxer_notif_iter
)
1158 struct bt_component
*comp
;
1164 * Add the connected input ports to this muxer notification
1165 * iterator's list of newly connected ports. They will be
1166 * handled by muxer_notif_iter_handle_newly_connected_ports().
1168 comp
= bt_component_from_private(muxer_comp
->priv_comp
);
1170 count
= bt_component_filter_get_input_port_count(comp
);
1172 BT_LOGD("No input port to initialize for muxer component's notification iterator: "
1173 "muxer-comp-addr=%p, muxer-notif-iter-addr=%p",
1174 muxer_comp
, muxer_notif_iter
);
1178 for (i
= 0; i
< count
; i
++) {
1179 struct bt_private_port
*priv_port
=
1180 bt_private_component_filter_get_input_private_port_by_index(
1181 muxer_comp
->priv_comp
, i
);
1182 struct bt_port
*port
;
1184 BT_ASSERT(priv_port
);
1185 port
= bt_port_from_private(priv_port
);
1188 if (!bt_port_is_connected(port
)) {
1189 BT_LOGD("Skipping input port: not connected: "
1190 "muxer-comp-addr=%p, port-addr=%p, port-name\"%s\"",
1191 muxer_comp
, port
, bt_port_get_name(port
));
1199 muxer_notif_iter
->newly_connected_priv_ports
=
1201 muxer_notif_iter
->newly_connected_priv_ports
,
1203 if (!muxer_notif_iter
->newly_connected_priv_ports
) {
1204 BT_LOGE("Cannot append port to muxer's notification iterator list of newly connected input ports: "
1205 "port-addr=%p, port-name=\"%s\", "
1206 "muxer-notif-iter-addr=%p", port
,
1207 bt_port_get_name(port
), muxer_notif_iter
);
1212 BT_LOGD("Appended port to muxer's notification iterator list of newly connected input ports: "
1213 "port-addr=%p, port-name=\"%s\", "
1214 "muxer-notif-iter-addr=%p", port
,
1215 bt_port_get_name(port
), muxer_notif_iter
);
1224 enum bt_notification_iterator_status
muxer_notif_iter_init(
1225 struct bt_private_connection_private_notification_iterator
*priv_notif_iter
,
1226 struct bt_private_port
*output_priv_port
)
1228 struct muxer_comp
*muxer_comp
= NULL
;
1229 struct muxer_notif_iter
*muxer_notif_iter
= NULL
;
1230 struct bt_private_component
*priv_comp
= NULL
;
1231 enum bt_notification_iterator_status status
=
1232 BT_NOTIFICATION_ITERATOR_STATUS_OK
;
1235 priv_comp
= bt_private_connection_private_notification_iterator_get_private_component(
1237 BT_ASSERT(priv_comp
);
1238 muxer_comp
= bt_private_component_get_user_data(priv_comp
);
1239 BT_ASSERT(muxer_comp
);
1240 BT_LOGD("Initializing muxer component's notification iterator: "
1241 "comp-addr=%p, muxer-comp-addr=%p, notif-iter-addr=%p",
1242 priv_comp
, muxer_comp
, priv_notif_iter
);
1244 if (muxer_comp
->initializing_muxer_notif_iter
) {
1246 * Weird, unhandled situation detected: downstream
1247 * creates a muxer notification iterator while creating
1248 * another muxer notification iterator (same component).
1250 BT_LOGE("Recursive initialization of muxer component's notification iterator: "
1251 "comp-addr=%p, muxer-comp-addr=%p, notif-iter-addr=%p",
1252 priv_comp
, muxer_comp
, priv_notif_iter
);
1256 muxer_comp
->initializing_muxer_notif_iter
= true;
1257 muxer_notif_iter
= g_new0(struct muxer_notif_iter
, 1);
1258 if (!muxer_notif_iter
) {
1259 BT_LOGE_STR("Failed to allocate one muxer component's notification iterator.");
1263 muxer_notif_iter
->last_returned_ts_ns
= INT64_MIN
;
1264 muxer_notif_iter
->muxer_upstream_notif_iters
=
1265 g_ptr_array_new_with_free_func(
1266 (GDestroyNotify
) destroy_muxer_upstream_notif_iter
);
1267 if (!muxer_notif_iter
->muxer_upstream_notif_iters
) {
1268 BT_LOGE_STR("Failed to allocate a GPtrArray.");
1273 * Add the muxer notification iterator to the component's array
1274 * of muxer notification iterators here because
1275 * muxer_notif_iter_init_newly_connected_ports() can cause
1276 * muxer_port_connected() to be called, which adds the newly
1277 * connected port to each muxer notification iterator's list of
1278 * newly connected ports.
1280 g_ptr_array_add(muxer_comp
->muxer_notif_iters
, muxer_notif_iter
);
1281 ret
= muxer_notif_iter_init_newly_connected_ports(muxer_comp
,
1284 BT_LOGE("Cannot initialize newly connected input ports for muxer component's notification iterator: "
1285 "comp-addr=%p, muxer-comp-addr=%p, "
1286 "muxer-notif-iter-addr=%p, notif-iter-addr=%p, ret=%d",
1287 priv_comp
, muxer_comp
, muxer_notif_iter
,
1288 priv_notif_iter
, ret
);
1292 ret
= bt_private_connection_private_notification_iterator_set_user_data(priv_notif_iter
,
1294 BT_ASSERT(ret
== 0);
1295 BT_LOGD("Initialized muxer component's notification iterator: "
1296 "comp-addr=%p, muxer-comp-addr=%p, muxer-notif-iter-addr=%p, "
1297 "notif-iter-addr=%p",
1298 priv_comp
, muxer_comp
, muxer_notif_iter
, priv_notif_iter
);
1302 if (g_ptr_array_index(muxer_comp
->muxer_notif_iters
,
1303 muxer_comp
->muxer_notif_iters
->len
- 1) == muxer_notif_iter
) {
1304 g_ptr_array_remove_index(muxer_comp
->muxer_notif_iters
,
1305 muxer_comp
->muxer_notif_iters
->len
- 1);
1308 destroy_muxer_notif_iter(muxer_notif_iter
);
1309 ret
= bt_private_connection_private_notification_iterator_set_user_data(priv_notif_iter
,
1311 BT_ASSERT(ret
== 0);
1312 status
= BT_NOTIFICATION_ITERATOR_STATUS_ERROR
;
1315 muxer_comp
->initializing_muxer_notif_iter
= false;
1321 void muxer_notif_iter_finalize(
1322 struct bt_private_connection_private_notification_iterator
*priv_notif_iter
)
1324 struct muxer_notif_iter
*muxer_notif_iter
=
1325 bt_private_connection_private_notification_iterator_get_user_data(priv_notif_iter
);
1326 struct bt_private_component
*priv_comp
= NULL
;
1327 struct muxer_comp
*muxer_comp
= NULL
;
1329 priv_comp
= bt_private_connection_private_notification_iterator_get_private_component(
1331 BT_ASSERT(priv_comp
);
1332 muxer_comp
= bt_private_component_get_user_data(priv_comp
);
1333 BT_LOGD("Finalizing muxer component's notification iterator: "
1334 "comp-addr=%p, muxer-comp-addr=%p, muxer-notif-iter-addr=%p, "
1335 "notif-iter-addr=%p",
1336 priv_comp
, muxer_comp
, muxer_notif_iter
, priv_notif_iter
);
1339 (void) g_ptr_array_remove_fast(muxer_comp
->muxer_notif_iters
,
1341 destroy_muxer_notif_iter(muxer_notif_iter
);
1348 struct bt_notification_iterator_next_method_return
muxer_notif_iter_next(
1349 struct bt_private_connection_private_notification_iterator
*priv_notif_iter
)
1351 struct bt_notification_iterator_next_method_return next_ret
;
1352 struct muxer_notif_iter
*muxer_notif_iter
=
1353 bt_private_connection_private_notification_iterator_get_user_data(priv_notif_iter
);
1354 struct bt_private_component
*priv_comp
= NULL
;
1355 struct muxer_comp
*muxer_comp
= NULL
;
1357 BT_ASSERT(muxer_notif_iter
);
1358 priv_comp
= bt_private_connection_private_notification_iterator_get_private_component(
1360 BT_ASSERT(priv_comp
);
1361 muxer_comp
= bt_private_component_get_user_data(priv_comp
);
1362 BT_ASSERT(muxer_comp
);
1364 BT_LOGV("Muxer component's notification iterator's \"next\" method called: "
1365 "comp-addr=%p, muxer-comp-addr=%p, muxer-notif-iter-addr=%p, "
1366 "notif-iter-addr=%p",
1367 priv_comp
, muxer_comp
, muxer_notif_iter
, priv_notif_iter
);
1369 /* Are we in an error state set elsewhere? */
1370 if (unlikely(muxer_comp
->error
)) {
1371 BT_LOGE("Muxer component is already in an error state: returning BT_NOTIFICATION_ITERATOR_STATUS_ERROR: "
1372 "comp-addr=%p, muxer-comp-addr=%p, muxer-notif-iter-addr=%p, "
1373 "notif-iter-addr=%p",
1374 priv_comp
, muxer_comp
, muxer_notif_iter
, priv_notif_iter
);
1375 next_ret
.notification
= NULL
;
1376 next_ret
.status
= BT_NOTIFICATION_ITERATOR_STATUS_ERROR
;
1380 next_ret
= muxer_notif_iter_do_next(muxer_comp
, muxer_notif_iter
);
1381 if (next_ret
.status
< 0) {
1382 BT_LOGE("Cannot get next notification: "
1383 "comp-addr=%p, muxer-comp-addr=%p, muxer-notif-iter-addr=%p, "
1384 "notif-iter-addr=%p, status=%s",
1385 priv_comp
, muxer_comp
, muxer_notif_iter
, priv_notif_iter
,
1386 bt_notification_iterator_status_string(next_ret
.status
));
1388 BT_LOGV("Returning from muxer component's notification iterator's \"next\" method: "
1389 "status=%s, notif-addr=%p",
1390 bt_notification_iterator_status_string(next_ret
.status
),
1391 next_ret
.notification
);
1400 void muxer_port_connected(
1401 struct bt_private_component
*priv_comp
,
1402 struct bt_private_port
*self_private_port
,
1403 struct bt_port
*other_port
)
1405 struct bt_port
*self_port
=
1406 bt_port_from_private(self_private_port
);
1407 struct muxer_comp
*muxer_comp
=
1408 bt_private_component_get_user_data(priv_comp
);
1412 BT_ASSERT(self_port
);
1413 BT_ASSERT(muxer_comp
);
1414 BT_LOGD("Port connected: "
1415 "comp-addr=%p, muxer-comp-addr=%p, "
1416 "port-addr=%p, port-name=\"%s\", "
1417 "other-port-addr=%p, other-port-name=\"%s\"",
1418 priv_comp
, muxer_comp
, self_port
, bt_port_get_name(self_port
),
1419 other_port
, bt_port_get_name(other_port
));
1421 if (bt_port_get_type(self_port
) == BT_PORT_TYPE_OUTPUT
) {
1425 for (i
= 0; i
< muxer_comp
->muxer_notif_iters
->len
; i
++) {
1426 struct muxer_notif_iter
*muxer_notif_iter
=
1427 g_ptr_array_index(muxer_comp
->muxer_notif_iters
, i
);
1430 * Add this port to the list of newly connected ports
1431 * for this muxer notification iterator. We append at
1432 * the end of this list while
1433 * muxer_notif_iter_handle_newly_connected_ports()
1434 * removes the nodes from the beginning.
1436 muxer_notif_iter
->newly_connected_priv_ports
=
1438 muxer_notif_iter
->newly_connected_priv_ports
,
1440 if (!muxer_notif_iter
->newly_connected_priv_ports
) {
1441 BT_LOGE("Cannot append port to muxer's notification iterator list of newly connected input ports: "
1442 "port-addr=%p, port-name=\"%s\", "
1443 "muxer-notif-iter-addr=%p", self_port
,
1444 bt_port_get_name(self_port
), muxer_notif_iter
);
1445 muxer_comp
->error
= true;
1449 BT_LOGD("Appended port to muxer's notification iterator list of newly connected input ports: "
1450 "port-addr=%p, port-name=\"%s\", "
1451 "muxer-notif-iter-addr=%p", self_port
,
1452 bt_port_get_name(self_port
), muxer_notif_iter
);
1455 /* One less available input port */
1456 muxer_comp
->available_input_ports
--;
1457 ret
= ensure_available_input_port(priv_comp
);
1460 * Only way to report an error later since this
1461 * method does not return anything.
1463 BT_LOGE("Cannot ensure that at least one muxer component's input port is available: "
1464 "muxer-comp-addr=%p, status=%s",
1465 muxer_comp
, bt_component_status_string(ret
));
1466 muxer_comp
->error
= true;
1475 void muxer_port_disconnected(struct bt_private_component
*priv_comp
,
1476 struct bt_private_port
*priv_port
)
1478 struct bt_port
*port
= bt_port_from_private(priv_port
);
1479 struct muxer_comp
*muxer_comp
=
1480 bt_private_component_get_user_data(priv_comp
);
1483 BT_ASSERT(muxer_comp
);
1484 BT_LOGD("Port disconnected: "
1485 "comp-addr=%p, muxer-comp-addr=%p, port-addr=%p, "
1486 "port-name=\"%s\"", priv_comp
, muxer_comp
,
1487 port
, bt_port_get_name(port
));
1490 * There's nothing special to do when a port is disconnected
1491 * because this component deals with upstream notification
1492 * iterators which were already created thanks to connected
1493 * ports. The fact that the port is disconnected does not cancel
1494 * the upstream notification iterators created using its
1495 * connection: they still exist, even if the connection is dead.
1496 * The only way to remove an upstream notification iterator is
1497 * for its "next" operation to return
1498 * BT_NOTIFICATION_ITERATOR_STATUS_END.
1500 if (bt_port_get_type(port
) == BT_PORT_TYPE_INPUT
) {
1501 /* One more available input port */
1502 muxer_comp
->available_input_ports
++;
1503 BT_LOGD("Leaving disconnected input port available for future connections: "
1504 "comp-addr=%p, muxer-comp-addr=%p, port-addr=%p, "
1505 "port-name=\"%s\", avail-input-port-count=%zu",
1506 priv_comp
, muxer_comp
, port
, bt_port_get_name(port
),
1507 muxer_comp
->available_input_ports
);