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-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"
60 /* Array of struct bt_private_notification_iterator * (weak refs) */
61 GPtrArray
*muxer_notif_iters
;
64 struct bt_private_component
*priv_comp
;
65 unsigned int next_port_num
;
66 size_t available_input_ports
;
68 bool initializing_muxer_notif_iter
;
69 bool assume_absolute_clock_classes
;
72 struct muxer_upstream_notif_iter
{
73 /* Owned by this, NULL if ended */
74 struct bt_notification_iterator
*notif_iter
;
77 * This flag is true if the upstream notification iterator's
78 * current notification must be considered for the multiplexing
79 * operations. If the upstream iterator returns
80 * BT_NOTIFICATION_ITERATOR_STATUS_AGAIN, then this object
81 * is considered invalid, because its current notification is
82 * still the previous one, but we already took it into account.
84 * The value of this flag is not important if notif_iter above
85 * is NULL (which means the upstream iterator is finished).
90 enum muxer_notif_iter_clock_class_expectation
{
91 MUXER_NOTIF_ITER_CLOCK_CLASS_EXPECTATION_ANY
= 0,
92 MUXER_NOTIF_ITER_CLOCK_CLASS_EXPECTATION_ABSOLUTE
,
93 MUXER_NOTIF_ITER_CLOCK_CLASS_EXPECTATION_NOT_ABS_SPEC_UUID
,
94 MUXER_NOTIF_ITER_CLOCK_CLASS_EXPECTATION_NOT_ABS_NO_UUID
,
97 struct muxer_notif_iter
{
99 * Array of struct muxer_upstream_notif_iter * (owned by this).
101 * NOTE: This array is searched in linearly to find the youngest
102 * current notification. Keep this until benchmarks confirm that
103 * another data structure is faster than this for our typical
106 GPtrArray
*muxer_upstream_notif_iters
;
109 * List of "recently" connected input ports (weak) to
110 * handle by this muxer notification iterator.
111 * muxer_port_connected() adds entries to this list, and the
112 * entries are removed when a notification iterator is created
113 * on the port's connection and put into
114 * muxer_upstream_notif_iters above by
115 * muxer_notif_iter_handle_newly_connected_ports().
117 GList
*newly_connected_priv_ports
;
119 /* Next thing to return by the "next" method */
120 struct bt_notification_iterator_next_return next_next_return
;
122 /* Last time returned in a notification */
123 int64_t last_returned_ts_ns
;
125 /* Clock class expectation state */
126 enum muxer_notif_iter_clock_class_expectation clock_class_expectation
;
129 * Expected clock class UUID, only valid when
130 * clock_class_expectation is
131 * MUXER_NOTIF_ITER_CLOCK_CLASS_EXPECTATION_NOT_ABS_SPEC_UUID.
133 unsigned char expected_clock_class_uuid
[BABELTRACE_UUID_LEN
];
137 void destroy_muxer_upstream_notif_iter(
138 struct muxer_upstream_notif_iter
*muxer_upstream_notif_iter
)
140 if (!muxer_upstream_notif_iter
) {
144 BT_LOGD("Destroying muxer's upstream notification iterator wrapper: "
145 "addr=%p, notif-iter-addr=%p, is-valid=%d",
146 muxer_upstream_notif_iter
,
147 muxer_upstream_notif_iter
->notif_iter
,
148 muxer_upstream_notif_iter
->is_valid
);
149 bt_put(muxer_upstream_notif_iter
->notif_iter
);
150 g_free(muxer_upstream_notif_iter
);
154 struct muxer_upstream_notif_iter
*muxer_notif_iter_add_upstream_notif_iter(
155 struct muxer_notif_iter
*muxer_notif_iter
,
156 struct bt_notification_iterator
*notif_iter
,
157 struct bt_private_port
*priv_port
)
159 struct muxer_upstream_notif_iter
*muxer_upstream_notif_iter
=
160 g_new0(struct muxer_upstream_notif_iter
, 1);
162 if (!muxer_upstream_notif_iter
) {
163 BT_LOGE_STR("Failed to allocate one muxer's upstream notification iterator wrapper.");
167 muxer_upstream_notif_iter
->notif_iter
= bt_get(notif_iter
);
168 muxer_upstream_notif_iter
->is_valid
= false;
169 g_ptr_array_add(muxer_notif_iter
->muxer_upstream_notif_iters
,
170 muxer_upstream_notif_iter
);
171 BT_LOGD("Added muxer's upstream notification iterator wrapper: "
172 "addr=%p, muxer-notif-iter-addr=%p, notif-iter-addr=%p",
173 muxer_upstream_notif_iter
, muxer_notif_iter
,
177 return muxer_upstream_notif_iter
;
181 enum bt_component_status
ensure_available_input_port(
182 struct bt_private_component
*priv_comp
)
184 struct muxer_comp
*muxer_comp
=
185 bt_private_component_get_user_data(priv_comp
);
186 enum bt_component_status status
= BT_COMPONENT_STATUS_OK
;
187 GString
*port_name
= NULL
;
191 if (muxer_comp
->available_input_ports
>= 1) {
195 port_name
= g_string_new("in");
197 BT_LOGE_STR("Failed to allocate a GString.");
198 status
= BT_COMPONENT_STATUS_NOMEM
;
202 g_string_append_printf(port_name
, "%u", muxer_comp
->next_port_num
);
203 status
= bt_private_component_filter_add_input_private_port(
204 priv_comp
, port_name
->str
, NULL
, NULL
);
205 if (status
!= BT_COMPONENT_STATUS_OK
) {
206 BT_LOGE("Cannot add input port to muxer component: "
207 "port-name=\"%s\", comp-addr=%p, status=%s",
208 port_name
->str
, priv_comp
,
209 bt_component_status_string(status
));
213 muxer_comp
->available_input_ports
++;
214 muxer_comp
->next_port_num
++;
215 BT_LOGD("Added one input port to muxer component: "
216 "port-name=\"%s\", comp-addr=%p",
217 port_name
->str
, priv_comp
);
220 g_string_free(port_name
, TRUE
);
227 enum bt_component_status
create_output_port(
228 struct bt_private_component
*priv_comp
)
230 return bt_private_component_filter_add_output_private_port(
231 priv_comp
, "out", NULL
, NULL
);
235 void destroy_muxer_comp(struct muxer_comp
*muxer_comp
)
241 BT_LOGD("Destroying muxer component: muxer-comp-addr=%p, "
242 "muxer-notif-iter-count=%u", muxer_comp
,
243 muxer_comp
->muxer_notif_iters
?
244 muxer_comp
->muxer_notif_iters
->len
: 0);
246 if (muxer_comp
->muxer_notif_iters
) {
247 g_ptr_array_free(muxer_comp
->muxer_notif_iters
, TRUE
);
254 struct bt_value
*get_default_params(void)
256 struct bt_value
*params
;
259 params
= bt_value_map_create();
261 BT_LOGE_STR("Cannot create a map value object.");
265 ret
= bt_value_map_insert_bool(params
,
266 ASSUME_ABSOLUTE_CLOCK_CLASSES_PARAM_NAME
, false);
268 BT_LOGE_STR("Cannot add boolean value to map value object.");
282 int configure_muxer_comp(struct muxer_comp
*muxer_comp
, struct bt_value
*params
)
284 struct bt_value
*default_params
= NULL
;
285 struct bt_value
*real_params
= NULL
;
286 struct bt_value
*assume_absolute_clock_classes
= NULL
;
290 default_params
= get_default_params();
291 if (!default_params
) {
292 BT_LOGE("Cannot get default parameters: "
293 "muxer-comp-addr=%p", muxer_comp
);
297 real_params
= bt_value_map_extend(default_params
, params
);
299 BT_LOGE("Cannot extend default parameters map value: "
300 "muxer-comp-addr=%p, def-params-addr=%p, "
301 "params-addr=%p", muxer_comp
, default_params
,
306 assume_absolute_clock_classes
= bt_value_map_get(real_params
,
307 ASSUME_ABSOLUTE_CLOCK_CLASSES_PARAM_NAME
);
308 if (!bt_value_is_bool(assume_absolute_clock_classes
)) {
309 BT_LOGE("Expecting a boolean value for the `%s` parameter: "
310 "muxer-comp-addr=%p, value-type=%s",
311 ASSUME_ABSOLUTE_CLOCK_CLASSES_PARAM_NAME
, muxer_comp
,
312 bt_value_type_string(
313 bt_value_get_type(assume_absolute_clock_classes
)));
317 ret
= bt_value_bool_get(assume_absolute_clock_classes
, &bool_val
);
319 muxer_comp
->assume_absolute_clock_classes
= (bool) bool_val
;
320 BT_LOGD("Configured muxer component: muxer-comp-addr=%p, "
321 "assume-absolute-clock-classes=%d",
322 muxer_comp
, muxer_comp
->assume_absolute_clock_classes
);
329 bt_put(default_params
);
331 bt_put(assume_absolute_clock_classes
);
336 enum bt_component_status
muxer_init(
337 struct bt_private_component
*priv_comp
,
338 struct bt_value
*params
, void *init_data
)
341 enum bt_component_status status
= BT_COMPONENT_STATUS_OK
;
342 struct muxer_comp
*muxer_comp
= g_new0(struct muxer_comp
, 1);
344 BT_LOGD("Initializing muxer component: "
345 "comp-addr=%p, params-addr=%p", priv_comp
, params
);
348 BT_LOGE_STR("Failed to allocate one muxer component.");
352 ret
= configure_muxer_comp(muxer_comp
, params
);
354 BT_LOGE("Cannot configure muxer component: "
355 "muxer-comp-addr=%p, params-addr=%p",
360 muxer_comp
->muxer_notif_iters
= g_ptr_array_new();
361 if (!muxer_comp
->muxer_notif_iters
) {
362 BT_LOGE_STR("Failed to allocate a GPtrArray.");
366 muxer_comp
->priv_comp
= priv_comp
;
367 ret
= bt_private_component_set_user_data(priv_comp
, muxer_comp
);
369 status
= ensure_available_input_port(priv_comp
);
370 if (status
!= BT_COMPONENT_STATUS_OK
) {
371 BT_LOGE("Cannot ensure that at least one muxer component's input port is available: "
372 "muxer-comp-addr=%p, status=%s",
374 bt_component_status_string(status
));
378 status
= create_output_port(priv_comp
);
380 BT_LOGE("Cannot create muxer component's output port: "
381 "muxer-comp-addr=%p, status=%s",
383 bt_component_status_string(status
));
387 BT_LOGD("Initialized muxer component: "
388 "comp-addr=%p, params-addr=%p, muxer-comp-addr=%p",
389 priv_comp
, params
, muxer_comp
);
394 destroy_muxer_comp(muxer_comp
);
395 ret
= bt_private_component_set_user_data(priv_comp
, NULL
);
398 if (status
== BT_COMPONENT_STATUS_OK
) {
399 status
= BT_COMPONENT_STATUS_ERROR
;
407 void muxer_finalize(struct bt_private_component
*priv_comp
)
409 struct muxer_comp
*muxer_comp
=
410 bt_private_component_get_user_data(priv_comp
);
412 BT_LOGD("Finalizing muxer component: comp-addr=%p",
414 destroy_muxer_comp(muxer_comp
);
418 struct bt_notification_iterator
*create_notif_iter_on_input_port(
419 struct bt_private_port
*priv_port
, int *ret
)
421 struct bt_port
*port
= bt_port_from_private_port(priv_port
);
422 struct bt_notification_iterator
*notif_iter
= NULL
;
423 struct bt_private_connection
*priv_conn
= NULL
;
424 enum bt_connection_status conn_status
;
429 assert(bt_port_is_connected(port
));
430 priv_conn
= bt_private_port_get_private_connection(priv_port
);
433 // TODO: Advance the iterator to >= the time of the latest
434 // returned notification by the muxer notification
435 // iterator which creates it.
436 conn_status
= bt_private_connection_create_notification_iterator(
437 priv_conn
, NULL
, ¬if_iter
);
438 if (conn_status
!= BT_CONNECTION_STATUS_OK
) {
439 BT_LOGE("Cannot create upstream notification iterator on input port's connection: "
440 "port-addr=%p, port-name=\"%s\", conn-addr=%p, "
442 port
, bt_port_get_name(port
), priv_conn
,
443 bt_connection_status_string(conn_status
));
448 BT_LOGD("Created upstream notification iterator on input port's connection: "
449 "port-addr=%p, port-name=\"%s\", conn-addr=%p, "
450 "notif-iter-addr=%p",
451 port
, bt_port_get_name(port
), priv_conn
, notif_iter
);
460 enum bt_notification_iterator_status
muxer_upstream_notif_iter_next(
461 struct muxer_upstream_notif_iter
*muxer_upstream_notif_iter
)
463 enum bt_notification_iterator_status status
;
465 BT_LOGV("Calling upstream notification iterator's \"next\" method: "
466 "muxer-upstream-notif-iter-wrap-addr=%p, notif-iter-addr=%p",
467 muxer_upstream_notif_iter
,
468 muxer_upstream_notif_iter
->notif_iter
);
469 status
= bt_notification_iterator_next(
470 muxer_upstream_notif_iter
->notif_iter
);
471 BT_LOGV("Upstream notification iterator's \"next\" method returned: "
472 "status=%s", bt_notification_iterator_status_string(status
));
475 case BT_NOTIFICATION_ITERATOR_STATUS_OK
:
477 * Notification iterator's current notification is valid:
478 * it must be considered for muxing operations.
480 BT_LOGV_STR("Validated upstream notification iterator wrapper.");
481 muxer_upstream_notif_iter
->is_valid
= true;
483 case BT_NOTIFICATION_ITERATOR_STATUS_AGAIN
:
485 * Notification iterator's current notification is not
486 * valid anymore. Return
487 * BT_NOTIFICATION_ITERATOR_STATUS_AGAIN
490 BT_LOGV_STR("Invalidated upstream notification iterator wrapper because of BT_NOTIFICATION_ITERATOR_STATUS_AGAIN.");
491 muxer_upstream_notif_iter
->is_valid
= false;
493 case BT_NOTIFICATION_ITERATOR_STATUS_END
: /* Fall-through. */
494 case BT_NOTIFICATION_ITERATOR_STATUS_CANCELED
:
496 * Notification iterator reached the end: release it. It
497 * won't be considered again to find the youngest
500 BT_LOGV_STR("Invalidated upstream notification iterator wrapper because of BT_NOTIFICATION_ITERATOR_STATUS_END or BT_NOTIFICATION_ITERATOR_STATUS_CANCELED.");
501 BT_PUT(muxer_upstream_notif_iter
->notif_iter
);
502 muxer_upstream_notif_iter
->is_valid
= false;
503 status
= BT_NOTIFICATION_ITERATOR_STATUS_OK
;
506 /* Error or unsupported status code */
507 BT_LOGE("Error or unsupported status code: "
508 "status-code=%d", status
);
509 status
= BT_NOTIFICATION_ITERATOR_STATUS_ERROR
;
517 int muxer_notif_iter_handle_newly_connected_ports(
518 struct muxer_notif_iter
*muxer_notif_iter
)
522 BT_LOGV("Handling newly connected ports: "
523 "muxer-notif-iter-addr=%p", muxer_notif_iter
);
526 * Here we create one upstream notification iterator for each
527 * newly connected port. We do not perform an initial "next" on
528 * those new upstream notification iterators: they are
529 * invalidated, to be validated later. The list of newly
530 * connected ports to handle here is updated by
531 * muxer_port_connected().
534 GList
*node
= muxer_notif_iter
->newly_connected_priv_ports
;
535 struct bt_private_port
*priv_port
;
536 struct bt_port
*port
;
537 struct bt_notification_iterator
*upstream_notif_iter
= NULL
;
538 struct muxer_upstream_notif_iter
*muxer_upstream_notif_iter
;
544 priv_port
= node
->data
;
545 port
= bt_port_from_private_port(priv_port
);
548 if (!bt_port_is_connected(port
)) {
550 * Looks like this port is not connected
551 * anymore: we can't create an upstream
552 * notification iterator on its (non-existing)
553 * connection in this case.
559 upstream_notif_iter
= create_notif_iter_on_input_port(priv_port
,
562 /* create_notif_iter_on_input_port() logs errors */
563 assert(!upstream_notif_iter
);
567 muxer_upstream_notif_iter
=
568 muxer_notif_iter_add_upstream_notif_iter(
569 muxer_notif_iter
, upstream_notif_iter
,
571 BT_PUT(upstream_notif_iter
);
572 if (!muxer_upstream_notif_iter
) {
574 * muxer_notif_iter_add_upstream_notif_iter()
581 bt_put(upstream_notif_iter
);
583 muxer_notif_iter
->newly_connected_priv_ports
=
585 muxer_notif_iter
->newly_connected_priv_ports
,
601 int get_notif_ts_ns(struct muxer_comp
*muxer_comp
,
602 struct muxer_notif_iter
*muxer_notif_iter
,
603 struct bt_notification
*notif
, int64_t last_returned_ts_ns
,
606 struct bt_clock_class_priority_map
*cc_prio_map
= NULL
;
607 struct bt_ctf_clock_class
*clock_class
= NULL
;
608 struct bt_ctf_clock_value
*clock_value
= NULL
;
609 struct bt_ctf_event
*event
= NULL
;
611 const unsigned char *cc_uuid
;
617 BT_LOGV("Getting notification's timestamp: "
618 "muxer-notif-iter-addr=%p, notif-addr=%p, "
619 "last-returned-ts=%" PRId64
,
620 muxer_notif_iter
, notif
, last_returned_ts_ns
);
622 switch (bt_notification_get_type(notif
)) {
623 case BT_NOTIFICATION_TYPE_EVENT
:
625 bt_notification_event_get_clock_class_priority_map(
629 case BT_NOTIFICATION_TYPE_INACTIVITY
:
631 bt_notification_inactivity_get_clock_class_priority_map(
635 /* All the other notifications have a higher priority */
636 BT_LOGV_STR("Notification has no timestamp: using the last returned timestamp.");
637 *ts_ns
= last_returned_ts_ns
;
642 BT_LOGE("Cannot get notification's clock class priority map: "
643 "notif-addr=%p", notif
);
648 * If the clock class priority map is empty, then we consider
649 * that this notification has no time. In this case it's always
652 if (bt_clock_class_priority_map_get_clock_class_count(cc_prio_map
) == 0) {
653 BT_LOGV_STR("Notification's clock class priorty map contains 0 clock classes: "
654 "using the last returned timestamp.");
655 *ts_ns
= last_returned_ts_ns
;
660 bt_clock_class_priority_map_get_highest_priority_clock_class(
663 BT_LOGE("Cannot get the clock class with the highest priority from clock class priority map: "
664 "cc-prio-map-addr=%p", cc_prio_map
);
668 cc_uuid
= bt_ctf_clock_class_get_uuid(clock_class
);
669 cc_name
= bt_ctf_clock_class_get_name(clock_class
);
671 if (muxer_notif_iter
->clock_class_expectation
==
672 MUXER_NOTIF_ITER_CLOCK_CLASS_EXPECTATION_ANY
) {
674 * This is the first clock class that this muxer
675 * notification iterator encounters. Its properties
676 * determine what to expect for the whole lifetime of
677 * the iterator without a true
678 * `assume-absolute-clock-classes` parameter.
680 if (bt_ctf_clock_class_is_absolute(clock_class
)) {
681 /* Expect absolute clock classes */
682 muxer_notif_iter
->clock_class_expectation
=
683 MUXER_NOTIF_ITER_CLOCK_CLASS_EXPECTATION_ABSOLUTE
;
687 * Expect non-absolute clock classes
688 * with a specific UUID.
690 muxer_notif_iter
->clock_class_expectation
=
691 MUXER_NOTIF_ITER_CLOCK_CLASS_EXPECTATION_NOT_ABS_SPEC_UUID
;
692 memcpy(muxer_notif_iter
->expected_clock_class_uuid
,
693 cc_uuid
, BABELTRACE_UUID_LEN
);
696 * Expect non-absolute clock classes
699 muxer_notif_iter
->clock_class_expectation
=
700 MUXER_NOTIF_ITER_CLOCK_CLASS_EXPECTATION_NOT_ABS_NO_UUID
;
705 if (!muxer_comp
->assume_absolute_clock_classes
) {
706 switch (muxer_notif_iter
->clock_class_expectation
) {
707 case MUXER_NOTIF_ITER_CLOCK_CLASS_EXPECTATION_ABSOLUTE
:
708 if (!bt_ctf_clock_class_is_absolute(clock_class
)) {
709 BT_LOGE("Expecting an absolute clock class, "
710 "but got a non-absolute one: "
711 "clock-class-addr=%p, clock-class-name=\"%s\"",
712 clock_class
, cc_name
);
716 case MUXER_NOTIF_ITER_CLOCK_CLASS_EXPECTATION_NOT_ABS_NO_UUID
:
717 if (bt_ctf_clock_class_is_absolute(clock_class
)) {
718 BT_LOGE("Expecting a non-absolute clock class with no UUID, "
719 "but got an absolute one: "
720 "clock-class-addr=%p, clock-class-name=\"%s\"",
721 clock_class
, cc_name
);
726 BT_LOGE("Expecting a non-absolute clock class with no UUID, "
727 "but got one with a UUID: "
728 "clock-class-addr=%p, clock-class-name=\"%s\", "
729 "uuid=\"%02x%02x%02x%02x-%02x%02x-%02x%02x-%02x%02x-%02x%02x%02x%02x%02x%02x\"",
730 clock_class
, cc_name
,
731 (unsigned int) cc_uuid
[0],
732 (unsigned int) cc_uuid
[1],
733 (unsigned int) cc_uuid
[2],
734 (unsigned int) cc_uuid
[3],
735 (unsigned int) cc_uuid
[4],
736 (unsigned int) cc_uuid
[5],
737 (unsigned int) cc_uuid
[6],
738 (unsigned int) cc_uuid
[7],
739 (unsigned int) cc_uuid
[8],
740 (unsigned int) cc_uuid
[9],
741 (unsigned int) cc_uuid
[10],
742 (unsigned int) cc_uuid
[11],
743 (unsigned int) cc_uuid
[12],
744 (unsigned int) cc_uuid
[13],
745 (unsigned int) cc_uuid
[14],
746 (unsigned int) cc_uuid
[15]);
750 case MUXER_NOTIF_ITER_CLOCK_CLASS_EXPECTATION_NOT_ABS_SPEC_UUID
:
751 if (bt_ctf_clock_class_is_absolute(clock_class
)) {
752 BT_LOGE("Expecting a non-absolute clock class with a specific UUID, "
753 "but got an absolute one: "
754 "clock-class-addr=%p, clock-class-name=\"%s\"",
755 clock_class
, cc_name
);
760 BT_LOGE("Expecting a non-absolute clock class with a specific UUID, "
761 "but got one with no UUID: "
762 "clock-class-addr=%p, clock-class-name=\"%s\"",
763 clock_class
, cc_name
);
767 if (memcmp(muxer_notif_iter
->expected_clock_class_uuid
,
768 cc_uuid
, BABELTRACE_UUID_LEN
) != 0) {
769 BT_LOGE("Expecting a non-absolute clock class with a specific UUID, "
770 "but got one with different UUID: "
771 "clock-class-addr=%p, clock-class-name=\"%s\", "
772 "expected-uuid=\"%02x%02x%02x%02x-%02x%02x-%02x%02x-%02x%02x-%02x%02x%02x%02x%02x%02x\", "
773 "uuid=\"%02x%02x%02x%02x-%02x%02x-%02x%02x-%02x%02x-%02x%02x%02x%02x%02x%02x\"",
774 clock_class
, cc_name
,
775 (unsigned int) muxer_notif_iter
->expected_clock_class_uuid
[0],
776 (unsigned int) muxer_notif_iter
->expected_clock_class_uuid
[1],
777 (unsigned int) muxer_notif_iter
->expected_clock_class_uuid
[2],
778 (unsigned int) muxer_notif_iter
->expected_clock_class_uuid
[3],
779 (unsigned int) muxer_notif_iter
->expected_clock_class_uuid
[4],
780 (unsigned int) muxer_notif_iter
->expected_clock_class_uuid
[5],
781 (unsigned int) muxer_notif_iter
->expected_clock_class_uuid
[6],
782 (unsigned int) muxer_notif_iter
->expected_clock_class_uuid
[7],
783 (unsigned int) muxer_notif_iter
->expected_clock_class_uuid
[8],
784 (unsigned int) muxer_notif_iter
->expected_clock_class_uuid
[9],
785 (unsigned int) muxer_notif_iter
->expected_clock_class_uuid
[10],
786 (unsigned int) muxer_notif_iter
->expected_clock_class_uuid
[11],
787 (unsigned int) muxer_notif_iter
->expected_clock_class_uuid
[12],
788 (unsigned int) muxer_notif_iter
->expected_clock_class_uuid
[13],
789 (unsigned int) muxer_notif_iter
->expected_clock_class_uuid
[14],
790 (unsigned int) muxer_notif_iter
->expected_clock_class_uuid
[15],
791 (unsigned int) cc_uuid
[0],
792 (unsigned int) cc_uuid
[1],
793 (unsigned int) cc_uuid
[2],
794 (unsigned int) cc_uuid
[3],
795 (unsigned int) cc_uuid
[4],
796 (unsigned int) cc_uuid
[5],
797 (unsigned int) cc_uuid
[6],
798 (unsigned int) cc_uuid
[7],
799 (unsigned int) cc_uuid
[8],
800 (unsigned int) cc_uuid
[9],
801 (unsigned int) cc_uuid
[10],
802 (unsigned int) cc_uuid
[11],
803 (unsigned int) cc_uuid
[12],
804 (unsigned int) cc_uuid
[13],
805 (unsigned int) cc_uuid
[14],
806 (unsigned int) cc_uuid
[15]);
812 BT_LOGF("Unexpected clock class expectation: "
813 "expectation-code=%d",
814 muxer_notif_iter
->clock_class_expectation
);
819 switch (bt_notification_get_type(notif
)) {
820 case BT_NOTIFICATION_TYPE_EVENT
:
821 event
= bt_notification_event_get_event(notif
);
823 clock_value
= bt_ctf_event_get_clock_value(event
,
826 case BT_NOTIFICATION_TYPE_INACTIVITY
:
827 clock_value
= bt_notification_inactivity_get_clock_value(
831 BT_LOGF("Unexpected notification type at this point: "
832 "type=%d", bt_notification_get_type(notif
));
837 BT_LOGE("Cannot get notification's clock value for clock class: "
838 "clock-class-addr=%p, clock-class-name=\"%s\"",
839 clock_class
, cc_name
);
843 ret
= bt_ctf_clock_value_get_value_ns_from_epoch(clock_value
, ts_ns
);
845 BT_LOGE("Cannot get nanoseconds from Epoch of clock value: "
846 "clock-value-addr=%p", clock_value
);
857 BT_LOGV("Found notification's timestamp: "
858 "muxer-notif-iter-addr=%p, notif-addr=%p, "
859 "last-returned-ts=%" PRId64
", ts=%" PRId64
,
860 muxer_notif_iter
, notif
, last_returned_ts_ns
,
872 * This function finds the youngest available notification amongst the
873 * non-ended upstream notification iterators and returns the upstream
874 * notification iterator which has it, or
875 * BT_NOTIFICATION_ITERATOR_STATUS_END if there's no available
878 * This function does NOT:
880 * * Update any upstream notification iterator.
881 * * Check for newly connected ports.
882 * * Check the upstream notification iterators to retry.
884 * On sucess, this function sets *muxer_upstream_notif_iter to the
885 * upstream notification iterator of which the current notification is
886 * the youngest, and sets *ts_ns to its time.
889 enum bt_notification_iterator_status
890 muxer_notif_iter_youngest_upstream_notif_iter(
891 struct muxer_comp
*muxer_comp
,
892 struct muxer_notif_iter
*muxer_notif_iter
,
893 struct muxer_upstream_notif_iter
**muxer_upstream_notif_iter
,
898 int64_t youngest_ts_ns
= INT64_MAX
;
899 enum bt_notification_iterator_status status
=
900 BT_NOTIFICATION_ITERATOR_STATUS_OK
;
903 assert(muxer_notif_iter
);
904 assert(muxer_upstream_notif_iter
);
905 *muxer_upstream_notif_iter
= NULL
;
907 for (i
= 0; i
< muxer_notif_iter
->muxer_upstream_notif_iters
->len
; i
++) {
908 struct bt_notification
*notif
;
909 struct muxer_upstream_notif_iter
*cur_muxer_upstream_notif_iter
=
910 g_ptr_array_index(muxer_notif_iter
->muxer_upstream_notif_iters
, i
);
913 if (!cur_muxer_upstream_notif_iter
->notif_iter
) {
914 /* This upstream notification iterator is ended */
915 BT_LOGV("Skipping ended upstream notification iterator: "
916 "muxer-upstream-notif-iter-wrap-addr=%p",
917 cur_muxer_upstream_notif_iter
);
921 assert(cur_muxer_upstream_notif_iter
->is_valid
);
922 notif
= bt_notification_iterator_get_notification(
923 cur_muxer_upstream_notif_iter
->notif_iter
);
925 ret
= get_notif_ts_ns(muxer_comp
, muxer_notif_iter
, notif
,
926 muxer_notif_iter
->last_returned_ts_ns
, ¬if_ts_ns
);
929 /* get_notif_ts_ns() logs errors */
930 *muxer_upstream_notif_iter
= NULL
;
931 status
= BT_NOTIFICATION_ITERATOR_STATUS_ERROR
;
935 if (notif_ts_ns
<= youngest_ts_ns
) {
936 *muxer_upstream_notif_iter
=
937 cur_muxer_upstream_notif_iter
;
938 youngest_ts_ns
= notif_ts_ns
;
939 *ts_ns
= youngest_ts_ns
;
943 if (!*muxer_upstream_notif_iter
) {
944 status
= BT_NOTIFICATION_ITERATOR_STATUS_END
;
953 enum bt_notification_iterator_status
validate_muxer_upstream_notif_iter(
954 struct muxer_upstream_notif_iter
*muxer_upstream_notif_iter
)
956 enum bt_notification_iterator_status status
=
957 BT_NOTIFICATION_ITERATOR_STATUS_OK
;
959 BT_LOGV("Validating muxer's upstream notification iterator wrapper: "
960 "muxer-upstream-notif-iter-wrap-addr=%p",
961 muxer_upstream_notif_iter
);
963 if (muxer_upstream_notif_iter
->is_valid
||
964 !muxer_upstream_notif_iter
->notif_iter
) {
968 /* muxer_upstream_notif_iter_next() logs details/errors */
969 status
= muxer_upstream_notif_iter_next(muxer_upstream_notif_iter
);
976 enum bt_notification_iterator_status
validate_muxer_upstream_notif_iters(
977 struct muxer_notif_iter
*muxer_notif_iter
)
979 enum bt_notification_iterator_status status
=
980 BT_NOTIFICATION_ITERATOR_STATUS_OK
;
983 BT_LOGV("Validating muxer's upstream notification iterator wrappers: "
984 "muxer-notif-iter-addr=%p", muxer_notif_iter
);
986 for (i
= 0; i
< muxer_notif_iter
->muxer_upstream_notif_iters
->len
; i
++) {
987 struct muxer_upstream_notif_iter
*muxer_upstream_notif_iter
=
989 muxer_notif_iter
->muxer_upstream_notif_iters
,
992 status
= validate_muxer_upstream_notif_iter(
993 muxer_upstream_notif_iter
);
994 if (status
!= BT_NOTIFICATION_ITERATOR_STATUS_OK
) {
996 BT_LOGE("Cannot validate muxer's upstream notification iterator wrapper: "
997 "muxer-notif-iter-addr=%p, "
998 "muxer-upstream-notif-iter-wrap-addr=%p",
1000 muxer_upstream_notif_iter
);
1002 BT_LOGV("Cannot validate muxer's upstream notification iterator wrapper: "
1003 "muxer-notif-iter-addr=%p, "
1004 "muxer-upstream-notif-iter-wrap-addr=%p",
1006 muxer_upstream_notif_iter
);
1013 * Remove this muxer upstream notification iterator
1014 * if it's ended or canceled.
1016 if (!muxer_upstream_notif_iter
->notif_iter
) {
1018 * Use g_ptr_array_remove_fast() because the
1019 * order of those elements is not important.
1021 BT_LOGV("Removing muxer's upstream notification iterator wrapper: ended or canceled: "
1022 "muxer-notif-iter-addr=%p, "
1023 "muxer-upstream-notif-iter-wrap-addr=%p",
1024 muxer_notif_iter
, muxer_upstream_notif_iter
);
1025 g_ptr_array_remove_index_fast(
1026 muxer_notif_iter
->muxer_upstream_notif_iters
,
1037 struct bt_notification_iterator_next_return
muxer_notif_iter_do_next(
1038 struct muxer_comp
*muxer_comp
,
1039 struct muxer_notif_iter
*muxer_notif_iter
)
1041 struct muxer_upstream_notif_iter
*muxer_upstream_notif_iter
= NULL
;
1042 struct bt_notification_iterator_next_return next_return
= {
1043 .notification
= NULL
,
1044 .status
= BT_NOTIFICATION_ITERATOR_STATUS_OK
,
1046 int64_t next_return_ts
;
1049 int ret
= muxer_notif_iter_handle_newly_connected_ports(
1053 BT_LOGE("Cannot handle newly connected input ports for muxer's notification iterator: "
1054 "muxer-comp-addr=%p, muxer-notif-iter-addr=%p, "
1056 muxer_comp
, muxer_notif_iter
, ret
);
1057 next_return
.status
=
1058 BT_NOTIFICATION_ITERATOR_STATUS_ERROR
;
1062 next_return
.status
=
1063 validate_muxer_upstream_notif_iters(muxer_notif_iter
);
1064 if (next_return
.status
!= BT_NOTIFICATION_ITERATOR_STATUS_OK
) {
1065 /* validate_muxer_upstream_notif_iters() logs details */
1070 * At this point, we know that all the existing upstream
1071 * notification iterators are valid. However the
1072 * operations to validate them (during
1073 * validate_muxer_upstream_notif_iters()) may have
1074 * connected new ports. If no ports were connected
1075 * during this operation, exit the loop.
1077 if (!muxer_notif_iter
->newly_connected_priv_ports
) {
1078 BT_LOGV("Not breaking this loop: muxer's notification iterator still has newly connected input ports to handle: "
1079 "muxer-comp-addr=%p", muxer_comp
);
1084 assert(!muxer_notif_iter
->newly_connected_priv_ports
);
1087 * At this point we know that all the existing upstream
1088 * notification iterators are valid. We can find the one,
1089 * amongst those, of which the current notification is the
1092 next_return
.status
=
1093 muxer_notif_iter_youngest_upstream_notif_iter(muxer_comp
,
1094 muxer_notif_iter
, &muxer_upstream_notif_iter
,
1096 if (next_return
.status
< 0 ||
1097 next_return
.status
== BT_NOTIFICATION_ITERATOR_STATUS_END
||
1098 next_return
.status
== BT_NOTIFICATION_ITERATOR_STATUS_CANCELED
) {
1099 if (next_return
.status
< 0) {
1100 BT_LOGE("Cannot find the youngest upstream notification iterator wrapper: "
1102 bt_notification_iterator_status_string(next_return
.status
));
1104 BT_LOGV("Cannot find the youngest upstream notification iterator wrapper: "
1106 bt_notification_iterator_status_string(next_return
.status
));
1112 if (next_return_ts
< muxer_notif_iter
->last_returned_ts_ns
) {
1113 BT_LOGE("Youngest upstream notification iterator wrapper's timestamp is less than muxer's notification iterator's last returned timestamp: "
1114 "muxer-notif-iter-addr=%p, ts=%" PRId64
", "
1115 "last-returned-ts=%" PRId64
,
1116 muxer_notif_iter
, next_return_ts
,
1117 muxer_notif_iter
->last_returned_ts_ns
);
1118 next_return
.status
= BT_NOTIFICATION_ITERATOR_STATUS_ERROR
;
1122 BT_LOGV("Found youngest upstream notification iterator wrapper: "
1123 "muxer-notif-iter-addr=%p, "
1124 "muxer-upstream-notif-iter-wrap-addr=%p, "
1126 muxer_notif_iter
, muxer_upstream_notif_iter
, next_return_ts
);
1127 assert(next_return
.status
== BT_NOTIFICATION_ITERATOR_STATUS_OK
);
1128 assert(muxer_upstream_notif_iter
);
1129 next_return
.notification
= bt_notification_iterator_get_notification(
1130 muxer_upstream_notif_iter
->notif_iter
);
1131 assert(next_return
.notification
);
1134 * We invalidate the upstream notification iterator so that, the
1135 * next time this function is called,
1136 * validate_muxer_upstream_notif_iters() will make it valid.
1138 muxer_upstream_notif_iter
->is_valid
= false;
1139 muxer_notif_iter
->last_returned_ts_ns
= next_return_ts
;
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_from_private_component(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
;
1196 port
= bt_port_from_private_port(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
));
1210 muxer_notif_iter
->newly_connected_priv_ports
=
1212 muxer_notif_iter
->newly_connected_priv_ports
,
1214 if (!muxer_notif_iter
->newly_connected_priv_ports
) {
1215 BT_LOGE("Cannot append port to muxer's notification iterator list of newly connected input ports: "
1216 "port-addr=%p, port-name=\"%s\", "
1217 "muxer-notif-iter-addr=%p", port
,
1218 bt_port_get_name(port
), muxer_notif_iter
);
1223 BT_LOGD("Appended port to muxer's notification iterator list of newly connected input ports: "
1224 "port-addr=%p, port-name=\"%s\", "
1225 "muxer-notif-iter-addr=%p", port
,
1226 bt_port_get_name(port
), muxer_notif_iter
);
1235 enum bt_notification_iterator_status
muxer_notif_iter_init(
1236 struct bt_private_notification_iterator
*priv_notif_iter
,
1237 struct bt_private_port
*output_priv_port
)
1239 struct muxer_comp
*muxer_comp
= NULL
;
1240 struct muxer_notif_iter
*muxer_notif_iter
= NULL
;
1241 struct bt_private_component
*priv_comp
= NULL
;
1242 enum bt_notification_iterator_status status
=
1243 BT_NOTIFICATION_ITERATOR_STATUS_OK
;
1246 priv_comp
= bt_private_notification_iterator_get_private_component(
1249 muxer_comp
= bt_private_component_get_user_data(priv_comp
);
1251 BT_LOGD("Initializing muxer component's notification iterator: "
1252 "comp-addr=%p, muxer-comp-addr=%p, notif-iter-addr=%p",
1253 priv_comp
, muxer_comp
, priv_notif_iter
);
1255 if (muxer_comp
->initializing_muxer_notif_iter
) {
1257 * Weird, unhandled situation detected: downstream
1258 * creates a muxer notification iterator while creating
1259 * another muxer notification iterator (same component).
1261 BT_LOGE("Recursive initialization of muxer component's notification iterator: "
1262 "comp-addr=%p, muxer-comp-addr=%p, notif-iter-addr=%p",
1263 priv_comp
, muxer_comp
, priv_notif_iter
);
1267 muxer_comp
->initializing_muxer_notif_iter
= true;
1268 muxer_notif_iter
= g_new0(struct muxer_notif_iter
, 1);
1269 if (!muxer_notif_iter
) {
1270 BT_LOGE_STR("Failed to allocate one muxer component's notification iterator.");
1274 muxer_notif_iter
->last_returned_ts_ns
= INT64_MIN
;
1275 muxer_notif_iter
->muxer_upstream_notif_iters
=
1276 g_ptr_array_new_with_free_func(
1277 (GDestroyNotify
) destroy_muxer_upstream_notif_iter
);
1278 if (!muxer_notif_iter
->muxer_upstream_notif_iters
) {
1279 BT_LOGE_STR("Failed to allocate a GPtrArray.");
1284 * Add the muxer notification iterator to the component's array
1285 * of muxer notification iterators here because
1286 * muxer_notif_iter_init_newly_connected_ports() can cause
1287 * muxer_port_connected() to be called, which adds the newly
1288 * connected port to each muxer notification iterator's list of
1289 * newly connected ports.
1291 g_ptr_array_add(muxer_comp
->muxer_notif_iters
, muxer_notif_iter
);
1292 ret
= muxer_notif_iter_init_newly_connected_ports(muxer_comp
,
1295 BT_LOGE("Cannot initialize newly connected input ports for muxer component's notification iterator: "
1296 "comp-addr=%p, muxer-comp-addr=%p, "
1297 "muxer-notif-iter-addr=%p, notif-iter-addr=%p, ret=%d",
1298 priv_comp
, muxer_comp
, muxer_notif_iter
,
1299 priv_notif_iter
, ret
);
1303 ret
= bt_private_notification_iterator_set_user_data(priv_notif_iter
,
1306 BT_LOGD("Initialized muxer component's notification iterator: "
1307 "comp-addr=%p, muxer-comp-addr=%p, muxer-notif-iter-addr=%p, "
1308 "notif-iter-addr=%p",
1309 priv_comp
, muxer_comp
, muxer_notif_iter
, priv_notif_iter
);
1313 if (g_ptr_array_index(muxer_comp
->muxer_notif_iters
,
1314 muxer_comp
->muxer_notif_iters
->len
- 1) == muxer_notif_iter
) {
1315 g_ptr_array_remove_index(muxer_comp
->muxer_notif_iters
,
1316 muxer_comp
->muxer_notif_iters
->len
- 1);
1319 destroy_muxer_notif_iter(muxer_notif_iter
);
1320 ret
= bt_private_notification_iterator_set_user_data(priv_notif_iter
,
1323 status
= BT_NOTIFICATION_ITERATOR_STATUS_ERROR
;
1326 muxer_comp
->initializing_muxer_notif_iter
= false;
1332 void muxer_notif_iter_finalize(
1333 struct bt_private_notification_iterator
*priv_notif_iter
)
1335 struct muxer_notif_iter
*muxer_notif_iter
=
1336 bt_private_notification_iterator_get_user_data(priv_notif_iter
);
1337 struct bt_private_component
*priv_comp
= NULL
;
1338 struct muxer_comp
*muxer_comp
= NULL
;
1340 priv_comp
= bt_private_notification_iterator_get_private_component(
1343 muxer_comp
= bt_private_component_get_user_data(priv_comp
);
1344 BT_LOGD("Finalizing muxer component's notification iterator: "
1345 "comp-addr=%p, muxer-comp-addr=%p, muxer-notif-iter-addr=%p, "
1346 "notif-iter-addr=%p",
1347 priv_comp
, muxer_comp
, muxer_notif_iter
, priv_notif_iter
);
1350 (void) g_ptr_array_remove_fast(muxer_comp
->muxer_notif_iters
,
1352 destroy_muxer_notif_iter(muxer_notif_iter
);
1359 struct bt_notification_iterator_next_return
muxer_notif_iter_next(
1360 struct bt_private_notification_iterator
*priv_notif_iter
)
1362 struct bt_notification_iterator_next_return next_ret
;
1363 struct muxer_notif_iter
*muxer_notif_iter
=
1364 bt_private_notification_iterator_get_user_data(priv_notif_iter
);
1365 struct bt_private_component
*priv_comp
= NULL
;
1366 struct muxer_comp
*muxer_comp
= NULL
;
1368 assert(muxer_notif_iter
);
1369 priv_comp
= bt_private_notification_iterator_get_private_component(
1372 muxer_comp
= bt_private_component_get_user_data(priv_comp
);
1375 BT_LOGV("Muxer component's notification iterator's \"next\" method called: "
1376 "comp-addr=%p, muxer-comp-addr=%p, muxer-notif-iter-addr=%p, "
1377 "notif-iter-addr=%p",
1378 priv_comp
, muxer_comp
, muxer_notif_iter
, priv_notif_iter
);
1380 /* Are we in an error state set elsewhere? */
1381 if (unlikely(muxer_comp
->error
)) {
1382 BT_LOGE("Muxer component is already in an error state: returning BT_NOTIFICATION_ITERATOR_STATUS_ERROR: "
1383 "comp-addr=%p, muxer-comp-addr=%p, muxer-notif-iter-addr=%p, "
1384 "notif-iter-addr=%p",
1385 priv_comp
, muxer_comp
, muxer_notif_iter
, priv_notif_iter
);
1386 next_ret
.notification
= NULL
;
1387 next_ret
.status
= BT_NOTIFICATION_ITERATOR_STATUS_ERROR
;
1391 next_ret
= muxer_notif_iter_do_next(muxer_comp
, muxer_notif_iter
);
1392 if (next_ret
.status
< 0) {
1393 BT_LOGE("Cannot get next notification: "
1394 "comp-addr=%p, muxer-comp-addr=%p, muxer-notif-iter-addr=%p, "
1395 "notif-iter-addr=%p, status=%s",
1396 priv_comp
, muxer_comp
, muxer_notif_iter
, priv_notif_iter
,
1397 bt_notification_iterator_status_string(next_ret
.status
));
1399 BT_LOGV("Returning from muxer component's notification iterator's \"next\" method: "
1400 "status=%s, notif-addr=%p",
1401 bt_notification_iterator_status_string(next_ret
.status
),
1402 next_ret
.notification
);
1411 void muxer_port_connected(
1412 struct bt_private_component
*priv_comp
,
1413 struct bt_private_port
*self_private_port
,
1414 struct bt_port
*other_port
)
1416 struct bt_port
*self_port
=
1417 bt_port_from_private_port(self_private_port
);
1418 struct muxer_comp
*muxer_comp
=
1419 bt_private_component_get_user_data(priv_comp
);
1425 BT_LOGD("Port connected: "
1426 "comp-addr=%p, muxer-comp-addr=%p, "
1427 "port-addr=%p, port-name=\"%s\", "
1428 "other-port-addr=%p, other-port-name=\"%s\"",
1429 priv_comp
, muxer_comp
, self_port
, bt_port_get_name(self_port
),
1430 other_port
, bt_port_get_name(other_port
));
1432 if (bt_port_get_type(self_port
) == BT_PORT_TYPE_OUTPUT
) {
1436 for (i
= 0; i
< muxer_comp
->muxer_notif_iters
->len
; i
++) {
1437 struct muxer_notif_iter
*muxer_notif_iter
=
1438 g_ptr_array_index(muxer_comp
->muxer_notif_iters
, i
);
1441 * Add this port to the list of newly connected ports
1442 * for this muxer notification iterator. We append at
1443 * the end of this list while
1444 * muxer_notif_iter_handle_newly_connected_ports()
1445 * removes the nodes from the beginning.
1447 muxer_notif_iter
->newly_connected_priv_ports
=
1449 muxer_notif_iter
->newly_connected_priv_ports
,
1451 if (!muxer_notif_iter
->newly_connected_priv_ports
) {
1452 BT_LOGE("Cannot append port to muxer's notification iterator list of newly connected input ports: "
1453 "port-addr=%p, port-name=\"%s\", "
1454 "muxer-notif-iter-addr=%p", self_port
,
1455 bt_port_get_name(self_port
), muxer_notif_iter
);
1456 muxer_comp
->error
= true;
1460 BT_LOGD("Appended port to muxer's notification iterator list of newly connected input ports: "
1461 "port-addr=%p, port-name=\"%s\", "
1462 "muxer-notif-iter-addr=%p", self_port
,
1463 bt_port_get_name(self_port
), muxer_notif_iter
);
1466 /* One less available input port */
1467 muxer_comp
->available_input_ports
--;
1468 ret
= ensure_available_input_port(priv_comp
);
1471 * Only way to report an error later since this
1472 * method does not return anything.
1474 BT_LOGE("Cannot ensure that at least one muxer component's input port is available: "
1475 "muxer-comp-addr=%p, status=%s",
1476 muxer_comp
, bt_component_status_string(ret
));
1477 muxer_comp
->error
= true;
1486 void muxer_port_disconnected(struct bt_private_component
*priv_comp
,
1487 struct bt_private_port
*priv_port
)
1489 struct bt_port
*port
= bt_port_from_private_port(priv_port
);
1490 struct muxer_comp
*muxer_comp
=
1491 bt_private_component_get_user_data(priv_comp
);
1495 BT_LOGD("Port disconnected: "
1496 "comp-addr=%p, muxer-comp-addr=%p, port-addr=%p, "
1497 "port-name=\"%s\"", priv_comp
, muxer_comp
,
1498 port
, bt_port_get_name(port
));
1501 * There's nothing special to do when a port is disconnected
1502 * because this component deals with upstream notification
1503 * iterators which were already created thanks to connected
1504 * ports. The fact that the port is disconnected does not cancel
1505 * the upstream notification iterators created using its
1506 * connection: they still exist, even if the connection is dead.
1507 * The only way to remove an upstream notification iterator is
1508 * for its "next" operation to return
1509 * BT_NOTIFICATION_ITERATOR_STATUS_END.
1511 if (bt_port_get_type(port
) == BT_PORT_TYPE_INPUT
) {
1512 /* One more available input port */
1513 muxer_comp
->available_input_ports
++;
1514 BT_LOGD("Leaving disconnected input port available for future connections: "
1515 "comp-addr=%p, muxer-comp-addr=%p, port-addr=%p, "
1516 "port-name=\"%s\", avail-input-port-count=%zu",
1517 priv_comp
, muxer_comp
, port
, bt_port_get_name(port
),
1518 muxer_comp
->available_input_ports
);