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 #include "cmpisrv.h"
00026 #include <time.h>
00027 #include <sys/time.h>
00028 #include <string.h>
00029 #include "OW_CIMDateTime.hpp"
00030 #include "OW_DateTime.hpp"
00031 #include "OW_CIMFwd.hpp"
00032
00033 static OpenWBEM::CIMDateTime * makeCIMDateTime(
00034 time_t inTime,
00035 unsigned long usec,
00036 CMPIBoolean interval)
00037 {
00038 if (interval)
00039 {
00040 OpenWBEM::UInt64 microsecs = inTime * 1000000;
00041 microsecs += usec;
00042 return new OpenWBEM::CIMDateTime(microsecs);
00043 }
00044
00045 OpenWBEM::DateTime dt(inTime, OpenWBEM::UInt32(usec));
00046 return new OpenWBEM::CIMDateTime(dt);
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060
00061
00062
00063
00064
00065
00066
00067
00068
00069
00070
00071
00072
00073
00074
00075 }
00076
00077 CMPIDateTime *newDateTime()
00078 {
00079 struct timeval tv;
00080 struct timezone tz;
00081 gettimeofday(&tv,&tz);
00082 return (CMPIDateTime*)
00083 new CMPI_Object(makeCIMDateTime(tv.tv_sec,tv.tv_usec,0));
00084 }
00085
00086 CMPIDateTime *newDateTime(CMPIUint64 tim, CMPIBoolean interval)
00087 {
00088 return (CMPIDateTime*)
00089 new CMPI_Object(makeCIMDateTime(tim/1000000,tim%1000000,interval));
00090 }
00091
00092 CMPIDateTime *newDateTime(const char *strTime)
00093 {
00094 OpenWBEM::CIMDateTime *dt=new OpenWBEM::CIMDateTime(OpenWBEM::String(strTime));
00095 return (CMPIDateTime*)new CMPI_Object(dt);
00096 }
00097
00098 static CMPIStatus dtRelease(CMPIDateTime* eDt)
00099 {
00100
00101 OpenWBEM::CIMDateTime* dt=(OpenWBEM::CIMDateTime*)eDt->hdl;
00102 if (dt)
00103 {
00104 delete dt;
00105 ((CMPI_Object*)eDt)->unlinkAndDelete();
00106 }
00107 CMReturn(CMPI_RC_OK);
00108 }
00109
00110 static CMPIDateTime* dtClone(const CMPIDateTime* eDt, CMPIStatus* rc)
00111 {
00112 OpenWBEM::CIMDateTime * dt=(OpenWBEM::CIMDateTime*)eDt->hdl;
00113
00114 OpenWBEM::CIMDateTime * cDt = new OpenWBEM::CIMDateTime(*dt);
00115
00116 CMPIDateTime* neDt=(CMPIDateTime*)new CMPI_Object(cDt,CMPI_DateTime_Ftab);
00117 CMSetStatus(rc,CMPI_RC_OK);
00118 return neDt;
00119 }
00120
00121 static CMPIBoolean dtIsInterval(const CMPIDateTime* eDt, CMPIStatus* rc)
00122 {
00123 OpenWBEM::CIMDateTime* dt=(OpenWBEM::CIMDateTime*)eDt->hdl;
00124 CMSetStatus(rc,CMPI_RC_OK);
00125 return dt->isInterval();
00126 }
00127
00128 static CMPIString *dtGetStringFormat(const CMPIDateTime* eDt, CMPIStatus* rc)
00129 {
00130 OpenWBEM::CIMDateTime* dt=(OpenWBEM::CIMDateTime*)eDt->hdl;
00131 CMPIString *str=(CMPIString*)new CMPI_Object(dt->toString());
00132 CMSetStatus(rc,CMPI_RC_OK);
00133 return str;
00134 }
00135
00136 static CMPIUint64 dtGetBinaryFormat(const CMPIDateTime* eDt, CMPIStatus* rc)
00137 {
00138 OpenWBEM::CIMDateTime* dt = (OpenWBEM::CIMDateTime*)eDt->hdl;
00139 CMPIUint64 days,hours,mins,secs,usecs,utc,lTime;
00140 struct tm tm,tmt;
00141
00142
00143
00144
00145 if (dt->isInterval())
00146 {
00147 usecs = dt->getMicroSeconds();
00148 secs = dt->getSeconds();
00149 mins = dt->getMinutes();
00150 hours = dt->getHours();
00151 days = dt->getDays();
00152
00153 lTime = (days*(OpenWBEM::UInt64)(86400000000LL))+
00154 (hours*(OpenWBEM::UInt64)(3600000000LL))+
00155 (mins*60000000)+(secs*1000000)+usecs;
00156 }
00157 else
00158 {
00159 time_t tt = time(NULL);
00160 localtime_r(&tt, &tmt);
00161 memset(&tm, 0, sizeof(tm));
00162 tm.tm_isdst = tmt.tm_isdst;
00163 utc = dt->getUtc();
00164 usecs = dt->getMicroSeconds();
00165 tm.tm_sec = dt->getSeconds();
00166 tm.tm_min = dt->getMinutes();
00167 tm.tm_hour = dt->getHours();
00168 tm.tm_mday = dt->getDays();
00169 tm.tm_mon = dt->getMonth();
00170 tm.tm_year = dt->getYear() - 1900;
00171
00172 lTime = mktime(&tm);
00173 lTime *= 1000000;
00174 lTime += usecs;
00175 }
00176
00177 return lTime;
00178 }
00179
00180 static CMPIDateTimeFT dateTime_FT =
00181 {
00182 CMPICurrentVersion,
00183 dtRelease,
00184 dtClone,
00185 dtGetBinaryFormat,
00186 dtGetStringFormat,
00187 dtIsInterval,
00188 };
00189
00190 CMPIDateTimeFT *CMPI_DateTime_Ftab=&dateTime_FT;
00191