Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/chat/src/libraries/util/SignalHandler.h @ 6636

Last change on this file since 6636 was 5738, checked in by landauf, 15 years ago

merged libraries2 back to trunk

  • Property svn:eol-style set to native
File size: 2.8 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    @brief Declaration of the SignalHandler class.
32*/
33
34#ifndef _SignalHandler_H__
35#define _SignalHandler_H__
36
37#include "UtilPrereqs.h"
38
39#include <cassert>
40#include <list>
41#include <string>
42#include "Singleton.h"
43
44namespace orxonox
45{
46    typedef int (*SignalCallback)( void * someData );
47}
48
49#ifdef ORXONOX_PLATFORM_LINUX
50#include <signal.h>
51
52namespace orxonox
53{
54    struct SignalRec
55    {
56        int signal;
57        sig_t handler;
58    };
59
60    struct SignalCallbackRec
61    {
62        SignalCallback cb;
63        void * someData;
64    };
65
66
67    typedef std::list<SignalRec> SignalRecList;
68    typedef std::list<SignalCallbackRec> SignalCallbackList;
69
70    class SignalHandler : public Singleton<SignalHandler>
71    {
72        friend class Singleton<SignalHandler>;
73    public:
74        SignalHandler()  { }
75        ~SignalHandler() { }
76
77        void registerCallback( SignalCallback cb, void * someData );
78
79        void doCatch( const std::string & appName, const std::string & filename );
80        void dontCatch();
81
82    private:
83        static void sigHandler( int sig );
84
85        void catchSignal( int sig );
86        SignalRecList sigRecList;
87
88        SignalCallbackList callbackList;
89
90        static SignalHandler* singletonPtr_s;
91
92        std::string appName;
93        std::string filename;
94    };
95}
96
97#else /* ORXONOX_PLATFORM_LINUX */
98
99namespace orxonox
100{
101    class _UtilExport SignalHandler : public Singleton<SignalHandler>
102    {
103        friend class Singleton<SignalHandler>;
104    public:
105        SignalHandler()  { }
106        ~SignalHandler() { }
107        void doCatch( const std::string & appName, const std::string & filename ) {}
108        void dontCatch() {}
109        void registerCallback( SignalCallback cb, void * someData ) {}
110
111    private:
112        static SignalHandler* singletonPtr_s;
113    };
114}
115
116#endif /* ORXONOX_PLATFORM_LINUX */
117
118#endif /* _SignalHandler_H__ */
Note: See TracBrowser for help on using the repository browser.