summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJosh Blum <josh@joshknows.com>2011-02-09 19:01:28 -0800
committerJosh Blum <josh@joshknows.com>2011-02-09 19:01:28 -0800
commitfb7e8a09a58f4c08f70ba0e088710a0e011ea01d (patch)
tree6a08b4b8751ba09263de160de89099573b97f69c
parent55884d630ca675c9f006eb0705bc8670119c4737 (diff)
downloaduhd-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.
-rw-r--r--host/examples/test_async_messages.cpp8
-rw-r--r--host/examples/tx_waveforms.cpp2
-rw-r--r--host/include/uhd/CMakeLists.txt1
-rw-r--r--host/include/uhd/device.hpp40
-rw-r--r--host/include/uhd/device.ipp55
-rw-r--r--host/include/uhd/types/CMakeLists.txt1
-rw-r--r--host/include/uhd/types/ref_vector.hpp69
-rw-r--r--host/lib/transport/vrt_packet_handler.hpp8
-rw-r--r--host/lib/usrp/usrp1/io_impl.cpp4
-rw-r--r--host/lib/usrp/usrp1/usrp1_impl.hpp4
-rw-r--r--host/lib/usrp/usrp2/io_impl.cpp4
-rw-r--r--host/lib/usrp/usrp2/usrp2_impl.hpp4
-rw-r--r--host/lib/usrp/usrp_e100/io_impl.cpp4
-rw-r--r--host/lib/usrp/usrp_e100/usrp_e100_impl.hpp6
14 files changed, 101 insertions, 109 deletions
diff --git a/host/examples/test_async_messages.cpp b/host/examples/test_async_messages.cpp
index 7f1094ee0..7f922ed35 100644
--- a/host/examples/test_async_messages.cpp
+++ b/host/examples/test_async_messages.cpp
@@ -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
@@ -91,8 +91,7 @@ bool test_underflow_message(uhd::usrp::multi_usrp::sptr usrp){
md.end_of_burst = false;
md.has_time_spec = false;
- usrp->get_device()->send(
- NULL, 0, md,
+ usrp->get_device()->send("", 0, md,
uhd::io_type_t::COMPLEX_FLOAT32,
uhd::device::SEND_MODE_FULL_BUFF
);
@@ -139,8 +138,7 @@ bool test_time_error_message(uhd::usrp::multi_usrp::sptr usrp){
usrp->set_time_now(uhd::time_spec_t(200.0)); //time at 200s
- usrp->get_device()->send(
- NULL, 0, md,
+ usrp->get_device()->send("", 0, md,
uhd::io_type_t::COMPLEX_FLOAT32,
uhd::device::SEND_MODE_FULL_BUFF
);
diff --git a/host/examples/tx_waveforms.cpp b/host/examples/tx_waveforms.cpp
index dd18d3174..05d49a8b3 100644
--- a/host/examples/tx_waveforms.cpp
+++ b/host/examples/tx_waveforms.cpp
@@ -171,7 +171,7 @@ int UHD_SAFE_MAIN(int argc, char *argv[]){
//send a mini EOB packet
md.start_of_burst = false;
md.end_of_burst = true;
- usrp->get_device()->send(NULL, 0, md,
+ usrp->get_device()->send("", 0, md,
uhd::io_type_t::COMPLEX_FLOAT32,
uhd::device::SEND_MODE_FULL_BUFF
);
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 */
diff --git a/host/lib/transport/vrt_packet_handler.hpp b/host/lib/transport/vrt_packet_handler.hpp
index 02f65000f..11c70dd07 100644
--- a/host/lib/transport/vrt_packet_handler.hpp
+++ b/host/lib/transport/vrt_packet_handler.hpp
@@ -148,7 +148,7 @@ template <typename T> UHD_INLINE T get_context_code(
******************************************************************/
static UHD_INLINE size_t _recv1(
recv_state &state,
- const std::vector<void *> &buffs,
+ const uhd::device::recv_buffs_type &buffs,
size_t offset_bytes,
size_t total_samps,
uhd::rx_metadata_t &metadata,
@@ -227,7 +227,7 @@ template <typename T> UHD_INLINE T get_context_code(
******************************************************************/
static UHD_INLINE size_t recv(
recv_state &state,
- const std::vector<void *> &buffs,
+ const uhd::device::recv_buffs_type &buffs,
const size_t total_num_samps,
uhd::rx_metadata_t &metadata,
uhd::device::recv_mode_t recv_mode,
@@ -328,7 +328,7 @@ template <typename T> UHD_INLINE T get_context_code(
******************************************************************/
static UHD_INLINE size_t _send1(
send_state &state,
- const std::vector<const void *> &buffs,
+ const uhd::device::send_buffs_type &buffs,
const size_t offset_bytes,
const size_t num_samps,
uhd::transport::vrt::if_packet_info_t &if_packet_info,
@@ -374,7 +374,7 @@ template <typename T> UHD_INLINE T get_context_code(
******************************************************************/
static UHD_INLINE size_t send(
send_state &state,
- const std::vector<const void *> &buffs,
+ const uhd::device::send_buffs_type &buffs,
const size_t total_num_samps,
const uhd::tx_metadata_t &metadata,
uhd::device::send_mode_t send_mode,
diff --git a/host/lib/usrp/usrp1/io_impl.cpp b/host/lib/usrp/usrp1/io_impl.cpp
index 7953447d1..88cbab073 100644
--- a/host/lib/usrp/usrp1/io_impl.cpp
+++ b/host/lib/usrp/usrp1/io_impl.cpp
@@ -220,7 +220,7 @@ size_t usrp1_impl::get_max_send_samps_per_packet(void) const {
}
size_t usrp1_impl::send(
- const std::vector<const void *> &buffs, size_t num_samps,
+ const send_buffs_type &buffs, size_t num_samps,
const tx_metadata_t &metadata, const io_type_t &io_type,
send_mode_t send_mode, double timeout
){
@@ -298,7 +298,7 @@ size_t usrp1_impl::get_max_recv_samps_per_packet(void) const {
}
size_t usrp1_impl::recv(
- const std::vector<void *> &buffs, size_t num_samps,
+ const recv_buffs_type &buffs, size_t num_samps,
rx_metadata_t &metadata, const io_type_t &io_type,
recv_mode_t recv_mode, double timeout
){
diff --git a/host/lib/usrp/usrp1/usrp1_impl.hpp b/host/lib/usrp/usrp1/usrp1_impl.hpp
index 28199ebe3..1d9f6709f 100644
--- a/host/lib/usrp/usrp1/usrp1_impl.hpp
+++ b/host/lib/usrp/usrp1/usrp1_impl.hpp
@@ -80,13 +80,13 @@ public:
~usrp1_impl(void);
//the io interface
- size_t send(const std::vector<const void *> &,
+ size_t send(const send_buffs_type &,
size_t,
const uhd::tx_metadata_t &,
const uhd::io_type_t &,
send_mode_t, double);
- size_t recv(const std::vector<void *> &,
+ size_t recv(const recv_buffs_type &,
size_t, uhd::rx_metadata_t &,
const uhd::io_type_t &,
recv_mode_t, double);
diff --git a/host/lib/usrp/usrp2/io_impl.cpp b/host/lib/usrp/usrp2/io_impl.cpp
index 56c20934b..0376ebdae 100644
--- a/host/lib/usrp/usrp2/io_impl.cpp
+++ b/host/lib/usrp/usrp2/io_impl.cpp
@@ -297,7 +297,7 @@ size_t usrp2_impl::get_max_send_samps_per_packet(void) const{
}
size_t usrp2_impl::send(
- const std::vector<const void *> &buffs, size_t num_samps,
+ const send_buffs_type &buffs, size_t num_samps,
const tx_metadata_t &metadata, const io_type_t &io_type,
send_mode_t send_mode, double timeout
){
@@ -459,7 +459,7 @@ static void handle_overflow(std::vector<usrp2_mboard_impl::sptr> &mboards, size_
}
size_t usrp2_impl::recv(
- const std::vector<void *> &buffs, size_t num_samps,
+ const recv_buffs_type &buffs, size_t num_samps,
rx_metadata_t &metadata, const io_type_t &io_type,
recv_mode_t recv_mode, double timeout
){
diff --git a/host/lib/usrp/usrp2/usrp2_impl.hpp b/host/lib/usrp/usrp2/usrp2_impl.hpp
index ad95b2a4a..337f842d6 100644
--- a/host/lib/usrp/usrp2/usrp2_impl.hpp
+++ b/host/lib/usrp/usrp2/usrp2_impl.hpp
@@ -200,12 +200,12 @@ public:
//the io interface
size_t send(
- const std::vector<const void *> &, size_t,
+ const send_buffs_type &, size_t,
const uhd::tx_metadata_t &, const uhd::io_type_t &,
uhd::device::send_mode_t, double
);
size_t recv(
- const std::vector<void *> &, size_t,
+ const recv_buffs_type &, size_t,
uhd::rx_metadata_t &, const uhd::io_type_t &,
uhd::device::recv_mode_t, double
);
diff --git a/host/lib/usrp/usrp_e100/io_impl.cpp b/host/lib/usrp/usrp_e100/io_impl.cpp
index c8b9e03d9..cf2410e4f 100644
--- a/host/lib/usrp/usrp_e100/io_impl.cpp
+++ b/host/lib/usrp/usrp_e100/io_impl.cpp
@@ -212,7 +212,7 @@ size_t usrp_e100_impl::get_max_send_samps_per_packet(void) const{
}
size_t usrp_e100_impl::send(
- const std::vector<const void *> &buffs, size_t num_samps,
+ const send_buffs_type &buffs, size_t num_samps,
const tx_metadata_t &metadata, const io_type_t &io_type,
send_mode_t send_mode, double timeout
){
@@ -242,7 +242,7 @@ size_t usrp_e100_impl::get_max_recv_samps_per_packet(void) const{
}
size_t usrp_e100_impl::recv(
- const std::vector<void *> &buffs, size_t num_samps,
+ const recv_buffs_type &buffs, size_t num_samps,
rx_metadata_t &metadata, const io_type_t &io_type,
recv_mode_t recv_mode, double timeout
){
diff --git a/host/lib/usrp/usrp_e100/usrp_e100_impl.hpp b/host/lib/usrp/usrp_e100/usrp_e100_impl.hpp
index df8e5dc9f..2dc401305 100644
--- a/host/lib/usrp/usrp_e100/usrp_e100_impl.hpp
+++ b/host/lib/usrp/usrp_e100/usrp_e100_impl.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
@@ -83,8 +83,8 @@ public:
~usrp_e100_impl(void);
//the io interface
- size_t send(const std::vector<const void *> &, size_t, const uhd::tx_metadata_t &, const uhd::io_type_t &, send_mode_t, double);
- size_t recv(const std::vector<void *> &, size_t, uhd::rx_metadata_t &, const uhd::io_type_t &, recv_mode_t, double);
+ size_t send(const send_buffs_type &, size_t, const uhd::tx_metadata_t &, const uhd::io_type_t &, send_mode_t, double);
+ size_t recv(const recv_buffs_type &, size_t, uhd::rx_metadata_t &, const uhd::io_type_t &, recv_mode_t, double);
bool recv_async_msg(uhd::async_metadata_t &, double);
size_t get_max_send_samps_per_packet(void) const;
size_t get_max_recv_samps_per_packet(void) const;