All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros
zero_copy.hpp
Go to the documentation of this file.
//
// 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
// 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_TRANSPORT_ZERO_COPY_HPP
#define INCLUDED_UHD_TRANSPORT_ZERO_COPY_HPP
#include <uhd/config.hpp>
#include <boost/utility.hpp>
#include <boost/shared_ptr.hpp>
#include <boost/intrusive_ptr.hpp>
namespace uhd{ namespace transport{
template <typename T> UHD_INLINE boost::intrusive_ptr<T> make_managed_buffer(T *p){
p->_ref_count = 1; //reset the count to 1 reference
return boost::intrusive_ptr<T>(p, false);
}
class UHD_API managed_recv_buffer{
public:
typedef boost::intrusive_ptr<managed_recv_buffer> sptr;
virtual void release(void) = 0;
template <class T> inline T cast(void) const{
return static_cast<T>(this->get_buff());
}
inline size_t size(void) const{
return this->get_size();
}
private:
virtual const void *get_buff(void) const = 0;
virtual size_t get_size(void) const = 0;
public: int _ref_count;
};
UHD_INLINE void intrusive_ptr_add_ref(managed_recv_buffer *p){
++(p->_ref_count);
}
UHD_INLINE void intrusive_ptr_release(managed_recv_buffer *p){
if (--(p->_ref_count) == 0) p->release();
}
class UHD_API managed_send_buffer{
public:
typedef boost::intrusive_ptr<managed_send_buffer> sptr;
virtual void commit(size_t num_bytes) = 0;
template <class T> inline T cast(void) const{
return static_cast<T>(this->get_buff());
}
inline size_t size(void) const{
return this->get_size();
}
private:
virtual void *get_buff(void) const = 0;
virtual size_t get_size(void) const = 0;
public: int _ref_count;
};
UHD_INLINE void intrusive_ptr_add_ref(managed_send_buffer *p){
++(p->_ref_count);
}
UHD_INLINE void intrusive_ptr_release(managed_send_buffer *p){
if (--(p->_ref_count) == 0) p->commit(0);
}
class UHD_API zero_copy_if : boost::noncopyable{
public:
typedef boost::shared_ptr<zero_copy_if> sptr;
virtual managed_recv_buffer::sptr get_recv_buff(double timeout = 0.1) = 0;
virtual size_t get_num_recv_frames(void) const = 0;
virtual size_t get_recv_frame_size(void) const = 0;
virtual managed_send_buffer::sptr get_send_buff(double timeout = 0.1) = 0;
virtual size_t get_num_send_frames(void) const = 0;
virtual size_t get_send_frame_size(void) const = 0;
};
}} //namespace
#endif /* INCLUDED_UHD_TRANSPORT_ZERO_COPY_HPP */