MotorControlModuleSDFM_TMS3.../Projects/EFC_Communication/UMLibrary/systemic/SystemException.hh
2024-06-07 11:12:56 +03:00

78 lines
2.0 KiB
C++
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

/*
* SystemException.hh
*
* Created on: 8 сент. 2020 г.
* Author: LeonidTitov
*/
#ifndef UMLIBRARY_SYSTEMIC_SYSTEMEXCEPTION_HH_
#define UMLIBRARY_SYSTEMIC_SYSTEMEXCEPTION_HH_
#include <exception>
#include <utility>
#include <cstddef>
namespace systemic {
struct SystemException : public std::exception {
virtual std::size_t id() const noexcept = 0;
virtual std::pair<const char *, std::size_t> binary() const noexcept = 0;
};
struct ExceptionInfo {
virtual bool raised() const = 0;
virtual std::size_t id() const = 0;
virtual std::pair<const char *, std::size_t> binary() const = 0;
virtual const char * description() const = 0;
};
class ExceptionHandler : public ExceptionInfo {
public:
//!Обработка исключения.
void insert( std::size_t id, const char * data, std::size_t size, const char * description );
//!Обработка исключения.
void handle( const std::exception & exception ) noexcept;
void notify() noexcept;
struct NotificationInterface {
virtual void notify( std::size_t id, const char * data, std::size_t size, const char * description ) = 0;
virtual ~NotificationInterface() = default;
};
static NotificationInterface & getDefault() {
struct DefaultHerald : public NotificationInterface {
void notify( std::size_t id, const char * data, std::size_t size, const char * description ) {}
};
static DefaultHerald herald;
return herald;
}
ExceptionHandler( char * buffer, std::size_t size, NotificationInterface & herald = getDefault() );
bool raised() const;
std::size_t id() const;
std::pair<const char *, std::size_t> binary() const;
const char * description() const;
private:
NotificationInterface & herald;
std::size_t exception_id;
std::size_t exception_size;
const std::pair<char *, std::size_t> buffer;
const char * what_happens = nullptr;
bool is_handled = false;
};
}
#endif /* UMLIBRARY_SYSTEMIC_SYSTEMEXCEPTION_HH_ */