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>
38 #include <babeltrace/common-internal.h>
42 #define ASSUME_ABSOLUTE_CLOCK_CLASSES_PARAM_NAME "assume-absolute-clock-classes"
47 * bt_private_connection_private_notification_iterator *
50 GPtrArray
*muxer_notif_iters
;
53 struct bt_private_component
*priv_comp
;
54 unsigned int next_port_num
;
55 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
;
64 /* Contains `struct bt_notification *`, owned by this */
68 enum muxer_notif_iter_clock_class_expectation
{
69 MUXER_NOTIF_ITER_CLOCK_CLASS_EXPECTATION_ANY
= 0,
70 MUXER_NOTIF_ITER_CLOCK_CLASS_EXPECTATION_ABSOLUTE
,
71 MUXER_NOTIF_ITER_CLOCK_CLASS_EXPECTATION_NOT_ABS_SPEC_UUID
,
72 MUXER_NOTIF_ITER_CLOCK_CLASS_EXPECTATION_NOT_ABS_NO_UUID
,
75 struct muxer_notif_iter
{
77 * Array of struct muxer_upstream_notif_iter * (owned by this).
79 * NOTE: This array is searched in linearly to find the youngest
80 * current notification. Keep this until benchmarks confirm that
81 * another data structure is faster than this for our typical
84 GPtrArray
*muxer_upstream_notif_iters
;
87 * List of "recently" connected input ports (weak) to
88 * handle by this muxer notification iterator.
89 * muxer_port_connected() adds entries to this list, and the
90 * entries are removed when a notification iterator is created
91 * on the port's connection and put into
92 * muxer_upstream_notif_iters above by
93 * muxer_notif_iter_handle_newly_connected_ports().
95 GList
*newly_connected_priv_ports
;
97 /* Last time returned in a notification */
98 int64_t last_returned_ts_ns
;
100 /* Clock class expectation state */
101 enum muxer_notif_iter_clock_class_expectation clock_class_expectation
;
104 * Expected clock class UUID, only valid when
105 * clock_class_expectation is
106 * MUXER_NOTIF_ITER_CLOCK_CLASS_EXPECTATION_NOT_ABS_SPEC_UUID.
108 unsigned char expected_clock_class_uuid
[BABELTRACE_UUID_LEN
];
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_LOGD("Destroying muxer's upstream notification iterator wrapper: "
120 "addr=%p, notif-iter-addr=%p, queue-len=%u",
121 muxer_upstream_notif_iter
,
122 muxer_upstream_notif_iter
->notif_iter
,
123 muxer_upstream_notif_iter
->notifs
->length
);
124 bt_object_put_ref(muxer_upstream_notif_iter
->notif_iter
);
126 if (muxer_upstream_notif_iter
->notifs
) {
127 struct bt_notification
*notif
;
129 while ((notif
= g_queue_pop_head(
130 muxer_upstream_notif_iter
->notifs
))) {
131 bt_object_put_ref(notif
);
134 g_queue_free(muxer_upstream_notif_iter
->notifs
);
137 g_free(muxer_upstream_notif_iter
);
141 struct muxer_upstream_notif_iter
*muxer_notif_iter_add_upstream_notif_iter(
142 struct muxer_notif_iter
*muxer_notif_iter
,
143 struct bt_notification_iterator
*notif_iter
,
144 struct bt_private_port
*priv_port
)
146 struct muxer_upstream_notif_iter
*muxer_upstream_notif_iter
=
147 g_new0(struct muxer_upstream_notif_iter
, 1);
149 if (!muxer_upstream_notif_iter
) {
150 BT_LOGE_STR("Failed to allocate one muxer's upstream notification iterator wrapper.");
154 muxer_upstream_notif_iter
->notif_iter
= bt_object_get_ref(notif_iter
);
155 muxer_upstream_notif_iter
->notifs
= g_queue_new();
156 if (!muxer_upstream_notif_iter
->notifs
) {
157 BT_LOGE_STR("Failed to allocate a GQueue.");
162 g_ptr_array_add(muxer_notif_iter
->muxer_upstream_notif_iters
,
163 muxer_upstream_notif_iter
);
164 BT_LOGD("Added muxer's upstream notification iterator wrapper: "
165 "addr=%p, muxer-notif-iter-addr=%p, notif-iter-addr=%p",
166 muxer_upstream_notif_iter
, muxer_notif_iter
,
170 return muxer_upstream_notif_iter
;
174 enum bt_component_status
ensure_available_input_port(
175 struct bt_private_component
*priv_comp
)
177 struct muxer_comp
*muxer_comp
=
178 bt_private_component_get_user_data(priv_comp
);
179 enum bt_component_status status
= BT_COMPONENT_STATUS_OK
;
180 GString
*port_name
= NULL
;
182 BT_ASSERT(muxer_comp
);
184 if (muxer_comp
->available_input_ports
>= 1) {
188 port_name
= g_string_new("in");
190 BT_LOGE_STR("Failed to allocate a GString.");
191 status
= BT_COMPONENT_STATUS_NOMEM
;
195 g_string_append_printf(port_name
, "%u", muxer_comp
->next_port_num
);
196 status
= bt_private_component_filter_add_input_private_port(
197 priv_comp
, port_name
->str
, NULL
, NULL
);
198 if (status
!= BT_COMPONENT_STATUS_OK
) {
199 BT_LOGE("Cannot add input port to muxer component: "
200 "port-name=\"%s\", comp-addr=%p, status=%s",
201 port_name
->str
, priv_comp
,
202 bt_component_status_string(status
));
206 muxer_comp
->available_input_ports
++;
207 muxer_comp
->next_port_num
++;
208 BT_LOGD("Added one input port to muxer component: "
209 "port-name=\"%s\", comp-addr=%p",
210 port_name
->str
, priv_comp
);
213 g_string_free(port_name
, TRUE
);
220 enum bt_component_status
create_output_port(
221 struct bt_private_component
*priv_comp
)
223 return bt_private_component_filter_add_output_private_port(
224 priv_comp
, "out", NULL
, NULL
);
228 void destroy_muxer_comp(struct muxer_comp
*muxer_comp
)
234 BT_LOGD("Destroying muxer component: muxer-comp-addr=%p, "
235 "muxer-notif-iter-count=%u", muxer_comp
,
236 muxer_comp
->muxer_notif_iters
?
237 muxer_comp
->muxer_notif_iters
->len
: 0);
239 if (muxer_comp
->muxer_notif_iters
) {
240 g_ptr_array_free(muxer_comp
->muxer_notif_iters
, TRUE
);
247 struct bt_private_value
*get_default_params(void)
249 struct bt_private_value
*params
;
252 params
= bt_private_value_map_create();
254 BT_LOGE_STR("Cannot create a map value object.");
258 ret
= bt_private_value_map_insert_bool_entry(params
,
259 ASSUME_ABSOLUTE_CLOCK_CLASSES_PARAM_NAME
, false);
261 BT_LOGE_STR("Cannot add boolean value to map value object.");
268 BT_OBJECT_PUT_REF_AND_RESET(params
);
275 int configure_muxer_comp(struct muxer_comp
*muxer_comp
, struct bt_value
*params
)
277 struct bt_private_value
*default_params
= NULL
;
278 struct bt_private_value
*real_params
= NULL
;
279 struct bt_value
*assume_absolute_clock_classes
= NULL
;
283 default_params
= get_default_params();
284 if (!default_params
) {
285 BT_LOGE("Cannot get default parameters: "
286 "muxer-comp-addr=%p", muxer_comp
);
290 real_params
= bt_value_map_extend(
291 bt_value_borrow_from_private(default_params
), params
);
293 BT_LOGE("Cannot extend default parameters map value: "
294 "muxer-comp-addr=%p, def-params-addr=%p, "
295 "params-addr=%p", muxer_comp
, default_params
,
300 assume_absolute_clock_classes
= bt_value_map_borrow_entry_value(
301 bt_value_borrow_from_private(real_params
),
302 ASSUME_ABSOLUTE_CLOCK_CLASSES_PARAM_NAME
);
303 if (assume_absolute_clock_classes
&&
304 !bt_value_is_bool(assume_absolute_clock_classes
)) {
305 BT_LOGE("Expecting a boolean value for the `%s` parameter: "
306 "muxer-comp-addr=%p, value-type=%s",
307 ASSUME_ABSOLUTE_CLOCK_CLASSES_PARAM_NAME
, muxer_comp
,
308 bt_common_value_type_string(
309 bt_value_get_type(assume_absolute_clock_classes
)));
313 ret
= bt_value_bool_get(assume_absolute_clock_classes
, &bool_val
);
315 muxer_comp
->assume_absolute_clock_classes
= (bool) bool_val
;
316 BT_LOGD("Configured muxer component: muxer-comp-addr=%p, "
317 "assume-absolute-clock-classes=%d",
318 muxer_comp
, muxer_comp
->assume_absolute_clock_classes
);
325 bt_object_put_ref(default_params
);
326 bt_object_put_ref(real_params
);
331 enum bt_component_status
muxer_init(
332 struct bt_private_component
*priv_comp
,
333 struct bt_value
*params
, void *init_data
)
336 enum bt_component_status status
= BT_COMPONENT_STATUS_OK
;
337 struct muxer_comp
*muxer_comp
= g_new0(struct muxer_comp
, 1);
339 BT_LOGD("Initializing muxer component: "
340 "comp-addr=%p, params-addr=%p", priv_comp
, params
);
343 BT_LOGE_STR("Failed to allocate one muxer component.");
347 ret
= configure_muxer_comp(muxer_comp
, params
);
349 BT_LOGE("Cannot configure muxer component: "
350 "muxer-comp-addr=%p, params-addr=%p",
355 muxer_comp
->muxer_notif_iters
= g_ptr_array_new();
356 if (!muxer_comp
->muxer_notif_iters
) {
357 BT_LOGE_STR("Failed to allocate a GPtrArray.");
361 muxer_comp
->priv_comp
= priv_comp
;
362 ret
= bt_private_component_set_user_data(priv_comp
, muxer_comp
);
364 status
= ensure_available_input_port(priv_comp
);
365 if (status
!= BT_COMPONENT_STATUS_OK
) {
366 BT_LOGE("Cannot ensure that at least one muxer component's input port is available: "
367 "muxer-comp-addr=%p, status=%s",
369 bt_component_status_string(status
));
373 status
= create_output_port(priv_comp
);
375 BT_LOGE("Cannot create muxer component's output port: "
376 "muxer-comp-addr=%p, status=%s",
378 bt_component_status_string(status
));
382 BT_LOGD("Initialized muxer component: "
383 "comp-addr=%p, params-addr=%p, muxer-comp-addr=%p",
384 priv_comp
, params
, muxer_comp
);
389 destroy_muxer_comp(muxer_comp
);
390 ret
= bt_private_component_set_user_data(priv_comp
, NULL
);
393 if (status
== BT_COMPONENT_STATUS_OK
) {
394 status
= BT_COMPONENT_STATUS_ERROR
;
402 void muxer_finalize(struct bt_private_component
*priv_comp
)
404 struct muxer_comp
*muxer_comp
=
405 bt_private_component_get_user_data(priv_comp
);
407 BT_LOGD("Finalizing muxer component: comp-addr=%p",
409 destroy_muxer_comp(muxer_comp
);
413 struct bt_notification_iterator
*create_notif_iter_on_input_port(
414 struct bt_private_port
*priv_port
, int *ret
)
416 struct bt_port
*port
= bt_port_borrow_from_private(priv_port
);
417 struct bt_notification_iterator
*notif_iter
= NULL
;
418 struct bt_private_connection
*priv_conn
= NULL
;
419 enum bt_connection_status conn_status
;
424 BT_ASSERT(bt_port_is_connected(port
));
425 priv_conn
= bt_private_port_get_private_connection(priv_port
);
426 BT_ASSERT(priv_conn
);
428 // TODO: Advance the iterator to >= the time of the latest
429 // returned notification by the muxer notification
430 // iterator which creates it.
431 conn_status
= bt_private_connection_create_notification_iterator(
432 priv_conn
, ¬if_iter
);
433 if (conn_status
!= BT_CONNECTION_STATUS_OK
) {
434 BT_LOGE("Cannot create upstream notification iterator on input port's connection: "
435 "port-addr=%p, port-name=\"%s\", conn-addr=%p, "
437 port
, bt_port_get_name(port
), priv_conn
,
438 bt_connection_status_string(conn_status
));
443 BT_LOGD("Created upstream notification iterator on input port's connection: "
444 "port-addr=%p, port-name=\"%s\", conn-addr=%p, "
445 "notif-iter-addr=%p",
446 port
, bt_port_get_name(port
), priv_conn
, notif_iter
);
449 bt_object_put_ref(priv_conn
);
454 enum bt_notification_iterator_status
muxer_upstream_notif_iter_next(
455 struct muxer_upstream_notif_iter
*muxer_upstream_notif_iter
)
457 enum bt_notification_iterator_status status
;
458 bt_notification_array notifs
;
462 BT_LOGV("Calling upstream notification iterator's \"next\" method: "
463 "muxer-upstream-notif-iter-wrap-addr=%p, notif-iter-addr=%p",
464 muxer_upstream_notif_iter
,
465 muxer_upstream_notif_iter
->notif_iter
);
466 status
= bt_private_connection_notification_iterator_next(
467 muxer_upstream_notif_iter
->notif_iter
, ¬ifs
, &count
);
468 BT_LOGV("Upstream notification iterator's \"next\" method returned: "
469 "status=%s", bt_notification_iterator_status_string(status
));
472 case BT_NOTIFICATION_ITERATOR_STATUS_OK
:
474 * Notification iterator's current notification is
475 * valid: it must be considered for muxing operations.
477 BT_LOGV_STR("Validated upstream notification iterator wrapper.");
478 BT_ASSERT(count
> 0);
480 /* Move notifications to our queue */
481 for (i
= 0; i
< count
; i
++) {
483 * Push to tail in order; other side
484 * (muxer_notif_iter_do_next_one()) consumes
485 * from the head first.
487 g_queue_push_tail(muxer_upstream_notif_iter
->notifs
,
491 case BT_NOTIFICATION_ITERATOR_STATUS_AGAIN
:
493 * Notification iterator's current notification is not
494 * valid anymore. Return
495 * BT_NOTIFICATION_ITERATOR_STATUS_AGAIN immediately.
498 case BT_NOTIFICATION_ITERATOR_STATUS_END
: /* Fall-through. */
499 case BT_NOTIFICATION_ITERATOR_STATUS_CANCELED
:
501 * Notification iterator reached the end: release it. It
502 * won't be considered again to find the youngest
505 BT_OBJECT_PUT_REF_AND_RESET(muxer_upstream_notif_iter
->notif_iter
);
506 status
= BT_NOTIFICATION_ITERATOR_STATUS_OK
;
509 /* Error or unsupported status code */
510 BT_LOGE("Error or unsupported status code: "
511 "status-code=%d", status
);
512 status
= BT_NOTIFICATION_ITERATOR_STATUS_ERROR
;
520 int muxer_notif_iter_handle_newly_connected_ports(
521 struct muxer_notif_iter
*muxer_notif_iter
)
525 BT_LOGV("Handling newly connected ports: "
526 "muxer-notif-iter-addr=%p", muxer_notif_iter
);
529 * Here we create one upstream notification iterator for each
530 * newly connected port. We do NOT perform an initial "next" on
531 * those new upstream notification iterators: they are
532 * invalidated, to be validated later. The list of newly
533 * connected ports to handle here is updated by
534 * muxer_port_connected().
537 GList
*node
= muxer_notif_iter
->newly_connected_priv_ports
;
538 struct bt_private_port
*priv_port
;
539 struct bt_port
*port
;
540 struct bt_notification_iterator
*upstream_notif_iter
= NULL
;
541 struct muxer_upstream_notif_iter
*muxer_upstream_notif_iter
;
547 priv_port
= node
->data
;
548 port
= bt_port_borrow_from_private(priv_port
);
551 if (!bt_port_is_connected(port
)) {
553 * Looks like this port is not connected
554 * anymore: we can't create an upstream
555 * notification iterator on its (non-existing)
556 * connection in this case.
561 upstream_notif_iter
= create_notif_iter_on_input_port(priv_port
,
564 /* create_notif_iter_on_input_port() logs errors */
565 BT_ASSERT(!upstream_notif_iter
);
569 muxer_upstream_notif_iter
=
570 muxer_notif_iter_add_upstream_notif_iter(
571 muxer_notif_iter
, upstream_notif_iter
,
573 BT_OBJECT_PUT_REF_AND_RESET(upstream_notif_iter
);
574 if (!muxer_upstream_notif_iter
) {
576 * muxer_notif_iter_add_upstream_notif_iter()
583 bt_object_put_ref(upstream_notif_iter
);
584 muxer_notif_iter
->newly_connected_priv_ports
=
586 muxer_notif_iter
->newly_connected_priv_ports
,
602 int get_notif_ts_ns(struct muxer_comp
*muxer_comp
,
603 struct muxer_notif_iter
*muxer_notif_iter
,
604 struct bt_notification
*notif
, int64_t last_returned_ts_ns
,
607 struct bt_clock_class
*clock_class
= NULL
;
608 struct bt_clock_value
*clock_value
= NULL
;
609 struct bt_event
*event
= NULL
;
611 const unsigned char *cc_uuid
;
613 enum bt_clock_value_status cv_status
= BT_CLOCK_VALUE_STATUS_KNOWN
;
618 BT_LOGV("Getting notification's timestamp: "
619 "muxer-notif-iter-addr=%p, notif-addr=%p, "
620 "last-returned-ts=%" PRId64
,
621 muxer_notif_iter
, notif
, last_returned_ts_ns
);
623 switch (bt_notification_get_type(notif
)) {
624 case BT_NOTIFICATION_TYPE_EVENT
:
625 event
= bt_notification_event_borrow_event(notif
);
627 cv_status
= bt_event_borrow_default_clock_value(event
,
631 case BT_NOTIFICATION_TYPE_INACTIVITY
:
633 bt_notification_inactivity_borrow_default_clock_value(
637 /* All the other notifications have a higher priority */
638 BT_LOGV_STR("Notification has no timestamp: using the last returned timestamp.");
639 *ts_ns
= last_returned_ts_ns
;
643 if (cv_status
!= BT_CLOCK_VALUE_STATUS_KNOWN
) {
644 BT_LOGE_STR("Unsupported unknown clock value.");
650 * If the clock value is missing, then we consider that this
651 * notification has no time. In this case it's always the
655 BT_LOGV_STR("Notification's default clock value is missing: "
656 "using the last returned timestamp.");
657 *ts_ns
= last_returned_ts_ns
;
661 clock_class
= bt_clock_value_borrow_clock_class(clock_value
);
662 BT_ASSERT(clock_class
);
663 cc_uuid
= bt_clock_class_get_uuid(clock_class
);
664 cc_name
= bt_clock_class_get_name(clock_class
);
666 if (muxer_notif_iter
->clock_class_expectation
==
667 MUXER_NOTIF_ITER_CLOCK_CLASS_EXPECTATION_ANY
) {
669 * This is the first clock class that this muxer
670 * notification iterator encounters. Its properties
671 * determine what to expect for the whole lifetime of
672 * the iterator without a true
673 * `assume-absolute-clock-classes` parameter.
675 if (bt_clock_class_is_absolute(clock_class
)) {
676 /* Expect absolute clock classes */
677 muxer_notif_iter
->clock_class_expectation
=
678 MUXER_NOTIF_ITER_CLOCK_CLASS_EXPECTATION_ABSOLUTE
;
682 * Expect non-absolute clock classes
683 * with a specific UUID.
685 muxer_notif_iter
->clock_class_expectation
=
686 MUXER_NOTIF_ITER_CLOCK_CLASS_EXPECTATION_NOT_ABS_SPEC_UUID
;
687 memcpy(muxer_notif_iter
->expected_clock_class_uuid
,
688 cc_uuid
, BABELTRACE_UUID_LEN
);
691 * Expect non-absolute clock classes
694 muxer_notif_iter
->clock_class_expectation
=
695 MUXER_NOTIF_ITER_CLOCK_CLASS_EXPECTATION_NOT_ABS_NO_UUID
;
700 if (!muxer_comp
->assume_absolute_clock_classes
) {
701 switch (muxer_notif_iter
->clock_class_expectation
) {
702 case MUXER_NOTIF_ITER_CLOCK_CLASS_EXPECTATION_ABSOLUTE
:
703 if (!bt_clock_class_is_absolute(clock_class
)) {
704 BT_LOGE("Expecting an absolute clock class, "
705 "but got a non-absolute one: "
706 "clock-class-addr=%p, clock-class-name=\"%s\"",
707 clock_class
, cc_name
);
711 case MUXER_NOTIF_ITER_CLOCK_CLASS_EXPECTATION_NOT_ABS_NO_UUID
:
712 if (bt_clock_class_is_absolute(clock_class
)) {
713 BT_LOGE("Expecting a non-absolute clock class with no UUID, "
714 "but got an absolute one: "
715 "clock-class-addr=%p, clock-class-name=\"%s\"",
716 clock_class
, cc_name
);
721 BT_LOGE("Expecting a non-absolute clock class with no UUID, "
722 "but got one with a UUID: "
723 "clock-class-addr=%p, clock-class-name=\"%s\", "
724 "uuid=\"%02x%02x%02x%02x-%02x%02x-%02x%02x-%02x%02x-%02x%02x%02x%02x%02x%02x\"",
725 clock_class
, cc_name
,
726 (unsigned int) cc_uuid
[0],
727 (unsigned int) cc_uuid
[1],
728 (unsigned int) cc_uuid
[2],
729 (unsigned int) cc_uuid
[3],
730 (unsigned int) cc_uuid
[4],
731 (unsigned int) cc_uuid
[5],
732 (unsigned int) cc_uuid
[6],
733 (unsigned int) cc_uuid
[7],
734 (unsigned int) cc_uuid
[8],
735 (unsigned int) cc_uuid
[9],
736 (unsigned int) cc_uuid
[10],
737 (unsigned int) cc_uuid
[11],
738 (unsigned int) cc_uuid
[12],
739 (unsigned int) cc_uuid
[13],
740 (unsigned int) cc_uuid
[14],
741 (unsigned int) cc_uuid
[15]);
745 case MUXER_NOTIF_ITER_CLOCK_CLASS_EXPECTATION_NOT_ABS_SPEC_UUID
:
746 if (bt_clock_class_is_absolute(clock_class
)) {
747 BT_LOGE("Expecting a non-absolute clock class with a specific UUID, "
748 "but got an absolute one: "
749 "clock-class-addr=%p, clock-class-name=\"%s\"",
750 clock_class
, cc_name
);
755 BT_LOGE("Expecting a non-absolute clock class with a specific UUID, "
756 "but got one with no UUID: "
757 "clock-class-addr=%p, clock-class-name=\"%s\"",
758 clock_class
, cc_name
);
762 if (memcmp(muxer_notif_iter
->expected_clock_class_uuid
,
763 cc_uuid
, BABELTRACE_UUID_LEN
) != 0) {
764 BT_LOGE("Expecting a non-absolute clock class with a specific UUID, "
765 "but got one with different UUID: "
766 "clock-class-addr=%p, clock-class-name=\"%s\", "
767 "expected-uuid=\"%02x%02x%02x%02x-%02x%02x-%02x%02x-%02x%02x-%02x%02x%02x%02x%02x%02x\", "
768 "uuid=\"%02x%02x%02x%02x-%02x%02x-%02x%02x-%02x%02x-%02x%02x%02x%02x%02x%02x\"",
769 clock_class
, cc_name
,
770 (unsigned int) muxer_notif_iter
->expected_clock_class_uuid
[0],
771 (unsigned int) muxer_notif_iter
->expected_clock_class_uuid
[1],
772 (unsigned int) muxer_notif_iter
->expected_clock_class_uuid
[2],
773 (unsigned int) muxer_notif_iter
->expected_clock_class_uuid
[3],
774 (unsigned int) muxer_notif_iter
->expected_clock_class_uuid
[4],
775 (unsigned int) muxer_notif_iter
->expected_clock_class_uuid
[5],
776 (unsigned int) muxer_notif_iter
->expected_clock_class_uuid
[6],
777 (unsigned int) muxer_notif_iter
->expected_clock_class_uuid
[7],
778 (unsigned int) muxer_notif_iter
->expected_clock_class_uuid
[8],
779 (unsigned int) muxer_notif_iter
->expected_clock_class_uuid
[9],
780 (unsigned int) muxer_notif_iter
->expected_clock_class_uuid
[10],
781 (unsigned int) muxer_notif_iter
->expected_clock_class_uuid
[11],
782 (unsigned int) muxer_notif_iter
->expected_clock_class_uuid
[12],
783 (unsigned int) muxer_notif_iter
->expected_clock_class_uuid
[13],
784 (unsigned int) muxer_notif_iter
->expected_clock_class_uuid
[14],
785 (unsigned int) muxer_notif_iter
->expected_clock_class_uuid
[15],
786 (unsigned int) cc_uuid
[0],
787 (unsigned int) cc_uuid
[1],
788 (unsigned int) cc_uuid
[2],
789 (unsigned int) cc_uuid
[3],
790 (unsigned int) cc_uuid
[4],
791 (unsigned int) cc_uuid
[5],
792 (unsigned int) cc_uuid
[6],
793 (unsigned int) cc_uuid
[7],
794 (unsigned int) cc_uuid
[8],
795 (unsigned int) cc_uuid
[9],
796 (unsigned int) cc_uuid
[10],
797 (unsigned int) cc_uuid
[11],
798 (unsigned int) cc_uuid
[12],
799 (unsigned int) cc_uuid
[13],
800 (unsigned int) cc_uuid
[14],
801 (unsigned int) cc_uuid
[15]);
807 BT_LOGF("Unexpected clock class expectation: "
808 "expectation-code=%d",
809 muxer_notif_iter
->clock_class_expectation
);
814 ret
= bt_clock_value_get_ns_from_origin(clock_value
, ts_ns
);
816 BT_LOGE("Cannot get nanoseconds from Epoch of clock value: "
817 "clock-value-addr=%p", clock_value
);
828 BT_LOGV("Found notification's timestamp: "
829 "muxer-notif-iter-addr=%p, notif-addr=%p, "
830 "last-returned-ts=%" PRId64
", ts=%" PRId64
,
831 muxer_notif_iter
, notif
, last_returned_ts_ns
,
839 * This function finds the youngest available notification amongst the
840 * non-ended upstream notification iterators and returns the upstream
841 * notification iterator which has it, or
842 * BT_NOTIFICATION_ITERATOR_STATUS_END if there's no available
845 * This function does NOT:
847 * * Update any upstream notification iterator.
848 * * Check for newly connected ports.
849 * * Check the upstream notification iterators to retry.
851 * On sucess, this function sets *muxer_upstream_notif_iter to the
852 * upstream notification iterator of which the current notification is
853 * the youngest, and sets *ts_ns to its time.
856 enum bt_notification_iterator_status
857 muxer_notif_iter_youngest_upstream_notif_iter(
858 struct muxer_comp
*muxer_comp
,
859 struct muxer_notif_iter
*muxer_notif_iter
,
860 struct muxer_upstream_notif_iter
**muxer_upstream_notif_iter
,
865 int64_t youngest_ts_ns
= INT64_MAX
;
866 enum bt_notification_iterator_status status
=
867 BT_NOTIFICATION_ITERATOR_STATUS_OK
;
869 BT_ASSERT(muxer_comp
);
870 BT_ASSERT(muxer_notif_iter
);
871 BT_ASSERT(muxer_upstream_notif_iter
);
872 *muxer_upstream_notif_iter
= NULL
;
874 for (i
= 0; i
< muxer_notif_iter
->muxer_upstream_notif_iters
->len
; i
++) {
875 struct bt_notification
*notif
;
876 struct muxer_upstream_notif_iter
*cur_muxer_upstream_notif_iter
=
877 g_ptr_array_index(muxer_notif_iter
->muxer_upstream_notif_iters
, i
);
880 if (!cur_muxer_upstream_notif_iter
->notif_iter
) {
881 /* This upstream notification iterator is ended */
882 BT_LOGV("Skipping ended upstream notification iterator: "
883 "muxer-upstream-notif-iter-wrap-addr=%p",
884 cur_muxer_upstream_notif_iter
);
888 BT_ASSERT(cur_muxer_upstream_notif_iter
->notifs
->length
> 0);
889 notif
= g_queue_peek_head(cur_muxer_upstream_notif_iter
->notifs
);
891 ret
= get_notif_ts_ns(muxer_comp
, muxer_notif_iter
, notif
,
892 muxer_notif_iter
->last_returned_ts_ns
, ¬if_ts_ns
);
894 /* get_notif_ts_ns() logs errors */
895 *muxer_upstream_notif_iter
= NULL
;
896 status
= BT_NOTIFICATION_ITERATOR_STATUS_ERROR
;
900 if (notif_ts_ns
<= youngest_ts_ns
) {
901 *muxer_upstream_notif_iter
=
902 cur_muxer_upstream_notif_iter
;
903 youngest_ts_ns
= notif_ts_ns
;
904 *ts_ns
= youngest_ts_ns
;
908 if (!*muxer_upstream_notif_iter
) {
909 status
= BT_NOTIFICATION_ITERATOR_STATUS_END
;
918 enum bt_notification_iterator_status
validate_muxer_upstream_notif_iter(
919 struct muxer_upstream_notif_iter
*muxer_upstream_notif_iter
)
921 enum bt_notification_iterator_status status
=
922 BT_NOTIFICATION_ITERATOR_STATUS_OK
;
924 BT_LOGV("Validating muxer's upstream notification iterator wrapper: "
925 "muxer-upstream-notif-iter-wrap-addr=%p",
926 muxer_upstream_notif_iter
);
928 if (muxer_upstream_notif_iter
->notifs
->length
> 0 ||
929 !muxer_upstream_notif_iter
->notif_iter
) {
930 BT_LOGV("Already valid or not considered: "
931 "queue-len=%u, upstream-notif-iter-addr=%p",
932 muxer_upstream_notif_iter
->notifs
->length
,
933 muxer_upstream_notif_iter
->notif_iter
);
937 /* muxer_upstream_notif_iter_next() logs details/errors */
938 status
= muxer_upstream_notif_iter_next(muxer_upstream_notif_iter
);
945 enum bt_notification_iterator_status
validate_muxer_upstream_notif_iters(
946 struct muxer_notif_iter
*muxer_notif_iter
)
948 enum bt_notification_iterator_status status
=
949 BT_NOTIFICATION_ITERATOR_STATUS_OK
;
952 BT_LOGV("Validating muxer's upstream notification iterator wrappers: "
953 "muxer-notif-iter-addr=%p", muxer_notif_iter
);
955 for (i
= 0; i
< muxer_notif_iter
->muxer_upstream_notif_iters
->len
; i
++) {
956 struct muxer_upstream_notif_iter
*muxer_upstream_notif_iter
=
958 muxer_notif_iter
->muxer_upstream_notif_iters
,
961 status
= validate_muxer_upstream_notif_iter(
962 muxer_upstream_notif_iter
);
963 if (status
!= BT_NOTIFICATION_ITERATOR_STATUS_OK
) {
965 BT_LOGE("Cannot validate muxer's upstream notification iterator wrapper: "
966 "muxer-notif-iter-addr=%p, "
967 "muxer-upstream-notif-iter-wrap-addr=%p",
969 muxer_upstream_notif_iter
);
971 BT_LOGV("Cannot validate muxer's upstream notification iterator wrapper: "
972 "muxer-notif-iter-addr=%p, "
973 "muxer-upstream-notif-iter-wrap-addr=%p",
975 muxer_upstream_notif_iter
);
982 * Remove this muxer upstream notification iterator
983 * if it's ended or canceled.
985 if (!muxer_upstream_notif_iter
->notif_iter
) {
987 * Use g_ptr_array_remove_fast() because the
988 * order of those elements is not important.
990 BT_LOGV("Removing muxer's upstream notification iterator wrapper: ended or canceled: "
991 "muxer-notif-iter-addr=%p, "
992 "muxer-upstream-notif-iter-wrap-addr=%p",
993 muxer_notif_iter
, muxer_upstream_notif_iter
);
994 g_ptr_array_remove_index_fast(
995 muxer_notif_iter
->muxer_upstream_notif_iters
,
1006 enum bt_notification_iterator_status
muxer_notif_iter_do_next_one(
1007 struct muxer_comp
*muxer_comp
,
1008 struct muxer_notif_iter
*muxer_notif_iter
,
1009 struct bt_notification
**notif
)
1011 enum bt_notification_iterator_status status
=
1012 BT_NOTIFICATION_ITERATOR_STATUS_OK
;
1013 struct muxer_upstream_notif_iter
*muxer_upstream_notif_iter
= NULL
;
1014 int64_t next_return_ts
;
1017 int ret
= muxer_notif_iter_handle_newly_connected_ports(
1021 BT_LOGE("Cannot handle newly connected input ports for muxer's notification iterator: "
1022 "muxer-comp-addr=%p, muxer-notif-iter-addr=%p, "
1024 muxer_comp
, muxer_notif_iter
, ret
);
1025 status
= BT_NOTIFICATION_ITERATOR_STATUS_ERROR
;
1029 status
= validate_muxer_upstream_notif_iters(muxer_notif_iter
);
1030 if (status
!= BT_NOTIFICATION_ITERATOR_STATUS_OK
) {
1031 /* validate_muxer_upstream_notif_iters() logs details */
1036 * At this point, we know that all the existing upstream
1037 * notification iterators are valid. However the
1038 * operations to validate them (during
1039 * validate_muxer_upstream_notif_iters()) may have
1040 * connected new ports. If no ports were connected
1041 * during this operation, exit the loop.
1043 if (!muxer_notif_iter
->newly_connected_priv_ports
) {
1044 BT_LOGV("Not breaking this loop: muxer's notification iterator still has newly connected input ports to handle: "
1045 "muxer-comp-addr=%p", muxer_comp
);
1050 BT_ASSERT(!muxer_notif_iter
->newly_connected_priv_ports
);
1053 * At this point we know that all the existing upstream
1054 * notification iterators are valid. We can find the one,
1055 * amongst those, of which the current notification is the
1058 status
= muxer_notif_iter_youngest_upstream_notif_iter(muxer_comp
,
1059 muxer_notif_iter
, &muxer_upstream_notif_iter
,
1061 if (status
< 0 || status
== BT_NOTIFICATION_ITERATOR_STATUS_END
||
1062 status
== BT_NOTIFICATION_ITERATOR_STATUS_CANCELED
) {
1064 BT_LOGE("Cannot find the youngest upstream notification iterator wrapper: "
1066 bt_notification_iterator_status_string(status
));
1068 BT_LOGV("Cannot find the youngest upstream notification iterator wrapper: "
1070 bt_notification_iterator_status_string(status
));
1076 if (next_return_ts
< muxer_notif_iter
->last_returned_ts_ns
) {
1077 BT_LOGE("Youngest upstream notification iterator wrapper's timestamp is less than muxer's notification iterator's last returned timestamp: "
1078 "muxer-notif-iter-addr=%p, ts=%" PRId64
", "
1079 "last-returned-ts=%" PRId64
,
1080 muxer_notif_iter
, next_return_ts
,
1081 muxer_notif_iter
->last_returned_ts_ns
);
1082 status
= BT_NOTIFICATION_ITERATOR_STATUS_ERROR
;
1086 BT_LOGV("Found youngest upstream notification iterator wrapper: "
1087 "muxer-notif-iter-addr=%p, "
1088 "muxer-upstream-notif-iter-wrap-addr=%p, "
1090 muxer_notif_iter
, muxer_upstream_notif_iter
, next_return_ts
);
1091 BT_ASSERT(status
== BT_NOTIFICATION_ITERATOR_STATUS_OK
);
1092 BT_ASSERT(muxer_upstream_notif_iter
);
1095 * Consume from the queue's head: other side
1096 * (muxer_upstream_notif_iter_next()) writes to the tail.
1098 *notif
= g_queue_pop_head(muxer_upstream_notif_iter
->notifs
);
1100 muxer_notif_iter
->last_returned_ts_ns
= next_return_ts
;
1107 enum bt_notification_iterator_status
muxer_notif_iter_do_next(
1108 struct muxer_comp
*muxer_comp
,
1109 struct muxer_notif_iter
*muxer_notif_iter
,
1110 bt_notification_array notifs
, uint64_t capacity
,
1113 enum bt_notification_iterator_status status
=
1114 BT_NOTIFICATION_ITERATOR_STATUS_OK
;
1117 while (i
< capacity
&& status
== BT_NOTIFICATION_ITERATOR_STATUS_OK
) {
1118 status
= muxer_notif_iter_do_next_one(muxer_comp
,
1119 muxer_notif_iter
, ¬ifs
[i
]);
1120 if (status
== BT_NOTIFICATION_ITERATOR_STATUS_OK
) {
1127 * Even if muxer_notif_iter_do_next_one() returned
1128 * something else than
1129 * BT_NOTIFICATION_ITERATOR_STATUS_OK, we accumulated
1130 * notification objects in the output notification
1131 * array, so we need to return
1132 * BT_NOTIFICATION_ITERATOR_STATUS_OK so that they are
1133 * transfered to downstream. This other status occurs
1134 * again the next time muxer_notif_iter_do_next() is
1135 * called, possibly without any accumulated
1136 * notification, in which case we'll return it.
1139 status
= BT_NOTIFICATION_ITERATOR_STATUS_OK
;
1146 void destroy_muxer_notif_iter(struct muxer_notif_iter
*muxer_notif_iter
)
1148 if (!muxer_notif_iter
) {
1152 BT_LOGD("Destroying muxer component's notification iterator: "
1153 "muxer-notif-iter-addr=%p", muxer_notif_iter
);
1155 if (muxer_notif_iter
->muxer_upstream_notif_iters
) {
1156 BT_LOGD_STR("Destroying muxer's upstream notification iterator wrappers.");
1158 muxer_notif_iter
->muxer_upstream_notif_iters
, TRUE
);
1161 g_list_free(muxer_notif_iter
->newly_connected_priv_ports
);
1162 g_free(muxer_notif_iter
);
1166 int muxer_notif_iter_init_newly_connected_ports(struct muxer_comp
*muxer_comp
,
1167 struct muxer_notif_iter
*muxer_notif_iter
)
1169 struct bt_component
*comp
;
1175 * Add the connected input ports to this muxer notification
1176 * iterator's list of newly connected ports. They will be
1177 * handled by muxer_notif_iter_handle_newly_connected_ports().
1179 comp
= bt_component_borrow_from_private(muxer_comp
->priv_comp
);
1181 count
= bt_component_filter_get_input_port_count(comp
);
1183 BT_LOGD("No input port to initialize for muxer component's notification iterator: "
1184 "muxer-comp-addr=%p, muxer-notif-iter-addr=%p",
1185 muxer_comp
, muxer_notif_iter
);
1189 for (i
= 0; i
< count
; i
++) {
1190 struct bt_private_port
*priv_port
=
1191 bt_private_component_filter_get_input_private_port_by_index(
1192 muxer_comp
->priv_comp
, i
);
1193 struct bt_port
*port
;
1195 BT_ASSERT(priv_port
);
1196 port
= bt_port_borrow_from_private(priv_port
);
1199 if (!bt_port_is_connected(port
)) {
1200 BT_LOGD("Skipping input port: not connected: "
1201 "muxer-comp-addr=%p, port-addr=%p, port-name\"%s\"",
1202 muxer_comp
, port
, bt_port_get_name(port
));
1203 bt_object_put_ref(priv_port
);
1207 bt_object_put_ref(priv_port
);
1208 muxer_notif_iter
->newly_connected_priv_ports
=
1210 muxer_notif_iter
->newly_connected_priv_ports
,
1212 if (!muxer_notif_iter
->newly_connected_priv_ports
) {
1213 BT_LOGE("Cannot append port to muxer's notification iterator list of newly connected input ports: "
1214 "port-addr=%p, port-name=\"%s\", "
1215 "muxer-notif-iter-addr=%p", port
,
1216 bt_port_get_name(port
), muxer_notif_iter
);
1221 BT_LOGD("Appended port to muxer's notification iterator list of newly connected input ports: "
1222 "port-addr=%p, port-name=\"%s\", "
1223 "muxer-notif-iter-addr=%p", port
,
1224 bt_port_get_name(port
), muxer_notif_iter
);
1232 enum bt_notification_iterator_status
muxer_notif_iter_init(
1233 struct bt_private_connection_private_notification_iterator
*priv_notif_iter
,
1234 struct bt_private_port
*output_priv_port
)
1236 struct muxer_comp
*muxer_comp
= NULL
;
1237 struct muxer_notif_iter
*muxer_notif_iter
= NULL
;
1238 struct bt_private_component
*priv_comp
= NULL
;
1239 enum bt_notification_iterator_status status
=
1240 BT_NOTIFICATION_ITERATOR_STATUS_OK
;
1243 priv_comp
= bt_private_connection_private_notification_iterator_get_private_component(
1245 BT_ASSERT(priv_comp
);
1246 muxer_comp
= bt_private_component_get_user_data(priv_comp
);
1247 BT_ASSERT(muxer_comp
);
1248 BT_LOGD("Initializing muxer component's notification iterator: "
1249 "comp-addr=%p, muxer-comp-addr=%p, notif-iter-addr=%p",
1250 priv_comp
, muxer_comp
, priv_notif_iter
);
1252 if (muxer_comp
->initializing_muxer_notif_iter
) {
1254 * Weird, unhandled situation detected: downstream
1255 * creates a muxer notification iterator while creating
1256 * another muxer notification iterator (same component).
1258 BT_LOGE("Recursive initialization of muxer component's notification iterator: "
1259 "comp-addr=%p, muxer-comp-addr=%p, notif-iter-addr=%p",
1260 priv_comp
, muxer_comp
, priv_notif_iter
);
1264 muxer_comp
->initializing_muxer_notif_iter
= true;
1265 muxer_notif_iter
= g_new0(struct muxer_notif_iter
, 1);
1266 if (!muxer_notif_iter
) {
1267 BT_LOGE_STR("Failed to allocate one muxer component's notification iterator.");
1271 muxer_notif_iter
->last_returned_ts_ns
= INT64_MIN
;
1272 muxer_notif_iter
->muxer_upstream_notif_iters
=
1273 g_ptr_array_new_with_free_func(
1274 (GDestroyNotify
) destroy_muxer_upstream_notif_iter
);
1275 if (!muxer_notif_iter
->muxer_upstream_notif_iters
) {
1276 BT_LOGE_STR("Failed to allocate a GPtrArray.");
1281 * Add the muxer notification iterator to the component's array
1282 * of muxer notification iterators here because
1283 * muxer_notif_iter_init_newly_connected_ports() can cause
1284 * muxer_port_connected() to be called, which adds the newly
1285 * connected port to each muxer notification iterator's list of
1286 * newly connected ports.
1288 g_ptr_array_add(muxer_comp
->muxer_notif_iters
, muxer_notif_iter
);
1289 ret
= muxer_notif_iter_init_newly_connected_ports(muxer_comp
,
1292 BT_LOGE("Cannot initialize newly connected input ports for muxer component's notification iterator: "
1293 "comp-addr=%p, muxer-comp-addr=%p, "
1294 "muxer-notif-iter-addr=%p, notif-iter-addr=%p, ret=%d",
1295 priv_comp
, muxer_comp
, muxer_notif_iter
,
1296 priv_notif_iter
, ret
);
1300 ret
= bt_private_connection_private_notification_iterator_set_user_data(priv_notif_iter
,
1302 BT_ASSERT(ret
== 0);
1303 BT_LOGD("Initialized muxer component's notification iterator: "
1304 "comp-addr=%p, muxer-comp-addr=%p, muxer-notif-iter-addr=%p, "
1305 "notif-iter-addr=%p",
1306 priv_comp
, muxer_comp
, muxer_notif_iter
, priv_notif_iter
);
1310 if (g_ptr_array_index(muxer_comp
->muxer_notif_iters
,
1311 muxer_comp
->muxer_notif_iters
->len
- 1) == muxer_notif_iter
) {
1312 g_ptr_array_remove_index(muxer_comp
->muxer_notif_iters
,
1313 muxer_comp
->muxer_notif_iters
->len
- 1);
1316 destroy_muxer_notif_iter(muxer_notif_iter
);
1317 ret
= bt_private_connection_private_notification_iterator_set_user_data(priv_notif_iter
,
1319 BT_ASSERT(ret
== 0);
1320 status
= BT_NOTIFICATION_ITERATOR_STATUS_ERROR
;
1323 muxer_comp
->initializing_muxer_notif_iter
= false;
1324 bt_object_put_ref(priv_comp
);
1329 void muxer_notif_iter_finalize(
1330 struct bt_private_connection_private_notification_iterator
*priv_notif_iter
)
1332 struct muxer_notif_iter
*muxer_notif_iter
=
1333 bt_private_connection_private_notification_iterator_get_user_data(priv_notif_iter
);
1334 struct bt_private_component
*priv_comp
= NULL
;
1335 struct muxer_comp
*muxer_comp
= NULL
;
1337 priv_comp
= bt_private_connection_private_notification_iterator_get_private_component(
1339 BT_ASSERT(priv_comp
);
1340 muxer_comp
= bt_private_component_get_user_data(priv_comp
);
1341 BT_LOGD("Finalizing muxer component's notification iterator: "
1342 "comp-addr=%p, muxer-comp-addr=%p, muxer-notif-iter-addr=%p, "
1343 "notif-iter-addr=%p",
1344 priv_comp
, muxer_comp
, muxer_notif_iter
, priv_notif_iter
);
1347 (void) g_ptr_array_remove_fast(muxer_comp
->muxer_notif_iters
,
1349 destroy_muxer_notif_iter(muxer_notif_iter
);
1352 bt_object_put_ref(priv_comp
);
1356 enum bt_notification_iterator_status
muxer_notif_iter_next(
1357 struct bt_private_connection_private_notification_iterator
*priv_notif_iter
,
1358 bt_notification_array notifs
, uint64_t capacity
,
1361 enum bt_notification_iterator_status status
;
1362 struct muxer_notif_iter
*muxer_notif_iter
=
1363 bt_private_connection_private_notification_iterator_get_user_data(priv_notif_iter
);
1364 struct bt_private_component
*priv_comp
= NULL
;
1365 struct muxer_comp
*muxer_comp
= NULL
;
1367 BT_ASSERT(muxer_notif_iter
);
1368 priv_comp
= bt_private_connection_private_notification_iterator_get_private_component(
1370 BT_ASSERT(priv_comp
);
1371 muxer_comp
= bt_private_component_get_user_data(priv_comp
);
1372 BT_ASSERT(muxer_comp
);
1373 BT_LOGV("Muxer component's notification iterator's \"next\" method called: "
1374 "comp-addr=%p, muxer-comp-addr=%p, muxer-notif-iter-addr=%p, "
1375 "notif-iter-addr=%p",
1376 priv_comp
, muxer_comp
, muxer_notif_iter
, priv_notif_iter
);
1378 status
= muxer_notif_iter_do_next(muxer_comp
, muxer_notif_iter
,
1379 notifs
, capacity
, count
);
1381 BT_LOGE("Cannot get next notification: "
1382 "comp-addr=%p, muxer-comp-addr=%p, muxer-notif-iter-addr=%p, "
1383 "notif-iter-addr=%p, status=%s",
1384 priv_comp
, muxer_comp
, muxer_notif_iter
, priv_notif_iter
,
1385 bt_notification_iterator_status_string(status
));
1387 BT_LOGV("Returning from muxer component's notification iterator's \"next\" method: "
1389 bt_notification_iterator_status_string(status
));
1392 bt_object_put_ref(priv_comp
);
1397 enum bt_component_status
muxer_port_connected(
1398 struct bt_private_component
*priv_comp
,
1399 struct bt_private_port
*self_private_port
,
1400 struct bt_port
*other_port
)
1402 enum bt_component_status status
= BT_COMPONENT_STATUS_OK
;
1403 struct bt_port
*self_port
=
1404 bt_port_borrow_from_private(self_private_port
);
1405 struct muxer_comp
*muxer_comp
=
1406 bt_private_component_get_user_data(priv_comp
);
1410 BT_ASSERT(self_port
);
1411 BT_ASSERT(muxer_comp
);
1412 BT_LOGD("Port connected: "
1413 "comp-addr=%p, muxer-comp-addr=%p, "
1414 "port-addr=%p, port-name=\"%s\", "
1415 "other-port-addr=%p, other-port-name=\"%s\"",
1416 priv_comp
, muxer_comp
, self_port
, bt_port_get_name(self_port
),
1417 other_port
, bt_port_get_name(other_port
));
1419 if (bt_port_get_type(self_port
) == BT_PORT_TYPE_OUTPUT
) {
1423 for (i
= 0; i
< muxer_comp
->muxer_notif_iters
->len
; i
++) {
1424 struct muxer_notif_iter
*muxer_notif_iter
=
1425 g_ptr_array_index(muxer_comp
->muxer_notif_iters
, i
);
1428 * Add this port to the list of newly connected ports
1429 * for this muxer notification iterator. We append at
1430 * the end of this list while
1431 * muxer_notif_iter_handle_newly_connected_ports()
1432 * removes the nodes from the beginning.
1434 muxer_notif_iter
->newly_connected_priv_ports
=
1436 muxer_notif_iter
->newly_connected_priv_ports
,
1438 if (!muxer_notif_iter
->newly_connected_priv_ports
) {
1439 BT_LOGE("Cannot append port to muxer's notification iterator list of newly connected input ports: "
1440 "port-addr=%p, port-name=\"%s\", "
1441 "muxer-notif-iter-addr=%p", self_port
,
1442 bt_port_get_name(self_port
), muxer_notif_iter
);
1443 status
= BT_COMPONENT_STATUS_ERROR
;
1447 BT_LOGD("Appended port to muxer's notification iterator list of newly connected input ports: "
1448 "port-addr=%p, port-name=\"%s\", "
1449 "muxer-notif-iter-addr=%p", self_port
,
1450 bt_port_get_name(self_port
), muxer_notif_iter
);
1453 /* One less available input port */
1454 muxer_comp
->available_input_ports
--;
1455 ret
= ensure_available_input_port(priv_comp
);
1458 * Only way to report an error later since this
1459 * method does not return anything.
1461 BT_LOGE("Cannot ensure that at least one muxer component's input port is available: "
1462 "muxer-comp-addr=%p, status=%s",
1463 muxer_comp
, bt_component_status_string(ret
));
1464 status
= BT_COMPONENT_STATUS_ERROR
;
1473 void muxer_port_disconnected(struct bt_private_component
*priv_comp
,
1474 struct bt_private_port
*priv_port
)
1476 struct bt_port
*port
= bt_port_borrow_from_private(priv_port
);
1477 struct muxer_comp
*muxer_comp
=
1478 bt_private_component_get_user_data(priv_comp
);
1481 BT_ASSERT(muxer_comp
);
1482 BT_LOGD("Port disconnected: "
1483 "comp-addr=%p, muxer-comp-addr=%p, port-addr=%p, "
1484 "port-name=\"%s\"", priv_comp
, muxer_comp
,
1485 port
, bt_port_get_name(port
));
1488 * There's nothing special to do when a port is disconnected
1489 * because this component deals with upstream notification
1490 * iterators which were already created thanks to connected
1491 * ports. The fact that the port is disconnected does not cancel
1492 * the upstream notification iterators created using its
1493 * connection: they still exist, even if the connection is dead.
1494 * The only way to remove an upstream notification iterator is
1495 * for its "next" operation to return
1496 * BT_NOTIFICATION_ITERATOR_STATUS_END.
1498 if (bt_port_get_type(port
) == BT_PORT_TYPE_INPUT
) {
1499 /* One more available input port */
1500 muxer_comp
->available_input_ports
++;
1501 BT_LOGD("Leaving disconnected input port available for future connections: "
1502 "comp-addr=%p, muxer-comp-addr=%p, port-addr=%p, "
1503 "port-name=\"%s\", avail-input-port-count=%zu",
1504 priv_comp
, muxer_comp
, port
, bt_port_get_name(port
),
1505 muxer_comp
->available_input_ports
);