Open Lighting Architecture: include/ola/io/IOQueue.h Source File

| Open Lighting Architecture 0.10.9

Loading...
Searching...
No Matches
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/io/IOVecInterface.h>
25#include <ola/io/InputBuffer.h>
26#include <ola/io/OutputBuffer.h>
27#include <stdint.h>
28#include <deque>
29#include <iostream>
30#include <queue>
31#include <string>
32
33namespace ola {
34namespace io {
35
39 class IOQueue: public InputBufferInterface,
40 public OutputBufferInterface,
41 public IOVecInterface {
42 public:
43 IOQueue();
44 explicit IOQueue(class MemoryBlockPool *block_pool);
45
46 ~IOQueue();
47
48 unsigned int Size() const;
49
50 bool Empty() const {
51 return m_blocks.empty();
52 }
53
54 // From OutputBuffer
55 void Write(const uint8_t *data, unsigned int length);
56
57 // From InputBuffer, these reads consume data from the buffer.
58 unsigned int Read(uint8_t *data, unsigned int length);
59 unsigned int Read(std::string *output, unsigned int length);
60
61 unsigned int Peek(uint8_t *data, unsigned int length) const;
62
63 // From IOVecInterface
64 const struct IOVec *AsIOVec(int *io_count) const;
65 void Pop(unsigned int n);
66
67 // Append a MemoryBlock to this IOQueue. Ownership of the block is taken.
68 void AppendBlock(class MemoryBlock *block);
69
74 void AppendMove(IOQueue *other);
75
76 void Clear();
77
78 // purge the underlying memory pool
79 void Purge();
80
81 void Dump(std::ostream *output);
82
83 private:
84 typedef std::deque<class MemoryBlock*> BlockVector;
85
86 class MemoryBlockPool* m_pool;
87 bool m_delete_pool;
88
89 BlockVector m_blocks;
90
91 void AppendBlock();
92
93 // no copying / assignment for now
94 IOQueue(const IOQueue&);
95 IOQueue& operator=(const IOQueue&);
96};
97} // namespace io
98} // namespace ola
99#endif // INCLUDE_OLA_IO_IOQUEUE_H_
ola::io::IOQueue::AppendMove
void AppendMove(IOQueue *other)
Move the contents of one IOQueue to another.
Definition IOQueue.cpp:217
ola::io::IOQueue::IOQueue
IOQueue()
IOQueue.
Definition IOQueue.cpp:42
ola::io::IOQueue::Clear
void Clear()
Definition IOQueue.cpp:229
ola::io::IOQueue::Write
void Write(const uint8_t *data, unsigned int length)
Definition IOQueue.cpp:82
ola::io::IOQueue::Peek
unsigned int Peek(uint8_t *data, unsigned int length) const
Definition IOQueue.cpp:147
ola::io::IOQueue::AppendBlock
void AppendBlock(class MemoryBlock *block)
Definition IOQueue.cpp:213
ola::io::IOQueue::AsIOVec
const struct IOVec * AsIOVec(int *io_count) const
Definition IOQueue.cpp:186
ola::io::IOQueue::Size
unsigned int Size() const
Definition IOQueue.cpp:67
ola::io::IOQueue::Pop
void Pop(unsigned int n)
Definition IOQueue.cpp:161
ola::io::IOQueue::Read
unsigned int Read(uint8_t *data, unsigned int length)
Definition IOQueue.cpp:103
ola::io::IOQueue::Dump
void Dump(std::ostream *output)
Definition IOQueue.cpp:243
ola::io::IOQueue::~IOQueue
~IOQueue()
Definition IOQueue.cpp:56
ola::io::IOVecInterface
Definition IOVecInterface.h:53
ola::io::InputBufferInterface
Definition InputBuffer.h:34
ola::io::MemoryBlock
A MemoryBlock encapsulates a chunk of memory. It's used by the IOQueue and IOStack classes.
Definition MemoryBlock.h:41
ola::io::MemoryBlockPool
MemoryBlockPool. This class is not thread safe.
Definition MemoryBlockPool.h:35
ola::io::OutputBufferInterface
Definition OutputBuffer.h:36
ola::io
Classes for general I/O and event handling.
Definition Descriptor.cpp:49
ola
The namespace containing all OLA symbols.
Definition Credentials.cpp:44
ola::io::IOVec
Definition IOVecInterface.h:36