(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                #include <stdio.h>
 41                #endif
 42                
 43 mike      1.19.2.1 #include <Pegasus/Common/Time.h>
 44 schuur    1.5      #include "CMPI_Version.h"
 45 schuur    1.2      
 46 schuur    1.1      #include "CMPI_DateTime.h"
 47                    #include "CMPI_Ftabs.h"
 48                    
 49                    #include <time.h>
 50 schuur    1.4      #ifdef PEGASUS_PLATFORM_WIN32_IX86_MSVC 
 51                    #define SNPRINTF _snprintf
 52                    #else
 53                    #define SNPRINTF snprintf
 54 schuur    1.1      #include <sys/time.h>
 55 schuur    1.4      #endif
 56 schuur    1.1      #include <string.h>
 57                    
 58                    PEGASUS_USING_STD;
 59                    PEGASUS_NAMESPACE_BEGIN
 60                    
 61 kumpf     1.3      static CIMDateTime *makeCIMDateTime(time_t inTime, unsigned long usec, CMPIBoolean interval)
 62 schuur    1.1      {
 63                       CIMDateTime *dt=new CIMDateTime();
 64                       char strTime[256];
 65                       char utcOffset[20];
 66                       char usTime[32];
 67                       struct tm tmTime;
 68                    
 69                       if (interval) {
 70                         // absolut time values needed
 71 schuur    1.4      #ifdef PEGASUS_PLATFORM_WIN32_IX86_MSVC
 72                         tmTime=*gmtime(&inTime);
 73                    #else 
 74 schuur    1.1           gmtime_r(&inTime,&tmTime);
 75 schuur    1.4      #endif
 76                         if (SNPRINTF(strTime,256,
 77 schuur    1.1      		  "%04d%02d%02d%02d%02d%02d.%06ld:000",
 78                    		  tmTime.tm_year-70,
 79                    		  tmTime.tm_mon,
 80                    		  tmTime.tm_mday-1,
 81                    		  tmTime.tm_hour,
 82                    		  tmTime.tm_min,
 83                    		  tmTime.tm_sec,
 84                    		  usec) > 0)
 85                           *dt=String(strTime);
 86                       } else {
 87 schuur    1.4      #ifdef PEGASUS_PLATFORM_WIN32_IX86_MSVC
 88                         tmTime=*localtime(&inTime);
 89                    #else
 90 schuur    1.1           localtime_r(&inTime,&tmTime);
 91 schuur    1.4      #endif
 92 schuur    1.1           if (strftime(strTime,256,"%Y%m%d%H%M%S.",&tmTime)) {
 93 schuur    1.4            SNPRINTF(usTime,32,"%6.6ld",usec);
 94 schuur    1.1            strcat(strTime,usTime);
 95 jenny.yu  1.13     #if defined (PEGASUS_OS_LINUX)
 96 schuur    1.4            SNPRINTF(utcOffset,20,"%+4.3ld",tmTime.tm_gmtoff/60);
 97 schuur    1.1      #else
 98 schuur    1.4            SNPRINTF(utcOffset,20,"%+4.3ld",0);
 99 schuur    1.1      #endif
100                          strncat(strTime,utcOffset,256);
101                          *dt=String(strTime);
102                          //cout<<"dt = " <<dt->toString()<<endl;
103                         }
104                       }
105                       return dt;
106                    }
107                    
108 schuur    1.8      extern "C" {
109                    
110                       static CMPIStatus dtRelease(CMPIDateTime* eDt) {
111                       //   cout<<"--- dtRelease()"<<endl;
112                          CIMDateTime* dt=(CIMDateTime*)eDt->hdl;
113                          if (dt) {
114                             delete dt;
115                             ((CMPI_Object*)eDt)->unlinkAndDelete();
116                          }
117                          CMReturn(CMPI_RC_OK);
118                       }
119                    
120                       CMPIDateTime *newDateTime() {
121                          struct timeval tv;
122 gs.keenan 1.12     #if defined (PEGASUS_OS_VMS)
123 mike      1.19.2.1       Time::gettimeofday(&tv);
124 gs.keenan 1.12     #else
125 mike      1.19.2.1       Time::gettimeofday(&tv);
126 gs.keenan 1.12     #endif
127 schuur    1.8            return (CMPIDateTime*)new CMPI_Object(makeCIMDateTime(tv.tv_sec,tv.tv_usec,0));
128                       }
129 schuur    1.1      
130 schuur    1.8         CMPIDateTime *newDateTimeBin(CMPIUint64 tim, CMPIBoolean interval) {
131                          return (CMPIDateTime*)new CMPI_Object(makeCIMDateTime(tim/1000000,tim%1000000,interval));
132                       }
133 schuur    1.1      
134 konrad.r  1.16        CMPIDateTime *newDateTimeChar(const char *strTime) {
135 schuur    1.8            CIMDateTime *dt=new CIMDateTime();
136 konrad.r  1.14     	  try {
137                          	*dt=String(strTime);
138                    	  } catch ( ... )
139                    		{
140                    			delete dt;
141                    			return NULL;
142                    		}
143 schuur    1.8            return (CMPIDateTime*)new CMPI_Object(dt);
144                       }
145 schuur    1.1      
146 konrad.r  1.15        static CMPIDateTime* dtClone(const CMPIDateTime* eDt, CMPIStatus* rc) {
147 schuur    1.8            CIMDateTime* dt=(CIMDateTime*)eDt->hdl;
148 konrad.r  1.10           if (!dt) {
149                    		if (rc) CMSetStatus(rc, CMPI_RC_ERR_INVALID_PARAMETER);
150                    	    return NULL;
151                          }
152 schuur    1.8            CIMDateTime* cDt=new CIMDateTime(dt->toString());
153                          CMPI_Object* obj=new CMPI_Object(cDt);
154                          obj->unlink();
155                          CMPIDateTime* neDt=(CMPIDateTime*)obj;
156                          if (rc) CMSetStatus(rc,CMPI_RC_OK);
157                          return neDt;
158 schuur    1.1         }
159                    
160 konrad.r  1.15        static CMPIBoolean dtIsInterval(const CMPIDateTime* eDt, CMPIStatus* rc) {
161 schuur    1.8            CIMDateTime* dt=(CIMDateTime*)eDt->hdl;
162 konrad.r  1.10           if (!dt) {
163                    		if (rc) CMSetStatus(rc, CMPI_RC_ERR_INVALID_PARAMETER);
164                    	    return false;
165                          }
166                    		
167 schuur    1.8            if (rc) CMSetStatus(rc,CMPI_RC_OK);
168                          return dt->isInterval();
169                       }
170 schuur    1.1      
171 konrad.r  1.15        static CMPIString *dtGetStringFormat(const CMPIDateTime* eDt, CMPIStatus* rc) {
172 schuur    1.8            CIMDateTime* dt=(CIMDateTime*)eDt->hdl;
173 konrad.r  1.10           if (!dt) {
174                    		if (rc) CMSetStatus(rc, CMPI_RC_ERR_INVALID_PARAMETER);
175                    	    return NULL;
176                          }
177 schuur    1.8            CMPIString *str=(CMPIString*)new CMPI_Object(dt->toString());
178                          if (rc) CMSetStatus(rc,CMPI_RC_OK);
179                          return str;
180                       }
181 schuur    1.1      
182 konrad.r  1.15        static CMPIUint64 dtGetBinaryFormat(const CMPIDateTime* eDt, CMPIStatus* rc) {
183 schuur    1.8            CIMDateTime* dt=(CIMDateTime*)eDt->hdl;
184 konrad.r  1.10           if (!dt) {
185                    		if (rc) CMSetStatus(rc, CMPI_RC_ERR_INVALID_PARAMETER);
186                    	    return 0;
187                          }
188 schuur    1.8            CMPIUint64 days,hours,mins,secs,usecs,utc,lTime;
189                          struct tm tm,tmt;
190                          CString tStr=dt->toString().getCString();
191 konrad.r  1.17           char cStr[26];
192                          memset( cStr, 0, 26);
193                          memcpy (cStr, (const char*)tStr, 25);
194 schuur    1.8            if (dt->isInterval()) {
195                             cStr[21]=0;
196                             usecs=atoi(cStr+15);
197                             cStr[15]=0;
198                             secs=atoi(cStr+12);
199                             cStr[12]=0;
200                             mins=atoi(cStr+10);
201                             cStr[10]=0;
202                             hours=atoi(cStr+8);
203                             cStr[8]=0;
204                             days=atoi(cStr);
205                             lTime=(days*PEGASUS_UINT64_LITERAL(86400000000))+
206                                   (hours*PEGASUS_UINT64_LITERAL(3600000000))+
207                                   (mins*60000000)+(secs*1000000)+usecs;
208                          }
209                    
210                          else {
211                             time_t tt=time(NULL);
212                       #ifdef PEGASUS_PLATFORM_WIN32_IX86_MSVC
213                             tmt=*localtime(&tt);
214                       #else
215 schuur    1.8               localtime_r(&tt,&tmt);
216                       #endif
217                             memset(&tm,0,sizeof(tm));
218                             tm.tm_isdst=tmt.tm_isdst;
219                             utc=atoi(cStr+21);
220                             cStr[21]=0;
221                             usecs=atoi(cStr+15);
222                             cStr[15]=0;
223                             tm.tm_sec=atoi(cStr+12);
224                             cStr[12]=0;
225                             tm.tm_min=atoi(cStr+10);
226                             cStr[10]=0;
227                             tm.tm_hour=atoi(cStr+8);
228                             cStr[8]=0;
229                             tm.tm_mday=atoi(cStr+6);
230                             cStr[6]=0;
231                             tm.tm_mon=(atoi(cStr+4)-1);
232                             cStr[4]=0;
233                             tm.tm_year=(atoi(cStr)-1900);
234                             lTime=mktime(&tm);
235                             lTime*=1000000;
236 schuur    1.8               lTime+=usecs;
237                          }
238 schuur    1.1      
239 schuur    1.8            return lTime;
240 schuur    1.1         }
241                    
242                    }
243                    
244                    static CMPIDateTimeFT dateTime_FT={
245                         CMPICurrentVersion,
246                         dtRelease,
247                         dtClone,
248                         dtGetBinaryFormat,
249                         dtGetStringFormat,
250                         dtIsInterval,
251                    };
252                    
253                    CMPIDateTimeFT *CMPI_DateTime_Ftab=&dateTime_FT;
254                    
255                    PEGASUS_NAMESPACE_END
256                    
257                    
258                    
259                    
260                    

No CVS admin address has been configured
Powered by
ViewCVS 0.9.2