SObjectizer 5.8
Loading...
Searching...
No Matches
msg_tracing.cpp
Go to the documentation of this file.
1/*
2 * SObjectizer-5
3 */
4
5#include <so_5/msg_tracing.hpp>
6
7#include <mutex>
8#include <iostream>
9
10namespace so_5 {
11
12namespace msg_tracing {
13
14namespace impl {
15
16//
17// std_stream_tracer_t
18//
19/*!
20 * \brief A simple implementation of tracer which uses one of
21 * standard streams.
22 *
23 * \since v.5.5.9
24 */
26 {
27 public :
28 //! Main constructor.
30 //! Stream to be used for tracing.
31 std::ostream & stream )
32 : m_stream( stream )
33 {}
34
35 virtual void
36 trace( const std::string & what ) noexcept override
37 {
38 std::lock_guard< std::mutex > lock{ m_lock };
39
40 m_stream << what << std::endl;
41 }
42
43 private :
44 //! Object lock.
45 /*!
46 * It is necessary for synchronization of trace calls from
47 * different threads.
48 */
49 std::mutex m_lock;
50
51 //! Stream to be used for tracing.
52 std::ostream & m_stream;
53 };
54
55} /* namespace impl */
56
57//
58// Standard stream tracers.
59//
60
61SO_5_FUNC tracer_unique_ptr_t
63 {
64 return tracer_unique_ptr_t{ new impl::std_stream_tracer_t{ std::cout } };
65 }
66
67SO_5_FUNC tracer_unique_ptr_t
69 {
70 return tracer_unique_ptr_t{ new impl::std_stream_tracer_t{ std::cerr } };
71 }
72
73SO_5_FUNC tracer_unique_ptr_t
75 {
76 return tracer_unique_ptr_t{ new impl::std_stream_tracer_t{ std::clog } };
77 }
78
79} /* namespace msg_tracing */
80
81} /* namespace so_5 */
A simple implementation of tracer which uses one of standard streams.
std_stream_tracer_t(std::ostream &stream)
Main constructor.
std::ostream & m_stream
Stream to be used for tracing.
virtual void trace(const std::string &what) noexcept override
Interface of tracer object.
#define SO_5_FUNC
Definition declspec.hpp:48
Implementation details of message delivery tracing mechanism.
Public part of message delivery tracing mechanism.
SO_5_FUNC tracer_unique_ptr_t std_cerr_tracer()
Factory for tracer which uses std::cerr stream.
SO_5_FUNC tracer_unique_ptr_t std_clog_tracer()
Factory for tracer which uses std::clog stream.
SO_5_FUNC tracer_unique_ptr_t std_cout_tracer()
Factory for tracer which uses std::cout stream.
Private part of message limit implementation.
Definition agent.cpp:33