SNode.C
Loading...
Searching...
No Matches
core::DescriptorEventPublisher Class Referenceabstract

#include <DescriptorEventPublisher.h>

Inheritance diagram for core::DescriptorEventPublisher:
Collaboration diagram for core::DescriptorEventPublisher:

Public Member Functions

 DescriptorEventPublisher ()=delete
 
virtual ~DescriptorEventPublisher ()
 
 DescriptorEventPublisher (const DescriptorEventPublisher &)=delete
 
DescriptorEventPublisheroperator= (const DescriptorEventPublisher &)=delete
 
void enable (DescriptorEventReceiver *descriptorEventReceiver)
 
void disable (DescriptorEventReceiver *descriptorEventReceiver)
 
void suspend (DescriptorEventReceiver *descriptorEventReceiver)
 
void resume (DescriptorEventReceiver *descriptorEventReceiver)
 
virtual void spanActiveEvents ()=0
 
void checkTimedOutEvents (const utils::Timeval &currentTime)
 
void releaseDisabledEvents (const utils::Timeval &currentTime)
 
int getObservedEventReceiverCount () const
 
int maxFd () const
 
utils::Timeval getNextTimeout (const utils::Timeval &currentTime) const
 
void signal (int sigNum)
 
void disable ()
 
const std::string & getName () const
 

Protected Member Functions

 DescriptorEventPublisher (std::string name)
 

Protected Attributes

std::map< int, std::list< DescriptorEventReceiver * > > observedEventReceiverLists
 
unsigned long eventCounter = 0
 

Private Member Functions

virtual void muxAdd (DescriptorEventReceiver *descriptorEventReceiver)=0
 
virtual void muxDel (int fd)=0
 
virtual void muxOn (DescriptorEventReceiver *descriptorEventReceiver)=0
 
virtual void muxOff (DescriptorEventReceiver *descriptorEventReceiver)=0
 

Private Attributes

std::string name
 
std::map< std::list< DescriptorEventReceiver * > *, std::list< DescriptorEventReceiver * > > dirtyEventReceiverLists
 

Detailed Description

Definition at line 63 of file DescriptorEventPublisher.h.

Constructor & Destructor Documentation

◆ DescriptorEventPublisher() [1/3]

core::DescriptorEventPublisher::DescriptorEventPublisher ( std::string  name)
protected

Definition at line 58 of file DescriptorEventPublisher.cpp.

59 : name(std::move(name)) {
60 }

References name.

Referenced by core::multiplexer::poll::DescriptorEventPublisher::DescriptorEventPublisher(), core::multiplexer::select::DescriptorEventPublisher::DescriptorEventPublisher(), and core::multiplexer::epoll::DescriptorEventPublisher::DescriptorEventPublisher().

Here is the caller graph for this function:

◆ DescriptorEventPublisher() [2/3]

core::DescriptorEventPublisher::DescriptorEventPublisher ( )
delete

◆ ~DescriptorEventPublisher()

core::DescriptorEventPublisher::~DescriptorEventPublisher ( )
virtual

Definition at line 62 of file DescriptorEventPublisher.cpp.

62 {
63 }

◆ DescriptorEventPublisher() [3/3]

core::DescriptorEventPublisher::DescriptorEventPublisher ( const DescriptorEventPublisher )
delete

Member Function Documentation

◆ checkTimedOutEvents()

void core::DescriptorEventPublisher::checkTimedOutEvents ( const utils::Timeval currentTime)

Definition at line 90 of file DescriptorEventPublisher.cpp.

90 {
91 for (auto& [fd, eventReceivers] : observedEventReceiverLists) {
92 eventReceivers.front()->checkTimeout(currentTime);
93 }
94 }
std::map< int, std::list< DescriptorEventReceiver * > > observedEventReceiverLists

References core::DescriptorEventReceiver::checkTimeout(), and observedEventReceiverLists.

Referenced by core::EventMultiplexer::checkTimedOutEvents().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ disable() [1/2]

void core::DescriptorEventPublisher::disable ( )

Definition at line 160 of file DescriptorEventPublisher.cpp.

160 {
161 for (auto& [fd, eventReceivers] : observedEventReceiverLists) {
162 for (DescriptorEventReceiver* eventReceiver : eventReceivers) {
163 eventReceiver->disable();
164 }
165 }
166 }

References core::DescriptorEventReceiver::disable(), and observedEventReceiverLists.

Referenced by core::EventMultiplexer::terminate().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ disable() [2/2]

void core::DescriptorEventPublisher::disable ( DescriptorEventReceiver descriptorEventReceiver)

Definition at line 76 of file DescriptorEventPublisher.cpp.

76 {
77 const int fd = descriptorEventReceiver->getRegisteredFd();
78
79 dirtyEventReceiverLists[&observedEventReceiverLists[fd]].push_back(descriptorEventReceiver);
80 }
std::map< std::list< DescriptorEventReceiver * > *, std::list< DescriptorEventReceiver * > > dirtyEventReceiverLists

References dirtyEventReceiverLists, core::DescriptorEventReceiver::getRegisteredFd(), and observedEventReceiverLists.

Referenced by core::DescriptorEventReceiver::disable().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ enable()

void core::DescriptorEventPublisher::enable ( DescriptorEventReceiver descriptorEventReceiver)

Definition at line 65 of file DescriptorEventPublisher.cpp.

65 {
66 const int fd = descriptorEventReceiver->getRegisteredFd();
67
68 observedEventReceiverLists[fd].push_front(descriptorEventReceiver);
69 muxAdd(descriptorEventReceiver);
70 if (descriptorEventReceiver->isSuspended()) {
71 muxOff(descriptorEventReceiver);
72 }
73 descriptorEventReceiver->setEnabled(utils::Timeval::currentTime());
74 }
virtual void muxAdd(DescriptorEventReceiver *descriptorEventReceiver)=0
virtual void muxOff(DescriptorEventReceiver *descriptorEventReceiver)=0
static Timeval currentTime()
Definition Timeval.cpp:76

References utils::Timeval::currentTime(), core::DescriptorEventReceiver::getRegisteredFd(), core::DescriptorEventReceiver::isSuspended(), muxAdd(), muxOff(), observedEventReceiverLists, and core::DescriptorEventReceiver::setEnabled().

Referenced by core::DescriptorEventReceiver::enable().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ getName()

const std::string & core::DescriptorEventPublisher::getName ( ) const

Definition at line 168 of file DescriptorEventPublisher.cpp.

168 {
169 return name;
170 }

References name.

◆ getNextTimeout()

utils::Timeval core::DescriptorEventPublisher::getNextTimeout ( const utils::Timeval currentTime) const

Definition at line 138 of file DescriptorEventPublisher.cpp.

138 {
140
141 if (dirtyEventReceiverLists.empty()) {
142 for (const auto& [fd, eventReceivers] : observedEventReceiverLists) {
143 nextTimeout = std::min(eventReceivers.front()->getTimeout(currentTime), nextTimeout);
144 }
145 } else {
146 nextTimeout = 0;
147 }
148
149 return nextTimeout;
150 }

References dirtyEventReceiverLists, core::DescriptorEventReceiver::getTimeout(), core::DescriptorEventReceiver::TIMEOUT::MAX, observedEventReceiverLists, and utils::Timeval::operator=().

Referenced by core::EventMultiplexer::getNextTimeout().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ getObservedEventReceiverCount()

int core::DescriptorEventPublisher::getObservedEventReceiverCount ( ) const

Definition at line 124 of file DescriptorEventPublisher.cpp.

124 {
125 return static_cast<int>(observedEventReceiverLists.size());
126 }

References observedEventReceiverLists.

Referenced by core::EventMultiplexer::observedEventReceiverCount().

Here is the caller graph for this function:

◆ maxFd()

int core::DescriptorEventPublisher::maxFd ( ) const

Definition at line 128 of file DescriptorEventPublisher.cpp.

128 {
129 int maxFd = -1;
130
131 if (!observedEventReceiverLists.empty()) {
132 maxFd = observedEventReceiverLists.rbegin()->first;
133 }
134
135 return maxFd;
136 }

References observedEventReceiverLists.

Referenced by core::EventMultiplexer::maxFd().

Here is the caller graph for this function:

◆ muxAdd()

virtual void core::DescriptorEventPublisher::muxAdd ( DescriptorEventReceiver descriptorEventReceiver)
privatepure virtual

Implemented in core::multiplexer::epoll::DescriptorEventPublisher, core::multiplexer::poll::DescriptorEventPublisher, and core::multiplexer::select::DescriptorEventPublisher.

Referenced by enable().

Here is the caller graph for this function:

◆ muxDel()

virtual void core::DescriptorEventPublisher::muxDel ( int  fd)
privatepure virtual

Implemented in core::multiplexer::epoll::DescriptorEventPublisher, core::multiplexer::poll::DescriptorEventPublisher, and core::multiplexer::select::DescriptorEventPublisher.

Referenced by releaseDisabledEvents().

Here is the caller graph for this function:

◆ muxOff()

virtual void core::DescriptorEventPublisher::muxOff ( DescriptorEventReceiver descriptorEventReceiver)
privatepure virtual

Implemented in core::multiplexer::epoll::DescriptorEventPublisher, core::multiplexer::poll::DescriptorEventPublisher, and core::multiplexer::select::DescriptorEventPublisher.

Referenced by enable(), releaseDisabledEvents(), and suspend().

Here is the caller graph for this function:

◆ muxOn()

virtual void core::DescriptorEventPublisher::muxOn ( DescriptorEventReceiver descriptorEventReceiver)
privatepure virtual

Implemented in core::multiplexer::epoll::DescriptorEventPublisher, core::multiplexer::poll::DescriptorEventPublisher, and core::multiplexer::select::DescriptorEventPublisher.

Referenced by releaseDisabledEvents(), and resume().

Here is the caller graph for this function:

◆ operator=()

DescriptorEventPublisher & core::DescriptorEventPublisher::operator= ( const DescriptorEventPublisher )
delete

◆ releaseDisabledEvents()

void core::DescriptorEventPublisher::releaseDisabledEvents ( const utils::Timeval currentTime)

Definition at line 96 of file DescriptorEventPublisher.cpp.

96 {
97 for (auto& [dirtyDescriptEventReceiverList, disabledDescriptorEventReceivers] : dirtyEventReceiverLists) {
98 for (DescriptorEventReceiver* disabledDescriptorEventReceiver : disabledDescriptorEventReceivers) {
99 dirtyDescriptEventReceiverList->remove(disabledDescriptorEventReceiver);
100
101 if (dirtyDescriptEventReceiverList->empty()) {
102 const int fd = disabledDescriptorEventReceiver->getRegisteredFd();
103
104 muxDel(fd);
106 } else {
107 DescriptorEventReceiver* activeDescriptorEventReceiver = dirtyDescriptEventReceiverList->front();
108
109 activeDescriptorEventReceiver->triggered(currentTime);
110 if (!activeDescriptorEventReceiver->isSuspended()) {
111 muxOn(activeDescriptorEventReceiver);
112 } else {
113 muxOff(activeDescriptorEventReceiver);
114 }
115 }
116
117 disabledDescriptorEventReceiver->setDisabled();
118 }
119 }
120
122 }
virtual void muxDel(int fd)=0
virtual void muxOn(DescriptorEventReceiver *descriptorEventReceiver)=0

References dirtyEventReceiverLists, core::DescriptorEventReceiver::getRegisteredFd(), core::DescriptorEventReceiver::isSuspended(), muxDel(), muxOff(), muxOn(), observedEventReceiverLists, core::DescriptorEventReceiver::setDisabled(), and core::DescriptorEventReceiver::triggered().

Referenced by core::EventMultiplexer::releaseExpiredResources().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ resume()

void core::DescriptorEventPublisher::resume ( DescriptorEventReceiver descriptorEventReceiver)

Definition at line 86 of file DescriptorEventPublisher.cpp.

86 {
87 muxOn(descriptorEventReceiver);
88 }

References muxOn().

Referenced by core::DescriptorEventReceiver::resume().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ signal()

void core::DescriptorEventPublisher::signal ( int  sigNum)

Definition at line 152 of file DescriptorEventPublisher.cpp.

152 {
153 for (auto& [fd, eventReceivers] : observedEventReceiverLists) {
154 for (DescriptorEventReceiver* eventReceiver : eventReceivers) {
155 eventReceiver->onSignal(sigNum);
156 }
157 }
158 }

References observedEventReceiverLists, and core::DescriptorEventReceiver::onSignal().

Referenced by core::EventMultiplexer::signal().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ spanActiveEvents()

virtual void core::DescriptorEventPublisher::spanActiveEvents ( )
pure virtual

◆ suspend()

void core::DescriptorEventPublisher::suspend ( DescriptorEventReceiver descriptorEventReceiver)

Definition at line 82 of file DescriptorEventPublisher.cpp.

82 {
83 muxOff(descriptorEventReceiver);
84 }

References muxOff().

Referenced by core::DescriptorEventReceiver::suspend().

Here is the call graph for this function:
Here is the caller graph for this function:

Member Data Documentation

◆ dirtyEventReceiverLists

std::map<std::list<DescriptorEventReceiver*>*, std::list<DescriptorEventReceiver*> > core::DescriptorEventPublisher::dirtyEventReceiverLists
private

Definition at line 106 of file DescriptorEventPublisher.h.

Referenced by disable(), getNextTimeout(), and releaseDisabledEvents().

◆ eventCounter

◆ name

std::string core::DescriptorEventPublisher::name
private

Definition at line 105 of file DescriptorEventPublisher.h.

Referenced by DescriptorEventPublisher(), and getName().

◆ observedEventReceiverLists


The documentation for this class was generated from the following files: