Lumiera 0.pre.04
»edit your freedom«
Loading...
Searching...
No Matches
lifecycle.cpp
Go to the documentation of this file.
1/*
2 Lifecycle - registering and triggering lifecycle callbacks
3
4 Copyright (C)
5 2008,2017 Hermann Vosseler <Ichthyostega@web.de>
6
7  **Lumiera** is free software; you can redistribute it and/or modify it
8  under the terms of the GNU General Public License as published by the
9  Free Software Foundation; either version 2 of the License, or (at your
10  option) any later version. See the file COPYING for further details.
11
12* *****************************************************************/
13
14
20#include "lib/error.hpp"
21#include "include/lifecycle.h"
23#include "lib/util.hpp"
24
25
26
27
28namespace lumiera {
29
30 // ==== implementation Lifecycle Registry =======
31
40 LifecycleRegistry&
42 {
43 static LifecycleRegistry theRegistry;
44 return theRegistry; // Meyer's singleton
45 }
46
47
48
49 // ==== implementation LifecycleHook class =======
50
52
53
55 {
56 add (eventLabel,callbackFun);
57 }
58
59 void
60 LifecycleHook::add (Symbol eventLabel, Callback callbackFun)
61 {
62 bool isNew = LifecycleRegistry::instance().enrol (eventLabel,callbackFun);
63
64 if (isNew and eventLabel == ON_BASIC_INIT)
65 callbackFun(); // when this code executes,
66 // then per definition we are already post "basic init"
67 // (which happens in the AppState ctor); thus fire it immediately
68 }
69
70
71 void
73 {
75 }
76
77
78
79 CStr ON_BASIC_INIT ("ON_BASIC_INIT");
80 CStr ON_GLOBAL_INIT ("ON_GLOBAL_INIT");
81 CStr ON_GLOBAL_SHUTDOWN ("ON_GLOBAL_SHUTDOWN");
82
83 CStr ON_EMERGENCY ("ON_EMERGENCY");
84
85
86} // namespace lumiera
87
88
89extern "C" { /* ==== implementation C interface for lifecycle hooks ======= */
90
91
95
97
98
99
100 void
101 lumiera_LifecycleHook_add (const char* eventLabel, void callbackFun(void))
102 {
103 lumiera::LifecycleHook (eventLabel, callbackFun);
104 }
105
106
107 void
108 lumiera_Lifecycle_trigger (const char* eventLabel)
109 {
111 }
112
113}
Token or Atom with distinct identity.
Definition symbol.hpp:120
define and register a callback for a specific lifecycle event.
Definition lifecycle.h:69
static void add(Symbol eventLabel, Hook callbackFun)
alternative, static interface for registering a callback
Definition lifecycle.cpp:60
static void trigger(Symbol eventLabel)
trigger lifecycle callbacks registered under the given label
Definition lifecycle.cpp:72
LifecycleHook(Symbol eventLabel, Hook callbackFun)
Definition lifecycle.cpp:54
Registry of callback functions accessible by a label (ID) provided at registration.
static LifecycleRegistry & instance()
get the (single) LifecycleRegistry instance.
Definition lifecycle.cpp:41
bool enrol(Symbol label, Hook toCall)
Lumiera error handling (C++ interface).
const char * CStr
Definition error.hpp:42
const char * lumiera_ON_EMERGENCY
Definition lifecycle.cpp:96
void lumiera_LifecycleHook_add(const char *eventLabel, void callbackFun(void))
const char * lumiera_ON_GLOBAL_SHUTDOWN
Definition lifecycle.cpp:94
void lumiera_Lifecycle_trigger(const char *eventLabel)
const char * lumiera_ON_BASIC_INIT
Definition lifecycle.cpp:92
const char * lumiera_ON_GLOBAL_INIT
Definition lifecycle.cpp:93
Installing and invoking of application lifecycle event callbacks.
Helper for registering lifecycle event callbacks, which are provided as a global service by lumiera::...
Lumiera public interface.
Definition advice.hpp:102
CStr ON_GLOBAL_INIT
to be triggered in main()
CStr ON_GLOBAL_SHUTDOWN
to be triggered at the end of main()
CStr ON_EMERGENCY
activated on shutdown after premature failure of a subsystem
CStr ON_BASIC_INIT
automatic static init. treated specially to run as soon as possible
LifecycleRegistry::Hook Callback
Definition lifecycle.cpp:51
Tiny helper functions and shortcuts to be used everywhere Consider this header to be effectively incl...