00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
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 ) : iostream(cout.rdbuf()) { logLevel = level; buffer.log = this; init(&buffer); }
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 &) : iostream(cout.rdbuf()) { }
00119 PSystemLog & operator=(const PSystemLog &) { return *this; }
00120
00121 class Buffer : public streambuf {
00122 public:
00123 virtual int overflow(int=EOF);
00124 virtual int 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
00238
00239
00240 virtual int _main(void * arg = NULL);
00241
00242
00243 protected:
00244
00246 PBoolean debugMode;
00247
00249 PSystemLog::Level currentLogLevel;
00250
00251 friend void PSystemLog::Output(PSystemLog::Level, const char *);
00252
00253
00254
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