00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #ifndef _psimpleapp_h_
00021 #define _psimpleapp_h_
00022
00023 #include <pclasses/config.h>
00024 #include <pclasses/pexport.h>
00025 #include <pclasses/paboutdata.h>
00026 #include <pclasses/psemaphore.h>
00027
00028 #ifndef WIN32
00029
00030 #define P_IMPLEMENT_MAIN(cl) \
00031 int main(int argc, char* argv[]) \
00032 { \
00033 cl app; \
00034 return app.run(argc, argv); \
00035 }
00036
00037 #else
00038
00039 #define P_IMPLEMENT_MAIN(cl) \
00040 int main(int argc, char* argv[]) \
00041 { \
00042 cl app; \
00043 return app.run(argc, argv); \
00044 }
00045
00046 #endif
00047
00048 namespace P {
00049
00051
00055 class PCORE_EXPORT SimpleApp {
00056 public:
00058
00062 SimpleApp(const AboutData& about);
00063 virtual ~SimpleApp();
00064
00066
00073 int run(int argc, char* argv[]);
00074
00076
00081 void stop(int code);
00082
00084 virtual void terminate(int signal);
00085
00087 const AboutData& about() const throw()
00088 { return m_about; }
00089
00091 PCORE_EXPORT friend SimpleApp* theApp() throw();
00092
00093 protected:
00095
00102 virtual int init(int argc, char* argv[]);
00103
00105
00112 virtual int main();
00113
00115
00119 virtual void cleanup() {}
00120
00122 static RETSIGTYPE SIGTERM_handler(int);
00123
00125 Semaphore& exitSem()
00126 { return m_exitSem; }
00127
00129 inline int exitCode() const
00130 { return m_exitCode; }
00131
00132 private:
00133 SimpleApp(const SimpleApp&);
00134 SimpleApp& operator=(const SimpleApp&);
00135
00136 Semaphore m_exitSem;
00137 int m_exitCode;
00138 const AboutData& m_about;
00139 static SimpleApp* m_theApp;
00140 };
00141
00142 }
00143
00144 #endif