1 #include "AppShutdown.h"
2 #include "TestAppExceptionC.h"
3 #include "ace/Log_Msg.h"
4 #include "ace/OS_NS_unistd.h"
6 AppShutdown::AppShutdown()
8 num_clients_shutdown_(0)
13 AppShutdown::~AppShutdown()
19 AppShutdown::init(CORBA::ORB_ptr orb
,
22 if ((!CORBA::is_nil(this->orb_
.in())) ||
23 (CORBA::is_nil(orb
)) ||
26 // Already init()'ed, or bad argument values.
27 throw TestAppException();
31 this->orb_
= CORBA::ORB::_duplicate(orb
);
32 this->num_clients_
= num_clients
;
33 this->num_clients_shutdown_
= 0;
41 this->orb_shutdown_task_
.wait();
46 AppShutdown::client_done()
48 if ((this->num_clients_
== 0) || (CORBA::is_nil(this->orb_
.in())))
50 ACE_ERROR((LM_ERROR
, "(%P|%t) AppShutdown was never initialized.\n"));
54 unsigned cur_shutdown
;
57 ACE_GUARD (TAO_SYNCH_MUTEX
, ace_mon
, this->lock_
);
58 cur_shutdown
= ++this->num_clients_shutdown_
;
61 if (cur_shutdown
== this->num_clients_
)
63 // Sleep for one second before shutting down the ORB. This
64 // is a poor-man version of "wait until the CSD request queue drains".
66 this->orb_shutdown_task_
.orb(this->orb_
.in());
67 if (this->orb_shutdown_task_
.open(0) != 0)
69 ACE_ERROR((LM_ERROR
, "(%P|%t) AppShutdown failed to create orb "\
70 "shutdown thread.\n"));
78 AppShutdown::instance ()
80 static AppShutdown app_shutdown
;