OpenZWave Library  1.5.0
Stream.h
Go to the documentation of this file.
1 //-----------------------------------------------------------------------------
2 //
3 // Stream.h
4 //
5 // Cross-platform circular buffer with signalling
6 //
7 // Copyright (c) 2010 Mal Lansell <mal@lansell.org>
8 // All rights reserved.
9 //
10 // SOFTWARE NOTICE AND LICENSE
11 //
12 // This file is part of OpenZWave.
13 //
14 // OpenZWave is free software: you can redistribute it and/or modify
15 // it under the terms of the GNU Lesser General Public License as published
16 // by the Free Software Foundation, either version 3 of the License,
17 // or (at your option) any later version.
18 //
19 // OpenZWave is distributed in the hope that it will be useful,
20 // but WITHOUT ANY WARRANTY; without even the implied warranty of
21 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 // GNU Lesser General Public License for more details.
23 //
24 // You should have received a copy of the GNU Lesser General Public License
25 // along with OpenZWave. If not, see <http://www.gnu.org/licenses/>.
26 //
27 //-----------------------------------------------------------------------------
28 #ifndef _Stream_H
29 #define _Stream_H
30 
31 #include "Defs.h"
32 #include "platform/Wait.h"
33 
34 #include <string>
35 
36 namespace OpenZWave
37 {
38  class Mutex;
39 
43  class Stream: public Wait
44  {
45  friend class Wait;
46 
47  public:
52  Stream( uint32 _bufferSize );
53 
61  void SetSignalThreshold( uint32 _size );
62 
63 
73  bool Get( uint8* _buffer, uint32 _size );
74 
84  bool Put( uint8* _buffer, uint32 _size );
85 
91  uint32 GetDataSize()const{ return m_dataSize; }
92 
98  void Purge();
99 
100  protected:
107  void LogData( uint8* _buffer, uint32 _size, const string &_function );
108 
112  virtual bool IsSignalled();
113 
118  ~Stream();
119 
120  private:
121  Stream( Stream const& ); // prevent copy
122  Stream& operator = ( Stream const& ); // prevent assignment
123 
124  uint8* m_buffer;
125  uint32 m_bufferSize;
126  uint32 m_signalSize;
127  uint32 m_dataSize;
128  uint32 m_head;
129  uint32 m_tail;
130  Mutex* m_mutex;
131  };
132 
133 } // namespace OpenZWave
134 
135 #endif //_Event_H
136 
Definition: Bitfield.h:34
bool Put(uint8 *_buffer, uint32 _size)
Definition: Stream.cpp:133
void LogData(uint8 *_buffer, uint32 _size, const string &_function)
Definition: Stream.cpp:208
Platform-independent definition of a circular buffer.
Definition: Stream.h:43
void SetSignalThreshold(uint32 _size)
Definition: Stream.cpp:74
uint32 GetDataSize() const
Definition: Stream.h:91
virtual bool IsSignalled()
Definition: Stream.cpp:197
Stream(uint32 _bufferSize)
Definition: Stream.cpp:43
unsigned int uint32
Definition: Defs.h:96
~Stream()
Definition: Stream.cpp:62
Platform-independent definition of Wait objects.
Definition: Wait.h:42
Implements a platform-independent mutex–for serializing access to a shared resource.
Definition: Mutex.h:40
void Purge()
Definition: Stream.cpp:184
bool Get(uint8 *_buffer, uint32 _size)
Definition: Stream.cpp:91
unsigned char uint8
Definition: Defs.h:90