• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  *                Copyright Lingxi Li 2015.
3  *             Copyright Andrey Semashev 2016.
4  * Distributed under the Boost Software License, Version 1.0.
5  *    (See accompanying file LICENSE_1_0.txt or copy at
6  *          http://www.boost.org/LICENSE_1_0.txt)
7  */
8 
9 #if !defined(BOOST_LOG_WITHOUT_IPC)
10 
11 #include <iostream>
12 #include <string>
13 #include <exception>
14 #include <boost/log/utility/ipc/reliable_message_queue.hpp>
15 #include <boost/log/utility/ipc/object_name.hpp>
16 #include <boost/log/utility/open_mode.hpp>
17 
18 namespace logging = boost::log;
19 namespace keywords = boost::log::keywords;
20 
21 //[ example_sinks_ipc_receiver
main()22 int main()
23 {
24     try
25     {
26         typedef logging::ipc::reliable_message_queue queue_t;
27 
28         // Create a message_queue_type object that is associated with the interprocess
29         // message queue named "ipc_message_queue".
30         queue_t queue
31         (
32             keywords::name = logging::ipc::object_name(logging::ipc::object_name::user, "ipc_message_queue"),
33             keywords::open_mode = logging::open_mode::open_or_create,
34             keywords::capacity = 256,
35             keywords::block_size = 1024,
36             keywords::overflow_policy = queue_t::block_on_overflow
37         );
38 
39         std::cout << "Viewer process running..." << std::endl;
40 
41         // Keep reading log messages from the associated message queue and print them on the console.
42         // queue.receive() will block if the queue is empty.
43         std::string message;
44         while (queue.receive(message) == queue_t::succeeded)
45         {
46             std::cout << message << std::endl;
47 
48             // Clear the buffer for the next message
49             message.clear();
50         }
51     }
52     catch (std::exception& e)
53     {
54         std::cout << "Failure: " << e.what() << std::endl;
55     }
56 
57     return 0;
58 }
59 //]
60 
61 #else // !defined(BOOST_LOG_WITHOUT_IPC)
62 
main()63 int main()
64 {
65     return 0;
66 }
67 
68 #endif // !defined(BOOST_LOG_WITHOUT_IPC)
69