/* * Retrieve a specific instance given an object path */ wbem::framework::Instance* wbem::support::NVDIMMSensorViewFactory::getInstance( framework::ObjectPath &path, framework::attribute_names_t &attributes) throw (wbem::framework::Exception) { LogEnterExit logging(__FUNCTION__, __FILE__, __LINE__); framework::Instance *pInstance = new framework::Instance(path); try { // Get the sensorViewAttributes checkAttributes(attributes); framework::Attribute attribute = path.getKeyValue(DEVICEID_KEY); std::string guidStr; enum sensor_type type; if(!NVDIMMSensorFactory::splitDeviceIdAttribute(attribute, guidStr, (int &)type)) { throw framework::ExceptionBadParameter(DEVICEID_KEY.c_str()); } NVM_GUID guid; str_to_guid(guidStr.c_str(), guid); struct sensor sensor; int rc = NVM_SUCCESS; if ((rc = nvm_get_sensor(guid, type, &sensor)) != NVM_SUCCESS) { throw exception::NvmExceptionLibError(rc); } // DimmID = handle or guid depending on user selection if (containsAttribute(DIMMID_KEY, attributes)) { framework::Attribute attrDimmId = physical_asset::NVDIMMFactory::guidToDimmIdAttribute(guidStr); pInstance->setAttribute(DIMMID_KEY, attrDimmId, attributes); } // DimmGUID if (containsAttribute(DIMMGUID_KEY, attributes)) { framework::Attribute attrDimmHandle(guidStr, false); pInstance->setAttribute(DIMMGUID_KEY, attrDimmHandle, attributes); } // DimmHandle = NFIT Handle if (containsAttribute(DIMMHANDLE_KEY, attributes)) { NVM_UINT32 handle; physical_asset::NVDIMMFactory::guidToHandle(guidStr, handle); framework::Attribute attrDimmHandle(handle, false); pInstance->setAttribute(DIMMHANDLE_KEY, attrDimmHandle, attributes); } if (containsAttribute(TYPE_KEY, attributes)) { framework::Attribute a(getSensorNameStr(type), false); pInstance->setAttribute(TYPE_KEY, a, attributes); } if (containsAttribute(CURRENTVALUE_KEY, attributes)) { std::stringstream currentValue; if (sensor.units == UNIT_SECONDS) { // convert to HH:MM:SS, note HH can grow beyond 2 digits which is fine. NVM_UINT64 hours, minutes, seconds, remainder = 0; // 60 seconds in a minute, 60 minutes in an hour hours = sensor.reading / (60*60); remainder = sensor.reading % (60*60); minutes = remainder / 60; seconds = remainder % 60; currentValue << std::setfill('0') << std::setw(2) << hours << ":"; currentValue << std::setfill('0') << std::setw(2) << minutes << ":"; currentValue << std::setfill('0') << std::setw(2) << seconds; } else if (sensor.type == SENSOR_MEDIA_TEMPERATURE || sensor.type == SENSOR_CONTROLLER_TEMPERATURE) { float celsius = nvm_decode_temperature(sensor.reading); currentValue << celsius << baseUnitToString(sensor.units); } else { NVM_INT32 scaled = 0; NVM_INT32 scaler = 0; NVDIMMSensorFactory::scaleNumberBaseTen(sensor.reading, &scaled, &scaler); currentValue << scaled << baseUnitToString(sensor.units); if (scaler > 0) { currentValue << "* 10 ^" << scaler; } } framework::Attribute a(currentValue.str(), false); pInstance->setAttribute(CURRENTVALUE_KEY, a, attributes); } if (containsAttribute(ENABLEDSTATE_KEY, attributes)) { std::string enabledState; if ((sensor.type == SENSOR_MEDIA_TEMPERATURE) || (sensor.type == SENSOR_SPARECAPACITY) || (sensor.type == SENSOR_CONTROLLER_TEMPERATURE)) { enabledState = getEnabledStateStr( sensor.settings.enabled ? SENSOR_ENABLEDSTATE_ENABLED : SENSOR_ENABLEDSTATE_DISABLED); } else { enabledState = getEnabledStateStr(SENSOR_ENABLEDSTATE_NA); } framework::Attribute a(enabledState, false); pInstance->setAttribute(ENABLEDSTATE_KEY, a, attributes); } if (containsAttribute(LOWERTHRESHOLDCRITICAL_KEY, attributes)) { framework::Attribute a(sensor.settings.lower_critical_threshold, false); pInstance->setAttribute(LOWERTHRESHOLDCRITICAL_KEY, a, attributes); } if (containsAttribute(UPPERTHRESHOLDCRITICAL_KEY, attributes)) { if (sensor.type == SENSOR_MEDIA_TEMPERATURE || sensor.type == SENSOR_CONTROLLER_TEMPERATURE) { float celsius = nvm_decode_temperature(sensor.settings.upper_critical_threshold); pInstance->setAttribute(UPPERTHRESHOLDCRITICAL_KEY, framework::Attribute (celsius, false), attributes); } else { pInstance->setAttribute(UPPERTHRESHOLDCRITICAL_KEY, framework::Attribute (sensor.settings.upper_critical_threshold, false), attributes); } } if (containsAttribute(CURRENTSTATE_KEY, attributes)) { framework::Attribute a(NVDIMMSensorFactory::getSensorStateStr(sensor.current_state), false); pInstance->setAttribute(CURRENTSTATE_KEY, a, attributes); } if (containsAttribute(SUPPORTEDTHRESHOLDS_KEY, attributes)) { framework::STR_LIST supportedThresholds; if (sensor.lower_critical_support) { supportedThresholds.push_back(getThresholdTypeStr(SENSOR_LOWER_CRITICAL_THRESHOLD)); } if (sensor.upper_critical_support) { supportedThresholds.push_back(getThresholdTypeStr(SENSOR_UPPER_CRITICAL_THRESHOLD)); } framework::Attribute a(supportedThresholds, false); pInstance->setAttribute(SUPPORTEDTHRESHOLDS_KEY, a, attributes); } if (containsAttribute(SETTABLETHRESHOLDS_KEY, attributes)) { framework::STR_LIST settableThresholds; if (sensor.lower_critical_settable) { settableThresholds.push_back(getThresholdTypeStr(SENSOR_LOWER_CRITICAL_THRESHOLD)); } if (sensor.upper_critical_settable) { settableThresholds.push_back(getThresholdTypeStr(SENSOR_UPPER_CRITICAL_THRESHOLD)); } framework::Attribute a(settableThresholds, false); pInstance->setAttribute(SETTABLETHRESHOLDS_KEY, a, attributes); } } catch (framework::Exception &) // clean up and re-throw { if (pInstance != NULL) { delete pInstance; } throw; } return pInstance; }
int LibWrapper::getSensor(const NVM_UID deviceUid, const enum sensor_type type, struct sensor *pSensor) const { LogEnterExit(__FUNCTION__, __FILE__, __LINE__); return nvm_get_sensor(deviceUid, type, pSensor); }