(file) Return to CMPI_DateTime.cpp CVS log (file) (dir) Up to [Pegasus] / pegasus / src / Pegasus / ProviderManager2 / CMPI

  1 karl  1.18 //%2006////////////////////////////////////////////////////////////////////////
  2 schuur 1.1  //
  3 karl   1.9  // Copyright (c) 2000, 2001, 2002 BMC Software; Hewlett-Packard Development
  4             // Company, L.P.; IBM Corp.; The Open Group; Tivoli Systems.
  5             // Copyright (c) 2003 BMC Software; Hewlett-Packard Development Company, L.P.;
  6 schuur 1.1  // IBM Corp.; EMC Corporation, The Open Group.
  7 karl   1.9  // Copyright (c) 2004 BMC Software; Hewlett-Packard Development Company, L.P.;
  8             // IBM Corp.; EMC Corporation; VERITAS Software Corporation; The Open Group.
  9 karl   1.11 // Copyright (c) 2005 Hewlett-Packard Development Company, L.P.; IBM Corp.;
 10             // EMC Corporation; VERITAS Software Corporation; The Open Group.
 11 karl   1.18 // Copyright (c) 2006 Hewlett-Packard Development Company, L.P.; IBM Corp.;
 12             // EMC Corporation; Symantec Corporation; The Open Group.
 13 schuur 1.1  //
 14             // Permission is hereby granted, free of charge, to any person obtaining a copy
 15             // of this software and associated documentation files (the "Software"), to
 16             // deal in the Software without restriction, including without limitation the
 17             // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
 18             // sell copies of the Software, and to permit persons to whom the Software is
 19             // furnished to do so, subject to the following conditions:
 20 karl   1.9  // 
 21 schuur 1.1  // THE ABOVE COPYRIGHT NOTICE AND THIS PERMISSION NOTICE SHALL BE INCLUDED IN
 22             // ALL COPIES OR SUBSTANTIAL PORTIONS OF THE SOFTWARE. THE SOFTWARE IS PROVIDED
 23             // "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT
 24             // LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
 25             // PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
 26             // HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
 27             // ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
 28             // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 29             //
 30             //==============================================================================
 31             //
 32             // Author:      Adrian Schuur, schuur@de.ibm.com
 33             //
 34             // Modified By:
 35 gs.keenan 1.12 //              Sean Keenan, Hewlett-Packard Company (sean.keenan@hp.com)
 36 schuur    1.1  //
 37                //%/////////////////////////////////////////////////////////////////////////////
 38                
 39 marek     1.19 #ifdef PEGASUS_PLATFORM_ZOS_ZSERIES_IBM
 40                #define _ISOC99_SOURCE
 41                #include <stdio.h>
 42                #endif
 43                
 44 mike      1.19.2.1 #include <Pegasus/Common/Time.h>
 45 schuur    1.5      #include "CMPI_Version.h"
 46 schuur    1.2      
 47 schuur    1.1      #include "CMPI_DateTime.h"
 48                    #include "CMPI_Ftabs.h"
 49                    
 50                    #include <time.h>
 51 schuur    1.4      #ifdef PEGASUS_PLATFORM_WIN32_IX86_MSVC 
 52                    #define SNPRINTF _snprintf
 53                    #else
 54                    #define SNPRINTF snprintf
 55 schuur    1.1      #include <sys/time.h>
 56 schuur    1.4      #endif
 57 schuur    1.1      #include <string.h>
 58                    
 59                    PEGASUS_USING_STD;
 60                    PEGASUS_NAMESPACE_BEGIN
 61                    
 62 kumpf     1.3      static CIMDateTime *makeCIMDateTime(time_t inTime, unsigned long usec, CMPIBoolean interval)
 63 schuur    1.1      {
 64                       CIMDateTime *dt=new CIMDateTime();
 65                       char strTime[256];
 66                       char utcOffset[20];
 67                       char usTime[32];
 68                       struct tm tmTime;
 69                    
 70                       if (interval) {
 71                         // absolut time values needed
 72 schuur    1.4      #ifdef PEGASUS_PLATFORM_WIN32_IX86_MSVC
 73                         tmTime=*gmtime(&inTime);
 74                    #else 
 75 schuur    1.1           gmtime_r(&inTime,&tmTime);
 76 schuur    1.4      #endif
 77                         if (SNPRINTF(strTime,256,
 78 schuur    1.1      		  "%04d%02d%02d%02d%02d%02d.%06ld:000",
 79                    		  tmTime.tm_year-70,
 80                    		  tmTime.tm_mon,
 81                    		  tmTime.tm_mday-1,
 82                    		  tmTime.tm_hour,
 83                    		  tmTime.tm_min,
 84                    		  tmTime.tm_sec,
 85                    		  usec) > 0)
 86                           *dt=String(strTime);
 87                       } else {
 88 schuur    1.4      #ifdef PEGASUS_PLATFORM_WIN32_IX86_MSVC
 89                         tmTime=*localtime(&inTime);
 90                    #else
 91 schuur    1.1           localtime_r(&inTime,&tmTime);
 92 schuur    1.4      #endif
 93 schuur    1.1           if (strftime(strTime,256,"%Y%m%d%H%M%S.",&tmTime)) {
 94 schuur    1.4            SNPRINTF(usTime,32,"%6.6ld",usec);
 95 schuur    1.1            strcat(strTime,usTime);
 96 jenny.yu  1.13     #if defined (PEGASUS_OS_LINUX)
 97 schuur    1.4            SNPRINTF(utcOffset,20,"%+4.3ld",tmTime.tm_gmtoff/60);
 98 schuur    1.1      #else
 99 schuur    1.4            SNPRINTF(utcOffset,20,"%+4.3ld",0);
100 schuur    1.1      #endif
101                          strncat(strTime,utcOffset,256);
102                          *dt=String(strTime);
103                          //cout<<"dt = " <<dt->toString()<<endl;
104                         }
105                       }
106                       return dt;
107                    }
108                    
109 schuur    1.8      extern "C" {
110                    
111                       static CMPIStatus dtRelease(CMPIDateTime* eDt) {
112                       //   cout<<"--- dtRelease()"<<endl;
113                          CIMDateTime* dt=(CIMDateTime*)eDt->hdl;
114                          if (dt) {
115                             delete dt;
116                             ((CMPI_Object*)eDt)->unlinkAndDelete();
117                          }
118                          CMReturn(CMPI_RC_OK);
119                       }
120                    
121                       CMPIDateTime *newDateTime() {
122                          struct timeval tv;
123 gs.keenan 1.12     #if defined (PEGASUS_OS_VMS)
124 mike      1.19.2.1       Time::gettimeofday(&tv);
125 gs.keenan 1.12     #else
126 mike      1.19.2.1       Time::gettimeofday(&tv);
127 gs.keenan 1.12     #endif
128 schuur    1.8            return (CMPIDateTime*)new CMPI_Object(makeCIMDateTime(tv.tv_sec,tv.tv_usec,0));
129                       }
130 schuur    1.1      
131 schuur    1.8         CMPIDateTime *newDateTimeBin(CMPIUint64 tim, CMPIBoolean interval) {
132                          return (CMPIDateTime*)new CMPI_Object(makeCIMDateTime(tim/1000000,tim%1000000,interval));
133                       }
134 schuur    1.1      
135 konrad.r  1.16        CMPIDateTime *newDateTimeChar(const char *strTime) {
136 schuur    1.8            CIMDateTime *dt=new CIMDateTime();
137 konrad.r  1.14     	  try {
138                          	*dt=String(strTime);
139                    	  } catch ( ... )
140                    		{
141                    			delete dt;
142                    			return NULL;
143                    		}
144 schuur    1.8            return (CMPIDateTime*)new CMPI_Object(dt);
145                       }
146 schuur    1.1      
147 konrad.r  1.15        static CMPIDateTime* dtClone(const CMPIDateTime* eDt, CMPIStatus* rc) {
148 schuur    1.8            CIMDateTime* dt=(CIMDateTime*)eDt->hdl;
149 konrad.r  1.10           if (!dt) {
150                    		if (rc) CMSetStatus(rc, CMPI_RC_ERR_INVALID_PARAMETER);
151                    	    return NULL;
152                          }
153 schuur    1.8            CIMDateTime* cDt=new CIMDateTime(dt->toString());
154                          CMPI_Object* obj=new CMPI_Object(cDt);
155                          obj->unlink();
156                          CMPIDateTime* neDt=(CMPIDateTime*)obj;
157                          if (rc) CMSetStatus(rc,CMPI_RC_OK);
158                          return neDt;
159 schuur    1.1         }
160                    
161 konrad.r  1.15        static CMPIBoolean dtIsInterval(const CMPIDateTime* eDt, CMPIStatus* rc) {
162 schuur    1.8            CIMDateTime* dt=(CIMDateTime*)eDt->hdl;
163 konrad.r  1.10           if (!dt) {
164                    		if (rc) CMSetStatus(rc, CMPI_RC_ERR_INVALID_PARAMETER);
165                    	    return false;
166                          }
167                    		
168 schuur    1.8            if (rc) CMSetStatus(rc,CMPI_RC_OK);
169                          return dt->isInterval();
170                       }
171 schuur    1.1      
172 konrad.r  1.15        static CMPIString *dtGetStringFormat(const CMPIDateTime* eDt, CMPIStatus* rc) {
173 schuur    1.8            CIMDateTime* dt=(CIMDateTime*)eDt->hdl;
174 konrad.r  1.10           if (!dt) {
175                    		if (rc) CMSetStatus(rc, CMPI_RC_ERR_INVALID_PARAMETER);
176                    	    return NULL;
177                          }
178 schuur    1.8            CMPIString *str=(CMPIString*)new CMPI_Object(dt->toString());
179                          if (rc) CMSetStatus(rc,CMPI_RC_OK);
180                          return str;
181                       }
182 schuur    1.1      
183 konrad.r  1.15        static CMPIUint64 dtGetBinaryFormat(const CMPIDateTime* eDt, CMPIStatus* rc) {
184 schuur    1.8            CIMDateTime* dt=(CIMDateTime*)eDt->hdl;
185 konrad.r  1.10           if (!dt) {
186                    		if (rc) CMSetStatus(rc, CMPI_RC_ERR_INVALID_PARAMETER);
187                    	    return 0;
188                          }
189 schuur    1.8            CMPIUint64 days,hours,mins,secs,usecs,utc,lTime;
190                          struct tm tm,tmt;
191                          CString tStr=dt->toString().getCString();
192 konrad.r  1.17           char cStr[26];
193                          memset( cStr, 0, 26);
194                          memcpy (cStr, (const char*)tStr, 25);
195 schuur    1.8            if (dt->isInterval()) {
196                             cStr[21]=0;
197                             usecs=atoi(cStr+15);
198                             cStr[15]=0;
199                             secs=atoi(cStr+12);
200                             cStr[12]=0;
201                             mins=atoi(cStr+10);
202                             cStr[10]=0;
203                             hours=atoi(cStr+8);
204                             cStr[8]=0;
205                             days=atoi(cStr);
206                             lTime=(days*PEGASUS_UINT64_LITERAL(86400000000))+
207                                   (hours*PEGASUS_UINT64_LITERAL(3600000000))+
208                                   (mins*60000000)+(secs*1000000)+usecs;
209                          }
210                    
211                          else {
212                             time_t tt=time(NULL);
213                       #ifdef PEGASUS_PLATFORM_WIN32_IX86_MSVC
214                             tmt=*localtime(&tt);
215                       #else
216 schuur    1.8               localtime_r(&tt,&tmt);
217                       #endif
218                             memset(&tm,0,sizeof(tm));
219                             tm.tm_isdst=tmt.tm_isdst;
220                             utc=atoi(cStr+21);
221                             cStr[21]=0;
222                             usecs=atoi(cStr+15);
223                             cStr[15]=0;
224                             tm.tm_sec=atoi(cStr+12);
225                             cStr[12]=0;
226                             tm.tm_min=atoi(cStr+10);
227                             cStr[10]=0;
228                             tm.tm_hour=atoi(cStr+8);
229                             cStr[8]=0;
230                             tm.tm_mday=atoi(cStr+6);
231                             cStr[6]=0;
232                             tm.tm_mon=(atoi(cStr+4)-1);
233                             cStr[4]=0;
234                             tm.tm_year=(atoi(cStr)-1900);
235                             lTime=mktime(&tm);
236                             lTime*=1000000;
237 schuur    1.8               lTime+=usecs;
238                          }
239 schuur    1.1      
240 schuur    1.8            return lTime;
241 schuur    1.1         }
242                    
243                    }
244                    
245                    static CMPIDateTimeFT dateTime_FT={
246                         CMPICurrentVersion,
247                         dtRelease,
248                         dtClone,
249                         dtGetBinaryFormat,
250                         dtGetStringFormat,
251                         dtIsInterval,
252                    };
253                    
254                    CMPIDateTimeFT *CMPI_DateTime_Ftab=&dateTime_FT;
255                    
256                    PEGASUS_NAMESPACE_END
257                    
258                    
259                    
260                    
261                    

No CVS admin address has been configured
Powered by
ViewCVS 0.9.2