diff options
author | Josh Blum <josh@joshknows.com> | 2011-02-09 19:01:28 -0800 |
---|---|---|
committer | Josh Blum <josh@joshknows.com> | 2011-02-09 19:01:28 -0800 |
commit | fb7e8a09a58f4c08f70ba0e088710a0e011ea01d (patch) | |
tree | 6a08b4b8751ba09263de160de89099573b97f69c /host/include | |
parent | 55884d630ca675c9f006eb0705bc8670119c4737 (diff) | |
download | uhd-fb7e8a09a58f4c08f70ba0e088710a0e011ea01d.tar.gz uhd-fb7e8a09a58f4c08f70ba0e088710a0e011ea01d.tar.bz2 uhd-fb7e8a09a58f4c08f70ba0e088710a0e011ea01d.zip |
uhd: replaced std::vector<type> for buffer arguments in send/recv
Created new type ref_vector for representing a vector of pointers.
Can be created from std::vector or a pointer.
Removes the convenience constrcutors for send/recv, its not needed.
Removes malloc/free overhead when using send/recv with pointer.
Diffstat (limited to 'host/include')
-rw-r--r-- | host/include/uhd/CMakeLists.txt | 1 | ||||
-rw-r--r-- | host/include/uhd/device.hpp | 40 | ||||
-rw-r--r-- | host/include/uhd/device.ipp | 55 | ||||
-rw-r--r-- | host/include/uhd/types/CMakeLists.txt | 1 | ||||
-rw-r--r-- | host/include/uhd/types/ref_vector.hpp | 69 |
5 files changed, 80 insertions, 86 deletions
diff --git a/host/include/uhd/CMakeLists.txt b/host/include/uhd/CMakeLists.txt index fee1270e9..b7a22cf0b 100644 --- a/host/include/uhd/CMakeLists.txt +++ b/host/include/uhd/CMakeLists.txt @@ -25,7 +25,6 @@ INSTALL(FILES config.hpp convert.hpp device.hpp - device.ipp version.hpp wax.hpp DESTINATION ${INCLUDE_DIR}/uhd diff --git a/host/include/uhd/device.hpp b/host/include/uhd/device.hpp index 992276928..50237472b 100644 --- a/host/include/uhd/device.hpp +++ b/host/include/uhd/device.hpp @@ -1,5 +1,5 @@ // -// Copyright 2010 Ettus Research LLC +// Copyright 2010-2011 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 @@ -22,11 +22,11 @@ #include <uhd/types/device_addr.hpp> #include <uhd/types/metadata.hpp> #include <uhd/types/io_type.hpp> +#include <uhd/types/ref_vector.hpp> #include <uhd/wax.hpp> #include <boost/utility.hpp> #include <boost/shared_ptr.hpp> #include <boost/function.hpp> -#include <vector> namespace uhd{ @@ -96,6 +96,12 @@ public: RECV_MODE_ONE_PACKET = 1 }; + //! Typedef for a pointer to a single, or a collection of send buffers + typedef ref_vector<const void *> send_buffs_type; + + //! Typedef for a pointer to a single, or a collection of recv buffers + typedef ref_vector<void *> recv_buffs_type; + /*! * Send buffers containing IF data described by the metadata. * @@ -121,7 +127,7 @@ public: * \return the number of samples sent */ virtual size_t send( - const std::vector<const void *> &buffs, + const send_buffs_type &buffs, size_t nsamps_per_buff, const tx_metadata_t &metadata, const io_type_t &io_type, @@ -130,18 +136,6 @@ public: ) = 0; /*! - * Convenience wrapper for send that takes a single buffer. - */ - size_t send( - const void *buff, - size_t nsamps_per_buff, - const tx_metadata_t &metadata, - const io_type_t &io_type, - send_mode_t send_mode, - double timeout = 0.1 - ); - - /*! * Receive buffers containing IF data described by the metadata. * * Receive handles fragmentation as follows: @@ -173,7 +167,7 @@ public: * \return the number of samples received or 0 on error */ virtual size_t recv( - const std::vector<void *> &buffs, + const recv_buffs_type &buffs, size_t nsamps_per_buff, rx_metadata_t &metadata, const io_type_t &io_type, @@ -182,18 +176,6 @@ public: ) = 0; /*! - * Convenience wrapper for recv that takes a single buffer. - */ - size_t recv( - void *buff, - size_t nsamps_per_buff, - rx_metadata_t &metadata, - const io_type_t &io_type, - recv_mode_t recv_mode, - double timeout = 0.1 - ); - - /*! * Get the maximum number of samples per packet on send. * \return the number of samples */ @@ -219,6 +201,4 @@ public: } //namespace uhd -#include <uhd/device.ipp> - #endif /* INCLUDED_UHD_DEVICE_HPP */ diff --git a/host/include/uhd/device.ipp b/host/include/uhd/device.ipp deleted file mode 100644 index e2e51ecd0..000000000 --- a/host/include/uhd/device.ipp +++ /dev/null @@ -1,55 +0,0 @@ -// -// 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_UHD_DEVICE_IPP -#define INCLUDED_UHD_DEVICE_IPP - -namespace uhd{ - - UHD_INLINE size_t device::send( - const void *buff, - size_t nsamps_per_buff, - const tx_metadata_t &metadata, - const io_type_t &io_type, - send_mode_t send_mode, - double timeout - ){ - return this->send( - std::vector<const void *>(1, buff), - nsamps_per_buff, metadata, - io_type, send_mode, timeout - ); - } - - UHD_INLINE size_t device::recv( - void *buff, - size_t nsamps_per_buff, - rx_metadata_t &metadata, - const io_type_t &io_type, - recv_mode_t recv_mode, - double timeout - ){ - return this->recv( - std::vector<void *>(1, buff), - nsamps_per_buff, metadata, - io_type, recv_mode, timeout - ); - } - -} //namespace uhd - -#endif /* INCLUDED_UHD_DEVICE_IPP */ diff --git a/host/include/uhd/types/CMakeLists.txt b/host/include/uhd/types/CMakeLists.txt index 51be164aa..c856e5568 100644 --- a/host/include/uhd/types/CMakeLists.txt +++ b/host/include/uhd/types/CMakeLists.txt @@ -26,6 +26,7 @@ INSTALL(FILES metadata.hpp otw_type.hpp ranges.hpp + ref_vector.hpp sensors.hpp serial.hpp stream_cmd.hpp diff --git a/host/include/uhd/types/ref_vector.hpp b/host/include/uhd/types/ref_vector.hpp new file mode 100644 index 000000000..ef970802f --- /dev/null +++ b/host/include/uhd/types/ref_vector.hpp @@ -0,0 +1,69 @@ +// +// Copyright 2011 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_UHD_TYPES_REF_VECTOR_HPP +#define INCLUDED_UHD_TYPES_REF_VECTOR_HPP + +#include <uhd/config.hpp> + +namespace uhd{ + +/*! + * Reference vector: + * - Provides a std::vector-like interface for an array. + * - Statically sized, and does not manage the memory. + */ +template <typename T> class ref_vector{ +public: + //! Create a reference vector of length one from a pointer + template <typename Ptr> ref_vector(Ptr *ptr): + _mem(memp_t(&ptr)), _size(1) + { + /* NOP */ + } + + //! Create a reference vector from a std::vector container + template <typename Range> ref_vector(const Range &range): + _mem(memp_t(&range[0])), _size(range.size()) + { + /* NOP */ + } + + //! Create a reference vector from a memory pointer and size + ref_vector(T *mem, size_t size): + _mem(mem), _size(size) + { + /* NOP */ + } + + T &operator[](size_t index) const{ + return _mem[index]; + } + + size_t size(void) const{ + return _size; + } + +private: + typedef T* memp_t; + const memp_t _mem; + const size_t _size; +}; + +} //namespace uhd + +#endif /* INCLUDED_UHD_TYPES_REF_VECTOR_HPP */ |