health table update

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

View File

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

View File

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