Merge pull request #1551 from DOCGroup/plm_jira_333
[ACE_TAO.git] / TAO / orbsvcs / tests / COIOP_Naming_Test / NamingTask.cpp
blobba73b4a8f066396058f1eed47b0fc1a411f8e9a1
1 #include "NamingTask.h"
2 #include "tao/Version.h"
3 #include "orbsvcs/Naming/Naming_Server.h"
4 #include "ace/OS_NS_unistd.h"
5 #include "ace/Argv_Type_Converter.h"
7 NamingTask::NamingTask (const char* orbname, int argc, ACE_TCHAR** argv)
8 : initialized_(false)
10 ACE_Argv_Type_Converter satc (argc, argv);
11 orb_ = CORBA::ORB_init(satc.get_argc (), satc.get_TCHAR_argv (), orbname);
14 void NamingTask::waitInit ()
16 // Wait for Naming Service initialized.
17 while (! initialized_) {
18 ACE_OS::sleep(ACE_Time_Value(0, 100 * 1000));
22 void NamingTask::end()
24 orb_->shutdown(0);
25 this->wait();
28 CosNaming::NamingContext_ptr
29 NamingTask::root (void) const
31 return CosNaming::NamingContext::_duplicate (root_);
34 int NamingTask::svc()
36 try {
37 // Get reference to Root POA
38 CORBA::Object_var obj = orb_->resolve_initial_references("RootPOA");
39 PortableServer::POA_var poa = PortableServer::POA::_narrow(obj.in());
41 // Activate POA Manager
42 PortableServer::POAManager_var poaManager = poa->the_POAManager();
43 poaManager->activate();
45 // Initialize the naming service
46 // We are not going to look for other naming servers
47 TAO_Naming_Server naming;
48 if (naming.init(orb_.in(),
49 poa.in(),
50 ACE_DEFAULT_MAP_SIZE,
54 TAO_NAMING_BASE_ADDR,
55 0) == 0)
57 ACE_DEBUG ((LM_DEBUG, "The Naming Service Task is ready.\n"));
58 root_ = CosNaming::NamingContext::_duplicate (naming.operator->());
59 initialized_ = true;
60 // Accept requests
61 orb_->run();
62 orb_->destroy();
63 return 0;
65 else {
66 ACE_ERROR ((LM_ERROR, "Error, Unable to initialize the Naming Service.\n"));
69 catch (const CORBA::Exception& ex) {
70 ex._tao_print_exception ("CORBA exception: NamingTask::svc() ");
73 return -1;