Lumiera  0.pre.03
»edit your freedom«
lifecycle.h
Go to the documentation of this file.
1 /*
2  LIFECYCLE.h - interface for registering and triggering lifecycle callbacks
3 
4  Copyright (C) Lumiera.org
5  2008, Hermann Vosseler <Ichthyostega@web.de>
6 
7  This program is free software; you can redistribute it and/or
8  modify it under the terms of the GNU General Public License as
9  published by the Free Software Foundation; either version 2 of
10  the License, or (at your option) any later version.
11 
12  This program is distributed in the hope that it will be useful,
13  but WITHOUT ANY WARRANTY; without even the implied warranty of
14  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  GNU General Public License for more details.
16 
17  You should have received a copy of the GNU General Public License
18  along with this program; if not, write to the Free Software
19  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20 
21 */
22 
37 #ifndef LUMIERA_LIFECYCLE_H
38 #define LUMIERA_LIFECYCLE_H
39 
40 
41 #ifdef __cplusplus
42 
43 #include "lib/symbol.hpp"
44 #include "lib/nocopy.hpp"
45 
46 
47 
48 namespace lumiera {
49 
50  using lib::Symbol;
51 
52  //defined in liblumiera.so
53  extern const char * ON_BASIC_INIT;
54  extern const char * ON_GLOBAL_INIT;
55  extern const char * ON_GLOBAL_SHUTDOWN;
56 
57  extern const char * ON_EMERGENCY;
58 
59 
60  // client code is free to register and use additional lifecycle events
61 
62 
63 
78  {
79  public:
80  typedef void (*Hook)(void);
81 
82  LifecycleHook (Symbol eventLabel, Hook callbackFun);
83 
85  static void add (Symbol eventLabel, Hook callbackFun);
86 
88  static void trigger (Symbol eventLabel);
89  };
90 
91 
92 
93 } // namespace lumiera
94 
95 
96 
97 #else /* =========== C interface ====================== */
98 
99 
100 //defined in liblumiera.so
101 extern const char * lumiera_ON_BASIC_INIT;
102 extern const char * lumiera_ON_GLOBAL_INIT;
103 extern const char * lumiera_ON_GLOBAL_SHUTDOWN;
104 
105 
106 void lumiera_LifecycleHook_add (const char* eventLabel, void callbackFun(void));
107 void lumiera_Lifecycle_trigger (const char* eventLabel);
108 
109 #endif
110 #endif
const char * ON_BASIC_INIT
automatic static init. treated specially to run as soon as possible
const char * ON_GLOBAL_SHUTDOWN
to be triggered at the end of main()
Any copy and copy construction prohibited.
Definition: nocopy.hpp:46
static void add(Symbol eventLabel, Hook callbackFun)
alternative, static interface for registering a callback
Definition: lifecycle.cpp:69
static void trigger(Symbol eventLabel)
trigger lifecycle callbacks registered under the given label
Definition: lifecycle.cpp:81
Token or Atom with distinct identity.
Definition: symbol.hpp:126
Mix-Ins to allow or prohibit various degrees of copying and cloning.
Marker types to indicate a literal string and a Symbol.
const char * ON_GLOBAL_INIT
to be triggered in main()
define and register a callback for a specific lifecycle event.
Definition: lifecycle.h:76
Lumiera public interface.
Definition: advice.cpp:113
const char * ON_EMERGENCY
activated on shutdown after premature failure of a subsystem