UHD
003.004.000-unknown
|
00001 // 00002 // Copyright 2010-2011 Ettus Research LLC 00003 // 00004 // This program is free software: you can redistribute it and/or modify 00005 // it under the terms of the GNU General Public License as published by 00006 // the Free Software Foundation, either version 3 of the License, or 00007 // (at your option) any later version. 00008 // 00009 // This program is distributed in the hope that it will be useful, 00010 // but WITHOUT ANY WARRANTY; without even the implied warranty of 00011 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00012 // GNU General Public License for more details. 00013 // 00014 // You should have received a copy of the GNU General Public License 00015 // along with this program. If not, see <http://www.gnu.org/licenses/>. 00016 // 00017 00018 #ifndef INCLUDED_UHD_TRANSPORT_ZERO_COPY_HPP 00019 #define INCLUDED_UHD_TRANSPORT_ZERO_COPY_HPP 00020 00021 #include <uhd/config.hpp> 00022 #include <boost/utility.hpp> 00023 #include <boost/shared_ptr.hpp> 00024 #include <boost/intrusive_ptr.hpp> 00025 00026 namespace uhd{ namespace transport{ 00027 00029 template <typename T> UHD_INLINE boost::intrusive_ptr<T> make_managed_buffer(T *p){ 00030 p->_ref_count = 1; //reset the count to 1 reference 00031 return boost::intrusive_ptr<T>(p, false); 00032 } 00033 00039 class UHD_API managed_recv_buffer{ 00040 public: 00041 typedef boost::intrusive_ptr<managed_recv_buffer> sptr; 00042 00048 virtual void release(void) = 0; 00049 00054 template <class T> inline T cast(void) const{ 00055 return static_cast<T>(this->get_buff()); 00056 } 00057 00062 inline size_t size(void) const{ 00063 return this->get_size(); 00064 } 00065 00066 private: 00067 virtual const void *get_buff(void) const = 0; 00068 virtual size_t get_size(void) const = 0; 00069 00070 public: int _ref_count; 00071 }; 00072 00073 UHD_INLINE void intrusive_ptr_add_ref(managed_recv_buffer *p){ 00074 ++(p->_ref_count); 00075 } 00076 00077 UHD_INLINE void intrusive_ptr_release(managed_recv_buffer *p){ 00078 if (--(p->_ref_count) == 0) p->release(); 00079 } 00080 00086 class UHD_API managed_send_buffer{ 00087 public: 00088 typedef boost::intrusive_ptr<managed_send_buffer> sptr; 00089 00096 virtual void commit(size_t num_bytes) = 0; 00097 00102 template <class T> inline T cast(void) const{ 00103 return static_cast<T>(this->get_buff()); 00104 } 00105 00110 inline size_t size(void) const{ 00111 return this->get_size(); 00112 } 00113 00114 private: 00115 virtual void *get_buff(void) const = 0; 00116 virtual size_t get_size(void) const = 0; 00117 00118 public: int _ref_count; 00119 }; 00120 00121 UHD_INLINE void intrusive_ptr_add_ref(managed_send_buffer *p){ 00122 ++(p->_ref_count); 00123 } 00124 00125 UHD_INLINE void intrusive_ptr_release(managed_send_buffer *p){ 00126 if (--(p->_ref_count) == 0) p->commit(0); 00127 } 00128 00134 class UHD_API zero_copy_if : boost::noncopyable{ 00135 public: 00136 typedef boost::shared_ptr<zero_copy_if> sptr; 00137 00143 virtual managed_recv_buffer::sptr get_recv_buff(double timeout = 0.1) = 0; 00144 00150 virtual size_t get_num_recv_frames(void) const = 0; 00151 00157 virtual size_t get_recv_frame_size(void) const = 0; 00158 00164 virtual managed_send_buffer::sptr get_send_buff(double timeout = 0.1) = 0; 00165 00171 virtual size_t get_num_send_frames(void) const = 0; 00172 00178 virtual size_t get_send_frame_size(void) const = 0; 00179 00180 }; 00181 00182 }} //namespace 00183 00184 #endif /* INCLUDED_UHD_TRANSPORT_ZERO_COPY_HPP */