Boolean OperatingSystem::getLastBootUpTime(CIMDateTime& lastBootUpTime) { Uint64 sysUpTime = 0; if(getSystemUpTime(sysUpTime)) { // convert sysUpTime to microseconds sysUpTime *= (1000 * 1000); CIMDateTime currentTime = CIMDateTime::getCurrentDateTime(); CIMDateTime bootTime = CIMDateTime(currentTime.toMicroSeconds() - sysUpTime, false); // adjust UTC offset String s1 = currentTime.toString(); String s2 = bootTime.toString(); s2[20] = s1[20]; s2[21] = s1[21]; s2[22] = s1[22]; s2[23] = s1[23]; lastBootUpTime = CIMDateTime(s2); return true; } return false; }
/** goodLocalDateTime method of SunOS OS Provider Test Client Uses the CIMOM getCurrentDateTime function and checks that the current time from the instance is within one hour of that time. */ Boolean OSTestClient::goodLocalDateTime( const CIMDateTime <ime, Boolean verbose) { if (verbose) cout<<"Checking LocalDateTime " << ltime.toString() << endl; CIMDateTime currentDT = CIMDateTime::getCurrentDateTime(); Sint64 raw_delta; try { raw_delta = CIMDateTime::getDifference(ltime, currentDT); } catch(DateTimeOutOfRangeException &e) { cout << "Error : " << e.getMessage() << endl; exit; } Uint64 delta = labs(raw_delta); if (verbose) { cout<<" Should be close to " << currentDT.toString() << endl; printf( " Delta should be within 360 seconds, is %lld\n",delta); fflush(stdout); } // arbitrary choice of expecting them to be within 360 seconds return (delta < 360000000); }
/* GoodInstallDate method for the OS Provider Test Client Checks the specified value against the expected value and returns TRUE if the same, else FALSE */ Boolean OSTestClient::goodInstallDate(const CIMDateTime &idate, Boolean verbose) { if (verbose) cout<<"Checking InstallDate " << idate.toString() << endl; return false; // not implemented for SunOS, fail if there }
Boolean OSTestClient::goodLocalDateTime(const CIMDateTime <ime, Boolean verbose) { if (verbose) cout<<"Checking LocalDateTime " << ltime.toString() << endl; cout<<"- No check written for LocalDateTime " << endl; return true; }
/* GoodInstallDate method for the OS Provider Test Client Checks the specified value against the expected value and returns TRUE if the same, else FALSE */ Boolean OSTestClient::goodInstallDate(const CIMDateTime &idate, Boolean verbose) { if (verbose) cout<<"Checking InstallDate " << idate.toString() << endl; cout<<"- No check written for InstallDate " << endl; return true; }
//------------------------------------------------------------------------------ void IPTestClient::_check_IPPEp_InstallDate(CIMDateTime &pv, Boolean verbose) { if (verbose) { cout << " >> checking CIM_IPProtocolEndpoint InstallDate `" << pv.toString() << "' . . ." << endl; } }
//------------------------------------------------------------------------------ void IPTestClient::_check_IPRoute_InstallDate(CIMDateTime &pv, Boolean verbose) { if (verbose) { cout << " >> checking PG_IPRoute InstallDate `" << pv.toString() << "' . . ." << endl; } }
/** goodCurrentTimeZone method of SunOS OS Provider Test Client Expect the timezone now to be identical to that returned. */ Boolean OSTestClient::goodCurrentTimeZone(const Sint16 &tz, Boolean verbose) { if (verbose) cout<<"Checking CurrentTimeZone " << tz << endl; CIMDateTime currentDT = CIMDateTime::getCurrentDateTime(); String ds = currentDT.toString(); // want timezone // cheat here since we know the position of the timezone info // subtracting '0' gets us the number from the ASCII, while // the multiplies do our shifts and we use the sign appropriately Sint32 calctz = ((ds[22]-'0') * 100 + (ds[23]-'0') * 10 + (ds[24]-'0')) * (ds[21]=='-'?-1:1); if (verbose) cout << " Should be " << calctz << endl; return (tz == calctz); }
Str(const CIMDateTime& x) : _cstr(x.toString().getCString()) { }
PEGASUS_NAMESPACE_BEGIN Boolean WQLInstancePropertySource::getValue( const CIMName& propertyName, WQLOperand& value) const { unsigned int pos=ci.findProperty(propertyName); if (pos==PEG_NOT_FOUND) return false; CIMValue val=ci.getProperty(pos).getValue(); CIMType type=val.getType(); if (val.isNull()) { value=WQLOperand(); return true; } if (val.isArray()) return false; switch (type) { case CIMTYPE_UINT8: Uint8 propertyValueUint8; val.get(propertyValueUint8); value=WQLOperand(propertyValueUint8,WQL_INTEGER_VALUE_TAG); break; case CIMTYPE_UINT16: Uint16 propertyValueUint16; val.get(propertyValueUint16); value=WQLOperand(propertyValueUint16, WQL_INTEGER_VALUE_TAG); break; case CIMTYPE_UINT32: Uint32 propertyValueUint32; val.get(propertyValueUint32); value=WQLOperand(propertyValueUint32, WQL_INTEGER_VALUE_TAG); break; case CIMTYPE_UINT64: Uint64 propertyValueUint64; val.get(propertyValueUint64); value=WQLOperand(propertyValueUint64, WQL_INTEGER_VALUE_TAG); break; case CIMTYPE_SINT8: Sint8 propertyValueSint8; val.get(propertyValueSint8); value=WQLOperand(propertyValueSint8, WQL_INTEGER_VALUE_TAG); break; case CIMTYPE_SINT16: Sint16 propertyValueSint16; val.get(propertyValueSint16); value=WQLOperand(propertyValueSint16, WQL_INTEGER_VALUE_TAG); break; case CIMTYPE_SINT32: Sint32 propertyValueSint32; val.get(propertyValueSint32); value=WQLOperand(propertyValueSint32, WQL_INTEGER_VALUE_TAG); break; case CIMTYPE_SINT64: Sint64 propertyValueSint64; val.get(propertyValueSint64); value=WQLOperand(propertyValueSint64, WQL_INTEGER_VALUE_TAG); break; case CIMTYPE_REAL32: Real32 propertyValueReal32; val.get(propertyValueReal32); value=WQLOperand(propertyValueReal32, WQL_DOUBLE_VALUE_TAG); break; case CIMTYPE_REAL64: Real64 propertyValueReal64; val.get(propertyValueReal64); value=WQLOperand(propertyValueReal64, WQL_DOUBLE_VALUE_TAG); break; case CIMTYPE_BOOLEAN : Boolean booleanValue; val.get(booleanValue); value=WQLOperand(booleanValue, WQL_BOOLEAN_VALUE_TAG); break; case CIMTYPE_CHAR16: { Char16 char16Value; val.get(char16Value); String str; str.append(char16Value); value=WQLOperand(str, WQL_STRING_VALUE_TAG); break; } case CIMTYPE_DATETIME : { CIMDateTime datetimeValue; val.get(datetimeValue); value=WQLOperand(datetimeValue.toString(),WQL_STRING_VALUE_TAG); break; } case CIMTYPE_STRING : { String strValue; val.get(strValue); value=WQLOperand(strValue,WQL_STRING_VALUE_TAG); break; } default: return false; } return true; }
String::String(const CIMDateTime& parm) : m_buf(NULL) { String s = parm.toString(); m_buf = s.m_buf; }
void OSInfoCommand::gatherProperties(CIMInstance &inst, Boolean cimFormat) { // don't have a try here - want it to be caught by caller // loop through the properties for (Uint32 j=0; j < inst.getPropertyCount(); j++) { CIMName propertyName = inst.getProperty(j).getName(); // only pull out those properties of interest if (propertyName.equal (CIMName ("CSName"))) { inst.getProperty(j).getValue().get(osCSName); } // end if CSName else if (propertyName.equal (CIMName ("Name"))) { inst.getProperty(j).getValue().get(osName); } // end if Name else if (propertyName.equal (CIMName ("NumberOfProcesses"))) { Uint32 propertyValue; inst.getProperty(j).getValue().get(propertyValue); char tmpString[80]; sprintf(tmpString, "%d processes", propertyValue); osNumberOfProcesses.assign(tmpString); } // end if NumberOfProcesses else if (propertyName.equal (CIMName ("NumberOfUsers"))) { Uint32 propertyValue; inst.getProperty(j).getValue().get(propertyValue); char tmpString[80]; sprintf(tmpString, "%d users", propertyValue); osNumberOfUsers.assign(tmpString); } // end if NumberOfUsers if (propertyName.equal (CIMName ("Version"))) { inst.getProperty(j).getValue().get(osVersion); } // end if Version else if (propertyName.equal (CIMName ("OperatingSystemCapability"))) { inst.getProperty(j).getValue().get(osCapability); } // end if OSCapability else if (propertyName.equal (CIMName ("OtherTypeDescription"))) { inst.getProperty(j).getValue().get(osOtherInfo); } // end if OtherTypeDescription else if (propertyName.equal (CIMName ("NumberOfLicensedUsers"))) { Uint32 propertyValue; inst.getProperty(j).getValue().get(propertyValue); // special consideration for HP-UX if (propertyValue == 0) { if (String::equalNoCase(osVersion,"HP-UX")) { osLicensedUsers.assign("128, 256, or unlimited users"); } else { osLicensedUsers.assign("Unlimited user license"); } } // end if 0 as number of licensed users else // standard number of users { char users[80]; sprintf(users, "%d users", propertyValue); osLicensedUsers.assign(users); } } // end if NumberOfLicensedUsers else if (propertyName.equal (CIMName ("LastBootUpTime"))) { CIMDateTime bdate; char bdateString[80]; inst.getProperty(j).getValue().get(bdate); CString dtStr = bdate.toString().getCString(); if (!cimFormat) { // else leave in raw CIM formatCIMDateTime(dtStr, bdateString); } else { sprintf(bdateString,"%s",(const char*)dtStr); } osBootUpTime.assign(bdateString); } // end if LastBootUpTime else if (propertyName.equal (CIMName ("LocalDateTime"))) { CIMDateTime ldate; char ldateString[80]; inst.getProperty(j).getValue().get(ldate); CString dtStr = ldate.toString().getCString(); if (!cimFormat) { // else leave in raw CIM formatCIMDateTime(dtStr, ldateString); } else { sprintf(ldateString,"%s",(const char*)dtStr); } osLocalDateTime.assign(ldateString); } // end if LocalDateTime else if (propertyName.equal (CIMName ("SystemUpTime"))) { Uint64 total; char uptime[80]; inst.getProperty(j).getValue().get(total); if (!cimFormat) { // else leave in raw CIM // let's make things a bit easier for our user to read Uint64 days = 0; Uint32 hours = 0; Uint32 minutes = 0; Uint32 seconds = 0; Uint64 totalSeconds = total; seconds = Uint32(total%60); total = total/60; minutes = Uint32(total%60); total = total/60; hours = Uint32(total%24); total = total/24; days = total; // now deal with the proper singular/plural char dayString[20]; char hourString[20]; char minuteString[20]; char secondString[20]; sprintf(dayString, (days == 0 ? "" : (days == 1 ? "1 day," : "%" PEGASUS_64BIT_CONVERSION_WIDTH "u days,")), days); // for other values, want to display the 0s sprintf(hourString, (hours == 1 ? "1 hr," : "%u hrs,"), hours); sprintf(minuteString, (minutes == 1 ? "1 min," : "%u mins,"), minutes); sprintf(secondString, (seconds == 1 ? "1 sec" : "%u secs"), seconds); sprintf(uptime, "%" PEGASUS_64BIT_CONVERSION_WIDTH "u seconds = %s %s %s %s", totalSeconds, dayString, hourString, minuteString, secondString); osSystemUpTime.assign(uptime); } // end of if wanted nicely formatted vs. raw CIM else { sprintf(uptime, "%" PEGASUS_64BIT_CONVERSION_WIDTH "u", total); } osSystemUpTime.assign(uptime); } // end if SystemUpTime } // end of for looping through properties }
String IndicationFormatter::_localizeDateTime( const CIMDateTime & propertyValueDateTime, const Locale & locale) { PEG_METHOD_ENTER (TRC_IND_FORMATTER, "IndicationFormatter::_localizeDateTime"); // Convert dateTimeValue to be microSeconds, // the number of microseconds from the epoch starting // 0/0/0000 (12 am Jan 1, 1BCE) // CIMDateTime dateTimeValue = propertyValueDateTime; Uint64 dateTimeValueInMicroSecs = dateTimeValue.toMicroSeconds(); // In ICU, as UTC milliseconds from the epoch starting // (1 January 1970 0:00 UTC) CIMDateTime dt; dt.set("19700101000000.000000+000"); // Convert dateTimeValue to be milliSeconds, // the number of milliSeconds from the epoch starting // (1 January 1970 0:00 UTC) UDate dateTimeValueInMilliSecs = (Sint64)(dateTimeValueInMicroSecs - dt.toMicroSeconds())/1000; // Create a formatter for DATE and TIME with medium length // such as Jan 12, 1952 3:30:32pm DateFormat *fmt; try { if (locale == 0) { fmt = DateFormat::createDateTimeInstance(DateFormat::MEDIUM, DateFormat::MEDIUM); } else { fmt = DateFormat::createDateTimeInstance(DateFormat::MEDIUM, DateFormat::MEDIUM, locale); } } catch(Exception& e) { PEG_TRACE_STRING(TRC_IND_FORMATTER, Tracer::LEVEL4, e.getMessage()); PEG_METHOD_EXIT(); return (dateTimeValue.toString()); } catch(...) { PEG_TRACE_STRING(TRC_IND_FORMATTER, Tracer::LEVEL4, "Caught General Exception During DateFormat::createDateTimeInstance"); PEG_METHOD_EXIT(); return (dateTimeValue.toString()); } if (fmt == 0) { PEG_TRACE_STRING(TRC_IND_FORMATTER, Tracer::LEVEL4, "Memory allocation error creating DateTime instance."); PEG_METHOD_EXIT(); return (dateTimeValue.toString()); } // Format the Date and Time UErrorCode status = U_ZERO_ERROR; UnicodeString dateTimeUniStr; fmt->format(dateTimeValueInMilliSecs, dateTimeUniStr, status); if (U_FAILURE(status)) { delete fmt; PEG_METHOD_EXIT(); return (dateTimeValue.toString()); } // convert UnicodeString to char * char dateTimeBuffer[256]; char *extractedStr = 0; // Copy the contents of the string into dateTimeBuffer Uint32 strLen = dateTimeUniStr.extract(0, sizeof(dateTimeBuffer), dateTimeBuffer); // There is not enough space in dateTimeBuffer if (strLen > sizeof(dateTimeBuffer)) { extractedStr = new char[strLen + 1]; strLen = dateTimeUniStr.extract(0, strLen + 1, extractedStr); } else { extractedStr = dateTimeBuffer; } String datetimeStr = extractedStr; if (extractedStr != dateTimeBuffer) { delete extractedStr; } delete fmt; PEG_METHOD_EXIT(); return (datetimeStr); }