Version: 0.6.0
init.h
1 /******************************************************************************
2  * Project: wxGIS
3  * Purpose: Initializer class for logs, locale, libs and etc.
4  * Author: Dmitry Baryshnikov (aka Bishop), polimax@mail.ru
5  ******************************************************************************
6 * Copyright (C) 2010-2012,2014 Dmitry Baryshnikov
7 *
8 * This program is free software: you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation, either version 2 of the License, or
11 * (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program. If not, see <http://www.gnu.org/licenses/>.
20  ****************************************************************************/
21 #pragma once
22 
23 #include "wxgis/core/core.h"
24 #include "wxgis/core/app.h"
25 #include "wxgis/core/config.h"
26 
27 #include <wx/dir.h>
28 #include <wx/filename.h>
29 #include <wx/file.h>
30 #include <wx/ffile.h>
31 #include <wx/datetime.h>
32 #include <wx/intl.h>
33 #include <wx/dynload.h>
34 #include <wx/dynlib.h>
35 #include <wx/cmdline.h>
36 
44 class WXDLLIMPEXP_GIS_CORE wxGISAppWithLibs
45 {
46 public:
47  wxGISAppWithLibs(void);
48  virtual ~wxGISAppWithLibs(void);
49  typedef std::map<wxString, wxDynamicLibrary*> LIBMAP;
50  virtual void LoadLib(const wxString &sPath, bool bStore = true);
51 protected:
52  virtual void LoadLibs(const wxXmlNode* pRootNode);
53  virtual void SerializeLibs();
54  virtual void UnLoadLibs();
55 protected:
56  wxArrayString m_asNoStore;
57  LIBMAP m_LibMap;
58 };
59 
81 class WXDLLIMPEXP_GIS_CORE wxGISInitializer :
82  public wxGISAppWithLibs,
83  public IApplication
84 {
85 public:
86  wxGISInitializer(void);
87  virtual ~wxGISInitializer(void);
88  virtual bool Initialize(const wxString &sAppName, const wxString &sLogFilePrefix);
89  virtual void Uninitialize();
90  // IApplication
91  virtual bool SetupSys(const wxString &sSysPath);
92  virtual void SetDebugMode(bool bDebugMode);
93  virtual bool SetupLog(const wxString &sLogPath, const wxString &sNamePrefix);
94  virtual bool SetupLoc(const wxString &sLoc, const wxString &sLocPath);
95  virtual wxString GetDecimalPoint(void) const{return m_sDecimalPoint;};
96  virtual bool CreateApp(void) {return true;};
97 protected:
98  wxLocale* m_pLocale; // locale we'll be using
99  wxFFile m_LogFile;
100  wxString m_sDecimalPoint;
101 };
102 
103 // Log levels
104 enum
105 {
106  LOG_ERROR = 0,
107  LOG_WARNING,
108  LOG_DEBUG,
109  // NOTE:
110  // "STARTUP" will be used to log messages for any LogLevel
111  // Use it for logging database connection errors which we
112  // don't want to abort the whole shebang.
113  LOG_STARTUP = 15
114 };
115 
122 class WXDLLIMPEXP_GIS_CORE wxGISService
123 {
124 public:
125  wxGISService(void);
126  virtual ~wxGISService(void);
127  virtual void LogMessage(wxString msg, int level);
128 #ifdef _WIN32
129  static void WINAPI ServiceMain(DWORD dwArgc, LPTSTR* lpszArgv);
130  static void WINAPI Handler(DWORD dwOpcode);
131  virtual bool IsInstalled();
132  virtual bool Install(const wxString &args, const wxString &user = wxEmptyString, const wxString &password = wxEmptyString);
133  virtual bool Uninstall();
134  virtual void Run() = 0;
135  virtual bool Initialize() = 0;
136  virtual void OnStop();
137  virtual void OnPause();
138  virtual void OnContinue();
139  virtual void OnInterrogate();
140  virtual void OnShutdown();
141 #else //_WIN32
142  virtual void Daemonize(void);
143 #endif //_WIN32
144 protected:
145 #ifdef _WIN32
146  virtual bool StartService();
147  virtual void SetStatus(DWORD dwState);
148 #else //_WIN32
149 #endif //_WIN32
150 protected:
151  int m_nMinLogLevel;
152  wxString m_sServiceName;
153  wxString m_sServiceDisplayName;
154  bool m_bServiceIsRunning;
155 #ifdef _WIN32
156  SERVICE_STATUS m_ServiceStatus;
157  SERVICE_STATUS_HANDLE m_hServiceStatusHandle;
158  HANDLE m_hEventSource;
159 #else
160  int m_hEventSource;
161 #endif //_WIN32
162  static wxGISService* m_pThis;
163 };
Definition: init.h:44
Definition: app.h:32