Mercurial > projects > hoofbaby
comparison deps/Platinum/Source/Core/PltRingBufferStream.h @ 0:3425707ddbf6
Initial import (hopefully this mercurial stuff works...)
author | fraserofthenight |
---|---|
date | Mon, 06 Jul 2009 08:06:28 -0700 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:3425707ddbf6 |
---|---|
1 /***************************************************************** | |
2 | | |
3 | Platinum - Ring buffer stream | |
4 | | |
5 | Copyright (c) 2004-2008, Plutinosoft, LLC. | |
6 | All rights reserved. | |
7 | http://www.plutinosoft.com | |
8 | | |
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. | |
13 | | |
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 | | |
21 | This program is distributed in the hope that it will be useful, | |
22 | but WITHOUT ANY WARRANTY; without even the implied warranty of | |
23 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
24 | GNU General Public License for more details. | |
25 | | |
26 | You should have received a copy of the GNU General Public License | |
27 | along with this program; see the file LICENSE.txt. If not, write to | |
28 | the Free Software Foundation, Inc., | |
29 | 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | |
30 | http://www.gnu.org/licenses/gpl-2.0.html | |
31 | | |
32 ****************************************************************/ | |
33 | |
34 #ifndef _PLT_RING_BUFFER_STREAM_H_ | |
35 #define _PLT_RING_BUFFER_STREAM_H_ | |
36 | |
37 /*---------------------------------------------------------------------- | |
38 | includes | |
39 +---------------------------------------------------------------------*/ | |
40 #include "NptStreams.h" | |
41 #include "NptRingBuffer.h" | |
42 #include "NptThreads.h" | |
43 | |
44 /*---------------------------------------------------------------------- | |
45 | PLT_RingBufferStream class | |
46 +---------------------------------------------------------------------*/ | |
47 class PLT_RingBufferStream : public NPT_DelegatingInputStream, | |
48 public NPT_DelegatingOutputStream | |
49 { | |
50 public: | |
51 PLT_RingBufferStream(NPT_Size buffer_size = 4096, bool blocking = true); | |
52 PLT_RingBufferStream(NPT_RingBufferReference& buffer, bool blocking = true); | |
53 virtual ~PLT_RingBufferStream(); | |
54 | |
55 void SetEos() {m_Eos = true;} | |
56 | |
57 // NPT_InputStream methods | |
58 NPT_Result Read(void* buffer, | |
59 NPT_Size bytes_to_read, | |
60 NPT_Size* bytes_read = NULL); | |
61 NPT_Result GetSize(NPT_LargeSize& size) { | |
62 NPT_AutoLock autoLock(m_Lock); | |
63 size = m_TotalBytesWritten; | |
64 return NPT_SUCCESS; | |
65 } | |
66 NPT_Result GetAvailable(NPT_LargeSize& available) { | |
67 NPT_AutoLock autoLock(m_Lock); | |
68 available = m_RingBuffer->GetAvailable(); | |
69 return NPT_SUCCESS; | |
70 } | |
71 | |
72 // NPT_OutputStream methods | |
73 NPT_Result Write(const void* buffer, | |
74 NPT_Size bytes_to_write, | |
75 NPT_Size* bytes_written = NULL); | |
76 NPT_Result Flush(); | |
77 NPT_Result Close() { m_RingBuffer->Close(); return NPT_SUCCESS; } | |
78 | |
79 protected: | |
80 // NPT_DelegatingInputStream methods | |
81 NPT_Result InputSeek(NPT_Position offset) { | |
82 NPT_COMPILER_UNUSED(offset); | |
83 return NPT_FAILURE; | |
84 } | |
85 NPT_Result InputTell(NPT_Position& offset) { | |
86 NPT_AutoLock autoLock(m_Lock); | |
87 offset = m_TotalBytesRead; | |
88 return NPT_SUCCESS; | |
89 } | |
90 | |
91 // NPT_DelegatingOutputStream methods | |
92 NPT_Result OutputSeek(NPT_Position offset) { | |
93 NPT_COMPILER_UNUSED(offset); | |
94 return NPT_FAILURE; | |
95 } | |
96 NPT_Result OutputTell(NPT_Position& offset) { | |
97 NPT_AutoLock autoLock(m_Lock); | |
98 offset = m_TotalBytesWritten; | |
99 return NPT_SUCCESS; | |
100 } | |
101 | |
102 private: | |
103 NPT_RingBufferReference m_RingBuffer; | |
104 NPT_Offset m_TotalBytesRead; | |
105 NPT_Offset m_TotalBytesWritten; | |
106 NPT_Mutex m_Lock; | |
107 bool m_Eos; | |
108 bool m_Blocking; | |
109 }; | |
110 | |
111 typedef NPT_Reference<PLT_RingBufferStream> PLT_RingBufferStreamReference; | |
112 | |
113 #endif // _PLT_RING_BUFFER_STREAM_H_ |