crawlserv++  [under development]
Application for crawling and analyzing textual content of websites.
SignalHandler.hpp
Go to the documentation of this file.
1 /*
2  *
3  * ---
4  *
5  * Copyright (C) 2021 Anselm Schmidt (ans[ät]ohai.su)
6  *
7  * This program is free software: you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation, either version 3 of the License, or
10  * (at your option) any later version in addition to the terms of any
11  * licences already herein identified.
12  *
13  * This program is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16  * GNU General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License
19  * along with this program. If not, see <https://www.gnu.org/licenses/>.
20  *
21  * ---
22  *
23  * SignalHandler.hpp
24  *
25  * Handles interrupting signals.
26  *
27  * Created on: Dec 11, 2021
28  * Author: ans
29  */
30 
31 #ifndef MAIN_SIGNALHANDLER_HPP_
32 #define MAIN_SIGNALHANDLER_HPP_
33 
34 #include <csignal> // sigaction, sigemptyset/signal, SIGINT, SIGTERM, std::sig_atomic_t
35 
36 namespace crawlservpp::Main {
37 
38  class SignalHandler {
39  public:
42 
43  SignalHandler();
44 
46  virtual ~SignalHandler() = default;
47 
49 
50  protected:
53 
54  void tick();
55 
59 
60  static void signal(int signalNumber);
61 
63  virtual void shutdown(std::sig_atomic_t signal) = 0;
64 
66 
67  private:
68  static volatile std::sig_atomic_t interruptionSignal;
69  };
70 
71 } /* namespace crawlservpp::Main */
72 
73 #endif /* MAIN_SIGNALHANDLER_HPP_ */
void tick()
Checks for interrupting signal.
Definition: SignalHandler.cpp:65
static void signal(int signalNumber)
Static signal handler.
Definition: SignalHandler.cpp:75
virtual void shutdown(std::sig_atomic_t signal)=0
In-class signal handler shutting down the application.
Definition: SignalHandler.hpp:38
virtual ~SignalHandler()=default
Destructor.
SignalHandler()
Constructor.
Definition: SignalHandler.cpp:41
Namespace for the main classes of the program.
Definition: App.cpp:34