StormByte-Buffer 4.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
44#include <StormByte/type_traits/safe.hxx>
45
49#include <StormByte/platform.h>
50#include <StormByte/safe/optional.hxx>
51#include <StormByte/safe/pointers.hxx>
52
53#include <memory>
54#include <utility>
55
60namespace StormByte {
65 namespace Buffer {
70 namespace Backend {
75 class Pumper;
76 }
77
82 class Chunk {
83 public:
88 explicit Chunk(const StormByte::ByteSize value) noexcept:
89 m_value(value) {}
90
95 StormByte::ByteSize Value() const noexcept {
96 return m_value;
97 }
98
99 private:
103 StormByte::ByteSize m_value;
104 };
105
114 class HighWater {
115 public:
120 explicit HighWater(const StormByte::ByteSize value) noexcept:
121 m_value(value) {}
122
127 StormByte::ByteSize Value() const noexcept {
128 return m_value;
129 }
130
131 private:
135 StormByte::ByteSize m_value;
136 };
137
177 public:
186 public:
190 Parameters() = default;
191
196 Parameters(const Parameters& other) = default;
197
202 Parameters(Parameters&& other) noexcept = default;
203
207 ~Parameters() noexcept = default;
208
214 Parameters& operator=(const Parameters& other) = default;
215
221 Parameters& operator=(Parameters&& other) noexcept = default;
222
228 template<typename... Knobs>
229 Parameters(Knobs... knobs) {
230 (Apply(std::move(knobs)), ...);
231 }
232
238 return m_chunk;
239 }
240
246 return m_high_water;
247 }
248
249 private:
254 void Apply(class Chunk knob) {
255 m_chunk = knob.Value();
256 }
257
262 void Apply(class HighWater knob) {
263 m_high_water = knob.Value();
264 }
265
271 template<typename Knob>
272 void Apply(Knob&& knob) = delete;
273
282 };
283
289 STORMBYTE_FORCE_INLINE explicit Pumper(Bridge&& bridge, Parameters parameters = {}):
290 Pumper(std::move(bridge),
291 parameters.Chunk().value_or(StormByte::ByteSize{0}),
292 parameters.HighWater()) {}
293
298 Pumper(const Pumper& other) = delete;
299
304 Pumper(Pumper&& other) noexcept;
305
309 ~Pumper() noexcept;
310
316 Pumper& operator=(const Pumper& other) = delete;
317
323 Pumper& operator=(Pumper&& other) noexcept;
324
331 void Cancel() noexcept;
332
337 bool Canceled() const noexcept;
338
343 bool EoF() const noexcept;
344
349 bool Failed() const noexcept;
350
358 void Toggle() noexcept;
359
364 const StormByte::Safe::Shared<StormByte::Buffer::ReadTelemetry> ReadTelemetry() const noexcept;
365
370 const StormByte::Safe::Shared<StormByte::Buffer::WriteTelemetry> WriteTelemetry() const noexcept;
371
372 private:
379 Pumper(Bridge&& bridge, StormByte::ByteSize chunk,
380 StormByte::Safe::Optional<StormByte::ByteSize> high_water);
381
385 std::unique_ptr<Backend::Pumper> m_backend;
386 };
387 }
388}
389
Private worker for StormByte::Buffer::Pumper.
Manual bridge between two StormByte-Buffer ends.
Definition bridge.hxx:129
Pumper cycle size.
Definition pumper.hxx:82
Chunk(const StormByte::ByteSize value) noexcept
Store the cycle size.
Definition pumper.hxx:88
StormByte::ByteSize Value() const noexcept
Cycle size.
Definition pumper.hxx:95
Input occupancy cap for Pumper.
Definition pumper.hxx:114
HighWater(const StormByte::ByteSize value) noexcept
Store the input cap.
Definition pumper.hxx:120
StormByte::ByteSize Value() const noexcept
Input cap.
Definition pumper.hxx:127
Optional Pumper knobs.
Definition pumper.hxx:185
Parameters(const Parameters &other)=default
Copy provider-owned knob values; may allocate and throw.
const StormByte::Safe::Optional< StormByte::ByteSize > & HighWater() const noexcept
Input cap when the caller set it.
Definition pumper.hxx:245
const StormByte::Safe::Optional< StormByte::ByteSize > & Chunk() const noexcept
Cycle size when the caller set it.
Definition pumper.hxx:237
~Parameters() noexcept=default
Release knobs through their provider callbacks.
Parameters(Parameters &&other) noexcept=default
Transfer provider-owned knob values.
Owns a Bridge and moves bytes until EoF, failure or Cancel.
Definition pumper.hxx:176
const StormByte::Safe::Shared< StormByte::Buffer::WriteTelemetry > WriteTelemetry() const noexcept
Write counters copied from the owned Bridge.
bool Failed() const noexcept
Whether the owned Bridge failed for real.
bool EoF() const noexcept
Whether the owned Bridge reports EoF.
STORMBYTE_FORCE_INLINE Pumper(Bridge &&bridge, Parameters parameters={})
Take a Bridge and start the worker.
Definition pumper.hxx:289
void Cancel() noexcept
Terminal stop.
bool Canceled() const noexcept
Whether Cancel ran.
Pumper(const Pumper &other)=delete
Copying a worker is not supported.
Pumper(Pumper &&other) noexcept
Move constructor.
const StormByte::Safe::Shared< StormByte::Buffer::ReadTelemetry > ReadTelemetry() const noexcept
Read counters copied from the owned Bridge.
void Toggle() noexcept
Pause or resume the worker.
~Pumper() noexcept
Destructor.
STORMBYTE_DECLARE_MAYBE_SAFE(class StormByte::System::Device::Access)
PIMPL coordinators for public Buffer types that are not IO.
Buffer module of the StormByte suite.
Root namespace of the StormByte C++ suite.
STL namespace.
#define STORMBYTE_FORCE_INLINE
#define STORMBYTE_BUFFER_PUBLIC
Definition visibility.h:54