Skip to content

Commit

Permalink
pylibschc.fragmenter: un/register_send can be a dynamic method
Browse files Browse the repository at this point in the history
  • Loading branch information
miri64 committed Feb 16, 2023
1 parent 5a7bc5f commit b3ad077
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 20 deletions.
2 changes: 1 addition & 1 deletion README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ Acknowledgements can be handled by the |pylibschc.fragmenter.Fragmenter.output|_
... end_tx=end_tx,
... remove_timer_entry=remove_timer_entry,
... )
... fragmenter.register_send(config.devices[0], send)
... fragmenter.register_send(send)
... reassembler = pylibschc.fragmenter.Reassembler(
... device=config.devices[0],
... post_timer_task=post_timer_task,
Expand Down
2 changes: 1 addition & 1 deletion pylibschc/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,4 @@
__copyright__ = "Copyright 2023 Freie Universität Berlin"
__license__ = "GPLv3"
__email__ = "[email protected]"
__version__ = "0.0.1b3"
__version__ = "0.1.0b0"
20 changes: 6 additions & 14 deletions pylibschc/fragmenter.py
Original file line number Diff line number Diff line change
Expand Up @@ -152,24 +152,16 @@ def output(self, data: typing.Union[bytes, BitArray]) -> FragmentationResult:
self._tx_conn_release()
raise

@classmethod
def register_send(
cls, device: pylibschc.device.Device, send: typing.Callable[[bytes], int]
):
"""Register a send function for a device.
def register_send(self, send: typing.Callable[[bytes], int]):
"""Register a send function for the device of this fragmenter.
:param device: A device,
:param send: The send function for ``device``.
"""
return cls.conn_cls.register_send(device.device_id, send)

@classmethod
def unregister_send(cls, device: pylibschc.device.Device):
"""Remove a send function for a device.
return self.conn_cls.register_send(self.device.device_id, send)

:param device: A device,
"""
return cls.conn_cls.unregister_send(device.device_id)
def unregister_send(self):
"""Remove a send function for the device of this fragmenter."""
return self.conn_cls.unregister_send(self.device.device_id)


class Reassembler(BaseFragmenterReassembler): # pylint: disable=too-few-public-methods
Expand Down
8 changes: 4 additions & 4 deletions tests/test_fragmenter.py
Original file line number Diff line number Diff line change
Expand Up @@ -306,7 +306,7 @@ def test_fragmenter_reassembler_threaded( # pylint: disable=too-many-arguments
end_rx=self.end_rx,
remove_timer_entry=self.remove_timer_entry,
)
self.fragmenter.register_send(device, self.send)
self.fragmenter.register_send(self.send)
with self.timer_lock:
if compress_data:
res, pkt = cr.output(self.input_type(data))
Expand All @@ -320,7 +320,7 @@ def test_fragmenter_reassembler_threaded( # pylint: disable=too-many-arguments
assert cr.input(pkt) == data
else:
assert pkt == data
self.fragmenter.unregister_send(device)
self.fragmenter.unregister_send()


class TestFragmenterReassemblerAsync: # pylint: disable=too-many-instance-attributes
Expand Down Expand Up @@ -436,7 +436,7 @@ async def output(buffer):
end_rx=self.end_rx,
remove_timer_entry=self.remove_timer_entry,
)
self.fragmenter.register_send(device, self.send)
self.fragmenter.register_send(self.send)
if compress_data:
res, pkt = cr.output(self.input_type(data))
assert res == pylibschc.compressor.CompressionResult.COMPRESSED
Expand All @@ -451,4 +451,4 @@ async def output(buffer):
assert cr.input(pkt) == data
else:
assert pkt == data
self.fragmenter.unregister_send(device)
self.fragmenter.unregister_send()

0 comments on commit b3ad077

Please sign in to comment.