]> granicus.if.org Git - icinga2/blob - lib/base/application.h
Implement support for constants in the config parser.
[icinga2] / lib / base / application.h
1 /******************************************************************************
2  * Icinga 2                                                                   *
3  * Copyright (C) 2012-2013 Icinga Development Team (http://www.icinga.org/)   *
4  *                                                                            *
5  * This program is free software; you can redistribute it and/or              *
6  * modify it under the terms of the GNU General Public License                *
7  * as published by the Free Software Foundation; either version 2             *
8  * of the License, or (at your option) any later version.                     *
9  *                                                                            *
10  * This program is distributed in the hope that it will be useful,            *
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of             *
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the              *
13  * GNU General Public License for more details.                               *
14  *                                                                            *
15  * You should have received a copy of the GNU General Public License          *
16  * along with this program; if not, write to the Free Software Foundation     *
17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.             *
18  ******************************************************************************/
19
20 #ifndef APPLICATION_H
21 #define APPLICATION_H
22
23 #include "base/i2-base.h"
24 #include "base/application.th"
25 #include "base/threadpool.h"
26 #include "base/dynamicobject.h"
27
28 namespace icinga {
29
30 class Component;
31
32 /**
33  * Abstract base class for applications.
34  *
35  * @ingroup base
36  */
37 class I2_BASE_API Application : public ObjectImpl<Application> {
38 public:
39         DECLARE_PTR_TYPEDEFS(Application);
40
41         ~Application(void);
42
43         static Application::Ptr GetInstance(void);
44
45         int Run(void);
46
47         /**
48          * Starts the application.
49          *
50          * @returns The exit code of the application.
51          */
52         virtual int Main(void) = 0;
53
54         static int GetArgC(void);
55         static void SetArgC(int argc);
56
57         static char **GetArgV(void);
58         static void SetArgV(char **argv);
59
60         static void InstallExceptionHandlers(void);
61
62         static void RequestShutdown(void);
63         static void RequestRestart(void);
64
65         static void SetDebugging(bool debug);
66         static bool IsDebugging(void);
67
68         void UpdatePidFile(const String& filename);
69         void ClosePidFile(void);
70
71         static String GetExePath(const String& argv0);
72
73         static String GetPrefixDir(void);
74         static void DeclarePrefixDir(const String& path);
75
76         static String GetSysconfDir(void);
77         static void DeclareSysconfDir(const String& path);
78
79         static String GetLocalStateDir(void);
80         static void DeclareLocalStateDir(const String& path);
81
82         static String GetPkgDataDir(void);
83         static void DeclarePkgDataDir(const String& path);
84
85         static String GetStatePath(void);
86         static void DeclareStatePath(const String& path);
87
88         static String GetPidPath(void);
89         static void DeclarePidPath(const String& path);
90
91         static String GetApplicationType(void);
92         static void DeclareApplicationType(const String& type);
93
94         static void MakeVariablesConstant(void);
95
96         static ThreadPool& GetTP(void);
97
98         static String GetVersion(void);
99
100         static double GetStartTime(void);
101         static void SetStartTime(double ts);
102
103 protected:
104         virtual void OnConfigLoaded(void);
105         virtual void Stop(void);
106
107         void RunEventLoop(void) const;
108
109         virtual void OnShutdown(void);
110
111 private:
112         static Application *m_Instance; /**< The application instance. */
113
114         static bool m_ShuttingDown; /**< Whether the application is in the process of
115                                   shutting down. */
116         static bool m_Restarting;
117         static int m_ArgC; /**< The number of command-line arguments. */
118         static char **m_ArgV; /**< Command-line arguments. */
119         FILE *m_PidFile; /**< The PID file */
120         static bool m_Debugging; /**< Whether debugging is enabled. */
121         static double m_StartTime;
122
123 #ifndef _WIN32
124         static void SigIntTermHandler(int signum);
125 #else /* _WIN32 */
126         static BOOL WINAPI CtrlHandler(DWORD type);
127         static LONG WINAPI SEHUnhandledExceptionFilter(PEXCEPTION_POINTERS exi);
128 #endif /* _WIN32 */
129
130         static void DisplayVersionMessage(void);
131         static void DisplayBugMessage(void);
132
133         static void SigAbrtHandler(int signum);
134         static void ExceptionHandler(void);
135
136         static void TimeWatchThreadProc(void);
137         static void NewTxTimerHandler(void);
138 };
139
140 }
141
142 #endif /* APPLICATION_H */