Merge pull request #2301 from sonndinh/remove-dup-reactor-functions
[ACE_TAO.git] / ACE / netsvcs / lib / Log_Message_Receiver.h
blobe98e221cf6a43eba09a0fd7303b582b094d90570
1 /* -*- C++ -*- */
3 //=============================================================================
4 /**
5 * @file Log_Message_Receiver.h
7 * @author Per Andersson
8 */
9 //=============================================================================
11 #ifndef LOG_MESSAGE_RECEIVER_H
12 #define LOG_MESSAGE_RECEIVER_H
14 #include "ace/Log_Record.h"
16 #if !defined (ACE_LACKS_PRAGMA_ONCE)
17 # pragma once
18 #endif /* ACE_LACKS_PRAGMA_ONCE */
20 #include "ace/Synch_Traits.h"
21 #include "ace/Guard_T.h"
22 #if defined (ACE_HAS_THREADS)
23 # include "ace/Thread_Mutex.h"
24 #else
25 # include "ace/Null_Mutex.h"
26 #endif /* ACE_HAS_THREADS */
28 // ==========================================================================//
29 //------------- General Requirements on a Log Message Receiver --------------//
30 // ==========================================================================//
31 // The requirements on a log manager receiver, T, are quite simple.
32 // 1: There must exist one "log_record" member function with the following
33 // prototype:
34 // void log_record(const ACE_TCHAR *hostname,
35 // ACE_Log_Record &record);
37 // 2: There must exist a public destructor.
38 // 3: There must exist a public copy constructor.
39 // 4: There must exist a default constructor. (for now)
41 // The semantics are also simple. A log message receiver should
42 // behave as an accessor object (smart pointer or envelope class).
43 // It should be very cheap to copy and the should be no noticeable
44 // difference when using either the new copy or the old log message
45 // receiver.
47 // Methods:
48 // void log_record(const ACE_TCHAR* hostname,
49 // ACE_Log_Record& record)
50 // Description:
51 // Processes the log record "record" from the host "hostname"
52 // Precondition:
53 // hostname != 0;
54 // Requirements:
55 // Record must be a valid ACE_Log_Record.
57 // ==========================================================================//
59 // ==========================================================================//
60 // ------------ General Description of a Log Message Receiver -------------- //
61 // ==========================================================================//
62 // Log Message Receivers, LRMs, are processing log records. It is the
63 // LRM that writes a log message to stderr, stdout, a log file and maybee
64 // converts some of the log messages to notifications, warnings, alarms
65 // and forwards them to some operation and maintenance system (PATROL).
67 // The client logging handler and server logging handler are responsible
68 // for forwarding, receiving, framing, processing log records.
69 // That is a very usable service, but it should also be possible to change
70 // how log records are processed without having to rewrite code in
71 // the server log handler. This code should instead be written as a
72 // separate entity, a Log Message Receiver.
74 // A simple LMR should be very easy to write but it should also
75 // be possible to write more complex LMRs, like one that creates
76 // a new log file each day or keeps a fixed size, round robin,
77 // log file. It should also be possible to have separate LMRs
78 // of the same type that uses different log files.
80 // ==========================================================================//
83 // Type based log message receiver
84 /**
85 * @class Static_Log_Message_Receiver
87 * @brief Static_Log_Message_Receiver is a simple log message receiver. It
88 * has no instance data and only static member
89 * functions. Static/typed based receivers are best when all LMR
90 * should do exactly the same thing.
92 * This class contains a static log_record member function that
93 * prints the content of log_records on stderr.
95 template<ACE_SYNCH_DECL>
96 class Static_Log_Message_Receiver
98 public:
99 /// Prints the log_record to stderr using record.print (hostname, 0, stderr).
100 /// Serializes the output by using a ACE_SYNCH_MUTEX.
101 static void log_record(const ACE_TCHAR *hostname,
102 ACE_Log_Record &record);
104 /// Prints the log_record to a user specified ostream.
105 static void log_output(const ACE_TCHAR *hostname,
106 ACE_Log_Record &record,
107 ostream *output);
110 // Instance based log message receiver
112 // ------------------------ Log_Message_Receiver --------------------------- //
113 // Log_Message_Receiver is little more complicated log message receiver.
114 // It is instance based and have a reference counted implementation.
115 // Log_Message_Receiver is the envelope class for Log_Message_Receiver_Impl.
117 // ------------------------------------------------------------------------- //
120 //Forward declaration
121 template<ACE_SYNCH_DECL> class Log_Message_Receiver_Impl;
124 * @class Log_Message_Receiver
126 * @brief Log_Message_Receiver is a little more complicated log message
127 * receiver. It is instance based and have a reference counted
128 * implementation. Log_Message_Receiver is the envelope class for
129 * Log_Message_Receiver_Impl. The difference between
130 * Static_Log_Message_Receiver and Log_Message_Receiver is that is
131 * possible to have instance data in Log_Message_Receiver.
132 * Comment:
133 * The practical usage of this is limited with the current
134 * ACE_Server_Logging_Acceptor_T design. Since
135 * ACE_Server_Logging_Acceptor_T will create the
136 * Log_Message_Receiver using the default constructor. The main
137 * reason for inclusion right now is to ensure that the code in
138 * ACE_Server_Logging_Handler_T works both with type and instance
139 * based LMRs.
141 * This class contains a log_record member function that prints the
142 * content of log_records on stderr.
144 template<ACE_SYNCH_DECL>
145 class Log_Message_Receiver
147 public:
148 /// Creates a new Log_Message_Receiver
149 Log_Message_Receiver ();
150 Log_Message_Receiver(Log_Message_Receiver<ACE_SYNCH_USE> const &rhs);
151 ~Log_Message_Receiver ();
153 void log_record (const ACE_TCHAR *hostname,
154 ACE_Log_Record &record);
156 void log_output(const ACE_TCHAR *hostname,
157 ACE_Log_Record &record,
158 ostream *output);
159 private:
160 void operator= (const Log_Message_Receiver<ACE_SYNCH_USE> &rhs) = delete;
162 /// Attributes
163 Log_Message_Receiver_Impl<ACE_SYNCH_USE> *receiver_impl_;
167 * @class Log_Message_Receiver_Impl
169 * @brief Implementation with reference count.
171 template<ACE_SYNCH_DECL>
172 class Log_Message_Receiver_Impl
174 public:
175 // Methods for handling reference count and instance lifetime
176 static Log_Message_Receiver_Impl *create ();
177 static Log_Message_Receiver_Impl *attach (Log_Message_Receiver_Impl<ACE_SYNCH_USE> *body);
178 static void detach (Log_Message_Receiver_Impl<ACE_SYNCH_USE> *body);
180 void log_record (const ACE_TCHAR *hostname, ACE_Log_Record &record);
182 void log_output(const ACE_TCHAR *hostname,
183 ACE_Log_Record &record,
184 ostream *output);
186 protected:
187 Log_Message_Receiver_Impl ();
188 ~Log_Message_Receiver_Impl ();
190 /// Attributes
191 int count_;
192 ACE_SYNCH_MUTEX_T print_lock_;
194 private:
195 static ACE_SYNCH_MUTEX_T copy_lock_;
197 void operator= (const Log_Message_Receiver_Impl<ACE_SYNCH_USE> &) = delete;
198 Log_Message_Receiver_Impl (const Log_Message_Receiver_Impl<ACE_SYNCH_USE> &) = delete;
201 #include "Log_Message_Receiver.cpp"
203 #endif /* LOG_MESSAGE_RECEIVER_H */