From 08233d44a6cfde878d7e10bca38ae935ed1c8fd5 Mon Sep 17 00:00:00 2001 From: Mauro Date: Wed, 30 Jun 2021 07:57:22 +0000 Subject: [HICN-713] Transport Library Major Refactoring 2 Co-authored-by: Luca Muscariello Co-authored-by: Michele Papalini Co-authored-by: Olivier Roques Co-authored-by: Giulio Grassi Signed-off-by: Mauro Sardara Change-Id: I5b2c667bad66feb45abdb5effe22ed0f6c85d1c2 --- libtransport/src/protocols/fec_base.h | 85 +++++++++++++++++++++-------------- 1 file changed, 51 insertions(+), 34 deletions(-) (limited to 'libtransport/src/protocols/fec_base.h') diff --git a/libtransport/src/protocols/fec_base.h b/libtransport/src/protocols/fec_base.h index a135c474f..a1929d85e 100644 --- a/libtransport/src/protocols/fec_base.h +++ b/libtransport/src/protocols/fec_base.h @@ -16,71 +16,88 @@ #pragma once #include +#include #include namespace transport { namespace protocol { -/** - * Interface classes to integrate FEC inside any producer transport protocol - */ -class ProducerFECBase { +namespace fec { + +using buffer = typename utils::MemBuf::Ptr; +using BufferArray = std::vector>; + +class FECBase { public: + virtual ~FECBase() = default; /** - * Callback, to be called by implementations as soon as a repair packet is - * ready. + * Callback to be called after the encode or the decode operations. In the + * former case it will contain the symbols, while in the latter the sources. */ - using RepairPacketsReady = - std::function &)>; + using PacketsReady = std::function; /** - * Producers will call this function upon production of a new packet. + * Callback to be called when a new buffer (for encoding / decoding) needs to + * be allocated. */ - virtual void onPacketProduced(const core::ContentObject &content_object) = 0; + using BufferRequested = std::function; /** - * Set callback to signal production protocol the repair packet is ready. + * @brief Get size of FEC header. */ - void setFECCallback(const RepairPacketsReady &on_repair_packet) { - rep_packet_ready_callback_ = on_repair_packet; + virtual std::size_t getFecHeaderSize() = 0; + + /** + * Set callback to call after packet encoding / decoding + */ + template + void setFECCallback(Handler &&callback) { + fec_callback_ = std::forward(callback); } + /** + * Set a callback to request a buffer. + */ + template + void setBufferCallback(Handler &&buffer_callback) { + buffer_callback_ = buffer_callback; + } + + virtual void reset() = 0; + protected: - RepairPacketsReady rep_packet_ready_callback_; + PacketsReady fec_callback_{0}; + BufferRequested buffer_callback_{0}; }; /** - * Interface classes to integrate FEC inside any consumer transport protocol + * Interface classes to integrate FEC inside any producer transport protocol */ -class ConsumerFECBase { +class ProducerFEC : public virtual FECBase { public: + virtual ~ProducerFEC() = default; /** - * Callback, to be called by implemrntations as soon as a packet is recovered. + * Producers will call this function upon production of a new packet. */ - using OnPacketsRecovered = - std::function &)>; + virtual void onPacketProduced(core::ContentObject &content_object, + uint32_t offset) = 0; +}; - /** - * Consumers will call this function when they receive a FEC packet. - */ - virtual void onFECPacket(const core::ContentObject &content_object) = 0; +/** + * Interface classes to integrate FEC inside any consumer transport protocol + */ +class ConsumerFEC : public virtual FECBase { + public: + virtual ~ConsumerFEC() = default; /** * Consumers will call this function when they receive a data packet */ - virtual void onDataPacket(const core::ContentObject &content_object) = 0; - - /** - * Set callback to signal consumer protocol the repair packet is ready. - */ - void setFECCallback(const OnPacketsRecovered &on_repair_packet) { - packet_recovered_callback_ = on_repair_packet; - } - - protected: - OnPacketsRecovered packet_recovered_callback_; + virtual void onDataPacket(core::ContentObject &content_object, + uint32_t offset) = 0; }; +} // namespace fec } // namespace protocol } // namespace transport \ No newline at end of file -- cgit 1.2.3-korg