File indexing completed on 2025-01-18 09:39:25
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015 #ifndef BOOST_LOG_SINKS_SYNC_FRONTEND_HPP_INCLUDED_
0016 #define BOOST_LOG_SINKS_SYNC_FRONTEND_HPP_INCLUDED_
0017
0018 #include <boost/log/detail/config.hpp>
0019
0020 #ifdef BOOST_HAS_PRAGMA_ONCE
0021 #pragma once
0022 #endif
0023
0024 #if defined(BOOST_LOG_NO_THREADS)
0025 #error Boost.Log: Synchronous sink frontend is only supported in multithreaded environment
0026 #endif
0027
0028 #include <boost/smart_ptr/shared_ptr.hpp>
0029 #include <boost/smart_ptr/make_shared_object.hpp>
0030 #include <boost/preprocessor/control/if.hpp>
0031 #include <boost/preprocessor/comparison/equal.hpp>
0032 #include <boost/thread/recursive_mutex.hpp>
0033 #include <boost/log/detail/locking_ptr.hpp>
0034 #include <boost/log/detail/parameter_tools.hpp>
0035 #include <boost/log/core/record_view.hpp>
0036 #include <boost/log/sinks/basic_sink_frontend.hpp>
0037 #include <boost/log/sinks/frontend_requirements.hpp>
0038 #include <boost/log/detail/header.hpp>
0039
0040 namespace boost {
0041
0042 BOOST_LOG_OPEN_NAMESPACE
0043
0044 namespace sinks {
0045
0046 #ifndef BOOST_LOG_DOXYGEN_PASS
0047
0048 #define BOOST_LOG_SINK_CTOR_FORWARD_INTERNAL_1(z, n, data)\
0049 template< typename T0 >\
0050 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()) :\
0051 base_type(false),\
0052 m_pBackend(boost::make_shared< sink_backend_type >(arg0)) {}
0053
0054 #define BOOST_LOG_SINK_CTOR_FORWARD_INTERNAL_N(z, n, data)\
0055 template< BOOST_PP_ENUM_PARAMS_Z(z, n, typename T) >\
0056 explicit synchronous_sink(BOOST_PP_ENUM_BINARY_PARAMS_Z(z, n, T, const& arg)) :\
0057 base_type(false),\
0058 m_pBackend(boost::make_shared< sink_backend_type >(BOOST_PP_ENUM_PARAMS_Z(z, n, arg))) {}
0059
0060 #define BOOST_LOG_SINK_CTOR_FORWARD_INTERNAL(z, n, data)\
0061 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)
0062
0063 #endif
0064
0065
0066
0067
0068
0069
0070 template< typename SinkBackendT >
0071 class synchronous_sink :
0072 public aux::make_sink_frontend_base< SinkBackendT >::type
0073 {
0074 typedef typename aux::make_sink_frontend_base< SinkBackendT >::type base_type;
0075
0076 private:
0077
0078 typedef boost::recursive_mutex backend_mutex_type;
0079
0080 public:
0081
0082 typedef SinkBackendT sink_backend_type;
0083
0084 static_assert(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");
0085
0086
0087 #ifndef BOOST_LOG_DOXYGEN_PASS
0088
0089
0090 typedef boost::log::aux::locking_ptr< sink_backend_type, backend_mutex_type > locked_backend_ptr;
0091
0092 #else
0093
0094
0095 typedef implementation_defined locked_backend_ptr;
0096
0097 #endif
0098
0099 private:
0100
0101 backend_mutex_type m_BackendMutex;
0102
0103 const shared_ptr< sink_backend_type > m_pBackend;
0104
0105 public:
0106
0107
0108
0109
0110 synchronous_sink() :
0111 base_type(false),
0112 m_pBackend(boost::make_shared< sink_backend_type >())
0113 {
0114 }
0115
0116
0117
0118
0119
0120
0121
0122 explicit synchronous_sink(shared_ptr< sink_backend_type > const& backend) :
0123 base_type(false),
0124 m_pBackend(backend)
0125 {
0126 }
0127
0128
0129
0130
0131
0132 #ifndef BOOST_LOG_DOXYGEN_PASS
0133 BOOST_LOG_PARAMETRIZED_CONSTRUCTORS_GEN(BOOST_LOG_SINK_CTOR_FORWARD_INTERNAL, ~)
0134 #else
0135 template< typename... Args >
0136 explicit synchronous_sink(Args&&... args);
0137 #endif
0138
0139
0140
0141
0142 locked_backend_ptr locked_backend()
0143 {
0144 return locked_backend_ptr(m_pBackend, m_BackendMutex);
0145 }
0146
0147
0148
0149
0150 void consume(record_view const& rec) BOOST_OVERRIDE
0151 {
0152 base_type::feed_record(rec, m_BackendMutex, *m_pBackend);
0153 }
0154
0155
0156
0157
0158 bool try_consume(record_view const& rec) BOOST_OVERRIDE
0159 {
0160 return base_type::try_feed_record(rec, m_BackendMutex, *m_pBackend);
0161 }
0162
0163
0164
0165
0166
0167
0168 void flush() BOOST_OVERRIDE
0169 {
0170 base_type::flush_backend(m_BackendMutex, *m_pBackend);
0171 }
0172 };
0173
0174 #undef BOOST_LOG_SINK_CTOR_FORWARD_INTERNAL_1
0175 #undef BOOST_LOG_SINK_CTOR_FORWARD_INTERNAL_N
0176 #undef BOOST_LOG_SINK_CTOR_FORWARD_INTERNAL
0177
0178 }
0179
0180 BOOST_LOG_CLOSE_NAMESPACE
0181
0182 }
0183
0184 #include <boost/log/detail/footer.hpp>
0185
0186 #endif