File indexing completed on 2025-10-31 08:43:26
0001 
0002 
0003 
0004 
0005 
0006 
0007 
0008 
0009 
0010 
0011 
0012 
0013 
0014 
0015 
0016 
0017 
0018 #ifndef BOOST_LOG_SINKS_TEXT_IPC_MESSAGE_QUEUE_BACKEND_HPP_INCLUDED_
0019 #define BOOST_LOG_SINKS_TEXT_IPC_MESSAGE_QUEUE_BACKEND_HPP_INCLUDED_
0020 
0021 #include <limits>
0022 #include <string>
0023 #include <boost/cstdint.hpp>
0024 #include <boost/move/core.hpp>
0025 #include <boost/preprocessor/control/if.hpp>
0026 #include <boost/preprocessor/comparison/equal.hpp>
0027 #include <boost/log/detail/config.hpp>
0028 #include <boost/log/detail/parameter_tools.hpp>
0029 #include <boost/log/core/record_view.hpp>
0030 #include <boost/log/sinks/basic_sink_backend.hpp>
0031 #include <boost/log/sinks/frontend_requirements.hpp>
0032 #include <boost/log/exceptions.hpp>
0033 #include <boost/log/detail/header.hpp>
0034 
0035 #ifdef BOOST_HAS_PRAGMA_ONCE
0036 #pragma once
0037 #endif
0038 
0039 namespace boost {
0040 
0041 BOOST_LOG_OPEN_NAMESPACE
0042 
0043 namespace sinks {
0044 
0045 #ifndef BOOST_LOG_DOXYGEN_PASS
0046 
0047 #define BOOST_LOG_IPC_BACKEND_CTOR_FORWARD_INTERNAL_1(z, n, data)\
0048     template< typename T0 >\
0049     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()) :\
0050         m_queue(arg0) {}
0051 
0052 #define BOOST_LOG_IPC_BACKEND_CTOR_FORWARD_INTERNAL_N(z, n, data)\
0053     template< BOOST_PP_ENUM_PARAMS_Z(z, n, typename T) >\
0054     explicit text_ipc_message_queue_backend(BOOST_PP_ENUM_BINARY_PARAMS_Z(z, n, T, const& arg)) :\
0055         m_queue(BOOST_PP_ENUM_PARAMS_Z(z, n, arg)) {}
0056 
0057 #define BOOST_LOG_IPC_BACKEND_CTOR_FORWARD_INTERNAL(z, n, data)\
0058     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)
0059 
0060 #endif 
0061 
0062 
0063 
0064 
0065 
0066 
0067 
0068 
0069 
0070 template< typename QueueT >
0071 class text_ipc_message_queue_backend :
0072     public basic_formatted_sink_backend< char, concurrent_feeding >
0073 {
0074     
0075     typedef basic_formatted_sink_backend< char, concurrent_feeding > base_type;
0076 
0077 public:
0078     
0079     typedef base_type::char_type char_type;
0080     
0081     typedef base_type::string_type string_type;
0082     
0083     typedef QueueT queue_type;
0084 
0085 private:
0086     
0087     queue_type m_queue;
0088 
0089 public:
0090     
0091 
0092 
0093 
0094 
0095     text_ipc_message_queue_backend() BOOST_NOEXCEPT
0096     {
0097     }
0098 
0099     
0100 
0101 
0102 
0103     explicit text_ipc_message_queue_backend(BOOST_RV_REF(queue_type) queue) BOOST_NOEXCEPT :
0104         m_queue(static_cast< BOOST_RV_REF(queue_type) >(queue))
0105     {
0106     }
0107 
0108     
0109 
0110 
0111 
0112 #ifndef BOOST_LOG_DOXYGEN_PASS
0113     BOOST_LOG_PARAMETRIZED_CONSTRUCTORS_GEN(BOOST_LOG_IPC_BACKEND_CTOR_FORWARD_INTERNAL, ~)
0114 #else
0115     template< typename... Args >
0116     explicit text_ipc_message_queue_backend(Args&&... args);
0117 #endif
0118 
0119     
0120 
0121 
0122 
0123 
0124     queue_type& message_queue() BOOST_NOEXCEPT { return m_queue; }
0125 
0126     
0127 
0128 
0129 
0130 
0131     queue_type const& message_queue() const BOOST_NOEXCEPT { return m_queue; }
0132 
0133     
0134 
0135 
0136 
0137 
0138 
0139     bool is_open() const BOOST_NOEXCEPT { return m_queue.is_open(); }
0140 
0141     
0142 
0143 
0144 
0145 
0146 
0147     void consume(record_view const&, string_type const& formatted_message)
0148     {
0149         if (m_queue.is_open())
0150         {
0151             typedef typename queue_type::size_type size_type;
0152             const string_type::size_type size = formatted_message.size();
0153             if (BOOST_UNLIKELY(size > static_cast< string_type::size_type >((std::numeric_limits< size_type >::max)())))
0154                 BOOST_LOG_THROW_DESCR(limitation_error, "Message too long to send to an interprocess queue");
0155             m_queue.send(formatted_message.data(), static_cast< size_type >(size));
0156         }
0157     }
0158 };
0159 
0160 #undef BOOST_LOG_IPC_BACKEND_CTOR_FORWARD_INTERNAL_1
0161 #undef BOOST_LOG_IPC_BACKEND_CTOR_FORWARD_INTERNAL_N
0162 #undef BOOST_LOG_IPC_BACKEND_CTOR_FORWARD_INTERNAL
0163 
0164 } 
0165 
0166 BOOST_LOG_CLOSE_NAMESPACE 
0167 
0168 } 
0169 
0170 #include <boost/log/detail/footer.hpp>
0171 
0172 #endif