cstool/csapplicationframework.h
Go to the documentation of this file.00001 /* 00002 Copyright (C) 2003 by Odes B. Boatwright. 00003 00004 This library is free software; you can redistribute it and/or 00005 modify it under the terms of the GNU Library General Public 00006 License as published by the Free Software Foundation; either 00007 version 2 of the License, or (at your option) any later version. 00008 00009 This library is distributed in the hope that it will be useful, 00010 but WITHOUT ANY WARRANTY; without even the implied warranty of 00011 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00012 Library General Public License for more details. 00013 00014 You should have received a copy of the GNU Library General Public 00015 License along with this library; if not, write to the Free 00016 Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 00017 */ 00018 00019 #ifndef __CS_CSAPPLICATIONFRAMEWORK_H__ 00020 #define __CS_CSAPPLICATIONFRAMEWORK_H__ 00021 00030 #include "csextern.h" 00031 00032 #include "cstool/initapp.h" 00033 #include "ivaria/reporter.h" 00034 00105 class CS_CRYSTALSPACE_EXPORT csApplicationFramework : public csInitializer 00106 { 00107 private: 00119 static csApplicationFramework* m_Ptr; 00120 00127 static const char* m_FoundationStringName; 00128 00135 static char* m_ApplicationStringName; 00136 00141 bool restartFlag; 00142 protected: 00152 csApplicationFramework (); 00153 00167 static bool Initialize (int argc, char* argv[]); 00168 00178 static bool Start (); 00179 00188 static void End (); 00189 public: 00193 virtual ~csApplicationFramework (); 00194 00202 static void Quit (); 00203 00204 protected: 00208 static iObjectRegistry* object_reg; 00209 00224 virtual bool OnInitialize (int argc, char* argv[]) = 0; 00225 00237 virtual bool Application () = 0; 00238 00247 virtual void OnExit (); 00248 00255 static bool SetupConfigManager (iObjectRegistry* object_reg, 00256 const char* configName) 00257 { 00258 return csInitializer::SetupConfigManager (object_reg, configName, 00259 GetApplicationName()); 00260 } 00261 public: 00262 // Inline Helper Functions 00266 static iObjectRegistry* GetObjectRegistry () { return object_reg; }; 00267 00276 operator iObjectRegistry* () { return object_reg; } 00277 00281 bool Open () { return OpenApplication (object_reg); } 00282 00298 static void SetApplicationName (char *name) 00299 { 00300 m_ApplicationStringName = name; 00301 } 00302 00309 static const char* GetApplicationName () 00310 { 00311 return m_ApplicationStringName ? m_ApplicationStringName : 00312 GetDefaultAppID(); 00313 } 00314 00320 static void Run () 00321 { 00322 csDefaultRunLoop (object_reg); 00323 } 00324 00330 void Restart(); 00331 private: 00339 static bool ReportLibError (const char* description, ...) 00340 { 00341 va_list args; 00342 va_start (args, description); 00343 csReportV (object_reg, CS_REPORTER_SEVERITY_ERROR, 00344 m_FoundationStringName, 00345 description, args); 00346 va_end (args); 00347 return false; 00348 } 00349 00350 public: 00358 static bool ReportError (const char* description, ...) 00359 { 00360 va_list args; 00361 va_start (args, description); 00362 csReportV (object_reg, CS_REPORTER_SEVERITY_ERROR, 00363 GetApplicationName(), 00364 description, args); 00365 va_end (args); 00366 return false; 00367 } 00368 00376 static void ReportWarning (const char* description, ...) 00377 { 00378 va_list args; 00379 va_start (args, description); 00380 csReportV (object_reg, CS_REPORTER_SEVERITY_WARNING, 00381 GetApplicationName(), 00382 description, args); 00383 va_end (args); 00384 } 00385 00393 static void ReportInfo (const char* description, ...) 00394 { 00395 va_list args; 00396 va_start (args, description); 00397 csReportV (object_reg, CS_REPORTER_SEVERITY_NOTIFY, 00398 GetApplicationName(), 00399 description, args); 00400 va_end (args); 00401 } 00402 00412 int Main (int argc, char* argv[]); 00413 00415 bool DoRestart(); 00416 }; 00417 00421 template <class T> 00422 class csApplicationRunner 00423 { 00424 public: 00426 static int Run (int argc, char* argv[]) 00427 { 00428 int result; 00429 bool again; 00430 do 00431 { 00432 T app; 00433 result = app.Main (argc, argv); 00434 again = app.DoRestart(); 00435 } 00436 while (again); 00437 return result; 00438 } 00439 }; 00440 00443 #endif //__CS_CSAPPLICATIONFRAMEWORK_H__
Generated for Crystal Space by doxygen 1.4.6