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  * $Log: svcproc.h,v $
00030  * Revision 1.26  2006/06/21 03:28:41  csoutheren
00031  * Various cleanups thanks for Frederic Heem
00032  *
00033  * Revision 1.25  2005/11/25 03:43:47  csoutheren
00034  * Fixed function argument comments to be compatible with Doxygen
00035  *
00036  * Revision 1.24  2003/09/17 05:41:59  csoutheren
00037  * Removed recursive includes
00038  *
00039  * Revision 1.23  2003/09/17 01:18:02  csoutheren
00040  * Removed recursive include file system and removed all references
00041  * to deprecated coooperative threading support
00042  *
00043  * Revision 1.22  2002/10/22 07:42:52  robertj
00044  * Added extra debugging for file handle and thread leak detection.
00045  *
00046  * Revision 1.21  2002/09/16 01:08:59  robertj
00047  * Added #define so can select if #pragma interface/implementation is used on
00048  *   platform basis (eg MacOS) rather than compiler, thanks Robert Monaghan.
00049  *
00050  * Revision 1.20  2002/01/26 23:55:55  craigs
00051  * Changed for GCC 3.0 compatibility, thanks to manty@manty.net
00052  *
00053  * Revision 1.19  2001/05/22 12:49:32  robertj
00054  * Did some seriously wierd rewrite of platform headers to eliminate the
00055  *   stupid GNU compiler warning about braces not matching.
00056  *
00057  * Revision 1.18  1999/09/21 08:20:16  robertj
00058  * Fixed name space problem with PSYSTEMLOG() macro.
00059  *
00060  * Revision 1.17  1999/09/13 13:15:06  robertj
00061  * Changed PTRACE so will output to system log in PServiceProcess applications.
00062  *
00063  * Revision 1.16  1999/03/09 02:59:51  robertj
00064  * Changed comments to doc++ compatible documentation.
00065  *
00066  * Revision 1.15  1999/02/16 08:11:17  robertj
00067  * MSVC 6.0 compatibility changes.
00068  *
00069  * Revision 1.14  1998/10/13 14:06:15  robertj
00070  * Complete rewrite of memory leak detection code.
00071  *
00072  * Revision 1.13  1998/09/23 06:21:31  robertj
00073  * Added open source copyright license.
00074  *
00075  * Revision 1.12  1998/04/07 13:33:21  robertj
00076  * Changed startup code to support PApplication class.
00077  *
00078  * Revision 1.11  1998/03/29 06:16:50  robertj
00079  * Rearranged initialisation sequence so PProcess descendent constructors can do "things".
00080  *
00081  * Revision 1.10  1998/02/16 00:13:16  robertj
00082  * Added tray icon support.
00083  *
00084  * Revision 1.9  1998/02/03 06:19:14  robertj
00085  * Added extra log levels.
00086  *
00087  * Revision 1.8  1997/07/08 13:02:32  robertj
00088  * DLL support.
00089  *
00090  * Revision 1.7  1997/02/05 11:51:15  robertj
00091  * Changed current process function to return reference and validate objects descendancy.
00092  *
00093  * Revision 1.6  1996/08/19 13:39:20  robertj
00094  * Added "Debug" level to system log.
00095  * Moved PSYSTEMLOG macro to common code.
00096  * Changed PSYSTEMLOG macro so does not execute << expression if below debug level.
00097  * Fixed memory leak in PSystemLog stream buffer.
00098  *
00099  * Revision 1.5  1996/08/17 10:00:27  robertj
00100  * Changes for Windows DLL support.
00101  *
00102  * Revision 1.4  1996/08/09 11:16:53  robertj
00103  * Moved log macro to platform dependent header.
00104  *
00105  * Revision 1.3  1996/07/30 12:24:13  robertj
00106  * Added SYSTEMLOG macro for GNU compiler compatibility.
00107  *
00108  * Revision 1.2  1996/07/27 04:10:06  robertj
00109  * Changed SystemLog to be stream based rather than printf based.
00110  *
00111  * Revision 1.1  1995/12/23 03:47:25  robertj
00112  * Initial revision
00113  *
00114  * Revision 1.3  1995/12/10 11:50:05  robertj
00115  * Numerous fixes for WIN32 service processes.
00116  *
00117  * Revision 1.2  1995/07/02 01:23:27  robertj
00118  * Set up service process to be in subthread not main thread.
00119  *
00120  * Revision 1.1  1995/06/17 00:50:54  robertj
00121  * Initial revision
00122  *
00123  */
00124 
00125 #ifndef _PSERVICEPROCESS
00126 #define _PSERVICEPROCESS
00127 
00128 #ifdef P_USE_PRAGMA
00129 #pragma interface
00130 #endif
00131 
00132 #include <ptlib/pprocess.h>
00133 
00138 class PSystemLog : public PObject, public iostream {
00139   PCLASSINFO(PSystemLog, PObject);
00140 
00141   public:
00144 
00145     enum Level {
00147       StdError = -1,
00149       Fatal,   
00151       Error,    
00153       Warning,  
00155       Info,     
00157       Debug,    
00159       Debug2,   
00161       Debug3,   
00163       Debug4,   
00165       Debug5,   
00167       Debug6,   
00168 
00169       NumLogLevels
00170     };
00171 
00173     PSystemLog(
00174      Level level   
00175     ) : iostream(cout.rdbuf()) { logLevel = level; buffer.log = this; init(&buffer); }
00176 
00178     ~PSystemLog() { flush(); }
00180 
00185     static void Output(
00186       Level level,      
00187       const char * msg  
00188     );
00190 
00196     void SetLevel(
00197       Level level  
00198     ) { logLevel = level; }
00199 
00205     Level GetLevel() const { return logLevel; }
00207 
00208   private:
00209     PSystemLog(const PSystemLog &) : iostream(cout.rdbuf()) { }
00210     PSystemLog & operator=(const PSystemLog &) { return *this; }
00211 
00212     class Buffer : public streambuf {
00213       public:
00214         virtual int overflow(int=EOF);
00215         virtual int underflow();
00216         virtual int sync();
00217         PSystemLog * log;
00218         PString string;
00219     } buffer;
00220     friend class Buffer;
00221 
00222     Level logLevel;
00223 };
00224 
00225 
00230 #define PSYSTEMLOG(level, variables) \
00231   if (PServiceProcess::Current().GetLogLevel() >= PSystemLog::level) { \
00232     PSystemLog P_systemlog(PSystemLog::level); \
00233     P_systemlog << variables; \
00234   } else (void)0
00235 
00236 
00237 
00241 class PServiceProcess : public PProcess
00242 {
00243   PCLASSINFO(PServiceProcess, PProcess);
00244 
00245   public:
00250     PServiceProcess(
00251       const char * manuf,   
00252       const char * name,    
00253       WORD majorVersion,    
00254       WORD minorVersion,    
00255       CodeStatus status,    
00256       WORD buildNumber      
00257     );
00259 
00269     virtual BOOL OnStart() = 0;
00270 
00275     virtual void OnStop();
00276 
00285     virtual BOOL OnPause();
00286 
00289     virtual void OnContinue();
00290 
00293     virtual void OnControl() = 0;
00295 
00303     static PServiceProcess & Current();
00304 
00305 
00315     void SetLogLevel(
00316       PSystemLog::Level level  
00317     ) { currentLogLevel = level; }
00318 
00324     PSystemLog::Level GetLogLevel() const { return currentLogLevel; }
00326 
00327 
00328     /* Internal initialisation function called directly from
00329        #main()#. The user should never call this function.
00330      */
00331     virtual int _main(void * arg = NULL);
00332 
00333 
00334   protected:
00335   // Member variables
00337     BOOL debugMode;
00338 
00340     PSystemLog::Level currentLogLevel;
00341 
00342     friend void PSystemLog::Output(PSystemLog::Level, const char *);
00343 
00344 
00345 // Include platform dependent part of class
00346 #ifdef _WIN32
00347 #include "msos/ptlib/svcproc.h"
00348 #else
00349 #include "unix/ptlib/svcproc.h"
00350 #endif
00351 };
00352 
00353 #endif
00354 
00355 
00356 // End Of File ///////////////////////////////////////////////////////////////

Generated on Fri Mar 7 06:25:03 2008 for PTLib by  doxygen 1.5.1