2021-02-08 09:25:10 +00:00
|
|
|
/*
|
2021-10-04 19:59:10 +00:00
|
|
|
* Copyright (c) Atmosphère-NX
|
2021-02-08 09:25:10 +00:00
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify it
|
|
|
|
* under the terms and conditions of the GNU General Public License,
|
|
|
|
* version 2, as published by the Free Software Foundation.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope it will be useful, but WITHOUT
|
|
|
|
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|
|
|
|
* more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
#pragma once
|
|
|
|
#include <stratosphere.hpp>
|
|
|
|
|
|
|
|
namespace ams::htclow::mux {
|
|
|
|
|
|
|
|
class RingBuffer {
|
|
|
|
private:
|
|
|
|
void *m_buffer;
|
|
|
|
void *m_read_only_buffer;
|
|
|
|
bool m_is_read_only;
|
|
|
|
size_t m_buffer_size;
|
|
|
|
size_t m_data_size;
|
|
|
|
size_t m_offset;
|
2021-02-09 11:21:45 +00:00
|
|
|
bool m_can_discard;
|
2021-02-08 09:25:10 +00:00
|
|
|
public:
|
2021-02-09 11:21:45 +00:00
|
|
|
RingBuffer() : m_buffer(), m_read_only_buffer(), m_is_read_only(true), m_buffer_size(), m_data_size(), m_offset(), m_can_discard(false) { /* ... */ }
|
2021-02-08 22:11:01 +00:00
|
|
|
|
2021-02-10 01:42:39 +00:00
|
|
|
void Initialize(void *buffer, size_t buffer_size);
|
|
|
|
void InitializeForReadOnly(const void *buffer, size_t buffer_size);
|
|
|
|
|
2021-02-10 03:07:51 +00:00
|
|
|
void Clear();
|
|
|
|
|
|
|
|
size_t GetBufferSize() { return m_buffer_size; }
|
2021-02-08 22:11:01 +00:00
|
|
|
size_t GetDataSize() { return m_data_size; }
|
|
|
|
|
2021-02-10 03:51:52 +00:00
|
|
|
Result Read(void *dst, size_t size);
|
2021-02-08 22:11:01 +00:00
|
|
|
Result Write(const void *data, size_t size);
|
2021-02-09 11:21:45 +00:00
|
|
|
|
|
|
|
Result Copy(void *dst, size_t size);
|
|
|
|
|
|
|
|
Result Discard(size_t size);
|
2021-02-08 09:25:10 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
}
|