UHD
003.005.000-54-stable
|
00001 // 00002 // Copyright 2010-2012 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 #include <boost/detail/atomic_count.hpp> 00026 00027 namespace uhd{ namespace transport{ 00028 00030 class UHD_API managed_buffer{ 00031 public: 00032 managed_buffer(void):_ref_count(0){} 00033 00039 virtual void release(void) = 0; 00040 00045 UHD_INLINE void commit(size_t num_bytes){ 00046 _length = num_bytes; 00047 } 00048 00053 template <class T> UHD_INLINE T cast(void) const{ 00054 return static_cast<T>(_buffer); 00055 } 00056 00061 UHD_INLINE size_t size(void) const{ 00062 return _length; 00063 } 00064 00066 template <typename T> UHD_INLINE boost::intrusive_ptr<T> make( 00067 T *p, void *buffer, size_t length 00068 ){ 00069 _buffer = buffer; 00070 _length = length; 00071 return boost::intrusive_ptr<T>(p); 00072 } 00073 00074 boost::detail::atomic_count _ref_count; 00075 00076 protected: 00077 void *_buffer; 00078 size_t _length; 00079 }; 00080 00081 UHD_INLINE void intrusive_ptr_add_ref(managed_buffer *p){ 00082 ++(p->_ref_count); 00083 } 00084 00085 UHD_INLINE void intrusive_ptr_release(managed_buffer *p){ 00086 if (--(p->_ref_count) == 0) p->release(); 00087 } 00088 00094 class UHD_API managed_recv_buffer : public managed_buffer{ 00095 public: 00096 typedef boost::intrusive_ptr<managed_recv_buffer> sptr; 00097 }; 00098 00104 class UHD_API managed_send_buffer : public managed_buffer{ 00105 public: 00106 typedef boost::intrusive_ptr<managed_send_buffer> sptr; 00107 }; 00108 00114 class UHD_API zero_copy_if : boost::noncopyable{ 00115 public: 00116 typedef boost::shared_ptr<zero_copy_if> sptr; 00117 00123 virtual managed_recv_buffer::sptr get_recv_buff(double timeout = 0.1) = 0; 00124 00130 virtual size_t get_num_recv_frames(void) const = 0; 00131 00137 virtual size_t get_recv_frame_size(void) const = 0; 00138 00144 virtual managed_send_buffer::sptr get_send_buff(double timeout = 0.1) = 0; 00145 00151 virtual size_t get_num_send_frames(void) const = 0; 00152 00158 virtual size_t get_send_frame_size(void) const = 0; 00159 00160 }; 00161 00162 }} //namespace 00163 00164 #endif /* INCLUDED_UHD_TRANSPORT_ZERO_COPY_HPP */