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/*
21 * MIT License
22 *
23 * Permission is hereby granted, free of charge, to any person obtaining a copy
24 * of this software and associated
25 * documentation files (the "Software"), to deal
26 * in the Software without restriction, including without limitation the rights
27 * to use,
28 * copy, modify, merge, publish, distribute, sublicense, and/or sell
29 * copies of the Software, and to permit persons to whom the Software
30 * is
31 * furnished to do so, subject to the following conditions:
32 *
33 * The above copyright notice and this permission notice shall be
34 * included in
35 * all copies or substantial portions of the Software.
36 *
37 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
38 * EXPRESS OR
39 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
40 * FITNESS FOR A PARTICULAR PURPOSE AND
41 * NONINFRINGEMENT. IN NO EVENT SHALL THE
42 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
43 * LIABILITY, WHETHER IN
44 * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
45 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
46 *
47 * THE SOFTWARE.
48 */
49
50#include "core/multiplexer/poll/DescriptorEventPublisher.h"
51
52#include "core/DescriptorEventReceiver.h"
53#include "core/multiplexer/poll/EventMultiplexer.h"
54
55#ifndef DOXYGEN_SHOULD_SKIP_THIS
56
57#include <list>
58#include <map>
59#include <unordered_map>
60#include <utility>
61
62#endif /* DOXYGEN_SHOULD_SKIP_THIS */
63
64namespace core::multiplexer::poll {
65
66 DescriptorEventPublisher::DescriptorEventPublisher(const std::string& name, PollFdsManager& pollFds, short events, short revents)
68 , pollFds(pollFds)
69 , events(events)
70 , revents(revents) {
71 }
72
74 pollFds.muxAdd(eventReceiver, events);
75 }
76
79 }
80
82 pollFds.muxOn(eventReceiver, events);
83 }
84
86 pollFds.muxOff(eventReceiver, events);
87 }
88
90 pollfd* pollfds = pollFds.getEvents();
91
92 const PollFdsManager::pollfdindex_map& pollFdsIndices = pollFds.getPollFdIndices();
93
94 for (auto& [fd, eventReceivers] : observedEventReceiverLists) {
95 const pollfd& pollFd = pollfds[pollFdsIndices.find(fd)->second.index];
96
97 if ((pollFd.events & events) != 0 && (pollFd.revents & revents) != 0) {
98 core::DescriptorEventReceiver* eventReceiver = eventReceivers.front();
100 eventReceiver->span();
101 }
102 }
103 }
104
105} // namespace core::multiplexer::poll
std::map< int, std::list< DescriptorEventReceiver * > > observedEventReceiverLists
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)