Revert "Use a variable on the stack to not have a temporary in the call"
[ACE_TAO.git] / TAO / tests / CSD_Strategy_Tests / TP_Common / AppShutdown.cpp
blob676e4ae79f22435c6303ea344d3fc31622d8d98f
1 #include "AppShutdown.h"
2 #include "TestAppExceptionC.h"
3 #include "ace/Log_Msg.h"
4 #include "ace/OS_NS_unistd.h"
7 AppShutdown::AppShutdown()
8 : num_clients_(0),
9 num_clients_shutdown_(0)
14 AppShutdown::~AppShutdown()
19 void
20 AppShutdown::init(CORBA::ORB_ptr orb,
21 unsigned num_clients)
23 if ((!CORBA::is_nil(this->orb_.in())) ||
24 (CORBA::is_nil(orb)) ||
25 (num_clients == 0))
27 // Already init()'ed, or bad argument values.
28 throw TestAppException();
30 else
32 this->orb_ = CORBA::ORB::_duplicate(orb);
33 this->num_clients_ = num_clients;
34 this->num_clients_shutdown_ = 0;
39 void
40 AppShutdown::wait ()
42 this->orb_shutdown_task_.wait();
46 void
47 AppShutdown::client_done()
49 if ((this->num_clients_ == 0) || (CORBA::is_nil(this->orb_.in())))
51 ACE_ERROR((LM_ERROR, "(%P|%t) AppShutdown was never initialized.\n"));
52 return;
55 unsigned cur_shutdown = ++this->num_clients_shutdown_;
57 if (cur_shutdown == this->num_clients_)
59 // Sleep for one second before shutting down the ORB. This
60 // is a poor-man version of "wait until the CSD request queue drains".
61 ACE_OS::sleep(1);
62 this->orb_shutdown_task_.orb(this->orb_.in());
63 if (this->orb_shutdown_task_.open(0) != 0)
65 ACE_ERROR((LM_ERROR, "(%P|%t) AppShutdown failed to create orb "\
66 "shutdown thread.\n"));
67 return;
73 AppShutdown*
74 AppShutdown::instance ()
76 static AppShutdown app_shutdown;
77 return &app_shutdown;