SNode.C
Loading...
Searching...
No Matches
DescriptorEventPublisher.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/multiplexer/poll/DescriptorEventPublisher.h"
21
22#include "core/DescriptorEventReceiver.h"
23#include "core/multiplexer/poll/EventMultiplexer.h"
24
25#ifndef DOXYGEN_SHOULD_SKIP_THIS
26
27#include <list>
28#include <map>
29#include <unordered_map>
30#include <utility>
31
32#endif /* DOXYGEN_SHOULD_SKIP_THIS */
33
34namespace core::multiplexer::poll {
35
36 DescriptorEventPublisher::DescriptorEventPublisher(const std::string& name, PollFdsManager& pollFds, short events, short revents)
37 : core::DescriptorEventPublisher(name)
38 , pollFds(pollFds)
39 , events(events)
40 , revents(revents) {
41 }
42
44 pollFds.muxAdd(eventReceiver, events);
45 }
46
50
52 pollFds.muxOn(eventReceiver, events);
53 }
54
56 pollFds.muxOff(eventReceiver, events);
57 }
58
60 pollfd* pollfds = pollFds.getEvents();
61
62 const std::unordered_map<int, PollFdsManager::PollFdIndex>& pollFdsIndices = pollFds.getPollFdIndices();
63
64 for (auto& [fd, eventReceivers] : observedEventReceiverLists) {
65 const pollfd& pollFd = pollfds[pollFdsIndices.find(fd)->second.index];
66
67 if ((pollFd.events & events) != 0 && (pollFd.revents & revents) != 0) {
68 core::DescriptorEventReceiver* eventReceiver = eventReceivers.front();
69 eventCounter++;
70 eventReceiver->span();
71 }
72 }
73 }
74
75} // namespace core::multiplexer::poll
core::multiplexer::poll::PollFdsManager & pollFds
DescriptorEventPublisher(const std::string &name, core::multiplexer::poll::PollFdsManager &pollFds, short events, short revents)
void muxOff(core::DescriptorEventReceiver *eventReceiver) override
void muxAdd(core::DescriptorEventReceiver *eventReceiver) override
void muxOn(core::DescriptorEventReceiver *eventReceiver) override
void muxOff(const DescriptorEventReceiver *eventReceiver, short event)
void muxAdd(core::DescriptorEventReceiver *eventReceiver, short event)
void muxOn(const core::DescriptorEventReceiver *eventReceiver, short event)