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/ctf-ir/clock-class.h>
29 #include <babeltrace/ctf-ir/event.h>
30 #include <babeltrace/graph/clock-class-priority-map.h>
31 #include <babeltrace/graph/component-filter.h>
32 #include <babeltrace/graph/component.h>
33 #include <babeltrace/graph/component-internal.h>
34 #include <babeltrace/graph/notification-event.h>
35 #include <babeltrace/graph/notification-inactivity.h>
36 #include <babeltrace/graph/notification-iterator.h>
37 #include <babeltrace/graph/notification-iterator-internal.h>
38 #include <babeltrace/graph/notification.h>
39 #include <babeltrace/graph/port.h>
40 #include <babeltrace/graph/private-component-filter.h>
41 #include <babeltrace/graph/private-component.h>
42 #include <babeltrace/graph/private-component.h>
43 #include <babeltrace/graph/private-connection.h>
44 #include <babeltrace/graph/private-connection-private-notification-iterator.h>
45 #include <babeltrace/graph/private-port.h>
46 #include <babeltrace/graph/connection.h>
47 #include <babeltrace/graph/connection-internal.h>
48 #include <babeltrace/values-internal.h>
49 #include <plugins-common.h>
57 #define ASSUME_ABSOLUTE_CLOCK_CLASSES_PARAM_NAME "assume-absolute-clock-classes"
62 * bt_private_connection_private_notification_iterator *
65 GPtrArray
*muxer_notif_iters
;
68 struct bt_private_component
*priv_comp
;
69 unsigned int next_port_num
;
70 size_t available_input_ports
;
72 bool initializing_muxer_notif_iter
;
73 bool assume_absolute_clock_classes
;
76 struct muxer_upstream_notif_iter
{
77 /* Owned by this, NULL if ended */
78 struct bt_notification_iterator
*notif_iter
;
81 * This flag is true if the upstream notification iterator's
82 * current notification must be considered for the multiplexing
83 * operations. If the upstream iterator returns
84 * BT_NOTIFICATION_ITERATOR_STATUS_AGAIN, then this object
85 * is considered invalid, because its current notification is
86 * still the previous one, but we already took it into account.
88 * The value of this flag is not important if notif_iter above
89 * is NULL (which means the upstream iterator is finished).
94 enum muxer_notif_iter_clock_class_expectation
{
95 MUXER_NOTIF_ITER_CLOCK_CLASS_EXPECTATION_ANY
= 0,
96 MUXER_NOTIF_ITER_CLOCK_CLASS_EXPECTATION_ABSOLUTE
,
97 MUXER_NOTIF_ITER_CLOCK_CLASS_EXPECTATION_NOT_ABS_SPEC_UUID
,
98 MUXER_NOTIF_ITER_CLOCK_CLASS_EXPECTATION_NOT_ABS_NO_UUID
,
101 struct muxer_notif_iter
{
103 * Array of struct muxer_upstream_notif_iter * (owned by this).
105 * NOTE: This array is searched in linearly to find the youngest
106 * current notification. Keep this until benchmarks confirm that
107 * another data structure is faster than this for our typical
110 GPtrArray
*muxer_upstream_notif_iters
;
113 * List of "recently" connected input ports (weak) to
114 * handle by this muxer notification iterator.
115 * muxer_port_connected() adds entries to this list, and the
116 * entries are removed when a notification iterator is created
117 * on the port's connection and put into
118 * muxer_upstream_notif_iters above by
119 * muxer_notif_iter_handle_newly_connected_ports().
121 GList
*newly_connected_priv_ports
;
123 /* Next thing to return by the "next" method */
124 struct bt_notification_iterator_next_method_return next_next_return
;
126 /* Last time returned in a notification */
127 int64_t last_returned_ts_ns
;
129 /* Clock class expectation state */
130 enum muxer_notif_iter_clock_class_expectation clock_class_expectation
;
133 * Expected clock class UUID, only valid when
134 * clock_class_expectation is
135 * MUXER_NOTIF_ITER_CLOCK_CLASS_EXPECTATION_NOT_ABS_SPEC_UUID.
137 unsigned char expected_clock_class_uuid
[BABELTRACE_UUID_LEN
];
141 void destroy_muxer_upstream_notif_iter(
142 struct muxer_upstream_notif_iter
*muxer_upstream_notif_iter
)
144 if (!muxer_upstream_notif_iter
) {
148 BT_LOGD("Destroying muxer's upstream notification iterator wrapper: "
149 "addr=%p, notif-iter-addr=%p, is-valid=%d",
150 muxer_upstream_notif_iter
,
151 muxer_upstream_notif_iter
->notif_iter
,
152 muxer_upstream_notif_iter
->is_valid
);
153 bt_put(muxer_upstream_notif_iter
->notif_iter
);
154 g_free(muxer_upstream_notif_iter
);
158 struct muxer_upstream_notif_iter
*muxer_notif_iter_add_upstream_notif_iter(
159 struct muxer_notif_iter
*muxer_notif_iter
,
160 struct bt_notification_iterator
*notif_iter
,
161 struct bt_private_port
*priv_port
)
163 struct muxer_upstream_notif_iter
*muxer_upstream_notif_iter
=
164 g_new0(struct muxer_upstream_notif_iter
, 1);
166 if (!muxer_upstream_notif_iter
) {
167 BT_LOGE_STR("Failed to allocate one muxer's upstream notification iterator wrapper.");
171 muxer_upstream_notif_iter
->notif_iter
= bt_get(notif_iter
);
172 muxer_upstream_notif_iter
->is_valid
= false;
173 g_ptr_array_add(muxer_notif_iter
->muxer_upstream_notif_iters
,
174 muxer_upstream_notif_iter
);
175 BT_LOGD("Added muxer's upstream notification iterator wrapper: "
176 "addr=%p, muxer-notif-iter-addr=%p, notif-iter-addr=%p",
177 muxer_upstream_notif_iter
, muxer_notif_iter
,
181 return muxer_upstream_notif_iter
;
185 enum bt_component_status
ensure_available_input_port(
186 struct bt_private_component
*priv_comp
)
188 struct muxer_comp
*muxer_comp
=
189 bt_private_component_get_user_data(priv_comp
);
190 enum bt_component_status status
= BT_COMPONENT_STATUS_OK
;
191 GString
*port_name
= NULL
;
195 if (muxer_comp
->available_input_ports
>= 1) {
199 port_name
= g_string_new("in");
201 BT_LOGE_STR("Failed to allocate a GString.");
202 status
= BT_COMPONENT_STATUS_NOMEM
;
206 g_string_append_printf(port_name
, "%u", muxer_comp
->next_port_num
);
207 status
= bt_private_component_filter_add_input_private_port(
208 priv_comp
, port_name
->str
, NULL
, NULL
);
209 if (status
!= BT_COMPONENT_STATUS_OK
) {
210 BT_LOGE("Cannot add input port to muxer component: "
211 "port-name=\"%s\", comp-addr=%p, status=%s",
212 port_name
->str
, priv_comp
,
213 bt_component_status_string(status
));
217 muxer_comp
->available_input_ports
++;
218 muxer_comp
->next_port_num
++;
219 BT_LOGD("Added one input port to muxer component: "
220 "port-name=\"%s\", comp-addr=%p",
221 port_name
->str
, priv_comp
);
224 g_string_free(port_name
, TRUE
);
231 enum bt_component_status
create_output_port(
232 struct bt_private_component
*priv_comp
)
234 return bt_private_component_filter_add_output_private_port(
235 priv_comp
, "out", NULL
, NULL
);
239 void destroy_muxer_comp(struct muxer_comp
*muxer_comp
)
245 BT_LOGD("Destroying muxer component: muxer-comp-addr=%p, "
246 "muxer-notif-iter-count=%u", muxer_comp
,
247 muxer_comp
->muxer_notif_iters
?
248 muxer_comp
->muxer_notif_iters
->len
: 0);
250 if (muxer_comp
->muxer_notif_iters
) {
251 g_ptr_array_free(muxer_comp
->muxer_notif_iters
, TRUE
);
258 struct bt_value
*get_default_params(void)
260 struct bt_value
*params
;
263 params
= bt_value_map_create();
265 BT_LOGE_STR("Cannot create a map value object.");
269 ret
= bt_value_map_insert_bool(params
,
270 ASSUME_ABSOLUTE_CLOCK_CLASSES_PARAM_NAME
, false);
272 BT_LOGE_STR("Cannot add boolean value to map value object.");
286 int configure_muxer_comp(struct muxer_comp
*muxer_comp
, struct bt_value
*params
)
288 struct bt_value
*default_params
= NULL
;
289 struct bt_value
*real_params
= NULL
;
290 struct bt_value
*assume_absolute_clock_classes
= NULL
;
294 default_params
= get_default_params();
295 if (!default_params
) {
296 BT_LOGE("Cannot get default parameters: "
297 "muxer-comp-addr=%p", muxer_comp
);
301 real_params
= bt_value_map_extend(default_params
, params
);
303 BT_LOGE("Cannot extend default parameters map value: "
304 "muxer-comp-addr=%p, def-params-addr=%p, "
305 "params-addr=%p", muxer_comp
, default_params
,
310 assume_absolute_clock_classes
= bt_value_map_get(real_params
,
311 ASSUME_ABSOLUTE_CLOCK_CLASSES_PARAM_NAME
);
312 if (!bt_value_is_bool(assume_absolute_clock_classes
)) {
313 BT_LOGE("Expecting a boolean value for the `%s` parameter: "
314 "muxer-comp-addr=%p, value-type=%s",
315 ASSUME_ABSOLUTE_CLOCK_CLASSES_PARAM_NAME
, muxer_comp
,
316 bt_value_type_string(
317 bt_value_get_type(assume_absolute_clock_classes
)));
321 ret
= bt_value_bool_get(assume_absolute_clock_classes
, &bool_val
);
323 muxer_comp
->assume_absolute_clock_classes
= (bool) bool_val
;
324 BT_LOGD("Configured muxer component: muxer-comp-addr=%p, "
325 "assume-absolute-clock-classes=%d",
326 muxer_comp
, muxer_comp
->assume_absolute_clock_classes
);
333 bt_put(default_params
);
335 bt_put(assume_absolute_clock_classes
);
340 enum bt_component_status
muxer_init(
341 struct bt_private_component
*priv_comp
,
342 struct bt_value
*params
, void *init_data
)
345 enum bt_component_status status
= BT_COMPONENT_STATUS_OK
;
346 struct muxer_comp
*muxer_comp
= g_new0(struct muxer_comp
, 1);
348 BT_LOGD("Initializing muxer component: "
349 "comp-addr=%p, params-addr=%p", priv_comp
, params
);
352 BT_LOGE_STR("Failed to allocate one muxer component.");
356 ret
= configure_muxer_comp(muxer_comp
, params
);
358 BT_LOGE("Cannot configure muxer component: "
359 "muxer-comp-addr=%p, params-addr=%p",
364 muxer_comp
->muxer_notif_iters
= g_ptr_array_new();
365 if (!muxer_comp
->muxer_notif_iters
) {
366 BT_LOGE_STR("Failed to allocate a GPtrArray.");
370 muxer_comp
->priv_comp
= priv_comp
;
371 ret
= bt_private_component_set_user_data(priv_comp
, muxer_comp
);
373 status
= ensure_available_input_port(priv_comp
);
374 if (status
!= BT_COMPONENT_STATUS_OK
) {
375 BT_LOGE("Cannot ensure that at least one muxer component's input port is available: "
376 "muxer-comp-addr=%p, status=%s",
378 bt_component_status_string(status
));
382 status
= create_output_port(priv_comp
);
384 BT_LOGE("Cannot create muxer component's output port: "
385 "muxer-comp-addr=%p, status=%s",
387 bt_component_status_string(status
));
391 BT_LOGD("Initialized muxer component: "
392 "comp-addr=%p, params-addr=%p, muxer-comp-addr=%p",
393 priv_comp
, params
, muxer_comp
);
398 destroy_muxer_comp(muxer_comp
);
399 ret
= bt_private_component_set_user_data(priv_comp
, NULL
);
402 if (status
== BT_COMPONENT_STATUS_OK
) {
403 status
= BT_COMPONENT_STATUS_ERROR
;
411 void muxer_finalize(struct bt_private_component
*priv_comp
)
413 struct muxer_comp
*muxer_comp
=
414 bt_private_component_get_user_data(priv_comp
);
416 BT_LOGD("Finalizing muxer component: comp-addr=%p",
418 destroy_muxer_comp(muxer_comp
);
422 struct bt_notification_iterator
*create_notif_iter_on_input_port(
423 struct bt_private_port
*priv_port
, int *ret
)
425 struct bt_port
*port
= bt_port_from_private_port(priv_port
);
426 struct bt_notification_iterator
*notif_iter
= NULL
;
427 struct bt_private_connection
*priv_conn
= NULL
;
428 enum bt_connection_status conn_status
;
433 assert(bt_port_is_connected(port
));
434 priv_conn
= bt_private_port_get_private_connection(priv_port
);
437 // TODO: Advance the iterator to >= the time of the latest
438 // returned notification by the muxer notification
439 // iterator which creates it.
440 conn_status
= bt_private_connection_create_notification_iterator(
441 priv_conn
, NULL
, ¬if_iter
);
442 if (conn_status
!= BT_CONNECTION_STATUS_OK
) {
443 BT_LOGE("Cannot create upstream notification iterator on input port's connection: "
444 "port-addr=%p, port-name=\"%s\", conn-addr=%p, "
446 port
, bt_port_get_name(port
), priv_conn
,
447 bt_connection_status_string(conn_status
));
452 BT_LOGD("Created upstream notification iterator on input port's connection: "
453 "port-addr=%p, port-name=\"%s\", conn-addr=%p, "
454 "notif-iter-addr=%p",
455 port
, bt_port_get_name(port
), priv_conn
, notif_iter
);
464 enum bt_notification_iterator_status
muxer_upstream_notif_iter_next(
465 struct muxer_upstream_notif_iter
*muxer_upstream_notif_iter
)
467 enum bt_notification_iterator_status status
;
469 BT_LOGV("Calling upstream notification iterator's \"next\" method: "
470 "muxer-upstream-notif-iter-wrap-addr=%p, notif-iter-addr=%p",
471 muxer_upstream_notif_iter
,
472 muxer_upstream_notif_iter
->notif_iter
);
473 status
= bt_notification_iterator_next(
474 muxer_upstream_notif_iter
->notif_iter
);
475 BT_LOGV("Upstream notification iterator's \"next\" method returned: "
476 "status=%s", bt_notification_iterator_status_string(status
));
479 case BT_NOTIFICATION_ITERATOR_STATUS_OK
:
481 * Notification iterator's current notification is valid:
482 * it must be considered for muxing operations.
484 BT_LOGV_STR("Validated upstream notification iterator wrapper.");
485 muxer_upstream_notif_iter
->is_valid
= true;
487 case BT_NOTIFICATION_ITERATOR_STATUS_AGAIN
:
489 * Notification iterator's current notification is not
490 * valid anymore. Return
491 * BT_NOTIFICATION_ITERATOR_STATUS_AGAIN
494 BT_LOGV_STR("Invalidated upstream notification iterator wrapper because of BT_NOTIFICATION_ITERATOR_STATUS_AGAIN.");
495 muxer_upstream_notif_iter
->is_valid
= false;
497 case BT_NOTIFICATION_ITERATOR_STATUS_END
: /* Fall-through. */
498 case BT_NOTIFICATION_ITERATOR_STATUS_CANCELED
:
500 * Notification iterator reached the end: release it. It
501 * won't be considered again to find the youngest
504 BT_LOGV_STR("Invalidated upstream notification iterator wrapper because of BT_NOTIFICATION_ITERATOR_STATUS_END or BT_NOTIFICATION_ITERATOR_STATUS_CANCELED.");
505 BT_PUT(muxer_upstream_notif_iter
->notif_iter
);
506 muxer_upstream_notif_iter
->is_valid
= false;
507 status
= BT_NOTIFICATION_ITERATOR_STATUS_OK
;
510 /* Error or unsupported status code */
511 BT_LOGE("Error or unsupported status code: "
512 "status-code=%d", status
);
513 status
= BT_NOTIFICATION_ITERATOR_STATUS_ERROR
;
521 int muxer_notif_iter_handle_newly_connected_ports(
522 struct muxer_notif_iter
*muxer_notif_iter
)
526 BT_LOGV("Handling newly connected ports: "
527 "muxer-notif-iter-addr=%p", muxer_notif_iter
);
530 * Here we create one upstream notification iterator for each
531 * newly connected port. We do not perform an initial "next" on
532 * those new upstream notification iterators: they are
533 * invalidated, to be validated later. The list of newly
534 * connected ports to handle here is updated by
535 * muxer_port_connected().
538 GList
*node
= muxer_notif_iter
->newly_connected_priv_ports
;
539 struct bt_private_port
*priv_port
;
540 struct bt_port
*port
;
541 struct bt_notification_iterator
*upstream_notif_iter
= NULL
;
542 struct muxer_upstream_notif_iter
*muxer_upstream_notif_iter
;
548 priv_port
= node
->data
;
549 port
= bt_port_from_private_port(priv_port
);
552 if (!bt_port_is_connected(port
)) {
554 * Looks like this port is not connected
555 * anymore: we can't create an upstream
556 * notification iterator on its (non-existing)
557 * connection in this case.
563 upstream_notif_iter
= create_notif_iter_on_input_port(priv_port
,
566 /* create_notif_iter_on_input_port() logs errors */
567 assert(!upstream_notif_iter
);
571 muxer_upstream_notif_iter
=
572 muxer_notif_iter_add_upstream_notif_iter(
573 muxer_notif_iter
, upstream_notif_iter
,
575 BT_PUT(upstream_notif_iter
);
576 if (!muxer_upstream_notif_iter
) {
578 * muxer_notif_iter_add_upstream_notif_iter()
585 bt_put(upstream_notif_iter
);
587 muxer_notif_iter
->newly_connected_priv_ports
=
589 muxer_notif_iter
->newly_connected_priv_ports
,
605 int get_notif_ts_ns(struct muxer_comp
*muxer_comp
,
606 struct muxer_notif_iter
*muxer_notif_iter
,
607 struct bt_notification
*notif
, int64_t last_returned_ts_ns
,
610 struct bt_clock_class_priority_map
*cc_prio_map
= NULL
;
611 struct bt_ctf_clock_class
*clock_class
= NULL
;
612 struct bt_ctf_clock_value
*clock_value
= NULL
;
613 struct bt_ctf_event
*event
= NULL
;
615 const unsigned char *cc_uuid
;
621 BT_LOGV("Getting notification's timestamp: "
622 "muxer-notif-iter-addr=%p, notif-addr=%p, "
623 "last-returned-ts=%" PRId64
,
624 muxer_notif_iter
, notif
, last_returned_ts_ns
);
626 switch (bt_notification_get_type(notif
)) {
627 case BT_NOTIFICATION_TYPE_EVENT
:
629 bt_notification_event_get_clock_class_priority_map(
633 case BT_NOTIFICATION_TYPE_INACTIVITY
:
635 bt_notification_inactivity_get_clock_class_priority_map(
639 /* All the other notifications have a higher priority */
640 BT_LOGV_STR("Notification has no timestamp: using the last returned timestamp.");
641 *ts_ns
= last_returned_ts_ns
;
646 BT_LOGE("Cannot get notification's clock class priority map: "
647 "notif-addr=%p", notif
);
652 * If the clock class priority map is empty, then we consider
653 * that this notification has no time. In this case it's always
656 if (bt_clock_class_priority_map_get_clock_class_count(cc_prio_map
) == 0) {
657 BT_LOGV_STR("Notification's clock class priorty map contains 0 clock classes: "
658 "using the last returned timestamp.");
659 *ts_ns
= last_returned_ts_ns
;
664 bt_clock_class_priority_map_get_highest_priority_clock_class(
667 BT_LOGE("Cannot get the clock class with the highest priority from clock class priority map: "
668 "cc-prio-map-addr=%p", cc_prio_map
);
672 cc_uuid
= bt_ctf_clock_class_get_uuid(clock_class
);
673 cc_name
= bt_ctf_clock_class_get_name(clock_class
);
675 if (muxer_notif_iter
->clock_class_expectation
==
676 MUXER_NOTIF_ITER_CLOCK_CLASS_EXPECTATION_ANY
) {
678 * This is the first clock class that this muxer
679 * notification iterator encounters. Its properties
680 * determine what to expect for the whole lifetime of
681 * the iterator without a true
682 * `assume-absolute-clock-classes` parameter.
684 if (bt_ctf_clock_class_is_absolute(clock_class
)) {
685 /* Expect absolute clock classes */
686 muxer_notif_iter
->clock_class_expectation
=
687 MUXER_NOTIF_ITER_CLOCK_CLASS_EXPECTATION_ABSOLUTE
;
691 * Expect non-absolute clock classes
692 * with a specific UUID.
694 muxer_notif_iter
->clock_class_expectation
=
695 MUXER_NOTIF_ITER_CLOCK_CLASS_EXPECTATION_NOT_ABS_SPEC_UUID
;
696 memcpy(muxer_notif_iter
->expected_clock_class_uuid
,
697 cc_uuid
, BABELTRACE_UUID_LEN
);
700 * Expect non-absolute clock classes
703 muxer_notif_iter
->clock_class_expectation
=
704 MUXER_NOTIF_ITER_CLOCK_CLASS_EXPECTATION_NOT_ABS_NO_UUID
;
709 if (!muxer_comp
->assume_absolute_clock_classes
) {
710 switch (muxer_notif_iter
->clock_class_expectation
) {
711 case MUXER_NOTIF_ITER_CLOCK_CLASS_EXPECTATION_ABSOLUTE
:
712 if (!bt_ctf_clock_class_is_absolute(clock_class
)) {
713 BT_LOGE("Expecting an absolute clock class, "
714 "but got a non-absolute one: "
715 "clock-class-addr=%p, clock-class-name=\"%s\"",
716 clock_class
, cc_name
);
720 case MUXER_NOTIF_ITER_CLOCK_CLASS_EXPECTATION_NOT_ABS_NO_UUID
:
721 if (bt_ctf_clock_class_is_absolute(clock_class
)) {
722 BT_LOGE("Expecting a non-absolute clock class with no UUID, "
723 "but got an absolute one: "
724 "clock-class-addr=%p, clock-class-name=\"%s\"",
725 clock_class
, cc_name
);
730 BT_LOGE("Expecting a non-absolute clock class with no UUID, "
731 "but got one with a UUID: "
732 "clock-class-addr=%p, clock-class-name=\"%s\", "
733 "uuid=\"%02x%02x%02x%02x-%02x%02x-%02x%02x-%02x%02x-%02x%02x%02x%02x%02x%02x\"",
734 clock_class
, cc_name
,
735 (unsigned int) cc_uuid
[0],
736 (unsigned int) cc_uuid
[1],
737 (unsigned int) cc_uuid
[2],
738 (unsigned int) cc_uuid
[3],
739 (unsigned int) cc_uuid
[4],
740 (unsigned int) cc_uuid
[5],
741 (unsigned int) cc_uuid
[6],
742 (unsigned int) cc_uuid
[7],
743 (unsigned int) cc_uuid
[8],
744 (unsigned int) cc_uuid
[9],
745 (unsigned int) cc_uuid
[10],
746 (unsigned int) cc_uuid
[11],
747 (unsigned int) cc_uuid
[12],
748 (unsigned int) cc_uuid
[13],
749 (unsigned int) cc_uuid
[14],
750 (unsigned int) cc_uuid
[15]);
754 case MUXER_NOTIF_ITER_CLOCK_CLASS_EXPECTATION_NOT_ABS_SPEC_UUID
:
755 if (bt_ctf_clock_class_is_absolute(clock_class
)) {
756 BT_LOGE("Expecting a non-absolute clock class with a specific UUID, "
757 "but got an absolute one: "
758 "clock-class-addr=%p, clock-class-name=\"%s\"",
759 clock_class
, cc_name
);
764 BT_LOGE("Expecting a non-absolute clock class with a specific UUID, "
765 "but got one with no UUID: "
766 "clock-class-addr=%p, clock-class-name=\"%s\"",
767 clock_class
, cc_name
);
771 if (memcmp(muxer_notif_iter
->expected_clock_class_uuid
,
772 cc_uuid
, BABELTRACE_UUID_LEN
) != 0) {
773 BT_LOGE("Expecting a non-absolute clock class with a specific UUID, "
774 "but got one with different UUID: "
775 "clock-class-addr=%p, clock-class-name=\"%s\", "
776 "expected-uuid=\"%02x%02x%02x%02x-%02x%02x-%02x%02x-%02x%02x-%02x%02x%02x%02x%02x%02x\", "
777 "uuid=\"%02x%02x%02x%02x-%02x%02x-%02x%02x-%02x%02x-%02x%02x%02x%02x%02x%02x\"",
778 clock_class
, cc_name
,
779 (unsigned int) muxer_notif_iter
->expected_clock_class_uuid
[0],
780 (unsigned int) muxer_notif_iter
->expected_clock_class_uuid
[1],
781 (unsigned int) muxer_notif_iter
->expected_clock_class_uuid
[2],
782 (unsigned int) muxer_notif_iter
->expected_clock_class_uuid
[3],
783 (unsigned int) muxer_notif_iter
->expected_clock_class_uuid
[4],
784 (unsigned int) muxer_notif_iter
->expected_clock_class_uuid
[5],
785 (unsigned int) muxer_notif_iter
->expected_clock_class_uuid
[6],
786 (unsigned int) muxer_notif_iter
->expected_clock_class_uuid
[7],
787 (unsigned int) muxer_notif_iter
->expected_clock_class_uuid
[8],
788 (unsigned int) muxer_notif_iter
->expected_clock_class_uuid
[9],
789 (unsigned int) muxer_notif_iter
->expected_clock_class_uuid
[10],
790 (unsigned int) muxer_notif_iter
->expected_clock_class_uuid
[11],
791 (unsigned int) muxer_notif_iter
->expected_clock_class_uuid
[12],
792 (unsigned int) muxer_notif_iter
->expected_clock_class_uuid
[13],
793 (unsigned int) muxer_notif_iter
->expected_clock_class_uuid
[14],
794 (unsigned int) muxer_notif_iter
->expected_clock_class_uuid
[15],
795 (unsigned int) cc_uuid
[0],
796 (unsigned int) cc_uuid
[1],
797 (unsigned int) cc_uuid
[2],
798 (unsigned int) cc_uuid
[3],
799 (unsigned int) cc_uuid
[4],
800 (unsigned int) cc_uuid
[5],
801 (unsigned int) cc_uuid
[6],
802 (unsigned int) cc_uuid
[7],
803 (unsigned int) cc_uuid
[8],
804 (unsigned int) cc_uuid
[9],
805 (unsigned int) cc_uuid
[10],
806 (unsigned int) cc_uuid
[11],
807 (unsigned int) cc_uuid
[12],
808 (unsigned int) cc_uuid
[13],
809 (unsigned int) cc_uuid
[14],
810 (unsigned int) cc_uuid
[15]);
816 BT_LOGF("Unexpected clock class expectation: "
817 "expectation-code=%d",
818 muxer_notif_iter
->clock_class_expectation
);
823 switch (bt_notification_get_type(notif
)) {
824 case BT_NOTIFICATION_TYPE_EVENT
:
825 event
= bt_notification_event_get_event(notif
);
827 clock_value
= bt_ctf_event_get_clock_value(event
,
830 case BT_NOTIFICATION_TYPE_INACTIVITY
:
831 clock_value
= bt_notification_inactivity_get_clock_value(
835 BT_LOGF("Unexpected notification type at this point: "
836 "type=%d", bt_notification_get_type(notif
));
841 BT_LOGE("Cannot get notification's clock value for clock class: "
842 "clock-class-addr=%p, clock-class-name=\"%s\"",
843 clock_class
, cc_name
);
847 ret
= bt_ctf_clock_value_get_value_ns_from_epoch(clock_value
, ts_ns
);
849 BT_LOGE("Cannot get nanoseconds from Epoch of clock value: "
850 "clock-value-addr=%p", clock_value
);
861 BT_LOGV("Found notification's timestamp: "
862 "muxer-notif-iter-addr=%p, notif-addr=%p, "
863 "last-returned-ts=%" PRId64
", ts=%" PRId64
,
864 muxer_notif_iter
, notif
, last_returned_ts_ns
,
876 * This function finds the youngest available notification amongst the
877 * non-ended upstream notification iterators and returns the upstream
878 * notification iterator which has it, or
879 * BT_NOTIFICATION_ITERATOR_STATUS_END if there's no available
882 * This function does NOT:
884 * * Update any upstream notification iterator.
885 * * Check for newly connected ports.
886 * * Check the upstream notification iterators to retry.
888 * On sucess, this function sets *muxer_upstream_notif_iter to the
889 * upstream notification iterator of which the current notification is
890 * the youngest, and sets *ts_ns to its time.
893 enum bt_notification_iterator_status
894 muxer_notif_iter_youngest_upstream_notif_iter(
895 struct muxer_comp
*muxer_comp
,
896 struct muxer_notif_iter
*muxer_notif_iter
,
897 struct muxer_upstream_notif_iter
**muxer_upstream_notif_iter
,
902 int64_t youngest_ts_ns
= INT64_MAX
;
903 enum bt_notification_iterator_status status
=
904 BT_NOTIFICATION_ITERATOR_STATUS_OK
;
907 assert(muxer_notif_iter
);
908 assert(muxer_upstream_notif_iter
);
909 *muxer_upstream_notif_iter
= NULL
;
911 for (i
= 0; i
< muxer_notif_iter
->muxer_upstream_notif_iters
->len
; i
++) {
912 struct bt_notification
*notif
;
913 struct muxer_upstream_notif_iter
*cur_muxer_upstream_notif_iter
=
914 g_ptr_array_index(muxer_notif_iter
->muxer_upstream_notif_iters
, i
);
917 if (!cur_muxer_upstream_notif_iter
->notif_iter
) {
918 /* This upstream notification iterator is ended */
919 BT_LOGV("Skipping ended upstream notification iterator: "
920 "muxer-upstream-notif-iter-wrap-addr=%p",
921 cur_muxer_upstream_notif_iter
);
925 assert(cur_muxer_upstream_notif_iter
->is_valid
);
926 notif
= bt_notification_iterator_get_notification(
927 cur_muxer_upstream_notif_iter
->notif_iter
);
929 ret
= get_notif_ts_ns(muxer_comp
, muxer_notif_iter
, notif
,
930 muxer_notif_iter
->last_returned_ts_ns
, ¬if_ts_ns
);
933 /* get_notif_ts_ns() logs errors */
934 *muxer_upstream_notif_iter
= NULL
;
935 status
= BT_NOTIFICATION_ITERATOR_STATUS_ERROR
;
939 if (notif_ts_ns
<= youngest_ts_ns
) {
940 *muxer_upstream_notif_iter
=
941 cur_muxer_upstream_notif_iter
;
942 youngest_ts_ns
= notif_ts_ns
;
943 *ts_ns
= youngest_ts_ns
;
947 if (!*muxer_upstream_notif_iter
) {
948 status
= BT_NOTIFICATION_ITERATOR_STATUS_END
;
957 enum bt_notification_iterator_status
validate_muxer_upstream_notif_iter(
958 struct muxer_upstream_notif_iter
*muxer_upstream_notif_iter
)
960 enum bt_notification_iterator_status status
=
961 BT_NOTIFICATION_ITERATOR_STATUS_OK
;
963 BT_LOGV("Validating muxer's upstream notification iterator wrapper: "
964 "muxer-upstream-notif-iter-wrap-addr=%p",
965 muxer_upstream_notif_iter
);
967 if (muxer_upstream_notif_iter
->is_valid
||
968 !muxer_upstream_notif_iter
->notif_iter
) {
972 /* muxer_upstream_notif_iter_next() logs details/errors */
973 status
= muxer_upstream_notif_iter_next(muxer_upstream_notif_iter
);
980 enum bt_notification_iterator_status
validate_muxer_upstream_notif_iters(
981 struct muxer_notif_iter
*muxer_notif_iter
)
983 enum bt_notification_iterator_status status
=
984 BT_NOTIFICATION_ITERATOR_STATUS_OK
;
987 BT_LOGV("Validating muxer's upstream notification iterator wrappers: "
988 "muxer-notif-iter-addr=%p", muxer_notif_iter
);
990 for (i
= 0; i
< muxer_notif_iter
->muxer_upstream_notif_iters
->len
; i
++) {
991 struct muxer_upstream_notif_iter
*muxer_upstream_notif_iter
=
993 muxer_notif_iter
->muxer_upstream_notif_iters
,
996 status
= validate_muxer_upstream_notif_iter(
997 muxer_upstream_notif_iter
);
998 if (status
!= BT_NOTIFICATION_ITERATOR_STATUS_OK
) {
1000 BT_LOGE("Cannot validate muxer's upstream notification iterator wrapper: "
1001 "muxer-notif-iter-addr=%p, "
1002 "muxer-upstream-notif-iter-wrap-addr=%p",
1004 muxer_upstream_notif_iter
);
1006 BT_LOGV("Cannot validate muxer's upstream notification iterator wrapper: "
1007 "muxer-notif-iter-addr=%p, "
1008 "muxer-upstream-notif-iter-wrap-addr=%p",
1010 muxer_upstream_notif_iter
);
1017 * Remove this muxer upstream notification iterator
1018 * if it's ended or canceled.
1020 if (!muxer_upstream_notif_iter
->notif_iter
) {
1022 * Use g_ptr_array_remove_fast() because the
1023 * order of those elements is not important.
1025 BT_LOGV("Removing muxer's upstream notification iterator wrapper: ended or canceled: "
1026 "muxer-notif-iter-addr=%p, "
1027 "muxer-upstream-notif-iter-wrap-addr=%p",
1028 muxer_notif_iter
, muxer_upstream_notif_iter
);
1029 g_ptr_array_remove_index_fast(
1030 muxer_notif_iter
->muxer_upstream_notif_iters
,
1041 struct bt_notification_iterator_next_method_return
muxer_notif_iter_do_next(
1042 struct muxer_comp
*muxer_comp
,
1043 struct muxer_notif_iter
*muxer_notif_iter
)
1045 struct muxer_upstream_notif_iter
*muxer_upstream_notif_iter
= NULL
;
1046 struct bt_notification_iterator_next_method_return next_return
= {
1047 .notification
= NULL
,
1048 .status
= BT_NOTIFICATION_ITERATOR_STATUS_OK
,
1050 int64_t next_return_ts
;
1053 int ret
= muxer_notif_iter_handle_newly_connected_ports(
1057 BT_LOGE("Cannot handle newly connected input ports for muxer's notification iterator: "
1058 "muxer-comp-addr=%p, muxer-notif-iter-addr=%p, "
1060 muxer_comp
, muxer_notif_iter
, ret
);
1061 next_return
.status
=
1062 BT_NOTIFICATION_ITERATOR_STATUS_ERROR
;
1066 next_return
.status
=
1067 validate_muxer_upstream_notif_iters(muxer_notif_iter
);
1068 if (next_return
.status
!= BT_NOTIFICATION_ITERATOR_STATUS_OK
) {
1069 /* validate_muxer_upstream_notif_iters() logs details */
1074 * At this point, we know that all the existing upstream
1075 * notification iterators are valid. However the
1076 * operations to validate them (during
1077 * validate_muxer_upstream_notif_iters()) may have
1078 * connected new ports. If no ports were connected
1079 * during this operation, exit the loop.
1081 if (!muxer_notif_iter
->newly_connected_priv_ports
) {
1082 BT_LOGV("Not breaking this loop: muxer's notification iterator still has newly connected input ports to handle: "
1083 "muxer-comp-addr=%p", muxer_comp
);
1088 assert(!muxer_notif_iter
->newly_connected_priv_ports
);
1091 * At this point we know that all the existing upstream
1092 * notification iterators are valid. We can find the one,
1093 * amongst those, of which the current notification is the
1096 next_return
.status
=
1097 muxer_notif_iter_youngest_upstream_notif_iter(muxer_comp
,
1098 muxer_notif_iter
, &muxer_upstream_notif_iter
,
1100 if (next_return
.status
< 0 ||
1101 next_return
.status
== BT_NOTIFICATION_ITERATOR_STATUS_END
||
1102 next_return
.status
== BT_NOTIFICATION_ITERATOR_STATUS_CANCELED
) {
1103 if (next_return
.status
< 0) {
1104 BT_LOGE("Cannot find the youngest upstream notification iterator wrapper: "
1106 bt_notification_iterator_status_string(next_return
.status
));
1108 BT_LOGV("Cannot find the youngest upstream notification iterator wrapper: "
1110 bt_notification_iterator_status_string(next_return
.status
));
1116 if (next_return_ts
< muxer_notif_iter
->last_returned_ts_ns
) {
1117 BT_LOGE("Youngest upstream notification iterator wrapper's timestamp is less than muxer's notification iterator's last returned timestamp: "
1118 "muxer-notif-iter-addr=%p, ts=%" PRId64
", "
1119 "last-returned-ts=%" PRId64
,
1120 muxer_notif_iter
, next_return_ts
,
1121 muxer_notif_iter
->last_returned_ts_ns
);
1122 next_return
.status
= BT_NOTIFICATION_ITERATOR_STATUS_ERROR
;
1126 BT_LOGV("Found youngest upstream notification iterator wrapper: "
1127 "muxer-notif-iter-addr=%p, "
1128 "muxer-upstream-notif-iter-wrap-addr=%p, "
1130 muxer_notif_iter
, muxer_upstream_notif_iter
, next_return_ts
);
1131 assert(next_return
.status
== BT_NOTIFICATION_ITERATOR_STATUS_OK
);
1132 assert(muxer_upstream_notif_iter
);
1133 next_return
.notification
= bt_notification_iterator_get_notification(
1134 muxer_upstream_notif_iter
->notif_iter
);
1135 assert(next_return
.notification
);
1138 * We invalidate the upstream notification iterator so that, the
1139 * next time this function is called,
1140 * validate_muxer_upstream_notif_iters() will make it valid.
1142 muxer_upstream_notif_iter
->is_valid
= false;
1143 muxer_notif_iter
->last_returned_ts_ns
= next_return_ts
;
1150 void destroy_muxer_notif_iter(struct muxer_notif_iter
*muxer_notif_iter
)
1152 if (!muxer_notif_iter
) {
1156 BT_LOGD("Destroying muxer component's notification iterator: "
1157 "muxer-notif-iter-addr=%p", muxer_notif_iter
);
1159 if (muxer_notif_iter
->muxer_upstream_notif_iters
) {
1160 BT_LOGD_STR("Destroying muxer's upstream notification iterator wrappers.");
1162 muxer_notif_iter
->muxer_upstream_notif_iters
, TRUE
);
1165 g_list_free(muxer_notif_iter
->newly_connected_priv_ports
);
1166 g_free(muxer_notif_iter
);
1170 int muxer_notif_iter_init_newly_connected_ports(struct muxer_comp
*muxer_comp
,
1171 struct muxer_notif_iter
*muxer_notif_iter
)
1173 struct bt_component
*comp
;
1179 * Add the connected input ports to this muxer notification
1180 * iterator's list of newly connected ports. They will be
1181 * handled by muxer_notif_iter_handle_newly_connected_ports().
1183 comp
= bt_component_from_private_component(muxer_comp
->priv_comp
);
1185 count
= bt_component_filter_get_input_port_count(comp
);
1187 BT_LOGD("No input port to initialize for muxer component's notification iterator: "
1188 "muxer-comp-addr=%p, muxer-notif-iter-addr=%p",
1189 muxer_comp
, muxer_notif_iter
);
1193 for (i
= 0; i
< count
; i
++) {
1194 struct bt_private_port
*priv_port
=
1195 bt_private_component_filter_get_input_private_port_by_index(
1196 muxer_comp
->priv_comp
, i
);
1197 struct bt_port
*port
;
1200 port
= bt_port_from_private_port(priv_port
);
1203 if (!bt_port_is_connected(port
)) {
1204 BT_LOGD("Skipping input port: not connected: "
1205 "muxer-comp-addr=%p, port-addr=%p, port-name\"%s\"",
1206 muxer_comp
, port
, bt_port_get_name(port
));
1214 muxer_notif_iter
->newly_connected_priv_ports
=
1216 muxer_notif_iter
->newly_connected_priv_ports
,
1218 if (!muxer_notif_iter
->newly_connected_priv_ports
) {
1219 BT_LOGE("Cannot append port to muxer's notification iterator list of newly connected input ports: "
1220 "port-addr=%p, port-name=\"%s\", "
1221 "muxer-notif-iter-addr=%p", port
,
1222 bt_port_get_name(port
), muxer_notif_iter
);
1227 BT_LOGD("Appended port to muxer's notification iterator list of newly connected input ports: "
1228 "port-addr=%p, port-name=\"%s\", "
1229 "muxer-notif-iter-addr=%p", port
,
1230 bt_port_get_name(port
), muxer_notif_iter
);
1239 enum bt_notification_iterator_status
muxer_notif_iter_init(
1240 struct bt_private_connection_private_notification_iterator
*priv_notif_iter
,
1241 struct bt_private_port
*output_priv_port
)
1243 struct muxer_comp
*muxer_comp
= NULL
;
1244 struct muxer_notif_iter
*muxer_notif_iter
= NULL
;
1245 struct bt_private_component
*priv_comp
= NULL
;
1246 enum bt_notification_iterator_status status
=
1247 BT_NOTIFICATION_ITERATOR_STATUS_OK
;
1250 priv_comp
= bt_private_connection_private_notification_iterator_get_private_component(
1253 muxer_comp
= bt_private_component_get_user_data(priv_comp
);
1255 BT_LOGD("Initializing muxer component's notification iterator: "
1256 "comp-addr=%p, muxer-comp-addr=%p, notif-iter-addr=%p",
1257 priv_comp
, muxer_comp
, priv_notif_iter
);
1259 if (muxer_comp
->initializing_muxer_notif_iter
) {
1261 * Weird, unhandled situation detected: downstream
1262 * creates a muxer notification iterator while creating
1263 * another muxer notification iterator (same component).
1265 BT_LOGE("Recursive initialization of muxer component's notification iterator: "
1266 "comp-addr=%p, muxer-comp-addr=%p, notif-iter-addr=%p",
1267 priv_comp
, muxer_comp
, priv_notif_iter
);
1271 muxer_comp
->initializing_muxer_notif_iter
= true;
1272 muxer_notif_iter
= g_new0(struct muxer_notif_iter
, 1);
1273 if (!muxer_notif_iter
) {
1274 BT_LOGE_STR("Failed to allocate one muxer component's notification iterator.");
1278 muxer_notif_iter
->last_returned_ts_ns
= INT64_MIN
;
1279 muxer_notif_iter
->muxer_upstream_notif_iters
=
1280 g_ptr_array_new_with_free_func(
1281 (GDestroyNotify
) destroy_muxer_upstream_notif_iter
);
1282 if (!muxer_notif_iter
->muxer_upstream_notif_iters
) {
1283 BT_LOGE_STR("Failed to allocate a GPtrArray.");
1288 * Add the muxer notification iterator to the component's array
1289 * of muxer notification iterators here because
1290 * muxer_notif_iter_init_newly_connected_ports() can cause
1291 * muxer_port_connected() to be called, which adds the newly
1292 * connected port to each muxer notification iterator's list of
1293 * newly connected ports.
1295 g_ptr_array_add(muxer_comp
->muxer_notif_iters
, muxer_notif_iter
);
1296 ret
= muxer_notif_iter_init_newly_connected_ports(muxer_comp
,
1299 BT_LOGE("Cannot initialize newly connected input ports for muxer component's notification iterator: "
1300 "comp-addr=%p, muxer-comp-addr=%p, "
1301 "muxer-notif-iter-addr=%p, notif-iter-addr=%p, ret=%d",
1302 priv_comp
, muxer_comp
, muxer_notif_iter
,
1303 priv_notif_iter
, ret
);
1307 ret
= bt_private_connection_private_notification_iterator_set_user_data(priv_notif_iter
,
1310 BT_LOGD("Initialized muxer component's notification iterator: "
1311 "comp-addr=%p, muxer-comp-addr=%p, muxer-notif-iter-addr=%p, "
1312 "notif-iter-addr=%p",
1313 priv_comp
, muxer_comp
, muxer_notif_iter
, priv_notif_iter
);
1317 if (g_ptr_array_index(muxer_comp
->muxer_notif_iters
,
1318 muxer_comp
->muxer_notif_iters
->len
- 1) == muxer_notif_iter
) {
1319 g_ptr_array_remove_index(muxer_comp
->muxer_notif_iters
,
1320 muxer_comp
->muxer_notif_iters
->len
- 1);
1323 destroy_muxer_notif_iter(muxer_notif_iter
);
1324 ret
= bt_private_connection_private_notification_iterator_set_user_data(priv_notif_iter
,
1327 status
= BT_NOTIFICATION_ITERATOR_STATUS_ERROR
;
1330 muxer_comp
->initializing_muxer_notif_iter
= false;
1336 void muxer_notif_iter_finalize(
1337 struct bt_private_connection_private_notification_iterator
*priv_notif_iter
)
1339 struct muxer_notif_iter
*muxer_notif_iter
=
1340 bt_private_connection_private_notification_iterator_get_user_data(priv_notif_iter
);
1341 struct bt_private_component
*priv_comp
= NULL
;
1342 struct muxer_comp
*muxer_comp
= NULL
;
1344 priv_comp
= bt_private_connection_private_notification_iterator_get_private_component(
1347 muxer_comp
= bt_private_component_get_user_data(priv_comp
);
1348 BT_LOGD("Finalizing muxer component's notification iterator: "
1349 "comp-addr=%p, muxer-comp-addr=%p, muxer-notif-iter-addr=%p, "
1350 "notif-iter-addr=%p",
1351 priv_comp
, muxer_comp
, muxer_notif_iter
, priv_notif_iter
);
1354 (void) g_ptr_array_remove_fast(muxer_comp
->muxer_notif_iters
,
1356 destroy_muxer_notif_iter(muxer_notif_iter
);
1363 struct bt_notification_iterator_next_method_return
muxer_notif_iter_next(
1364 struct bt_private_connection_private_notification_iterator
*priv_notif_iter
)
1366 struct bt_notification_iterator_next_method_return next_ret
;
1367 struct muxer_notif_iter
*muxer_notif_iter
=
1368 bt_private_connection_private_notification_iterator_get_user_data(priv_notif_iter
);
1369 struct bt_private_component
*priv_comp
= NULL
;
1370 struct muxer_comp
*muxer_comp
= NULL
;
1372 assert(muxer_notif_iter
);
1373 priv_comp
= bt_private_connection_private_notification_iterator_get_private_component(
1376 muxer_comp
= bt_private_component_get_user_data(priv_comp
);
1379 BT_LOGV("Muxer component's notification iterator's \"next\" method called: "
1380 "comp-addr=%p, muxer-comp-addr=%p, muxer-notif-iter-addr=%p, "
1381 "notif-iter-addr=%p",
1382 priv_comp
, muxer_comp
, muxer_notif_iter
, priv_notif_iter
);
1384 /* Are we in an error state set elsewhere? */
1385 if (unlikely(muxer_comp
->error
)) {
1386 BT_LOGE("Muxer component is already in an error state: returning BT_NOTIFICATION_ITERATOR_STATUS_ERROR: "
1387 "comp-addr=%p, muxer-comp-addr=%p, muxer-notif-iter-addr=%p, "
1388 "notif-iter-addr=%p",
1389 priv_comp
, muxer_comp
, muxer_notif_iter
, priv_notif_iter
);
1390 next_ret
.notification
= NULL
;
1391 next_ret
.status
= BT_NOTIFICATION_ITERATOR_STATUS_ERROR
;
1395 next_ret
= muxer_notif_iter_do_next(muxer_comp
, muxer_notif_iter
);
1396 if (next_ret
.status
< 0) {
1397 BT_LOGE("Cannot get next notification: "
1398 "comp-addr=%p, muxer-comp-addr=%p, muxer-notif-iter-addr=%p, "
1399 "notif-iter-addr=%p, status=%s",
1400 priv_comp
, muxer_comp
, muxer_notif_iter
, priv_notif_iter
,
1401 bt_notification_iterator_status_string(next_ret
.status
));
1403 BT_LOGV("Returning from muxer component's notification iterator's \"next\" method: "
1404 "status=%s, notif-addr=%p",
1405 bt_notification_iterator_status_string(next_ret
.status
),
1406 next_ret
.notification
);
1415 void muxer_port_connected(
1416 struct bt_private_component
*priv_comp
,
1417 struct bt_private_port
*self_private_port
,
1418 struct bt_port
*other_port
)
1420 struct bt_port
*self_port
=
1421 bt_port_from_private_port(self_private_port
);
1422 struct muxer_comp
*muxer_comp
=
1423 bt_private_component_get_user_data(priv_comp
);
1429 BT_LOGD("Port connected: "
1430 "comp-addr=%p, muxer-comp-addr=%p, "
1431 "port-addr=%p, port-name=\"%s\", "
1432 "other-port-addr=%p, other-port-name=\"%s\"",
1433 priv_comp
, muxer_comp
, self_port
, bt_port_get_name(self_port
),
1434 other_port
, bt_port_get_name(other_port
));
1436 if (bt_port_get_type(self_port
) == BT_PORT_TYPE_OUTPUT
) {
1440 for (i
= 0; i
< muxer_comp
->muxer_notif_iters
->len
; i
++) {
1441 struct muxer_notif_iter
*muxer_notif_iter
=
1442 g_ptr_array_index(muxer_comp
->muxer_notif_iters
, i
);
1445 * Add this port to the list of newly connected ports
1446 * for this muxer notification iterator. We append at
1447 * the end of this list while
1448 * muxer_notif_iter_handle_newly_connected_ports()
1449 * removes the nodes from the beginning.
1451 muxer_notif_iter
->newly_connected_priv_ports
=
1453 muxer_notif_iter
->newly_connected_priv_ports
,
1455 if (!muxer_notif_iter
->newly_connected_priv_ports
) {
1456 BT_LOGE("Cannot append port to muxer's notification iterator list of newly connected input ports: "
1457 "port-addr=%p, port-name=\"%s\", "
1458 "muxer-notif-iter-addr=%p", self_port
,
1459 bt_port_get_name(self_port
), muxer_notif_iter
);
1460 muxer_comp
->error
= true;
1464 BT_LOGD("Appended port to muxer's notification iterator list of newly connected input ports: "
1465 "port-addr=%p, port-name=\"%s\", "
1466 "muxer-notif-iter-addr=%p", self_port
,
1467 bt_port_get_name(self_port
), muxer_notif_iter
);
1470 /* One less available input port */
1471 muxer_comp
->available_input_ports
--;
1472 ret
= ensure_available_input_port(priv_comp
);
1475 * Only way to report an error later since this
1476 * method does not return anything.
1478 BT_LOGE("Cannot ensure that at least one muxer component's input port is available: "
1479 "muxer-comp-addr=%p, status=%s",
1480 muxer_comp
, bt_component_status_string(ret
));
1481 muxer_comp
->error
= true;
1490 void muxer_port_disconnected(struct bt_private_component
*priv_comp
,
1491 struct bt_private_port
*priv_port
)
1493 struct bt_port
*port
= bt_port_from_private_port(priv_port
);
1494 struct muxer_comp
*muxer_comp
=
1495 bt_private_component_get_user_data(priv_comp
);
1499 BT_LOGD("Port disconnected: "
1500 "comp-addr=%p, muxer-comp-addr=%p, port-addr=%p, "
1501 "port-name=\"%s\"", priv_comp
, muxer_comp
,
1502 port
, bt_port_get_name(port
));
1505 * There's nothing special to do when a port is disconnected
1506 * because this component deals with upstream notification
1507 * iterators which were already created thanks to connected
1508 * ports. The fact that the port is disconnected does not cancel
1509 * the upstream notification iterators created using its
1510 * connection: they still exist, even if the connection is dead.
1511 * The only way to remove an upstream notification iterator is
1512 * for its "next" operation to return
1513 * BT_NOTIFICATION_ITERATOR_STATUS_END.
1515 if (bt_port_get_type(port
) == BT_PORT_TYPE_INPUT
) {
1516 /* One more available input port */
1517 muxer_comp
->available_input_ports
++;
1518 BT_LOGD("Leaving disconnected input port available for future connections: "
1519 "comp-addr=%p, muxer-comp-addr=%p, port-addr=%p, "
1520 "port-name=\"%s\", avail-input-port-count=%zu",
1521 priv_comp
, muxer_comp
, port
, bt_port_get_name(port
),
1522 muxer_comp
->available_input_ports
);