Merge pull request #1844 from jrw972/monterey
[ACE_TAO.git] / TAO / orbsvcs / tests / Bug_2800_Regression / NamingTask.cpp
blob519524c7afdaea2dcd807ae7dfb44752577e4713
1 #include "NamingTask.h"
2 #include "orbsvcs/Naming/Naming_Server.h"
3 #include "ace/OS_NS_unistd.h"
4 #include "ace/Argv_Type_Converter.h"
6 NamingTask::NamingTask (const char* orbname, int argc, ACE_TCHAR **argv, unsigned short port)
7 : initialized_(false)
9 ACE_TCHAR **my_argv = new ACE_TCHAR *[argc + 2];
10 ACE_TCHAR buf[128];
11 int my_argc = 0;
12 for(; my_argc<argc ;++my_argc)
13 my_argv[my_argc] = argv[my_argc];
14 ACE_OS::sprintf (buf, ACE_TEXT ("iiop://localhost:%d"), port);
15 const ACE_TCHAR* epopt = ACE_TEXT ("-ORBEndpoint");
16 my_argv[my_argc++] = const_cast<ACE_TCHAR *> (epopt);
17 my_argv[my_argc++] = buf;
19 orb_ = CORBA::ORB_init (my_argc, my_argv, orbname);
21 delete [] my_argv;
24 void NamingTask::waitInit ()
26 // Wait for Naming Service initialized.
27 while (! initialized_) {
28 ACE_OS::sleep(ACE_Time_Value(0, 100 * 1000));
32 void NamingTask::end()
34 orb_->shutdown(0);
35 this->wait();
38 const char* NamingTask::ior()
40 return ior_.in ();
43 int NamingTask::svc()
45 try {
46 // Get reference to Root POA
47 CORBA::Object_var obj = orb_->resolve_initial_references("RootPOA");
48 PortableServer::POA_var poa = PortableServer::POA::_narrow(obj.in());
50 // Activate POA Manager
51 PortableServer::POAManager_var poaManager = poa->the_POAManager();
52 poaManager->activate();
54 // Initialize the naming service
55 // We are not going to look for other naming servers
56 TAO_Naming_Server naming;
57 if (naming.init(orb_.in(),
58 poa.in(),
59 ACE_DEFAULT_MAP_SIZE,
63 TAO_NAMING_BASE_ADDR,
64 0) == 0)
66 ACE_DEBUG ((LM_DEBUG, "The Naming Service Task is ready.\n"));
67 ior_ = naming.naming_service_ior ();
68 initialized_ = true;
69 // Accept requests
70 orb_->run();
71 return 0;
73 else
75 ACE_ERROR ((LM_ERROR, "Unable to initialize the Naming Service.\n"));
78 catch (const CORBA::Exception& ex)
80 ex._tao_print_exception ("NamingTask::svc() CORBA::Exception: ");
83 return -1;