core.h

Go to the documentation of this file.
00001 /* Core module.
00002  *
00003  * PegSoft modules subsystem library (c) 2005 PegSoft
00004  * Contact us at pegsoft@pegsoft.net
00005  *
00006  * This program is free software; you can redistribute it and/or modify
00007  * it under the terms of the GNU General Public License version 2 as
00008  * published by the Free Software Foundation.
00009  *
00010  * This program is distributed in the hope that it will be useful, but
00011  * WITHOUT ANY WARRANTY; without even the implied warranty of
00012  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00013  * General Public License for more details.
00014  *
00015  * You should have received a copy of the GNU General Public License
00016  * along with this software (the COPYING file); if not, write to the
00017  * Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139,
00018  * USA.
00019  *
00020  */
00021 
00027 #ifndef MODULES_CORE_H
00028 #define MODULES_CORE_H
00029 
00030 /*************************************************************************/
00031 
00032 #include <string>
00033 
00034 #include <modules/module.h>
00035 
00036 /*************************************************************************/
00037 
00038 namespace cmdline { class CmdLineParser; }
00039 namespace conf { class ConfLogger; }
00040 namespace xlog { class Logger; class LogLevel; }
00041 namespace scheduler { class Scheduler; }
00042 
00043 /*************************************************************************/
00044 
00046 
00047 namespace modules
00048 {
00049 
00050 /*************************************************************************/
00051 
00052 class ModManager;
00053 
00054 /*************************************************************************/
00055 
00057 
00069 class Core : public Module
00070 {
00071     public:
00073         Core();
00074     
00076 
00084         virtual void fatal(char const *msg = 0) = 0;
00085         
00087         void fatalf(char const *msg, ...) FORMAT(printf,2,3);
00088         
00090 
00098         void log(xlog::LogLevel const &level, char const *format, ...)
00099                 FORMAT(printf, 3, 4);
00100         
00102 
00112         void log_perror(xlog::LogLevel const &level,
00113                 char const *format, ...) FORMAT(printf, 3, 4);
00114         
00116 
00118         enum
00119         {
00121             sfReload =  0x00000001,
00123             sfSync =    0x00000002,
00125             sfRestart = 0x00000004,
00127             sfStop =    0x00000008,
00129             sfFatal =   0x00000010
00130         };
00131         
00133 
00148         virtual void schedule(unsigned int action) { m_action |= action; }
00149         
00151 
00161         virtual cmdline::CmdLineParser &clp() = 0;
00162         
00164 
00167         virtual conf::ConfLogger &conf_logger() = 0;
00168         
00170 
00175         virtual unsigned int debuglevel() const { return m_debuglevel; }
00177 
00181         virtual unsigned int debuglevel(unsigned int lev)
00182                 { return (m_debuglevel = lev); }
00183         
00185 
00187         static int const exitmsg_size = 256;
00189 
00192         char exitmsg[exitmsg_size];
00193         
00195 
00197         enum
00198         {
00200             pfForeground = 0x00000001,
00202             pfBackground = 0x00000002,
00204             pfConfigured = 0x00000004,
00206             pfReadOnly   = 0x00000008,
00208             pfQuiet      = 0x00000010,
00210             pfVeryQuiet  = 0x00000020
00211         };
00212         
00214 
00221         virtual unsigned int flags() const { return m_flags; }
00223 
00231         virtual unsigned int flags_add(unsigned int flg)
00232                 { return (m_flags |= flg); }
00234 
00242         virtual unsigned int flags_remove(unsigned int flg)
00243                 { return (m_flags &= ~flg); }
00244         
00246 
00250         virtual xlog::Logger &logger() = 0;
00251         
00253 
00257         virtual ModManager &modules() = 0; 
00258         
00260 
00263         virtual bool started() const { return m_started; }
00265 
00267         virtual time_t start_time() const { return m_starttime; }
00268         
00270 
00275         virtual scheduler::Scheduler &tasks() = 0;
00276         
00278 
00280         virtual std::string const version_string() const = 0;
00281     protected:
00283         unsigned int m_action;
00285         unsigned int m_debuglevel;
00287         unsigned int m_flags;
00288         
00290         bool m_started;
00292         time_t m_starttime;
00293 };
00294 
00295 /*************************************************************************/
00296 
00297 } /* namespace modules */
00298 
00299 /*************************************************************************/
00300 
00301 #endif /* MODULES_CORE_H */

Generated on Sun May 20 21:32:13 2007 for Epona API by  doxygen 1.4.6