svcproc.h

Go to the documentation of this file.
00001 /*
00002  * svcproc.h
00003  *
00004  * Service Process (daemon) class.
00005  *
00006  * Portable Windows Library
00007  *
00008  * Copyright (c) 1993-1998 Equivalence Pty. Ltd.
00009  *
00010  * The contents of this file are subject to the Mozilla Public License
00011  * Version 1.0 (the "License"); you may not use this file except in
00012  * compliance with the License. You may obtain a copy of the License at
00013  * http://www.mozilla.org/MPL/
00014  *
00015  * Software distributed under the License is distributed on an "AS IS"
00016  * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
00017  * the License for the specific language governing rights and limitations
00018  * under the License.
00019  *
00020  * The Original Code is Portable Windows Library.
00021  *
00022  * The Initial Developer of the Original Code is Equivalence Pty. Ltd.
00023  *
00024  * Portions are Copyright (C) 1993 Free Software Foundation, Inc.
00025  * All Rights Reserved.
00026  *
00027  * Contributor(s): ______________________________________.
00028  *
00029  * $Revision: 21583 $
00030  * $Author: rjongbloed $
00031  * $Date: 2008-11-20 12:56:31 +0000 (Thu, 20 Nov 2008) $
00032  */
00033 
00034 #ifndef _PSERVICEPROCESS
00035 #define _PSERVICEPROCESS
00036 
00037 #ifdef P_USE_PRAGMA
00038 #pragma interface
00039 #endif
00040 
00041 #include <ptlib/pprocess.h>
00042 
00047 class PSystemLog : public PObject, public iostream {
00048   PCLASSINFO(PSystemLog, PObject);
00049 
00050   public:
00053 
00054     enum Level {
00056       StdError = -1,
00058       Fatal,   
00060       Error,    
00062       Warning,  
00064       Info,     
00066       Debug,    
00068       Debug2,   
00070       Debug3,   
00072       Debug4,   
00074       Debug5,   
00076       Debug6,   
00077 
00078       NumLogLevels
00079     };
00080 
00082     PSystemLog(
00083      Level level   
00084     );
00085 
00087     ~PSystemLog() { flush(); }
00089 
00094     static void Output(
00095       Level level,      
00096       const char * msg  
00097     );
00099 
00105     void SetLevel(
00106       Level level  
00107     ) { logLevel = level; }
00108 
00114     Level GetLevel() const { return logLevel; }
00116 
00117   private:
00118     PSystemLog(const PSystemLog & other);
00119     PSystemLog & operator=(const PSystemLog &);
00120 
00121     class Buffer : public streambuf {
00122       public:
00123         virtual int_type overflow(int=EOF);
00124         virtual int_type underflow();
00125         virtual int sync();
00126         PSystemLog * log;
00127         PString string;
00128     } buffer;
00129     friend class Buffer;
00130 
00131     Level logLevel;
00132 };
00133 
00134 
00139 #define PSYSTEMLOG(level, variables) \
00140   if (PServiceProcess::Current().GetLogLevel() >= PSystemLog::level) { \
00141     PSystemLog P_systemlog(PSystemLog::level); \
00142     P_systemlog << variables; \
00143   } else (void)0
00144 
00145 
00146 
00150 class PServiceProcess : public PProcess
00151 {
00152   PCLASSINFO(PServiceProcess, PProcess);
00153 
00154   public:
00159     PServiceProcess(
00160       const char * manuf,   
00161       const char * name,    
00162       WORD majorVersion,    
00163       WORD minorVersion,    
00164       CodeStatus status,    
00165       WORD buildNumber      
00166     );
00168 
00178     virtual PBoolean OnStart() = 0;
00179 
00184     virtual void OnStop();
00185 
00194     virtual PBoolean OnPause();
00195 
00198     virtual void OnContinue();
00199 
00202     virtual void OnControl() = 0;
00204 
00212     static PServiceProcess & Current();
00213 
00214 
00224     void SetLogLevel(
00225       PSystemLog::Level level  
00226     ) { currentLogLevel = level; }
00227 
00233     PSystemLog::Level GetLogLevel() const { return currentLogLevel; }
00235 
00236 
00237     /* Internal initialisation function called directly from
00238        #main()#. The user should never call this function.
00239      */
00240     virtual int _main(void * arg = NULL);
00241 
00242 
00243   protected:
00244   // Member variables
00246     PBoolean debugMode;
00247 
00249     PSystemLog::Level currentLogLevel;
00250 
00251     friend void PSystemLog::Output(PSystemLog::Level, const char *);
00252 
00253 
00254 // Include platform dependent part of class
00255 #ifdef _WIN32
00256 #include "msos/ptlib/svcproc.h"
00257 #else
00258 #include "unix/ptlib/svcproc.h"
00259 #endif
00260 };
00261 
00262 #endif
00263 
00264 
00265 // End Of File ///////////////////////////////////////////////////////////////

Generated on Mon Feb 23 01:57:54 2009 for PTLib by  doxygen 1.5.1