OpenZWave Library  1.5.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
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 
42  class Stream: public Wait
43  {
44  friend class Wait;
45 
46  public:
51  Stream( uint32 _bufferSize );
52 
60  void SetSignalThreshold( uint32 _size );
61 
62 
72  bool Get( uint8* _buffer, uint32 _size );
73 
83  bool Put( uint8* _buffer, uint32 _size );
84 
90  uint32 GetDataSize()const{ return m_dataSize; }
91 
97  void Purge();
98 
99  protected:
106  void LogData( uint8* _buffer, uint32 _size, const string &_function );
107 
111  virtual bool IsSignalled();
112 
117  ~Stream();
118 
119  private:
120  Stream( Stream const& ); // prevent copy
121  Stream& operator = ( Stream const& ); // prevent assignment
122 
123  uint8* m_buffer;
124  uint32 m_bufferSize;
125  uint32 m_signalSize;
126  uint32 m_dataSize;
127  uint32 m_head;
128  uint32 m_tail;
129  Mutex* m_mutex;
130  };
131 
132 } // namespace OpenZWave
133 
134 #endif //_Event_H
135 
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:42
void SetSignalThreshold(uint32 _size)
Definition: Stream.cpp:74
virtual bool IsSignalled()
Definition: Stream.cpp:197
Stream(uint32 _bufferSize)
Definition: Stream.cpp:43
unsigned int uint32
Definition: Defs.h:80
~Stream()
Definition: Stream.cpp:62
uint32 GetDataSize() const
Definition: Stream.h:90
Platform-independent definition of Wait objects.
Definition: Wait.h:41
Implements a platform-independent mutex–for serializing access to a shared resource.
Definition: Mutex.h:39
void Purge()
Definition: Stream.cpp:184
bool Get(uint8 *_buffer, uint32 _size)
Definition: Stream.cpp:91
unsigned char uint8
Definition: Defs.h:74