Skip to content

Commit

Permalink
rename drain event to flow
Browse files Browse the repository at this point in the history
  • Loading branch information
barbibulle committed Jan 24, 2025
1 parent cbd46ad commit 6fe7931
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 28 deletions.
6 changes: 3 additions & 3 deletions apps/auracast.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright 2024 Google LLC
# Copyright 2025 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -826,7 +826,7 @@ async def run_broadcast(
)
print('Setup ISO Data Path')

def on_drain(packet_queue):
def on_flow(packet_queue):
print(
f'\rPACKETS: pending={packet_queue.pending}, '
f'queued={packet_queue.queued}, completed={packet_queue.completed}',
Expand All @@ -842,7 +842,7 @@ def on_drain(packet_queue):
packet_queue = bis_link.data_packet_queue

if packet_queue:
packet_queue.on('drain', lambda: on_drain(packet_queue))
packet_queue.on('flow', lambda: on_flow(packet_queue))

for frame in itertools.cycle(frames):
mid = len(frame) // 2
Expand Down
28 changes: 7 additions & 21 deletions bumble/host.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright 2021-2022 Google LLC
# Copyright 2021-2025 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -71,7 +71,7 @@ class DataPacketQueue(pyee.EventEmitter):
but not completed yet. Packets are no longer "in flight" when the controller
declares them as completed.
The queue emits a 'drain' event whenever one or more packets are completed.
The queue emits a 'flow' event whenever one or more packets are completed.
"""

max_packet_size: int
Expand Down Expand Up @@ -126,7 +126,7 @@ def flush(self, connection_handle: int) -> None:
Remove all packets associated with a connection.
All packets associated with the connection that are in flight are implicitly
marked as completed, but no 'drain' event is emitted.
marked as completed, but no 'flow' event is emitted.
"""

packets_to_keep = [
Expand Down Expand Up @@ -180,7 +180,7 @@ def on_packets_completed(self, packet_count: int, connection_handle: int) -> Non
self._completed = self._queued

self._check_queue()
self.emit('drain')
self.emit('flow')


# -----------------------------------------------------------------------------
Expand Down Expand Up @@ -920,23 +920,9 @@ def on_hci_number_of_completed_packets_event(
for connection_handle, num_completed_packets in zip(
event.connection_handles, event.num_completed_packets
):
if connection := self.connections.get(connection_handle):
connection.acl_packet_queue.on_packets_completed(
num_completed_packets, connection_handle
)
return

if cis_link := self.cis_links.get(connection_handle):
cis_link.packet_queue.on_packets_completed(
num_completed_packets, connection_handle
)
return

if bis_link := self.bis_links.get(connection_handle):
bis_link.packet_queue.on_packets_completed(
num_completed_packets, connection_handle
)
return
if queue := self.get_data_packet_queue(connection_handle):
queue.on_packets_completed(num_completed_packets, connection_handle)
continue

if connection_handle not in self.sco_links:
logger.warning(
Expand Down
8 changes: 4 additions & 4 deletions tests/host_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -138,15 +138,15 @@ def test_data_packet_queue():
assert queue.completed == 11

drain_listener = unittest.mock.Mock()
queue.on('drain', drain_listener.on_drain)
queue.on('flow', drain_listener.on_flow)
queue.enqueue(packet, 123)
assert drain_listener.on_drain.call_count == 0
assert drain_listener.on_flow.call_count == 0
queue.on_packets_completed(1, 123)
assert drain_listener.on_drain.call_count == 1
assert drain_listener.on_flow.call_count == 1
queue.enqueue(packet, 123)
queue.enqueue(packet, 123)
queue.enqueue(packet, 123)
queue.flush(123)
assert drain_listener.on_drain.call_count == 1
assert drain_listener.on_flow.call_count == 1
assert queue.queued == 15
assert queue.completed == 15

0 comments on commit 6fe7931

Please sign in to comment.