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.25  2005/11/25 03:43:47  csoutheren
00031  * Fixed function argument comments to be compatible with Doxygen
00032  *
00033  * Revision 1.24  2003/09/17 05:41:59  csoutheren
00034  * Removed recursive includes
00035  *
00036  * Revision 1.23  2003/09/17 01:18:02  csoutheren
00037  * Removed recursive include file system and removed all references
00038  * to deprecated coooperative threading support
00039  *
00040  * Revision 1.22  2002/10/22 07:42:52  robertj
00041  * Added extra debugging for file handle and thread leak detection.
00042  *
00043  * Revision 1.21  2002/09/16 01:08:59  robertj
00044  * Added #define so can select if #pragma interface/implementation is used on
00045  *   platform basis (eg MacOS) rather than compiler, thanks Robert Monaghan.
00046  *
00047  * Revision 1.20  2002/01/26 23:55:55  craigs
00048  * Changed for GCC 3.0 compatibility, thanks to manty@manty.net
00049  *
00050  * Revision 1.19  2001/05/22 12:49:32  robertj
00051  * Did some seriously wierd rewrite of platform headers to eliminate the
00052  *   stupid GNU compiler warning about braces not matching.
00053  *
00054  * Revision 1.18  1999/09/21 08:20:16  robertj
00055  * Fixed name space problem with PSYSTEMLOG() macro.
00056  *
00057  * Revision 1.17  1999/09/13 13:15:06  robertj
00058  * Changed PTRACE so will output to system log in PServiceProcess applications.
00059  *
00060  * Revision 1.16  1999/03/09 02:59:51  robertj
00061  * Changed comments to doc++ compatible documentation.
00062  *
00063  * Revision 1.15  1999/02/16 08:11:17  robertj
00064  * MSVC 6.0 compatibility changes.
00065  *
00066  * Revision 1.14  1998/10/13 14:06:15  robertj
00067  * Complete rewrite of memory leak detection code.
00068  *
00069  * Revision 1.13  1998/09/23 06:21:31  robertj
00070  * Added open source copyright license.
00071  *
00072  * Revision 1.12  1998/04/07 13:33:21  robertj
00073  * Changed startup code to support PApplication class.
00074  *
00075  * Revision 1.11  1998/03/29 06:16:50  robertj
00076  * Rearranged initialisation sequence so PProcess descendent constructors can do "things".
00077  *
00078  * Revision 1.10  1998/02/16 00:13:16  robertj
00079  * Added tray icon support.
00080  *
00081  * Revision 1.9  1998/02/03 06:19:14  robertj
00082  * Added extra log levels.
00083  *
00084  * Revision 1.8  1997/07/08 13:02:32  robertj
00085  * DLL support.
00086  *
00087  * Revision 1.7  1997/02/05 11:51:15  robertj
00088  * Changed current process function to return reference and validate objects descendancy.
00089  *
00090  * Revision 1.6  1996/08/19 13:39:20  robertj
00091  * Added "Debug" level to system log.
00092  * Moved PSYSTEMLOG macro to common code.
00093  * Changed PSYSTEMLOG macro so does not execute << expression if below debug level.
00094  * Fixed memory leak in PSystemLog stream buffer.
00095  *
00096  * Revision 1.5  1996/08/17 10:00:27  robertj
00097  * Changes for Windows DLL support.
00098  *
00099  * Revision 1.4  1996/08/09 11:16:53  robertj
00100  * Moved log macro to platform dependent header.
00101  *
00102  * Revision 1.3  1996/07/30 12:24:13  robertj
00103  * Added SYSTEMLOG macro for GNU compiler compatibility.
00104  *
00105  * Revision 1.2  1996/07/27 04:10:06  robertj
00106  * Changed SystemLog to be stream based rather than printf based.
00107  *
00108  * Revision 1.1  1995/12/23 03:47:25  robertj
00109  * Initial revision
00110  *
00111  * Revision 1.3  1995/12/10 11:50:05  robertj
00112  * Numerous fixes for WIN32 service processes.
00113  *
00114  * Revision 1.2  1995/07/02 01:23:27  robertj
00115  * Set up service process to be in subthread not main thread.
00116  *
00117  * Revision 1.1  1995/06/17 00:50:54  robertj
00118  * Initial revision
00119  *
00120  */
00121 
00122 #ifndef _PSERVICEPROCESS
00123 #define _PSERVICEPROCESS
00124 
00125 #ifdef P_USE_PRAGMA
00126 #pragma interface
00127 #endif
00128 
00133 class PSystemLog : public PObject, public iostream {
00134   PCLASSINFO(PSystemLog, PObject);
00135 
00136   public:
00139 
00140     enum Level {
00142       StdError = -1,
00144       Fatal,   
00146       Error,    
00148       Warning,  
00150       Info,     
00152       Debug,    
00154       Debug2,   
00156       Debug3,   
00158       Debug4,   
00160       Debug5,   
00162       Debug6,   
00163 
00164       NumLogLevels
00165     };
00166 
00168     PSystemLog(
00169      Level level   
00170     ) : iostream(cout.rdbuf()) { logLevel = level; buffer.log = this; init(&buffer); }
00171 
00173     ~PSystemLog() { flush(); }
00175 
00180     static void Output(
00181       Level level,      
00182       const char * msg  
00183     );
00185 
00191     void SetLevel(
00192       Level level  
00193     ) { logLevel = level; }
00194 
00200     Level GetLevel() const { return logLevel; }
00202 
00203   private:
00204     PSystemLog(const PSystemLog &) : iostream(cout.rdbuf()) { }
00205     PSystemLog & operator=(const PSystemLog &) { return *this; }
00206 
00207     class Buffer : public streambuf {
00208       public:
00209         virtual int overflow(int=EOF);
00210         virtual int underflow();
00211         virtual int sync();
00212         PSystemLog * log;
00213         PString string;
00214     } buffer;
00215     friend class Buffer;
00216 
00217     Level logLevel;
00218 };
00219 
00220 
00225 #define PSYSTEMLOG(level, variables) \
00226   if (PServiceProcess::Current().GetLogLevel() >= PSystemLog::level) { \
00227     PSystemLog P_systemlog(PSystemLog::level); \
00228     P_systemlog << variables; \
00229   } else (void)0
00230 
00231 
00232 
00236 class PServiceProcess : public PProcess
00237 {
00238   PCLASSINFO(PServiceProcess, PProcess);
00239 
00240   public:
00245     PServiceProcess(
00246       const char * manuf,   
00247       const char * name,    
00248       WORD majorVersion,    
00249       WORD minorVersion,    
00250       CodeStatus status,    
00251       WORD buildNumber      
00252     );
00254 
00264     virtual BOOL OnStart() = 0;
00265 
00270     virtual void OnStop();
00271 
00280     virtual BOOL OnPause();
00281 
00284     virtual void OnContinue();
00285 
00288     virtual void OnControl() = 0;
00290 
00298     static PServiceProcess & Current();
00299 
00300 
00310     void SetLogLevel(
00311       PSystemLog::Level level  
00312     ) { currentLogLevel = level; }
00313 
00319     PSystemLog::Level GetLogLevel() const { return currentLogLevel; }
00321 
00322 
00323     /* Internal initialisation function called directly from
00324        #main()#. The user should never call this function.
00325      */
00326     virtual int _main(void * arg = NULL);
00327 
00328 
00329   protected:
00330   // Member variables
00332     BOOL debugMode;
00333 
00335     PSystemLog::Level currentLogLevel;
00336 
00337     friend void PSystemLog::Output(PSystemLog::Level, const char *);
00338 
00339 
00340 // Include platform dependent part of class
00341 #ifdef _WIN32
00342 #include "msos/ptlib/svcproc.h"
00343 #else
00344 #include "unix/ptlib/svcproc.h"
00345 #endif
00346 };
00347 
00348 #endif
00349 
00350 
00351 // End Of File ///////////////////////////////////////////////////////////////

Generated on Fri Sep 21 14:40:11 2007 for PWLib by  doxygen 1.5.3