00001 #ifndef __SYSTEM_H_INCLUDDED__ 00002 #define __SYSTEM_H_INCLUDDED__ 1 00003 00004 #include <stdio.h> 00005 #include <stdarg.h> 00006 #include <time.h> 00007 #include <assert.h> 00008 #include "platform.hh" 00009 00010 class CriticalSection 00011 { 00012 public: 00013 CriticalSection(); 00014 virtual ~CriticalSection(); 00015 void enter(); 00016 void leave(); 00017 00018 private: 00019 const void * const implData; 00020 }; 00021 00022 class LIFOCriticalSection 00023 { 00024 public: 00025 LIFOCriticalSection(); 00026 virtual ~LIFOCriticalSection(); 00027 void enter(); 00028 void leave(); 00029 private: 00030 const void * const implData; 00031 }; 00032 00033 class LIFOSemaphore 00034 { 00035 public: 00036 LIFOSemaphore(unsigned long initCount=0L); 00037 virtual ~LIFOSemaphore(); 00038 void release(unsigned long relCount=1); 00039 void wait(unsigned long timeoutMillisec = 0xFFFFFFFF); 00040 private: 00041 const void * const implData; 00042 }; 00043 00044 class System 00045 { 00046 System() {} // static object - no construction 00047 static CriticalSection *systemCS; 00048 public: 00049 // 00050 // Prints a formatted string to debugger out window for Win32/stdout for unix 00051 // (use DbgView under win32 if not running under debugger) 00052 // 00053 static void vdebugPrint(const char *format, va_list args); 00054 static void debugPrint(const char *format, ...); 00055 static const char *strptime(const char *buf, const char *format, tm *tm); 00056 static long getLastOSErrorCode(); 00057 static void displayErrorMessage( const char *title, const char *message ); 00058 static unsigned long getOSTimeSeconds(); 00059 00060 static void yieldThread(); 00061 static void sleep( unsigned long milliseconds ); 00062 00063 static void atomicIncrement( volatile unsigned long &v, CriticalSection *varCS = systemCS ); 00064 static void atomicDecrement( volatile unsigned long &v, CriticalSection *varCS = systemCS ); 00065 00066 static int initializeSockets(); 00067 static void cleanupSockets(); 00068 static int closeSocket(SOCKET s); 00069 static SOCKET accept( SOCKET s, struct sockaddr *addr, int *addrlen ); 00070 00071 static CriticalSection *createCriticalSection() 00072 { return new CriticalSection(); } 00073 00074 static LIFOCriticalSection *createLIFOCriticalSection() 00075 { return new LIFOCriticalSection(); } 00076 00077 static LIFOSemaphore *createLIFOSemaphore(unsigned long initCount=0L) 00078 { return new LIFOSemaphore(initCount); } 00079 00080 }; 00081 #endif // #ifndef __SYSTEM_H_INCLUDDED__ 00082
1.5.5