Main Page | Modules | Namespace List | Class Hierarchy | Alphabetical List | Compound List | File List | Namespace Members | Compound Members | File Members | Related Pages | Examples

psimpleapp.h

Go to the documentation of this file.
00001 /*
00002  *   P::Classes - Portable C++ Application Framework
00003  *   Copyright (C) 2000-2003  Christian Prochnow <cproch@seculogix.de>
00004  *
00005  *   This library is free software; you can redistribute it and/or
00006  *   modify it under the terms of the GNU Lesser General Public
00007  *   License as published by the Free Software Foundation; either
00008  *   version 2 of the License, or (at your option) any later version.
00009  *
00010  *   This library is distributed in the hope that it will be useful,
00011  *   but WITHOUT ANY WARRANTY; without even the implied warranty of
00012  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00013  *   Lesser General Public License for more details.
00014  *
00015  *   You should have received a copy of the GNU Lesser General Public
00016  *   License along with this library; if not, write to the Free Software
00017  *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
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

Generated on Fri Mar 12 21:08:31 2004 for P::Classes by doxygen 1.3.3