cmpiDateTime.cpp

Go to the documentation of this file.
00001 
00002 /*
00003  *
00004  * cmpiDateTime.cpp
00005  *
00006  * Copyright (c) 2002, International Business Machines
00007  * 
00008  * THIS FILE IS PROVIDED UNDER THE TERMS OF THE COMMON PUBLIC LICENSE
00009  * ("AGREEMENT"). ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS FILE
00010  * CONSTITUTES RECIPIENTS ACCEPTANCE OF THE AGREEMENT.
00011  *
00012  * You can obtain a current copy of the Common Public License from
00013  * http://oss.software.ibm.com/developerworks/opensource/license-cpl.html
00014  *
00015  * Author:        Adrian Schuur <schuur@de.ibm.com>
00016  * 
00017  * Contributor:   Markus Mueller <sedgewick_de@yahoo.de>
00018  *
00019  * Description: CMPIClass support
00020  *
00021  */
00022 
00023 //#include "OW_config.h"
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    OpenWBEM::CIMDateTime * dt;
00049    char strTime[256];
00050    char utcOffset[20];
00051    char usTime[32];
00052    struct tm tmTime;
00053 
00054    localtime_r(&inTime,&tmTime);
00055    if (strftime(strTime,256,"%Y%m%d%H%M%S.",&tmTime)) 
00056    {
00057       snprintf(usTime,32,"%6.6ld",usec);
00058       strcat(strTime,usTime);
00059       if (interval) 
00060          strcpy(utcOffset,":000");
00061       else 
00062       {
00063 #if defined (OW_GNU_LINUX)
00064          snprintf(utcOffset,20,"%+4.3ld",tmTime.tm_gmtoff/60);
00065 #else
00066          snprintf(utcOffset,20,"%+4.3ld",0L);
00067 #endif
00068       }
00069       strncat(strTime,utcOffset,256);
00070       dt = new OpenWBEM::CIMDateTime(OpenWBEM::String(strTime));
00071       //cout<<"dt = " <<dt->toString()<<endl;
00072    }
00073    return dt;
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    //cout<<"--- dtRelease()"<<endl;
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    //OpenWBEM::CIMDateTime * cDt=new OpenWBEM::CIMDateTime(dt->toString());
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    //CString tStr=dt->toString().getCString();
00142    //const char * tStr=dt->toString().c_str();
00143    //char *cStr=strdup((const char*)tStr);
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 

Generated on Thu Feb 9 08:47:48 2006 for openwbem by  doxygen 1.4.6