151 lines
4.5 KiB
C++
151 lines
4.5 KiB
C++
/*
|
|
* FailureManager.cpp
|
|
*
|
|
* Created on: 4 îêò. 2019 ã.
|
|
* Author: titov
|
|
*/
|
|
|
|
#include "FailureManager.hh"
|
|
#include <stdexcept>
|
|
|
|
using processing::failure::FailureManager;
|
|
|
|
FailureManager::FailureManager(
|
|
driver::safety::ITermination & terminator,
|
|
std::pmr::memory_resource * memory ) : failures( FaliureRecords::allocator_type(memory) ),
|
|
failure_stored(false), terminator(terminator) {}
|
|
|
|
FailureManager::FailureIterator::FailureIterator( FailureId pos, const FaliureRecords & records ) : position(pos), records(records) {}
|
|
|
|
bool FailureManager::FailureIterator::operator !=(
|
|
const FailureIterator & rhs ) const {
|
|
return position != rhs.position;
|
|
}
|
|
|
|
processing::failure::FailureId FailureManager::FailureIterator::operator *() const {
|
|
return records[position].first;
|
|
}
|
|
|
|
const FailureManager::FailureIterator & FailureManager::FailureIterator::operator ++() {
|
|
while( ++position < records.size() and not check() );
|
|
return *this;
|
|
}
|
|
|
|
FailureManager::FailureIterator FailureManager::FailureStoredConteiner::begin() const {
|
|
FailureId position = 0u;
|
|
if( not records.empty() ) while( not records[position].second->stored() and ++position < records.size() );
|
|
return FailureIterator( position, records );
|
|
}
|
|
|
|
|
|
FailureManager::FailureIterator FailureManager::FailureStoredConteiner::end() const {
|
|
return FailureIterator( records.size(), records );
|
|
}
|
|
|
|
unsigned int FailureManager::FailureStoredConteiner::getFailureCount() const {
|
|
FailureId n = 0;
|
|
|
|
for( int i = 0; i < records.size(); i++ )
|
|
if( records[i].second->stored() )
|
|
++n;
|
|
|
|
return n;
|
|
}
|
|
|
|
bool FailureManager::isFailureActual() const {
|
|
|
|
bool failure_actual = false;
|
|
|
|
for( FaliureRecords::const_iterator iter = failures.begin(); iter != failures.end() and not failure_actual; ++iter )
|
|
failure_actual = iter->second->actual() or failure_actual;
|
|
|
|
return failure_actual;
|
|
}
|
|
|
|
bool FailureManager::isFailureStored() const {
|
|
return failure_stored;
|
|
}
|
|
|
|
bool FailureManager::checkFailureStored(FailureId id) const {
|
|
FailureId position = 0u;
|
|
if( not failures.empty() ) while( failures[position].first != id and ++position < failures.size() );
|
|
|
|
return position < failures.size() ? failures[position].second->stored() : false;
|
|
}
|
|
|
|
FailureManager::FailureStoredConteiner FailureManager::getFailureStoredId() const {
|
|
return FailureStoredConteiner( failures );
|
|
}
|
|
//
|
|
//FailureManager::FailureUpdateConteiner FailureManager::getFailureUpdateId() const {
|
|
// return FailureUpdateConteiner( failures );
|
|
//}
|
|
|
|
void FailureManager::acknowledge() {
|
|
bool failure_actual = false;
|
|
|
|
for( FaliureRecords::iterator iter = failures.begin(); iter != failures.end(); ++iter ) {
|
|
|
|
FaliureInterface & failure = *iter->second;
|
|
|
|
failure_actual = not failure.acknowledge() || failure_actual;
|
|
|
|
}
|
|
|
|
if( not failure_actual and failure_stored ) {
|
|
failure_stored = false;
|
|
|
|
terminator.recovery();
|
|
}
|
|
}
|
|
|
|
void FailureManager::fault() {
|
|
|
|
if( not failure_stored ) {
|
|
terminator.terminate();
|
|
|
|
failure_stored = true;
|
|
}
|
|
}
|
|
|
|
void FailureManager::registration( FailureId failure_id, FaliureInterface * failure ) {
|
|
|
|
if( not failure )
|
|
throw std::domain_error("Failure is nullptr");
|
|
|
|
failures.push_back( std::make_pair(failure_id, failure) );
|
|
|
|
}
|
|
|
|
//todo: ïîäóìàòü î êîïèðîâàíèè, äëÿ ñíÿòèÿ ìíãíîâåííîãî ñíèìêà îòêàçîâ, ÷òî áû äàëüøå ðàáîòàòü ñ êîïèåé.
|
|
FailureManager::FailureStoredConteiner::FailureStoredConteiner(
|
|
const FaliureRecords &records) :
|
|
records(records) {}
|
|
|
|
bool processing::failure::FailureManager::FailureIterator::check() {
|
|
return records[position].second->stored();
|
|
}
|
|
|
|
bool processing::failure::FailureManager::FailureTickedIterator::check() {
|
|
return records[position].second->ticket();
|
|
}
|
|
|
|
FailureManager::FailureTickedIterator processing::failure::FailureManager::FailureTickedConteiner::begin() const {
|
|
FailureId position = 0u;
|
|
if( not records.empty() ) while( not records[position].second->ticket() and ++position < records.size() );
|
|
return FailureTickedIterator( position, records );
|
|
}
|
|
|
|
FailureManager::FailureTickedIterator processing::failure::FailureManager::FailureTickedConteiner::end() const {
|
|
return FailureTickedIterator( records.size(), records );
|
|
}
|
|
|
|
processing::failure::FailureManager::FailureTickedConteiner::FailureTickedConteiner(
|
|
const FaliureRecords & records) : records(records)
|
|
{
|
|
}
|
|
|
|
FailureManager::FailureTickedConteiner processing::failure::FailureManager::getFailureTickedId() const {
|
|
return FailureManager::FailureTickedConteiner( failures );
|
|
}
|