1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189
|
/*
* ipmi_utils.cpp
*
* Copyright (c) 2003 by FORCE Computers
*
* Note that this file is based on parts of OpenIPMI
* written by Corey Minyard <minyard@mvista.com>
* of MontaVista Software. Corey's code was helpful
* and many thanks go to him. He gave the permission
* to use this code in OpenHPI under BSD license.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. This
* file and program are licensed under a BSD style license. See
* the Copying file included with the OpenHPI distribution for
* full licensing terms.
*
* Authors:
* Thomas Kanngieser <thomas.kanngieser@fci.com>
*/
#ifndef dIpmiUtils_h
#define dIpmiUtils_h
#include <sys/time.h>
enum tIpmiFruState
{
eIpmiFruStateNotInstalled = 0,
eIpmiFruStateInactive = 1,
eIpmiFruStateActivationRequest = 2,
eIpmiFruStateActivationInProgress = 3,
eIpmiFruStateActive = 4,
eIpmiFruStateDeactivationRequest = 5,
eIpmiFruStateDeactivationInProgress = 6,
eIpmiFruStateCommunicationLost = 7
};
const char *IpmiFruStateToString( tIpmiFruState state );
unsigned int IpmiGetUint16( const unsigned char *data );
void IpmiSetUint16( unsigned char *data, int val );
unsigned int IpmiGetUint32( const unsigned char *data );
void IpmiSetUint32( unsigned char *data, int val );
#define dDateStringSize 11
void IpmiDateToString( unsigned int time, char *str );
#define dTimeStringSize 9
void IpmiTimeToString( unsigned int time, char *str );
#define dDateTimeStringSize 20
void IpmiDateTimeToString( unsigned int time, char *str );
class cTime
{
public:
timeval m_time;
cTime()
{
m_time.tv_sec = 0;
m_time.tv_usec = 0;
}
cTime( const struct timeval &tv )
{
m_time.tv_sec = tv.tv_sec;
m_time.tv_usec = tv.tv_usec;
}
cTime( const cTime &t )
{
m_time.tv_sec = t.m_time.tv_sec;
m_time.tv_usec = t.m_time.tv_usec;
}
cTime( unsigned int s, unsigned int u )
{
m_time.tv_sec = s;
m_time.tv_usec = u;
}
void Normalize()
{
while( m_time.tv_usec > 1000000 )
{
m_time.tv_usec -= 1000000;
m_time.tv_sec++;
}
while( m_time.tv_usec < 0 )
{
m_time.tv_usec += 1000000;
m_time.tv_sec--;
}
}
int Cmp( const cTime &t )
{
if ( m_time.tv_sec < t.m_time.tv_sec )
return -1;
if ( m_time.tv_sec > t.m_time.tv_sec )
return 1;
if ( m_time.tv_usec < t.m_time.tv_usec )
return -1;
if ( m_time.tv_usec > t.m_time.tv_usec )
return 1;
return 0;
}
bool operator<( const cTime &t )
{
return Cmp( t ) < 0;
}
bool operator<=( const cTime &t )
{
return Cmp( t ) < 0;
}
bool operator>( const cTime &t )
{
return Cmp( t ) > 0;
}
bool operator>=( const cTime &t )
{
return Cmp( t ) >= 0;
}
bool operator==( const cTime &t )
{
return Cmp( t ) == 0;
}
bool operator!=( const cTime &t )
{
return Cmp( t ) == 0;
}
cTime &operator+=( const cTime &t )
{
m_time.tv_sec += t.m_time.tv_sec;
m_time.tv_usec += t.m_time.tv_usec;
Normalize();
return *this;
}
cTime &operator+=( int ms )
{
m_time.tv_sec += ms / 1000;
m_time.tv_usec += (ms % 1000) * 1000;
Normalize();
return *this;
}
cTime &operator-=( int ms )
{
m_time.tv_sec -= ms / 1000;
m_time.tv_usec -= (ms % 1000) * 1000;
Normalize();
return *this;
}
static cTime Now()
{
cTime t;
gettimeofday( &t.m_time, 0 );
return t;
}
};
#endif
|