92 lines
1.8 KiB
C++
92 lines
1.8 KiB
C++
/*
|
||
* SystemException.cpp
|
||
*
|
||
* Created on: 8 сент. 2020 г.
|
||
* Author: LeonidTitov
|
||
*/
|
||
|
||
#include "SystemException.hh"
|
||
|
||
#include <cstring>
|
||
|
||
void systemic::ExceptionHandler::handle( const std::exception & exception ) noexcept {
|
||
|
||
if( is_handled )
|
||
return;
|
||
|
||
what_happens = exception.what();
|
||
|
||
const SystemException * system_exception = dynamic_cast<const SystemException *>( &exception );
|
||
|
||
std::pair<const char *, std::size_t> data( nullptr, 0 );
|
||
|
||
if( system_exception ) {
|
||
|
||
exception_id = system_exception->id();
|
||
|
||
data = system_exception->binary();
|
||
|
||
if( buffer.second >= data.second )
|
||
std::memcpy( buffer.first, data.first, exception_size = data.second );
|
||
|
||
}
|
||
|
||
is_handled = true;
|
||
|
||
notify();
|
||
|
||
}
|
||
|
||
systemic::ExceptionHandler::ExceptionHandler( char * buffer, std::size_t size, NotificationInterface & herald )
|
||
: buffer( buffer, size ), herald(herald) {}
|
||
|
||
|
||
bool systemic::ExceptionHandler::raised() const {
|
||
|
||
return is_handled;
|
||
|
||
}
|
||
|
||
std::size_t systemic::ExceptionHandler::id() const {
|
||
|
||
return exception_id;
|
||
|
||
}
|
||
|
||
std::pair<const char *, std::size_t> systemic::ExceptionHandler::binary() const {
|
||
|
||
return { buffer.first, exception_size };
|
||
|
||
}
|
||
|
||
const char * systemic::ExceptionHandler::description() const {
|
||
|
||
return what_happens;
|
||
|
||
}
|
||
|
||
void systemic::ExceptionHandler::insert( std::size_t id, const char * data,
|
||
std::size_t size,
|
||
const char * description ) {
|
||
|
||
exception_id = id;
|
||
|
||
if( size < buffer.second )
|
||
std::memcpy( buffer.first, data, exception_size = size );
|
||
|
||
what_happens = description;
|
||
|
||
is_handled = true;
|
||
|
||
}
|
||
|
||
void systemic::ExceptionHandler::notify() noexcept {
|
||
|
||
try {
|
||
|
||
herald.notify( exception_id, buffer.first, exception_size, what_happens );
|
||
|
||
} catch( ... ) {}
|
||
|
||
}
|