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 _PPROCESS
00035 #define _PPROCESS
00036
00037 #ifdef P_USE_PRAGMA
00038 #pragma interface
00039 #endif
00040
00041 #include <ptlib/mutex.h>
00042 #include <ptlib/syncpoint.h>
00043 #include <ptlib/thread.h>
00044 #include <ptlib/pfactory.h>
00045
00052 #ifdef P_VXWORKS
00053 #define PCREATE_PROCESS(cls) \
00054 PProcess::PreInitialise(0, NULL, NULL); \
00055 cls instance; \
00056 instance._main();
00057 #elif defined(P_RTEMS)
00058 #define PCREATE_PROCESS(cls) \
00059 extern "C" {\
00060 void* POSIX_Init( void* argument) \
00061 { PProcess::PreInitialise(0, 0, 0); \
00062 static cls instance; \
00063 exit( instance._main() ); \
00064 } \
00065 }
00066 #elif defined(_WIN32_WCE)
00067 #define PCREATE_PROCESS(cls) \
00068 int WinMain(HINSTANCE, HINSTANCE, LPWSTR, int) \
00069 { cls *pInstance = new cls(); \
00070 int terminationValue = pInstance->_main(); \
00071 delete pInstance; \
00072 return terminationValue; \
00073 }
00074 #else
00075 #define PCREATE_PROCESS(cls) \
00076 int main(int argc, char ** argv, char ** envp) \
00077 { PProcess::PreInitialise(argc, argv, envp); \
00078 cls *pInstance = new cls(); \
00079 int terminationValue = pInstance->_main(); \
00080 delete pInstance; \
00081 return terminationValue; \
00082 }
00083 #endif // P_VXWORKS
00084
00085
00086
00087
00088
00089
00090
00091 #define PDECLARE_PROCESS(cls,ancestor,manuf,name,major,minor,status,build) \
00092 class cls : public ancestor { \
00093 PCLASSINFO(cls, ancestor); \
00094 public: \
00095 cls() : ancestor(manuf, name, major, minor, status, build) { } \
00096 private: \
00097 virtual void Main(); \
00098 };
00099
00100
00101 PLIST(PInternalTimerList, PTimer);
00102
00103 class PTimerList : PInternalTimerList
00104
00105
00106
00107
00108
00109
00110 {
00111 PCLASSINFO(PTimerList, PInternalTimerList);
00112
00113 public:
00114 PTimerList();
00115
00116
00117 PTimeInterval Process();
00118
00119
00120
00121
00122
00123
00124
00125
00126
00127
00128
00129
00130
00131 private:
00132 PMutex listMutex, processingMutex, inTimeoutMutex;
00133
00134
00135 PTimeInterval lastSample;
00136
00137
00138 PTimer * currentTimer;
00139
00140
00141 friend class PTimer;
00142 };
00143
00144
00146
00147
00160 class PProcess : public PThread
00161 {
00162 PCLASSINFO(PProcess, PThread);
00163
00164 public:
00167
00168 enum CodeStatus {
00170 AlphaCode,
00172 BetaCode,
00174 ReleaseCode,
00175 NumCodeStatuses
00176 };
00177
00180 PProcess(
00181 const char * manuf = "",
00182 const char * name = "",
00183 WORD majorVersion = 1,
00184 WORD minorVersion = 0,
00185 CodeStatus status = ReleaseCode,
00186 WORD buildNumber = 1
00187 );
00189
00198 Comparison Compare(
00199 const PObject & obj
00200 ) const;
00202
00207 virtual void Terminate();
00208
00214 virtual PString GetThreadName() const;
00215
00221 virtual void SetThreadName(
00222 const PString & name
00223 );
00225
00234 static PProcess & Current();
00235
00239 virtual void OnThreadStart(
00240 PThread & thread
00241 );
00242
00246 virtual void OnThreadEnded(
00247 PThread & thread
00248 );
00249
00256 static PBoolean IsInitialised();
00257
00264 void SetTerminationValue(
00265 int value
00266 );
00267
00277 int GetTerminationValue() const;
00278
00285 PArgList & GetArguments();
00286
00296 virtual const PString & GetManufacturer() const;
00297
00307 virtual const PString & GetName() const;
00308
00323 virtual PString GetVersion(
00324 PBoolean full = PTrue
00325 ) const;
00326
00332 const PFilePath & GetFile() const;
00333
00341 DWORD GetProcessID() const;
00342
00345 PTime GetStartTime() const;
00346
00355 PString GetUserName() const;
00356
00379 PBoolean SetUserName(
00380 const PString & username,
00381 PBoolean permanent = PFalse
00382 );
00383
00392 PString GetGroupName() const;
00393
00418 PBoolean SetGroupName(
00419 const PString & groupname,
00420 PBoolean permanent = PFalse
00421 );
00422
00429 int GetMaxHandles() const;
00430
00440 PBoolean SetMaxHandles(
00441 int newLimit
00442 );
00443
00444 #ifdef P_CONFIG_FILE
00445
00447 virtual PString GetConfigurationFile();
00448 #endif
00449
00463 void SetConfigurationPath(
00464 const PString & path
00465 );
00467
00476 static PString GetOSClass();
00477
00484 static PString GetOSName();
00485
00491 static PString GetOSHardware();
00492
00499 static PString GetOSVersion();
00500
00508 static PDirectory GetOSConfigDir();
00510
00517 PTimerList * GetTimerList();
00518
00522 static void PreInitialise(
00523 int argc,
00524 char ** argv,
00525 char ** envp
00526 );
00527
00531 static void PreShutdown();
00532
00534 virtual int _main(void * arg = NULL);
00535
00536 private:
00537 void Construct();
00538
00539
00540 static int p_argc;
00541 static char ** p_argv;
00542 static char ** p_envp;
00543
00544
00545 int terminationValue;
00546
00547
00548 PString manufacturer;
00549
00550
00551 PString productName;
00552
00553
00554 WORD majorVersion;
00555
00556
00557 WORD minorVersion;
00558
00559
00560 CodeStatus status;
00561
00562
00563 WORD buildNumber;
00564
00565
00566 PFilePath executableFile;
00567
00568
00569 PStringList configurationPaths;
00570
00571
00572 PArgList arguments;
00573
00574
00575 PTimerList timers;
00576
00577
00578 PTime programStartTime;
00579
00580
00581 int maxHandles;
00582
00583
00584
00585 friend class PThread;
00586
00587
00588
00589 #ifdef _WIN32
00590 #include "msos/ptlib/pprocess.h"
00591 #else
00592 #include "unix/ptlib/pprocess.h"
00593 #endif
00594 };
00595
00596
00597
00598
00599
00600
00601
00602
00603 class PProcessStartup : public PObject
00604 {
00605 PCLASSINFO(PProcessStartup, PObject)
00606 public:
00607 virtual void OnStartup() { }
00608 virtual void OnShutdown() { }
00609 };
00610
00611 typedef PFactory<PProcessStartup> PProcessStartupFactory;
00612
00613
00614 #define P_DEFAULT_TRACE_OPTIONS ( PTrace::Blocks | PTrace::Timestamp | PTrace::Thread | PTrace::FileAndLine )
00615
00616 template <unsigned _level, unsigned _options = P_DEFAULT_TRACE_OPTIONS >
00617 class PTraceLevelSetStartup : public PProcessStartup
00618 {
00619 public:
00620 void OnStartup()
00621 { PTrace::Initialise(_level, NULL, _options); }
00622 };
00623
00624 #endif
00625
00626