Use =default for skeleton copy constructor
[ACE_TAO.git] / ACE / examples / C++NPv2 / TP_Logging_Server.cpp
blob10bb93f05865d365a63994bf63bc780c3fe82f86
1 /*
2 ** Copyright 2002 Addison Wesley. All Rights Reserved.
3 */
5 #include "ace/OS_Memory.h"
6 #include "ace/Guard_T.h"
7 #include "ace/Message_Block.h"
8 #include "TP_Logging_Server.h"
10 int TP_Logging_Handler::handle_input (ACE_HANDLE) {
11 ACE_Message_Block *mblk = 0;
12 if (logging_handler_.recv_log_record (mblk) != -1) {
13 ACE_Message_Block *log_blk = 0;
14 ACE_NEW_RETURN
15 (log_blk, ACE_Message_Block
16 (reinterpret_cast<char *> (this)), -1);
17 log_blk->cont (mblk);
18 ACE_GUARD_RETURN (ACE_SYNCH_MUTEX, guard, lock_, -1);
19 if (TP_LOGGING_TASK::instance ()->put (log_blk) == -1)
20 { log_blk->release (); return -1; }
21 ++queued_count_;
22 return 0;
23 } else return -1;
27 int
28 TP_Logging_Handler::handle_close (ACE_HANDLE handle,
29 ACE_Reactor_Mask) {
30 int close_now = 0;
31 if (handle != ACE_INVALID_HANDLE) {
32 ACE_GUARD_RETURN (ACE_SYNCH_MUTEX, guard, lock_, -1);
33 if (queued_count_ == 0)
34 close_now = 1;
35 else
36 deferred_close_ = 1;
37 } else {
38 ACE_GUARD_RETURN (ACE_SYNCH_MUTEX, guard, lock_, -1);
39 queued_count_--;
40 if (queued_count_ == 0) close_now = deferred_close_;
43 if (close_now)
44 return Logging_Event_Handler::handle_close ();
45 return 0;
49 int TP_Logging_Task::svc () {
50 for (ACE_Message_Block *log_blk; getq (log_blk) != -1; ) {
51 TP_Logging_Handler *tp_handler = reinterpret_cast<TP_Logging_Handler *> (log_blk->rd_ptr ());
52 Logging_Handler logging_handler (tp_handler->log_file ());
53 logging_handler.write_log_record (log_blk->cont ());
55 log_blk->release ();
56 tp_handler->handle_close (ACE_INVALID_HANDLE, 0);
58 return 0;
61 ACE_FACTORY_DEFINE (TPLS, TP_Logging_Server)
63 ACE_SINGLETON_TEMPLATE_INSTANTIATE(ACE_Singleton, TP_Logging_Task, ACE_Null_Mutex);
64 ACE_SINGLETON_TEMPLATE_INSTANTIATE(ACE_Unmanaged_Singleton, TP_Logging_Task, ACE_Null_Mutex);