Merge pull request #1551 from DOCGroup/plm_jira_333
[ACE_TAO.git] / TAO / orbsvcs / tests / COIOP_Naming_Test / Server_Task.cpp
blob9b72cfaecad54ce81ecaea928797a058206427fa
1 #include "Server_Task.h"
2 #include "TestS.h"
3 #include "Hello.h"
5 #include "ace/Manual_Event.h"
7 Server_Task::Server_Task (CosNaming::NamingContext_ptr root_context,
8 CORBA::ORB_ptr sorb,
9 ACE_Manual_Event &me,
10 ACE_Thread_Manager *thr_mgr)
11 : ACE_Task_Base (thr_mgr)
12 , root_context_ (CosNaming::NamingContext::_duplicate (root_context))
13 , me_ (me)
14 , sorb_ (CORBA::ORB::_duplicate (sorb))
18 int
19 Server_Task::svc (void)
21 try
23 CORBA::Object_var poa_object =
24 this->sorb_->resolve_initial_references("RootPOA");
26 PortableServer::POA_var root_poa =
27 PortableServer::POA::_narrow (poa_object.in ());
29 if (CORBA::is_nil (root_poa.in ()))
30 ACE_ERROR_RETURN ((LM_ERROR,
31 " (%P|%t) Panic: nil RootPOA\n"),
32 1);
34 PortableServer::POAManager_var poa_manager =
35 root_poa->the_POAManager ();
37 Hello *hello_impl = 0;
38 ACE_NEW_RETURN (hello_impl,
39 Hello (this->sorb_.in (),
40 ACE_Thread::self ()),
41 1);
43 PortableServer::ServantBase_var owner_transfer(hello_impl);
45 Test::Hello_var hello =
46 hello_impl->_this ();
48 CosNaming::NamingContext_var example_nc;
49 CosNaming::Name name;
50 name.length(1);
51 name[0].id = CORBA::string_dup("Hello");
52 root_context_->rebind(name, hello.in());
54 poa_manager->activate ();
56 // Signal the main thread before we call orb->run ();
57 this->me_.signal ();
59 ACE_Time_Value runtime (10);
60 this->sorb_->run (runtime);
62 ACE_DEBUG ((LM_DEBUG, "(%P|%t) server - event loop finished\n"));
64 catch (const CORBA::Exception& ex)
66 ex._tao_print_exception ("Exception caught:");
67 return 1;
70 return 0;