Use =default for skeleton copy constructor
[ACE_TAO.git] / ACE / netsvcs / lib / Server_Logging_Handler_T.h
blob0a6e3804e99f7052a2a73ef859859e988b30fb79
1 /* -*- C++ -*- */
3 //=============================================================================
4 /**
5 * @file Server_Logging_Handler_T.h
7 * @author Doug Schmidt and Per Andersson
8 */
9 //=============================================================================
12 #ifndef ACE_SERVER_LOGGING_HANDLER_T_H
13 #define ACE_SERVER_LOGGING_HANDLER_T_H
15 #include "ace/config-all.h"
17 #if !defined (ACE_LACKS_PRAGMA_ONCE)
18 # pragma once
19 #endif /* ACE_LACKS_PRAGMA_ONCE */
21 #include "ace/TLI_Acceptor.h"
22 #include "ace/SOCK_Acceptor.h"
23 #include "ace/Svc_Handler.h"
24 #include "ace/Acceptor.h"
25 #include "ace/SString.h"
26 #include "ace/Atomic_Op.h"
29 #if !defined (__GNUG__)
30 #include "Base_Optimizer.h"
31 #endif /* ! __GNUG__ */
33 /**
34 * @class ACE_Server_Logging_Handler_T
36 * @brief Product object created by an <ACE_Server_Logging_Acceptor_T>. An
37 * <ACE_Server_Logging_Handler_T> receives, and frames logging
38 * records. The logging record is then processed by the
39 * <LOG_MESSAGE_RECEIVER>
41 * Defines the classes that perform server logging daemon
42 * functionality.
44 template <ACE_PEER_STREAM_1, class COUNTER, ACE_SYNCH_DECL, class LOG_MESSAGE_RECEIVER>
45 class ACE_Server_Logging_Handler_T : public ACE_Svc_Handler<ACE_PEER_STREAM_2, ACE_SYNCH_USE>
47 public:
48 /// Constructor.
49 ACE_Server_Logging_Handler_T (ACE_Thread_Manager *,
50 const LOG_MESSAGE_RECEIVER &receiver );
53 /// Process remote logging records.
54 virtual int handle_input (ACE_HANDLE = ACE_INVALID_HANDLE);
56 protected:
57 /// Receive the logging record from a client.
58 int handle_logging_record ();
60 /// Common parts of open function, sets hostname and diables NONBLOCK in peer
61 /// called from derived classes open method.
62 int open_common ();
64 /// Count the number of logging records that arrive.
65 static COUNTER request_count_;
67 #if !defined (__GNUG__)
68 /**
69 * Packs a LOG_MESSAGE_RECEIVER and ACE_CString attribute together
70 * in a optimized fashion. The LOG_MESSAGE_RECEIVER class is often
71 * a class with no instance data.
73 Base_Optimizer<LOG_MESSAGE_RECEIVER, ACE_TString> receiver_;
74 #else
75 LOG_MESSAGE_RECEIVER receiver_;
76 ACE_TString host_name_;
77 #endif /* ! __GNUG__ */
78 /// Name of the host we are connected to.
79 const ACE_TCHAR *host_name ();
81 /// The receiver of log records
82 LOG_MESSAGE_RECEIVER &receiver () { return receiver_; }
85 #if 1 //!defined (ACE_HAS_TLI)
86 #define LOGGING_PEER_ACCEPTOR ACE_SOCK_ACCEPTOR
87 #define LOGGING_PEER_STREAM ACE_SOCK_STREAM
88 #else /* use sockets */
89 #define LOGGING_PEER_ACCEPTOR ACE_TLI_ACCEPTOR
90 #define LOGGING_PEER_STREAM ACE_TLI_STREAM
91 #endif /* ACE_HAS_TLI */
93 /**
94 * @class ACE_Server_Logging_Acceptor_T
96 * @brief Factory that creates <SERVER_LOGGING_HANDLER>s scheduled with
97 * <SCHEDULE_STRATEGY> and logging records proccessed by a
98 * <LOG_MESSAGE_RECEIVER>
100 * This class contains the service-specific methods that can't
101 * easily be factored into the <ACE_Strategy_Acceptor>.
103 template<class SERVER_LOGGING_HANDLER, class LOG_MESSAGE_RECEIVER, class SCHEDULE_STRATEGY>
104 class ACE_Server_Logging_Acceptor_T : public ACE_Strategy_Acceptor<SERVER_LOGGING_HANDLER, LOGGING_PEER_ACCEPTOR>
106 public:
107 /// Dynamic linking hook.
108 ACE_Server_Logging_Acceptor_T ();
109 virtual int init (int argc, ACE_TCHAR *argv[]);
111 protected:
112 /// Parse svc.conf arguments.
113 int parse_args (int argc, ACE_TCHAR *argv[]);
116 * Factory that creates a new <SERVER_LOGGING_HANDLER>. We need to
117 * specialize this since the <LOG_MESSAGE_RECEIVER> held by this Acceptor must be
118 * passed into the <SERVER_LOGGING_HANDLER>.
120 virtual int make_svc_handler (SERVER_LOGGING_HANDLER *&);
122 private:
123 // At the moment each ACE_Server_Logging_Acceptor_T contains
124 // a <LOG_MESSAGE_RECEIVER> attribute that is passed to the
125 // <SERVER_LOGGING_HANDLER> at construction. A better idea might
126 // be to have accessor class as template argument. The accessor
127 // should be a factory/strategy that hands the
128 // ACE_Server_Logging_Acceptor_T instance references
129 // to a <LOG_MESSAGE_RECEIVER>. This makes it possible
130 // to change how <LOG_MESSAGE_RECEIVER> are created without chaning the
131 // ACE_Server_Logging_Acceptor_T code.
133 #if !defined (__GNUG__)
135 * Packs a LOG_MESSAGE_RECEIVER and ACE_CString attribute together
136 * in a optimized fashion. The LOG_MESSAGE_RECEIVER class is often a
137 * class with no instance data.
139 Base_Optimizer<LOG_MESSAGE_RECEIVER, SCHEDULE_STRATEGY> receiver_;
140 #else
141 LOG_MESSAGE_RECEIVER receiver_;
142 SCHEDULE_STRATEGY schedule_strategy_;
143 #endif /* ! __GNUG__ */
145 /// The scheduling strategy for the service.
146 SCHEDULE_STRATEGY &scheduling_strategy ();
148 /// The receiver of log records
149 LOG_MESSAGE_RECEIVER &receiver ();
153 * @class ACE_Server_Logging_Handler
155 * @brief Product object created by a
156 * <ACE_Server_Logging_Acceptor_T<ACE_Server_Logging_Handler> >. An
157 * ACE_Server_Logging_Handler receives, frames. The logging record
158 * is then processed by the <LOG_MESSAGE_RECEIVER>
160 * All clients are handled in the same thread.
162 template<class LOG_MESSAGE_RECEIVER>
163 class ACE_Server_Logging_Handler : public ACE_Server_Logging_Handler_T<LOGGING_PEER_STREAM, u_long, ACE_NULL_SYNCH, LOG_MESSAGE_RECEIVER>
165 public:
166 ACE_Server_Logging_Handler (ACE_Thread_Manager * = 0);
167 ACE_Server_Logging_Handler (ACE_Thread_Manager *,
168 const LOG_MESSAGE_RECEIVER &receiver);
170 virtual int open (void* = 0);
173 #if defined (ACE_HAS_THREADS)
174 typedef ACE_Atomic_Op <ACE_Thread_Mutex, u_long> ACE_LOGGER_COUNTER;
175 #define ACE_LOGGER_SYNCH ACE_MT_SYNCH
176 #else
177 typedef u_long ACE_LOGGER_COUNTER;
178 #define ACE_LOGGER_SYNCH ACE_NULL_SYNCH
179 #endif /* ACE_HAS_THREADS */
182 * @class ACE_Thr_Server_Logging_Handler
184 * @brief Product object created by a
185 * <ACE_Server_Logging_Acceptor_T<ACE_Thr_Server_Logging_Handler>
186 * >. An ACE_Thr_Server_Logging_Handler receives, frames. The
187 * logging record is then processed by the <LOG_MESSAGE_RECEIVER>
189 * Each client is handled in its own separate thread.
191 template<class LOG_MESSAGE_RECEIVER>
192 class ACE_Thr_Server_Logging_Handler : public ACE_Server_Logging_Handler_T<LOGGING_PEER_STREAM, ACE_LOGGER_COUNTER, ACE_LOGGER_SYNCH, LOG_MESSAGE_RECEIVER>
194 public:
195 ACE_Thr_Server_Logging_Handler (ACE_Thread_Manager * = 0);
196 ACE_Thr_Server_Logging_Handler (ACE_Thread_Manager *,
197 const LOG_MESSAGE_RECEIVER &receiver);
198 virtual int open (void * = 0);
199 virtual int svc ();
202 #include "Server_Logging_Handler_T.cpp"
204 #endif /* ACE_SERVER_LOGGING_HANDLER_T_H */