Merge pull request #1551 from DOCGroup/plm_jira_333
[ACE_TAO.git] / TAO / orbsvcs / tests / Bug_2709_Regression / Server_Task.cpp
blobeaa5b66865ac8823b6cdceea3917213d1bb1d809
1 #include "ace/OS_NS_unistd.h"
2 #include "TestImpl.h"
3 #include "Server_Task.h"
5 //////////////////////////////////////////////////////////////////////////
7 Server_Task::Server_Task (const ACE_TCHAR *output,
8 CORBA::ORB_ptr sorb,
9 ACE_Manual_Event &me,
10 ACE_Thread_Manager *thr_mgr) :
11 ACE_Task_Base(thr_mgr),
12 output_(output),
13 me_(me),
14 sorb_(sorb)
18 int
19 Server_Task::svc (void)
21 try
23 CORBA::Object_var poa_object =
24 sorb_->resolve_initial_references ("RootPOA");
26 if (CORBA::is_nil (poa_object.in ()))
27 ACE_ERROR_RETURN ((LM_ERROR, " (%P|%t) Unable to initialize the POA.\n"), 1);
29 PortableServer::POA_var root_poa =
30 PortableServer::POA::_narrow (poa_object.in ());
32 PortableServer::POAManager_var poa_manager =
33 root_poa->the_POAManager ();
35 poa_manager->activate ();
37 TestImpl * server_impl = 0;
38 ACE_NEW_RETURN (server_impl, TestImpl (sorb_.in ()), 1);
40 PortableServer::ObjectId_var id =
41 root_poa->activate_object (server_impl);
43 CORBA::Object_var test_obj =
44 root_poa->id_to_reference (id.in ());
46 Test_var server = Test::_narrow (test_obj.in ());
48 CORBA::String_var ior =
49 sorb_->object_to_string (test_obj.in ());
51 // Output the IOR to the <ior_output_file>
52 FILE *output_file= ACE_OS::fopen (output_, "w");
53 if (output_file != 0)
55 ACE_OS::fprintf (output_file, "%s", ior.in ());
56 ACE_OS::fclose (output_file);
58 ACE_DEBUG ((LM_ERROR, "(%P): Server's IOR was written to file: %s.\n", output_) );
61 // Signal the main thread before we call orb->run ();
62 this->me_.signal ();
64 this->sorb_->run ();
66 ACE_DEBUG ((LM_DEBUG, "event loop finished\n"));
68 root_poa->destroy (1, 1);
70 catch (const CORBA::Exception& ex)
72 ex._tao_print_exception ("Exception caught in server task:");
73 return 1;
76 return 0;