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 PTLIB_SERVICEPROCESS_H
00035 #define PTLIB_SERVICEPROCESS_H
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())
00085 , logLevel(level)
00086 {
00087 buffer.log = this;
00088 init(&buffer);
00089 }
00090
00092 ~PSystemLog() { flush(); }
00094
00099 static void Output(
00100 Level level,
00101 const char * msg
00102 );
00104
00110 void SetLevel(
00111 Level level
00112 ) { logLevel = level; }
00113
00119 Level GetLevel() const { return logLevel; }
00121
00122 private:
00123 PSystemLog(const PSystemLog & other) : PObject(other), iostream(cout.rdbuf()) { }
00124 PSystemLog & operator=(const PSystemLog &) { return *this; }
00125
00126 class Buffer : public streambuf {
00127 public:
00128 virtual int_type overflow(int=EOF);
00129 virtual int_type underflow();
00130 virtual int sync();
00131 PSystemLog * log;
00132 PString string;
00133 } buffer;
00134 friend class Buffer;
00135
00136 Level logLevel;
00137 };
00138
00139
00144 #define PSYSTEMLOG(level, variables) \
00145 if (PServiceProcess::Current().GetLogLevel() >= PSystemLog::level) { \
00146 PSystemLog P_systemlog(PSystemLog::level); \
00147 P_systemlog << variables; \
00148 } else (void)0
00149
00150
00151
00155 class PServiceProcess : public PProcess
00156 {
00157 PCLASSINFO(PServiceProcess, PProcess);
00158
00159 public:
00164 PServiceProcess(
00165 const char * manuf,
00166 const char * name,
00167 WORD majorVersion,
00168 WORD minorVersion,
00169 CodeStatus status,
00170 WORD buildNumber
00171 );
00173
00183 virtual PBoolean OnStart() = 0;
00184
00189 virtual void OnStop();
00190
00199 virtual PBoolean OnPause();
00200
00203 virtual void OnContinue();
00204
00207 virtual void OnControl() = 0;
00209
00217 static PServiceProcess & Current();
00218
00219
00229 void SetLogLevel(
00230 PSystemLog::Level level
00231 ) { currentLogLevel = level; }
00232
00238 PSystemLog::Level GetLogLevel() const { return currentLogLevel; }
00240
00241
00242
00243
00244
00245 virtual int InternalMain(void * arg = NULL);
00246
00247
00248 protected:
00249
00251 PBoolean debugMode;
00252
00254 PSystemLog::Level currentLogLevel;
00255
00256 friend void PSystemLog::Output(PSystemLog::Level, const char *);
00257
00258
00259
00260 #ifdef _WIN32
00261 #include "msos/ptlib/svcproc.h"
00262 #else
00263 #include "unix/ptlib/svcproc.h"
00264 #endif
00265 };
00266
00267
00268 #endif // PTLIB_SERVICEPROCESS_H
00269
00270
00271