Files
externals/linux/include/OnixS/CME/MDP3/AsyncLog.h
T
2017-08-09 14:33:06 +00:00

161 lines
5.8 KiB
C++
Executable File

// Copyright Onix Solutions Limited [OnixS]. All rights reserved.
//
// This software owned by Onix Solutions Limited [OnixS] and is protected by copyright law
// and international copyright treaties.
//
// Access to and use of the software is governed by the terms of the applicable OnixS Software
// Services Agreement (the Agreement) and Customer end user license agreements granting
// a non-assignable, non-transferable and non-exclusive license to use the software
// for it's own data processing purposes under the terms defined in the Agreement.
//
// Except as otherwise granted within the terms of the Agreement, copying or reproduction of any part
// of this source code or associated reference material to any other location for further reproduction
// or redistribution, and any amendments to this copyright notice, are expressly prohibited.
//
// Any reproduction or redistribution for sale or hiring of the Software not in accordance with
// the terms of the Agreement is a violation of copyright law.
//
#pragma once
#include "OnixS/CME/MDP3/Types.h"
#include "OnixS/CME/MDP3/ThreadAffinity.h"
namespace OnixS
{
namespace CME
{
namespace MDP3
{
/// Asynchronous logging service configuration settings.
struct
ONIXS_CME_MDP3_API
AsyncLogSettings
{
/// Minimal interval between the moment when log entry is passed
/// to log service and moment when it is written to the disk.
///
/// Interval is measured in milliseconds.
///
/// @note Default value is '100'.
unsigned int flushTimeoutInterval() const
{
return flushTimeoutInterval_;
}
/// Sets flushTimeoutInterval. @see flushTimeoutInterval.
void flushTimeoutInterval(unsigned int value)
{
flushTimeoutInterval_ = value;
}
/// Preferred amount of allocated log entries per handler instance.
/// Asynchronous logging service uses pool to minimize memory allocations
/// and reuse log entries memory. When handler instance is bound to async
/// logging service this amount of log entries is preallocated. When pool
/// size exceeds this amount unused extra entries start freeing.
///
/// @note Default value is '256'.
unsigned int preferredPoolSize() const
{
return preferredPoolSize_;
}
/// Sets preferredPoolSize. @see preferredPoolSize.
void preferredPoolSize(unsigned int value)
{
preferredPoolSize_ = value;
}
/// Defines set of CPUs by their indices (starting from zero)
/// allowed for asynchronous logging thread to be executed on.
///
/// @note By default set is empty thus allowing thread
/// to be executed on any CPU available in the system.
const ThreadAffinity& threadAffinity() const
{
return threadAffinity_;
}
/// @see threadAffinity.
ThreadAffinity& threadAffinity()
{
return threadAffinity_;
}
/// Initializes parameters with default values.
AsyncLogSettings();
/// Cleans everything up.
~AsyncLogSettings();
/// Returns textual presentation.
std::string toString() const
{
std::string str;
toString(str);
return str;
}
/// Returns textual presentation.
void toString(std::string&) const;
private:
unsigned int flushTimeoutInterval_;
unsigned int preferredPoolSize_;
ThreadAffinity threadAffinity_;
};
ONIXS_CME_MDP3_API_DECL(class, AsyncLogService);
ONIXS_CME_MDP3_API_DECL(class, Error);
/// Listener for Asynchronous Logging Service thread-related events.
class
ONIXS_CME_MDP3_API
AsyncLogListener
{
public:
/// Member invoked by Asynchronous Logging Service when
/// error occurred while processing log entries.
virtual
void
onAsyncLogError(
const AsyncLogService& source,
const Error& error) = 0;
protected:
virtual ~AsyncLogListener();
};
/// Asynchronous Logging Service.
///
/// @note Starts separate auxiliary thread performing
/// disk I/O operations on background.
class
ONIXS_CME_MDP3_API
AsyncLogService
{
public:
class Implementation;
/// Initializes instance according to given settings.
AsyncLogService(
const AsyncLogSettings& settings,
AsyncLogListener* listener = NULL);
/// Destructor.
~AsyncLogService();
private:
friend class Implementation;
Implementation* impl_;
AsyncLogService(const AsyncLogService&);
AsyncLogService& operator =(const AsyncLogService&);
};
}
}
}