Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/doc/src/libraries/util/SignalHandler.h @ 7364

Last change on this file since 7364 was 7327, checked in by landauf, 14 years ago

added documentation

  • Property svn:eol-style set to native
File size: 3.0 KB
Line 
1/*
2 *   ORXONOX - the hottest 3D action shooter ever to exist
3 *                    > www.orxonox.net <
4 *
5 *
6 *   License notice:
7 *
8 *   This program is free software; you can redistribute it and/or
9 *   modify it under the terms of the GNU General Public License
10 *   as published by the Free Software Foundation; either version 2
11 *   of the License, or (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 *   Author:
23 *      Christoph Renner
24 *   Co-authors:
25 *      ...
26 *
27 */
28
29/**
30    @file
31    @ingroup Util
32    @brief Declaration of the SignalHandler class.
33*/
34
35#ifndef _SignalHandler_H__
36#define _SignalHandler_H__
37
38#include "UtilPrereqs.h"
39
40#include <cassert>
41#include <list>
42#include <string>
43#include "Singleton.h"
44
45namespace orxonox
46{
47    typedef int (*SignalCallback)( void * someData );
48}
49
50#ifdef ORXONOX_PLATFORM_LINUX
51#include <signal.h>
52
53namespace orxonox
54{
55    struct SignalRec
56    {
57        int signal;
58        sig_t handler;
59    };
60
61    struct SignalCallbackRec
62    {
63        SignalCallback cb;
64        void * someData;
65    };
66
67
68    typedef std::list<SignalRec> SignalRecList;
69    typedef std::list<SignalCallbackRec> SignalCallbackList;
70
71    /// The SignalHandler is used to catch signals like SIGSEGV and write a backtrace to the logfile.
72    class SignalHandler : public Singleton<SignalHandler>
73    {
74        friend class Singleton<SignalHandler>;
75    public:
76        SignalHandler()  { }
77        ~SignalHandler() { }
78
79        void registerCallback( SignalCallback cb, void * someData );
80
81        void doCatch( const std::string & appName, const std::string & filename );
82        void dontCatch();
83
84    private:
85        static void sigHandler( int sig );
86
87        void catchSignal( int sig );
88        SignalRecList sigRecList;
89
90        SignalCallbackList callbackList;
91
92        static SignalHandler* singletonPtr_s;
93
94        std::string appName;
95        std::string filename;
96    };
97}
98
99#else /* ORXONOX_PLATFORM_LINUX */
100
101namespace orxonox
102{
103    /// The SignalHandler is used to catch signals like SIGSEGV and write a backtrace to the logfile. Not implemented on Windows.
104    class _UtilExport SignalHandler : public Singleton<SignalHandler>
105    {
106        friend class Singleton<SignalHandler>;
107    public:
108        SignalHandler()  { }
109        ~SignalHandler() { }
110        void doCatch( const std::string & appName, const std::string & filename ) {}
111        void dontCatch() {}
112        void registerCallback( SignalCallback cb, void * someData ) {}
113
114    private:
115        static SignalHandler* singletonPtr_s;
116    };
117}
118
119#endif /* ORXONOX_PLATFORM_LINUX */
120
121#endif /* _SignalHandler_H__ */
Note: See TracBrowser for help on using the repository browser.