FreeNOS
IOBuffer.h
Go to the documentation of this file.
1/*
2 * Copyright (C) 2015 Niek Linnenbank
3 *
4 * This program is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation, either version 3 of the License, or
7 * (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program. If not, see <http://www.gnu.org/licenses/>.
16 */
17
18#ifndef __LIB_LIBFS_IOBUFFER_H
19#define __LIB_LIBFS_IOBUFFER_H
20
21#include <Types.h>
22#include <Macros.h>
23#include <Memory.h>
24#include "FileSystemMessage.h"
25
38{
39 public:
40
44 IOBuffer();
45
51 IOBuffer(const FileSystemMessage *msg);
52
56 virtual ~IOBuffer();
57
63 Size getCount() const;
64
70 void addCount(const Size bytes);
71
80 void setMessage(const FileSystemMessage *msg);
81
87 const FileSystemMessage * getMessage() const;
88
94 u8 * getBuffer();
95
105 FileSystem::Result read(void *buffer,
106 const Size size,
107 const Size offset = ZERO);
108
118 FileSystem::Result write(const void *buffer,
119 const Size size,
120 const Size offset = ZERO);
121
128
137 FileSystem::Result bufferedWrite(const void *buffer,
138 const Size size);
139
146
154 u8 operator[] (Size index) const;
155
156 private:
157
169
172
175
178
181
184};
185
191#endif /* __LIB_LIBFS_IOBUFFER_H */
Abstract Input/Output buffer.
Definition IOBuffer.h:38
FileSystem::Result flushWrite()
Flush write buffers.
Definition IOBuffer.cpp:204
void addCount(const Size bytes)
Increment byte counter.
Definition IOBuffer.cpp:114
void setMessage(const FileSystemMessage *msg)
Set filesystem message.
Definition IOBuffer.cpp:63
Size m_size
Buffer size.
Definition IOBuffer.h:180
Size getCount() const
Get byte count.
Definition IOBuffer.cpp:109
Memory::Range m_directMapRange
Contains the memory address range of the direct memory mapping.
Definition IOBuffer.h:174
u8 * getBuffer()
Get raw buffer.
Definition IOBuffer.cpp:125
FileSystem::Result bufferedWrite(const void *buffer, const Size size)
Buffered write bytes to the I/O buffer.
Definition IOBuffer.cpp:146
Size m_count
Bytes written to the buffer.
Definition IOBuffer.h:183
const FileSystemMessage * m_message
Current request being processed.
Definition IOBuffer.h:168
virtual ~IOBuffer()
Destructor.
Definition IOBuffer.cpp:43
bool m_directMapped
True if using directly memory-mapped memory (unbuffered)
Definition IOBuffer.h:171
u8 operator[](Size index) const
Byte index operator.
Definition IOBuffer.cpp:217
IOBuffer()
Default empty constructor.
Definition IOBuffer.cpp:24
FileSystem::Result read(void *buffer, const Size size, const Size offset=ZERO)
Read bytes from the I/O buffer.
Definition IOBuffer.cpp:156
FileSystem::Result write(const void *buffer, const Size size, const Size offset=ZERO)
Write bytes to the I/O buffer.
Definition IOBuffer.cpp:180
const FileSystemMessage * getMessage() const
Get filesystem message.
Definition IOBuffer.cpp:120
u8 * m_buffer
Buffer for storing temporary data.
Definition IOBuffer.h:177
FileSystem::Result bufferedRead()
Buffered read bytes from the I/O buffer.
Definition IOBuffer.cpp:130
unsigned int Size
Any sane size indicator cannot go negative.
Definition Types.h:128
#define ZERO
Zero value.
Definition Macros.h:43
unsigned char u8
Unsigned 8-bit number.
Definition Types.h:59
Result
Result code for filesystem Actions.
Definition FileSystem.h:53
FileSystem IPC message.
Memory range.
Definition Memory.h:56