Chris@16
|
1 /*
|
Chris@101
|
2 * Copyright Andrey Semashev 2007 - 2015.
|
Chris@16
|
3 * Distributed under the Boost Software License, Version 1.0.
|
Chris@16
|
4 * (See accompanying file LICENSE_1_0.txt or copy at
|
Chris@16
|
5 * http://www.boost.org/LICENSE_1_0.txt)
|
Chris@16
|
6 */
|
Chris@16
|
7 /*!
|
Chris@16
|
8 * \file unlocked_frontend.hpp
|
Chris@16
|
9 * \author Andrey Semashev
|
Chris@16
|
10 * \date 14.07.2009
|
Chris@16
|
11 *
|
Chris@16
|
12 * The header contains declaration of an unlocked sink frontend.
|
Chris@16
|
13 */
|
Chris@16
|
14
|
Chris@16
|
15 #ifndef BOOST_LOG_SINKS_UNLOCKED_FRONTEND_HPP_INCLUDED_
|
Chris@16
|
16 #define BOOST_LOG_SINKS_UNLOCKED_FRONTEND_HPP_INCLUDED_
|
Chris@16
|
17
|
Chris@16
|
18 #include <boost/static_assert.hpp>
|
Chris@16
|
19 #include <boost/smart_ptr/shared_ptr.hpp>
|
Chris@16
|
20 #include <boost/smart_ptr/make_shared_object.hpp>
|
Chris@16
|
21 #include <boost/log/detail/config.hpp>
|
Chris@16
|
22 #include <boost/log/detail/parameter_tools.hpp>
|
Chris@16
|
23 #include <boost/log/detail/fake_mutex.hpp>
|
Chris@16
|
24 #include <boost/log/sinks/basic_sink_frontend.hpp>
|
Chris@16
|
25 #include <boost/log/sinks/frontend_requirements.hpp>
|
Chris@16
|
26 #include <boost/log/detail/header.hpp>
|
Chris@16
|
27
|
Chris@16
|
28 #ifdef BOOST_HAS_PRAGMA_ONCE
|
Chris@16
|
29 #pragma once
|
Chris@16
|
30 #endif
|
Chris@16
|
31
|
Chris@16
|
32 namespace boost {
|
Chris@16
|
33
|
Chris@16
|
34 BOOST_LOG_OPEN_NAMESPACE
|
Chris@16
|
35
|
Chris@16
|
36 namespace sinks {
|
Chris@16
|
37
|
Chris@16
|
38 #ifndef BOOST_LOG_DOXYGEN_PASS
|
Chris@16
|
39
|
Chris@16
|
40 #define BOOST_LOG_SINK_CTOR_FORWARD_INTERNAL(z, n, types)\
|
Chris@16
|
41 template< BOOST_PP_ENUM_PARAMS(n, typename T) >\
|
Chris@16
|
42 explicit unlocked_sink(BOOST_PP_ENUM_BINARY_PARAMS(n, T, const& arg)) :\
|
Chris@16
|
43 base_type(false),\
|
Chris@16
|
44 m_pBackend(boost::make_shared< sink_backend_type >(BOOST_PP_ENUM_PARAMS(n, arg))) {}
|
Chris@16
|
45
|
Chris@16
|
46 #endif // BOOST_LOG_DOXYGEN_PASS
|
Chris@16
|
47
|
Chris@16
|
48 /*!
|
Chris@16
|
49 * \brief Non-blocking logging sink frontend
|
Chris@16
|
50 *
|
Chris@16
|
51 * The sink frontend does not perform thread synchronization and
|
Chris@16
|
52 * simply passes logging records to the sink backend.
|
Chris@16
|
53 */
|
Chris@16
|
54 template< typename SinkBackendT >
|
Chris@16
|
55 class unlocked_sink :
|
Chris@16
|
56 public aux::make_sink_frontend_base< SinkBackendT >::type
|
Chris@16
|
57 {
|
Chris@16
|
58 typedef typename aux::make_sink_frontend_base< SinkBackendT >::type base_type;
|
Chris@16
|
59
|
Chris@16
|
60 public:
|
Chris@16
|
61 //! Sink implementation type
|
Chris@16
|
62 typedef SinkBackendT sink_backend_type;
|
Chris@16
|
63 //! \cond
|
Chris@16
|
64 BOOST_STATIC_ASSERT_MSG((has_requirement< typename sink_backend_type::frontend_requirements, concurrent_feeding >::value), "Unlocked sink frontend is incompatible with the specified backend: thread synchronization requirements are not met");
|
Chris@16
|
65 //! \endcond
|
Chris@16
|
66
|
Chris@16
|
67 //! Type of pointer to the backend
|
Chris@16
|
68 typedef shared_ptr< sink_backend_type > locked_backend_ptr;
|
Chris@16
|
69
|
Chris@16
|
70 private:
|
Chris@16
|
71 //! Pointer to the backend
|
Chris@16
|
72 const shared_ptr< sink_backend_type > m_pBackend;
|
Chris@16
|
73
|
Chris@16
|
74 public:
|
Chris@16
|
75 /*!
|
Chris@16
|
76 * Default constructor. Constructs the sink backend instance.
|
Chris@16
|
77 * Requires the backend to be default-constructible.
|
Chris@16
|
78 */
|
Chris@16
|
79 unlocked_sink() :
|
Chris@16
|
80 base_type(false),
|
Chris@16
|
81 m_pBackend(boost::make_shared< sink_backend_type >())
|
Chris@16
|
82 {
|
Chris@16
|
83 }
|
Chris@16
|
84 /*!
|
Chris@16
|
85 * Constructor attaches user-constructed backend instance
|
Chris@16
|
86 *
|
Chris@16
|
87 * \param backend Pointer to the backend instance
|
Chris@16
|
88 *
|
Chris@16
|
89 * \pre \a backend is not \c NULL.
|
Chris@16
|
90 */
|
Chris@16
|
91 explicit unlocked_sink(shared_ptr< sink_backend_type > const& backend) :
|
Chris@16
|
92 base_type(false),
|
Chris@16
|
93 m_pBackend(backend)
|
Chris@16
|
94 {
|
Chris@16
|
95 }
|
Chris@16
|
96
|
Chris@16
|
97 // Constructors that pass arbitrary parameters to the backend constructor
|
Chris@16
|
98 BOOST_LOG_PARAMETRIZED_CONSTRUCTORS_GEN(BOOST_LOG_SINK_CTOR_FORWARD_INTERNAL, ~)
|
Chris@16
|
99
|
Chris@16
|
100 /*!
|
Chris@16
|
101 * Locking accessor to the attached backend.
|
Chris@16
|
102 *
|
Chris@16
|
103 * \note Does not do any actual locking, provided only for interface consistency
|
Chris@16
|
104 * with other frontends.
|
Chris@16
|
105 */
|
Chris@16
|
106 locked_backend_ptr locked_backend()
|
Chris@16
|
107 {
|
Chris@16
|
108 return m_pBackend;
|
Chris@16
|
109 }
|
Chris@16
|
110
|
Chris@16
|
111 /*!
|
Chris@16
|
112 * Passes the log record to the backend
|
Chris@16
|
113 */
|
Chris@16
|
114 void consume(record_view const& rec)
|
Chris@16
|
115 {
|
Chris@16
|
116 boost::log::aux::fake_mutex m;
|
Chris@16
|
117 base_type::feed_record(rec, m, *m_pBackend);
|
Chris@16
|
118 }
|
Chris@16
|
119
|
Chris@16
|
120 /*!
|
Chris@16
|
121 * The method performs flushing of any internal buffers that may hold log records. The method
|
Chris@16
|
122 * may take considerable time to complete and may block both the calling thread and threads
|
Chris@16
|
123 * attempting to put new records into the sink while this call is in progress.
|
Chris@16
|
124 */
|
Chris@16
|
125 void flush()
|
Chris@16
|
126 {
|
Chris@16
|
127 boost::log::aux::fake_mutex m;
|
Chris@16
|
128 base_type::flush_backend(m, *m_pBackend);
|
Chris@16
|
129 }
|
Chris@16
|
130 };
|
Chris@16
|
131
|
Chris@16
|
132 #undef BOOST_LOG_SINK_CTOR_FORWARD_INTERNAL
|
Chris@16
|
133
|
Chris@16
|
134 } // namespace sinks
|
Chris@16
|
135
|
Chris@16
|
136 BOOST_LOG_CLOSE_NAMESPACE // namespace log
|
Chris@16
|
137
|
Chris@16
|
138 } // namespace boost
|
Chris@16
|
139
|
Chris@16
|
140 #include <boost/log/detail/footer.hpp>
|
Chris@16
|
141
|
Chris@16
|
142 #endif // BOOST_LOG_SINKS_UNLOCKED_FRONTEND_HPP_INCLUDED_
|