1 /******************************************************************************
3 * Copyright (C) 2012-2013 Icinga Development Team (http://www.icinga.org/) *
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. *
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. *
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 ******************************************************************************/
23 #include "base/i2-base.h"
24 #include "base/application.th"
25 #include "base/threadpool.h"
26 #include "base/dynamicobject.h"
33 * Abstract base class for applications.
37 class I2_BASE_API Application : public ObjectImpl<Application> {
39 DECLARE_PTR_TYPEDEFS(Application);
43 static Application::Ptr GetInstance(void);
48 * Starts the application.
50 * @returns The exit code of the application.
52 virtual int Main(void) = 0;
54 static int GetArgC(void);
55 static void SetArgC(int argc);
57 static char **GetArgV(void);
58 static void SetArgV(char **argv);
60 static void InstallExceptionHandlers(void);
62 static void RequestShutdown(void);
63 static void RequestRestart(void);
65 static void SetDebugging(bool debug);
66 static bool IsDebugging(void);
68 void UpdatePidFile(const String& filename);
69 void ClosePidFile(void);
71 static String GetExePath(const String& argv0);
73 static String GetPrefixDir(void);
74 static void DeclarePrefixDir(const String& path);
76 static String GetSysconfDir(void);
77 static void DeclareSysconfDir(const String& path);
79 static String GetLocalStateDir(void);
80 static void DeclareLocalStateDir(const String& path);
82 static String GetPkgDataDir(void);
83 static void DeclarePkgDataDir(const String& path);
85 static String GetStatePath(void);
86 static void DeclareStatePath(const String& path);
88 static String GetPidPath(void);
89 static void DeclarePidPath(const String& path);
91 static String GetApplicationType(void);
92 static void DeclareApplicationType(const String& type);
94 static void MakeVariablesConstant(void);
96 static ThreadPool& GetTP(void);
98 static String GetVersion(void);
100 static double GetStartTime(void);
101 static void SetStartTime(double ts);
104 virtual void OnConfigLoaded(void);
105 virtual void Stop(void);
107 void RunEventLoop(void) const;
109 virtual void OnShutdown(void);
112 static Application *m_Instance; /**< The application instance. */
114 static bool m_ShuttingDown; /**< Whether the application is in the process of
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;
124 static void SigIntTermHandler(int signum);
126 static BOOL WINAPI CtrlHandler(DWORD type);
127 static LONG WINAPI SEHUnhandledExceptionFilter(PEXCEPTION_POINTERS exi);
130 static void DisplayVersionMessage(void);
131 static void DisplayBugMessage(void);
133 static void SigAbrtHandler(int signum);
134 static void ExceptionHandler(void);
136 static void TimeWatchThreadProc(void);
137 static void NewTxTimerHandler(void);
142 #endif /* APPLICATION_H */