health changes taken over

This commit is contained in:
Robin Müller 2020-11-02 15:47:09 +01:00
parent e0a11f3a6e
commit aed7f31f24
2 changed files with 17 additions and 7 deletions

View File

@ -10,6 +10,12 @@ HealthTable::HealthTable(object_id_t objectid) :
mapIterator = healthMap.begin();
}
void HealthTable::setMutexTimeout(MutexIF::TimeoutType timeoutType,
uint32_t timeoutMs) {
this->timeoutType = timeoutType;
this->mutexTimeoutMs = timeoutMs;
}
HealthTable::~HealthTable() {
MutexFactory::instance()->deleteMutex(mutex);
}
@ -25,7 +31,7 @@ ReturnValue_t HealthTable::registerObject(object_id_t object,
void HealthTable::setHealth(object_id_t object,
HasHealthIF::HealthState newState) {
MutexHelper(mutex, MutexIF::TimeoutType::WAITING, 20);
MutexHelper(mutex, timeoutType, mutexTimeoutMs);
HealthMap::iterator iter = healthMap.find(object);
if (iter != healthMap.end()) {
iter->second = newState;
@ -34,7 +40,7 @@ void HealthTable::setHealth(object_id_t object,
HasHealthIF::HealthState HealthTable::getHealth(object_id_t object) {
HasHealthIF::HealthState state = HasHealthIF::HEALTHY;
MutexHelper(mutex, MutexIF::TimeoutType::WAITING, 20);
MutexHelper(mutex, timeoutType, mutexTimeoutMs);
HealthMap::iterator iter = healthMap.find(object);
if (iter != healthMap.end()) {
state = iter->second;
@ -42,9 +48,8 @@ HasHealthIF::HealthState HealthTable::getHealth(object_id_t object) {
return state;
}
bool HealthTable::hasHealth(object_id_t object) {
MutexHelper(mutex, MutexIF::TimeoutType::WAITING, 20);
MutexHelper(mutex, timeoutType, mutexTimeoutMs);
HealthMap::iterator iter = healthMap.find(object);
if (iter != healthMap.end()) {
return true;
@ -53,14 +58,14 @@ bool HealthTable::hasHealth(object_id_t object) {
}
size_t HealthTable::getPrintSize() {
MutexHelper(mutex, MutexIF::TimeoutType::WAITING, 20);
MutexHelper(mutex, timeoutType, mutexTimeoutMs);
uint32_t size = healthMap.size() * sizeof(object_id_t) +
sizeof(HasHealthIF::HealthState) + sizeof(uint16_t);
return size;
}
void HealthTable::printAll(uint8_t* pointer, size_t maxSize) {
MutexHelper(mutex, MutexIF::TimeoutType::WAITING, 20);
MutexHelper(mutex, timeoutType, mutexTimeoutMs);
size_t size = 0;
uint16_t count = healthMap.size();
SerializeAdapter::serialize(&count,
@ -76,7 +81,7 @@ void HealthTable::printAll(uint8_t* pointer, size_t maxSize) {
ReturnValue_t HealthTable::iterate(HealthEntry *value, bool reset) {
ReturnValue_t result = HasReturnvaluesIF::RETURN_OK;
MutexHelper(mutex, MutexIF::TimeoutType::WAITING, 20);
MutexHelper(mutex, timeoutType, mutexTimeoutMs);
if (reset) {
mapIterator = healthMap.begin();
}

View File

@ -12,6 +12,8 @@ public:
HealthTable(object_id_t objectid);
virtual ~HealthTable();
void setMutexTimeout(MutexIF::TimeoutType timeoutType, uint32_t timeoutMs);
/** HealthTableIF overrides */
virtual ReturnValue_t registerObject(object_id_t object,
HasHealthIF::HealthState initilialState =
@ -30,6 +32,9 @@ protected:
using HealthEntry = std::pair<object_id_t, HasHealthIF::HealthState>;
MutexIF* mutex;
MutexIF::TimeoutType timeoutType = MutexIF::TimeoutType::WAITING;
uint32_t mutexTimeoutMs = 20;
HealthMap healthMap;
HealthMap::iterator mapIterator;