1 /*****************************************************************
3 | Platinum - Ring buffer stream
5 | Copyright (c) 2004-2010, Plutinosoft, LLC.
7 | http://www.plutinosoft.com
9 | This program is free software; you can redistribute it and/or
10 | modify it under the terms of the GNU General Public License
11 | as published by the Free Software Foundation; either version 2
12 | of the License, or (at your option) any later version.
14 | OEMs, ISVs, VARs and other distributors that combine and
15 | distribute commercially licensed software with Platinum software
16 | and do not wish to distribute the source code for the commercially
17 | licensed software under version 2, or (at your option) any later
18 | version, of the GNU General Public License (the "GPL") must enter
19 | into a commercial license agreement with Plutinosoft, LLC.
20 | licensing@plutinosoft.com
22 | This program is distributed in the hope that it will be useful,
23 | but WITHOUT ANY WARRANTY; without even the implied warranty of
24 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
25 | GNU General Public License for more details.
27 | You should have received a copy of the GNU General Public License
28 | along with this program; see the file LICENSE.txt. If not, write to
29 | the Free Software Foundation, Inc.,
30 | 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
31 | http://www.gnu.org/licenses/gpl-2.0.html
33 ****************************************************************/
35 #ifndef _PLT_RING_BUFFER_STREAM_H_
36 #define _PLT_RING_BUFFER_STREAM_H_
38 /*----------------------------------------------------------------------
40 +---------------------------------------------------------------------*/
43 /*----------------------------------------------------------------------
44 | PLT_RingBufferStream class
45 +---------------------------------------------------------------------*/
46 class PLT_RingBufferStream
: public NPT_DelegatingInputStream
,
47 public NPT_DelegatingOutputStream
50 PLT_RingBufferStream(NPT_Size buffer_size
= 4096, bool blocking
= true);
51 PLT_RingBufferStream(NPT_RingBufferReference
& buffer
, bool blocking
= true);
52 ~PLT_RingBufferStream() override
;
55 bool IsAborted() { return m_Aborted
; }
57 // NPT_InputStream methods
58 NPT_Result
Read(void* buffer
,
59 NPT_Size bytes_to_read
,
60 NPT_Size
* bytes_read
= NULL
) override
;
61 NPT_Result
GetSize(NPT_LargeSize
& size
) override
{
62 NPT_COMPILER_UNUSED(size
);
63 return NPT_ERROR_NOT_SUPPORTED
;
65 NPT_Result
GetSpace(NPT_LargeSize
& space
) {
66 NPT_AutoLock
autoLock(m_Lock
);
67 space
= m_RingBuffer
->GetSpace();
70 NPT_Result
GetAvailable(NPT_LargeSize
& available
) override
{
71 NPT_AutoLock
autoLock(m_Lock
);
72 available
= m_RingBuffer
->GetAvailable();
76 // NPT_OutputStream methods
77 NPT_Result
Write(const void* buffer
,
78 NPT_Size bytes_to_write
,
79 NPT_Size
* bytes_written
= NULL
) override
;
80 NPT_Result
Flush() override
;
85 // NPT_DelegatingInputStream methods
86 NPT_Result
InputSeek(NPT_Position offset
) override
{
87 NPT_COMPILER_UNUSED(offset
);
88 return NPT_ERROR_NOT_SUPPORTED
;
90 NPT_Result
InputTell(NPT_Position
& offset
) override
{
91 NPT_AutoLock
autoLock(m_Lock
);
92 offset
= m_TotalBytesRead
;
96 // NPT_DelegatingOutputStream methods
97 NPT_Result
OutputSeek(NPT_Position offset
) override
{
98 NPT_COMPILER_UNUSED(offset
);
99 return NPT_ERROR_NOT_SUPPORTED
;
101 NPT_Result
OutputTell(NPT_Position
& offset
) override
{
102 NPT_AutoLock
autoLock(m_Lock
);
103 offset
= m_TotalBytesWritten
;
108 NPT_RingBufferReference m_RingBuffer
;
109 NPT_Offset m_TotalBytesRead
;
110 NPT_Offset m_TotalBytesWritten
;
117 typedef NPT_Reference
<PLT_RingBufferStream
> PLT_RingBufferStreamReference
;
119 #endif // _PLT_RING_BUFFER_STREAM_H_