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/*
21 * MIT License
22 *
23 * Permission is hereby granted, free of charge, to any person obtaining a copy
24 * of this software and associated documentation files (the "Software"), to deal
25 * in the Software without restriction, including without limitation the rights
26 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
27 * copies of the Software, and to permit persons to whom the Software is
28 * furnished to do so, subject to the following conditions:
29 *
30 * The above copyright notice and this permission notice shall be included in
31 * all copies or substantial portions of the Software.
32 *
33 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
34 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
35 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
36 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
37 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
38 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
39 * THE SOFTWARE.
40 */
41
42#ifndef CORE_EVENTLOOP_H
43#define CORE_EVENTLOOP_H
44
45#include "core/State.h" // IWYU pragma: export
46#include "core/TickStatus.h"
47
48namespace core {
49 class EventMultiplexer;
50} // namespace core
51
52#ifndef DOXYGEN_SHOULD_SKIP_THIS
53
54namespace utils {
55 class Timeval;
56}
57
58#endif /* DOXYGEN_SHOULD_SKIP_THIS */
59
60namespace core {
61
62 class EventLoop {
63 public:
64 EventLoop(const EventLoop& eventLoop) = delete;
65
66 EventLoop& operator=(const EventLoop& eventLoop) = delete;
67
68 private:
69 EventLoop();
70 ~EventLoop() = default;
71
72 public:
73 static EventLoop& instance();
74
75 static unsigned long getTickCounter();
77
78 static core::State getEventLoopState();
79
80 private:
81 // NOLINTNEXTLINE(cppcoreguidelines-avoid-c-arrays, hicpp-avoid-c-arrays, modernize-avoid-c-arrays)
82 static bool init(int argc, char* argv[]);
83 TickStatus _tick(const utils::Timeval& timeOut);
84 static TickStatus tick(const utils::Timeval& timeOut);
85 static int start(const utils::Timeval& timeOut);
86 static void stop();
87 static void free();
88
89 static void stoponsig(int sig);
90
92
93 static int stopsig;
94
95 static unsigned long tickCounter;
96
97 static core::State eventLoopState;
98
99 friend class SNodeC;
100 };
101
102} // namespace core
103
104#endif // CORE_EVENTLOOP_H
static unsigned long tickCounter
Definition EventLoop.h:95
EventMultiplexer & getEventMultiplexer()
Definition EventLoop.cpp:89
EventLoop(const EventLoop &eventLoop)=delete
static core::State getEventLoopState()
Definition EventLoop.cpp:93
static void free()
TickStatus _tick(const utils::Timeval &timeOut)
static EventLoop & instance()
Definition EventLoop.cpp:79
core::EventMultiplexer & eventMultiplexer
Definition EventLoop.h:91
static core::State eventLoopState
Definition EventLoop.h:97
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:93
static TickStatus tick(const utils::Timeval &timeOut)
static bool init(int argc, char *argv[])
Definition EventLoop.cpp:98
static unsigned long getTickCounter()
Definition EventLoop.cpp:85
void span(core::Event *event)
void relax(core::Event *event)
virtual void onEvent(const utils::Timeval &currentTime)=0
bool published
Definition Event.h:83
void span()
Definition Event.cpp:64
const std::string & getName() const
Definition Event.cpp:78
void dispatch(const utils::Timeval &currentTime)
Definition Event.cpp:82
EventMultiplexer & eventMultiplexer
Definition Event.h:81
EventReceiver * eventReceiver
Definition Event.h:80
std::string name
Definition Event.h:78
Event(EventReceiver *eventReceiver, const std::string &name)
Definition Event.cpp:54
EventReceiver * getEventReceiver() const
Definition Event.cpp:87
void relax()
Definition Event.cpp:71
TickStatus
Definition TickStatus.h:51
State
Definition State.h:51