00001 /*************************************************************************** 00002 LOW_platformMisc.h - description 00003 ------------------- 00004 begin : Thu Aug 1 2002 00005 copyright : (C) 2002 by Harald Roelle 00006 email : roelle@informatik.uni-muenchen.de 00007 ***************************************************************************/ 00008 00009 /*************************************************************************** 00010 * * 00011 * This program is free software; you can redistribute it and/or modify * 00012 * it under the terms of the GNU General Public License as published by * 00013 * the Free Software Foundation; either version 2 of the License, or * 00014 * (at your option) any later version. * 00015 * * 00016 ***************************************************************************/ 00017 00018 #ifndef LOW_PLATFORMMISC_H 00019 #define LOW_PLATFORMMISC_H 00020 00021 00022 #include "LOW_exception.h" 00023 #include "LOW_platformMiscFactory.h" 00024 00025 00026 /** Abstract base class for simple opering system dependent functions. 00027 00028 The methods are accessed via the public and static access functions. 00029 This class itself takes care of creating an appropiate instance. 00030 00031 Specific platforms dereive their implementation classes from this class. 00032 00033 The instances are created by LOW_platformMiscFactory, following the factory 00034 design pattern. 00035 00036 <B>Note:</B> There is no prescribed constructor. A class deriving from this 00037 one should only provide the default constructor.<BR> 00038 00039 This class is thread-safe. 00040 00041 @see LOW_platformMiscFactory 00042 00043 @author Harald Roelle 00044 */ 00045 class LOW_platformMisc { 00046 00047 //======================================================================================= 00048 public: 00049 00050 //===================================================================================== 00051 // 00052 // exceptions 00053 // 00054 00055 /** Exception base class for all exceptions thrown by LOW_platformMisc. */ 00056 class_DERIVE_FROM_EXCEPTION( platformMisc_error, LOW_exception); 00057 00058 00059 //===================================================================================== 00060 // 00061 // type definitions 00062 // 00063 00064 /** Data structure for timestamps. */ 00065 typedef struct timestamp_t { 00066 long sec; 00067 int milSec; 00068 } timestamp_t; 00069 00070 00071 00072 //===================================================================================== 00073 // 00074 // static methods 00075 // 00076 00077 /** Sleep for a specified number of seconds. 00078 @param inSeconds Number of seconds to sleep. 00079 */ 00080 static const void secSleep( const unsigned int inSeconds); 00081 00082 /** Sleep for a specified number of milli seconds. 00083 @param inMilliSeconds Number of milli seconds to sleep. 00084 */ 00085 static const void milliSleep( const unsigned long inMilliSeconds); 00086 00087 /** Sleep for a specified number of micro seconds. 00088 @param inMicroSeconds Number of micro seconds to sleep. 00089 */ 00090 static const void microSleep( const unsigned long inMicroSeconds); 00091 00092 /** Sleep for a specified number of nano seconds. 00093 @param inNanoSeconds Number of nano seconds to sleep. 00094 */ 00095 static const void nanoSleep( const unsigned long inNanoSeconds); 00096 00097 /** Sleep for a specified number of nano seconds. 00098 @param inSeconds Number of seconds to sleep. 00099 @param inNanoSeconds Number of additional nano seconds to sleep. 00100 */ 00101 static const void nanoSleep( const unsigned int inSeconds, const unsigned long inNanoSeconds); 00102 00103 00104 /** Get a timestamp. 00105 @param outTimestamp Where timestamp should be written to. 00106 */ 00107 static const void getTimestamp( timestamp_t &outTimestamp); 00108 00109 00110 /** Calculate difference of two timestamps. 00111 @param inT1 A timestamp. 00112 @param inT2 A timestamp. 00113 @param outResult T1-T2. 00114 */ 00115 static const void diffTimestamp( const timestamp_t &inT1, const timestamp_t &inT2, timestamp_t &outResult); 00116 00117 00118 /** Get identifier for current thread. 00119 @return Unique identifier for current thread. 00120 */ 00121 static const LOW_platformMiscFactory::threadIdent_t getThreadID(); 00122 00123 00124 /** Get the host's name. 00125 @return Host's name. 00126 */ 00127 static const std::string getHostname(); 00128 00129 00130 //======================================================================================= 00131 protected: 00132 00133 //===================================================================================== 00134 // 00135 // methods 00136 // 00137 00138 /** Sleep for a specified number of seconds. 00139 Virtual method to be implemented by OS specific subclasses. 00140 @param inSeconds Number of seconds to sleep. 00141 */ 00142 virtual const void p_secSleep( const unsigned int inSeconds) const = 0; 00143 00144 /** Sleep for a specified number of milli seconds. 00145 Virtual method to be implemented by OS specific subclasses. 00146 @param inMilliSeconds Number of milli seconds to sleep. 00147 */ 00148 virtual const void p_milliSleep( const unsigned long inMilliSeconds) const = 0; 00149 00150 /** Sleep for a specified number of micro seconds. 00151 Virtual method to be implemented by OS specific subclasses. 00152 @param inMicroSeconds Number of micro seconds to sleep. 00153 */ 00154 virtual const void p_microSleep( const unsigned long inMicroSeconds) const = 0; 00155 00156 /** Sleep for a specified number of nano seconds. 00157 Virtual method to be implemented by OS specific subclasses. 00158 @param inNanoSeconds Number of nano seconds to sleep. 00159 */ 00160 virtual const void p_nanoSleep( const unsigned long inNanoSeconds) const = 0; 00161 00162 /** Sleep for a specified number of nano seconds. 00163 Virtual method to be implemented by OS specific subclasses. 00164 @param inSeconds Number of seconds to sleep. 00165 @param inNanoSeconds Number of additional nano seconds to sleep. 00166 */ 00167 virtual const void p_nanoSleep( const unsigned int inSeconds, const unsigned long inNanoSeconds) const = 0; 00168 00169 00170 /** Get a timestamp. 00171 Virtual method to be implemented by OS specific subclasses. 00172 @param outTimestamp Where timestamp should written to. 00173 */ 00174 virtual const void p_getTimestamp( timestamp_t &outTimestamp) const = 0; 00175 00176 00177 /** Get identifier for current thread. 00178 Virtual method to be implemented by OS specific subclasses. 00179 @return Unique identifier for current thread. 00180 */ 00181 virtual const LOW_platformMiscFactory::threadIdent_t p_getThreadID() const = 0; 00182 00183 00184 /** Get the host's name. 00185 Virtual method to be implemented by OS specific subclasses. 00186 @return Host's name. 00187 */ 00188 virtual const std::string p_getHostname() const = 0; 00189 00190 00191 //======================================================================================= 00192 private: 00193 00194 //===================================================================================== 00195 // 00196 // attributes 00197 // 00198 00199 /** Runtime instance of platform specific implementation of this class. 00200 Having created this instance relieves the burden of explicitely 00201 creating/accessing an instance by users of methods in this class. 00202 */ 00203 static const LOW_platformMisc *runtimeInstance; 00204 00205 }; 00206 00207 #endif