PGROUTING  3.2
signalhandler.cpp
Go to the documentation of this file.
1 /*PGR-GNU*****************************************************************
2 
3 Copyright (c) 2015 pgRouting developers
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 <[email protected]>
28  * Copyright 2014 Vicky Vergara <[email protected]>
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 
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 
SignalHandler
Definition: signalhandler.h:70
signalhandler.h
SignalHandler::SignalHandler
SignalHandler(void)
Definition: signalhandler.h:87
SignalHandler::dispatcher
static void dispatcher(int signum)
Definition: signalhandler.cpp:73
SignalHandler::signalHandlers_
static EventHandler * signalHandlers_[NSIG]
Definition: signalhandler.h:100
EventHandler::handleSignal
virtual void handleSignal(int signum)=0
SignalHandler::instance_
static SignalHandler * instance_
Definition: signalhandler.h:90
SignalHandler::registerHandler
EventHandler * registerHandler(int signum, EventHandler *eh)
Definition: signalhandler.cpp:47
SignalHandler::instance
static SignalHandler * instance(void)
Definition: signalhandler.cpp:38
SignalHandler::removeHandler
void removeHandler(int signum)
Definition: signalhandler.cpp:67
EventHandler
Definition: signalhandler.h:59