SNode.C
Loading...
Searching...
No Matches
Source.h
Go to the documentation of this file.
1/*
2 * SNode.C - a slim toolkit for network communication
3 * Copyright (C) Volker Christian <me@vchrist.at>
4 * 2020, 2021, 2022, 2023, 2024, 2025
5 *
6 * This program is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU Lesser General Public License as published
8 * by the Free Software Foundation, either version 3 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU Lesser General Public License for more details.
15 *
16 * You should have received a copy of the GNU Lesser General Public License
17 * along with this program. If not, see <http://www.gnu.org/licenses/>.
18 */
19
20#ifndef CORE_PIPE_SOURCE_H
21#define CORE_PIPE_SOURCE_H
22
23namespace core::pipe {
24 class Sink;
25}
26
27#ifndef DOXYGEN_SHOULD_SKIP_THIS
28
29#include <cstddef>
30#include <functional>
31#include <memory>
32#include <sys/types.h>
33
34#endif /* DOXYGEN_SHOULD_SKIP_THIS */
35
36namespace core::pipe {
37
38 class Source {
39 public:
40 Source() = default;
41
42 Source(Source&) = delete;
43 Source(Source&&) noexcept = default;
44
45 Source& operator=(Source&) = delete;
46 Source& operator=(Source&&) noexcept = default;
47
48 virtual ~Source();
49
50 virtual bool isOpen() = 0;
51
52 void pipe(Sink* sink, const std::function<void(int)>& callback);
53 void pipe(const std::shared_ptr<Sink>& sink, const std::function<void(int)>& callback);
54
55 virtual void start() = 0;
56 virtual void suspend() = 0;
57 virtual void resume() = 0;
58 virtual void stop() = 0;
59
60 protected:
61 ssize_t send(const char* chunk, std::size_t chunkLen);
62 void eof();
63 void error(int errnum);
64
65 private:
66 void disconnect(const Sink* sink);
67
68 Sink* sink = nullptr;
69
70 friend class Sink;
71 };
72
73} // namespace core::pipe
74
75#endif // CORE_PIPE_SOURCE_H
constexpr int MF_READSIZE
std::size_t pufferSize
Definition FileReader.h:56
void onEvent(const utils::Timeval &currentTime) override
static FileReader * open(const std::string &path)
FileReader(int fd, const std::string &name, std::size_t pufferSize, int openErrno)
bool isOpen() override
void error(int errnum)
Definition Source.cpp:87
Source(Source &)=delete
virtual void stop()=0
ssize_t send(const char *chunk, std::size_t chunkLen)
Definition Source.cpp:68
virtual void suspend()=0
Source(Source &&) noexcept=default
void pipe(const std::shared_ptr< Sink > &sink, const std::function< void(int)> &callback)
Definition Source.cpp:55
virtual ~Source()
Definition Source.cpp:32
virtual bool isOpen()=0
Source & operator=(Source &&) noexcept=default
void disconnect(const Sink *sink)
Definition Source.cpp:59
void pipe(Sink *sink, const std::function< void(int)> &callback)
Definition Source.cpp:38
virtual void resume()=0
Source & operator=(Source &)=delete
virtual void start()=0