123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172 |
- #ifndef BOOST_LOG_SINKS_TEXT_IPC_MESSAGE_QUEUE_BACKEND_HPP_INCLUDED_
- #define BOOST_LOG_SINKS_TEXT_IPC_MESSAGE_QUEUE_BACKEND_HPP_INCLUDED_
- #include <limits>
- #include <string>
- #include <boost/cstdint.hpp>
- #include <boost/move/core.hpp>
- #include <boost/preprocessor/control/if.hpp>
- #include <boost/preprocessor/comparison/equal.hpp>
- #include <boost/log/detail/config.hpp>
- #include <boost/log/detail/parameter_tools.hpp>
- #include <boost/log/core/record_view.hpp>
- #include <boost/log/sinks/basic_sink_backend.hpp>
- #include <boost/log/sinks/frontend_requirements.hpp>
- #include <boost/log/exceptions.hpp>
- #include <boost/log/detail/header.hpp>
- #ifdef BOOST_HAS_PRAGMA_ONCE
- #pragma once
- #endif
- namespace boost {
- BOOST_LOG_OPEN_NAMESPACE
- namespace sinks {
- #ifndef BOOST_LOG_DOXYGEN_PASS
- #define BOOST_LOG_IPC_BACKEND_CTOR_FORWARD_INTERNAL_1(z, n, data)\
- template< typename T0 >\
- explicit text_ipc_message_queue_backend(T0 const& arg0, typename boost::log::aux::enable_if_named_parameters< T0, boost::log::aux::sfinae_dummy >::type = boost::log::aux::sfinae_dummy()) :\
- m_queue(arg0) {}
- #define BOOST_LOG_IPC_BACKEND_CTOR_FORWARD_INTERNAL_N(z, n, data)\
- template< BOOST_PP_ENUM_PARAMS_Z(z, n, typename T) >\
- explicit text_ipc_message_queue_backend(BOOST_PP_ENUM_BINARY_PARAMS_Z(z, n, T, const& arg)) :\
- m_queue(BOOST_PP_ENUM_PARAMS_Z(z, n, arg)) {}
- #define BOOST_LOG_IPC_BACKEND_CTOR_FORWARD_INTERNAL(z, n, data)\
- BOOST_PP_IF(BOOST_PP_EQUAL(n, 1), BOOST_LOG_IPC_BACKEND_CTOR_FORWARD_INTERNAL_1, BOOST_LOG_IPC_BACKEND_CTOR_FORWARD_INTERNAL_N)(z, n, data)
- #endif
- template< typename QueueT >
- class text_ipc_message_queue_backend :
- public basic_formatted_sink_backend< char, concurrent_feeding >
- {
-
- typedef basic_formatted_sink_backend< char, concurrent_feeding > base_type;
- public:
-
- typedef base_type::char_type char_type;
-
- typedef base_type::string_type string_type;
-
- typedef QueueT queue_type;
- private:
-
- queue_type m_queue;
- public:
-
- text_ipc_message_queue_backend() BOOST_NOEXCEPT
- {
- }
-
- explicit text_ipc_message_queue_backend(BOOST_RV_REF(queue_type) queue) BOOST_NOEXCEPT :
- m_queue(static_cast< BOOST_RV_REF(queue_type) >(queue))
- {
- }
-
- #ifndef BOOST_LOG_DOXYGEN_PASS
- BOOST_LOG_PARAMETRIZED_CONSTRUCTORS_GEN(BOOST_LOG_IPC_BACKEND_CTOR_FORWARD_INTERNAL, ~)
- #else
- template< typename... Args >
- explicit text_ipc_message_queue_backend(Args&&... args);
- #endif
-
- queue_type& message_queue() BOOST_NOEXCEPT { return m_queue; }
-
- queue_type const& message_queue() const BOOST_NOEXCEPT { return m_queue; }
-
- bool is_open() const BOOST_NOEXCEPT { return m_queue.is_open(); }
-
- void consume(record_view const&, string_type const& formatted_message)
- {
- if (m_queue.is_open())
- {
- typedef typename queue_type::size_type size_type;
- const string_type::size_type size = formatted_message.size();
- if (BOOST_UNLIKELY(size > static_cast< string_type::size_type >((std::numeric_limits< size_type >::max)())))
- BOOST_LOG_THROW_DESCR(limitation_error, "Message too long to send to an interprocess queue");
- m_queue.send(formatted_message.data(), static_cast< size_type >(size));
- }
- }
- };
- #undef BOOST_LOG_IPC_BACKEND_CTOR_FORWARD_INTERNAL_1
- #undef BOOST_LOG_IPC_BACKEND_CTOR_FORWARD_INTERNAL_N
- #undef BOOST_LOG_IPC_BACKEND_CTOR_FORWARD_INTERNAL
- }
- BOOST_LOG_CLOSE_NAMESPACE
- }
- #include <boost/log/detail/footer.hpp>
- #endif
|