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

68 lines
1.6 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.

/*
* MemoryLogHandler.h
*
* Created on: 24 апр. 2020 г.
* Author: AAM
*/
#ifndef LOGGING_MEMORYLOGHANDLER_H_
#define LOGGING_MEMORYLOGHANDLER_H_
#include <memory_resource>
#include <map>
#include <deque>
#include <vector>
#include <functional>
#include <mutex>
#include "ILogHandler.hh"
#include "StorageManager.hh"
namespace logging {
class MemoryLogHandler : public ILogHandler {
public:
enum ACCUMULATION_POLICY {
RESTRICTIVE = 0,
EXPANSION = 1
};
private:
std::size_t records_balance;
std::size_t records_capacity;
ACCUMULATION_POLICY accum_policy;
std::mutex lock;
typedef std::vector< char, std::pmr::polymorphic_allocator<char> > RecordData;
typedef std::deque< RecordData, std::pmr::polymorphic_allocator<RecordData> > Records;
typedef std::map< base::record_priority, Records, std::greater<base::record_priority>,
std::pmr::polymorphic_allocator< std::pair< const base::record_priority, Records > >
> Collection;
Collection records;
StorageManager & storage;
public:
MemoryLogHandler( StorageManager &, std::pmr::memory_resource *, std::size_t );
/* Разместь журнальную запись в памяти хранилища. */
void publish( const LogRecord & );
/* Очистить память хранилища от записей.*/
void flush();
void process();
/* Установить вместительность сообщений. */
void set_capacity( std::size_t );
void set_accumulation_policy( ACCUMULATION_POLICY );
};
}
#endif /* LOGGING_MEMORYLOGHANDLER_H_ */