VideoTools
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
gcleanup.h
Go to the documentation of this file.
1 //
2 // Copyright (C) 2017 Graeme Walker
3 //
4 // This program is free software: you can redistribute it and/or modify
5 // it under the terms of the GNU General Public License as published by
6 // the Free Software Foundation, either version 3 of the License, or
7 // (at your option) any later version.
8 //
9 // This program is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 // GNU General Public License for more details.
13 //
14 // You should have received a copy of the GNU General Public License
15 // along with this program. If not, see <http://www.gnu.org/licenses/>.
16 // ===
17 ///
18 /// \file gcleanup.h
19 ///
20 
21 #ifndef G_CLEANUP_H
22 #define G_CLEANUP_H
23 
24 #include "gdef.h"
25 #include "gpath.h"
26 #include "gsignalsafe.h"
27 #include "gexception.h"
28 
29 namespace G
30 {
31  class Cleanup ;
32 }
33 
34 /// \class G::Cleanup
35 /// A static interface for registering cleanup functions that are called when
36 /// the process terminates abnormally. On unix this relates to signals like
37 /// SIGTERM, SIGINT etc.
38 ///
40 {
41 public:
42  G_EXCEPTION( Error , "cleanup error" ) ;
43 
44  static void init() ;
45  ///< An optional early-initialisation function. May be called more than once.
46 
47  static void add( void (*fn)(SignalSafe,const char*) , const char * arg ) ;
48  ///< Adds the given handler to the list of handlers that are to be called
49  ///< when the process terminates abnormally. The handler function must be
50  ///< fully reentrant, hence the SignalSafe dummy parameter. The 'arg'
51  ///< pointer is kept.
52 
53  static void atexit( bool active = true ) ;
54  ///< Ensures that the cleanup functions are also called via atexit(), in
55  ///< addition to abnormal-termination signals.
56  ///<
57  ///< This can be useful when third-party library code (eg. Xlib) might call
58  ///< exit() (grrr). But be careful to call atexit(false) before normal
59  ///< termination, returning from main().
60 
61 private:
62  Cleanup() ; // not implemeneted
63 } ;
64 
65 #endif
static void atexit(bool active=true)
Ensures that the cleanup functions are also called via atexit(), in addition to abnormal-termination ...
A static interface for registering cleanup functions that are called when the process terminates abno...
Definition: gcleanup.h:39
An empty structure that is used to indicate a signal-safe, reentrant implementation.
Definition: gsignalsafe.h:36
static void init()
An optional early-initialisation function. May be called more than once.
static void add(void(*fn)(SignalSafe, const char *), const char *arg)
Adds the given handler to the list of handlers that are to be called when the process terminates abno...