Open Lighting Architecture  Latest Git
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
IOQueue.h
1 /*
2  * This library is free software; you can redistribute it and/or
3  * modify it under the terms of the GNU Lesser General Public
4  * License as published by the Free Software Foundation; either
5  * version 2.1 of the License, or (at your option) any later version.
6  *
7  * This library is distributed in the hope that it will be useful,
8  * but WITHOUT ANY WARRANTY; without even the implied warranty of
9  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
10  * Lesser General Public License for more details.
11  *
12  * You should have received a copy of the GNU Lesser General Public
13  * License along with this library; if not, write to the Free Software
14  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
15  *
16  * IOQueue.h
17  * A non-contigous memory buffer that operates as a queue (FIFO).
18  * Copyright (C) 2012 Simon Newton
19  */
20 
21 #ifndef INCLUDE_OLA_IO_IOQUEUE_H_
22 #define INCLUDE_OLA_IO_IOQUEUE_H_
23 
24 #include <ola/base/Macro.h>
25 #include <ola/io/IOVecInterface.h>
26 #include <ola/io/InputBuffer.h>
27 #include <ola/io/OutputBuffer.h>
28 #include <stdint.h>
29 #include <deque>
30 #include <iostream>
31 #include <queue>
32 #include <string>
33 
34 namespace ola {
35 namespace io {
36 
41  public OutputBufferInterface,
42  public IOVecInterface {
43  public:
44  IOQueue();
45  explicit IOQueue(class MemoryBlockPool *block_pool);
46 
47  ~IOQueue();
48 
49  unsigned int Size() const;
50 
51  bool Empty() const {
52  return m_blocks.empty();
53  }
54 
55  // From OutputBuffer
56  void Write(const uint8_t *data, unsigned int length);
57 
58  // From InputBuffer, these reads consume data from the buffer.
59  unsigned int Read(uint8_t *data, unsigned int length);
60  unsigned int Read(std::string *output, unsigned int length);
61 
62  unsigned int Peek(uint8_t *data, unsigned int length) const;
63 
64  // From IOVecInterface
65  const struct IOVec *AsIOVec(int *io_count) const;
66  void Pop(unsigned int n);
67 
68  // Append a MemoryBlock to this IOQueue. Ownership of the block is taken.
69  void AppendBlock(class MemoryBlock *block);
70 
75  void AppendMove(IOQueue *other);
76 
77  void Clear();
78 
79  // purge the underlying memory pool
80  void Purge();
81 
82  void Dump(std::ostream *output);
83 
84  private:
85  typedef std::deque<class MemoryBlock*> BlockVector;
86 
87  class MemoryBlockPool* m_pool;
88  bool m_delete_pool;
89 
90  BlockVector m_blocks;
91 
92  void AppendBlock();
93 
94  // no copying / assignment for now
96 };
97 } // namespace io
98 } // namespace ola
99 #endif // INCLUDE_OLA_IO_IOQUEUE_H_
unsigned int Size() const
Definition: IOQueue.cpp:67
#define DISALLOW_COPY_AND_ASSIGN(TypeName)
Creates dummy copy constructor and assignment operator declarations.
Definition: Macro.h:44
Definition: OutputBuffer.h:36
~IOQueue()
Definition: IOQueue.cpp:56
Definition: IOVecInterface.h:36
const struct IOVec * AsIOVec(int *io_count) const
Definition: IOQueue.cpp:186
void AppendBlock(class MemoryBlock *block)
Definition: IOQueue.cpp:213
void Write(const uint8_t *data, unsigned int length)
Definition: IOQueue.cpp:82
Definition: IOQueue.h:40
void Clear()
Definition: IOQueue.cpp:229
Definition: IOVecInterface.h:53
A MemoryBlock encapsulates a chunk of memory. It's used by the IOQueue and IOStack classes...
Definition: MemoryBlock.h:41
Definition: InputBuffer.h:34
Helper macros.
void Dump(std::ostream *output)
Definition: IOQueue.cpp:243
The namespace containing all OLA symbols.
Definition: Credentials.cpp:44
unsigned int Peek(uint8_t *data, unsigned int length) const
Definition: IOQueue.cpp:147
unsigned int Read(uint8_t *data, unsigned int length)
Definition: IOQueue.cpp:103
MemoryBlockPool. This class is not thread safe.
Definition: MemoryBlockPool.h:35
void Pop(unsigned int n)
Definition: IOQueue.cpp:161
void AppendMove(IOQueue *other)
Move the contents of one IOQueue to another.
Definition: IOQueue.cpp:217
IOQueue()
IOQueue.
Definition: IOQueue.cpp:42