Main Page | Class Hierarchy | Class List | File List | Class Members | File Members | Related Pages

new_sim_utils.h

Go to the documentation of this file.
00001 
00025 #ifndef __NEW_SIM_UTILS_H__
00026 #define __NEW_SIM_UTILS_H__
00027 
00028 #include <sys/time.h>
00029 
00035 enum tNewSimulatorFruState
00036 {
00037   eFruStateNotInstalled           = 0,
00038   eFruStateInactive               = 1,
00039   eFruStateActivationRequest      = 2,
00040   eFruStateActivationInProgress   = 3,
00041   eFruStateActive                 = 4,
00042   eFruStateDeactivationRequest    = 5,
00043   eFruStateDeactivationInProgress = 6,
00044   eFruStateCommunicationLost      = 7
00045 };
00046 
00053 const char *NewSimulatorFruStateToString( tNewSimulatorFruState state );
00054 
00056 #define dDateStringSize 11
00057 void NewSimulatorDateToString( unsigned int time, char *str );
00058 
00060 #define dTimeStringSize 9
00061 void NewSimulatorTimeToString( unsigned int time, char *str );
00062 
00064 #define dDateTimeStringSize 20
00065 void NewSimulatorDateTimeToString( unsigned int time, char *str );
00066 
00067 
00073 class cTime
00074 {
00075 public:
00077   timeval m_time;
00078 
00082   cTime()
00083   {
00084     m_time.tv_sec  = 0;
00085     m_time.tv_usec = 0;    
00086   }
00087   
00091   cTime( const struct timeval &tv )
00092   {
00093     m_time.tv_sec  = tv.tv_sec;
00094     m_time.tv_usec = tv.tv_usec;
00095   }
00096   
00100   cTime( const cTime &t )
00101   {
00102     m_time.tv_sec  = t.m_time.tv_sec;
00103     m_time.tv_usec = t.m_time.tv_usec;
00104   }
00105   
00109   cTime( unsigned int s, unsigned int u )
00110   {
00111     m_time.tv_sec = s;
00112     m_time.tv_usec = u;
00113   }
00114 
00118   void Normalize()
00119   {
00120     while( m_time.tv_usec > 1000000 )
00121        {
00122          m_time.tv_usec -= 1000000;
00123          m_time.tv_sec++;
00124        }
00125 
00126     while( m_time.tv_usec < 0 )
00127        {
00128          m_time.tv_usec += 1000000;
00129          m_time.tv_sec--;
00130        }
00131   }
00132 
00136   int Cmp( const cTime &t )
00137   {
00138     if ( m_time.tv_sec < t.m_time.tv_sec )
00139          return -1;
00140 
00141     if ( m_time.tv_sec > t.m_time.tv_sec )
00142          return 1;
00143 
00144     if ( m_time.tv_usec < t.m_time.tv_usec )
00145          return -1;
00146 
00147     if ( m_time.tv_usec > t.m_time.tv_usec )
00148          return 1;
00149 
00150     return 0;
00151   }
00152 
00156   bool operator<( const cTime &t )
00157   {
00158     return Cmp( t ) < 0;
00159   }
00160 
00164   bool operator<=( const cTime &t )
00165   {
00166     return Cmp( t ) < 0;
00167   }
00168 
00172   bool operator>( const cTime &t )
00173   {
00174     return Cmp( t ) > 0;
00175   }
00176 
00180   bool operator>=( const cTime &t )
00181   {
00182     return Cmp( t ) >= 0;
00183   }
00184 
00188   bool operator==( const cTime &t )
00189   {
00190     return Cmp( t ) == 0;
00191   }
00192 
00196   bool operator!=( const cTime &t )
00197   {
00198     return Cmp( t ) == 0;
00199   }
00200 
00204   cTime &operator+=( const cTime &t )
00205   {
00206     m_time.tv_sec += t.m_time.tv_sec;
00207     m_time.tv_usec += t.m_time.tv_usec;
00208 
00209     Normalize();
00210 
00211     return *this;
00212   }
00213 
00217   cTime &operator+=( int ms )
00218   {
00219     m_time.tv_sec  += ms / 1000;
00220     m_time.tv_usec += (ms % 1000) * 1000;
00221 
00222     Normalize();
00223 
00224     return *this;
00225   }
00226 
00230   cTime &operator-=( int ms )
00231   {
00232     m_time.tv_sec  -= ms / 1000;
00233     m_time.tv_usec -= (ms % 1000) * 1000;
00234 
00235     Normalize();
00236 
00237     return *this;
00238   }
00239   
00243   cTime &operator-=( cTime t )
00244   {
00245     m_time.tv_sec  -= t.m_time.tv_sec;
00246     m_time.tv_usec -= t.m_time.tv_usec;
00247 
00248     Normalize();
00249 
00250     return *this;
00251   }
00252 
00256   static cTime Now()
00257   {
00258     cTime t;
00259     gettimeofday( &t.m_time, 0 );
00260 
00261     return t;
00262   }
00263   
00267    unsigned int GetMsec()
00268    {
00269           return (unsigned int) (m_time.tv_sec * 1000 + m_time.tv_usec / 1000);
00270    }
00271    
00275    void Clear()
00276    {
00277       m_time.tv_sec  = 0;
00278       m_time.tv_usec = 0;
00279    }
00280    
00284    bool IsSet()
00285    {
00286       return ( !(( m_time.tv_sec == 0 ) && ( m_time.tv_usec == 0 )) );
00287    }
00288 };
00289 
00290 
00291 #endif

Generated on Mon Apr 26 14:36:48 2010 for New Simulator by  doxygen 1.4.4