2012-06-10 16:50:54 +00:00
|
|
|
/*
|
2024-09-17 19:00:25 +00:00
|
|
|
* Deskflow -- mouse and keyboard sharing utility
|
2025-01-24 00:11:17 +00:00
|
|
|
* SPDX-FileCopyrightText: (C) 2012 - 2016 Symless Ltd.
|
|
|
|
|
* SPDX-FileCopyrightText: (C) 2002 Chris Schoeneman
|
|
|
|
|
* SPDX-License-Identifier: GPL-2.0-only WITH LicenseRef-OpenSSL-Exception
|
2012-06-10 16:50:54 +00:00
|
|
|
*/
|
|
|
|
|
|
2014-02-28 12:36:45 +00:00
|
|
|
#pragma once
|
2012-06-10 16:50:54 +00:00
|
|
|
|
2025-11-06 22:21:01 +00:00
|
|
|
#include <cstdint>
|
2025-03-20 22:44:45 +00:00
|
|
|
#include <list>
|
2025-03-20 22:42:02 +00:00
|
|
|
#include <vector>
|
2012-06-10 16:50:54 +00:00
|
|
|
|
|
|
|
|
//! FIFO of bytes
|
|
|
|
|
/*!
|
|
|
|
|
This class maintains a FIFO (first-in, last-out) buffer of bytes.
|
|
|
|
|
*/
|
2024-10-17 18:04:35 +00:00
|
|
|
class StreamBuffer
|
|
|
|
|
{
|
2012-06-10 16:50:54 +00:00
|
|
|
public:
|
2025-05-22 22:22:20 +00:00
|
|
|
StreamBuffer() = default;
|
2025-05-01 15:12:05 +00:00
|
|
|
~StreamBuffer() = default;
|
2012-06-10 16:50:54 +00:00
|
|
|
|
2024-07-02 19:07:06 +00:00
|
|
|
//! @name manipulators
|
|
|
|
|
//@{
|
2012-06-10 16:50:54 +00:00
|
|
|
|
2024-07-02 19:07:06 +00:00
|
|
|
//! Read data without removing from buffer
|
|
|
|
|
/*!
|
|
|
|
|
Return a pointer to memory with the next \c n bytes in the buffer
|
|
|
|
|
(which must be <= getSize()). The caller must not modify the returned
|
|
|
|
|
memory nor delete it.
|
|
|
|
|
*/
|
2025-01-11 02:13:19 +00:00
|
|
|
const void *peek(uint32_t n);
|
2012-06-10 16:50:54 +00:00
|
|
|
|
2024-07-02 19:07:06 +00:00
|
|
|
//! Discard data
|
|
|
|
|
/*!
|
|
|
|
|
Discards the next \c n bytes. If \c n >= getSize() then the buffer
|
|
|
|
|
is cleared.
|
|
|
|
|
*/
|
2025-01-11 02:13:19 +00:00
|
|
|
void pop(uint32_t n);
|
2012-06-10 16:50:54 +00:00
|
|
|
|
2024-07-02 19:07:06 +00:00
|
|
|
//! Write data to buffer
|
|
|
|
|
/*!
|
|
|
|
|
Appends \c n bytes from \c data to the buffer.
|
|
|
|
|
*/
|
2025-01-11 02:13:19 +00:00
|
|
|
void write(const void *data, uint32_t n);
|
2012-06-10 16:50:54 +00:00
|
|
|
|
2024-07-02 19:07:06 +00:00
|
|
|
//@}
|
|
|
|
|
//! @name accessors
|
|
|
|
|
//@{
|
2012-06-10 16:50:54 +00:00
|
|
|
|
2024-07-02 19:07:06 +00:00
|
|
|
//! Get size of buffer
|
|
|
|
|
/*!
|
|
|
|
|
Returns the number of bytes in the buffer.
|
|
|
|
|
*/
|
2025-01-11 02:13:19 +00:00
|
|
|
uint32_t getSize() const;
|
2012-06-10 16:50:54 +00:00
|
|
|
|
2024-07-02 19:07:06 +00:00
|
|
|
//@}
|
2012-06-10 16:50:54 +00:00
|
|
|
|
|
|
|
|
private:
|
2025-01-11 02:13:19 +00:00
|
|
|
static const uint32_t kChunkSize;
|
2012-06-10 16:50:54 +00:00
|
|
|
|
2025-01-11 00:09:43 +00:00
|
|
|
using Chunk = std::vector<uint8_t>;
|
2024-11-27 16:51:48 +00:00
|
|
|
using ChunkList = std::list<Chunk>;
|
2012-06-10 16:50:54 +00:00
|
|
|
|
2024-07-02 19:07:06 +00:00
|
|
|
ChunkList m_chunks;
|
2025-05-22 22:22:20 +00:00
|
|
|
uint32_t m_size = 0;
|
|
|
|
|
uint32_t m_headUsed = 0;
|
2012-06-10 16:50:54 +00:00
|
|
|
};
|