SNode.C
Loading...
Searching...
No Matches
Event.cpp
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#include "core/Event.h"
21
22#include "core/EventLoop.h"
23#include "core/EventMultiplexer.h"
24#include "core/EventReceiver.h"
25
26#ifndef DOXYGEN_SHOULD_SKIP_THIS
27
28#endif /* DOXYGEN_SHOULD_SKIP_THIS */
29
30namespace core {
31
32 core::Event::Event(EventReceiver* eventReceiver, const std::string& name)
33 : name(name)
34 , eventReceiver(eventReceiver)
36 }
37
39 relax();
40 }
41
42 void Event::span() {
43 if (!published) {
44 published = true;
46 }
47 }
48
49 void Event::relax() {
50 if (published) {
51 published = false;
53 }
54 }
55
56 const std::string& Event::getName() const {
57 return name;
58 }
59
60 void Event::dispatch(const utils::Timeval& currentTime) {
61 published = false;
62 eventReceiver->onEvent(currentTime);
63 }
64
68
69} // namespace core
EventMultiplexer & getEventMultiplexer()
Definition EventLoop.cpp:67
static EventLoop & instance()
Definition EventLoop.cpp:57
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