SNode.C
Loading...
Searching...
No Matches
core::EventLoop Class Reference

#include <EventLoop.h>

Collaboration diagram for core::EventLoop:

Public Member Functions

 EventLoop (const EventLoop &eventLoop)=delete
 
EventLoopoperator= (const EventLoop &eventLoop)=delete
 
EventMultiplexergetEventMultiplexer ()
 

Static Public Member Functions

static EventLoopinstance ()
 
static unsigned long getTickCounter ()
 
static core::State getEventLoopState ()
 

Private Member Functions

 EventLoop ()
 
 ~EventLoop ()=default
 
TickStatus _tick (const utils::Timeval &timeOut)
 

Static Private Member Functions

static bool init (int argc, char *argv[])
 
static TickStatus tick (const utils::Timeval &timeOut)
 
static int start (const utils::Timeval &timeOut)
 
static void stop ()
 
static void free ()
 
static void stoponsig (int sig)
 

Private Attributes

core::EventMultiplexereventMultiplexer
 

Static Private Attributes

static int stopsig = 0
 
static unsigned long tickCounter = 0
 
static core::State eventLoopState = State::LOADED
 

Friends

class SNodeC
 

Detailed Description

Definition at line 40 of file EventLoop.h.

Constructor & Destructor Documentation

◆ EventLoop() [1/2]

core::EventLoop::EventLoop ( const EventLoop & eventLoop)
delete

◆ EventLoop() [2/2]

core::EventLoop::EventLoop ( )
private

Definition at line 53 of file EventLoop.cpp.

55 }
core::EventMultiplexer & EventMultiplexer()
core::EventMultiplexer & eventMultiplexer
Definition EventLoop.h:69

◆ ~EventLoop()

core::EventLoop::~EventLoop ( )
privatedefault

Member Function Documentation

◆ _tick()

TickStatus core::EventLoop::_tick ( const utils::Timeval & timeOut)
private

Definition at line 114 of file EventLoop.cpp.

114 {
115 TickStatus tickStatus = TickStatus::SUCCESS;
116
117 tickCounter++;
118
119 sigset_t newSet{};
120 sigaddset(&newSet, SIGINT);
121 sigaddset(&newSet, SIGTERM);
122 sigaddset(&newSet, SIGALRM);
123 sigaddset(&newSet, SIGHUP);
124
125 sigset_t oldSet{};
126 sigprocmask(SIG_BLOCK, &newSet, &oldSet);
127
129 tickStatus = eventMultiplexer.tick(tickTimeOut, oldSet);
130 }
131
132 sigprocmask(SIG_SETMASK, &oldSet, nullptr);
133
134 return tickStatus;
135 }
static unsigned long tickCounter
Definition EventLoop.h:73
static core::State eventLoopState
Definition EventLoop.h:75
TickStatus tick(const utils::Timeval &tickTimeOut, const sigset_t &sigMask)
TickStatus
Definition TickStatus.h:29

◆ free()

void core::EventLoop::free ( )
staticprivate

Definition at line 227 of file EventLoop.cpp.

227 {
228 std::string signal = "SIG" + utils::system::sigabbrev_np(stopsig);
229
230 if (signal == "SIGUNKNOWN") {
231 signal = std::to_string(stopsig);
232 }
233
234 if (stopsig != 0) {
235 LOG(TRACE) << "Core: Sending signal " << signal << " to all DescriptorEventReceivers";
236
238 }
239
241
242 utils::Timeval timeout = 2;
243
245 do {
246 auto t1 = std::chrono::system_clock::now();
247 const utils::Timeval timeoutOp = timeout;
248
249 tickStatus = EventLoop::instance()._tick(timeoutOp);
250
251 auto t2 = std::chrono::system_clock::now();
252 const std::chrono::duration<double> seconds = t2 - t1;
253
254 timeout -= seconds.count();
255 } while (timeout > 0 && (tickStatus == TickStatus::SUCCESS));
256
257 LOG(TRACE) << "Core: Terminate all stalled DescriptorEventReceivers";
258
260
261 LOG(TRACE) << "Core: Close all libraries opened during runtime";
262
264
265 LOG(TRACE) << "Core:: Clean up the filesystem";
266
268
269 LOG(TRACE) << "Core:: All resources released";
270
271 LOG(TRACE) << "SNode.C: Ended ... BYE";
272 }
static void execDlCloseAll()
TickStatus _tick(const utils::Timeval &timeOut)
static EventLoop & instance()
Definition EventLoop.cpp:57
static int stopsig
Definition EventLoop.h:71
static void terminate()
Definition Config.cpp:614
sighandler_t signal(int sig, sighandler_t handler)
Definition signal.cpp:32
std::string sigabbrev_np(int sig)
Definition signal.cpp:37

Referenced by core::SNodeC::free().

Here is the caller graph for this function:

◆ getEventLoopState()

State core::EventLoop::getEventLoopState ( )
static

Definition at line 71 of file EventLoop.cpp.

71 {
72 return eventLoopState;
73 }

Referenced by core::eventLoopState(), and core::SNodeC::state().

Here is the caller graph for this function:

◆ getEventMultiplexer()

◆ getTickCounter()

unsigned long core::EventLoop::getTickCounter ( )
static

Definition at line 63 of file EventLoop.cpp.

63 {
64 return tickCounter;
65 }

◆ init()

bool core::EventLoop::init ( int argc,
char * argv[] )
staticprivate

Definition at line 76 of file EventLoop.cpp.

76 {
77 struct sigaction sact{};
78 sigemptyset(&sact.sa_mask);
79 sact.sa_flags = 0;
80 sact.sa_handler = SIG_IGN;
81
82 struct sigaction oldPipeAct{};
83 sigaction(SIGPIPE, &sact, &oldPipeAct);
84
85 struct sigaction oldIntAct{};
86 sigaction(SIGINT, &sact, &oldIntAct);
87
88 struct sigaction oldTermAct{};
89 sigaction(SIGTERM, &sact, &oldTermAct);
90
91 struct sigaction oldAlarmAct{};
92 sigaction(SIGALRM, &sact, &oldAlarmAct);
93
94 struct sigaction oldHupAct{};
95 sigaction(SIGHUP, &sact, &oldHupAct);
96
98
99 if (utils::Config::init(argc, argv)) {
101
102 LOG(TRACE) << "SNode.C: Starting ... HELLO";
103 }
104
105 sigaction(SIGPIPE, &oldPipeAct, nullptr);
106 sigaction(SIGINT, &oldIntAct, nullptr);
107 sigaction(SIGTERM, &oldTermAct, nullptr);
108 sigaction(SIGALRM, &oldAlarmAct, nullptr);
109 sigaction(SIGHUP, &oldHupAct, nullptr);
110
112 }
static void setCustomFormatSpec(const char *format, const el::FormatSpecifierValueResolver &resolver)
Definition Logger.cpp:56
static bool init(int argc, char *argv[])
Definition Config.cpp:106
static std::string getTickCounterAsString(const el::LogMessage *logMessage)
Definition EventLoop.cpp:43

Referenced by core::SNodeC::init().

Here is the caller graph for this function:

◆ instance()

EventLoop & core::EventLoop::instance ( )
static

◆ operator=()

EventLoop & core::EventLoop::operator= ( const EventLoop & eventLoop)
delete

◆ start()

int core::EventLoop::start ( const utils::Timeval & timeOut)
staticprivate

Definition at line 162 of file EventLoop.cpp.

162 {
163 struct sigaction sact{};
164 sigemptyset(&sact.sa_mask);
165 sact.sa_flags = 0;
166 sact.sa_handler = SIG_IGN;
167
168 struct sigaction oldPipeAct{};
169 sigaction(SIGPIPE, &sact, &oldPipeAct);
170
171 sact.sa_handler = EventLoop::stoponsig;
172
173 struct sigaction oldIntAct{};
174 sigaction(SIGINT, &sact, &oldIntAct);
175
176 struct sigaction oldTermAct{};
177 sigaction(SIGTERM, &sact, &oldTermAct);
178
179 struct sigaction oldAlarmAct{};
180 sigaction(SIGALRM, &sact, &oldAlarmAct);
181
182 struct sigaction oldHupAct{};
183 sigaction(SIGHUP, &sact, &oldHupAct);
184
188
189 LOG(TRACE) << "Core::EventLoop: started";
190
191 do {
192 tickStatus = EventLoop::instance()._tick(timeOut);
193 } while ((tickStatus == TickStatus::SUCCESS || tickStatus == TickStatus::INTERRUPTED) && eventLoopState == State::RUNNING);
194
195 switch (tickStatus) {
197 LOG(TRACE) << "Core::EventLoop: Stopped";
198 break;
200 LOG(TRACE) << "Core::EventLoop: No Observer";
201 break;
203 LOG(TRACE) << "Core::EventLoop: Interrupted";
204 break;
206 PLOG(FATAL) << "Core::EventLoop: _tick()";
207 break;
208 }
209 }
210
211 sigaction(SIGPIPE, &oldPipeAct, nullptr);
212 sigaction(SIGTERM, &oldTermAct, nullptr);
213 sigaction(SIGALRM, &oldAlarmAct, nullptr);
214 sigaction(SIGHUP, &oldHupAct, nullptr);
215
216 free();
217
218 sigaction(SIGINT, &oldIntAct, nullptr);
219
220 return stopsig;
221 }
static void free()
static void stoponsig(int sig)
static bool bootstrap()
Definition Config.cpp:343

Referenced by core::SNodeC::start().

Here is the caller graph for this function:

◆ stop()

void core::EventLoop::stop ( )
staticprivate

Definition at line 223 of file EventLoop.cpp.

223 {
225 }

Referenced by core::SNodeC::stop().

Here is the caller graph for this function:

◆ stoponsig()

void core::EventLoop::stoponsig ( int sig)
staticprivate

Definition at line 274 of file EventLoop.cpp.

274 {
275 LOG(TRACE) << "Core: Received signal '" << strsignal(sig) << "' (SIG" << utils::system::sigabbrev_np(sig) << " = " << sig << ")";
276 stopsig = sig;
277 stop();
278 }
static void stop()

◆ tick()

TickStatus core::EventLoop::tick ( const utils::Timeval & timeOut)
staticprivate

Definition at line 137 of file EventLoop.cpp.

137 {
138 TickStatus tickStatus = TickStatus::TRACE;
139
141 struct sigaction sact{};
142 sigemptyset(&sact.sa_mask);
143 sact.sa_flags = 0;
144 sact.sa_handler = SIG_IGN;
145
146 struct sigaction oldPipeAct{};
147 sigaction(SIGPIPE, &sact, &oldPipeAct);
148
149 tickStatus = EventLoop::instance()._tick(timeOut);
150
151 sigaction(SIGPIPE, &oldPipeAct, nullptr);
152 } else {
154 free();
155
156 PLOG(FATAL) << "Core: not initialized: No events will be processed\nCall SNodeC::init(argc, argv) before SNodeC::tick().";
157 }
158
159 return tickStatus;
160 }

Referenced by core::SNodeC::tick().

Here is the caller graph for this function:

Friends And Related Symbol Documentation

◆ SNodeC

friend class SNodeC
friend

Definition at line 77 of file EventLoop.h.

Member Data Documentation

◆ eventLoopState

core::State core::EventLoop::eventLoopState = State::LOADED
staticprivate

Definition at line 75 of file EventLoop.h.

◆ eventMultiplexer

core::EventMultiplexer& core::EventLoop::eventMultiplexer
private

Definition at line 69 of file EventLoop.h.

◆ stopsig

int core::EventLoop::stopsig = 0
staticprivate

Definition at line 71 of file EventLoop.h.

◆ tickCounter

unsigned long core::EventLoop::tickCounter = 0
staticprivate

Definition at line 73 of file EventLoop.h.


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