PGROUTING  2.4
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
signalhandler.cpp
Go to the documentation of this file.
1 /*PGR-GNU*****************************************************************
2 
3 Copyright (c) 2015 pgRouting developers
4 Mail: project@pgrouting.org
5 
6 ------
7 
8 This program is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 2 of the License, or
11 (at your option) any later version.
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, write to the Free Software
20 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
21 
22 ********************************************************************PGR-GNU*/
23 /*PGR-MIT******************************************************************
24  *
25  * file signalhandler.cpp
26  *
27  * Copyright 2014 Stephen Woodbridge <woodbri@imaptools.com>
28  * Copyright 2014 Vicky Vergara <vicky_vergara@hotmail.com>
29  *
30  * This is free software; you can redistribute and/or modify it under
31  * the terms of the MIT License. Please file MIT-LICENSE for details.
32  *
33  *****************************************************************PGR-MIT*/
34 
35 #include "./signalhandler.h"
36 
39  if (!instance_) instance_ = new SignalHandler;
40 
41  // assert(instance_ != NULL);
42  return instance_;
43 }
44 
45 
48  // Copy the <old_eh> from the <signum> slot in
49  // the <signalHandlers_> table.
50  EventHandler *old_eh = signalHandlers_[signum];
51 
52  // Store <eh> into the <signum> slot in the
53  // <signalHandlers_> table.
54  SignalHandler::signalHandlers_[signum] = eh;
55 
56  // Register the <dispatcher> to handle this
57  // <signum>.
58  struct sigaction sa;
59  sa.sa_handler = SignalHandler::dispatcher;
60  sigemptyset(&sa.sa_mask);
61  sa.sa_flags = 0;
62  sigaction(signum, &sa, 0);
63 
64  return old_eh;
65 }
66 
67 void SignalHandler::removeHandler(int signum) {
68  // EventHandler *old_eh = signalHandlers_[signum];
69  signalHandlers_[signum] = static_cast<EventHandler *>(0);
70 }
71 
72 
73 void SignalHandler::dispatcher(int signum) {
74  // Perform a sanity check...
75  if (SignalHandler::signalHandlers_[signum] != 0)
76  // Dispatch the handler's hook method.
78 }
79 
80 // these allocate actual storage
83 
virtual void handleSignal(int signum)=0
static SignalHandler * instance_
Definition: signalhandler.h:90
SignalHandler(void)
Definition: signalhandler.h:87
EventHandler * registerHandler(int signum, EventHandler *eh)
static EventHandler * signalHandlers_[NSIG]
void removeHandler(int signum)
static void dispatcher(int signum)
static SignalHandler * instance(void)