diff options
author | Ciro Nishiguchi <ciro.nishiguchi@ni.com> | 2019-03-25 12:41:34 -0500 |
---|---|---|
committer | Martin Braun <martin.braun@ettus.com> | 2019-11-26 11:49:18 -0800 |
commit | 9c2d90292b9a613fb290c5a04e99014d1a9118ab (patch) | |
tree | e240e14d30e0d40e0a1b4f8aff12542d1efb4ba8 /host/lib/include/uhdlib/transport/link_if.hpp | |
parent | 6ec8cf3eeac70d4458ad7a4f7f1eea4f082c140d (diff) | |
download | uhd-9c2d90292b9a613fb290c5a04e99014d1a9118ab.tar.gz uhd-9c2d90292b9a613fb290c5a04e99014d1a9118ab.tar.bz2 uhd-9c2d90292b9a613fb290c5a04e99014d1a9118ab.zip |
uhd: add new transport interface and base class implementation
New interface aimed to replace zero_copy_if for new code, including new
RFNoC development and redesign of streamer objects.
Generic implementation of send and receive transport interfaces to allow
reuse by various transport types. Derived classes implement
transport-specific functions that are invoked by the base classes
through CRTP.
Diffstat (limited to 'host/lib/include/uhdlib/transport/link_if.hpp')
-rw-r--r-- | host/lib/include/uhdlib/transport/link_if.hpp | 101 |
1 files changed, 101 insertions, 0 deletions
diff --git a/host/lib/include/uhdlib/transport/link_if.hpp b/host/lib/include/uhdlib/transport/link_if.hpp new file mode 100644 index 000000000..60376e571 --- /dev/null +++ b/host/lib/include/uhdlib/transport/link_if.hpp @@ -0,0 +1,101 @@ +// +// Copyright 2019 Ettus Research, a National Instruments Brand +// +// SPDX-License-Identifier: GPL-3.0-or-later +// + +#include <uhd/transport/frame_buff.hpp> +#include <memory> + +#ifndef INCLUDED_UHDLIB_TRANSPORT_LINK_IF_HPP +# define INCLUDED_UHDLIB_TRANSPORT_LINK_IF_HPP + +namespace uhd { namespace transport { + +/*! + * Link interface for transmitting packets. + */ +class send_link_if +{ +public: + using sptr = std::shared_ptr<send_link_if>; + + /*! + * Get the number of frame buffers that can be queued by this link. + */ + virtual size_t get_num_send_frames() const = 0; + + /*! + * Get the maximum capacity of a frame buffer. + */ + virtual size_t get_send_frame_size() const = 0; + + /*! + * Get an empty frame buffer in which to write packet contents. + * + * \param timeout_ms a positive timeout value specifies the maximum number + of ms to wait, a negative value specifies to block + until successful, and a value of 0 specifies no wait. + * \return a frame buffer, or null uptr if timeout occurs + */ + virtual frame_buff::uptr get_send_buff(int32_t timeout_ms) = 0; + + /*! + * Send a packet with the contents of the frame buffer and release the + * buffer, allowing the link driver to reuse it. If the size of the frame + * buffer is 0, the buffer is released with no packet being sent. + * + * \param buffer frame buffer containing packet data + * + * Throws an exception if an I/O error occurs while sending + */ + virtual void release_send_buff(frame_buff::uptr buff) = 0; + + send_link_if() = default; + send_link_if(const send_link_if&) = delete; + send_link_if& operator=(const send_link_if&) = delete; +}; + +/*! + * Link interface for receiving packets. + */ +class recv_link_if +{ +public: + using sptr = std::shared_ptr<recv_link_if>; + + /*! + * Get the number of frame buffers that can be queued by this link. + */ + virtual size_t get_num_recv_frames() const = 0; + + /*! + * Get the maximum capacity of a frame buffer. + */ + virtual size_t get_recv_frame_size() const = 0; + + /*! + * Receive a packet and return a frame buffer containing the packet data. + * + * \param timeout_ms a positive timeout value specifies the maximum number + of ms to wait, a negative value specifies to block + until successful, and a value of 0 specifies no wait. + * \return a frame buffer, or null uptr if timeout occurs + */ + virtual frame_buff::uptr get_recv_buff(int32_t timeout_ms) = 0; + + /*! + * Release a frame buffer, allowing the link driver to reuse it. + * + * \param buffer frame buffer to release for reuse by the link + */ + virtual void release_recv_buff(frame_buff::uptr buff) = 0; + + recv_link_if() = default; + recv_link_if(const recv_link_if&) = delete; + recv_link_if& operator=(const recv_link_if&) = delete; +}; + +}} // namespace uhd::transport + +#endif /* INCLUDED_UHDLIB_TRANSPORT_LINK_IF_HPP */ |