StormByte-Buffer 2.0.0
C++26 buffer module of the StormByte suite
 
Loading...
Searching...
No Matches
pumper.hxx
Go to the documentation of this file.
1/*
2 * Copyright (C) 2024-2026 David C. Manuelda (StormBytePP)
3 *
4 * This file is part of StormByte-Buffer.
5 *
6 * StormByte-Buffer original source is dual-licensed:
7 *
8 * 1. GNU Lesser General Public License v3.0 (or later)
9 * You may redistribute and/or modify this file under the terms of the
10 * GNU Lesser General Public License as published by the Free Software
11 * Foundation, either version 3 of the License, or (at your option)
12 * any later version.
13 *
14 * 2. Commercial license
15 * Alternatively, this file may be used under the terms of a commercial
16 * license agreement with the copyright holder
17 * (David C. Manuelda <StormByte@gmail.com>).
18 *
19 * Both licenses apply only to original StormByte-Buffer source in this
20 * repository. They do not cover other StormByte modules or any third-party
21 * material shipped with this repository (including everything under
22 * thirdparty/, and in particular the bundled StormByte-Logger tree and
23 * the rest of the StormByte suite it vendors), which remains under its own
24 * license.
25 *
26 * Neither license grants any patent rights. Any patent licenses required
27 * to use this software or third-party components must be obtained separately
28 * from the patent holders.
29 *
30 * StormByte-Buffer is distributed in the hope that it will be useful,
31 * but WITHOUT ANY WARRANTY; without even the implied warranty of
32 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
33 * GNU Lesser General Public License for more details.
34 *
35 * You should have received a copy of the GNU Lesser General Public License
36 * version 3 along with StormByte-Buffer. If not, see
37 * <https://www.gnu.org/licenses/lgpl-3.0.html>.
38 *
39 * SPDX-License-Identifier: LGPL-3.0-or-later OR LicenseRef-StormByte-Commercial
40 */
41
42#pragma once
43
47#include <StormByte/platform.h>
49
50#include <memory>
51#include <optional>
52#include <utility>
53
58namespace StormByte {
63 namespace Buffer {
68 namespace Backend {
73 class Pumper;
74 }
75
80 class Chunk {
81 public:
86 STORMBYTE_FORCE_INLINE explicit Chunk(const StormByte::ByteSize value) noexcept:
87 m_value(value) {}
88
94 return m_value;
95 }
96
97 private:
98 StormByte::ByteSize m_value;
99 };
100
109 class HighWater {
110 public:
116 m_value(value) {}
117
123 return m_value;
124 }
125
126 private:
127 StormByte::ByteSize m_value;
128 };
129
169 public:
179 public:
183 STORMBYTE_FORCE_INLINE Parameters() noexcept = default;
184
190 template<typename... Knobs>
191 STORMBYTE_FORCE_INLINE Parameters(Knobs... knobs) {
192 (Apply(std::move(knobs)), ...);
193 }
194
199 STORMBYTE_FORCE_INLINE const std::optional<StormByte::ByteSize>& Chunk() const noexcept {
200 return m_chunk;
201 }
202
207 STORMBYTE_FORCE_INLINE const std::optional<StormByte::ByteSize>& HighWater() const noexcept {
208 return m_high_water;
209 }
210
211 private:
216 STORMBYTE_FORCE_INLINE void Apply(class Chunk knob) noexcept {
217 m_chunk = knob.Value();
218 }
219
224 STORMBYTE_FORCE_INLINE void Apply(class HighWater knob) noexcept {
225 m_high_water = knob.Value();
226 }
227
228 template<typename Knob>
229 void Apply(Knob&&) = delete;
230
231 std::optional<StormByte::ByteSize> m_chunk;
232 std::optional<StormByte::ByteSize> m_high_water;
233 };
234
240 STORMBYTE_FORCE_INLINE explicit Pumper(Bridge&& bridge, Parameters parameters = {}):
241 Pumper(std::move(bridge),
242 parameters.Chunk().value_or(StormByte::ByteSize{0}),
243 parameters.HighWater()) {}
244
245 Pumper(const Pumper&) = delete;
246
251 Pumper(Pumper&& other) noexcept;
252
256 ~Pumper() noexcept;
257
258 Pumper& operator=(const Pumper&) = delete;
259
265 Pumper& operator=(Pumper&& other) noexcept;
266
273 void Cancel() noexcept;
274
279 bool Canceled() const noexcept;
280
285 bool EoF() const noexcept;
286
291 bool Failed() const noexcept;
292
298 void Toggle() noexcept;
299
304 const StormByte::Shared<StormByte::Buffer::ReadTelemetry> ReadTelemetry() const noexcept;
305
310 const StormByte::Shared<StormByte::Buffer::WriteTelemetry> WriteTelemetry() const noexcept;
311
312 private:
319 Pumper(Bridge&& bridge, StormByte::ByteSize chunk,
320 std::optional<StormByte::ByteSize> high_water);
321
322 std::unique_ptr<Backend::Pumper> m_backend;
323 };
324 }
325}
Private worker for StormByte::Buffer::Pumper.
Manual bridge between two StormByte-Buffer ends.
Definition bridge.hxx:156
Pumper cycle size.
Definition pumper.hxx:80
STORMBYTE_FORCE_INLINE StormByte::ByteSize Value() const noexcept
Cycle size.
Definition pumper.hxx:93
STORMBYTE_FORCE_INLINE Chunk(const StormByte::ByteSize value) noexcept
Store the cycle size.
Definition pumper.hxx:86
Input occupancy cap for Pumper.
Definition pumper.hxx:109
STORMBYTE_FORCE_INLINE HighWater(const StormByte::ByteSize value) noexcept
Store the input cap.
Definition pumper.hxx:115
STORMBYTE_FORCE_INLINE StormByte::ByteSize Value() const noexcept
Input cap.
Definition pumper.hxx:122
Optional Pumper knobs.
Definition pumper.hxx:178
STORMBYTE_FORCE_INLINE Parameters() noexcept=default
No knobs.
STORMBYTE_FORCE_INLINE const std::optional< StormByte::ByteSize > & Chunk() const noexcept
Cycle size when the caller set it.
Definition pumper.hxx:199
STORMBYTE_FORCE_INLINE const std::optional< StormByte::ByteSize > & HighWater() const noexcept
Input cap when the caller set it.
Definition pumper.hxx:207
Owns a Bridge and moves bytes until EoF, failure or Cancel.
Definition pumper.hxx:168
STORMBYTE_FORCE_INLINE Pumper(Bridge &&bridge, Parameters parameters={})
Take a Bridge and start the worker.
Definition pumper.hxx:240
Pumper(Pumper &&other) noexcept
Move constructor.
Pumper(const Pumper &)=delete
~Pumper() noexcept
Destructor.
Basic read counters.
Definition telemetry.hxx:141
Basic write counters.
Definition telemetry.hxx:181
Root namespace of the StormByte C++ suite.
STL namespace.
#define STORMBYTE_FORCE_INLINE
#define STORMBYTE_BUFFER_PUBLIC
Definition visibility.h:54