Commit a77e7ee8 authored by Michael Ott's avatar Michael Ott

Add LenovoXCC object to IPMIHost so it doesn't have to be created on every single call

parent e705789f
......@@ -27,6 +27,7 @@
#include "IPMIHost.h"
#include "timestamp.h"
#include "LenovoXCC.h"
#include <cerrno>
#include <cstdio>
......@@ -58,7 +59,8 @@ IPMIHost::IPMIHost(const std::string &name)
_sessionTimeout(0),
_retransmissionTimeout(0),
_errorCount(0),
_delayNextReadUntil(0) {
_delayNextReadUntil(0),
_xcc(nullptr) {
}
IPMIHost::IPMIHost(const IPMIHost &other)
......@@ -75,10 +77,15 @@ IPMIHost::IPMIHost(const IPMIHost &other)
_sessionTimeout(other._sessionTimeout),
_retransmissionTimeout(other._retransmissionTimeout),
_errorCount(0),
_delayNextReadUntil(other._delayNextReadUntil) {
_delayNextReadUntil(other._delayNextReadUntil),
_xcc(other._xcc) {
}
IPMIHost::~IPMIHost() {}
IPMIHost::~IPMIHost() {
if (_xcc != nullptr) {
delete _xcc;
}
}
IPMIHost &IPMIHost::operator=(const IPMIHost &other) {
EntityInterface::operator=(other);
......@@ -95,6 +102,7 @@ IPMIHost &IPMIHost::operator=(const IPMIHost &other) {
_retransmissionTimeout = other._retransmissionTimeout;
_errorCount = 0;
_delayNextReadUntil = other._delayNextReadUntil;
_xcc = other._xcc;
return *this;
}
......
......@@ -34,6 +34,8 @@
#include <list>
#include <string>
class LenovoXCC;
/**
* @brief Handles all connections to the same IPMI host.
*
......@@ -67,6 +69,7 @@ class IPMIHost : public EntityInterface {
void setSessionTimeout(uint32_t sessionTimeout) { _sessionTimeout = sessionTimeout; }
void setRetransmissionTimeout(uint32_t retransmissionTimeout) { _retransmissionTimeout = retransmissionTimeout; }
void setDelayNextReadUntil(uint64_t delayNextReadUntil) { _delayNextReadUntil = delayNextReadUntil; }
void setXCC(LenovoXCC* xcc) { _xcc = xcc; }
uint8_t getAuth() const { return _auth; }
const std::string &getHostName() const { return _name; }
......@@ -77,6 +80,7 @@ class IPMIHost : public EntityInterface {
uint8_t getIpmiVersion() const { return _ipmiVersion; }
const std::string &getUserName() const { return _userName; }
uint64_t getDelayNextReadUntil() const { return _delayNextReadUntil; }
LenovoXCC* getXCC() { return _xcc; }
void printEntityConfig(LOG_LEVEL ll, unsigned int leadingSpaces) final override;
......@@ -105,6 +109,7 @@ class IPMIHost : public EntityInterface {
uint32_t _errorCount;
std::string _errorMsg;
volatile uint64_t _delayNextReadUntil;
LenovoXCC* _xcc;
};
#endif /* IPMIHOST_H_ */
......@@ -104,7 +104,7 @@ void IPMISensorGroup::read() {
case IPMISensorBase::sensorType::xccDatastorePower: {
std::vector<reading_t> readings;
LenovoXCC xcc(_entity);
if (xcc.getDatastorePower(readings) == 0) {
if (_entity->getXCC()->getDatastorePower(readings) == 0) {
for (int i=0; i<readings.size(); i++) {
s->storeReading(readings[i], s->getFactor());
}
......@@ -113,16 +113,14 @@ void IPMISensorGroup::read() {
break;
}
case IPMISensorBase::sensorType::xccSingleEnergy: {
LenovoXCC xcc(_entity);
if (xcc.getSingleEnergy(reading) == 0) {
if (_entity->getXCC()->getSingleEnergy(reading) == 0) {
s->storeReading(reading, s->getFactor());
}
break;
}
case IPMISensorBase::sensorType::xccBulkPower: {
std::vector<reading_t> readings;
LenovoXCC xcc(_entity);
if (xcc.getBulkPower(readings) == 0) {
if (_entity->getXCC()->getBulkPower(readings) == 0) {
for (unsigned int i=0; i<readings.size(); i++) {
s->storeReading(readings[i], s->getFactor());
}
......@@ -132,8 +130,7 @@ void IPMISensorGroup::read() {
}
case IPMISensorBase::sensorType::xccBulkEnergy: {
std::vector<reading_t> readings;
LenovoXCC xcc(_entity);
if (xcc.getBulkEnergy(readings) == 0) {
if (_entity->getXCC()->getBulkEnergy(readings) == 0) {
for (unsigned int i=0; i<readings.size(); i++) {
s->storeReading(readings[i], s->getFactor());
}
......@@ -205,3 +202,20 @@ bool IPMISensorGroup::checkConfig() {
}
return true;
}
void IPMISensorGroup::execOnInit() {
for (const auto &s : _sensors) {
switch(s->getType()) {
case IPMISensorBase::sensorType::xccDatastorePower:
case IPMISensorBase::sensorType::xccSingleEnergy:
case IPMISensorBase::sensorType::xccBulkPower:
case IPMISensorBase::sensorType::xccBulkEnergy:
if (_entity->getXCC() == nullptr) {
_entity->setXCC(new LenovoXCC(_entity));
}
break;
default:
break;
}
}
}
......@@ -45,6 +45,7 @@ class IPMISensorGroup : public SensorGroupTemplateEntity<IPMISensorBase, IPMIHos
IPMISensorGroup &operator=(const IPMISensorGroup &other);
uint64_t nextReadingTime() override;
bool checkConfig();
void execOnInit() final override;
private:
void read() final override;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment