OpenZWave Library  1.6.770
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  namespace Internal
39  {
40  namespace Platform
41  {
42  class Mutex;
43 
47  class Stream: public Wait
48  {
49  friend class Wait;
50 
51  public:
56  Stream(uint32 _bufferSize);
57 
65  void SetSignalThreshold(uint32 _size);
66 
76  bool Get(uint8* _buffer, uint32 _size);
77 
87  bool Put(uint8* _buffer, uint32 _size);
88 
95  {
96  return m_dataSize;
97  }
98 
104  void Purge();
105 
106  protected:
113  void LogData(uint8* _buffer, uint32 _size, const string &_function);
114 
118  virtual bool IsSignalled();
119 
124  ~Stream();
125 
126  private:
127  Stream(Stream const&); // prevent copy
128  Stream& operator =(Stream const&); // prevent assignment
129 
130  uint8* m_buffer;
131  uint32 m_bufferSize;
132  uint32 m_signalSize;
133  uint32 m_dataSize;
134  uint32 m_head;
135  uint32 m_tail;
136  Mutex* m_mutex;
137  };
138  } // namespace Platform
139  } // namespace Internal
140 } // namespace OpenZWave
141 
142 #endif //_Event_H
143 
Definition: Bitfield.cpp:30
Platform-independent definition of a circular buffer.
Definition: Stream.h:47
uint32 GetDataSize() const
Definition: Stream.h:94
bool Get(uint8 *_buffer, uint32 _size)
Definition: Stream.cpp:82
~Stream()
Definition: Stream.cpp:58
Platform-independent definition of Wait objects.
Definition: Wait.h:46
unsigned int uint32
Definition: Defs.h:91
void LogData(uint8 *_buffer, uint32 _size, const string &_function)
Definition: Stream.cpp:187
bool Put(uint8 *_buffer, uint32 _size)
Definition: Stream.cpp:120
virtual bool IsSignalled()
Definition: Stream.cpp:178
Implements a platform-independent mutex–for serializing access to a shared resource.
Definition: Mutex.h:44
void SetSignalThreshold(uint32 _size)
Definition: Stream.cpp:68
Stream(uint32 _bufferSize)
Definition: Stream.cpp:47
void Purge()
Definition: Stream.cpp:167
unsigned char uint8
Definition: Defs.h:85