SNode.C
Loading...
Searching...
No Matches
EventLoop.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_EVENTLOOP_H
21#define CORE_EVENTLOOP_H
22
23#include "core/State.h" // IWYU pragma: export
24#include "core/TickStatus.h"
25
26namespace core {
27 class EventMultiplexer;
28} // namespace core
29
30#ifndef DOXYGEN_SHOULD_SKIP_THIS
31
32namespace utils {
33 class Timeval;
34}
35
36#endif /* DOXYGEN_SHOULD_SKIP_THIS */
37
38namespace core {
39
40 class EventLoop {
41 public:
42 EventLoop(const EventLoop& eventLoop) = delete;
43
44 EventLoop& operator=(const EventLoop& eventLoop) = delete;
45
46 private:
47 EventLoop();
48 ~EventLoop() = default;
49
50 public:
51 static EventLoop& instance();
52
53 static unsigned long getTickCounter();
55
56 static core::State getEventLoopState();
57
58 private:
59 // NOLINTNEXTLINE(cppcoreguidelines-avoid-c-arrays, hicpp-avoid-c-arrays, modernize-avoid-c-arrays)
60 static bool init(int argc, char* argv[]);
61 TickStatus _tick(const utils::Timeval& timeOut);
62 static TickStatus tick(const utils::Timeval& timeOut);
63 static int start(const utils::Timeval& timeOut);
64 static void stop();
65 static void free();
66
67 static void stoponsig(int sig);
68
70
71 static int stopsig;
72
73 static unsigned long tickCounter;
74
75 static core::State eventLoopState;
76
77 friend class SNodeC;
78 };
79
80} // namespace core
81
82#endif // CORE_EVENTLOOP_H
static unsigned long tickCounter
Definition EventLoop.h:73
EventMultiplexer & getEventMultiplexer()
Definition EventLoop.cpp:67
EventLoop(const EventLoop &eventLoop)=delete
static core::State getEventLoopState()
Definition EventLoop.cpp:71
static void free()
TickStatus _tick(const utils::Timeval &timeOut)
static EventLoop & instance()
Definition EventLoop.cpp:57
core::EventMultiplexer & eventMultiplexer
Definition EventLoop.h:69
static core::State eventLoopState
Definition EventLoop.h:75
EventLoop & operator=(const EventLoop &eventLoop)=delete
static void stoponsig(int sig)
static int start(const utils::Timeval &timeOut)
static void stop()
~EventLoop()=default
static int stopsig
Definition EventLoop.h:71
static TickStatus tick(const utils::Timeval &timeOut)
static bool init(int argc, char *argv[])
Definition EventLoop.cpp:76
static unsigned long getTickCounter()
Definition EventLoop.cpp:63
void span(core::Event *event)
void relax(core::Event *event)
virtual void onEvent(const utils::Timeval &currentTime)=0
bool published
Definition Event.h:61
void span()
Definition Event.cpp:42
const std::string & getName() const
Definition Event.cpp:56
void dispatch(const utils::Timeval &currentTime)
Definition Event.cpp:60
EventMultiplexer & eventMultiplexer
Definition Event.h:59
EventReceiver * eventReceiver
Definition Event.h:58
Event(EventReceiver *eventReceiver, const std::string &name)
Definition Event.cpp:32
EventReceiver * getEventReceiver() const
Definition Event.cpp:65
void relax()
Definition Event.cpp:49
TickStatus
Definition TickStatus.h:29
State
Definition State.h:29