diff options
author | Josh Blum <josh@joshknows.com> | 2010-06-01 12:23:20 -0700 |
---|---|---|
committer | Josh Blum <josh@joshknows.com> | 2010-06-01 12:23:20 -0700 |
commit | bb1eef8cade6e39532919918ce1168c3e62a54df (patch) | |
tree | 4b8b68cf6a4e464ad82e6cbfa1a48a4a841cd6cc /host/lib/transport | |
parent | 8c0759df03520f010203fdeb3979f82fc41b72f7 (diff) | |
download | uhd-bb1eef8cade6e39532919918ce1168c3e62a54df.tar.gz uhd-bb1eef8cade6e39532919918ce1168c3e62a54df.tar.bz2 uhd-bb1eef8cade6e39532919918ce1168c3e62a54df.zip |
Moved the packet handler state stuff into a separate header (so we dont pull in all the includes).
Use callback for getting buffers rather than zc interface pointer so its more modular.
Diffstat (limited to 'host/lib/transport')
-rw-r--r-- | host/lib/transport/CMakeLists.txt | 1 | ||||
-rw-r--r-- | host/lib/transport/vrt_packet_handler.hpp | 50 | ||||
-rw-r--r-- | host/lib/transport/vrt_packet_handler_state.hpp | 56 |
3 files changed, 71 insertions, 36 deletions
diff --git a/host/lib/transport/CMakeLists.txt b/host/lib/transport/CMakeLists.txt index a74f7d527..32644a6c0 100644 --- a/host/lib/transport/CMakeLists.txt +++ b/host/lib/transport/CMakeLists.txt @@ -50,5 +50,6 @@ LIBUHD_APPEND_SOURCES( ${CMAKE_SOURCE_DIR}/lib/transport/udp_simple.cpp ${CMAKE_SOURCE_DIR}/lib/transport/udp_zero_copy_asio.cpp ${CMAKE_SOURCE_DIR}/lib/transport/vrt_packet_handler.hpp + ${CMAKE_SOURCE_DIR}/lib/transport/vrt_packet_handler_state.hpp ${CMAKE_SOURCE_DIR}/lib/transport/zero_copy.cpp ) diff --git a/host/lib/transport/vrt_packet_handler.hpp b/host/lib/transport/vrt_packet_handler.hpp index e64e3383d..a179731ca 100644 --- a/host/lib/transport/vrt_packet_handler.hpp +++ b/host/lib/transport/vrt_packet_handler.hpp @@ -18,6 +18,7 @@ #ifndef INCLUDED_LIBUHD_TRANSPORT_VRT_PACKET_HANDLER_HPP #define INCLUDED_LIBUHD_TRANSPORT_VRT_PACKET_HANDLER_HPP +#include "vrt_packet_handler_state.hpp" #include <uhd/config.hpp> #include <uhd/device.hpp> #include <uhd/types/io_type.hpp> @@ -36,23 +37,7 @@ namespace vrt_packet_handler{ /*********************************************************************** * vrt packet handler for recv **********************************************************************/ - struct recv_state{ - //init the expected seq number - size_t next_packet_seq; - - //state variables to handle fragments - uhd::transport::managed_recv_buffer::sptr managed_buff; - boost::asio::const_buffer copy_buff; - size_t fragment_offset_in_samps; - - recv_state(void){ - //first expected seq is zero - next_packet_seq = 0; - - //initially empty copy buffer - copy_buff = boost::asio::buffer("", 0); - } - }; + typedef boost::function<uhd::transport::managed_recv_buffer::sptr(void)> get_recv_buff_t; typedef boost::function<void(uhd::transport::managed_recv_buffer::sptr)> recv_cb_t; @@ -112,15 +97,15 @@ namespace vrt_packet_handler{ const uhd::io_type_t &io_type, const uhd::otw_type_t &otw_type, double tick_rate, - uhd::transport::zero_copy_if::sptr zc_iface, + const get_recv_buff_t &get_recv_buff, //use these two params to handle a layer above vrt size_t vrt_header_offset_words32, - const recv_cb_t& recv_cb + const recv_cb_t &recv_cb ){ //perform a receive if no rx data is waiting to be copied if (boost::asio::buffer_size(state.copy_buff) == 0){ state.fragment_offset_in_samps = 0; - state.managed_buff = zc_iface->get_recv_buff(); + state.managed_buff = get_recv_buff(); recv_cb(state.managed_buff); //callback before vrt unpack try{ _recv1_helper( @@ -169,7 +154,7 @@ namespace vrt_packet_handler{ const uhd::io_type_t &io_type, const uhd::otw_type_t &otw_type, double tick_rate, - uhd::transport::zero_copy_if::sptr zc_iface, + const get_recv_buff_t &get_recv_buff, //use these two params to handle a layer above vrt size_t vrt_header_offset_words32 = 0, const recv_cb_t& recv_cb = &recv_cb_nop @@ -189,7 +174,7 @@ namespace vrt_packet_handler{ metadata, io_type, otw_type, tick_rate, - zc_iface, + get_recv_buff, vrt_header_offset_words32, recv_cb ); @@ -208,7 +193,7 @@ namespace vrt_packet_handler{ (accum_num_samps == 0)? metadata : tmp_md, //only the first metadata gets kept io_type, otw_type, tick_rate, - zc_iface, + get_recv_buff, vrt_header_offset_words32, recv_cb ); @@ -225,14 +210,7 @@ namespace vrt_packet_handler{ /*********************************************************************** * vrt packet handler for send **********************************************************************/ - struct send_state{ - //init the expected seq number - size_t next_packet_seq; - - send_state(void){ - next_packet_seq = 0; - } - }; + typedef boost::function<uhd::transport::managed_send_buffer::sptr(void)> get_send_buff_t; typedef boost::function<void(uhd::transport::managed_send_buffer::sptr)> send_cb_t; @@ -252,12 +230,12 @@ namespace vrt_packet_handler{ const uhd::io_type_t &io_type, const uhd::otw_type_t &otw_type, double tick_rate, - uhd::transport::zero_copy_if::sptr zc_iface, + const get_send_buff_t &get_send_buff, size_t vrt_header_offset_words32, const send_cb_t& send_cb ){ //get a new managed send buffer - uhd::transport::managed_send_buffer::sptr send_buff = zc_iface->get_send_buff(); + uhd::transport::managed_send_buffer::sptr send_buff = get_send_buff(); boost::uint32_t *tx_mem = send_buff->cast<boost::uint32_t *>() + vrt_header_offset_words32; size_t num_header_words32, num_packet_words32; @@ -298,7 +276,7 @@ namespace vrt_packet_handler{ const uhd::io_type_t &io_type, const uhd::otw_type_t &otw_type, double tick_rate, - uhd::transport::zero_copy_if::sptr zc_iface, + const get_send_buff_t &get_send_buff, size_t max_samples_per_packet, //use these two params to handle a layer above vrt size_t vrt_header_offset_words32 = 0, @@ -319,7 +297,7 @@ namespace vrt_packet_handler{ metadata, io_type, otw_type, tick_rate, - zc_iface, + get_send_buff, vrt_header_offset_words32, send_cb ); @@ -353,7 +331,7 @@ namespace vrt_packet_handler{ md, io_type, otw_type, tick_rate, - zc_iface, + get_send_buff, vrt_header_offset_words32, send_cb ); diff --git a/host/lib/transport/vrt_packet_handler_state.hpp b/host/lib/transport/vrt_packet_handler_state.hpp new file mode 100644 index 000000000..2320a3b8e --- /dev/null +++ b/host/lib/transport/vrt_packet_handler_state.hpp @@ -0,0 +1,56 @@ +// +// Copyright 2010 Ettus Research LLC +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, see <http://www.gnu.org/licenses/>. +// + +#ifndef INCLUDED_LIBUHD_TRANSPORT_VRT_PACKET_HANDLER_STATE_HPP +#define INCLUDED_LIBUHD_TRANSPORT_VRT_PACKET_HANDLER_STATE_HPP + +#include <uhd/config.hpp> +#include <uhd/transport/zero_copy.hpp> +#include <boost/asio/buffer.hpp> + +namespace vrt_packet_handler{ + + struct recv_state{ + //init the expected seq number + size_t next_packet_seq; + + //state variables to handle fragments + uhd::transport::managed_recv_buffer::sptr managed_buff; + boost::asio::const_buffer copy_buff; + size_t fragment_offset_in_samps; + + recv_state(void){ + //first expected seq is zero + next_packet_seq = 0; + + //initially empty copy buffer + copy_buff = boost::asio::buffer("", 0); + } + }; + + struct send_state{ + //init the expected seq number + size_t next_packet_seq; + + send_state(void){ + next_packet_seq = 0; + } + }; + +} //namespace vrt_packet_handler + +#endif /* INCLUDED_LIBUHD_TRANSPORT_VRT_PACKET_HANDLER_STATE_HPP */ |