123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187 |
- #ifndef BOOST_LOG_SINKS_SYNC_FRONTEND_HPP_INCLUDED_
- #define BOOST_LOG_SINKS_SYNC_FRONTEND_HPP_INCLUDED_
- #include <boost/log/detail/config.hpp>
- #ifdef BOOST_HAS_PRAGMA_ONCE
- #pragma once
- #endif
- #if defined(BOOST_LOG_NO_THREADS)
- #error Boost.Log: Synchronous sink frontend is only supported in multithreaded environment
- #endif
- #include <boost/static_assert.hpp>
- #include <boost/smart_ptr/shared_ptr.hpp>
- #include <boost/smart_ptr/make_shared_object.hpp>
- #include <boost/preprocessor/control/if.hpp>
- #include <boost/preprocessor/comparison/equal.hpp>
- #include <boost/thread/recursive_mutex.hpp>
- #include <boost/log/detail/locking_ptr.hpp>
- #include <boost/log/detail/parameter_tools.hpp>
- #include <boost/log/core/record_view.hpp>
- #include <boost/log/sinks/basic_sink_frontend.hpp>
- #include <boost/log/sinks/frontend_requirements.hpp>
- #include <boost/log/detail/header.hpp>
- namespace boost {
- BOOST_LOG_OPEN_NAMESPACE
- namespace sinks {
- #ifndef BOOST_LOG_DOXYGEN_PASS
- #define BOOST_LOG_SINK_CTOR_FORWARD_INTERNAL_1(z, n, data)\
- template< typename T0 >\
- explicit synchronous_sink(T0 const& arg0, typename boost::log::aux::enable_if_named_parameters< T0, boost::log::aux::sfinae_dummy >::type = boost::log::aux::sfinae_dummy()) :\
- base_type(false),\
- m_pBackend(boost::make_shared< sink_backend_type >(arg0)) {}
- #define BOOST_LOG_SINK_CTOR_FORWARD_INTERNAL_N(z, n, data)\
- template< BOOST_PP_ENUM_PARAMS_Z(z, n, typename T) >\
- explicit synchronous_sink(BOOST_PP_ENUM_BINARY_PARAMS_Z(z, n, T, const& arg)) :\
- base_type(false),\
- m_pBackend(boost::make_shared< sink_backend_type >(BOOST_PP_ENUM_PARAMS_Z(z, n, arg))) {}
- #define BOOST_LOG_SINK_CTOR_FORWARD_INTERNAL(z, n, data)\
- BOOST_PP_IF(BOOST_PP_EQUAL(n, 1), BOOST_LOG_SINK_CTOR_FORWARD_INTERNAL_1, BOOST_LOG_SINK_CTOR_FORWARD_INTERNAL_N)(z, n, data)
- #endif
- template< typename SinkBackendT >
- class synchronous_sink :
- public aux::make_sink_frontend_base< SinkBackendT >::type
- {
- typedef typename aux::make_sink_frontend_base< SinkBackendT >::type base_type;
- private:
-
- typedef boost::recursive_mutex backend_mutex_type;
- public:
-
- typedef SinkBackendT sink_backend_type;
-
- BOOST_STATIC_ASSERT_MSG((has_requirement< typename sink_backend_type::frontend_requirements, synchronized_feeding >::value), "Synchronous sink frontend is incompatible with the specified backend: thread synchronization requirements are not met");
-
- #ifndef BOOST_LOG_DOXYGEN_PASS
-
- typedef boost::log::aux::locking_ptr< sink_backend_type, backend_mutex_type > locked_backend_ptr;
- #else
-
- typedef implementation_defined locked_backend_ptr;
- #endif
- private:
-
- backend_mutex_type m_BackendMutex;
-
- const shared_ptr< sink_backend_type > m_pBackend;
- public:
-
- synchronous_sink() :
- base_type(false),
- m_pBackend(boost::make_shared< sink_backend_type >())
- {
- }
-
- explicit synchronous_sink(shared_ptr< sink_backend_type > const& backend) :
- base_type(false),
- m_pBackend(backend)
- {
- }
-
- #ifndef BOOST_LOG_DOXYGEN_PASS
- BOOST_LOG_PARAMETRIZED_CONSTRUCTORS_GEN(BOOST_LOG_SINK_CTOR_FORWARD_INTERNAL, ~)
- #else
- template< typename... Args >
- explicit synchronous_sink(Args&&... args);
- #endif
-
- locked_backend_ptr locked_backend()
- {
- return locked_backend_ptr(m_pBackend, m_BackendMutex);
- }
-
- void consume(record_view const& rec) BOOST_OVERRIDE
- {
- base_type::feed_record(rec, m_BackendMutex, *m_pBackend);
- }
-
- bool try_consume(record_view const& rec) BOOST_OVERRIDE
- {
- return base_type::try_feed_record(rec, m_BackendMutex, *m_pBackend);
- }
-
- void flush() BOOST_OVERRIDE
- {
- base_type::flush_backend(m_BackendMutex, *m_pBackend);
- }
- };
- #undef BOOST_LOG_SINK_CTOR_FORWARD_INTERNAL_1
- #undef BOOST_LOG_SINK_CTOR_FORWARD_INTERNAL_N
- #undef BOOST_LOG_SINK_CTOR_FORWARD_INTERNAL
- }
- BOOST_LOG_CLOSE_NAMESPACE
- }
- #include <boost/log/detail/footer.hpp>
- #endif
|