Merge pull request #2216 from jwillemsen/jwi-cxxversionchecks
[ACE_TAO.git] / ACE / netsvcs / lib / Log_Message_Receiver.cpp
blobc775f77074b664857e53fac90a502cffbc5570d6
1 #if !defined (LOG_MESSAGE_RECEIVER_CPP)
2 #define LOG_MESSAGE_RECEIVER_CPP
4 #include "ace/Log_Msg.h"
5 #include "Log_Message_Receiver.h"
7 // Type based log message receiver
8 template<ACE_SYNCH_DECL> void
9 Static_Log_Message_Receiver<ACE_SYNCH_USE>::log_record (const ACE_TCHAR *hostname,
10 ACE_Log_Record &record)
12 #if defined (ACE_HAS_THREADS)
13 static ACE_SYNCH_MUTEX_T lock_;
14 ACE_GUARD (ACE_SYNCH_MUTEX_T, guard, lock_);
15 #endif /* ACE_HAS_THREADS */
17 record.print (hostname,
18 ACE_Log_Msg::instance ()->flags (),
19 stderr);
22 template<ACE_SYNCH_DECL> void
23 Static_Log_Message_Receiver<ACE_SYNCH_USE>::log_output (const ACE_TCHAR *hostname,
24 ACE_Log_Record &record,
25 ostream *outputfile)
27 if (outputfile != 0)
29 #if defined (ACE_HAS_THREADS)
30 static ACE_SYNCH_MUTEX_T lock_;
31 ACE_GUARD (ACE_SYNCH_MUTEX_T, guard, lock_);
32 #endif /* ACE_HAS_THREADS */
33 record.print (hostname,
34 ACE_Log_Msg::instance ()->flags (),
35 *outputfile);
39 template<ACE_SYNCH_DECL>
40 ACE_SYNCH_MUTEX_T Log_Message_Receiver_Impl<ACE_SYNCH_USE>::copy_lock_;
42 template<ACE_SYNCH_DECL>
43 Log_Message_Receiver_Impl<ACE_SYNCH_USE>::Log_Message_Receiver_Impl ()
44 : count_ (0)
48 template<ACE_SYNCH_DECL>
49 Log_Message_Receiver_Impl<ACE_SYNCH_USE> *
50 Log_Message_Receiver_Impl<ACE_SYNCH_USE>::create ()
52 return new Log_Message_Receiver_Impl<ACE_SYNCH_USE>;
55 template<ACE_SYNCH_DECL>
56 Log_Message_Receiver_Impl<ACE_SYNCH_USE> *
57 Log_Message_Receiver_Impl<ACE_SYNCH_USE>::attach (Log_Message_Receiver_Impl<ACE_SYNCH_USE> *body)
59 ACE_ASSERT (body != 0);
61 #if defined (ACE_HAS_THREADS)
62 ACE_GUARD_RETURN (ACE_SYNCH_MUTEX_T, guard, copy_lock_, 0);
63 #endif /* ACE_HAS_THREADS */
64 ++body->count_;
65 return body;
68 template<ACE_SYNCH_DECL> void
69 Log_Message_Receiver_Impl<ACE_SYNCH_USE>::detach (Log_Message_Receiver_Impl<ACE_SYNCH_USE> *body)
71 ACE_ASSERT (body != 0);
73 #if defined (ACE_HAS_THREADS)
74 ACE_GUARD (ACE_SYNCH_MUTEX_T, guard, copy_lock_);
75 #endif /* ACE_HAS_THREADS */
76 if (body->count_-- == 0)
77 delete body;
80 // Type based log message receiver
81 template<ACE_SYNCH_DECL> void
82 Log_Message_Receiver_Impl<ACE_SYNCH_USE>::log_record (const ACE_TCHAR *hostname,
83 ACE_Log_Record &record)
85 ACE_GUARD (ACE_SYNCH_MUTEX_T, guard, print_lock_);
86 record.print (hostname,
87 ACE_Log_Msg::instance ()->flags (),
88 stderr);
91 template<ACE_SYNCH_DECL> void
92 Log_Message_Receiver_Impl<ACE_SYNCH_USE>::log_output (const ACE_TCHAR *hostname,
93 ACE_Log_Record &record,
94 ostream *outputfile)
96 if (outputfile != 0)
98 ACE_GUARD (ACE_SYNCH_MUTEX_T, guard, print_lock_);
99 record.print (hostname,
100 ACE_Log_Msg::instance ()->flags (),
101 *outputfile);
105 template<ACE_SYNCH_DECL>
106 Log_Message_Receiver_Impl<ACE_SYNCH_USE>::~Log_Message_Receiver_Impl ()
108 ACE_ASSERT (count_ == 0 - 1);
111 template<ACE_SYNCH_DECL>
112 Log_Message_Receiver<ACE_SYNCH_USE>::Log_Message_Receiver ()
113 : receiver_impl_ (Log_Message_Receiver_Impl<ACE_SYNCH_USE>::create ())
115 ACE_ASSERT (receiver_impl_ != 0);
118 template<ACE_SYNCH_DECL>
119 Log_Message_Receiver<ACE_SYNCH_USE>::Log_Message_Receiver
120 (Log_Message_Receiver<ACE_SYNCH_USE> const &rhs)
121 : receiver_impl_ (Log_Message_Receiver_Impl<ACE_SYNCH_USE>::attach (rhs.receiver_impl_))
123 ACE_ASSERT (receiver_impl_ != 0);
126 // Type based log message receiver
127 template<ACE_SYNCH_DECL> void
128 Log_Message_Receiver<ACE_SYNCH_USE>::log_record(const ACE_TCHAR *hostname,
129 ACE_Log_Record &record)
131 ACE_ASSERT (receiver_impl_ != 0);
132 receiver_impl_->log_record (hostname, record);
135 template<ACE_SYNCH_DECL> void
136 Log_Message_Receiver<ACE_SYNCH_USE>::log_output(const ACE_TCHAR *hostname,
137 ACE_Log_Record &record,
138 ostream *outputfile)
140 ACE_ASSERT (receiver_impl_ != 0);
141 receiver_impl_->log_output (hostname, record, outputfile);
144 template<ACE_SYNCH_DECL>
145 Log_Message_Receiver<ACE_SYNCH_USE>::~Log_Message_Receiver ()
147 ACE_ASSERT (receiver_impl_ != 0);
148 Log_Message_Receiver_Impl<ACE_SYNCH_USE>::detach (receiver_impl_);
151 #endif /* LOG_MESSAGE_RECEIVER_CPP */